KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > pool > TurbinePool


1 package org.apache.turbine.services.pool;
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.services.TurbineServices;
20 import org.apache.turbine.util.TurbineException;
21
22 /**
23  * This is a static accessor to common pooling tasks.
24  *
25  * @author <a HREF="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
26  * @version $Id: TurbinePool.java,v 1.4.2.2 2004/05/20 03:06:52 seade Exp $
27  */

28 public abstract class TurbinePool
29 {
30     /**
31      * Gets an instance of a named class either from the pool
32      * or by calling the Factory Service if the pool is empty.
33      *
34      * @param className the name of the class.
35      * @return the instance.
36      * @throws TurbineException if recycling fails.
37      */

38     public static Object JavaDoc getInstance(String JavaDoc className)
39             throws TurbineException
40     {
41         return getService().getInstance(className);
42     }
43
44     /**
45      * Gets an instance of a named class either from the pool
46      * or by calling the Factory Service if the pool is empty.
47      * The specified class loader will be passed to the Factory Service.
48      *
49      * @param className the name of the class.
50      * @param loader the class loader.
51      * @return the instance.
52      * @throws TurbineException if recycling fails.
53      */

54     public static Object JavaDoc getInstance(String JavaDoc className,
55                                      ClassLoader JavaDoc loader)
56             throws TurbineException
57     {
58         return getService().getInstance(className, loader);
59     }
60
61     /**
62      * Gets an instance of a named class either from the pool
63      * or by calling the Factory Service if the pool is empty.
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 className the name of the class.
68      * @param loader the class loader.
69      * @param params an array containing the parameters of the constructor.
70      * @param signature an array containing the signature of the constructor.
71      * @return the instance.
72      * @throws TurbineException if recycling fails.
73      */

74     public static Object JavaDoc getInstance(String JavaDoc className,
75                                      Object JavaDoc[] params,
76                                      String JavaDoc[] signature)
77             throws TurbineException
78     {
79         return getService().getInstance(className, params, signature);
80     }
81
82     /**
83      * Gets an instance of a named class either from the pool
84      * or by calling the Factory Service if the pool is empty.
85      * Parameters for its constructor are given as an array of objects,
86      * primitive types must be wrapped with a corresponding class.
87      * The specified class loader will be passed to the Factory Service.
88      *
89      * @param className the name of the class.
90      * @param loader the class loader.
91      * @param params an array containing the parameters of the constructor.
92      * @param signature an array containing the signature of the constructor.
93      * @return the instance.
94      * @throws TurbineException if recycling fails.
95      */

96     public static Object JavaDoc getInstance(String JavaDoc className,
97                                      ClassLoader JavaDoc loader,
98                                      Object JavaDoc[] params,
99                                      String JavaDoc[] signature)
100             throws TurbineException
101     {
102         return getService().getInstance(className, loader, params, signature);
103     }
104
105     /**
106      * Gets an instance of a specified class either from the pool
107      * or by instatiating from the class if the pool is empty.
108      *
109      * @param clazz the class.
110      * @return the instance.
111      * @throws TurbineException if recycling fails.
112      */

113     public static Object JavaDoc getInstance(Class JavaDoc clazz)
114             throws TurbineException
115     {
116         return getService().getInstance(clazz);
117     }
118
119     /**
120      * Gets an instance of a specified class either from the pool
121      * or by instatiating from the class if the pool is empty.
122      *
123      * @param clazz the class.
124      * @param params an array containing the parameters of the constructor.
125      * @param signature an array containing the signature of the constructor.
126      * @return the instance.
127      * @throws TurbineException if recycling fails.
128      */

129     public static Object JavaDoc getInstance(Class JavaDoc clazz,
130                                      Object JavaDoc params[],
131                                      String JavaDoc signature[])
132             throws TurbineException
133     {
134         return getService().getInstance(clazz, params, signature);
135     }
136
137     /**
138      * Puts a used object back to the pool. Objects implementing
139      * the Recyclable interface can provide a recycle method to
140      * be called when they are reused and a dispose method to be
141      * called when they are returned to the pool.
142      *
143      * @param instance the object instance to recycle.
144      * @return true if the instance was accepted.
145      */

146     public static boolean putInstance(Object JavaDoc instance)
147     {
148         return getService().putInstance(instance);
149     }
150
151     /**
152      * Gets the pool service implementation.
153      *
154      * @return the pool service implementation.
155      */

156     public static PoolService getService()
157     {
158         return (PoolService) TurbineServices.
159                 getInstance().getService(PoolService.SERVICE_NAME);
160     }
161 }
162
Popular Tags