use of org.nutz.ioc.meta.IocObject 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);
}
use of org.nutz.ioc.meta.IocObject in project nutz by nutzam.
the class Iocs method wrap.
public static IocObject wrap(Object obj) {
IocObject iobj = new IocObject();
//iobj.setType(obj.getClass());
iobj.setFactory(Iocs.class.getName() + "#self");
IocValue ival = new IocValue(null, new StaticValue(obj));
iobj.addArg(ival);
return iobj;
}
use of org.nutz.ioc.meta.IocObject in project nutz by nutzam.
the class SimpleAopMaker method load.
public IocObject load(IocLoading loading, String name) throws ObjectLoadException {
IocObject iobj = Iocs.wrap(this);
iobj.setType(getClass());
IocEventSet events = new IocEventSet();
events.setDepose("depose");
events.setCreate("init");
events.setFetch("fetch");
iobj.setEvents(events);
return iobj;
}
use of org.nutz.ioc.meta.IocObject in project nutz by nutzam.
the class NutIoc method getNamesByType.
public String[] getNamesByType(Class<?> klass, IocContext context) {
List<String> names = new ArrayList<String>();
for (String name : getNames()) {
try {
IocObject iobj = loader.load(createLoading(), name);
if (iobj != null && iobj.getType() != null && klass.isAssignableFrom(iobj.getType()))
names.add(name);
} catch (Exception e) {
}
}
IocContext cntx;
if (null == context || context == this.context)
cntx = this.context;
else
cntx = new ComboContext(context, this.context);
for (String name : cntx.names()) {
ObjectProxy op = cntx.fetch(name);
if (op.getObj() != null && klass.isAssignableFrom(op.getObj().getClass()))
names.add(name);
}
return new LinkedHashSet<String>(names).toArray(new String[names.size()]);
}
use of org.nutz.ioc.meta.IocObject in project nutz by nutzam.
the class NutIoc method getByType.
public <K> K getByType(Class<K> klass, IocContext context) {
String _name = null;
IocContext cntx;
if (null == context || context == this.context)
cntx = this.context;
else
cntx = new ComboContext(context, this.context);
for (String name : cntx.names()) {
ObjectProxy op = cntx.fetch(name);
if (op.getObj() != null && klass.isAssignableFrom(op.getObj().getClass())) {
_name = name;
break;
}
}
if (_name != null)
return get(klass, _name, context);
for (String name : getNames()) {
try {
IocObject iobj = loader.load(createLoading(), name);
if (iobj != null && iobj.getType() != null && klass.isAssignableFrom(iobj.getType()))
_name = name;
} catch (Exception e) {
continue;
}
if (_name != null)
return get(klass, name, context);
}
throw new IocException("class:" + klass.getName(), "none ioc bean match class=" + klass.getName());
}
Aggregations