📄 snmpvarbind.java
字号:
/* * @(#)file SnmpVarBind.java * @(#)author Sun Microsystems, Inc. * @(#)version 4.14 * @(#)date 08/07/21 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * */// Copyright (c) 1995-96 by Cisco Systems, Inc.package com.sun.jmx.snmp;// java imports//import java.io.Serializable;/** * This class holds information for a MIB variable contained in an {@link com.sun.jmx.snmp.SnmpVarBindList}. * An <CODE>SnmpVarBind</CODE> consists of three parts:<P> * <DL> * <DD>- The corresponding OID object for the MIB variable. * <DD>- The value part associated with that OID instance. * If present, it determines the MIB syntax for the object. * <DD>- The status of the <CODE>SnmpVarBind</CODE> which specifies whether the agent responded with an * exception condition for this variable such as <CODE>noSuchInstance</CODE>, <CODE>endOfMibView</CODE>, * or <CODE>noSuchObject</CODE>. * </DL> * <p><b>This API is a Sun Microsystems internal API and is subject * to change without notice.</b></p> */public class SnmpVarBind implements SnmpDataTypeEnums, Cloneable, Serializable { // PUBLIC VARIABLES //----------------- /** * Keeps the legend for the value part of the <CODE>SnmpVarBind</CODE>. */ static final public String statusLegend[] = { "Status Mapper", "Value not initialized", "Valid Value", "No such object", "No such Instance", "End of Mib View" } ; /** * Useful constant indicating that the status of the <CODE>SnmpVarBind</CODE> object is not initialized. */ static final public int stValueUnspecified = 1 ; /** * Useful constant indicating that the status of the <CODE>SnmpVarBind</CODE> object is valid. */ static final public int stValueOk = 2 ; /** * Useful constant indicating that the status of the <CODE>SnmpVarBind</CODE> object is <CODE>noSuchObject</CODE>. * Status of <CODE>SnmpVarBind</CODE> as returned by the SNMPv2 agent. */ static final public int stValueNoSuchObject = 3 ; /** * Useful constant indicating that the status of the <CODE>SnmpVarBind</CODE> object is * <CODE>noSuchInstance</CODE>. * Status of <CODE>SnmpVarBind</CODE> as returned by the SNMPv2 agent. * In the SNMPv1 context, this is appropriate when <CODE>noSuchName</CODE> is returned in response to the * <CODE>SnmpGet</CODE> request. */ static final public int stValueNoSuchInstance = 4 ; /** * Useful constant indicating that the status of the <CODE>SnmpVarBind</CODE> object is <CODE>endOfMibView</CODE>. * Status of <CODE>SnmpVarBind</CODE> as returned by the SNMPv2 agent. * In the SNMPv1 context, this is appropriate when <CODE>noSuchName</CODE> is returned in response to the * <CODE>SnmpGetNext</CODE> request. */ static final public int stValueEndOfMibView = 5 ; // // These are predefined values for SNMP V2 variables // /** * Error code value as defined in RFC 1448 for: <CODE>noSuchObject</CODE>. */ public final static SnmpNull noSuchObject = new SnmpNull(errNoSuchObjectTag) ; /** * Error code value as defined in RFC 1448 for: <CODE>noSuchInstance</CODE>. */ public final static SnmpNull noSuchInstance = new SnmpNull(errNoSuchInstanceTag) ; /** * Error code value as defined in RFC 1448 for: <CODE>endOfMibView</CODE>. */ public final static SnmpNull endOfMibView = new SnmpNull(errEndOfMibViewTag) ; /** * The OID of the <CODE>SnmpVarBind</CODE>. * The default value is null. * <p><b>Reserved for internal use:</b><br> * As of Java Dynamic Management Kit 5.0, use instead <CODE>getOid</CODE> and <CODE>setOid</CODE></p> */ public SnmpOid oid = null ; /** * The value of the <CODE>SnmpVarBind</CODE>. * The default value is null. * <p><b>Reserved for internal use:</b><br> * As of Java Dynamic Management Kit 5.0, use instead <CODE>getSnmpValue</CODE> and <CODE>setSnmpValue</CODE></p> */ public SnmpValue value = null ; /** * Indicates the status of the value in this <CODE>SnmpVarBind</CODE>. * The default value is <CODE>stValueUnspecified</CODE>. * This attribute is updated internally and should not be changed otherwise. */ public int status = stValueUnspecified ; // CONSTRUCTORS //------------- /** * Default constructor. */ public SnmpVarBind() { } /** * Constructs a new <CODE>SnmpVarBind</CODE> object from the specified <CODE>SnmpOid</CODE> value. * @param oid The OID part of the <CODE>SnmpVarBind</CODE>. */ public SnmpVarBind(SnmpOid oid) { this.oid = oid ; } /** * Constructs a new <CODE>SnmpVarBind</CODE> object from the specified <CODE>SnmpOid</CODE> and * <CODE>SnmpValue</CODE>. * @param oid The OID part of the <CODE>SnmpVarBind</CODE>. * @param val The value part of the <CODE>SnmpVarBind</CODE>. */ public SnmpVarBind(SnmpOid oid, SnmpValue val) { this.oid = oid ; this.setSnmpValue(val) ; } /** * Constructs a new <CODE>SnmpVarBind</CODE> object from the specified <CODE>String</CODE> value. * If the name is a MIB variable, it resolves the name with the MIB database. * @param name The MIB variable name or a dot-formatted OID <CODE>String</CODE>. * @exception SnmpStatusException An error occurred while resolving the MIB variable name. */ public SnmpVarBind(String name) throws SnmpStatusException { if (name.startsWith(".")) { this.oid = new SnmpOid(name) ; } else { SnmpOidRecord record= null; try { int index = name.indexOf('.') ; handleLong(name, index); this.oid = new SnmpOid(name); } catch(NumberFormatException e) { int index = name.indexOf('.') ; if (index <= 0) { record = resolveVarName(name) ; this.oid = new SnmpOid(record.getName()) ; } else { record = resolveVarName(name.substring(0, index)) ; this.oid = new SnmpOid(record.getName() + name.substring(index)) ; } } } } // GETTER/SETTER //-------------- /** * Returns the complete OID part associated with this <CODE>SnmpVarBind</CODE>. * @return The <CODE>SnmpOid</CODE> for this variable. */ final public SnmpOid getOid() { return this.oid ; } /** * Sets the <CODE>SnmpOid</CODE> part associated with this <CODE>SnmpVarBind</CODE> with the specified OID. * The value part of this <CODE>SnmpVarBind</CODE> will automatically be nulled. * @param oid The new OID. */ final public void setOid(SnmpOid oid) { this.oid = oid ; clearValue() ; } /** * Returns the value part associated with this <CODE>SnmpVarBind</CODE>. * @return The <CODE>SnmpValue</CODE> for this variable. */ final synchronized public SnmpValue getSnmpValue() { return this.value ; } /** * Sets the <CODE>SnmpValue</CODE> part associated with this <CODE>SnmpVarBind</CODE> with the specified value. * The status is updated to indicate that the value is valid. * @param val The new value. */ final public void setSnmpValue(SnmpValue val) { this.value= val ; setValueValid(); } /** * Returns the value part associated with this <CODE>SnmpVarBind</CODE>. * @return The <CODE>SnmpCounter64</CODE> value for this variable. * @exception ClassCastException An attempt has been made to cast an object to a subclass of which * it is not an instance. */ final public SnmpCounter64 getSnmpCounter64Value() throws ClassCastException { return (SnmpCounter64)this.value ; } /** * Sets the <CODE>SnmpCounter64</CODE> value part associated with this <CODE>SnmpVarBind</CODE> * with the specified counter 64 value. * The status is updated to indicate that the value is valid. * @param val The new counter 64 value. * @exception IllegalArgumentException The specified value is negative or larger than <CODE>Long.MAX_VALUE</CODE>. * @see SnmpCounter64 */ final public void setSnmpCounter64Value(long val) throws IllegalArgumentException { clearValue() ; this.value = new SnmpCounter64(val) ; setValueValid() ; } /** * Returns the value part associated with this <CODE>SnmpVarBind</CODE>. * @return The <CODE>SnmpInt</CODE> value for this variable. * @exception ClassCastException An attempt has been made to cast an object to a subclass of which * it is not an instance. */ final public SnmpInt getSnmpIntValue() throws ClassCastException { return (SnmpInt)this.value ; } /** * Sets the <CODE>SnmpInt</CODE> value part associated with this <CODE>SnmpVarBind</CODE> * with the specified integer value. * The status is updated to indicate that the value is valid. * @param val The new integer value. * @exception IllegalArgumentException The specified value is smaller than <CODE>Integer.MIN_VALUE</CODE> * or larger than <CODE>Integer.MAX_VALUE</CODE>. * @see SnmpInt */ final public void setSnmpIntValue(long val) throws IllegalArgumentException { clearValue() ; this.value = new SnmpInt(val) ; setValueValid() ; } /** * Returns the value part associated with this <CODE>SnmpVarBind</CODE>. * @return The <CODE>SnmpCounter</CODE> value for this variable. * @exception ClassCastException An attempt has been made to cast an object to a subclass of which * it is not an instance. */ final public SnmpCounter getSnmpCounterValue() throws ClassCastException { return (SnmpCounter)this.value ; } /** * Sets the <CODE>SnmpCounter</CODE> value part associated with this <CODE>SnmpVarBind</CODE> * with the specified counter value. * The status is updated to indicate that the value is valid. * @param val The new counter value. * @exception IllegalArgumentException The specified value is negative or larger than * <CODE>SnmpUnsignedInt.MAX_VALUE</CODE>. * @see SnmpCounter */ final public void setSnmpCounterValue(long val) throws IllegalArgumentException { clearValue() ; this.value = new SnmpCounter(val) ; setValueValid() ; } /** * Returns the value part associated with this <CODE>SnmpVarBind</CODE>. * @return The <CODE>SnmpGauge</CODE> value for this variable. * @exception ClassCastException An attempt has been made to cast an object to a subclass of which * it is not an instance. */ final public SnmpGauge getSnmpGaugeValue() throws ClassCastException { return (SnmpGauge)this.value ; } /** * Sets the <CODE>SnmpGauge</CODE> value part associated with this <CODE>SnmpVarBind</CODE> * with the specified gauge value. * The status is updated to indicate that the value is valid. * @param val The new gauge value. * @exception IllegalArgumentException The specified value is negative or larger than * <CODE>SnmpUnsignedInt.MAX_VALUE</CODE>. * @see SnmpGauge */ final public void setSnmpGaugeValue(long val) throws IllegalArgumentException { clearValue() ; this.value = new SnmpGauge(val) ; setValueValid() ; } /** * Returns the value part associated with this <CODE>SnmpVarBind</CODE>. * @return The <CODE>SnmpTimeticks</CODE> value for this variable. * @exception ClassCastException An attempt has been made to cast an object to a subclass of which * it is not an instance. */ final public SnmpTimeticks getSnmpTimeticksValue() throws ClassCastException { return (SnmpTimeticks)this.value ; } /** * Sets the <CODE>SnmpTimeticks</CODE> value part associated with this <CODE>SnmpVarBind</CODE> * with the specified timeticks value. * The status is updated to indicate that the value is valid. * @param val The new timeticks value. * @exception IllegalArgumentException The specified value is negative or larger than * <CODE>SnmpUnsignedInt.MAX_VALUE</CODE>. * @see SnmpTimeticks */ final public void setSnmpTimeticksValue(long val) throws IllegalArgumentException { clearValue() ; this.value = new SnmpTimeticks(val) ; setValueValid() ; } /** * Returns the value part associated with this <CODE>SnmpVarBind</CODE>. * @return The <CODE>SnmpOid</CODE> value for this variable. * @exception ClassCastException An attempt has been made to cast an object to a subclass of which * it is not an instance. */ final public SnmpOid getSnmpOidValue() throws ClassCastException { return (SnmpOid)this.value ; } /** * Sets the <CODE>SnmpOid</CODE> value part associated with this <CODE>SnmpVarBind</CODE> * with the specified OID value. * The status is updated to indicate that the value is valid. * @param val The new OID value. * @exception IllegalArgumentException The specified value is neither a numeric <CODE>String</CODE> * nor a <CODE>String</CODE> of the MIB database. * @see SnmpOid */ final public void setSnmpOidValue(String val) throws IllegalArgumentException { clearValue() ; this.value = new SnmpOid(val) ; setValueValid() ; } /** * Returns the value part associated with this <CODE>SnmpVarBind</CODE>. * @return The <CODE>SnmpIpAddress</CODE> value for this variable.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -