1 11 12 13 package com.sun.jmx.snmp; 14 15 16 import java.util.Vector ; 19 import java.util.Enumeration ; 20 import java.util.Hashtable ; 21 22 import com.sun.jmx.snmp.SnmpOidTable; 24 import com.sun.jmx.snmp.SnmpOidRecord; 25 import com.sun.jmx.snmp.SnmpStatusException; 26 27 import com.sun.jmx.trace.Trace; 30 31 47 48 public class SnmpOidTableSupport implements SnmpOidTable { 49 50 56 public SnmpOidTableSupport(String name) { 57 myName=name; 58 } 59 60 68 public SnmpOidRecord resolveVarName(String name) throws SnmpStatusException { 69 70 SnmpOidRecord var = (SnmpOidRecord)oidStore.get(name) ; 71 if (var != null) { 72 return var; 73 } else { 74 throw new SnmpStatusException("Variable name <" + name + "> not found in Oid repository") ; 75 } 76 } 77 78 86 public SnmpOidRecord resolveVarOid(String oid) throws SnmpStatusException { 87 88 int index = oid.indexOf('.') ; 91 if (index < 0) { 92 throw new SnmpStatusException("Variable oid <" + oid + "> not found in Oid repository") ; 93 } 94 if (index == 0) { 95 oid= oid.substring(1, oid.length()); 98 } 99 100 for(Enumeration list= oidStore.elements(); list.hasMoreElements(); ) { 103 SnmpOidRecord element= (SnmpOidRecord) list.nextElement(); 104 if (element.getOid().equals(oid)) 105 return element; 106 } 107 108 throw new SnmpStatusException("Variable oid <" + oid + "> not found in Oid repository") ; 109 } 110 111 115 public Vector getAllEntries() { 116 117 Vector elementsVector = new Vector (); 118 for (Enumeration e = oidStore.elements(); 120 e.hasMoreElements(); ) { 121 elementsVector.addElement(e.nextElement()); 122 } 123 return elementsVector ; 124 } 125 126 132 public synchronized void loadMib(SnmpOidRecord[] mibs) { 133 try { 134 for (int i = 0; ; i++) { 135 SnmpOidRecord s = mibs[i] ; 136 if (isTraceOn()) { 137 trace("loadMib", "load " + s.getName()); 138 } 139 oidStore.put(s.getName(), s) ; 140 } 141 } catch (ArrayIndexOutOfBoundsException e) { 142 } 143 } 144 145 151 public boolean equals(Object object) { 152 153 if (!(object instanceof SnmpOidTableSupport)) { 154 return false; 155 } 156 SnmpOidTableSupport val = (SnmpOidTableSupport) object; 157 return myName.equals(val.getName()); 158 } 159 160 164 public String getName() { 165 return myName; 166 } 167 172 173 176 boolean isTraceOn() { 177 return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_SNMP); 178 } 179 180 void trace(String clz, String func, String info) { 181 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_SNMP, clz, func, info); 182 } 183 184 void trace(String func, String info) { 185 trace(dbgTag, func, info); 186 } 187 188 boolean isDebugOn() { 189 return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_SNMP); 190 } 191 192 void debug(String clz, String func, String info) { 193 Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_SNMP, clz, func, info); 194 } 195 196 void debug(String func, String info) { 197 debug(dbgTag, func, info); 198 } 199 200 String dbgTag = "SnmpOidTableSupport"; 201 202 private Hashtable oidStore = new Hashtable () ; private String myName; 204 } 205 | Popular Tags |