KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > factory > Factory


1 package org.apache.turbine.services.factory;
2
3 /*
4  * Copyright 2001-2004 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,v 1.5.2.2 2004/05/20 03:05:18 seade Exp $
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 JavaDoc 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 JavaDoc 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 JavaDoc getInstance(ClassLoader JavaDoc 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 JavaDoc getInstance(Object JavaDoc[] params,
77                        String JavaDoc[] 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 JavaDoc getInstance(ClassLoader JavaDoc loader,
95                        Object JavaDoc[] params,
96                        String JavaDoc[] 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 }
106
Popular Tags