/*
* 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.Collections;
import java.util.HashMap;
import java.util.Map;
import org.strecks.controller.LookupDispatchActionController;
import org.strecks.controller.internal.ActionBeanAnnotationReader;
import org.strecks.dispatch.annotation.DispatchMethod;
/**
* Implements <code>ActionBeanAnnotationReader</code> to handle lookup of key to method mappings
* @author Phil Zoio
*/
public class DispatchMethodLookupReader implements ActionBeanAnnotationReader<LookupDispatchActionController>
{
private Map<String, String> keyMethodMap = new HashMap<String, String>();
public boolean readAnnotations(Class actionBeanClass)
{
Method[] methods = actionBeanClass.getMethods();
boolean found = false;
for (Method method : methods)
{
DispatchMethod annotation = method.getAnnotation(DispatchMethod.class);
if (annotation != null)
{
String key = annotation.key();
String methodName = method.getName();
keyMethodMap.put(key, methodName);
found = true;
}
}
return found;
}
public void populateController(LookupDispatchActionController controller)
{
controller.setKeyMethodMap(Collections.unmodifiableMap(keyMethodMap));
}
Map<String, String> getKeyMethodMap()
{
return keyMethodMap;
}
void setKeyMethodMap(Map<String, String> keyMethodMap)
{
this.keyMethodMap = keyMethodMap;
}
}