Package org.nutz.ioc

Examples of org.nutz.ioc.IocException


              log.debugf("\t >> Make...'%s'<%s>", name, type);
            op = maker.make(ing, iobj);
          }
          // 处理异常
          catch (ObjectLoadException e) {
            throw new IocException(e, "For object [%s] - type:[%s]", name, type);
          }
        }
      }
    }
    return (T) op.get(type, ing);
View Full Code Here


                            log.debug("\t >> Load definition");

                        // 读取对象定义
                        IocObject iobj = loader.load(createLoading(), name);
                        if (null == iobj)
                            throw new IocException("Undefined object '%s'", name);

                        // 修正对象类型
                        if (null == iobj.getType())
                            if (null == type)
                                throw new IocException("NULL TYPE object '%s'", name);
                            else
                                iobj.setType(type);

                        // 检查对象级别
                        if (Strings.isBlank(iobj.getScope()))
                            iobj.setScope(defaultScope);

                        // 根据对象定义,创建对象,maker 会自动的缓存对象到 context 中
                        if (log.isDebugEnabled())
                            log.debugf("\t >> Make...'%s'<%s>", name, type);
                        op = maker.make(ing, iobj);
                    }
                    // 处理异常
                    catch (IocException e) {
                        throw e;
                    }
                    catch (Throwable e) {
                        throw new IocException(Lang.unwrapThrow(e), "For object [%s] - type:[%s]", name, type);
                    }
                }
            }
        }
        synchronized (lock_get) {
View Full Code Here

                Mirror<?> mi = Mirror.me(Lang.loadClass(ss[0]));

                if (hasNullArg) {
                    Method m = (Method) Lang.first(mi.findMethods(ss[1],args.length));
                    if (m == null)
                      throw new IocException("Factory method not found --> ", iobj.getFactory());
                    dw.setBorning(new MethodCastingBorning<Object>(m));
                } else {
                    Method m = mi.findMethod(ss[1], args);
                    dw.setBorning(new MethodBorning<Object>(m));
                }

            } else {
                dw.setBorning((Borning<?>) mirror.getBorning(args));
            }

            // 如果这个对象是容器中的单例,那么就可以生成实例了
            // 这一步非常重要,它解除了字段互相引用的问题
            Object obj = null;
            if (iobj.isSingleton()) {
                obj = dw.born(ing);
                op.setObj(obj);
            }

            // 获得每个字段的注入方式
            FieldInjector[] fields = new FieldInjector[iobj.getFields().length];
            for (int i = 0; i < fields.length; i++) {
                IocField ifld = iobj.getFields()[i];
                try {
                    ValueProxy vp = ing.makeValue(ifld.getValue());
                    fields[i] = FieldInjector.create(mirror, ifld.getName(), vp, ifld.isOptional());
                }
                catch (Exception e) {
                  throw Lang.wrapThrow(e, "Fail to eval Injector for field: '%s'", ifld.getName());
                }
            }
            dw.setFields(fields);

            // 如果是单例对象,前面已经生成实例了,在这里需要填充一下它的字段
            if (null != obj)
                dw.fill(ing, obj);

            // 对象创建完毕,如果有 create 事件,调用它
            dw.onCreate(obj);

        }
        // 当异常发生,从 context 里移除 ObjectProxy
        catch (Throwable e) {
            ing.getContext().remove(iobj.getScope(), ing.getObjectName());
            throw new IocException(e, "create ioc bean fail name=%s ioc define:\n%s", ing.getObjectName(), iobj);
        }

        // 返回
        return op;
    }
View Full Code Here

                        IocObject iobj = loader.load(createLoading(), name);
                        if (null == iobj) {
                          for (String iocBeanName : loader.getName()) {
                            // 相似性少于3 --> 大小写错误,1-2个字符调换顺序或写错
                if (3 > LevenshteinDistance.computeLevenshteinDistance(name.toLowerCase(), iocBeanName.toLowerCase())) {
                  throw new IocException("Undefined object '%s' but found similar name '%s'", name, iocBeanName);
                }
              }
                            throw new IocException("Undefined object '%s'", name);
                        }

                        // 修正对象类型
                        if (null == iobj.getType())
                            if (null == type)
                                throw new IocException("NULL TYPE object '%s'", name);
                            else
                                iobj.setType(type);

                        // 检查对象级别
                        if (Strings.isBlank(iobj.getScope()))
                            iobj.setScope(defaultScope);

                        // 根据对象定义,创建对象,maker 会自动的缓存对象到 context 中
                        if (log.isDebugEnabled())
                            log.debugf("\t >> Make...'%s'<%s>", name, type == null ? "" : type);
                        op = maker.make(ing, iobj);
                    }
                    // 处理异常
                    catch (IocException e) {
                        throw e;
                    }
                    catch (Throwable e) {
                        throw new IocException(Lang.unwrapThrow(e), "For object [%s] - type:[%s]", name, type == null ? "" : type);
                    }
                }
            }
        }
        synchronized (lock_get) {
View Full Code Here

TOP

Related Classes of org.nutz.ioc.IocException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.