01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.dispatch.internal;
16:
17: import java.lang.reflect.Method;
18: import java.util.HashMap;
19:
20: import org.apache.struts.action.ActionMapping;
21: import org.strecks.exceptions.ApplicationConfigurationException;
22: import org.strecks.util.ReflectHelper;
23:
24: /**
25: * Class used internally by <code>BasicDispatchController</code> and <code>NavigableDispatchController</code> to
26: * store method name to method mappings, and other tasks
27: * @author Phil Zoio
28: */
29: public class DispatchControllerHelper {
30:
31: /**
32: * The set of Method objects we have introspected for this class, keyed by method name. This collection is populated
33: * as different methods are called, so that introspection needs to occur only once per method name.
34: */
35: protected HashMap<String, Method> methods = new HashMap<String, Method>();
36:
37: public void checkParameterName(ActionMapping mapping,
38: String parameterName) {
39: if (parameterName == null) {
40: throw new ApplicationConfigurationException(
41: "The element 'parameter' is required to determine the method name, and is required in required in path "
42: + mapping.getPath());
43: }
44: }
45:
46: public Method getMethod(Object actionBean, String methodName) {
47: synchronized (methods) {
48: Method method = methods.get(methodName);
49: if (method == null) {
50: method = ReflectHelper
51: .getMethod(actionBean, methodName);
52: methods.put(methodName, method);
53: }
54: return method;
55: }
56: }
57: }
|