net.sf.collections15.functors.factory
Class InstantiateFactory<E>

java.lang.Object
  extended by net.sf.collections15.functors.factory.InstantiateFactory<E>
All Implemented Interfaces:
java.io.Serializable, Factory<E>

public class InstantiateFactory<E>
extends java.lang.Object
implements Factory<E>, java.io.Serializable

Factory implementation that creates a new object instance of a specified class using by reflection.

Since:
Collections15 1.0
Author:
Stephen Colebourne, Chris Lambrou (port to Java 5.0)
See Also:
Serialized Form

Constructor Summary
protected InstantiateFactory(java.lang.Class<? extends E> classToInstantiate, java.lang.Class[] paramTypes, java.lang.Object[] args)
          Constructs a new Factory that creates instances of the specified class, using the parameterless constructor of the class.
 
Method Summary
 E create()
          Creates an object using the stored constructor, parameter types and arguments.
static
<T> InstantiateFactory<T>
getInstance(java.lang.Class<? extends T> classToInstantiate)
          Creates a Factory that creates instances of the specified class, using the parameterless constructor of the class.
static
<T> Factory<T>
getInstance(java.lang.Class<? extends T> classToInstantiate, java.lang.Class[] paramTypes, java.lang.Object[] args)
          Creates a Factory that creates instances of the specified class, using the parameterless constructor of the class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InstantiateFactory

protected InstantiateFactory(java.lang.Class<? extends E> classToInstantiate,
                             java.lang.Class[] paramTypes,
                             java.lang.Object[] args)
Constructs a new Factory that creates instances of the specified class, using the parameterless constructor of the class.

Parameters:
classToInstantiate - The class that the InstantiateFactory should create instances of.
paramTypes - The types of the constructor parameters of the class to instantiate.
args - The arguments passed to the constructor used to instantiate the objects created by the Factory.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified class is null, or deosn't have a public constructor with the specified parameter types.
java.lang.IllegalArgumentException - Thrown if either the paramTypes or args arrays are null, are of unequal length, or are otherwise invalid.
Method Detail

getInstance

public static <T> Factory<T> getInstance(java.lang.Class<? extends T> classToInstantiate,
                                         java.lang.Class[] paramTypes,
                                         java.lang.Object[] args)
Creates a Factory that creates instances of the specified class, using the parameterless constructor of the class.

Parameters:
classToInstantiate - The class that the InstantiateFactory should create instances of.
paramTypes - The types of the constructor parameters of the class to instantiate.
args - The arguments passed to the constructor used to instantiate the objects created by the Factory.
Returns:
A Factory that creates instances of the specified class, using the constructor with the specified parameter types and values.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified class is null, or deosn't have a public constructor with the specified parameter types.
java.lang.IllegalArgumentException - Thrown if either the paramTypes or args arrays are null, are of unequal length, or are otherwise invalid.

getInstance

public static <T> InstantiateFactory<T> getInstance(java.lang.Class<? extends T> classToInstantiate)
Creates a Factory that creates instances of the specified class, using the parameterless constructor of the class.

Parameters:
classToInstantiate - The class that the InstantiateFactory should create instances of.
Returns:
A Factory that creates instances of the specified class, using its parameterless constructor.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified class is null, or deosn't have a public parameterless constructor.

create

public E create()
Creates an object using the stored constructor, parameter types and arguments.

Specified by:
create in interface Factory<E>
Returns:
A newly instantiated object.


Copyright © 2001-2005 SourceForge.net. All Rights Reserved.