1 17 package org.apache.servicemix.jbi.management; 18 19 import org.apache.commons.beanutils.PropertyUtilsBean; 20 21 import javax.management.Attribute ; 22 import javax.management.MBeanAttributeInfo ; 23 import javax.management.MBeanException ; 24 25 import java.beans.PropertyDescriptor ; 26 import java.lang.reflect.InvocationTargetException ; 27 28 33 public class CachedAttribute { 34 private Object bean; 35 private String name; 36 private Attribute attribute; 37 private MBeanAttributeInfo attributeInfo; 38 private PropertyDescriptor propertyDescriptor; 39 40 45 public CachedAttribute(Attribute attr) { 46 this.attribute = attr; 47 this.name = attr.getName(); 48 } 49 50 53 public String getName() { 54 return name; 55 } 56 57 60 public void setName(String name) { 61 this.name = name; 62 } 63 64 67 public Attribute getAttribute() { 68 return attribute; 69 } 70 71 76 public void setAttribute(Attribute attribute) { 77 this.attribute = attribute; 78 } 79 80 86 public void updateValue(PropertyUtilsBean beanUtil) throws MBeanException { 87 try { 88 Object value = beanUtil.getProperty(bean, getName()); 89 if (value != attribute.getValue()) { 90 this.attribute = new Attribute (getName(), value); 91 } 92 } 93 catch (IllegalAccessException e) { 94 throw new MBeanException (e); 95 } 96 catch (InvocationTargetException e) { 97 throw new MBeanException (e); 98 } 99 catch (NoSuchMethodException e) { 100 throw new MBeanException (e); 101 } 102 } 103 104 113 public void updateAttribute(PropertyUtilsBean beanUtils, Attribute attribute) throws IllegalAccessException , 114 InvocationTargetException , NoSuchMethodException { 115 if (this.attribute != null && propertyDescriptor != null) { 116 beanUtils.setProperty(bean, getName(), attribute.getValue()); 118 } 119 this.attribute = attribute; 120 } 121 122 127 public void updateAttributeValue(Object value) { 128 this.attribute = new Attribute (this.attribute.getName(), value); 129 } 130 131 134 public Object getBean() { 135 return bean; 136 } 137 138 141 public void setBean(Object bean) { 142 this.bean = bean; 143 } 144 145 148 public PropertyDescriptor getPropertyDescriptor() { 149 return propertyDescriptor; 150 } 151 152 155 public void setPropertyDescriptor(PropertyDescriptor propertyDescriptor) { 156 this.propertyDescriptor = propertyDescriptor; 157 } 158 159 162 public MBeanAttributeInfo getAttributeInfo() { 163 return attributeInfo; 164 } 165 166 169 public void setAttributeInfo(MBeanAttributeInfo attributeInfo) { 170 this.attributeInfo = attributeInfo; 171 } 172 } | Popular Tags |