org.apache.commons.collections
Class FactoryUtils
java.lang.Object
org.apache.commons.collections.FactoryUtils
public class FactoryUtils
extends java.lang.Object
FactoryUtils
provides reference implementations and utilities
for the Factory functor interface. The supplied factories are:
- Prototype - clones a specified object
- Reflection - creates objects using reflection
- Constant - always returns the same object
- Null - always returns null
- Exception - always throws an exception
All the supplied factories are Serializable.
$Revision: 1.14 $ $Date: 2004/04/14 21:47:47 $
static Factory | constantFactory(Object constantToReturn) - Creates a Factory that will return the same object each time the factory
is used.
|
static Factory | exceptionFactory() - Gets a Factory that always throws an exception.
|
static Factory | instantiateFactory(Class classToInstantiate) - Creates a Factory that can create objects of a specific type using
a no-args constructor.
|
static Factory | instantiateFactory(Class classToInstantiate, Class[] paramTypes, Object[] args) - Creates a Factory that can create objects of a specific type using
the arguments specified to this method.
|
static Factory | nullFactory() - Gets a Factory that will return null each time the factory is used.
|
static Factory | prototypeFactory(Object prototype) - Creates a Factory that will return a clone of the same prototype object
each time the factory is used.
|
FactoryUtils
public FactoryUtils()
This class is not normally instantiated.
constantFactory
public static Factory constantFactory(Object constantToReturn)
Creates a Factory that will return the same object each time the factory
is used. No check is made that the object is immutable. In general, only
immutable objects should use the constant factory. Mutable objects should
use the prototype factory.
constantToReturn
- the constant object to return each time in the factory
exceptionFactory
public static Factory exceptionFactory()
Gets a Factory that always throws an exception.
This could be useful during testing as a placeholder.
instantiateFactory
public static Factory instantiateFactory(Class classToInstantiate)
Creates a Factory that can create objects of a specific type using
a no-args constructor.
classToInstantiate
- the Class to instantiate each time in the factory
instantiateFactory
public static Factory instantiateFactory(Class classToInstantiate,
Class[] paramTypes,
Object[] args)
Creates a Factory that can create objects of a specific type using
the arguments specified to this method.
classToInstantiate
- the Class to instantiate each time in the factoryparamTypes
- parameter types for the constructor, can be nullargs
- the arguments to pass to the constructor, can be null
nullFactory
public static Factory nullFactory()
Gets a Factory that will return null each time the factory is used.
This could be useful during testing as a placeholder.
prototypeFactory
public static Factory prototypeFactory(Object prototype)
Creates a Factory that will return a clone of the same prototype object
each time the factory is used. The prototype will be cloned using one of these
techniques (in order):
- public clone method
- public copy constructor
- serialization clone
prototype
- the object to clone each time in the factory
Copyright © 2001-2006 Apache Software Foundation. All Rights Reserved.