Module org.snmp4j

Class AbstractVariable

    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractVariable()
      The abstract Variable class serves as the base class for all specific SNMP syntax types.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract java.lang.Object clone()
      Clones this variable.
      abstract int compareTo​(Variable o)  
      static Variable createFromBER​(BERInputStream inputStream)
      Creates a Variable from a BER encoded BERInputStream.
      static Variable createFromSyntax​(int smiSyntax)
      Creates a Variable from the supplied SMI syntax identifier.
      abstract void decodeBER​(BERInputStream inputStream)
      Decodes a Variable from an BERInputStream.
      abstract void encodeBER​(java.io.OutputStream outputStream)
      Encodes a Variable to an OutputStream.
      static boolean equal​(AbstractVariable a, AbstractVariable b)
      Tests if two variables have the same value.
      abstract boolean equals​(java.lang.Object o)  
      abstract void fromSubIndex​(OID subIndex, boolean impliedLength)
      Sets the value of this Variable from the supplied (sub-)index.
      abstract int getBERLength()
      Returns the length of this Variable in bytes when encoded according to the Basic Encoding Rules (BER).
      int getBERPayloadLength()
      Returns the length of the payload of this BERSerializable object in bytes when encoded according to the Basic Encoding Rules (BER).
      abstract int getSyntax()
      Gets the ASN.1 syntax identifier value of this SNMP variable.
      static int getSyntaxFromString​(java.lang.String syntaxString)
      Returns the BER syntax ID for the supplied syntax string (as returned by getSyntaxString(int)).
      java.lang.String getSyntaxString()
      Gets a textual description of this Variable.
      static java.lang.String getSyntaxString​(int syntax)
      Gets a textual description of the supplied syntax type.
      abstract int hashCode()  
      boolean isDynamic()
      Indicates whether this variable is dynamic, which means that it might change its value while it is being (BER) serialized.
      boolean isException()
      Checks whether this variable represents an exception like noSuchObject, noSuchInstance, and endOfMibView.
      abstract int toInt()
      Returns an integer representation of this variable if such a representation exists.
      abstract long toLong()
      Returns a long representation of this variable if such a representation exists.
      abstract java.lang.String toString()
      Gets a string representation of the variable.
      abstract OID toSubIndex​(boolean impliedLength)
      Converts the value of this Variable to a (sub-)index value.
      • Methods inherited from class java.lang.Object

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

      • SMISYNTAXES_PROPERTIES

        public static final java.lang.String SMISYNTAXES_PROPERTIES
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractVariable

        public AbstractVariable()
        The abstract Variable class serves as the base class for all specific SNMP syntax types.
    • Method Detail

      • equals

        public abstract boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface Variable
        Overrides:
        equals in class java.lang.Object
      • compareTo

        public abstract int compareTo​(Variable o)
        Specified by:
        compareTo in interface java.lang.Comparable<Variable>
        Specified by:
        compareTo in interface Variable
      • hashCode

        public abstract int hashCode()
        Specified by:
        hashCode in interface Variable
        Overrides:
        hashCode in class java.lang.Object
      • getBERLength

        public abstract int getBERLength()
        Returns the length of this Variable in bytes when encoded according to the Basic Encoding Rules (BER).
        Specified by:
        getBERLength in interface BERSerializable
        Returns:
        the BER encoded length of this variable.
      • getBERPayloadLength

        public int getBERPayloadLength()
        Description copied from interface: BERSerializable
        Returns the length of the payload of this BERSerializable object in bytes when encoded according to the Basic Encoding Rules (BER).
        Specified by:
        getBERPayloadLength in interface BERSerializable
        Returns:
        the BER encoded length of this variable.
      • decodeBER

        public abstract void decodeBER​(BERInputStream inputStream)
                                throws java.io.IOException
        Decodes a Variable from an BERInputStream.
        Specified by:
        decodeBER in interface BERSerializable
        Parameters:
        inputStream - an BERInputStream containing a BER encoded byte stream.
        Throws:
        java.io.IOException - if the stream could not be decoded by using BER rules.
      • encodeBER

        public abstract void encodeBER​(java.io.OutputStream outputStream)
                                throws java.io.IOException
        Encodes a Variable to an OutputStream.
        Specified by:
        encodeBER in interface BERSerializable
        Parameters:
        outputStream - an OutputStream.
        Throws:
        java.io.IOException - if an error occurs while writing to the stream.
      • createFromBER

        public static Variable createFromBER​(BERInputStream inputStream)
                                      throws java.io.IOException
        Creates a Variable from a BER encoded BERInputStream. Subclasses of Variable are registered using the properties file smisyntaxes.properties in this package. The properties are read when this method is called first.
        Parameters:
        inputStream - an BERInputStream containing a BER encoded byte stream.
        Returns:
        an instance of a subclass of Variable.
        Throws:
        java.io.IOException - if the inputStream is not properly BER encoded.
      • createFromSyntax

        public static Variable createFromSyntax​(int smiSyntax)
        Creates a Variable from the supplied SMI syntax identifier. Subclasses of Variable are registered using the properties file smisyntaxes.properties in this package. The properties are read when this method is called for the first time.
        Parameters:
        smiSyntax - an SMI syntax identifier of the registered types, which is typically defined by SMIConstants.
        Returns:
        a Variable variable instance of the supplied SMI syntax.
      • getSyntax

        public abstract int getSyntax()
        Gets the ASN.1 syntax identifier value of this SNMP variable.
        Specified by:
        getSyntax in interface Variable
        Returns:
        an integer value less than 128 for regular SMI objects and a value greater or equal than 128 for exception values like noSuchObject, noSuchInstance, and endOfMibView.
      • toString

        public abstract java.lang.String toString()
        Gets a string representation of the variable.
        Specified by:
        toString in interface Variable
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of the variable's value.
      • toInt

        public abstract int toInt()
        Returns an integer representation of this variable if such a representation exists.
        Specified by:
        toInt in interface Variable
        Returns:
        an integer value (if the native representation of this variable would be a long, then the long value will be casted to int).
        Throws:
        java.lang.UnsupportedOperationException - if an integer representation does not exists for this Variable.
        Since:
        1.7
      • toLong

        public abstract long toLong()
        Returns a long representation of this variable if such a representation exists.
        Specified by:
        toLong in interface Variable
        Returns:
        a long value.
        Throws:
        java.lang.UnsupportedOperationException - if a long representation does not exists for this Variable.
        Since:
        1.7
      • clone

        public abstract java.lang.Object clone()
        Description copied from interface: Variable
        Clones this variable. Cloning can be used by the SNMP4J API to better support concurrency by creating a clone for internal processing. The content of this object is independent to the content of the clone. Thus, changes to the clone will have no effect to this object.
        Specified by:
        clone in interface Variable
        Overrides:
        clone in class java.lang.Object
        Returns:
        a new instance of this Variable with the same value.
      • getSyntaxString

        public static java.lang.String getSyntaxString​(int syntax)
        Gets a textual description of the supplied syntax type.
        Parameters:
        syntax - the BER code of the syntax.
        Returns:
        a textual description like 'Integer32' for syntax as used in the Structure of Management Information (SMI) modules. '?' is returned if the supplied syntax is unknown.
      • getSyntaxString

        public final java.lang.String getSyntaxString()
        Gets a textual description of this Variable.
        Specified by:
        getSyntaxString in interface Variable
        Returns:
        a textual description like 'Integer32' as used in the Structure of Management Information (SMI) modules. '?' is returned if the syntax is unknown.
        Since:
        1.7
      • getSyntaxFromString

        public static int getSyntaxFromString​(java.lang.String syntaxString)
        Returns the BER syntax ID for the supplied syntax string (as returned by getSyntaxString(int)).
        Parameters:
        syntaxString - the textual representation of the syntax.
        Returns:
        the corresponding BER ID.
        Since:
        1.6
      • toSubIndex

        public abstract OID toSubIndex​(boolean impliedLength)
        Converts the value of this Variable to a (sub-)index value.
        Specified by:
        toSubIndex in interface Variable
        Parameters:
        impliedLength - specifies if the sub-index has an implied length. This parameter applies to variable length variables only (e.g. OctetString and OID). For other variables it has no effect.
        Returns:
        an OID that represents this value as an (sub-)index.
        Throws:
        java.lang.UnsupportedOperationException - if this variable cannot be used in an index.
        Since:
        1.7
      • fromSubIndex

        public abstract void fromSubIndex​(OID subIndex,
                                          boolean impliedLength)
        Sets the value of this Variable from the supplied (sub-)index.
        Specified by:
        fromSubIndex in interface Variable
        Parameters:
        subIndex - the sub-index OID.
        impliedLength - specifies if the sub-index has an implied length. This parameter applies to variable length variables only (e.g. OctetString and OID). For other variables it has no effect.
        Throws:
        java.lang.UnsupportedOperationException - if this variable cannot be used in an index.
        Since:
        1.7
      • isDynamic

        public boolean isDynamic()
        Indicates whether this variable is dynamic, which means that it might change its value while it is being (BER) serialized. If a variable is dynamic, it will be cloned on-the-fly when it is added to a PDU with PDU.add(VariableBinding). By cloning the value, it is ensured that there are no inconsistent changes between determining the length with getBERLength() for encoding enclosing SEQUENCES and the actual encoding of the Variable itself with encodeBER(java.io.OutputStream).
        Specified by:
        isDynamic in interface Variable
        Returns:
        false by default. Derived classes may override this if implementing dynamic Variable instances.
        Since:
        1.8
      • equal

        public static boolean equal​(AbstractVariable a,
                                    AbstractVariable b)
        Tests if two variables have the same value.
        Parameters:
        a - a variable.
        b - another variable.
        Returns:
        true if a == null) ? (b == null) : a.equals(b).
        Since:
        2.0