1 package org.sapia.soto.jmx; 2 3 import javax.management.Attribute ; 4 import javax.management.AttributeList ; 5 import javax.management.AttributeNotFoundException ; 6 import javax.management.DynamicMBean ; 7 import javax.management.InvalidAttributeValueException ; 8 import javax.management.MBeanException ; 9 import javax.management.MBeanInfo ; 10 import javax.management.ReflectionException ; 11 12 13 32 public class DynamicMBeanAdaptor implements DynamicMBean { 33 private MBeanDescriptor _desc; 34 35 40 public DynamicMBeanAdaptor(MBeanDescriptor desc) { 41 _desc = desc; 42 } 43 44 47 public Object getAttribute(String attribute) 48 throws AttributeNotFoundException , MBeanException , ReflectionException { 49 return _desc.getAttribute(attribute); 50 } 51 52 55 public AttributeList getAttributes(String [] names) { 56 AttributeList list = new AttributeList (); 57 58 for (int i = 0; i < names.length; i++) { 59 try { 60 list.add(new Attribute (names[i], _desc.getAttribute(names[i]))); 61 } catch (ReflectionException e) { 62 } catch (MBeanException e) { 64 } catch (AttributeNotFoundException e) { 66 } 68 } 69 70 return list; 71 } 72 73 76 public MBeanInfo getMBeanInfo() { 77 return _desc.getMBeanInfo(); 78 } 79 80 83 public Object invoke(String actionName, Object [] params, String [] sig) 84 throws MBeanException , ReflectionException { 85 return _desc.invoke(actionName, params, sig); 86 } 87 88 91 public void setAttribute(Attribute attr) 92 throws AttributeNotFoundException , InvalidAttributeValueException , 93 MBeanException , ReflectionException { 94 _desc.setAttribute(attr); 95 } 96 97 100 public AttributeList setAttributes(AttributeList attributes) { 101 AttributeList list = new AttributeList (); 102 Attribute attr; 103 104 for (int i = 0; i < attributes.size(); i++) { 105 try { 106 attr = (Attribute ) attributes.get(i); 107 _desc.setAttribute(attr); 108 list.add(new Attribute (attr.getName(), null)); 109 } catch (ReflectionException e) { 110 } catch (MBeanException e) { 112 } catch (AttributeNotFoundException e) { 114 } 116 } 117 118 return list; 119 } 120 } 121 | Popular Tags |