FileDocCategorySizeDatePackage
SnmpVarBind.javaAPI DocJava SE 5 API27341Fri Aug 26 14:55:04 BST 2005com.sun.jmx.snmp

SnmpVarBind

public class SnmpVarBind extends Object implements Serializable, Cloneable, SnmpDataTypeEnums
This class holds information for a MIB variable contained in an {@link com.sun.jmx.snmp.SnmpVarBindList}. An SnmpVarBind consists of three parts:

- The corresponding OID object for the MIB variable.
- The value part associated with that OID instance. If present, it determines the MIB syntax for the object.
- The status of the SnmpVarBind which specifies whether the agent responded with an exception condition for this variable such as noSuchInstance, endOfMibView, or noSuchObject.

This API is a Sun Microsystems internal API and is subject to change without notice.

Fields Summary
public static final String[]
statusLegend
Keeps the legend for the value part of the SnmpVarBind.
public static final int
stValueUnspecified
Useful constant indicating that the status of the SnmpVarBind object is not initialized.
public static final int
stValueOk
Useful constant indicating that the status of the SnmpVarBind object is valid.
public static final int
stValueNoSuchObject
Useful constant indicating that the status of the SnmpVarBind object is noSuchObject. Status of SnmpVarBind as returned by the SNMPv2 agent.
public static final int
stValueNoSuchInstance
Useful constant indicating that the status of the SnmpVarBind object is noSuchInstance. Status of SnmpVarBind as returned by the SNMPv2 agent. In the SNMPv1 context, this is appropriate when noSuchName is returned in response to the SnmpGet request.
public static final int
stValueEndOfMibView
Useful constant indicating that the status of the SnmpVarBind object is endOfMibView. Status of SnmpVarBind as returned by the SNMPv2 agent. In the SNMPv1 context, this is appropriate when noSuchName is returned in response to the SnmpGetNext request.
public static final SnmpNull
noSuchObject
Error code value as defined in RFC 1448 for: noSuchObject.
public static final SnmpNull
noSuchInstance
Error code value as defined in RFC 1448 for: noSuchInstance.
public static final SnmpNull
endOfMibView
Error code value as defined in RFC 1448 for: endOfMibView.
public SnmpOid
oid
The OID of the SnmpVarBind. The default value is null.

Reserved for internal use:
As of Java Dynamic Management Kit 5.0, use instead getOid and setOid

public SnmpValue
value
The value of the SnmpVarBind. The default value is null.

Reserved for internal use:
As of Java Dynamic Management Kit 5.0, use instead getSnmpValue and setSnmpValue

public int
status
Indicates the status of the value in this SnmpVarBind. The default value is stValueUnspecified. This attribute is updated internally and should not be changed otherwise.
Constructors Summary
public SnmpVarBind()
Default constructor.

    
    
    // CONSTRUCTORS
    //-------------
    
           
      
    
public SnmpVarBind(SnmpOid oid)
Constructs a new SnmpVarBind object from the specified SnmpOid value.

param
oid The OID part of the SnmpVarBind.

        this.oid = oid ;
    
public SnmpVarBind(SnmpOid oid, SnmpValue val)
Constructs a new SnmpVarBind object from the specified SnmpOid and SnmpValue.

param
oid The OID part of the SnmpVarBind.
param
val The value part of the SnmpVarBind.

        this.oid = oid ;
        this.setSnmpValue(val) ;
    
public SnmpVarBind(String name)
Constructs a new SnmpVarBind object from the specified String 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 String.
exception
SnmpStatusException An error occurred while resolving the MIB variable name.


        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)) ;
                }
            }
        }
    
Methods Summary
public final voidaddInstance(long inst)
Adds an instance part to the OID in the SnmpOid object. Note that there is no getInstance method. This method will directly add the instance to the SnmpOid object.

param
inst The sub-identifier to be appended to the OID.

        oid.append(inst) ;
        return ;
    
public final voidaddInstance(long[] inst)
Adds an instance part to the OID in the SnmpOid object. Note that there is no getInstance method. This method will directly add the instance to the SnmpOid object.

param
inst The sub-identifier array to be appended to the OID.
exception
SnmpStatusException An error occurred while accessing a MIB node.

        oid.addToOid(inst) ;
        return ;
    
public final voidaddInstance(java.lang.String inst)
Adds an instance part to the OID in the SnmpOid object. Note that there is no getInstance method. This method will directly add the instance to the SnmpOid object.

param
inst Dot-formatted sub-identifier String to be appended to the OID.
exception
SnmpStatusException An error occurred while accessing a MIB node.

        if (inst != null) {
            oid.addToOid(inst) ;
        }
        return ;
    
public voidappendInOid(SnmpOid oid)
Appends the specified SnmpOid to the end of the OID of this SnmpVarBind.

param
oid The OID to append.

        this.oid.append(oid) ;
    
public final voidclearValue()
Clears the value associated with this SnmpVarBind and sets the status to stValueUnspecified.

        this.value = null ;
        status = stValueUnspecified ;
    
public java.lang.Objectclone()
Clones the SNMP variable (including value).

return
The SNMP variable clone.

 
//         SnmpVarBind v = null ;
//         try {
//             v = (SnmpVarBind) super.clone() ;
//             v.copyValueAndOid(this) ;
//         } catch (CloneNotSupportedException e) {
//             throw new InternalError() ;
//         }
//         return v ;
        SnmpVarBind v = new SnmpVarBind() ;
        v.copyValueAndOid(this) ;
        return v ;
    
public java.lang.ObjectcloneWithoutValue()
Clones the SNMP variable. It does not clone the value portion.

return
A new object with the value part set to null.

        SnmpOid noid = (SnmpOid)this.oid.clone() ;
        return new SnmpVarBind(noid) ;
    
public voidcopyValue(com.sun.jmx.snmp.SnmpVarBind var)
Clones and copies only the value part from another SnmpVarBind object.

param
var The SnmpVarBind clone.

        if (var.isValidValue()) {
            this.value = var.getSnmpValue().duplicate() ;
            setValueValid() ;
        } else {
            status = var.getValueStatus() ;
	    if (status == stValueEndOfMibView)        value=endOfMibView;
	    else if (status == stValueNoSuchObject)   value=noSuchObject;
	    else if (status == stValueNoSuchInstance) value=noSuchInstance;
        }
    
public voidcopyValueAndOid(com.sun.jmx.snmp.SnmpVarBind var)
Clones and copies the OID and value part from another SnmpVarBind object.

param
var The SnmpVarBind clone.

        setOid((SnmpOid) (var.oid.clone())) ;
        copyValue(var) ;
    
public final SnmpOidgetOid()
Returns the complete OID part associated with this SnmpVarBind.

return
The SnmpOid for this variable.

        return this.oid ;
    
public final SnmpCounter64getSnmpCounter64Value()
Returns the value part associated with this SnmpVarBind.

return
The SnmpCounter64 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.

        return (SnmpCounter64)this.value ;
    
public final SnmpCountergetSnmpCounterValue()
Returns the value part associated with this SnmpVarBind.

return
The SnmpCounter 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.

        return (SnmpCounter)this.value ;
    
public final SnmpGaugegetSnmpGaugeValue()
Returns the value part associated with this SnmpVarBind.

return
The SnmpGauge 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.

        return (SnmpGauge)this.value ;
    
public final SnmpIntgetSnmpIntValue()
Returns the value part associated with this SnmpVarBind.

return
The SnmpInt 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.

        return (SnmpInt)this.value ;
    
public final SnmpIpAddressgetSnmpIpAddressValue()
Returns the value part associated with this SnmpVarBind.

return
The SnmpIpAddress 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.

        return (SnmpIpAddress)this.value ;
    
public final SnmpOidgetSnmpOidValue()
Returns the value part associated with this SnmpVarBind.

return
The SnmpOid 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.

        return (SnmpOid)this.value ;
    
public final SnmpOpaquegetSnmpOpaqueValue()
Returns the value part associated with this SnmpVarBind.

return
The SnmpOpaque 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.

        return (SnmpOpaque)this.value ;
    
public final SnmpStringFixedgetSnmpStringFixedValue()
Returns the value part associated with this SnmpVarBind.

return
The SnmpStringFixed 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.

        return (SnmpStringFixed)this.value ;
    
public final SnmpStringgetSnmpStringValue()
Returns the value part associated with this SnmpVarBind.

return
The SnmpString 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.

        return (SnmpString)this.value ;
    
public final SnmpTimeticksgetSnmpTimeticksValue()
Returns the value part associated with this SnmpVarBind.

return
The SnmpTimeticks 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.

        return (SnmpTimeticks)this.value ;
    
public final synchronized SnmpValuegetSnmpValue()
Returns the value part associated with this SnmpVarBind.

return
The SnmpValue for this variable.

        return this.value ;
    
public final java.lang.StringgetStringValue()
Returns the printable ASCII representation for the corresponding variable value.

return
The printable ASCII representation.

        return this.value.toString() ;
    
public final intgetValueStatus()
Returns the status of the value associated with this SnmpVarBind as an integer. This value is one of {@link #stValueUnspecified}, {@link #stValueOk}, {@link #stValueNoSuchObject}, {@link #stValueNoSuchInstance}, {@link #stValueEndOfMibView}.

return
The status of the associated value.

        return status ;
    
public final java.lang.StringgetValueStatusLegend()
Returns the status of the value associated with this SnmpVarBind as a String. This value is a displayable representation of the status integer value. It is one of Value not initialized, Valid Value, No such object, No such Instance, End of Mib View.

return
The status of the associated value.

        return statusLegend[status] ;
    
private voidhandleLong(java.lang.String oid, int index)


        String str;
        if (index >0) {
            str= oid.substring(0, index);
        } else {
            str= oid ;
        }

        // just parse the element.
        //
        Long.parseLong(str);
    
public final synchronized booleanhasVarBindException()
Determines whether the SnmpVarBind has an SNMP exception (generated by agent in response to a request).

return
true if the SnmpVarBind has an SNMP response exception, false otherwise.

        switch (status) {
        case  stValueUnspecified :
        case  stValueNoSuchObject :
        case  stValueNoSuchInstance :
        case  stValueEndOfMibView :
            return true ;
        }
        return false ;
    
public voidinsertInOid(int oid)
Inserts a sub-id at the beginning of the OID of this SnmpVarBind.

param
oid The sub-id to insert.

        this.oid.insert(oid) ;
    
public final booleanisOidEqual(com.sun.jmx.snmp.SnmpVarBind var)
Checks whether the OID for this variable completely matches the OID part of the specified SnmpVarBind object.

param
var The object whose OID part is to be matched.
return
true if the OID part matches exactly, false otherwise.

        return this.oid.equals(var.oid) ;
    
public final booleanisUnspecifiedValue()
Checks whether the value associated with this SnmpVarBind is unspecified.

return
true if the status is unspecified, false otherwise.

        return (status == stValueUnspecified) ;
    
public final booleanisValidValue()
Checks whether the object contains a valid accessible value.

return
true if the associated value is valid, false otherwise.

        return (status == stValueOk) ;
    
public SnmpOidRecordresolveVarName(java.lang.String name)
Consults the MIB table storage to resolve the name to its OID type structure.

param
name The MIB variable name or a dot-formatted OID String.
return
The SnmpOidRecord object containing information on the MIB variable.
exception
SnmpStatusException An error occurred while resolving the MIB variable name.

        
        SnmpOidTable mibTable = oid.getSnmpOidTable();
        if (mibTable == null)
            throw new SnmpStatusException(SnmpStatusException.noSuchName);
        int index = name.indexOf('.");
        if (index < 0) {
            return mibTable.resolveVarName(name);
        } else {
            return mibTable.resolveVarOid(name);
        }
    
public final voidsetEndOfMibView()
Set the value to {@link #endOfMibView}. This is equivalent to setSnmpValue(SnmpVarBind.endOfMibView).

	value=endOfMibView;
	status=stValueEndOfMibView;
    
public final voidsetNoSuchInstance()
Set the value to {@link #noSuchInstance}. This is equivalent to setSnmpValue(SnmpVarBind.noSuchInstance).

	value=noSuchInstance;
	status=stValueNoSuchInstance;
    
public final voidsetNoSuchObject()
Set the value to {@link #noSuchObject}. This is equivalent to setSnmpValue(SnmpVarBind.noSuchObject).

	value=noSuchObject;
	status=stValueNoSuchObject;
    
public final voidsetOid(SnmpOid oid)
Sets the SnmpOid part associated with this SnmpVarBind with the specified OID. The value part of this SnmpVarBind will automatically be nulled.

param
oid The new OID.

        this.oid = oid ;
        clearValue() ;
    
public final voidsetSnmpCounter64Value(long val)
Sets the SnmpCounter64 value part associated with this SnmpVarBind 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 Long.MAX_VALUE.
see
SnmpCounter64

        clearValue() ;
        this.value = new SnmpCounter64(val) ;
        setValueValid() ;
    
public final voidsetSnmpCounterValue(long val)
Sets the SnmpCounter value part associated with this SnmpVarBind 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 SnmpUnsignedInt.MAX_VALUE.
see
SnmpCounter

        clearValue() ;
        this.value = new SnmpCounter(val) ;
        setValueValid() ;
    
public final voidsetSnmpGaugeValue(long val)
Sets the SnmpGauge value part associated with this SnmpVarBind 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 SnmpUnsignedInt.MAX_VALUE.
see
SnmpGauge

        clearValue() ;
        this.value = new SnmpGauge(val) ;
        setValueValid() ;
    
public final voidsetSnmpIntValue(long val)
Sets the SnmpInt value part associated with this SnmpVarBind 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 Integer.MIN_VALUE or larger than Integer.MAX_VALUE.
see
SnmpInt

        clearValue() ;
        this.value = new SnmpInt(val) ;
        setValueValid() ;
    
public final voidsetSnmpIpAddressValue(java.lang.String val)
Sets the SnmpIpAddress value part associated with this SnmpVarBind with the specified ipAddress value. The status is updated to indicate that the value is valid.

param
val The new IP address value.
exception
IllegalArgumentException The specified value does not correspond to an IP address.
see
SnmpIpAddress

        clearValue() ;
        this.value = new SnmpIpAddress(val) ;
        setValueValid() ;
    
public final voidsetSnmpOidValue(java.lang.String val)
Sets the SnmpOid value part associated with this SnmpVarBind 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 String nor a String of the MIB database.
see
SnmpOid

        clearValue() ;
        this.value = new SnmpOid(val) ;
        setValueValid() ;
    
public final voidsetSnmpOpaqueValue(byte[] val)
Sets the SnmpOpaque value part associated with this SnmpVarBind with the specified bytes array values. The status is updated to indicate that the value is valid.

param
val The new bytes array value.
see
SnmpOpaque

        clearValue() ;
        this.value = new SnmpOpaque(val) ;
        setValueValid() ;
    
public final voidsetSnmpStringFixedValue(java.lang.String val)
Sets the SnmpStringFixed value part associated with this SnmpVarBind with the specified string value. The status is updated to indicate that the value is valid.

param
val The new string value.
see
SnmpStringFixed

        clearValue() ;
        this.value = new SnmpStringFixed(val) ;
        setValueValid() ;
    
public final voidsetSnmpStringValue(java.lang.String val)
Sets the SnmpString value part associated with this SnmpVarBind with the specified string value. The status is updated to indicate that the value is valid.

param
val The new string value.
see
SnmpString

        clearValue() ;
        this.value = new SnmpString(val) ;
        setValueValid() ;
    
public final voidsetSnmpTimeticksValue(long val)
Sets the SnmpTimeticks value part associated with this SnmpVarBind 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 SnmpUnsignedInt.MAX_VALUE.
see
SnmpTimeticks

        clearValue() ;
        this.value = new SnmpTimeticks(val) ;
        setValueValid() ;
    
public final voidsetSnmpValue(SnmpValue val)
Sets the SnmpValue part associated with this SnmpVarBind with the specified value. The status is updated to indicate that the value is valid.

param
val The new value.

        this.value= val ;
        setValueValid();
    
private voidsetValueValid()
Sets the status to indicate that the value for this SnmpVarBind is valid.

	if (value == endOfMibView)        status=stValueEndOfMibView;
	else if (value == noSuchObject)   status=stValueNoSuchObject;
	else if (value == noSuchInstance) status=stValueNoSuchInstance;
        else status = stValueOk ;
    
public final java.lang.StringtoString()
Returns the printable ASCII representation of this SnmpVarBind.

return
The printable ASCII representation.

        StringBuffer s = new StringBuffer(400) ;
        s.append("Object ID : " + this.oid.toString()) ; 

        if (isValidValue()) {
            s.append("  (Syntax : " + this.value.getTypeName() + ")\n") ;
            s.append("Value : " + this.value.toString()) ;
        } else {
            s.append("\n" + "Value Exception : " + getValueStatusLegend()) ;
        }
        return s.toString() ;