01: package org.apache.turbine.services.factory;
02:
03: /*
04: * Copyright 2001-2005 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License")
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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: * Initializes the factory. This method is called by
35: * the Factory Service before the factory is used.
36: *
37: * @param className the name of the production class
38: * @throws TurbineException if initialization fails.
39: */
40: void init(String className) throws TurbineException;
41:
42: /**
43: * Gets an instance of a class.
44: *
45: * @return the instance.
46: * @throws TurbineException if instantiation fails.
47: */
48: Object getInstance() throws TurbineException;
49:
50: /**
51: * Gets an instance of a class using a specified class loader.
52: *
53: * <p>Class loaders are supported only if the isLoaderSupported
54: * method returns true. Otherwise the loader parameter is ignored.
55: *
56: * @param loader the class loader.
57: * @return the instance.
58: * @throws TurbineException if instantiation fails.
59: */
60: Object getInstance(ClassLoader loader) throws TurbineException;
61:
62: /**
63: * Gets an instance of a named class.
64: * Parameters for its constructor are given as an array of objects,
65: * primitive types must be wrapped with a corresponding class.
66: *
67: * @param params an array containing the parameters of the constructor.
68: * @param signature an array containing the signature of the constructor.
69: * @return the instance.
70: * @throws TurbineException if instantiation fails.
71: */
72: Object getInstance(Object[] params, String[] signature)
73: throws TurbineException;
74:
75: /**
76: * Gets an instance of a named class using a specified class loader.
77: * Parameters for its constructor are given as an array of objects,
78: * primitive types must be wrapped with a corresponding class.
79: *
80: * <p>Class loaders are supported only if the isLoaderSupported
81: * method returns true. Otherwise the loader parameter is ignored.
82: *
83: * @param loader the class loader.
84: * @param params an array containing the parameters of the constructor.
85: * @param signature an array containing the signature of the constructor.
86: * @return the instance.
87: * @throws TurbineException if instantiation fails.
88: */
89: Object getInstance(ClassLoader loader, Object[] params,
90: String[] signature) throws TurbineException;
91:
92: /**
93: * Tests if this object factory supports specified class loaders.
94: *
95: * @return true if class loaders are supported, false otherwise.
96: */
97: boolean isLoaderSupported();
98: }
|