View Javadoc

1   package org.apache.turbine.services.intake;
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 java.beans.IntrospectionException;
23  
24  import java.lang.reflect.Method;
25  
26  import org.apache.turbine.services.TurbineServices;
27  import org.apache.turbine.services.intake.model.Group;
28  
29  /***
30   * This is a Facade class for IntakeService.
31   *
32   * This class provides static methods that call related methods of the
33   * implementation of the IntakeService used by the System, according to
34   * the settings in TurbineResources.
35   *
36   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
37   * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
38   * @version $Id: TurbineIntake.java 534527 2007-05-02 16:10:59Z tv $
39   */
40  public abstract class TurbineIntake
41  {
42      /***
43       * Gets an instance of a named group either from the pool
44       * or by calling the Factory Service if the pool is empty.
45       *
46       * @param groupName the name of the group.
47       * @return a Group instance.
48       * @throws IntakeException if recycling fails.
49       */
50      public static Group getGroup(String groupName)
51              throws IntakeException
52      {
53          if (groupName == null)
54          {
55              throw new IntakeException(
56                      "TurbineIntake.getGroup(groupName) is null");
57          }
58          return getService().getGroup(groupName);
59      }
60  
61      /***
62       * Puts a group back to the pool.
63       * @param instance the object instance to recycle.
64       * @throws IntakeException A non existant group was passed
65       */
66      public static void releaseGroup(Group instance)
67              throws IntakeException
68      {
69          getService().releaseGroup(instance);
70      }
71  
72      /***
73       * Gets the current size of the pool for a named group.
74       *
75       * @param groupName the name of the group.
76       * @return the current pool size
77       * @throws IntakeException A non existant group was passed
78       */
79      public static int getSize(String groupName)
80              throws IntakeException
81      {
82          return getService().getSize(groupName);
83      }
84  
85      /***
86       * Names of all the defined groups.
87       *
88       * @return array of names.
89       */
90      public static String[] getGroupNames()
91      {
92          return getService().getGroupNames();
93      }
94  
95      /***
96       * Gets the key (usually a short identifier) for a group.
97       *
98       * @param groupName the name of the group.
99       * @return the the key.
100      */
101     public static String getGroupKey(String groupName)
102     {
103         return getService().getGroupKey(groupName);
104     }
105 
106     /***
107      * Gets the group name given its key.
108      *
109      * @param groupKey the key.
110      * @return groupName the name of the group.
111      */
112     public static String getGroupName(String groupKey)
113     {
114         return getService().getGroupName(groupKey);
115     }
116 
117     /***
118      * Gets the Method that can be used to set a property.
119      *
120      * @param className the name of the object.
121      * @param propName the name of the property.
122      * @return the setter.
123      * @throws ClassNotFoundException
124      * @throws IntrospectionException
125      */
126     public static Method getFieldSetter(String className, String propName)
127             throws IntrospectionException, ClassNotFoundException
128     {
129         return getService().getFieldSetter(className, propName);
130     }
131 
132     /***
133      * Gets the Method that can be used to get a property value.
134      *
135      * @param className the name of the object.
136      * @param propName the name of the property.
137      * @return the getter.
138      * @throws ClassNotFoundException
139      * @throws IntrospectionException
140      */
141     public static Method getFieldGetter(String className, String propName)
142             throws IntrospectionException, ClassNotFoundException
143     {
144         return getService().getFieldGetter(className, propName);
145     }
146 
147     /***
148      * Utility method for accessing the service
149      * implementation
150      *
151      * @return a IntakeService implementation instance
152      */
153     private static IntakeService getService()
154     {
155         return (IntakeService) TurbineServices
156                 .getInstance().getService(IntakeService.SERVICE_NAME);
157     }
158 
159 }
160 
161 
162 
163 
164 
165 
166 
167 
168 
169