MentaContainer

Compare Revisions

Ignore whitespace Rev 95 → Rev 96

/trunk/src/main/java/org/mentacontainer/impl/ClassFactory.java
33,6 → 33,8
private Map<String, Method> cache = null;
private boolean useZeroArgumentConstructor = false;
public ClassFactory(Container container, Class<? extends Object> klass) {
this.container = container;
56,6 → 58,14
}
@Override
public ConfigurableFactory useZeroArgumentConstructor() {
this.useZeroArgumentConstructor = true;
return this;
}
@Override
public ConfigurableFactory addPropertyDependency(String property, String key) {
return addPropertyValue(property, new DependencyKey(key));
322,29 → 332,32
return (T) obj;
}
/*
private Constructor<? extends Object> findConstructor() {
private Constructor<? extends Object> findConstructor(List<Object> valuesToBeUsed) {
LinkedList<Class<? extends Object>> copy = new LinkedList<Class<? extends Object>>(initTypes);
LinkedList<Class<? extends Object>> providedInitTypes = new LinkedList<Class<? extends Object>>(initTypes);
LinkedList<Object> providedInitValues = new LinkedList<Object>(initValues);
Constructor<? extends Object>[] constructors = klass.getConstructors();
Constructor<? extends Object> found = null;
for(Constructor<? extends Object> c : constructors) {
Class<? extends Object>[] params = c.getParameterTypes();
Class<? extends Object>[] constructorParams = c.getParameterTypes();
if (params == null || params.length == 0) continue; // skip default constructor for now...
if (constructorParams == null || constructorParams.length == 0) continue; // skip default constructor for now...
for(Class<? extends Object> p : params) {
for(Class<? extends Object> constructorParam : constructorParams) {
// first see if it was given...
// first see if it was provided...
Class<? extends Object> given = copy.isEmpty() ? null : copy.get(0);
Class<? extends Object> provided = providedInitTypes.isEmpty() ? null : providedInitTypes.get(0);
if (p.equals(given)) {
if (provided != null && constructorParam.isAssignableFrom(provided)) {
providedInitTypes.removeFirst(); // we matched this one, so removed...
continue; // found param, let's check the other one...
} else {
353,8 → 366,9
}
}
}
return null;
}
*/
private static class DependencyKey {
/trunk/src/main/java/org/mentacontainer/ConfigurableFactory.java
22,6 → 22,10
public ConfigurableFactory addInitPrimitive(Object value);
public ConfigurableFactory addInitDependency(String key);
public ConfigurableFactory useZeroArgumentConstructor();
/**
* Add a property to be injected through a setter when the factory is instantiated.
*
31,7 → 35,5
*/
public ConfigurableFactory addPropertyValue(String name, Object value);
public ConfigurableFactory addInitDependency(String key);
public ConfigurableFactory addPropertyDependency(String property, String key);
}