use of org.nutz.ioc.ObjectProxy in project nutz by nutzam.
the class ScopeContext method clear.
public void clear() {
checkBuffer();
List<Entry<String, ObjectProxy>> list = new ArrayList<Entry<String, ObjectProxy>>(objs.entrySet());
Collections.reverse(list);
List<Entry<String, ObjectProxy>> tmp = new ArrayList<Entry<String, ObjectProxy>>();
for (Entry<String, ObjectProxy> en : list) {
try {
ObjectProxy op = en.getValue();
Object obj = op.getObj();
if (obj != null && obj instanceof DataSource) {
tmp.add(en);
continue;
}
} catch (Throwable e) {
}
if (log.isDebugEnabled())
log.debugf("Depose object '%s' ...", en.getKey());
en.getValue().depose();
}
for (Entry<String, ObjectProxy> en : tmp) {
if (log.isDebugEnabled())
log.debugf("Depose object '%s' ...", en.getKey());
en.getValue().depose();
}
objs.clear();
}
use of org.nutz.ioc.ObjectProxy 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.ObjectProxy 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