MentaContainer

Compare Revisions

Ignore whitespace Rev 142 → Rev 141

/trunk/src/main/java/org/mentacontainer/impl/MentaContainer.java
12,6 → 12,7
import org.mentacontainer.ConfigurableFactory;
import org.mentacontainer.Container;
import org.mentacontainer.Creator;
import org.mentacontainer.Interceptor;
import org.mentacontainer.Pool;
import org.mentacontainer.Scope;
import org.mentacontainer.util.InjectionUtils;
39,7 → 40,7
private Set<ConstructorDependency> forConstructMethod = Collections.synchronizedSet(new HashSet<ConstructorDependency>());
@Override
public Class<?> getType(Object key) {
public Class<? extends Object> getType(Object key) {
String k = InjectionUtils.getKeyName(key);
215,6 → 216,8
target = c.createInstance();
checkInterceptable(c, target);
synchronized(this) {
 
singletonsCache.put(keyString, target);
267,6 → 270,8
target = c.createInstance();
checkInterceptable(c, target);
t.set(target);
}
282,6 → 287,8
 
target = c.createInstance();
checkInterceptable(c, target);
} else {
throw new UnsupportedOperationException("Don't know how to handle scope: " + scope);
331,6 → 338,16
}
}
private final void checkInterceptable(Creator<?> f, Object value) {
if (f instanceof Interceptor) {
Interceptor i = (Interceptor) f;
((Interceptor) f).onCreated(value);
}
}
private static <T> Pool<T> fromFactory(final Creator<T> creator) {
return new Pool<T>() {
354,15 → 371,10
@Override
public <T> Creator<T> ioc(Object key, Creator<T> factory, Scope scope) {
return ioc(key, fromFactory(factory), scope);
}
@Override
public <T> Pool<T> ioc(Object key, Pool<T> factory, Scope scope) {
String keyString = InjectionUtils.getKeyName(key);
factoriesByName.put(keyString, factory);
factoriesByName.put(keyString, fromFactory(factory));
singletonsCache.remove(keyString); // just in case we are overriding a previous singleton bean...
379,18 → 391,12
}
@Override
public <T> Creator<T> ioc(Object key, Creator<T> factory) {
public Creator<?> ioc(Object key, Creator<?> factory) {
return ioc(key, fromFactory(factory));
return ioc(key, factory, Scope.NONE);
}
@Override
public <T> Pool<T> ioc(Object key, Pool<T> pool) {
return ioc(key, pool, Scope.NONE);
}
@Override
public <T> ConfigurableFactory<T> ioc(Object key, Class<T> klass) {
ConfigurableFactory<T> cc = new ClassFactory<T>(this, klass);