MentaContainer

Compare Revisions

Ignore whitespace Rev 44 → Rev 45

/trunk/src/main/java/org/mentacontainer/impl/MentaComponent.java
8,7 → 8,7
import java.util.List;
import java.util.Map;
 
import org.mentacontainer.Component;
import org.mentacontainer.ConfigurableComponent;
import org.mentacontainer.util.FindMethod;
 
/**
16,7 → 16,7
*
* @author sergio.oliveira.jr@gmail.com
*/
public class MentaComponent implements Component {
public class MentaComponent implements ConfigurableComponent {
private final Class<? extends Object> klass;
46,7 → 46,7
public boolean isSingleton() { return singleton; }
public Component addProperty(String name, Object value) {
public ConfigurableComponent addProperty(String name, Object value) {
if (props == null) {
60,7 → 60,7
return this;
}
public Component addInitValue(Object value) {
public ConfigurableComponent addInitValue(Object value) {
if (initValues == null) {
/trunk/src/main/java/org/mentacontainer/impl/MentaContainer.java
7,6 → 7,7
import java.util.Set;
 
import org.mentacontainer.Component;
import org.mentacontainer.ConfigurableComponent;
import org.mentacontainer.Container;
import org.mentacontainer.Dependency;
import org.mentacontainer.util.InjectionUtils;
118,14 → 119,22
return component;
}
public Component ioc(String key, Class<? extends Object> klass) {
public ConfigurableComponent ioc(String key, Class<? extends Object> klass) {
return ioc(key, new MentaComponent(klass));
ConfigurableComponent cc = new MentaComponent(klass);
ioc(key, cc);
return cc;
}
public Component ioc(String key, Class<? extends Object> klass, boolean singleton) {
public ConfigurableComponent ioc(String key, Class<? extends Object> klass, boolean singleton) {
return ioc(key, new MentaComponent(klass, singleton));
ConfigurableComponent cc = new MentaComponent(klass, singleton);
ioc(key, cc);
return cc;
}
 
public Dependency autowire(Dependency d) {
/trunk/src/main/java/org/mentacontainer/Component.java
1,8 → 1,7
package org.mentacontainer;
 
/**
* An IoC component that knows how to create instances of itself and accepts init values for its constructor
* and properties to be injected through its setters.
* An IoC component that knows how to create instances of itself.
*
* @author sergio.oliveira.jr@gmail.com
*/
16,24 → 15,6
public <T> T getInstance();
/**
* Add a constructor parameter to be used when the bean is instantiated. It can be called more than once to
* use constructors with more than one argument.
*
* @param value A parameter value to be used by a constructor.
* @return The component itself. (Fluent API)
*/
public Component addInitValue(Object value);
/**
* Add a property to be injected through a setter when the component is instantiated.
*
* @param name The property name.
* @param value The property value.
* @return The component itself. (Fluent API)
*/
public Component addProperty(String name, Object value);
/**
* Is this component a singleton component, in other words,
* it always returns the same instance?
*
/trunk/src/main/java/org/mentacontainer/Container.java
35,9 → 35,9
* @param key The key representing the bean to return. The name of the bean in the container.
* @param klass The class used to instantiate the bean, in other words, its implementation.
* @param singleton A boolean to indicate if this bean will be a singleton.
* @return The component created. (Fluent API)
* @return The component created as a ConfigurableComponent. (Fluent API)
*/
public Component ioc(String key, Class<? extends Object> klass, boolean singleton);
public ConfigurableComponent ioc(String key, Class<? extends Object> klass, boolean singleton);
/**
* Same as {@link #ioc(String, Class, boolean)} except that it assumes
45,16 → 45,16
*
* @param key
* @param klass
* @return The component created. (Fluent API)
* @return The component created as a ConfigurableComponent. (Fluent API)
*/
public Component ioc(String key, Class<?extends Object> klass);
public ConfigurableComponent ioc(String key, Class<?extends Object> klass);
/**
* Set up IoC based on the component passed.
*
* @param key The key representing the bean to return. The name of the bean in the container.
* @param component The component for the IoC.
* @return The component passed as a parameter. (Fluent API)
* @return The component passed as a parameter.
* @see Component
*/
public Component ioc(String key, Component component);
/trunk/src/main/java/org/mentacontainer/ConfigurableComponent.java
New file
0,0 → 1,29
package org.mentacontainer;
 
/**
* An IoC component that knows how to create instances of itself and
* can be configured by accepting values for its constructor
* and properties for its setters.
*
* @author sergio.oliveira.jr@gmail.com
*/
public interface ConfigurableComponent extends Component {
/**
* Add a constructor parameter to be used when the bean is instantiated. It can be called more than once to
* use constructors with more than one argument.
*
* @param value A parameter value to be used by a constructor.
* @return The component itself. (Fluent API)
*/
public ConfigurableComponent addInitValue(Object value);
/**
* Add a property to be injected through a setter when the component is instantiated.
*
* @param name The property name.
* @param value The property value.
* @return The component itself. (Fluent API)
*/
public ConfigurableComponent addProperty(String name, Object value);
}