1 22 23 package org.snmp4j.agent.mo.jmx; 24 25 import javax.management.ObjectName ; 26 import java.util.Iterator ; 27 import javax.management.MBeanServerConnection ; 28 import java.io.IOException ; 29 import javax.management.MBeanException ; 30 import javax.management.AttributeNotFoundException ; 31 import javax.management.InstanceNotFoundException ; 32 import javax.management.ReflectionException ; 33 import org.snmp4j.agent.mo.jmx.util.JMXArrayIndexKeyIterator; 34 import org.snmp4j.agent.mo.jmx.types.*; 35 import org.snmp4j.agent.mo.jmx.util.JMXArrayIndexKey; 36 import java.util.Collection ; 37 import java.util.List ; 38 39 46 public class MBeanArrayIndexKeyProvider extends MBeanAttributeKeyProvider { 47 48 62 public MBeanArrayIndexKeyProvider(ObjectName name, TypedAttribute attribute) { 63 super(name, attribute); 64 } 65 66 public Iterator keyIterator(MBeanServerConnection server) throws IOException , 67 MBeanException , AttributeNotFoundException , InstanceNotFoundException , 68 ReflectionException { 69 return new JMXArrayIndexKeyIterator(super.keyIterator(server)); 70 } 71 72 protected Iterator createTailIterator(Iterator it, int pos) { 73 return new JMXArrayIndexKeyIterator(it, pos); 74 } 75 76 97 public Object getRowValues(MBeanServerConnection server, 98 Object indexObject) throws IOException , 99 MBeanException , AttributeNotFoundException , InstanceNotFoundException , 100 ReflectionException 101 { 102 if (indexObject instanceof JMXArrayIndexKey) { 103 int index = ((JMXArrayIndexKey) indexObject).getIndex(); 104 Object keys = getAttribute(server); 105 if (keys instanceof List ) { 106 return ((List ) keys).get(index); 107 } 108 if (keys instanceof Object []) { 109 return ((Object []) keys)[index]; 110 } 111 else if (keys instanceof Collection ) { 112 Iterator it = ((Collection ) keys).iterator(); 113 for (int i = 0; (i < index) && (it.hasNext()); i++) { 114 it.next(); 115 } 116 if (it.hasNext()) { 117 return it.next(); 118 } 119 } 120 } 121 return indexObject; 122 } 123 124 } 125 | Popular Tags |