public abstract class AbstractVariable extends Object implements Variable, Serializable
Variable abstract class is the base class for all SNMP
variables.
All derived classes need to be registered with their SMI BER type in the
smisyntaxes.propertiesso that the
createFromBER(BERInputStream inputStream) method
is able to decode a variable from a BER encoded stream.
To register additional syntaxes, set the system property
SMISYNTAXES_PROPERTIES before decoding a Variable for the first
time. The path of the property file must be accessible from the classpath
and it has to be specified relative to the Variable class.
| Modifier and Type | Field and Description |
|---|---|
static String |
SMISYNTAXES_PROPERTIES |
| Constructor and Description |
|---|
AbstractVariable()
The abstract
Variable class serves as the base class for all
specific SNMP syntax types. |
| Modifier and Type | Method and Description |
|---|---|
abstract Object |
clone()
Clones this variable.
|
abstract int |
compareTo(Variable o) |
static Variable |
createFromBER(BERInputStream inputStream)
Creates a
Variable from a BER encoded InputStream. |
static Variable |
createFromSyntax(int smiSyntax)
Creates a
Variable from the supplied SMI syntax identifier. |
abstract void |
decodeBER(BERInputStream inputStream)
Decodes a
Variable from an InputStream. |
abstract void |
encodeBER(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(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(String syntaxString)
Returns the BER syntax ID for the supplied syntax string (as returned
by
getSyntaxString(int)). |
String |
getSyntaxString()
Gets a textual description of this Variable.
|
static 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 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. |
public static final String SMISYNTAXES_PROPERTIES
public AbstractVariable()
Variable class serves as the base class for all
specific SNMP syntax types.public abstract boolean equals(Object o)
public abstract int compareTo(Variable o)
compareTo in interface Comparable<Variable>compareTo in interface Variablepublic abstract int hashCode()
public abstract int getBERLength()
Variable in bytes when encoded
according to the Basic Encoding Rules (BER).getBERLength in interface BERSerializablepublic int getBERPayloadLength()
BERSerializableBERSerializable object
in bytes when encoded according to the Basic Encoding Rules (BER).getBERPayloadLength in interface BERSerializablepublic abstract void decodeBER(BERInputStream inputStream) throws IOException
Variable from an InputStream.decodeBER in interface BERSerializableinputStream - an InputStream containing a BER encoded byte stream.IOException - if the stream could not be decoded by using BER rules.public abstract void encodeBER(OutputStream outputStream) throws IOException
Variable to an OutputStream.encodeBER in interface BERSerializableoutputStream - an OutputStream.IOException - if an error occurs while writing to the stream.public static Variable createFromBER(BERInputStream inputStream) throws IOException
Variable from a BER encoded InputStream.
Subclasses of Variable are registered using the properties file
smisyntaxes.properties in this package. The properties are
read when this method is called first.inputStream - an BERInputStream containing a BER encoded byte stream.Variable.IOException - if the inputStream is not properly BER encoded.public static Variable createFromSyntax(int smiSyntax)
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.smiSyntax - an SMI syntax identifier of the registered types, which is typically
defined by SMIConstants.Variable variable instance of the supplied SMI syntax.public abstract int getSyntax()
public boolean isException()
isException in interface Variabletrue if the syntax of this variable is an instance of
Null and its syntax equals one of the following:
public abstract String toString()
public abstract int toInt()
toInt in interface VariableUnsupportedOperationException - if an integer representation
does not exists for this Variable.public abstract long toLong()
toLong in interface VariableUnsupportedOperationException - if a long representation
does not exists for this Variable.public abstract Object clone()
Variablepublic static String getSyntaxString(int syntax)
syntax - the BER code of the syntax.syntax
as used in the Structure of Management Information (SMI) modules.
'?' is returned if the supplied syntax is unknown.public final String getSyntaxString()
getSyntaxString in interface Variablepublic static int getSyntaxFromString(String syntaxString)
getSyntaxString(int)).syntaxString - the textual representation of the syntax.public abstract OID toSubIndex(boolean impliedLength)
Variable to a (sub-)index
value.toSubIndex in interface VariableimpliedLength - 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.UnsupportedOperationException - if this variable cannot be used in an index.public abstract void fromSubIndex(OID subIndex, boolean impliedLength)
Variable from the supplied (sub-)index.fromSubIndex in interface VariablesubIndex - 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.UnsupportedOperationException - if this variable cannot be used in an index.public boolean isDynamic()
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).public static boolean equal(AbstractVariable a, AbstractVariable b)
a - a variable.b - another variable.true if
a == null) ? (b == null) : a.equals(b).Copyright © 2016 SNMP4J.org. All Rights Reserved.