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);
}
}
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!");
}
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);
}
Aggregations