gov.sandia.cognition.factory
Class ConstructorBasedFactory<CreatedType>

java.lang.Object
  extended by gov.sandia.cognition.factory.ConstructorBasedFactory<CreatedType>
Type Parameters:
CreatedType - The type that the factory creates.
All Implemented Interfaces:
Factory<CreatedType>, Cloneable

@CodeReview(reviewer="Kevin R. Dixon",
            date="2008-12-02",
            changesNeeded=false,
            comments={"I just don\'t think this class will be useful.","However, the implementation is great... if anybody ever finds it useful."})
public class ConstructorBasedFactory<CreatedType>
extends Object
implements Factory<CreatedType>, Cloneable

The ConstructorBasedFactory class implements a Factory that takes a constructor and parameters to that constructor used to create new objects.

Since:
2.1
Author:
Justin Basilico

Field Summary
protected  Constructor<? extends CreatedType> constructor
          The constructor to use to create new objects.
protected  Object[] parameters
          The parameters to pass to the constructor.
 
Constructor Summary
ConstructorBasedFactory(Constructor<? extends CreatedType> constructor, Object... parameters)
          Creates a new ConstructorBasedFactory from the given constructor and parameters.
 
Method Summary
 ConstructorBasedFactory<CreatedType> clone()
           
 CreatedType create()
          Creates a new object by calling the constructor inside the factory with the parameters it is configured to take.
 Constructor<? extends CreatedType> getConstructor()
          Gets the constructor used to create new objects.
 Object[] getParameters()
          Gets the parameters that are passed to the constructor to create new objects.
 void setConstructor(Constructor<? extends CreatedType> constructor)
          Sets the constructor to use to create new objects.
 void setParameters(Object... parameters)
          Sets the parameters that are passed to the constructor to create new objects.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

constructor

protected Constructor<? extends CreatedType> constructor
The constructor to use to create new objects.


parameters

protected Object[] parameters
The parameters to pass to the constructor.

Constructor Detail

ConstructorBasedFactory

public ConstructorBasedFactory(Constructor<? extends CreatedType> constructor,
                               Object... parameters)
Creates a new ConstructorBasedFactory from the given constructor and parameters.

Parameters:
constructor - The constructor to use to create new objects.
parameters - The parameters to the constructor.
Method Detail

clone

public ConstructorBasedFactory<CreatedType> clone()
Overrides:
clone in class Object

create

public CreatedType create()
Creates a new object by calling the constructor inside the factory with the parameters it is configured to take.

Specified by:
create in interface Factory<CreatedType>
Returns:
A new object.

getConstructor

public Constructor<? extends CreatedType> getConstructor()
Gets the constructor used to create new objects.

Returns:
The constructor used to create new objects.

setConstructor

public void setConstructor(Constructor<? extends CreatedType> constructor)
Sets the constructor to use to create new objects.

Parameters:
constructor - The constructor used to create new objects. It cannot be null. The parameters on the factory must be set to match the parameter types the constructor expects before create is called.

getParameters

public Object[] getParameters()
Gets the parameters that are passed to the constructor to create new objects.

Returns:
The parameters that are passed to the constructor.

setParameters

public void setParameters(Object... parameters)
Sets the parameters that are passed to the constructor to create new objects.

Parameters:
parameters - The parameters to pass to the constructor.