Search in sources :

Example 1 with ObjectLoadException

use of org.nutz.ioc.ObjectLoadException in project nutz by nutzam.

the class MapLoader method checkParents.

/**
     * 检查继承关系,如果发现循环继承,或其他错误的继承关系,则抛出ObjectLoadException
     * 
     * @param name
     *            beanId
     * @throws ObjectLoadException
     *             if Inheritance errors or Inheritance cycle founded.
     */
@SuppressWarnings("unchecked")
private void checkParents(String name) throws ObjectLoadException {
    ArrayList<String> list = new ArrayList<String>();
    list.add(name);
    String currentParent = map.get(name).get("parent").toString();
    while (true) {
        if (currentParent == null)
            break;
        if (list.contains(currentParent))
            throw Lang.makeThrow(ObjectLoadException.class, "!!!Inheritance cycle! id = %s", name);
        list.add(currentParent);
        Object obj = map.get(currentParent);
        if (obj != null && obj instanceof Map)
            currentParent = (String) ((Map<String, Object>) obj).get("parent");
        else
            throw Lang.makeThrow(ObjectLoadException.class, "!!!Inheritance errors! id = %s", name);
    }
}
Also used : ObjectLoadException(org.nutz.ioc.ObjectLoadException) ArrayList(java.util.ArrayList) IocObject(org.nutz.ioc.meta.IocObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ObjectLoadException

use of org.nutz.ioc.ObjectLoadException in project nutz by nutzam.

the class ComboIocLoader method load.

public IocObject load(IocLoading loading, String name) throws ObjectLoadException {
    for (IocLoader iocLoader : iocLoaders) if (iocLoader.has(name)) {
        IocObject iocObject = iocLoader.load(loading, name);
        if (log.isDebugEnabled()) {
            // TODO 弄成更好看的格式,方便debug
            String printName;
            if (iocLoader instanceof AnnotationIocLoader) {
                String packages = Arrays.toString(((AnnotationIocLoader) iocLoader).getPackages());
                printName = "AnnotationIocLoader(packages=" + packages + ")";
            } else if (JsonLoader.class.equals(iocLoader.getClass()) && ((JsonLoader) iocLoader).getPaths() != null) {
                String paths = Arrays.toString(((JsonLoader) iocLoader).getPaths());
                printName = "JsonLoader(paths=" + paths + ")";
            } else {
                printName = iocLoader.getClass().getSimpleName() + "@" + iocLoader.hashCode();
            }
            log.debugf("Found IocObject(%s) in %s", name, printName);
        }
        return iocObject;
    }
    throw new ObjectLoadException("Object '" + name + "' without define!");
}
Also used : AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) ObjectLoadException(org.nutz.ioc.ObjectLoadException) IocObject(org.nutz.ioc.meta.IocObject) XmlIocLoader(org.nutz.ioc.loader.xml.XmlIocLoader) IocLoader(org.nutz.ioc.IocLoader) AsyncAopIocLoader(org.nutz.aop.interceptor.async.AsyncAopIocLoader) AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) PropertiesIocLoader(org.nutz.ioc.loader.properties.PropertiesIocLoader) TransIocLoader(org.nutz.aop.interceptor.ioc.TransIocLoader) JsonLoader(org.nutz.ioc.loader.json.JsonLoader)

Example 3 with ObjectLoadException

use of org.nutz.ioc.ObjectLoadException in project nutz by nutzam.

the class MapLoader method load.

/**
     * {@link ObjectLoadException}
     */
public IocObject load(IocLoading loading, String name) throws ObjectLoadException {
    Map<String, Object> m = getMap(name);
    if (null == m)
        throw new ObjectLoadException("Object '" + name + "' without define!");
    if (log.isDebugEnabled())
        log.debug("Loading define for name=" + name);
    // If has parent
    Object p = m.get("parent");
    if (null != p) {
        checkParents(name);
        IocObject parent = load(loading, p.toString());
        // create new map without parent
        Map<String, Object> newMap = new HashMap<String, Object>();
        for (Entry<String, Object> en : m.entrySet()) {
            if ("parent".equals(en.getKey()))
                continue;
            newMap.put(en.getKey(), en.getValue());
        }
        // Create self IocObject
        IocObject self = loading.map2iobj(newMap);
        // Merge with parent
        return Iocs.mergeWith(self, parent);
    }
    return loading.map2iobj(m);
}
Also used : ObjectLoadException(org.nutz.ioc.ObjectLoadException) HashMap(java.util.HashMap) IocObject(org.nutz.ioc.meta.IocObject) IocObject(org.nutz.ioc.meta.IocObject)

Aggregations

ObjectLoadException (org.nutz.ioc.ObjectLoadException)3 IocObject (org.nutz.ioc.meta.IocObject)3 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 AsyncAopIocLoader (org.nutz.aop.interceptor.async.AsyncAopIocLoader)1 TransIocLoader (org.nutz.aop.interceptor.ioc.TransIocLoader)1 IocLoader (org.nutz.ioc.IocLoader)1 AnnotationIocLoader (org.nutz.ioc.loader.annotation.AnnotationIocLoader)1 JsonLoader (org.nutz.ioc.loader.json.JsonLoader)1 PropertiesIocLoader (org.nutz.ioc.loader.properties.PropertiesIocLoader)1 XmlIocLoader (org.nutz.ioc.loader.xml.XmlIocLoader)1