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.util.TurbineException;
20  
21  /***
22   * Factory is an interface for object factories. Object factories
23   * can be registered with the Factory Service to support customized
24   * functionality during instantiation of specific classes that
25   * the service itself cannot provide. Examples include
26   * instantiation of XML parsers and secure sockets requiring
27   * provider specific initializations before instantiation.
28   *
29   * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
30   * @version $Id: Factory.java 264148 2005-08-29 14:21:04Z henning $
31   */
32  public interface Factory
33  {
34      /***
35       * Initializes the factory. This method is called by
36       * the Factory Service before the factory is used.
37       *
38       * @param className the name of the production class
39       * @throws TurbineException if initialization fails.
40       */
41      void init(String className)
42              throws TurbineException;
43  
44      /***
45       * Gets an instance of a class.
46       *
47       * @return the instance.
48       * @throws TurbineException if instantiation fails.
49       */
50      Object getInstance()
51              throws TurbineException;
52  
53      /***
54       * Gets an instance of a class using a specified class loader.
55       *
56       * <p>Class loaders are supported only if the isLoaderSupported
57       * method returns true. Otherwise the loader parameter is ignored.
58       *
59       * @param loader the class loader.
60       * @return the instance.
61       * @throws TurbineException if instantiation fails.
62       */
63      Object getInstance(ClassLoader loader)
64              throws TurbineException;
65  
66      /***
67       * Gets an instance of a named class.
68       * Parameters for its constructor are given as an array of objects,
69       * primitive types must be wrapped with a corresponding class.
70       *
71       * @param params an array containing the parameters of the constructor.
72       * @param signature an array containing the signature of the constructor.
73       * @return the instance.
74       * @throws TurbineException if instantiation fails.
75       */
76      Object getInstance(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 loader the class loader.
89       * @param params an array containing the parameters of the constructor.
90       * @param signature an array containing the signature of the constructor.
91       * @return the instance.
92       * @throws TurbineException if instantiation fails.
93       */
94      Object getInstance(ClassLoader loader,
95                         Object[] params,
96                         String[] signature)
97              throws TurbineException;
98  
99      /***
100      * Tests if this object factory supports specified class loaders.
101      *
102      * @return true if class loaders are supported, false otherwise.
103      */
104     boolean isLoaderSupported();
105 }