View Javadoc

1   package org.apache.turbine.services.factory;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.turbine.util.TurbineException;
23  
24  /***
25   * Factory is an interface for object factories. Object factories
26   * can be registered with the Factory Service to support customized
27   * functionality during instantiation of specific classes that
28   * the service itself cannot provide. Examples include
29   * instantiation of XML parsers and secure sockets requiring
30   * provider specific initializations before instantiation.
31   *
32   * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
33   * @version $Id: Factory.java 534527 2007-05-02 16:10:59Z tv $
34   */
35  public interface Factory
36  {
37      /***
38       * Initializes the factory. This method is called by
39       * the Factory Service before the factory is used.
40       *
41       * @param className the name of the production class
42       * @throws TurbineException if initialization fails.
43       */
44      void init(String className)
45              throws TurbineException;
46  
47      /***
48       * Gets an instance of a class.
49       *
50       * @return the instance.
51       * @throws TurbineException if instantiation fails.
52       */
53      Object getInstance()
54              throws TurbineException;
55  
56      /***
57       * Gets an instance of a class using a specified class loader.
58       *
59       * <p>Class loaders are supported only if the isLoaderSupported
60       * method returns true. Otherwise the loader parameter is ignored.
61       *
62       * @param loader the class loader.
63       * @return the instance.
64       * @throws TurbineException if instantiation fails.
65       */
66      Object getInstance(ClassLoader loader)
67              throws TurbineException;
68  
69      /***
70       * Gets an instance of a named class.
71       * Parameters for its constructor are given as an array of objects,
72       * primitive types must be wrapped with a corresponding class.
73       *
74       * @param params an array containing the parameters of the constructor.
75       * @param signature an array containing the signature of the constructor.
76       * @return the instance.
77       * @throws TurbineException if instantiation fails.
78       */
79      Object getInstance(Object[] params,
80                         String[] signature)
81              throws TurbineException;
82  
83      /***
84       * Gets an instance of a named class using a specified class loader.
85       * Parameters for its constructor are given as an array of objects,
86       * primitive types must be wrapped with a corresponding class.
87       *
88       * <p>Class loaders are supported only if the isLoaderSupported
89       * method returns true. Otherwise the loader parameter is ignored.
90       *
91       * @param loader the class loader.
92       * @param params an array containing the parameters of the constructor.
93       * @param signature an array containing the signature of the constructor.
94       * @return the instance.
95       * @throws TurbineException if instantiation fails.
96       */
97      Object getInstance(ClassLoader loader,
98                         Object[] params,
99                         String[] signature)
100             throws TurbineException;
101 
102     /***
103      * Tests if this object factory supports specified class loaders.
104      *
105      * @return true if class loaders are supported, false otherwise.
106      */
107     boolean isLoaderSupported();
108 }