SnmpMibGroup.java revision 0
0N/A * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Sun in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A// SNMP Runtime imports 0N/A * Represents a node in an SNMP MIB which corresponds to a group. 0N/A * This class allows subnodes to be registered below a group, providing 0N/A * support for nested groups. The subnodes are registered at run time 0N/A * when registering the nested groups in the global MIB OID tree. 0N/A * This class is used by the class generated by <CODE>mibgen</CODE>. 0N/A * You should not need to use this class directly. 0N/A * <p><b>This API is a Sun Microsystems internal API and is subject 0N/A * to change without notice.</b></p> 0N/A // We will register the OID arcs leading to subgroups in this hashtable. 0N/A // So for each arc in varList, if the arc is also in subgroups, it leads 0N/A // to a subgroup, if it is not in subgroup, it leads either to a table 0N/A // or to a variable. 0N/A * Tells whether the given arc identifies a table in this group. 0N/A * @param arc An OID arc. 0N/A * @return <CODE>true</CODE> if `arc' leads to a table. 0N/A * Tells whether the given arc identifies a variable (scalar object) in 0N/A * @param arc An OID arc. 0N/A * @return <CODE>true</CODE> if `arc' leads to a variable. 0N/A * Tells whether the given arc identifies a readable scalar object in 0N/A * @param arc An OID arc. 0N/A * @return <CODE>true</CODE> if `arc' leads to a readable variable. 0N/A * Gets the table identified by the given `arc'. 0N/A * @param arc An OID arc. 0N/A * @return The <CODE>SnmpMibTable</CODE> identified by `arc', or 0N/A * <CODE>null</CODE> if `arc' does not identify any table. 0N/A * Checks whether the given OID arc identifies a variable (scalar 0N/A * @exception If the given `arc' does not identify any variable in this 0N/A * group, throws an SnmpStatusException. 0N/A // ------------------------------------------------------------------- 0N/A // We use a hashtable (subgroup) in order to determine whether an 0N/A // OID arc leads to a subgroup. This implementation can be changed if 0N/A // For instance, the subclass could provide a generated isNestedArc() 0N/A // method in which the subgroup OID arcs would be hardcoded. 0N/A // However, the generic approach was prefered because at this time 0N/A // groups and subgroups are dynamically registered in the MIB. 0N/A * Tell whether the given OID arc identifies a sub-tree 0N/A * leading to a nested SNMP sub-group. This method is used internally. 0N/A * You shouldn't need to call it directly. 0N/A * @param arc An OID arc. 0N/A * @return <CODE>true</CODE> if the given OID arc identifies a subtree 0N/A * leading to a nested SNMP sub-group. 0N/A // if the arc is registered in the hashtable, 0N/A // it leads to a subgroup. 0N/A * Generic handling of the <CODE>get</CODE> operation. 0N/A * <p>The actual implementation of this method will be generated 0N/A * by mibgen. Usually, this implementation only delegates the 0N/A * job to some other provided runtime class, which knows how to 0N/A * access the MBean. The current toolkit thus provides two 0N/A * <ul><li>The standard implementation will directly access the 0N/A * MBean through a java reference,</li> 0N/A * <li>The generic implementation will access the MBean through 0N/A * the MBean server.</li> 0N/A * <p>Both implementations rely upon specific - and distinct, set of 0N/A * mibgen generated methods. 0N/A * <p> You can override this method if you need to implement some 0N/A * specific policies for minimizing the accesses made to some remote 0N/A * underlying resources. 0N/A * @param req The sub-request that must be handled by this node. 0N/A * @param depth The depth reached in the OID tree. 0N/A * @exception SnmpStatusException An error occurred while accessing 0N/A * Generic handling of the <CODE>set</CODE> operation. 0N/A * <p>The actual implementation of this method will be generated 0N/A * by mibgen. Usually, this implementation only delegates the 0N/A * job to some other provided runtime class, which knows how to 0N/A * access the MBean. The current toolkit thus provides two 0N/A * <ul><li>The standard implementation will directly access the 0N/A * MBean through a java reference,</li> 0N/A * <li>The generic implementation will access the MBean through 0N/A * the MBean server.</li> 0N/A * <p>Both implementations rely upon specific - and distinct, set of 0N/A * mibgen generated methods. 0N/A * <p> You can override this method if you need to implement some 0N/A * specific policies for minimizing the accesses made to some remote 0N/A * underlying resources. 0N/A * @param req The sub-request that must be handled by this node. 0N/A * @param depth The depth reached in the OID tree. 0N/A * @exception SnmpStatusException An error occurred while accessing 0N/A * Generic handling of the <CODE>check</CODE> operation. 0N/A * <p>The actual implementation of this method will be generated 0N/A * by mibgen. Usually, this implementation only delegates the 0N/A * job to some other provided runtime class, which knows how to 0N/A * access the MBean. The current toolkit thus provides two 0N/A * <ul><li>The standard implementation will directly access the 0N/A * MBean through a java reference,</li> 0N/A * <li>The generic implementation will access the MBean through 0N/A * the MBean server.</li> 0N/A * <p>Both implementations rely upon specific - and distinct, set of 0N/A * mibgen generated methods. 0N/A * <p> You can override this method if you need to implement some 0N/A * specific policies for minimizing the accesses made to some remote 0N/A * underlying resources, or if you need to implement some consistency 0N/A * checks between the different values provided in the varbind list. 0N/A * @param req The sub-request that must be handled by this node. 0N/A * @param depth The depth reached in the OID tree. 0N/A * @exception SnmpStatusException An error occurred while accessing 0N/A // -------------------------------------------------------------------- 0N/A // If we reach this node, we are below the root OID, so we just 0N/A // -------------------------------------------------------------------- 0N/A // ------------------------------------------------------------------- 0N/A // ------------------------------------------------------------------- 0N/A // ------------------------------------------------------------------- 0N/A // This method can also be overriden in a subclass to provide a 0N/A // different implementation of the isNestedArc() method. 0N/A // => if isNestedArc() is hardcoded, then registerSubArc() becomes 0N/A // useless and can become empty. 0N/A * Register an OID arc that identifies a sub-tree 0N/A * leading to a nested SNMP sub-group. This method is used internally. 0N/A * You shouldn't ever call it directly. 0N/A * @param arc An OID arc. 0N/A // registers the arc in the hashtable. 0N/A // ------------------------------------------------------------------- 0N/A // The SnmpMibOid algorithm relies on the fact that for every arc 0N/A // registered in varList, there is a corresponding node at the same 0N/A // position in children. 0N/A // So the trick is to register a null node in children for each variable 0N/A // in varList, so that the real subgroup nodes can be inserted at the 0N/A // correct location. 0N/A // registerObject() should be called for each scalar object and each 0N/A // table arc by the generated subclass. 0N/A * Register an OID arc that identifies a scalar object or a table. 0N/A * This method is used internally. You shouldn't ever call it directly. 0N/A * @param arc An OID arc. 0N/A // this will register the variable in both varList and children 0N/A // The node registered in children will be null, so that the parent 0N/A // algorithm will behave as if no node were registered. This is a 0N/A // trick that makes the parent algorithm behave as if only subgroups 0N/A // were registered in varList and children. 0N/A // ------------------------------------------------------------------- 0N/A // registerNode() will be called at runtime when nested groups are 0N/A // registered in the MIB. So we do know that this method will only 0N/A // be called to register nested-groups. 0N/A // We trap registerNode() in order to call registerSubArc() 0N/A * Register a child node of this node in the OID tree. 0N/A * This method is used internally. You shouldn't ever call it directly. 0N/A * @param oid The oid of the node being registered. 0N/A * @param cursor The position reached in the oid. 0N/A * @param node The node being registered. 0N/A // if we get here, then it means we are registering a subgroup. 0N/A // We will thus register the sub arc in the subgroups hashtable. 0N/A // ------------------------------------------------------------------- 0N/A // see comments in SnmpMibNode 0N/A // ------------------------------------------------------------------- 0N/A // Nothing is left... the oid is not valid 0N/A // This arc leads to a subgroup: delegates the search to the 0N/A // method defined in SnmpMibOid 0N/A // This arc leads to a table: forward the search to the table. 0N/A // Forward the search to the table 0N/A // If it's not a variable, throws an exception 0N/A // The trailing .0 is missing in the OID 0N/A // There are too many arcs left in the OID (there should remain 0N/A // a single trailing .0) 0N/A // The last trailing arc is not .0 0N/A // It's one of our variable, register this node. 0N/A // ------------------------------------------------------------------- 0N/A // See comments in SnmpMibNode. 0N/A // ------------------------------------------------------------------- 0N/A // This should be considered as a genErr, but we do not want to 0N/A // abort the whole request, so we're going to throw 0N/A // a noSuchObject... 0N/A // The generic case where the end of the OID has been reached is 0N/A // handled in the superclass 0N/A // XXX Revisit: this works but it is somewhat convoluted. Just setting 0N/A // arc to -1 would work too. 0N/A // Ok, we've got the arc. 0N/A // We have a recursive logic. Should we have a loop instead? 0N/A // If the arc identifies a table, then we need to forward 0N/A // the search to the table. 0N/A // Gets the table identified by `arc' 0N/A // Forward to the table 0N/A // Build up the leaf OID 0N/A // If the arc identifies a readable variable, then two cases: 0N/A // The end of the OID is reached, so we return the leaf 0N/A // corresponding to the variable identified by `arc' 0N/A // result = new SnmpOid(0); 0N/A // result.insert((int)arc); 0N/A // Registers this node 0N/A // The end of the OID is not yet reached, so we must return 0N/A // the next leaf following the variable identified by `arc'. 0N/A // We cannot return the variable because whatever follows in 0N/A // the OID will be greater or equals to 0, and 0 identifies 0N/A // the variable itself - so we have indeed to return the 0N/A // So we do nothing, because this case is handled at the 0N/A // end of the if ... else if ... else ... block. 0N/A // Now if the arc leads to a subgroup, we delegate the 0N/A // search to the child, just as done in SnmpMibNode. 0N/A // get the child ( = nested arc node). 0N/A // The oid is not valid, we will throw an exception in order 0N/A // to try with the next valid identifier... 0N/A // We didn't find anything at the given arc, so we're going 0N/A // to try with the next valid arc