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.Collections;
19: import java.util.HashMap;
20: import java.util.Map;
21:
22: import org.strecks.controller.LookupDispatchActionController;
23: import org.strecks.controller.internal.ActionBeanAnnotationReader;
24: import org.strecks.dispatch.annotation.DispatchMethod;
25:
26: /**
27: * Implements <code>ActionBeanAnnotationReader</code> to handle lookup of key to method mappings
28: * @author Phil Zoio
29: */
30: public class DispatchMethodLookupReader implements
31: ActionBeanAnnotationReader<LookupDispatchActionController> {
32:
33: private Map<String, String> keyMethodMap = new HashMap<String, String>();
34:
35: public boolean readAnnotations(Class actionBeanClass) {
36:
37: Method[] methods = actionBeanClass.getMethods();
38:
39: boolean found = false;
40:
41: for (Method method : methods) {
42: DispatchMethod annotation = method
43: .getAnnotation(DispatchMethod.class);
44: if (annotation != null) {
45: String key = annotation.key();
46: String methodName = method.getName();
47: keyMethodMap.put(key, methodName);
48: found = true;
49: }
50: }
51:
52: return found;
53: }
54:
55: public void populateController(
56: LookupDispatchActionController controller) {
57: controller.setKeyMethodMap(Collections
58: .unmodifiableMap(keyMethodMap));
59: }
60:
61: Map<String, String> getKeyMethodMap() {
62: return keyMethodMap;
63: }
64:
65: void setKeyMethodMap(Map<String, String> keyMethodMap) {
66: this.keyMethodMap = keyMethodMap;
67: }
68:
69: }
|