1 22 23 package org.snmp4j.agent.mo.jmx; 24 25 import javax.management.*; 26 import java.io.IOException ; 27 import org.snmp4j.agent.mo.jmx.types.*; 28 29 35 public class MBeanAttributeMOInfo extends MBeanMOInfo { 36 37 protected TypedAttribute attribute; 38 39 48 public MBeanAttributeMOInfo(ObjectName name, String attributeName, 49 Class attributeType) { 50 super(name); 51 this.attribute = new TypedAttribute(attributeName, attributeType); 52 } 53 54 62 public MBeanAttributeMOInfo(ObjectName name, TypedAttribute attribute) { 63 super(name); 64 this.attribute = attribute; 65 } 66 67 public String getAttributeName() { 68 return attribute.getName(); 69 } 70 71 public Class getAttributeType() { 72 return attribute.getType(); 73 } 74 75 public TypedAttribute getAttribute() { 76 return attribute; 77 } 78 79 public Object getAttribute(MBeanServerConnection server) throws ReflectionException, 80 InstanceNotFoundException, AttributeNotFoundException, MBeanException, 81 IOException { 82 return getAttribute(server, getObjectName(), getAttribute()); 83 } 84 85 public static Object getAttribute(MBeanServerConnection server, 86 ObjectName name, 87 TypedAttribute attribute) throws 88 ReflectionException, 89 InstanceNotFoundException, AttributeNotFoundException, MBeanException, 90 IOException 91 { 92 Object nativeValue = server.getAttribute(name, attribute.getName()); 93 return attribute.transformFromNative(nativeValue, name); 94 } 95 96 97 public void setAttribute(MBeanServerConnection server, Object value) throws 98 ReflectionException, MBeanException, InvalidAttributeValueException, 99 AttributeNotFoundException, InstanceNotFoundException, IOException { 100 setAttribute(server, getObjectName(), getAttribute(), value); 101 } 102 103 public static void setAttribute(MBeanServerConnection server, 104 ObjectName name, 105 TypedAttribute attribute, 106 Object value) throws 107 ReflectionException, MBeanException, InvalidAttributeValueException, 108 AttributeNotFoundException, InstanceNotFoundException, IOException 109 { 110 Object nativeValue; 111 if (attribute.isNativeValueAlwaysNeeded()) { 112 nativeValue = 113 server.getAttribute(name, attribute.getName()); 114 nativeValue = attribute.transformToNative(value, nativeValue, name); 115 } 116 else { 117 nativeValue = attribute.transformToNative(value, null, name); 118 } 119 server.setAttribute(name, new Attribute(attribute.getName(), nativeValue)); 120 } 121 122 } 123 | Popular Tags |