org.apache.fulcrum.factory
Interface FactoryService

All Known Implementing Classes:
DefaultFactoryService

public interface FactoryService

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 535465 2007-05-05 06:58:06Z tv $
Author:
Eric Pugh, Ilkka Priha

Field Summary
static String ROLE
          The key under which this component is known by an avalon container.
 
Method Summary
 Object getInstance(Class clazz)
          Gets an instance of a class.
 Object getInstance(String className)
          Gets an instance of a named class.
 Object getInstance(String className, ClassLoader loader)
          Gets an instance of a named class using a specified class loader.
 Object getInstance(String className, ClassLoader loader, Object[] params, String[] signature)
          Gets an instance of a named class using a specified class loader.
 Object getInstance(String className, Object[] params, String[] signature)
          Gets an instance of a named class.
 Class[] getSignature(Class clazz, Object[] params, String[] signature)
          Gets the signature classes for parameters of a method of a class.
 boolean isLoaderSupported(String className)
          Tests if specified class loaders are supported for a named class.
 

Field Detail

ROLE

static final String ROLE
The key under which this component is known by an avalon container.

Method Detail

getInstance

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

Parameters:
clazz - the name of the class.
Returns:
the instance.
Throws:
ServiceException - if instantiation fails.
FactoryException

getInstance

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

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

getInstance

Object getInstance(String className,
                   ClassLoader loader)
                   throws FactoryException
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:
ServiceException - if instantiation fails.
FactoryException

getInstance

Object getInstance(String className,
                   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:
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:
ServiceException - if instantiation fails.
FactoryException

getInstance

Object getInstance(String className,
                   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:
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:
ServiceException - if instantiation fails.
FactoryException

isLoaderSupported

boolean isLoaderSupported(String className)
                          throws FactoryException
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:
ServiceException - if test fails.
FactoryException

getSignature

Class[] getSignature(Class clazz,
                     Object[] params,
                     String[] signature)
                     throws 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:
ClassNotFoundException - if any of the classes is not found.


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