MentaContainer

Compare Revisions

Ignore whitespace Rev 101 → Rev 102

/trunk/src/main/java/org/mentacontainer/impl/MentaContainer.java
26,8 → 26,6
 
private Map<String, Factory> factoriesByName = new Hashtable<String, Factory>();
private Map<Class<? extends Object>, List<String>> factoryKeysByType = new Hashtable<Class<? extends Object>, List<String>>();
private Map<String, Scope> scopes = new Hashtable<String, Scope>();
private Map<String, Object> singletonsCache = new Hashtable<String, Object>();
38,6 → 36,8
private Set<ConstructorDependency> constructorDependencies = Collections.synchronizedSet(new HashSet<ConstructorDependency>());
private Set<ConstructorDependency> forConstructMethod = Collections.synchronizedSet(new HashSet<ConstructorDependency>());
@Override
public Class<? extends Object> getType(String key) {
361,38 → 361,19
}
}
private void mapeTypeToKeys(String key, Factory factory) {
Class<? extends Object> type = factory.getType();
synchronized(factoryKeysByType) {
List<String> list = factoryKeysByType.get(type);
if (list == null) {
list = new LinkedList<String>();
factoryKeysByType.put(type, list);
}
list.add(key);
}
}
 
@Override
public Factory ioc(String key, Factory factory, Scope scope) {
factoriesByName.put(key, factory);
mapeTypeToKeys(key, factory);
singletonsCache.remove(key); // just in case we are overriding a previous singleton bean...
threadLocalsCache.remove(key); // just in case we are overriding a previous thread local...
scopes.put(key, scope);
forConstructMethod.add(new ConstructorDependency(key, factory.getType()));
return factory;
}
467,6 → 448,14
return constructorDependencies;
}
@Override
public <T> T construct(Class<? extends Object> klass) {
ClassFactory f = new ClassFactory(this, klass, forConstructMethod);
return (T) f.getInstance();
}
 
@Override
public Container populate(Object bean) {