org.mentawai.ioc
Class DefaultComponent

java.lang.Object
  extended by org.mentawai.ioc.DefaultComponent
All Implemented Interfaces:
Bean
Direct Known Subclasses:
ScopeComponent

public class DefaultComponent
extends Object
implements Bean

The default implementation of a Mentawai IoC component. This component allows you to define constructor values and object properties.

Author:
Sergio Oliveira

Constructor Summary
DefaultComponent(Class<? extends Object> klass)
          Creates a new DefaultComponent for the given class.
DefaultComponent(Class<? extends Object> klass, List<Object> initValues)
          Creates a new DefaultComponent for the given class with the given init (constructor) values.
DefaultComponent(Class<? extends Object> klass, List<Object> initValues, Map<String,Object> props)
          Creates a new DefaultComponent for the given class with the given property map and the given init (constructor) values.
DefaultComponent(Class<? extends Object> klass, Map<String,Object> props)
          Creates a new DefaultComponent for the given class with the given property map.
 
Method Summary
 DefaultComponent addInitValue(Object value)
          Adds a new init value for this component.
 DefaultComponent addInitValues(List values)
          Adds the init values from the given list to this component's class.
 DefaultComponent addProperties(Map map)
          Adds the properties from the given map in this component.
 DefaultComponent addProperty(String name, Object value)
          Adds a property to be set in each new instance of this component's class.
 Object getBean()
          Returns an instance of the class this component represents.
 Class<? extends Object> getType()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultComponent

public DefaultComponent(Class<? extends Object> klass)
Creates a new DefaultComponent for the given class.

Parameters:
klass - The class used to create new instances.

DefaultComponent

public DefaultComponent(Class<? extends Object> klass,
                        List<Object> initValues)
Creates a new DefaultComponent for the given class with the given init (constructor) values. A constructor with the given init values will be called to instantiate the class.

Parameters:
klass - The class used to create new instances.
initValues - The values for the constructor.

DefaultComponent

public DefaultComponent(Class<? extends Object> klass,
                        Map<String,Object> props)
Creates a new DefaultComponent for the given class with the given property map. The properties will be injected in the instance with reflection.

Parameters:
klass - The class used to create new instances.
props - The properties that need to be injected in each instance.

DefaultComponent

public DefaultComponent(Class<? extends Object> klass,
                        List<Object> initValues,
                        Map<String,Object> props)
Creates a new DefaultComponent for the given class with the given property map and the given init (constructor) values. The properties will be injected in the instance with reflection. A constructor with the given init values will be called to instantiate the class.

Parameters:
klass - The class used to create new instances.
initValues - The values for the constructor.
props - The properties that need to be injected in each instance.
Method Detail

getType

public Class<? extends Object> getType()
Specified by:
getType in interface Bean

addProperty

public DefaultComponent addProperty(String name,
                                    Object value)
Adds a property to be set in each new instance of this component's class.

Parameters:
name - The name of the property or attribute.
value - The value of the property or attribute.
Returns:
This object

addProperties

public DefaultComponent addProperties(Map map)
Adds the properties from the given map in this component.

Parameters:
map - The properties to add in this component.
Returns:
This object

addInitValue

public DefaultComponent addInitValue(Object value)
Adds a new init value for this component. The init values are used to select a constructor for the component's class.

Parameters:
value - The init value to add to this component.
Returns:
This object

addInitValues

public DefaultComponent addInitValues(List values)
Adds the init values from the given list to this component's class. The init values are used to select a constructor for the component's class.

Parameters:
values - The init values to add to this component.
Returns:
This object

getBean

public Object getBean()
               throws InstantiationException
Description copied from interface: Bean
Returns an instance of the class this component represents.

Specified by:
getBean in interface Bean
Returns:
An instance of the class this component represents.
Throws:
InstantiationException - if for any reason the instance cannot be created.


Copyright © 2013. All Rights Reserved.