1 package org.apache.turbine.services.factory;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }