001: package org.apache.turbine.services.intake;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.beans.IntrospectionException;
023:
024: import java.lang.reflect.Method;
025:
026: import org.apache.turbine.services.TurbineServices;
027: import org.apache.turbine.services.intake.model.Group;
028:
029: /**
030: * This is a Facade class for IntakeService.
031: *
032: * This class provides static methods that call related methods of the
033: * implementation of the IntakeService used by the System, according to
034: * the settings in TurbineResources.
035: *
036: * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
037: * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
038: * @version $Id: TurbineIntake.java 534527 2007-05-02 16:10:59Z tv $
039: */
040: public abstract class TurbineIntake {
041: /**
042: * Gets an instance of a named group either from the pool
043: * or by calling the Factory Service if the pool is empty.
044: *
045: * @param groupName the name of the group.
046: * @return a Group instance.
047: * @throws IntakeException if recycling fails.
048: */
049: public static Group getGroup(String groupName)
050: throws IntakeException {
051: if (groupName == null) {
052: throw new IntakeException(
053: "TurbineIntake.getGroup(groupName) is null");
054: }
055: return getService().getGroup(groupName);
056: }
057:
058: /**
059: * Puts a group back to the pool.
060: * @param instance the object instance to recycle.
061: * @throws IntakeException A non existant group was passed
062: */
063: public static void releaseGroup(Group instance)
064: throws IntakeException {
065: getService().releaseGroup(instance);
066: }
067:
068: /**
069: * Gets the current size of the pool for a named group.
070: *
071: * @param groupName the name of the group.
072: * @return the current pool size
073: * @throws IntakeException A non existant group was passed
074: */
075: public static int getSize(String groupName) throws IntakeException {
076: return getService().getSize(groupName);
077: }
078:
079: /**
080: * Names of all the defined groups.
081: *
082: * @return array of names.
083: */
084: public static String[] getGroupNames() {
085: return getService().getGroupNames();
086: }
087:
088: /**
089: * Gets the key (usually a short identifier) for a group.
090: *
091: * @param groupName the name of the group.
092: * @return the the key.
093: */
094: public static String getGroupKey(String groupName) {
095: return getService().getGroupKey(groupName);
096: }
097:
098: /**
099: * Gets the group name given its key.
100: *
101: * @param groupKey the key.
102: * @return groupName the name of the group.
103: */
104: public static String getGroupName(String groupKey) {
105: return getService().getGroupName(groupKey);
106: }
107:
108: /**
109: * Gets the Method that can be used to set a property.
110: *
111: * @param className the name of the object.
112: * @param propName the name of the property.
113: * @return the setter.
114: * @throws ClassNotFoundException
115: * @throws IntrospectionException
116: */
117: public static Method getFieldSetter(String className,
118: String propName) throws IntrospectionException,
119: ClassNotFoundException {
120: return getService().getFieldSetter(className, propName);
121: }
122:
123: /**
124: * Gets the Method that can be used to get a property value.
125: *
126: * @param className the name of the object.
127: * @param propName the name of the property.
128: * @return the getter.
129: * @throws ClassNotFoundException
130: * @throws IntrospectionException
131: */
132: public static Method getFieldGetter(String className,
133: String propName) throws IntrospectionException,
134: ClassNotFoundException {
135: return getService().getFieldGetter(className, propName);
136: }
137:
138: /**
139: * Utility method for accessing the service
140: * implementation
141: *
142: * @return a IntakeService implementation instance
143: */
144: private static IntakeService getService() {
145: return (IntakeService) TurbineServices.getInstance()
146: .getService(IntakeService.SERVICE_NAME);
147: }
148:
149: }
|