org.apache.turbine.services.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 264148 2005-08-29 14:21:04Z henning $
Author:
Ilkka Priha

Method Summary
 java.lang.Object getInstance()
          Gets an instance of a class.
 java.lang.Object getInstance(java.lang.ClassLoader loader)
          Gets an instance of a class using a specified class loader.
 java.lang.Object getInstance(java.lang.ClassLoader loader, java.lang.Object[] params, java.lang.String[] signature)
          Gets an instance of a named class using a specified class loader.
 java.lang.Object getInstance(java.lang.Object[] params, java.lang.String[] signature)
          Gets an instance of a named class.
 void init(java.lang.String className)
          Initializes the factory.
 boolean isLoaderSupported()
          Tests if this object factory supports specified class loaders.
 

Method Detail

init

public void init(java.lang.String className)
          throws TurbineException
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:
TurbineException - if initialization fails.

getInstance

public java.lang.Object getInstance()
                             throws TurbineException
Gets an instance of a class.

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

getInstance

public java.lang.Object getInstance(java.lang.ClassLoader loader)
                             throws TurbineException
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:
TurbineException - if instantiation fails.

getInstance

public java.lang.Object getInstance(java.lang.Object[] params,
                                    java.lang.String[] signature)
                             throws TurbineException
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:
TurbineException - if instantiation fails.

getInstance

public java.lang.Object getInstance(java.lang.ClassLoader loader,
                                    java.lang.Object[] params,
                                    java.lang.String[] signature)
                             throws TurbineException
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:
TurbineException - if instantiation fails.

isLoaderSupported

public boolean isLoaderSupported()
Tests if this object factory supports specified class loaders.

Returns:
true if class loaders are supported, false otherwise.


Copyright © 2000-2005 Apache Software Foundation. All Rights Reserved.