1 10 11 package com.sun.jmx.snmp.agent; 12 13 import java.io.Serializable ; 16 import java.util.Hashtable ; 17 import java.util.Enumeration ; 18 import java.util.Vector ; 19 20 import com.sun.jmx.snmp.SnmpOid; 23 import com.sun.jmx.snmp.SnmpValue; 24 import com.sun.jmx.snmp.SnmpVarBind; 25 import com.sun.jmx.snmp.SnmpStatusException; 26 27 import com.sun.jmx.snmp.agent.SnmpMibOid; 30 import com.sun.jmx.snmp.agent.SnmpMibNode; 31 32 46 47 public abstract class SnmpMibGroup extends SnmpMibOid 48 implements Serializable { 49 50 protected Hashtable subgroups = null; 55 56 63 public abstract boolean isTable(long arc); 64 65 73 public abstract boolean isVariable(long arc); 74 75 83 public abstract boolean isReadable(long arc); 84 85 86 94 public abstract SnmpMibTable getTable(long arc); 95 96 103 public void validateVarId(long arc, Object userData) 104 throws SnmpStatusException { 105 if (isVariable(arc) == false) 106 throw noSuchObjectException; 107 } 108 109 110 130 public boolean isNestedArc(long arc) { 131 if (subgroups == null) return false; 132 Object obj = subgroups.get(new Long (arc)); 133 return (obj != null); 136 } 137 138 164 abstract public void get(SnmpMibSubRequest req, int depth) 165 throws SnmpStatusException; 166 167 193 abstract public void set(SnmpMibSubRequest req, int depth) 194 throws SnmpStatusException; 195 196 224 abstract public void check(SnmpMibSubRequest req, int depth) 225 throws SnmpStatusException; 226 227 public void getRootOid(Vector result) { 232 return; 233 } 234 235 239 252 void registerNestedArc(long arc) { 253 Long obj = new Long (arc); 254 if (subgroups == null) subgroups = new Hashtable (); 255 subgroups.put(obj,obj); 257 } 258 259 275 protected void registerObject(long arc) 276 throws IllegalAccessException { 277 278 long[] oid = new long[1]; 284 oid[0] = arc; 285 super.registerNode(oid,0,null); 286 } 287 288 302 void registerNode(long[] oid, int cursor ,SnmpMibNode node) 303 throws IllegalAccessException { 304 super.registerNode(oid,cursor,node); 305 if (cursor < 0) return; 306 if (cursor >= oid.length) return; 307 registerNestedArc(oid[cursor]); 310 } 311 312 void findHandlingNode(SnmpVarBind varbind, 316 long[] oid, int depth, 317 SnmpRequestTree handlers) 318 throws SnmpStatusException { 319 320 int length = oid.length; 321 SnmpMibNode node = null; 322 323 if (handlers == null) 324 throw new SnmpStatusException(SnmpStatusException.snmpRspGenErr); 325 326 final Object data = handlers.getUserData(); 327 328 if (depth >= length) { 329 throw new SnmpStatusException(SnmpStatusException.noAccess); 331 } 332 333 long arc = oid[depth]; 334 335 if (isNestedArc(arc)) { 336 super.findHandlingNode(varbind,oid,depth,handlers); 339 return; 340 } else if (isTable(arc)) { 341 343 SnmpMibTable table = getTable(arc); 345 346 table.findHandlingNode(varbind,oid,depth+1,handlers); 348 349 } else { 350 validateVarId(arc, data); 352 353 if (depth+2 > length) 355 throw noSuchInstanceException; 356 357 if (depth+2 < length) 360 throw noSuchInstanceException; 361 362 if (oid[depth+1] != 0L) 364 throw noSuchInstanceException; 365 366 handlers.add(this,depth,varbind); 368 } 369 } 370 371 long[] findNextHandlingNode(SnmpVarBind varbind, 375 long[] oid, int pos, int depth, 376 SnmpRequestTree handlers, AcmChecker checker) 377 throws SnmpStatusException { 378 379 int length = oid.length; 380 SnmpMibNode node = null; 381 382 if (handlers == null) 383 throw noSuchObjectException; 388 389 final Object data = handlers.getUserData(); 390 final int pduVersion = handlers.getRequestPduVersion(); 391 392 393 if (pos >= length) 398 return super.findNextHandlingNode(varbind,oid,pos,depth, 399 handlers, checker); 400 401 long arc = oid[pos]; 403 404 long[] result = null; 405 406 try { 408 409 if (isTable(arc)) { 410 413 SnmpMibTable table = getTable(arc); 415 416 checker.add(depth, arc); 418 try { 419 result = table.findNextHandlingNode(varbind,oid,pos+1, 420 depth+1,handlers, 421 checker); 422 }catch(SnmpStatusException ex) { 423 throw noSuchObjectException; 424 } finally { 425 checker.remove(depth); 426 } 427 result[depth] = arc; 429 return result; 430 } else if (isReadable(arc)) { 431 433 if (pos == (length - 1)) { 434 437 result = new long[depth+2]; 441 result[depth+1] = 0L; 442 result[depth] = arc; 443 444 checker.add(depth, result, depth, 2); 445 try { 446 checker.checkCurrentOid(); 447 } catch(SnmpStatusException e) { 448 throw noSuchObjectException; 449 } finally { 450 checker.remove(depth,2); 451 } 452 453 handlers.add(this,depth,varbind); 455 return result; 456 } 457 458 467 } else if (isNestedArc(arc)) { 468 472 final SnmpMibNode child = getChild(arc); 475 476 if (child != null) { 477 checker.add(depth, arc); 478 try { 479 result = child.findNextHandlingNode(varbind,oid,pos+1, 480 depth+1,handlers, 481 checker); 482 result[depth] = arc; 483 return result; 484 } finally { 485 checker.remove(depth); 486 } 487 } 488 } 489 490 throw noSuchObjectException; 494 495 } catch (SnmpStatusException e) { 496 long[] newOid = new long[1]; 500 newOid[0] = getNextVarId(arc,data,pduVersion); 501 return findNextHandlingNode(varbind,newOid,0,depth, 502 handlers,checker); 503 } 504 } 505 506 } 507 | Popular Tags |