MentaContainer

Compare Revisions

Regard whitespace Rev 3 → Rev 4

/trunk/src/main/java/org/mentacontainer/impl/MentaContainer.java
7,6 → 7,7
import java.util.Set;
 
import org.mentacontainer.Container;
import org.mentacontainer.util.InjectionUtils;
 
public class MentaContainer implements Container {
56,19 → 57,12
if (m != null) {
boolean hasAlreadyReceived = d.hasAlreadyReceived(target);
// has already received the dependency?
if (!hasAlreadyReceived) {
String sourceKey = d.getSource();
// get dependency from action input
if (sourceKey.equals(key)) {
// cannot depend on itself...
// also avoid recusive StackOverflow...
// also avoid recursive StackOverflow...
continue;
78,39 → 72,30
boolean isAssignable = source != null && d.getDependencyClass().isAssignableFrom(source.getClass());
// check if we can find the dependency and if it is assignable to the target dependency
// check if we can find the dependency and if it is
// assignable to the target dependency
if (isAssignable) {
try {
// inject
m.invoke(target, source);
// flag it has received
d.setAlreadyReceived(target);
} catch(Exception e) {
throw new RuntimeException("Cannot inject dependency: method = " + (m != null ? m.getName() : "NULL") + " / source = "
+ (source != null ? source : "NULL") + " / target = " + target, e);
throw new RuntimeException("AutoWiringFilter cannot inject dependency: method = " + (m != null ? m.getName() : "NULL") + " / source = " + (source != null ? source : "NULL") + " / target = " + target, e);
}
}
}
}
}
}
 
return target; // return target nicely with all the dependencies injected
return target; // return target nicely with all the dependencies
// injected
} catch(Exception e) {
throw new RuntimeException(e);
139,6 → 124,8
if (dependencies.contains(d)) throw new RuntimeException("Dependency is already set: " + property);
if (!klass.isInterface()) throw new RuntimeException("Dependency must be an interface!");
 
dependencies.add(d);
return this;
170,8 → 157,15
return this;
}
 
public Container populate(Object bean) {
// TODO Auto-generated method stub
return null;
public Container populate(Object bean) throws Exception {
 
InjectionUtils.getObject(bean, this, false, null, true, false, true);
return this;
}
public boolean contains(String key) {
return beans.containsKey(key);
}
}