MentaContainer

Compare Revisions

Ignore whitespace Rev 142 → Rev 143

/trunk/src/main/java/org/mentacontainer/impl/MentaContainer.java
11,7 → 11,7
 
import org.mentacontainer.ConfigurableFactory;
import org.mentacontainer.Container;
import org.mentacontainer.Creator;
import org.mentacontainer.Factory;
import org.mentacontainer.Pool;
import org.mentacontainer.Scope;
import org.mentacontainer.util.InjectionUtils;
24,7 → 24,7
*/
public class MentaContainer implements Container {
 
private Map<String, Pool<?>> factoriesByName = new Hashtable<String, Pool<?>>();
private Map<String, Pool<?>> poolsByName = new Hashtable<String, Pool<?>>();
private Map<String, Scope> scopes = new Hashtable<String, Scope>();
43,7 → 43,7
String k = InjectionUtils.getKeyName(key);
Creator<?> factory = factoriesByName.get(k);
Factory<?> factory = poolsByName.get(k);
if (factory == null) return null;
61,7 → 61,7
for(String key : singletonsCache.keySet()) {
Pool<?> pool = factoriesByName.get(key);
Pool<?> pool = poolsByName.get(key);
Object value = singletonsCache.get(key);
83,7 → 83,7
for(String key : threadLocalsCache.keySet()) {
Pool<?> factory = factoriesByName.get(key);
Pool<?> factory = poolsByName.get(key);
ThreadLocal<Object> t = threadLocalsCache.get(key);
109,7 → 109,7
String keyString = InjectionUtils.getKeyName(key);
if (!factoriesByName.containsKey(keyString)) return null;
if (!poolsByName.containsKey(keyString)) return null;
Scope scope = scopes.get(keyString);
125,7 → 125,7
if (value != null) {
Pool<?> factory = factoriesByName.get(keyString);
Pool<?> factory = poolsByName.get(keyString);
cp = new ClearableHolder(factory, value);
}
151,7 → 151,7
if (o != null) {
Pool<?> factory = factoriesByName.get(keyString);
Pool<?> factory = poolsByName.get(keyString);
cp = new ClearableHolder(factory, o);
181,9 → 181,9
String keyString = InjectionUtils.getKeyName(key);
 
if (!factoriesByName.containsKey(keyString)) return null;
if (!poolsByName.containsKey(keyString)) return null;
 
Creator<?> c = factoriesByName.get(keyString);
Factory<?> c = poolsByName.get(keyString);
Scope scope = scopes.get(keyString);
213,7 → 213,7
// getInstance needs to be in a non-synchronized block
target = c.createInstance();
target = c.getInstance();
synchronized(this) {
 
265,7 → 265,7
// getInstance needs to be in a non-synchronized block
target = c.createInstance();
target = c.getInstance();
t.set(target);
}
280,7 → 280,7
} else if (scope == Scope.NONE) {
 
target = c.createInstance();
target = c.getInstance();
} else {
331,13 → 331,13
}
}
private static <T> Pool<T> fromFactory(final Creator<T> creator) {
private static <T> Pool<T> fromFactory(final Factory<T> creator) {
return new Pool<T>() {
 
@Override
public T createInstance() {
return creator.createInstance();
public T getInstance() {
return creator.getInstance();
}
 
@Override
353,7 → 353,7
}
@Override
public <T> Creator<T> ioc(Object key, Creator<T> factory, Scope scope) {
public <T> Factory<T> ioc(Object key, Factory<T> factory, Scope scope) {
return ioc(key, fromFactory(factory), scope);
}
362,7 → 362,7
String keyString = InjectionUtils.getKeyName(key);
factoriesByName.put(keyString, factory);
poolsByName.put(keyString, factory);
singletonsCache.remove(keyString); // just in case we are overriding a previous singleton bean...
379,7 → 379,7
}
@Override
public <T> Creator<T> ioc(Object key, Creator<T> factory) {
public <T> Factory<T> ioc(Object key, Factory<T> factory) {
return ioc(key, fromFactory(factory));
}
467,7 → 467,7
ClassFactory<T> f = new ClassFactory<T>(this, klass, forConstructMethod);
return f.createInstance();
return f.getInstance();
}
 
@Override
504,7 → 504,7
String key = InjectionUtils.getKeyName(obj);
if (!factoriesByName.containsKey(key)) return false;
if (!poolsByName.containsKey(key)) return false;
Scope scope = scopes.get(key);