1 17 package org.apache.servicemix.jbi.management; 18 19 import org.apache.commons.beanutils.PropertyUtilsBean; 20 21 import javax.management.IntrospectionException ; 22 import javax.management.MBeanAttributeInfo ; 23 import javax.management.ReflectionException ; 24 25 import java.beans.PropertyDescriptor ; 26 import java.lang.reflect.InvocationTargetException ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 35 public class AttributeInfoHelper { 36 private PropertyUtilsBean beanUtil = new PropertyUtilsBean(); 37 private List list = new ArrayList (); 38 39 48 public void addAttribute(Object theObject, String name, String description) throws ReflectionException { 49 PropertyDescriptor pd; 50 try { 51 pd = beanUtil.getPropertyDescriptor(theObject, name); 52 MBeanAttributeInfo info = new MBeanAttributeInfo (name, description, pd.getReadMethod(), pd.getWriteMethod()); 53 list.add(info); 54 } 55 catch(IntrospectionException e){ 56 throw new ReflectionException (e); 57 } 58 catch (IllegalAccessException e) { 59 throw new ReflectionException (e); 60 } 61 catch (InvocationTargetException e) { 62 throw new ReflectionException (e); 63 } 64 catch (NoSuchMethodException e) { 65 throw new ReflectionException (e); 66 } 67 68 69 } 70 71 76 public MBeanAttributeInfo [] getAttributeInfos() { 77 MBeanAttributeInfo [] result = new MBeanAttributeInfo [list.size()]; 78 list.toArray(result); 79 return result; 80 } 81 82 85 public void clear() { 86 list.clear(); 87 } 88 89 95 public static MBeanAttributeInfo [] join(MBeanAttributeInfo [] attrs1,MBeanAttributeInfo [] attrs2){ 96 MBeanAttributeInfo [] result = null; 97 int length = 0; 98 int startPos = 0; 99 if (attrs1 != null){ 100 length = attrs1.length; 101 } 102 if (attrs2 != null){ 103 length += attrs2.length; 104 } 105 106 result = new MBeanAttributeInfo [length]; 107 if (attrs1 != null){ 108 System.arraycopy(attrs1, 0, result, startPos, attrs1.length); 109 startPos = attrs1.length; 110 } 111 if(attrs2 != null){ 112 System.arraycopy(attrs2, 0, result, startPos, attrs2.length); 113 } 114 return result; 115 } 116 } | Popular Tags |