org.nutz.ioc.Ioc.get()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(274)

本文整理了Java中org.nutz.ioc.Ioc.get()方法的一些代码示例,展示了Ioc.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ioc.get()方法的具体详情如下:
包路径:org.nutz.ioc.Ioc
类名称:Ioc
方法名:get

Ioc.get介绍

[英]从容器中获取一个对象。这个对象的名称会根据传入的类型按如下规则决定

  • 如果定义了注解 '@InjectName',采用其值为注入名
  • 否则采用类型 simpleName 的首字母小写形式作为注入名
    [中]从容器中获取一个对象。这个对象的名称会根据传入的类型按如下规则决定
  • 如果定义了注解 '@名称'采用其值为注入名
  • 否则采用类型 单纯形的首字母小写形式作为注入名

代码示例

代码示例来源:origin: nutzam/nutz

public Object get(ServletContext sc, HttpServletRequest req, HttpServletResponse resp, Object refer) {
  Ioc ioc = Mvcs.getIoc();
  if (null == ioc)
    throw new RuntimeException("You need define @IocBy in main module!!!");
  if (Strings.isBlank(objName))
    return ioc.get(objType);
  return ioc.get(objType, objName);
}

代码示例来源:origin: nutzam/nutz

if (!beanName.startsWith(AopConfigration.IOCNAME))
  continue;
AopConfigration cnf = ioc.get(AopConfigration.class, beanName);
list.add(cnf);
if (cnf instanceof AnnotationAopConfigration)

代码示例来源:origin: nutzam/nutz

names = ioc.getNamesByType(type);
  if (names != null && names.length == 1) {
    return ioc.get(type, names[0]);
if (ioc instanceof Ioc2)
  return ((Ioc2)ioc).get(type, name, ctx);
return ioc.get(type, name);

代码示例来源:origin: nutzam/nutz

public List<? extends MethodInterceptor> makeIt(Aop t, Method method, Ioc ioc) {
    List<MethodInterceptor> list = new ArrayList<MethodInterceptor>();
    for (String name : t.value()) {
      list.add(ioc.get(MethodInterceptor.class, name));
    }
    return list;
  }
}

代码示例来源:origin: nutzam/nutz

for (int i = 0; i < vms.value().length; i++) {
  if (vms.value()[i].getAnnotation(IocBean.class) != null && ioc != null) {
    makers.add(ioc.get(vms.value()[i]));
  } else {
    makers.add(Mirror.me(vms.value()[i]).born());
  if (name != null && name.startsWith(ViewMaker.IOCNAME)) {
    log.debug("add ViewMaker from Ioc by name=" + name);
    makers.add(ioc.get(ViewMaker.class, name));

代码示例来源:origin: nutzam/nutz

protected Object getValue(IocMaking ing, Object obj) throws Exception {
  return ing.getIoc().get(type, name);
}

代码示例来源:origin: nutzam/nutz

Setup setup = config.getIoc().get(Setup.class, name);
config.setAttributeIgnoreNull(Setup.class.getName(), setup);
setup.init(config);

代码示例来源:origin: nutzam/nutz

public Object get(String key) {
    if (key == null)
      return null;
    if ("sys".equals(key))
      return System.getProperties();
    if ("env".equals(key))
      return System.getenv();
    if ("$ioc".equals(key))
      return ioc;
    if (key.startsWith("$") && key.length() > 1)
      return ioc.get(Object.class, key.substring(1));
    return super.get(key);
  }
}

代码示例来源:origin: nutzam/nutz

@SuppressWarnings("unchecked")
  public List<T> gets() {
    List<T> aList = new ArrayList<T>(names.length);
    for (String name : names) {
      try {
        Plugin plugin = ioc.get(Plugin.class, name);
        if (plugin.canWork())
          aList.add((T)plugin);
      }
      catch (IocException e) {}
    }
    return aList;
  }
}

代码示例来源:origin: nutzam/nutz

@SuppressWarnings("unchecked")
public T get() throws NoPluginCanWorkException {
  for (String name : names) {
    try {
      Plugin plugin = ioc.get(Plugin.class, name);
      if (plugin.canWork())
        return (T) plugin;
    }
    catch (IocException e) {}
  }
  throw new NoPluginCanWorkException();
}

代码示例来源:origin: nutzam/nutz

public Object born(Object... args) {
    Object factoryBean = ing.getIoc().get(null, ss[0].substring(1));
    return Mirror.me(factoryBean).invoke(factoryBean, ss[1], args);
  }
});

代码示例来源:origin: nutzam/nutz

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
  if (proxy == null) {
    synchronized (lock) {
      if (proxy == null) {
        Ioc ioc = Mvcs.ctx().getDefaultIoc();
        Filter proxy = ioc.get(null, beanName);
        proxy.init(filterConfig);
        this.proxy = proxy;
      }
    }
  }
  proxy.doFilter(request, response, chain);
}

代码示例来源:origin: nutzam/nutz

public Object get(IocMaking ing) {
  Ioc ioc = ing.getIoc();
  if (ioc instanceof Ioc2)
    return ((Ioc2)ioc).get(type, name,ing.getContext());
  return ioc.get(type, name);
}

代码示例来源:origin: nutzam/nutz

public static <T> T evalObj(NutConfig config, Class<T> type, String[] args) {
  // 用上下文替换参数
  Context context = config.getLoadingContext();
  for (int i = 0; i < args.length; i++) {
    args[i] = Segments.replace(args[i], context);
  }
  // 判断是否是 Ioc 注入
  if (args.length == 1 && args[0].startsWith("ioc:")) {
    String name = Strings.trim(args[0].substring(4));
    return config.getIoc().get(type, name);
  }
  return Mirror.me(type).born((Object[]) args);
}

代码示例来源:origin: nutzam/nutz

protected MethodInterceptor getMethodInterceptor(    Ioc ioc,
                          String interceptorName,
                          boolean singleton) {
  if (interceptorName.startsWith("ioc:"))
    return ioc.get(MethodInterceptor.class, interceptorName.substring(4));
  try {
    if (singleton == false)
      return (MethodInterceptor) Mirror.me(Lang.loadClass(interceptorName)).born();
    MethodInterceptor methodInterceptor = cachedMethodInterceptor.get(interceptorName);
    if (methodInterceptor == null) {
      methodInterceptor = (MethodInterceptor) Mirror.me(Lang.loadClass(interceptorName)).born();
      cachedMethodInterceptor.put(interceptorName, methodInterceptor);
    }
    return methodInterceptor;
  }
  catch (Throwable e) {
    throw Lang.wrapThrow(e);
  }
}

代码示例来源:origin: nutzam/nutz

protected Processor getProcessorByName(NutConfig config,String name) throws Exception {
    if (name.startsWith("ioc:") && name.length() > 4) {
      if (config.getIoc() == null)
        throw new IllegalArgumentException("getProcessorByName " + name + " but no ioc !");
      return config.getIoc().get(Processor.class, name.substring(4).trim());
    }
    else {
      Class<?> klass = null;
      if (name.startsWith("!")) {
        name = name.substring(1);
        if (disabledProcessor.contains(name))
          return null;
        try {
          klass = Lang.loadClass(name);
        }
        catch (Throwable e) {
          log.info("Optional processor class not found, disabled : " + name);
          disabledProcessor.put(name, name);
          return null;
        }
        return (Processor) Mirror.me(klass).born();
      }
      return (Processor) Mirror.me(Lang.loadClass(name)).born();
    }
  }
}

代码示例来源:origin: nutzam/nutz

return new VoidView();
if (VIEW_IOC.equals(type))
  return ioc.get(View.class, value);
if (VIEW_HTTP.equals(type)) {
  String val = Strings.sBlank(value, "500");

代码示例来源:origin: nutzam/nutz

@SuppressWarnings({"all"})
protected void createSessionProvider(NutConfig config, Class<?> mainModule) throws Exception {
  SessionBy sb = mainModule.getAnnotation(SessionBy.class);
  if (sb != null) {
    SessionProvider sp = null;
    if (sb.args() != null && sb.args().length == 1 && sb.args()[0].startsWith("ioc:"))
      sp = config.getIoc().get(sb.value(), sb.args()[0].substring(4));
    else
      sp = Mirror.me(sb.value()).born((Object[])sb.args());
    if (log.isInfoEnabled())
      log.info("SessionBy --> " + sp);
    config.setSessionProvider(sp);
  }
}

代码示例来源:origin: nutzam/nutz

protected Ioc createIoc(NutConfig config, Class<?> mainModule) throws Exception {
  IocBy ib = mainModule.getAnnotation(IocBy.class);
  if (null != ib) {
    if (log.isDebugEnabled())
      log.debugf("@IocBy(type=%s, args=%s,init=%s)",
            ib.type().getName(),
            Json.toJson(ib.args()),
            Json.toJson(ib.init()));
    Ioc ioc = Mirror.me(ib.type()).born().create(config, ib.args());
    // 如果是 Ioc2 的实现,增加新的 ValueMaker
    if (ioc instanceof Ioc2) {
      ((Ioc2) ioc).addValueProxyMaker(new ServletValueProxyMaker(config.getServletContext()));
    }
    // 如果给定了 Ioc 的初始化,则依次调用
    for (String objName : ib.init()) {
      ioc.get(null, objName);
    }
    // 保存 Ioc 对象
    Mvcs.setIoc(ioc);
    return ioc;
  } else if (log.isInfoEnabled())
    log.info("!!!Your application without @IocBy supporting");
  return null;
}

代码示例来源:origin: nutzam/nutz

msgLoader = config.getIoc().get(lc.type(), lc.beanName());

相关文章