MentaContainer

Compare Revisions

Ignore whitespace Rev 40 → Rev 39

/trunk/src/main/java/org/mentacontainer/impl/GenericComponent.java
28,17 → 28,20
}
}
public Object getInstance() {
public Object getInstance() throws InstantiationException {
try {
return method.invoke(factory, (Object[]) null);
} catch(Exception e) {
} catch(InvocationTargetException e) {
throw new RuntimeException("Cannot invoke method: " + method, e);
throw new InstantiationException("InvocationTargetException: " + method.getName() + " / " + e.getMessage());
}
} catch(IllegalAccessException e) {
throw new InstantiationException("IllegalAccessException: " + method.getName() + " / " + e.getMessage());
}
}
public Component addInitValue(Object value) {
/trunk/src/main/java/org/mentacontainer/impl/MentaComponent.java
118,7 → 118,7
/*
* Use reflection to set a property in the bean
*/
private void setValue(Object bean, String name, Object value) {
private void setValue(Object bean, String name, Object value) throws InstantiationException {
try {
178,7 → 178,7
} catch(Exception e) {
throw new RuntimeException("Error trying to set a property with reflection: " + name, e);
throw new InstantiationException("Error trying to set a property with reflection: " + name);
}
}
194,7 → 194,7
return null;
}
public Object getInstance() {
public Object getInstance() throws InstantiationException {
if (singleton && singletonValue != null) return singletonValue;
210,7 → 210,7
} catch(Exception e) {
throw new RuntimeException("Cannot find a constructor for class: " + klass, e);
throw new InstantiationException("Cannot find a constructor for class: " + klass);
}
}
220,7 → 220,7
} catch(Exception e) {
throw new RuntimeException("Cannot create instance from constructor: " + constructor, e);
throw new InstantiationException("Cannot create instance from constructor: " + constructor);
}
} else {
231,7 → 231,7
} catch(Exception e) {
throw new RuntimeException("Cannot create instance from class: " + klass, e);
throw new InstantiationException("Cannot create instance from class: " + klass);
}
}
/trunk/src/main/java/org/mentacontainer/impl/MentaContainer.java
146,7 → 146,7
return autowire(new MentaDependency(property, klass, source));
}
 
public Container populate(Object bean) {
public Container populate(Object bean) throws Exception {
Provider p = new Provider() {
161,15 → 161,8
}
};
try {
 
InjectionUtils.getObject(bean, p, false, null, true, false, true);
} catch(Exception e) {
throw new RuntimeException("Error populating bean: " + bean, e);
}
InjectionUtils.getObject(bean, p, false, null, true, false, true);
 
return this;
}
/trunk/src/main/java/org/mentacontainer/Component.java
12,8 → 12,9
* Instantiate the bean.
*
* @return The instantiated bean based on the container configuration.
* @throws InstantiationException
*/
public Object getInstance();
public Object getInstance() throws InstantiationException;
/**
* Add a constructor parameter to be used when the bean is instantiated. It can be called more than once to
/trunk/src/main/java/org/mentacontainer/Container.java
103,7 → 103,7
* @param bean The bean to be populated with other beans from the container.
* @return The container itself. (Fluent API)
*/
public Container populate(Object bean);
public Container populate(Object bean) throws Exception;
/**
* Check whether the container is configured to provide a bean with name 'key'.
/trunk/src/main/java/org/mentacontainer/example/BasicOperations.java
7,7 → 7,7
 
public class BasicOperations {
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
case1();
case2();
117,7 → 117,7
}
}
private static void case4() {
private static void case4() throws Exception {
Container c = new MentaContainer();