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$
    Author:
    Eric Pugh, Ilkka Priha
    • Field Detail

      • ROLE

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

      • getInstance

        <T> T getInstance​(Class<T> clazz)
                   throws FactoryException
        Gets an instance of a class.
        Type Parameters:
        T - Type of the class
        Parameters:
        clazz - the name of the class.
        Returns:
        the instance.
        Throws:
        FactoryException - if instantiation fails.
      • getInstance

        <T> T getInstance​(String className)
                   throws FactoryException
        Gets an instance of a named class.
        Type Parameters:
        T - Type of the class
        Parameters:
        className - the name of the class.
        Returns:
        the instance.
        Throws:
        FactoryException - if instantiation fails.
      • getInstance

        <T> T 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.
        Type Parameters:
        T - Type of the class
        Parameters:
        className - the name of the class.
        loader - the class loader.
        Returns:
        the instance.
        Throws:
        FactoryException - if instantiation fails.
      • getInstance

        <T> T 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.
        Type Parameters:
        T - Type of the 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:
        FactoryException - if instantiation fails.
      • getInstance

        <T> T 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.
        Type Parameters:
        T - Type of the class
        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:
        FactoryException - if instantiation fails.
      • 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:
        FactoryException - if test fails.
      • 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.