/* * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package com.sun.jmx.snmp.agent; // java imports // import java.io.Serializable; import java.util.Vector; import java.util.Enumeration; // jmx imports // import com.sun.jmx.snmp.SnmpOid; import com.sun.jmx.snmp.SnmpValue; import com.sun.jmx.snmp.SnmpVarBind; import com.sun.jmx.snmp.SnmpStatusException; /** * Represents a node in an SNMP MIB which is neither a group nor a variable. * This class defines a list of sub-nodes and the methods that allow to * manipulate the sub-nodes. *
* This class is used internally and by the class generated by
* mibgen
.
* You should not need to use this class directly.
*
*
This API is a Sun Microsystems internal API and is subject * to change without notice.
*/ public class SnmpMibOid extends SnmpMibNode implements Serializable { private static final long serialVersionUID = 5012254771107446812L; /** * Default constructor. */ public SnmpMibOid() { } // PUBLIC METHODS //--------------- /** * Generic handling of theget
operation.
*
* This method should be overridden in subclasses. *
*
* @param req The sub-request that must be handled by this node.
*
* @param depth The depth reached in the OID tree.
*
* @exception SnmpStatusException The default implementation (if not
* overridden) is to generate a SnmpStatusException.
*/
public void get(SnmpMibSubRequest req, int depth)
throws SnmpStatusException {
for (Enumeration e= req.getElements(); e.hasMoreElements();) {
SnmpVarBind var= (SnmpVarBind) e.nextElement();
SnmpStatusException x =
new SnmpStatusException(SnmpStatusException.noSuchObject);
req.registerGetException(var,x);
}
}
/**
* Generic handling of the set
operation.
*
*
This method should be overridden in subclasses. *
*
* @param req The sub-request that must be handled by this node.
*
* @param depth The depth reached in the OID tree.
*
* @exception SnmpStatusException The default implementation (if not
* overridden) is to generate a SnmpStatusException.
*/
public void set(SnmpMibSubRequest req, int depth)
throws SnmpStatusException {
for (Enumeration e= req.getElements(); e.hasMoreElements();) {
SnmpVarBind var= (SnmpVarBind) e.nextElement();
SnmpStatusException x =
new SnmpStatusException(SnmpStatusException.noAccess);
req.registerSetException(var,x);
}
}
/**
* Generic handling of the check
operation.
*
*
This method should be overridden in subclasses. *
*
* @param req The sub-request that must be handled by this node.
*
* @param depth The depth reached in the OID tree.
*
* @exception SnmpStatusException The default implementation (if not
* overriden) is to generate a SnmpStatusException.
*/
public void check(SnmpMibSubRequest req, int depth)
throws SnmpStatusException {
for (Enumeration e= req.getElements(); e.hasMoreElements();) {
SnmpVarBind var= (SnmpVarBind) e.nextElement();
SnmpStatusException x =
new SnmpStatusException(SnmpStatusException.noAccess);
req.registerCheckException(var,x);
}
}
// ---------------------------------------------------------------------
//
// Implements the method defined in SnmpMibNode.
//
// ---------------------------------------------------------------------
//
void findHandlingNode(SnmpVarBind varbind,
long[] oid, int depth,
SnmpRequestTree handlers)
throws SnmpStatusException {
final int length = oid.length;
SnmpMibNode node = null;
if (handlers == null)
throw new SnmpStatusException(SnmpStatusException.snmpRspGenErr);
if (depth > length) {
// Nothing is left... the oid is not valid
throw noSuchObjectException;
} else if (depth == length) {
// The oid is not complete...
throw noSuchInstanceException;
} else {
// Some children variable or subobject is being querried
// getChild() will raise an exception if no child is found.
//
final SnmpMibNode child= getChild(oid[depth]);
// XXXX zzzz : what about null children?
// (variables for nested groups)
// if child==null, then we're dealing with a variable or
// a table: we register this node.
// This behaviour should be overriden in subclasses,
// in particular in group meta classes: the group
// meta classes that hold tables should take care
// of forwarding this call to all the tables involved.
//
if (child == null)
handlers.add(this,depth,varbind);
else
child.findHandlingNode(varbind,oid,depth+1,handlers);
}
}
// ---------------------------------------------------------------------
//
// Implements the method defined in SnmpMibNode.
//
// ---------------------------------------------------------------------
//
long[] findNextHandlingNode(SnmpVarBind varbind,
long[] oid, int pos, int depth,
SnmpRequestTree handlers,
AcmChecker checker)
throws SnmpStatusException {
final int length = oid.length;
SnmpMibNode node = null;
long[] result = null;
if (handlers == null)
// This should be considered as a genErr, but we do not want to
// abort the whole request, so we're going to throw
// a noSuchObject...
//
throw noSuchObjectException;
final Object data = handlers.getUserData();
final int pduVersion = handlers.getRequestPduVersion();
if (pos >= length) {
long[] newOid= new long[1];
newOid[0]= getNextVarId(-1,data,pduVersion);
result = findNextHandlingNode(varbind,newOid,0,depth,handlers,
checker);
return result;
}
// search the element specified in the oid
//
long[] newOid= new long[1];
long index= oid[pos];
while (true) {
try {
final SnmpMibNode child = getChild(index);
// SnmpOid result = null;
if (child == null) {
// shouldn't happen
throw noSuchObjectException;
// validateVarId(index);
// handlers.add(this,varbind,depth);
// result = new SnmpOid(0);
} else {
checker.add(depth, index);
try {
result = child.findNextHandlingNode(varbind,oid,pos+1,
depth+1,handlers,
checker);
} finally {
checker.remove(depth);
}
}
// Build up the leaf OID
result[depth] = index;
return result;
} catch(SnmpStatusException e) {
// If there is no such element go one level up ...
//
index= getNextVarId(index,data,pduVersion);
// There is no need to carry the original oid ...
newOid[0]=index;
pos= 1;
oid=newOid;
}
}
}
/**
* Computes the root OID of the MIB.
*/
public void getRootOid(Vector