/*
* Copyright 2005-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.strecks.dispatch.internal;
import java.lang.reflect.Method;
import java.util.HashMap;
import org.apache.struts.action.ActionMapping;
import org.strecks.exceptions.ApplicationConfigurationException;
import org.strecks.util.ReflectHelper;
/**
* Class used internally by <code>BasicDispatchController</code> and <code>NavigableDispatchController</code> to
* store method name to method mappings, and other tasks
* @author Phil Zoio
*/
public class DispatchControllerHelper
{
/**
* The set of Method objects we have introspected for this class, keyed by method name. This collection is populated
* as different methods are called, so that introspection needs to occur only once per method name.
*/
protected HashMap<String, Method> methods = new HashMap<String, Method>();
public void checkParameterName(ActionMapping mapping, String parameterName)
{
if (parameterName == null)
{
throw new ApplicationConfigurationException(
"The element 'parameter' is required to determine the method name, and is required in required in path "
+ mapping.getPath());
}
}
public Method getMethod(Object actionBean, String methodName)
{
synchronized (methods)
{
Method method = methods.get(methodName);
if (method == null)
{
method = ReflectHelper.getMethod(actionBean, methodName);
methods.put(methodName, method);
}
return method;
}
}
}