Package org.nutz.ioc.meta

Examples of org.nutz.ioc.meta.IocField


            }

            // 获得每个字段的注入方式
            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);

            // 如果是单例对象,前面已经生成实例了,在这里需要填充一下它的字段
View Full Code Here


    @SuppressWarnings("unchecked")
    public IocObject map2iobj(Map<String, Object> map) throws ObjectLoadException {
        final IocObject iobj = new IocObject();
        if (!isIocObject(map)) {
            for (Entry<String, Object> en : map.entrySet()) {
                IocField ifld = new IocField();
                ifld.setName(en.getKey());
                ifld.setValue(object2value(en.getValue()));
                iobj.addField(ifld);
            }
            if (log.isWarnEnabled()) // TODO 移除这种兼容性
                log.warn("Using *Declared* ioc-define (without type or events)!!! Pls use Standard Ioc-Define!!"
                            + " Bean will define as:\n"
                            + Json.toJson(iobj));
        } else {
            Object v = map.get("type");
            // type
            try {
                String typeName = (String) v;
                if (!Strings.isBlank(typeName)) {
                    iobj.setType(Lang.loadClass(typeName));
                }
            }
            catch (Exception e) {
                throw E(e, "Wrong type name: '%s'", v);
            }
            // singleton
            try {
                v = map.get("singleton");
                if (null != v)
                    iobj.setSingleton(Castors.me().castTo(v, boolean.class));
            }
            catch (FailToCastObjectException e) {
                throw E(e, "Wrong singleton: '%s'", v);
            }
            // scope
            v = map.get("scope");
            if (null != v)
                iobj.setScope(v.toString());
            // events
            try {
                v = map.get("events");
                if (null != v) {
                    IocEventSet ies = Lang.map2Object((Map<?, ?>) v, IocEventSet.class);
                    iobj.setEvents(ies);
                }
            }
            catch (Exception e) {
                throw E(e, "Wrong events: '%s'", v);
            }
            // args
            try {
                v = map.get("args");
                if (null != v) {
                    Lang.each(v, new Each<Object>() {
                        public void invoke(int i, Object ele, int length) {
                            iobj.addArg(object2value(ele));
                        }
                    });
                }
            }
            catch (Exception e) {
                throw E(e, "Wrong args: '%s'", v);
            }
            // fields
            try {
                v = map.get("fields");
                if (null != v) {
                    Map<String, Object> fields = (Map<String, Object>) v;
                    for (Entry<String, Object> en : fields.entrySet()) {
                        IocField ifld = new IocField();
                        ifld.setName(en.getKey());
                        ifld.setValue(object2value(en.getValue()));
                        iobj.addField(ifld);
                    }
                }
            }
            catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.nutz.ioc.meta.IocField

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.