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 37 public class MBeanMultiAttributeMOInfo extends MBeanAttributeMOInfo { 38 39 public MBeanMultiAttributeMOInfo(ObjectName name, 40 CombinedTypedAttribute attributes) { 41 super(name, attributes); 42 } 43 44 public CombinedTypedAttribute getAttributes() { 45 return (CombinedTypedAttribute) super.getAttribute(); 46 } 47 48 public Object getAttribute(MBeanServerConnection server) throws ReflectionException, 49 InstanceNotFoundException, AttributeNotFoundException, MBeanException, 50 IOException { 51 return MBeanMultiAttributeMOInfo.getAttribute(server, getObjectName(), 52 getAttributes()); 53 } 54 55 public static Object getAttribute(MBeanServerConnection server, 56 ObjectName name, 57 CombinedTypedAttribute attributes) throws 58 ReflectionException, 59 InstanceNotFoundException, AttributeNotFoundException, MBeanException, 60 IOException 61 { 62 TypedAttribute[] attr = attributes.getAttributes(); 63 Object [] values = new Object [attr.length]; 64 for (int i=0; i<values.length; i++) { 65 values[i] = server.getAttribute(name, attr[i].getName()); 66 values[i] = attr[i].transformFromNative(values[i], name); 67 } 68 return attributes.transformFromNative(values, name); 69 } 70 71 72 public void setAttribute(MBeanServerConnection server, Object value) throws 73 ReflectionException, MBeanException, InvalidAttributeValueException, 74 AttributeNotFoundException, InstanceNotFoundException, IOException { 75 MBeanMultiAttributeMOInfo.setAttribute(server, getObjectName(), 76 getAttributes(), value); 77 } 78 79 public static void setAttribute(MBeanServerConnection server, 80 ObjectName name, 81 CombinedTypedAttribute attributes, 82 Object value) throws 83 ReflectionException, MBeanException, InvalidAttributeValueException, 84 AttributeNotFoundException, InstanceNotFoundException, IOException 85 { 86 TypedAttribute[] attr = attributes.getAttributes(); 87 Object [] values = new Object [attr.length]; 88 Object [] nativeValue; 89 if (attributes.isNativeValueAlwaysNeeded()) { 90 for (int i=0; i<values.length; i++) { 91 values[i] = server.getAttribute(name, attr[i].getName()); 92 } 93 nativeValue = (Object []) attributes.transformToNative(value, values, null); 94 } 95 else { 96 nativeValue = (Object []) attributes.transformToNative(value, null, null); 97 } 98 for (int i=0; (i<nativeValue.length) && (i<attr.length); i++) { 99 Object v = attr[i].transformToNative(nativeValue[i], values[i], null); 100 if (v != null) { 101 server.setAttribute(name, new Attribute(attr[i].getName(), v)); 102 } 103 } 104 } 105 } 106 | Popular Tags |