1 6 7 package org.jfox.ioc.management; 8 9 import java.lang.reflect.Method ; 10 import java.util.HashMap ; 11 import java.util.Map ; 12 13 import org.jfox.ioc.ext.ManagableComponent; 14 import org.jfox.ioc.util.Annotations; 15 import org.jfox.ioc.util.Methods; 16 17 20 21 public class ManagementInfo { 22 23 26 private Map mangementOperationInfos = new HashMap (); 27 28 public ManagementOperationInfo getManagementOperationInfo(String 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 implementation){ 41 ManagementInfo managementInfo = new ManagementInfo(); 42 if(ManagableComponent.class.isAssignableFrom(implementation)){ 43 Method [] 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 clz) { 57 ManagementInfo managementInfo = new ManagementInfo(); 58 Method [] 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 .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 clz) { 72 ManagementInfo managementInfo = new ManagementInfo(); 73 Method [] 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 .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 clz) { 88 ManagementInfo managementInfo = new ManagementInfo(); 89 Method [] 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 .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 clz) { 104 ManagementInfo managementInfo = new ManagementInfo(); 105 Method [] 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 .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 [] args) { 120 121 } 122 } 123 124 | Popular Tags |