org.apache.turbine.services.factory
Class TurbineFactory

java.lang.Object
  extended byorg.apache.turbine.services.factory.TurbineFactory

public abstract class TurbineFactory
extends java.lang.Object

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: TurbineFactory.java 534527 2007-05-02 16:10:59Z tv $
Author:
Ilkka Priha, Henning P. Schmiedehausen

Constructor Summary
TurbineFactory()
           
 
Method Summary
static java.lang.Object getInstance(java.lang.String className)
          Gets an instance of a named class.
static java.lang.Object getInstance(java.lang.String className, java.lang.ClassLoader loader)
          Gets an instance of a named class using a specified class loader.
static 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.
static java.lang.Object getInstance(java.lang.String className, java.lang.Object[] params, java.lang.String[] signature)
          Gets an instance of a named class.
static FactoryService getService()
          Utility method for accessing the service implementation
static 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.
static boolean isLoaderSupported(java.lang.String className)
          Tests if specified class loaders are supported for a named class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TurbineFactory

public TurbineFactory()
Method Detail

getService

public static FactoryService getService()
Utility method for accessing the service implementation

Returns:
An AssemblerBroker implementation instance

getInstance

public static 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 static 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 static 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 static 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 static 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 static 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-2008 Apache Software Foundation. All Rights Reserved.