1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.orchestra.annotation;
20
21 import java.lang.reflect.Method;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.myfaces.orchestra.conversation.annotations.ConversationName;
28 import org.apache.myfaces.orchestra.conversation.annotations.ConversationRequire;
29 import org.apache.myfaces.orchestra.viewController.annotations.InitView;
30 import org.apache.myfaces.orchestra.viewController.annotations.PreProcess;
31 import org.apache.myfaces.orchestra.viewController.annotations.PreRenderView;
32 import org.apache.myfaces.orchestra.viewController.annotations.ViewController;
33
34
35
36
37
38
39
40
41
42
43 public class AnnotationInfoManager
44 {
45 private final Log log = LogFactory.getLog(AnnotationInfoManager.class);
46
47 private Map<String, AnnotationInfo> annotationsInfoByName = new HashMap<String, AnnotationInfo>();
48 private Map<String, AnnotationInfo> annotationsInfoByViewId = new HashMap<String, AnnotationInfo>();
49
50 protected void addAnnotationsInfo(AnnotationInfo annotationInfo)
51 {
52 if (annotationsInfoByName.containsKey(annotationInfo.getBeanName()))
53 {
54 if (log.isInfoEnabled())
55 {
56 log.info("duplicate bean definition: " + annotationInfo.getBeanName());
57 }
58 }
59
60 annotationsInfoByName.put(annotationInfo.getBeanName(), annotationInfo);
61
62 ViewController viewController = annotationInfo.getViewController();
63 if (viewController != null)
64 {
65 String[] viewIds = viewController.viewIds();
66 for (int i = 0; i<viewIds.length; i++)
67 {
68 String viewId = viewIds[i];
69
70 if (log.isInfoEnabled())
71 {
72 if (annotationsInfoByViewId.containsKey(annotationInfo.getBeanName()))
73 {
74 log.info("duplicate viewId definition: " + annotationInfo.getBeanName());
75 }
76 }
77
78 annotationsInfoByViewId.put(viewId, annotationInfo);
79 }
80 }
81 }
82
83 public AnnotationInfo getAnnotationInfoByBeanName(String beanName)
84 {
85 return annotationsInfoByName.get(beanName);
86 }
87
88 public AnnotationInfo getAnnotationInfoByViewId(String viewId)
89 {
90 return annotationsInfoByViewId.get(viewId);
91 }
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 public void processBeanAnnotations(String beanName, Class<?> clazz)
108 {
109 ConversationName conversationName = (ConversationName) clazz.getAnnotation(ConversationName.class);
110 ViewController viewController = (ViewController) clazz.getAnnotation(ViewController.class);
111 ConversationRequire conversationRequire = (ConversationRequire) clazz.getAnnotation(ConversationRequire.class);
112
113 if (conversationName == null && viewController == null && conversationRequire == null)
114 {
115 return;
116 }
117
118 AnnotationInfo annotationInfo = new AnnotationInfo(beanName, clazz);
119 annotationInfo.setConversationName(conversationName);
120 annotationInfo.setConversationRequire(conversationRequire);
121
122 if (viewController != null)
123 {
124 annotationInfo.setViewController(viewController);
125 Method[] methods = clazz.getMethods();
126 for (int i = 0; i<methods.length; i++)
127 {
128 Method method = methods[i];
129 if (method.isAnnotationPresent(InitView.class))
130 {
131 annotationInfo.setInitViewMethod(method);
132 }
133 if (method.isAnnotationPresent(PreProcess.class))
134 {
135 annotationInfo.setPreProcessMethod(method);
136 }
137 if (method.isAnnotationPresent(PreRenderView.class))
138 {
139 annotationInfo.setPreRenderViewMethod(method);
140 }
141 }
142 }
143
144 addAnnotationsInfo(annotationInfo);
145 }
146 }