@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) {