- java.lang.Object
-
- org.snmp4j.smi.VariableBinding
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,BERSerializable
public class VariableBinding extends java.lang.Object implements java.io.Serializable, BERSerializable, java.lang.Cloneable
AVariableBindingis an association of a object instance identifier (OID) and the instance's value (Variable).- Version:
- 1.9
- Author:
- Frank Fock
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description VariableBinding()Creates a variable binding with a zero length OID and aNullvalue.VariableBinding(OID oid)Creates a variable binding with the supplied object instance identifier and aNullvalue.VariableBinding(OID oid, java.lang.String variableText)Creates a variable binding with the supplied OID and a text value.VariableBinding(OID oid, Variable variable)Creates a variable binding with the supplied OID and value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()static VariableBinding[]createFromOIDs(OID[] oids)Create an array ofVariableBindings based on the provided OIDs.voiddecodeBER(BERInputStream inputStream)Decodes aVariablefrom anInputStream.voidencodeBER(java.io.OutputStream outputStream)Encodes aVariableto anOutputStream.booleanequals(java.lang.Object o)intgetBERLength()Returns the length of thisBERSerializableobject in bytes when encoded according to the Basic Encoding Rules (BER).intgetBERPayloadLength()Returns the length of the payload of thisBERSerializableobject in bytes when encoded according to the Basic Encoding Rules (BER).OIDgetOid()Gets the object instance identifier of the variable binding.intgetSyntax()Gets the syntax of the variable bindings value.VariablegetVariable()Gets the value of the variable binding.inthashCode()booleanisException()Returns whether the variable bindings value has an exception syntax.voidsetOid(OID oid)Sets the object instance identifier for the variable binding.voidsetVariable(Variable variable)Sets the value of the variable binding.java.lang.StringtoString()Gets a string representation of this variable binding using theVariableTextFormatconfigured bySNMP4JSettings.java.lang.StringtoValueString()Gets a string representation of this variable binding's value using theVariableTextFormatconfigured bySNMP4JSettings.
-
-
-
Constructor Detail
-
VariableBinding
public VariableBinding()
Creates a variable binding with a zero length OID and aNullvalue.
-
VariableBinding
public VariableBinding(OID oid)
Creates a variable binding with the supplied object instance identifier and aNullvalue.- Parameters:
oid- the OID for the new variable binding.
-
VariableBinding
public VariableBinding(OID oid, Variable variable)
Creates a variable binding with the supplied OID and value.- Parameters:
oid- the OID for the new variable binding (must not benull).variable- the value for the new variable binding (must not benull).
-
VariableBinding
public VariableBinding(OID oid, java.lang.String variableText) throws java.text.ParseException
Creates a variable binding with the supplied OID and a text value. The text value is parsed based on MIB information to a Variable using theVariableTextFormatset bySNMP4JSettings.setVariableTextFormat(org.snmp4j.util.VariableTextFormat). The defaultSimpleVariableTextFormatdoes not support this operation. To be able to use this constructor, register theSmiManagerof SNMP4J-SMI instead asVariableTextFormatinstead.
-
-
Method Detail
-
getOid
public OID getOid()
Gets the object instance identifier of the variable binding.- Returns:
- an
OID.
-
setOid
public void setOid(OID oid)
Sets the object instance identifier for the variable binding.- Parameters:
oid- an OID (must not benull) that is cloned when added to this binding.
-
setVariable
public void setVariable(Variable variable)
Sets the value of the variable binding.- Parameters:
variable- aVariable(must not benull) that is cloned when added to this binding.
-
getVariable
public Variable getVariable()
Gets the value of the variable binding.- Returns:
- a
Variableinstance.
-
getSyntax
public final int getSyntax()
Gets the syntax of the variable bindings value.- Returns:
- a SMI syntax identifier (see
SMIConstants).
-
isException
public boolean isException()
Returns whether the variable bindings value has an exception syntax.- Returns:
trueif the syntax of this variable is an instance ofNulland its syntax equals one of the following:- See Also:
Variable
-
getBERPayloadLength
public final 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.
-
getBERLength
public final int getBERLength()
Description copied from interface:BERSerializableReturns the length of thisBERSerializableobject in bytes when encoded according to the Basic Encoding Rules (BER).- Specified by:
getBERLengthin interfaceBERSerializable- Returns:
- the BER encoded length of this variable.
-
decodeBER
public final void decodeBER(BERInputStream inputStream) throws java.io.IOException
Description copied from interface:BERSerializableDecodes aVariablefrom anInputStream.- Specified by:
decodeBERin interfaceBERSerializable- Parameters:
inputStream- anInputStreamcontaining a BER encoded byte stream.- Throws:
java.io.IOException- if the stream could not be decoded by using BER rules.
-
encodeBER
public final void encodeBER(java.io.OutputStream outputStream) throws java.io.IOExceptionDescription copied from interface:BERSerializableEncodes aVariableto anOutputStream.- Specified by:
encodeBERin interfaceBERSerializable- Parameters:
outputStream- anOutputStream.- Throws:
java.io.IOException- if an error occurs while writing to the stream.
-
toString
public java.lang.String toString()
Gets a string representation of this variable binding using theVariableTextFormatconfigured bySNMP4JSettings.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string of the form
<OID> = <Variable>.
-
toValueString
public java.lang.String toValueString()
Gets a string representation of this variable binding's value using theVariableTextFormatconfigured bySNMP4JSettings.- Returns:
- a string of the form
<Variable>. - Since:
- 1.10
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
createFromOIDs
public static VariableBinding[] createFromOIDs(OID[] oids)
Create an array ofVariableBindings based on the provided OIDs.- Parameters:
oids- an array of OIDs (must not be null).- Returns:
- an array of
VariableBindings where each the n-th binding's OID is the n-th OID out ofoids. - Since:
- 2.1
-
-