Package org.apache.fulcrum.factory
Interface Factory<T>
-
public interface Factory<T>
Factory is an interface for object factories. Object factories can be registered with the Factory Service to support customized functionality during instantiation of specific classes that the service itself cannot provide. Examples include instantiation of XML parsers and secure sockets requiring provider specific initializations before instantiation.- Version:
- $Id$
- Author:
- Ilkka Priha, Stephen McConnell
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description T
getInstance()
Gets an instance of a class.T
getInstance(ClassLoader loader)
Gets an instance of a class using a specified class loader.T
getInstance(ClassLoader loader, Object[] params, String[] signature)
Gets an instance of a named class using a specified class loader.T
getInstance(Object[] params, String[] signature)
Gets an instance of a named class.void
init(String className)
Initializes the factory.boolean
isLoaderSupported()
Tests if this object factory supports specified class loaders.
-
-
-
Method Detail
-
init
void init(String className) throws FactoryException
Initializes the factory. This method is called by the Factory Service before the factory is used.- Parameters:
className
- the name of the production class- Throws:
FactoryException
- if initialization fails.
-
getInstance
T getInstance() throws FactoryException
Gets an instance of a class.- Returns:
- the instance.
- Throws:
FactoryException
- if instantiation fails.
-
getInstance
T getInstance(ClassLoader loader) throws FactoryException
Gets an instance of a class using a specified class loader.Class loaders are supported only if the isLoaderSupported method returns true. Otherwise the loader parameter is ignored.
- Parameters:
loader
- the class loader.- Returns:
- the instance.
- Throws:
FactoryException
- if instantiation fails.
-
getInstance
T getInstance(Object[] params, String[] signature) throws FactoryException
Gets an instance of a named class. Parameters for its constructor are given as an array of objects, primitive types must be wrapped with a corresponding class.- Parameters:
params
- an array containing the parameters of the constructor.signature
- an array containing the signature of the constructor.- Returns:
- the instance.
- Throws:
FactoryException
- if instantiation fails.
-
getInstance
T getInstance(ClassLoader loader, Object[] params, String[] signature) throws FactoryException
Gets an instance of a named class using a specified class loader. Parameters for its constructor are given as an array of objects, primitive types must be wrapped with a corresponding class.Class loaders are supported only if the isLoaderSupported method returns true. Otherwise the loader parameter is ignored.
- Parameters:
loader
- the class loader.params
- an array containing the parameters of the constructor.signature
- an array containing the signature of the constructor.- Returns:
- the instance.
- Throws:
FactoryException
- if instantiation fails.
-
isLoaderSupported
boolean isLoaderSupported()
Tests if this object factory supports specified class loaders.- Returns:
- true if class loaders are supported, false otherwise.
-
-