1 17 package org.apache.servicemix.jbi.management; 18 19 import javax.management.MBeanOperationInfo ; 20 import javax.management.MBeanParameterInfo ; 21 22 import java.lang.reflect.Method ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 26 31 public class OperationInfoHelper { 32 private List list = new ArrayList (); 33 34 42 public ParameterHelper addOperation(Object theObject, String name, String description) { 43 return addOperation(theObject, name, 0, description); 44 } 45 46 55 public ParameterHelper addOperation(Object theObject, String name, int numberParams, String description) { 56 Method method = getMethod(theObject.getClass(), name, numberParams); 57 MBeanOperationInfo opInfo = new MBeanOperationInfo (description, method); 58 list.add(opInfo); 59 MBeanParameterInfo [] result = opInfo.getSignature(); 60 return new ParameterHelper(result); 61 } 62 63 68 public MBeanOperationInfo [] getOperationInfos() { 69 MBeanOperationInfo [] result = new MBeanOperationInfo [list.size()]; 70 list.toArray(result); 71 return result; 72 } 73 74 77 public void clear() { 78 list.clear(); 79 } 80 81 88 public static MBeanOperationInfo [] join(MBeanOperationInfo [] ops1, MBeanOperationInfo [] ops2) { 89 MBeanOperationInfo [] result = null; 90 int length = 0; 91 int startPos = 0; 92 if (ops1 != null) { 93 length = ops1.length; 94 } 95 if (ops2 != null) { 96 length += ops2.length; 97 } 98 result = new MBeanOperationInfo [length]; 99 if (ops1 != null) { 100 System.arraycopy(ops1, 0, result, startPos, ops1.length); 101 startPos = ops1.length; 102 } 103 if (ops2 != null) { 104 System.arraycopy(ops2, 0, result, startPos, ops2.length); 105 } 106 return result; 107 } 108 109 private Method getMethod(Class theClass, String name, int numParams) { 110 Method result = null; 111 Method [] methods = theClass.getMethods(); 112 if (methods != null) { 113 for (int i = 0;i < methods.length;i++) { 114 if (methods[i].getName().equals(name) && methods[i].getParameterTypes().length == numParams) { 115 result = methods[i]; 116 break; 117 } 118 } 119 if (result == null){ 120 for (int i = 0;i < methods.length;i++) { 122 if (methods[i].getName().equals(name)) { 123 result = methods[i]; 124 break; 125 } 126 } 127 } 128 } 129 return result; 130 } 131 } | Popular Tags |