Package org.snmp4j.smi
Class AbstractVariable
java.lang.Object
org.snmp4j.smi.AbstractVariable
- All Implemented Interfaces:
 Serializable,Cloneable,Comparable<Variable>,BERSerializable,Variable
- Direct Known Subclasses:
 Counter64,Integer32,Null,OctetString,OID,SMIAddress,UnsignedInteger32,VariantVariable
The 
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.
- Since:
 - 1.8
 - Version:
 - 1.8
 - Author:
 - Frank Fock, Jochen Katz
 - See Also:
 
- 
Field Summary
Fields - 
Constructor Summary
ConstructorsConstructorDescriptionThe abstractVariableclass serves as the base class for all specific SNMP syntax types. - 
Method Summary
Modifier and TypeMethodDescriptionabstract Objectclone()Clones this variable.abstract intstatic VariablecreateFromBER(BERInputStream inputStream) Creates aVariablefrom a BER encodedBERInputStream.static VariablecreateFromSyntax(int smiSyntax) Creates aVariablefrom the supplied SMI syntax identifier.abstract voiddecodeBER(BERInputStream inputStream) Decodes aVariablefrom anBERInputStream.abstract voidencodeBER(OutputStream outputStream) Encodes aVariableto anOutputStream.static booleanTests if two variables have the same value.abstract booleanabstract voidfromSubIndex(OID subIndex, boolean impliedLength) Sets the value of thisVariablefrom the supplied (sub-)index.abstract intReturns the length of thisVariablein bytes when encoded according to the Basic Encoding Rules (BER).intReturns the length of the payload of thisBERSerializableobject in bytes when encoded according to the Basic Encoding Rules (BER).abstract intGets the ASN.1 syntax identifier value of this SNMP variable.static intgetSyntaxFromString(String syntaxString) Returns the BER syntax ID for the supplied syntax string (as returned bygetSyntaxString(int)).final StringGets a textual description of this Variable.static StringgetSyntaxString(int syntax) Gets a textual description of the supplied syntax type.abstract inthashCode()booleanIndicates whether this variable is dynamic, which means that it might change its value while it is being (BER) serialized.booleanChecks whether this variable represents an exception like noSuchObject, noSuchInstance, and endOfMibView.abstract inttoInt()Returns an integer representation of this variable if such a representation exists.abstract longtoLong()Returns a long representation of this variable if such a representation exists.abstract StringtoString()Gets a string representation of the variable.abstract OIDtoSubIndex(boolean impliedLength) Converts the value of thisVariableto a (sub-)index value. 
- 
Field Details
- 
SMISYNTAXES_PROPERTIES
- See Also:
 
 
 - 
 - 
Constructor Details
- 
AbstractVariable
public AbstractVariable()The abstractVariableclass serves as the base class for all specific SNMP syntax types. 
 - 
 - 
Method Details
- 
equals
 - 
compareTo
- Specified by:
 compareToin interfaceComparable<Variable>- Specified by:
 compareToin interfaceVariable
 - 
hashCode
public abstract int hashCode() - 
getBERLength
public abstract int getBERLength()Returns the length of thisVariablein bytes when encoded according to the Basic Encoding Rules (BER).- Specified by:
 getBERLengthin interfaceBERSerializable- Returns:
 - the BER encoded length of this variable.
 
 - 
getBERPayloadLength
public int getBERPayloadLength()Description copied from interface:BERSerializableReturns the length of the payload of thisBERSerializableobject in bytes when encoded according to the Basic Encoding Rules (BER).- Specified by:
 getBERPayloadLengthin interfaceBERSerializable- Returns:
 - the BER encoded length of this variable.
 
 - 
decodeBER
Decodes aVariablefrom anBERInputStream.- Specified by:
 decodeBERin interfaceBERSerializable- Parameters:
 inputStream- anBERInputStreamcontaining a BER encoded byte stream.- Throws:
 IOException- if the stream could not be decoded by using BER rules.
 - 
encodeBER
Encodes aVariableto anOutputStream.- Specified by:
 encodeBERin interfaceBERSerializable- Parameters:
 outputStream- anOutputStream.- Throws:
 IOException- if an error occurs while writing to the stream.
 - 
createFromBER
Creates aVariablefrom a BER encodedBERInputStream. Subclasses ofVariableare registered using the properties filesmisyntaxes.propertiesin this package. The properties are read when this method is called first.- Parameters:
 inputStream- anBERInputStreamcontaining a BER encoded byte stream.- Returns:
 - an instance of a subclass of 
Variable. - Throws:
 IOException- if theinputStreamis not properly BER encoded.
 - 
createFromSyntax
Creates aVariablefrom the supplied SMI syntax identifier. Subclasses ofVariableare registered using the properties filesmisyntaxes.propertiesin 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 bySMIConstants.- Returns:
 - a 
Variablevariable instance of the supplied SMI syntax. 
 - 
getSyntax
public abstract int getSyntax()Gets the ASN.1 syntax identifier value of this SNMP variable. - 
isException
public boolean isException()Checks whether this variable represents an exception like noSuchObject, noSuchInstance, and endOfMibView.- Specified by:
 isExceptionin interfaceVariable- Returns:
 trueif the syntax of this variable is an instance ofNulland its syntax equals one of the following:
 - 
toString
Gets a string representation of the variable. - 
toInt
public abstract int toInt()Returns an integer representation of this variable if such a representation exists.- Specified by:
 toIntin interfaceVariable- 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:
 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:
 toLongin interfaceVariable- Returns:
 - a long value.
 - Throws:
 UnsupportedOperationException- if a long representation does not exists for this Variable.- Since:
 - 1.7
 
 - 
clone
Description copied from interface:VariableClones 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. - 
getSyntaxString
Gets a textual description of the supplied syntax type.- Parameters:
 syntax- the BER code of the syntax.- Returns:
 - a textual description like 'Integer32' for 
syntaxas used in the Structure of Management Information (SMI) modules. '?' is returned if the supplied syntax is unknown. 
 - 
getSyntaxString
Gets a textual description of this Variable.- Specified by:
 getSyntaxStringin interfaceVariable- 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
Returns the BER syntax ID for the supplied syntax string (as returned bygetSyntaxString(int)).- Parameters:
 syntaxString- the textual representation of the syntax.- Returns:
 - the corresponding BER ID.
 - Since:
 - 1.6
 
 - 
toSubIndex
Converts the value of thisVariableto a (sub-)index value.- Specified by:
 toSubIndexin interfaceVariable- Parameters:
 impliedLength- specifies if the sub-index has an implied length. This parameter applies to variable length variables only (e.g.OctetStringandOID). For other variables it has no effect.- Returns:
 - an OID that represents this value as an (sub-)index.
 - Throws:
 UnsupportedOperationException- if this variable cannot be used in an index.- Since:
 - 1.7
 
 - 
fromSubIndex
Sets the value of thisVariablefrom the supplied (sub-)index.- Specified by:
 fromSubIndexin interfaceVariable- 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.OctetStringandOID). For other variables it has no effect.- Throws:
 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 aPDUwithPDU.add(VariableBinding). By cloning the value, it is ensured that there are no inconsistent changes between determining the length withgetBERLength()for encoding enclosing SEQUENCES and the actual encoding of the Variable itself withencodeBER(java.io.OutputStream). - 
equal
Tests if two variables have the same value.- Parameters:
 a- a variable.b- another variable.- Returns:
 trueifa == null) ? (b == null) : a.equals(b).- Since:
 - 2.0
 
 
 -