001 package org.apache.fulcrum.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 import java.lang.reflect.Method; 024 025 import org.apache.fulcrum.intake.model.Group; 026 027 /** 028 * This is a Facade class for IntakeService. 029 * 030 * This class provides static methods that call related methods of the 031 * implementation of the IntakeService used by the System, according to the 032 * settings in your intake.xml file. 033 * 034 * Note: How should a facade class work? It seems to me that maybe it should 035 * only have a hook into the Avalon Component Manager somehow? 036 * 037 * @author <a href="mailto:jmcnally@collab.net">John McNally</a> 038 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a> 039 * @version $Id: IntakeServiceFacade.java 832048 2009-11-02 18:55:08Z tv $ 040 */ 041 public class IntakeServiceFacade 042 { 043 /** Static instance of the intakeService. */ 044 045 private static IntakeService intakeService; 046 047 /** 048 * Return whether the intake service has been initialized. 049 * @return true if the service has been initialzed 050 */ 051 public static boolean isInitialized() 052 { 053 return (!(intakeService == null)); 054 } 055 056 /** 057 * Gets an instance of a named group either from the pool or by calling the 058 * Factory Service if the pool is empty. 059 * 060 * @param groupName 061 * the name of the group. 062 * @return a Group instance. 063 * @throws IntakeException 064 * if recycling fails. 065 */ 066 public static Group getGroup(String groupName) throws IntakeException 067 { 068 if (groupName == null) 069 { 070 throw new IntakeException("IntakeServiceFacade.getGroup(groupName) is null"); 071 } 072 return getService().getGroup(groupName); 073 } 074 075 /** 076 * Puts a group back to the pool. 077 * 078 * @param instance 079 * the object instance to recycle. 080 * @throws IntakeException 081 * A non existant group was passed 082 */ 083 public static void releaseGroup(Group instance) throws IntakeException 084 { 085 getService().releaseGroup(instance); 086 } 087 088 /** 089 * Gets the current size of the pool for a named group. 090 * 091 * @param groupName 092 * the name of the group. 093 * @return the current pool size 094 * @throws IntakeException 095 * A non existant group was passed 096 */ 097 public static int getSize(String groupName) throws IntakeException 098 { 099 return getService().getSize(groupName); 100 } 101 102 /** 103 * Names of all the defined groups. 104 * 105 * @return array of names. 106 */ 107 public static String[] getGroupNames() 108 { 109 return getService().getGroupNames(); 110 } 111 112 /** 113 * Gets the key (usually a short identifier) for a group. 114 * 115 * @param groupName 116 * the name of the group. 117 * @return the the key. 118 */ 119 public static String getGroupKey(String groupName) 120 { 121 return getService().getGroupKey(groupName); 122 } 123 124 /** 125 * Gets the group name given its key. 126 * 127 * @param groupKey 128 * the key. 129 * @return groupName the name of the group. 130 */ 131 public static String getGroupName(String groupKey) 132 { 133 return getService().getGroupName(groupKey); 134 } 135 136 /** 137 * Gets the Method that can be used to set a property. 138 * 139 * @param className 140 * the name of the object. 141 * @param propName 142 * the name of the property. 143 * @return the setter. 144 * @throws ClassNotFoundException 145 * @throws IntrospectionException 146 */ 147 public static Method getFieldSetter(String className, String propName) throws IntrospectionException, ClassNotFoundException 148 { 149 return getService().getFieldSetter(className, propName); 150 } 151 152 /** 153 * Gets the Method that can be used to get a property value. 154 * 155 * @param className 156 * the name of the object. 157 * @param propName 158 * the name of the property. 159 * @return the getter. 160 * @throws ClassNotFoundException 161 * @throws IntrospectionException 162 */ 163 public static Method getFieldGetter(String className, String propName) throws IntrospectionException, ClassNotFoundException 164 { 165 return getService().getFieldGetter(className, propName); 166 } 167 168 /** 169 * Utility method for accessing the service implementation 170 * 171 * @return a IntakeService implementation instance 172 */ 173 private static IntakeService getService() 174 { 175 return intakeService; 176 } 177 178 public static void setIntakeService(IntakeService service) 179 { 180 intakeService = service; 181 } 182 183 }