Class SnmpVarBind

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, SnmpSyntax

    public class SnmpVarBind
    extends java.lang.Object
    implements SnmpSyntax, java.lang.Cloneable, java.io.Serializable
    This class defined the SNMP variables that are transmitted to and from an agent. A variable is defined by its name (a SnmpObjectId) and its value (SnmpSyntax). The SnmpVarBind is used by the SnmpPduPacket class and uses SnmpObjectId along with any class that implements the SnmpSyntax interface.
    Version:
    1.1.1.1
    Author:
    Brian Weaver
    See Also:
    SnmpSyntax, SnmpPduPacket, Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte ASNTYPE
      The ASN.1 identifier used to mark SNMP variables
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()
      Returns a newly created duplicate object to the caller
      int decodeASN​(byte[] buf, int offset, AsnEncoder encoder)
      Used to recover the encoded variable data from the passed ASN.1 buffer.
      SnmpVarBind duplicate()
      Returns a newly created duplicate object to the caller
      int encodeASN​(byte[] buf, int offset, AsnEncoder encoder)
      Encodes the SnmpVarBind object into the passed buffer.
      SnmpObjectId getName()
      Returns the object identifier that names the variable.
      SnmpSyntax getValue()
      Retreives the variable's value.
      void setName​(java.lang.String name)
      Sets the variable's name to passed value.
      void setName​(SnmpObjectId name)
      Sets the variable's object identifier name.
      void setValue​(SnmpSyntax value)
      Sets the value for the variable
      java.lang.String toString()
      Converts the object to a string representation
      byte typeId()
      Returns the ASN.1 type id for the object.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • ASNTYPE

        public static final byte ASNTYPE
        The ASN.1 identifier used to mark SNMP variables
        See Also:
        Constant Field Values
    • Constructor Detail

      • SnmpVarBind

        public SnmpVarBind​(SnmpObjectId name)
        Constructs a specific variable with the "name" equal to the passed object identifier. The variable portion is set to an instance of SnmpNull.
        Parameters:
        name - The object identifer name for this variable.
      • SnmpVarBind

        public SnmpVarBind​(SnmpObjectId name,
                           SnmpSyntax value)
        Constructs a variable with the passed name and value. The name and value are duplicated so that any further changes to the passed data will not affect the SNMP variable.
        Parameters:
        name - The object identifier name
        value - The syntax object.
      • SnmpVarBind

        public SnmpVarBind​(java.lang.String name)
        Constructs a new variable with the give name. The name must be a dotted decimal object identifier string.
        Parameters:
        name - Dotted decimal object identifier.
        See Also:
        SnmpObjectId
      • SnmpVarBind

        public SnmpVarBind​(java.lang.String name,
                           SnmpSyntax value)
        Constructs a new variable with the passed name and value. The name must be in a dotted decimal format. The value must not be null, but must be a valid SnmpSyntax object.
        Parameters:
        name - The dotted decimal object identifer name
        value - The SnmpSyntax value for the variable
      • SnmpVarBind

        public SnmpVarBind​(SnmpVarBind second)
        Class copy constructor. Makes a duplicate copy of the passed variable and stores the new references in self. If the passed variable is modified after the construction, it will not affect the object.
        Parameters:
        second - The variable to copy
    • Method Detail

      • getName

        public SnmpObjectId getName()
        Returns the object identifier that names the variable.
        Returns:
        The variable's object identifier
      • setName

        public void setName​(SnmpObjectId name)
        Sets the variable's object identifier name.
        Parameters:
        name - The new object id for the variable.
      • setName

        public void setName​(java.lang.String name)
        Sets the variable's name to passed value.
        Parameters:
        name - The dotted decimal object identifier.
      • getValue

        public SnmpSyntax getValue()
        Retreives the variable's value.
        Returns:
        The SnmpSyntax object for the variable.
      • setValue

        public void setValue​(SnmpSyntax value)
        Sets the value for the variable
        Parameters:
        value - The new value for the object
      • typeId

        public byte typeId()
        Returns the ASN.1 type id for the object.
        Specified by:
        typeId in interface SnmpSyntax
        Returns:
        The ASN.1 type identifier.
      • encodeASN

        public int encodeASN​(byte[] buf,
                             int offset,
                             AsnEncoder encoder)
                      throws AsnEncodingException
        Encodes the SnmpVarBind object into the passed buffer. The variable's data is encoded using the passed AsnEncoder object. The offset for the next object to be encoded is returned by the method. This method is defined to fulfill the contract with the SnmpSytnax interface.
        Specified by:
        encodeASN in interface SnmpSyntax
        Parameters:
        buf - Storeage for the encoded data
        offset - Offset to start encoding data
        encoder - The encoder used to convert the data
        Returns:
        The offset of the next byte immediately after the last encoded byte by this routine.
        Throws:
        AsnEncodingException - Thrown if the encoder encounters an error while building the buffer.
      • decodeASN

        public int decodeASN​(byte[] buf,
                             int offset,
                             AsnEncoder encoder)
                      throws AsnDecodingException
        Used to recover the encoded variable data from the passed ASN.1 buffer. The encoder object provides a way for the data to be decoded. The offset marks the start location for the decoding operation. Once the data is decoded it is set in the current object.
        Specified by:
        decodeASN in interface SnmpSyntax
        Parameters:
        buf - Encoded ASN.1 data
        offset - Offset to first byte of encoded data
        encoder - The encoder used to convert the data
        Returns:
        The byte offset immediantly after the last decoded byte of information.
        Throws:
        AsnDecodingException - Thrown if an error occurs while attempting to decode the data. This exception will be thrown byte encoder object.
      • duplicate

        public SnmpVarBind duplicate()
        Returns a newly created duplicate object to the caller
        Specified by:
        duplicate in interface SnmpSyntax
        Returns:
        A newly created variable
      • clone

        public java.lang.Object clone()
        Returns a newly created duplicate object to the caller
        Overrides:
        clone in class java.lang.Object
        Returns:
        A newly created variable
      • toString

        public java.lang.String toString()
        Converts the object to a string representation
        Overrides:
        toString in class java.lang.Object