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 log.info("duplicate bean definition: " + annotationInfo.getBeanName());
55 }
56
57 annotationsInfoByName.put(annotationInfo.getBeanName(), annotationInfo);
58
59 ViewController viewController = annotationInfo.getViewController();
60 if (viewController != null)
61 {
62 String[] viewIds = viewController.viewIds();
63 for (int i = 0; i<viewIds.length; i++)
64 {
65 String viewId = viewIds[i];
66
67 if (annotationsInfoByViewId.containsKey(annotationInfo.getBeanName()))
68 {
69 log.info("duplicate viewId definition: " + annotationInfo.getBeanName());
70 }
71
72 annotationsInfoByViewId.put(viewId, annotationInfo);
73 }
74 }
75 }
76
77 public AnnotationInfo getAnnotationInfoByBeanName(String beanName)
78 {
79 return annotationsInfoByName.get(beanName);
80 }
81
82 public AnnotationInfo getAnnotationInfoByViewId(String viewId)
83 {
84 return annotationsInfoByViewId.get(viewId);
85 }
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 public void processBeanAnnotations(String beanName, Class<?> clazz)
102 {
103 ConversationName conversationName = (ConversationName) clazz.getAnnotation(ConversationName.class);
104 ViewController viewController = (ViewController) clazz.getAnnotation(ViewController.class);
105 ConversationRequire conversationRequire = (ConversationRequire) clazz.getAnnotation(ConversationRequire.class);
106
107 if (conversationName == null && viewController == null && conversationRequire == null)
108 {
109 return;
110 }
111
112 AnnotationInfo annotationInfo = new AnnotationInfo(beanName, clazz);
113 annotationInfo.setConversationName(conversationName);
114 annotationInfo.setConversationRequire(conversationRequire);
115
116 if (viewController != null)
117 {
118 annotationInfo.setViewController(viewController);
119 Method[] methods = clazz.getMethods();
120 for (int i = 0; i<methods.length; i++)
121 {
122 Method method = methods[i];
123 if (method.isAnnotationPresent(InitView.class))
124 {
125 annotationInfo.setInitViewMethod(method);
126 }
127 if (method.isAnnotationPresent(PreProcess.class))
128 {
129 annotationInfo.setPreProcessMethod(method);
130 }
131 if (method.isAnnotationPresent(PreRenderView.class))
132 {
133 annotationInfo.setPreRenderViewMethod(method);
134 }
135 }
136 }
137
138 addAnnotationsInfo(annotationInfo);
139 }
140 }