org.apache.turbine.services.factory
Interface FactoryService

All Superinterfaces:
Initable, Service
All Known Implementing Classes:
TurbineFactoryService

public interface FactoryService
extends Service

The Factory Service instantiates objects using either default class loaders or a specified one. Whether specified class loaders are supported for a class depends on implementation and can be tested with the isLoaderSupported method.

Version:
$Id: FactoryService.java 264148 2005-08-29 14:21:04Z henning $
Author:
Ilkka Priha

Field Summary
static java.lang.String SERVICE_NAME
          The key under which this service is stored in TurbineServices.
 
Method Summary
 java.lang.Object getInstance(java.lang.String className)
          Gets an instance of a named class.
 java.lang.Object getInstance(java.lang.String className, java.lang.ClassLoader loader)
          Gets an instance of a named class using a specified class loader.
 java.lang.Object getInstance(java.lang.String className, 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.String className, java.lang.Object[] params, java.lang.String[] signature)
          Gets an instance of a named class.
 java.lang.Class[] getSignature(java.lang.Class clazz, java.lang.Object[] params, java.lang.String[] signature)
          Gets the signature classes for parameters of a method of a class.
 boolean isLoaderSupported(java.lang.String className)
          Tests if specified class loaders are supported for a named class.
 
Methods inherited from interface org.apache.turbine.services.Service
getConfiguration, getName, getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, init, init, setInitableBroker, shutdown
 

Field Detail

SERVICE_NAME

public static final java.lang.String SERVICE_NAME
The key under which this service is stored in TurbineServices.

See Also:
Constant Field Values
Method Detail

getInstance

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

Parameters:
className - the name of the class.
Returns:
the instance.
Throws:
TurbineException - if instantiation fails.

getInstance

public java.lang.Object getInstance(java.lang.String className,
                                    java.lang.ClassLoader loader)
                             throws TurbineException
Gets an instance of a named class using a specified class loader.

Class loaders are supported only if the isLoaderSupported method returns true. Otherwise the loader parameter is ignored.

Parameters:
className - the name of the class.
loader - the class loader.
Returns:
the instance.
Throws:
TurbineException - if instantiation fails.

getInstance

public java.lang.Object getInstance(java.lang.String className,
                                    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:
className - the name of the class.
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.String className,
                                    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:
className - the name of the class.
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(java.lang.String className)
                          throws TurbineException
Tests if specified class loaders are supported for a named class.

Parameters:
className - the name of the class.
Returns:
true if class loaders are supported, false otherwise.
Throws:
TurbineException - if test fails.

getSignature

public java.lang.Class[] getSignature(java.lang.Class clazz,
                                      java.lang.Object[] params,
                                      java.lang.String[] signature)
                               throws java.lang.ClassNotFoundException
Gets the signature classes for parameters of a method of a class.

Parameters:
clazz - the class.
params - an array containing the parameters of the method.
signature - an array containing the signature of the method.
Returns:
an array of signature classes. Note that in some cases objects in the parameter array can be switched to the context of a different class loader.
Throws:
java.lang.ClassNotFoundException - if any of the classes is not found.


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