org.apache.fulcrum.factory
Interface Factory


public interface Factory

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: Factory.java 535465 2007-05-05 06:58:06Z tv $
Author:
Ilkka Priha, Stephen McConnell

Method Summary
 Object getInstance()
          Gets an instance of a class.
 Object getInstance(ClassLoader loader)
          Gets an instance of a class using a specified class loader.
 Object getInstance(ClassLoader loader, Object[] params, String[] signature)
          Gets an instance of a named class using a specified class loader.
 Object 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

Object getInstance()
                   throws FactoryException
Gets an instance of a class.

Returns:
the instance.
Throws:
FactoryException - if instantiation fails.

getInstance

Object 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

Object 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

Object 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.


Copyright © 2005-2009 The Apache Software Foundation. All Rights Reserved.