KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > management > ManagementInfo


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.ioc.management;
8
9 import java.lang.reflect.Method JavaDoc;
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import org.jfox.ioc.ext.ManagableComponent;
14 import org.jfox.ioc.util.Annotations;
15 import org.jfox.ioc.util.Methods;
16
17 /**
18  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
19  */

20
21 public class ManagementInfo {
22
23     /**
24      * manangementOperationInfo hash => ManagementOperationInfo object
25      */

26     private Map JavaDoc mangementOperationInfos = new HashMap JavaDoc();
27
28     public ManagementOperationInfo getManagementOperationInfo(String JavaDoc hash) {
29         return (ManagementOperationInfo) mangementOperationInfos.get(hash);
30     }
31
32     public ManagementOperationInfo[] getAllManagementOperationInfos() {
33         return (ManagementOperationInfo[]) mangementOperationInfos.values().toArray(new ManagementOperationInfo[mangementOperationInfos.size()]);
34     }
35
36     public void addOperationInfo(ManagementOperationInfo operInfo) {
37         mangementOperationInfos.put(operInfo.getMethodHashCode(), operInfo);
38     }
39
40     public static ManagementInfo getManagementInfoByAnnotation(Class JavaDoc implementation){
41         ManagementInfo managementInfo = new ManagementInfo();
42         if(ManagableComponent.class.isAssignableFrom(implementation)){
43             Method JavaDoc[] methods = implementation.getMethods();
44             for(int i=0; i<methods.length; i++) {
45                 if(Annotations.isAnnotated(methods[i],org.jfox.ioc.annotation.Managable.class)) {
46                     managementInfo.addOperationInfo(new ManagementOperationInfo(methods[i]));
47                 }
48             }
49             return managementInfo;
50         }
51         else {
52             return null;
53         }
54     }
55
56     public static ManagementInfo exposePublic(Class JavaDoc clz) {
57         ManagementInfo managementInfo = new ManagementInfo();
58         Method JavaDoc[] methods = clz.getMethods();
59         for(int i = 0; i < methods.length; i++) {
60             if(!Methods.isAbstract(methods[i])
61                     && !Methods.isPrivate(methods[i])
62                     && !Methods.isStatic(methods[i])
63                     && !Methods.isDeclaredBy(methods[i], Object JavaDoc.class)
64                     && !Methods.isDeclaredBy(methods[i], ManagableComponent.class)
65             )
66                 managementInfo.addOperationInfo(new ManagementOperationInfo(methods[i]));
67         }
68         return managementInfo;
69     }
70
71     public static ManagementInfo exposeGet(Class JavaDoc clz) {
72         ManagementInfo managementInfo = new ManagementInfo();
73         Method JavaDoc[] methods = clz.getMethods();
74         for(int i = 0; i < methods.length; i++) {
75             if(!Methods.isAbstract(methods[i])
76                     && !Methods.isPrivate(methods[i])
77                     && !Methods.isStatic(methods[i])
78                     && !Methods.isDeclaredBy(methods[i], Object JavaDoc.class)
79                     && !Methods.isDeclaredBy(methods[i], ManagableComponent.class)
80                     && Methods.isGetMethod(methods[i])) {
81                 managementInfo.addOperationInfo(new ManagementOperationInfo(methods[i]));
82             }
83         }
84         return managementInfo;
85     }
86
87     public static ManagementInfo exposeSet(Class JavaDoc clz) {
88         ManagementInfo managementInfo = new ManagementInfo();
89         Method JavaDoc[] methods = clz.getMethods();
90         for(int i = 0; i < methods.length; i++) {
91             if(!Methods.isAbstract(methods[i])
92                     && !Methods.isPrivate(methods[i])
93                     && !Methods.isStatic(methods[i])
94                     && !Methods.isDeclaredBy(methods[i], Object JavaDoc.class)
95                     && !Methods.isDeclaredBy(methods[i], ManagableComponent.class)
96                     && Methods.isSetMethod(methods[i])) {
97                 managementInfo.addOperationInfo(new ManagementOperationInfo(methods[i]));
98             }
99         }
100         return managementInfo;
101     }
102
103     public static ManagementInfo exposeDeclaring(Class JavaDoc clz) {
104         ManagementInfo managementInfo = new ManagementInfo();
105         Method JavaDoc[] methods = clz.getDeclaredMethods();
106         for(int i = 0; i < methods.length; i++) {
107             if(!Methods.isAbstract(methods[i])
108                     && !Methods.isPrivate(methods[i])
109                     && !Methods.isStatic(methods[i])
110                     && !Methods.isDeclaredBy(methods[i], Object JavaDoc.class)
111                     && !Methods.isDeclaredBy(methods[i], ManagableComponent.class)
112             )
113                 managementInfo.addOperationInfo(new ManagementOperationInfo(methods[i]));
114         }
115         return managementInfo;
116
117     }
118
119     public static void main(String JavaDoc[] args) {
120
121     }
122 }
123
124
Popular Tags