⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmpmib.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
}/** * Abstract class for representing an SNMP MIB. * <P> * When compiling a SNMP MIB, among all the classes generated by  * <CODE>mibgen</CODE>, there is one which extends <CODE>SnmpMib</CODE>  * for representing a whole MIB. * <BR>The class is used by the SNMP protocol adaptor as the entry point in  * the MIB. * * <p>This generated class can be subclassed in your code in order to  * plug in your own specific behaviour. * </p> * * <p><b>This API is a Sun Microsystems internal API  and is subject  * to change without notice.</b></p> * @version     4.30     11/17/05 * @author      Sun Microsystems, Inc */public abstract class SnmpMib extends SnmpMibAgent implements Serializable {      /**     * Default constructor.     * Initializes the OID tree.     */    public SnmpMib() {        root= new SnmpMibOid();    }    // --------------------------------------------------------------------    // POLYMORHIC METHODS    // --------------------------------------------------------------------    /**     * <p>     * This callback should return the OID associated to the group      * identified by the given <code>groupName</code>.      * </p>     *     * <p>     * This method is provided as a hook to plug-in some custom     * specific behavior. Although doing so is discouraged you might     * want to subclass this method in order to store & provide more metadata     * information (mapping OID <-> symbolic name) within the agent,     * or to "change" the root of the MIB OID by prefixing the      * defaultOid by an application dependant OID string, for instance.     * </p>     *     * <p>     * The default implementation of this method is to return the given     * <code>defaultOid</code>     * </p>     *     * @param groupName   The java-ized name of the SNMP group.     * @param defaultOid  The OID defined in the MIB for that group      *                    (in dot notation).     *     * @return The OID of the group identified by <code>groupName</code>,     *         in dot-notation.     */    protected String getGroupOid(String groupName, String defaultOid) {	return defaultOid;    }    /**     * <p>     * This callback should return the ObjectName associated to the      * group identified by the given <code>groupName</code>.      * </p>     *     * <p>     * This method is provided as a hook to plug-in some custom     * specific behavior. You might want to override this method      * in order to provide a different object naming scheme than     * that proposed by default by <code>mibgen</code>.     * </p>     *     * <p>     * This method is only meaningful if the MIB is registered     * in the MBeanServer, otherwise, it will not be called.     * </p>     *     * <p>     * The default implementation of this method is to return an ObjectName     * built from the given <code>defaultName</code>.     * </p>     *     * @param name  The java-ized name of the SNMP group.     * @param oid   The OID returned by getGroupOid() - in dot notation.     * @param defaultName The name by default generated by <code>     *                    mibgen</code>     *     * @return The ObjectName of the group identified by <code>name</code>     */    protected ObjectName getGroupObjectName(String name, String oid, 					    String defaultName) 	throws MalformedObjectNameException {	return new ObjectName(defaultName);    }    /**     * <p>     * Register an SNMP group and its metadata node in the MIB.      * </p>     *     * <p>     * This method is provided as a hook to plug-in some custom     * specific behavior. You might want to override this method      * if you want to set special links between the MBean, its metadata     * node, its OID or ObjectName etc..     * </p>     *     * <p>     * If the MIB is not registered in the MBeanServer, the <code>     * server</code> and <code>groupObjName</code> parameters will be      * <code>null</code>.<br>     * If the given group MBean is not <code>null</code>, and if the      * <code>server</code> and <code>groupObjName</code> parameters are      * not null, then this method will also automatically register the      * group MBean with the given MBeanServer <code>server</code>.     * </p>     *     * @param groupName  The java-ized name of the SNMP group.     * @param groupOid   The OID as returned by getGroupOid() - in dot      *                   notation.     * @param groupObjName The ObjectName as returned by getGroupObjectName().     *                   This parameter may be <code>null</code> if the     *                   MIB is not registered in the MBeanServer.     * @param node       The metadata node, as returned by the metadata     *                   factory method for this group.     * @param group      The MBean for this group, as returned by the     *                   MBean factory method for this group.     * @param server     The MBeanServer in which the groups are to be     *                   registered. This parameter will be <code>null</code>     *                   if the MIB is not registered, otherwise it is a     *                   reference to the MBeanServer in which the MIB is     *                   registered.     *     */    protected void registerGroupNode(String groupName,   String groupOid, 				     ObjectName groupObjName, SnmpMibNode node,				     Object group, MBeanServer server)	throws NotCompliantMBeanException, MBeanRegistrationException, 	InstanceAlreadyExistsException, IllegalAccessException {	root.registerNode(groupOid,node);	if (server != null && groupObjName != null && group != null) 	    server.registerMBean(group,groupObjName);    }     /**     * <p>     * Register an SNMP Table metadata node in the MIB.      * </p>     *     * <p>     * <b><i>     * This method is used internally and you should never need to      * call it directly.</i></b><br> It is used to establish the link      * between an SNMP table metadata node and its bean-like counterpart.     * <br>     * The group metadata nodes will create and register their      * underlying table metadata nodes in the MIB using this      * method. <br>     * The metadata nodes will be later retrieved from the MIB by the     * bean-like table objects using the getRegisterTableMeta() method.     * </p>     *     * @param name      The java-ized name of the SNMP table.     * @param table     The SNMP table metadata node - usually this      *                  corresponds to a <code>mibgen</code> generated      *                  object.     */    public abstract void registerTableMeta(String name, SnmpMibTable table);    /**     * Returns a registered SNMP Table metadata node.     *     * <p><b><i>     * This method is used internally and you should never need to      * call it directly.     * </i></b></p>     *     */    public abstract SnmpMibTable getRegisteredTableMeta(String name);    // --------------------------------------------------------------------    // PUBLIC METHODS    // --------------------------------------------------------------------      /**     * Processes a <CODE>get</CODE> operation.     *     **/     // Implements the method defined in SnmpMibAgent. See SnmpMibAgent    // for java-doc    //    public void get(SnmpMibRequest req) throws SnmpStatusException {	// Builds the request tree: creation is not allowed, operation	// is not atomic.	final int reqType = SnmpDefinitions.pduGetRequestPdu;	SnmpRequestTree handlers = getHandlers(req,false,false,reqType);	SnmpRequestTree.Handler h = null;	SnmpMibNode meta = null;	if (isDebugOn()) 	    debug("get","Processing handlers for GET... ");	// For each sub-request stored in the request-tree, invoke the	// get() method.	for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) {	    h = (SnmpRequestTree.Handler) eh.nextElement();	    // Gets the Meta node. It can be either a Group Meta or a 	    // Table Meta.	    //	    meta = handlers.getMetaNode(h);	    // Gets the depth of the Meta node in the OID tree	    final int depth = handlers.getOidDepth(h);	    for (Enumeration rqs=handlers.getSubRequests(h);		 rqs.hasMoreElements();) {		// Invoke the get() operation.		meta.get((SnmpMibSubRequest)rqs.nextElement(),depth);	    }	}    }    /**     * Processes a <CODE>set</CODE> operation.     *      */    // Implements the method defined in SnmpMibAgent. See SnmpMibAgent    // for java-doc    //    public void set(SnmpMibRequest req) throws SnmpStatusException {	SnmpRequestTree handlers = null;	// Optimization: we're going to get the whole SnmpRequestTree	// built in the "check" method, so that we don't have to rebuild 	// it here.	//	if (req instanceof SnmpMibRequestImpl)	    handlers = ((SnmpMibRequestImpl)req).getRequestTree();	// Optimization didn't work: we have to rebuild the tree.	//	// Builds the request tree: creation is not allowed, operation	// is atomic.	//	final int reqType = SnmpDefinitions.pduSetRequestPdu;	if (handlers == null) handlers = getHandlers(req,false,true,reqType);	handlers.switchCreationFlag(false);	handlers.setPduType(reqType);	SnmpRequestTree.Handler h = null;	SnmpMibNode meta = null;	if (isDebugOn()) 	    debug("set","Processing handlers for SET... ");	// For each sub-request stored in the request-tree, invoke the	// get() method.	for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) {	    h = (SnmpRequestTree.Handler) eh.nextElement();	    // Gets the Meta node. It can be either a Group Meta or a 	    // Table Meta.	    //	    meta = handlers.getMetaNode(h);	    // Gets the depth of the Meta node in the OID tree	    final int depth = handlers.getOidDepth(h);	    for (Enumeration rqs=handlers.getSubRequests(h);		 rqs.hasMoreElements();) {		// Invoke the set() operation		meta.set((SnmpMibSubRequest)rqs.nextElement(),depth);	    }	}    }    /**     * Checks if a <CODE>set</CODE> operation can be performed.     * If the operation cannot be performed, the method will raise a      * <CODE>SnmpStatusException</CODE>.     *     */    // Implements the method defined in SnmpMibAgent. See SnmpMibAgent    // for java-doc    //    public void check(SnmpMibRequest req) throws SnmpStatusException {	final int reqType = SnmpDefinitions.pduWalkRequest;	// Builds the request tree: creation is allowed, operation	// is atomic.	SnmpRequestTree handlers = getHandlers(req,true,true,reqType);	SnmpRequestTree.Handler h = null;	SnmpMibNode meta = null;	if (isDebugOn()) 	    debug("check","Processing handlers for CHECK... ");	// For each sub-request stored in the request-tree, invoke the	// check() method.	for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) {	    h = (SnmpRequestTree.Handler) eh.nextElement();	    // Gets the Meta node. It can be either a Group Meta or a 	    // Table Meta.	    //	    meta = handlers.getMetaNode(h);	    // Gets the depth of the Meta node in the OID tree	    final int depth = handlers.getOidDepth(h);	    for (Enumeration rqs=handlers.getSubRequests(h);		 rqs.hasMoreElements();) {		// Invoke the check() operation		meta.check((SnmpMibSubRequest)rqs.nextElement(),depth);	    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -