net.sf.japaki.basic
Class DefaultFactory<T>

java.lang.Object
  extended by net.sf.japaki.basic.DefaultFactory<T>
All Implemented Interfaces:
Factory<T>

public class DefaultFactory<T>
extends Object
implements Factory<T>

Provides a factory for classes with public default constructors. The implementation is based on reflection.


Constructor Summary
DefaultFactory()
           
DefaultFactory(Class<T> type)
          Creates a new factory for the given type.
 
Method Summary
 T create()
          Creates a new instance of type T.
static
<T> Factory<T>
newInstance(Class<T> type)
          Creates a new factory for the given type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFactory

public DefaultFactory(Class<T> type)
               throws InstantiationException,
                      IllegalAccessException
Creates a new factory for the given type.

Parameters:
type - a class with a public default constructor.
Throws:
NullPointerException - if type is null
InstantiationException - see Class.newInstance()
IllegalAccessException - see Class.newInstance()

DefaultFactory

public DefaultFactory()
Method Detail

newInstance

public static <T> Factory<T> newInstance(Class<T> type)
Creates a new factory for the given type.

Parameters:
type - a class with a public default constructor.
Throws:
NullPointerException - if type is null
RuntimeException - if the class could not be instatiated.

create

public T create()
Description copied from interface: Factory
Creates a new instance of type T.

Specified by:
create in interface Factory<T>
Returns:
the newly created instance