0N/A/*
2362N/A * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
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 *
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 *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage com.sun.jmx.snmp.agent;
0N/A
0N/A// java imports
0N/A//
0N/Aimport java.io.Serializable;
0N/Aimport java.util.Hashtable;
0N/Aimport java.util.Enumeration;
0N/Aimport java.util.Vector;
0N/A
0N/A// jmx imports
0N/A//
0N/Aimport com.sun.jmx.snmp.SnmpOid;
0N/Aimport com.sun.jmx.snmp.SnmpValue;
0N/Aimport com.sun.jmx.snmp.SnmpVarBind;
0N/Aimport com.sun.jmx.snmp.SnmpStatusException;
0N/A
0N/A// SNMP Runtime imports
0N/A//
0N/A
0N/A/**
0N/A * <p>
0N/A * This class is a utility class that transform SNMP GET / SET requests
0N/A * into series of get<i>AttributeName</i>() set<i>AttributeName</i>()
0N/A * invoked on the MBean.
0N/A * </p>
0N/A *
0N/A * <p>
0N/A * The transformation relies on the metadata information provided by the
0N/A * {@link com.sun.jmx.snmp.agent.SnmpStandardMetaServer} object which is
0N/A * passed as first parameter to every method. This SnmpStandardMetaServer
0N/A * object is usually a Metadata object generated by <code>mibgen</code>.
0N/A * </p>
0N/A *
0N/A * <p>
0N/A * The MBean is not invoked directly by this class but through the
0N/A * metadata object which holds a reference on it.
0N/A * </p>
0N/A *
0N/A * <p><b><i>
0N/A * This class is used internally by mibgen generated metadata objects and
0N/A * you should never need to use it directly.
0N/A * </b></i></p>
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 **/
0N/A
0N/Apublic class SnmpStandardObjectServer implements Serializable {
0N/A private static final long serialVersionUID = -4641068116505308488L;
0N/A
0N/A /**
0N/A * Generic handling of the <CODE>get</CODE> operation.
0N/A * <p> The default implementation of this method is to loop over the
0N/A * varbind list associated with the sub-request and to call
0N/A * <CODE>get(var.oid.getOidArc(depth), data);</CODE>
0N/A * <pre>
0N/A * public void get(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
0N/A * int depth)
0N/A * throws SnmpStatusException {
0N/A *
0N/A * final Object data = req.getUserData();
0N/A *
0N/A * for (Enumeration e= req.getElements(); e.hasMoreElements();) {
0N/A *
0N/A * final SnmpVarBind var= (SnmpVarBind) e.nextElement();
0N/A *
0N/A * try {
0N/A * // This method will generate a SnmpStatusException
0N/A * // if `depth' is out of bounds.
0N/A * //
0N/A * final long id = var.oid.getOidArc(depth);
0N/A * var.value = meta.get(id, data);
0N/A * } catch(SnmpStatusException x) {
0N/A * req.registerGetException(var,x);
0N/A * }
0N/A * }
0N/A * }
0N/A * </pre>
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 * <p>
0N/A *
0N/A * @param meta A pointer to the generated meta-data object which
0N/A * implements the <code>SnmpStandardMetaServer</code>
0N/A * interface.
0N/A *
0N/A * @param req The sub-request that must be handled by this node.
0N/A *
0N/A * @param depth The depth reached in the OID tree.
0N/A *
0N/A * @exception SnmpStatusException An error occurred while accessing
0N/A * the MIB node.
0N/A */
0N/A public void get(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
0N/A int depth)
0N/A throws SnmpStatusException {
0N/A
0N/A final Object data = req.getUserData();
0N/A
0N/A for (Enumeration e= req.getElements(); e.hasMoreElements();) {
0N/A final SnmpVarBind var= (SnmpVarBind) e.nextElement();
0N/A try {
0N/A final long id = var.oid.getOidArc(depth);
0N/A var.value = meta.get(id, data);
0N/A } catch(SnmpStatusException x) {
0N/A req.registerGetException(var,x);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Generic handling of the <CODE>set</CODE> operation.
0N/A * <p> The default implementation of this method is to loop over the
0N/A * varbind list associated with the sub-request and to call
0N/A * <CODE>set(var.value, var.oid.getOidArc(depth), data);</CODE>
0N/A * <pre>
0N/A * public void set(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
0N/A * int depth)
0N/A * throws SnmpStatusException {
0N/A *
0N/A * final Object data = req.getUserData();
0N/A *
0N/A * for (Enumeration e= req.getElements(); e.hasMoreElements();) {
0N/A *
0N/A * final SnmpVarBind var= (SnmpVarBind) e.nextElement();
0N/A *
0N/A * try {
0N/A * // This method will generate a SnmpStatusException
0N/A * // if `depth' is out of bounds.
0N/A * //
0N/A * final long id = var.oid.getOidArc(depth);
0N/A * var.value = meta.set(var.value, id, data);
0N/A * } catch(SnmpStatusException x) {
0N/A * req.registerSetException(var,x);
0N/A * }
0N/A * }
0N/A * }
0N/A * </pre>
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 * <p>
0N/A *
0N/A * @param meta A pointer to the generated meta-data object which
0N/A * implements the <code>SnmpStandardMetaServer</code>
0N/A * interface.
0N/A *
0N/A * @param req The sub-request that must be handled by this node.
0N/A *
0N/A * @param depth The depth reached in the OID tree.
0N/A *
0N/A * @exception SnmpStatusException An error occurred while accessing
0N/A * the MIB node.
0N/A */
0N/A public void set(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
0N/A int depth)
0N/A throws SnmpStatusException {
0N/A
0N/A final Object data = req.getUserData();
0N/A
0N/A for (Enumeration e= req.getElements(); e.hasMoreElements();) {
0N/A SnmpVarBind var = null;
0N/A var = (SnmpVarBind) e.nextElement();
0N/A try {
0N/A // This method will generate a SnmpStatusException
0N/A // if `depth' is out of bounds.
0N/A //
0N/A final long id = var.oid.getOidArc(depth);
0N/A var.value = meta.set(var.value, id, data);
0N/A } catch(SnmpStatusException x) {
0N/A req.registerSetException(var,x);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Generic handling of the <CODE>check</CODE> operation.
0N/A * <p> The default implementation of this method is to loop over the
0N/A * varbind list associated with the sub-request and to call
0N/A * <CODE>check(var.value, var.oid.getOidArc(depth), data);</CODE>
0N/A * <pre>
0N/A * public void check(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
0N/A * int depth)
0N/A * throws SnmpStatusException {
0N/A *
0N/A * final Object data = req.getUserData();
0N/A *
0N/A * for (Enumeration e= req.getElements(); e.hasMoreElements();) {
0N/A *
0N/A * final SnmpVarBind var= (SnmpVarBind) e.nextElement();
0N/A *
0N/A * try {
0N/A * // This method will generate a SnmpStatusException
0N/A * // if `depth' is out of bounds.
0N/A * //
0N/A * final long id = var.oid.getOidArc(depth);
0N/A * meta.check(var.value, id, data);
0N/A * } catch(SnmpStatusException x) {
0N/A * req.registerCheckException(var,x);
0N/A * }
0N/A * }
0N/A * }
0N/A * </pre>
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 * <p>
0N/A *
0N/A * @param meta A pointer to the generated meta-data object which
0N/A * implements the <code>SnmpStandardMetaServer</code>
0N/A * interface.
0N/A *
0N/A * @param req The sub-request that must be handled by this node.
0N/A *
0N/A * @param depth The depth reached in the OID tree.
0N/A *
0N/A * @exception SnmpStatusException An error occurred while accessing
0N/A * the MIB node.
0N/A */
0N/A public void check(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
0N/A int depth)
0N/A throws SnmpStatusException {
0N/A
0N/A final Object data = req.getUserData();
0N/A
0N/A for (Enumeration e= req.getElements(); e.hasMoreElements();) {
0N/A final SnmpVarBind var = (SnmpVarBind) e.nextElement();
0N/A try {
0N/A // This method will generate a SnmpStatusException
0N/A // if `depth' is out of bounds.
0N/A //
0N/A final long id = var.oid.getOidArc(depth);
0N/A meta.check(var.value,id,data);
0N/A } catch(SnmpStatusException x) {
0N/A req.registerCheckException(var,x);
0N/A }
0N/A }
0N/A }
0N/A}