com.ail.core.factory
Class ClassFactory
java.lang.Object
com.ail.core.factory.AbstractFactory
com.ail.core.factory.ClassFactory
- Direct Known Subclasses:
- CachingClassFactory
public class ClassFactory
- extends AbstractFactory
This factory instantiates the class specified as it's key, and initialises the properties of the instance
based on the parameters nested in the types definition.
The following section of configuration shows how this factory can be used to create an instance of
Version and populate some of it's properties:
<configuration>
<builders>
<builder name="ClassBuilder" factory="com.ail.core.factory.ClassFactory"/>
</builders>
<types>
<type name="MyVersion" builder="ClassBuilder" key="com.ail.core.Version">
<parameter name="date">01/01/2005</parameter>
<parameter name="author">H.G.Wells</parameter>
<parameter name="comment">This coffee smells yellow</parameter>
</type>
</types>
</configuration>>
The example shows the factory itself being bound to a builder name (ClassBuilder). This
builder is then used to define the type MyVersion. When an instance of MyVersion
is requested, the class com.ail.core.Version will be instantiated, and the setters setDate, setAuthor,
and setComment are each invoked in turn and passed the value for corresponding parameter.
- Version:
- $Revision: 1.3 $
|
Method Summary |
java.lang.Object |
instantiateType(Type typeSpec)
Create an instance of an object. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ClassFactory
public ClassFactory()
instantiateType
public java.lang.Object instantiateType(Type typeSpec)
- Description copied from class:
AbstractFactory
- Create an instance of an object.
All concrete factories are required to implement this method. The
implementation should simply create an instance of the type specified
in the typeSpec argument. They should not attempt to process the
arguments (parameters) in the spec.
- Parameters:
typeSpec - Details of the type to be instantiated
- Returns:
- The instance of the created object