use of org.nutz.ioc.IocContext 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.IocContext 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