View Javadoc

1   package org.apache.turbine.services.factory;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.apache.turbine.services.Service;
20  import org.apache.turbine.util.TurbineException;
21  
22  /***
23   * The Factory Service instantiates objects using either default
24   * class loaders or a specified one. Whether specified class
25   * loaders are supported for a class depends on implementation
26   * and can be tested with the isLoaderSupported method.
27   *
28   * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
29   * @version $Id: FactoryService.java 264148 2005-08-29 14:21:04Z henning $
30   */
31  public interface FactoryService
32          extends Service
33  {
34      /***
35       * The key under which this service is stored in TurbineServices.
36       */
37      String SERVICE_NAME = "FactoryService";
38  
39      /***
40       * Gets an instance of a named class.
41       *
42       * @param className the name of the class.
43       * @return the instance.
44       * @throws TurbineException if instantiation fails.
45       */
46      Object getInstance(String className)
47              throws TurbineException;
48  
49      /***
50       * Gets an instance of a named class using a specified class loader.
51       *
52       * <p>Class loaders are supported only if the isLoaderSupported
53       * method returns true. Otherwise the loader parameter is ignored.
54       *
55       * @param className the name of the class.
56       * @param loader the class loader.
57       * @return the instance.
58       * @throws TurbineException if instantiation fails.
59       */
60      Object getInstance(String className,
61              ClassLoader loader)
62              throws TurbineException;
63  
64      /***
65       * Gets an instance of a named class.
66       * Parameters for its constructor are given as an array of objects,
67       * primitive types must be wrapped with a corresponding class.
68       *
69       * @param className the name of the class.
70       * @param params an array containing the parameters of the constructor.
71       * @param signature an array containing the signature of the constructor.
72       * @return the instance.
73       * @throws TurbineException if instantiation fails.
74       */
75      Object getInstance(String className,
76              Object[] params,
77              String[] signature)
78              throws TurbineException;
79  
80      /***
81       * Gets an instance of a named class using a specified class loader.
82       * Parameters for its constructor are given as an array of objects,
83       * primitive types must be wrapped with a corresponding class.
84       *
85       * <p>Class loaders are supported only if the isLoaderSupported
86       * method returns true. Otherwise the loader parameter is ignored.
87       *
88       * @param className the name of the class.
89       * @param loader the class loader.
90       * @param params an array containing the parameters of the constructor.
91       * @param signature an array containing the signature of the constructor.
92       * @return the instance.
93       * @throws TurbineException if instantiation fails.
94       */
95      Object getInstance(String className,
96              ClassLoader loader,
97              Object[] params,
98              String[] signature)
99              throws TurbineException;
100 
101     /***
102      * Tests if specified class loaders are supported for a named class.
103      *
104      * @param className the name of the class.
105      * @return true if class loaders are supported, false otherwise.
106      * @throws TurbineException if test fails.
107      */
108     boolean isLoaderSupported(String className)
109             throws TurbineException;
110 
111     /***
112      * Gets the signature classes for parameters of a method of a class.
113      *
114      * @param clazz the class.
115      * @param params an array containing the parameters of the method.
116      * @param signature an array containing the signature of the method.
117      * @return an array of signature classes. Note that in some cases
118      * objects in the parameter array can be switched to the context
119      * of a different class loader.
120      * @throws ClassNotFoundException if any of the classes is not found.
121      */
122     Class[] getSignature(Class clazz,
123             Object params[],
124             String signature[])
125             throws ClassNotFoundException;
126 }