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

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

本文整理了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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. public Object get(String key) {
  2. if (key == null)
  3. return null;
  4. if ("sys".equals(key))
  5. return System.getProperties();
  6. if ("env".equals(key))
  7. return System.getenv();
  8. if ("$ioc".equals(key))
  9. return ioc;
  10. if (key.startsWith("$") && key.length() > 1)
  11. return ioc.get(Object.class, key.substring(1));
  12. return super.get(key);
  13. }
  14. }

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

  1. @SuppressWarnings("unchecked")
  2. public List<T> gets() {
  3. List<T> aList = new ArrayList<T>(names.length);
  4. for (String name : names) {
  5. try {
  6. Plugin plugin = ioc.get(Plugin.class, name);
  7. if (plugin.canWork())
  8. aList.add((T)plugin);
  9. }
  10. catch (IocException e) {}
  11. }
  12. return aList;
  13. }
  14. }

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

  1. @SuppressWarnings("unchecked")
  2. public T get() throws NoPluginCanWorkException {
  3. for (String name : names) {
  4. try {
  5. Plugin plugin = ioc.get(Plugin.class, name);
  6. if (plugin.canWork())
  7. return (T) plugin;
  8. }
  9. catch (IocException e) {}
  10. }
  11. throw new NoPluginCanWorkException();
  12. }

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

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

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

  1. public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
  2. throws IOException, ServletException {
  3. if (proxy == null) {
  4. synchronized (lock) {
  5. if (proxy == null) {
  6. Ioc ioc = Mvcs.ctx().getDefaultIoc();
  7. Filter proxy = ioc.get(null, beanName);
  8. proxy.init(filterConfig);
  9. this.proxy = proxy;
  10. }
  11. }
  12. }
  13. proxy.doFilter(request, response, chain);
  14. }

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

  1. public Object get(IocMaking ing) {
  2. Ioc ioc = ing.getIoc();
  3. if (ioc instanceof Ioc2)
  4. return ((Ioc2)ioc).get(type, name,ing.getContext());
  5. return ioc.get(type, name);
  6. }

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

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

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

  1. protected MethodInterceptor getMethodInterceptor( Ioc ioc,
  2. String interceptorName,
  3. boolean singleton) {
  4. if (interceptorName.startsWith("ioc:"))
  5. return ioc.get(MethodInterceptor.class, interceptorName.substring(4));
  6. try {
  7. if (singleton == false)
  8. return (MethodInterceptor) Mirror.me(Lang.loadClass(interceptorName)).born();
  9. MethodInterceptor methodInterceptor = cachedMethodInterceptor.get(interceptorName);
  10. if (methodInterceptor == null) {
  11. methodInterceptor = (MethodInterceptor) Mirror.me(Lang.loadClass(interceptorName)).born();
  12. cachedMethodInterceptor.put(interceptorName, methodInterceptor);
  13. }
  14. return methodInterceptor;
  15. }
  16. catch (Throwable e) {
  17. throw Lang.wrapThrow(e);
  18. }
  19. }

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

  1. protected Processor getProcessorByName(NutConfig config,String name) throws Exception {
  2. if (name.startsWith("ioc:") && name.length() > 4) {
  3. if (config.getIoc() == null)
  4. throw new IllegalArgumentException("getProcessorByName " + name + " but no ioc !");
  5. return config.getIoc().get(Processor.class, name.substring(4).trim());
  6. }
  7. else {
  8. Class<?> klass = null;
  9. if (name.startsWith("!")) {
  10. name = name.substring(1);
  11. if (disabledProcessor.contains(name))
  12. return null;
  13. try {
  14. klass = Lang.loadClass(name);
  15. }
  16. catch (Throwable e) {
  17. log.info("Optional processor class not found, disabled : " + name);
  18. disabledProcessor.put(name, name);
  19. return null;
  20. }
  21. return (Processor) Mirror.me(klass).born();
  22. }
  23. return (Processor) Mirror.me(Lang.loadClass(name)).born();
  24. }
  25. }
  26. }

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

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

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

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

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

  1. protected Ioc createIoc(NutConfig config, Class<?> mainModule) throws Exception {
  2. IocBy ib = mainModule.getAnnotation(IocBy.class);
  3. if (null != ib) {
  4. if (log.isDebugEnabled())
  5. log.debugf("@IocBy(type=%s, args=%s,init=%s)",
  6. ib.type().getName(),
  7. Json.toJson(ib.args()),
  8. Json.toJson(ib.init()));
  9. Ioc ioc = Mirror.me(ib.type()).born().create(config, ib.args());
  10. // 如果是 Ioc2 的实现,增加新的 ValueMaker
  11. if (ioc instanceof Ioc2) {
  12. ((Ioc2) ioc).addValueProxyMaker(new ServletValueProxyMaker(config.getServletContext()));
  13. }
  14. // 如果给定了 Ioc 的初始化,则依次调用
  15. for (String objName : ib.init()) {
  16. ioc.get(null, objName);
  17. }
  18. // 保存 Ioc 对象
  19. Mvcs.setIoc(ioc);
  20. return ioc;
  21. } else if (log.isInfoEnabled())
  22. log.info("!!!Your application without @IocBy supporting");
  23. return null;
  24. }

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

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

相关文章