MentaContainer

Compare Revisions

Regard whitespace Rev 141 → Rev 142

/trunk/src/test/java/org/mentacontainer/impl/MentaContainerTest.java
4,8 → 4,6
 
import org.junit.Test;
import org.mentacontainer.Container;
import org.mentacontainer.Creator;
import org.mentacontainer.Interceptor;
import org.mentacontainer.Scope;
 
public class MentaContainerTest {
/trunk/src/test/java/org/mentacontainer/impl/ClassFactoryTest.java
4,7 → 4,6
 
import org.junit.Test;
import org.mentacontainer.Creator;
import org.mentacontainer.Factory;
 
public class ClassFactoryTest {
/trunk/src/main/java/org/mentacontainer/Factory.java
File deleted
\ No newline at end of file
/trunk/src/main/java/org/mentacontainer/Interceptor.java
File deleted
\ No newline at end of file
/trunk/src/main/java/org/mentacontainer/impl/GenericFactory.java
3,10 → 3,9
import java.lang.reflect.Method;
 
import org.mentacontainer.Creator;
import org.mentacontainer.Interceptor;
import org.mentacontainer.util.FindMethod;
 
public class GenericFactory<E> implements Creator<E>, Interceptor<E> {
public class GenericFactory<E> implements Creator<E> {
private final Object factory;
14,8 → 13,6
private final Class<E> type;
private Interceptor<E> interceptor = null;
public GenericFactory(Object factory, String methodName) {
this.factory = factory;
34,26 → 31,7
}
}
public void setInterceptor(Interceptor<E> interceptor) {
this.interceptor = interceptor;
}
@Override
public void onCreated(E createdObject) {
if (interceptor != null) {
interceptor.onCreated(createdObject);
}
}
@Override
public void onCleared(E clearedObject) {
if (interceptor != null) {
interceptor.onCleared(clearedObject);
}
}
@Override
public E createInstance() {
try {
/trunk/src/main/java/org/mentacontainer/impl/MentaContainer.java
12,7 → 12,6
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;
40,7 → 39,7
private Set<ConstructorDependency> forConstructMethod = Collections.synchronizedSet(new HashSet<ConstructorDependency>());
@Override
public Class<? extends Object> getType(Object key) {
public Class<?> getType(Object key) {
String k = InjectionUtils.getKeyName(key);
216,8 → 215,6
target = c.createInstance();
checkInterceptable(c, target);
synchronized(this) {
 
singletonsCache.put(keyString, target);
270,8 → 267,6
target = c.createInstance();
checkInterceptable(c, target);
t.set(target);
}
287,8 → 282,6
 
target = c.createInstance();
checkInterceptable(c, target);
} else {
throw new UnsupportedOperationException("Don't know how to handle scope: " + scope);
338,16 → 331,6
}
}
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>() {
371,10 → 354,15
@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, fromFactory(factory));
factoriesByName.put(keyString, factory);
singletonsCache.remove(keyString); // just in case we are overriding a previous singleton bean...
391,12 → 379,18
}
@Override
public Creator<?> ioc(Object key, Creator<?> factory) {
public <T> Creator<T> ioc(Object key, Creator<T> factory) {
return ioc(key, factory, Scope.NONE);
return ioc(key, fromFactory(factory));
}
@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);
/trunk/src/main/java/org/mentacontainer/Container.java
71,9 → 71,19
* @return The factory passed as a parameter. (Fluent API)
* @see Factory
*/
public Creator<?> ioc(Object key, Creator<?> factory);
public <T> Creator<T> ioc(Object key, Creator<T> factory);
/**
* Set up a pool for the given key. The scope assumed is NONE.
*
* @param key The key representing the bean to return. The name of the bean in the container.
* @param pool The pool for the IoC.
* @return The factory passed as a parameter. (Fluent API)
* @see Pool
*/
public <T> Pool<T> ioc(Object key, Pool<T> pool);
/**
* Set up a factory for the given key in the given scope.
*
* @param key The key representing the bean to return. The name of the bean in the container.
86,6 → 96,18
public <T> Creator<T> ioc(Object key, Creator<T> factory, Scope scope);
/**
* Set up a pool for the given key in the given scope.
*
* @param key The key representing the bean to return. The name of the bean in the container.
* @param pool The pool for the IoC.
* @param scope The scope used by the factory.
* @return The factory passed as a parameter (Fluent API).
* @see Pool
* @see Scope
*/
public <T> Pool<T> ioc(Object key, Pool<T> pool, Scope scope);
/**
* Configure a bean dependency to be auto-wired by the container.
* It wires by constructor and by setter. By constructor is uses the type of sourceFromContainer. By setter it assumes the property is also named sourceFromContainer.
*
/trunk/src/main/java/org/mentacontainer/util/InjectionUtils.java
267,6 → 267,7
 
try {
@SuppressWarnings("rawtypes")
Class k = (Class) targetType; // not sure how to avoid this raw type!
 
newValue = Enum.valueOf(k, value);