Package org.opennms.protocols.snmp
Class SnmpVarBind
- java.lang.Object
-
- org.opennms.protocols.snmp.SnmpVarBind
-
- All Implemented Interfaces:
Serializable
,Cloneable
,SnmpSyntax
public class SnmpVarBind extends Object implements SnmpSyntax, Cloneable, 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
-
Constructor Summary
Constructors Constructor Description SnmpVarBind()
The default class constructor.SnmpVarBind(String name)
Constructs a new variable with the give name.SnmpVarBind(String name, SnmpSyntax value)
Constructs a new variable with the passed name and value.SnmpVarBind(SnmpObjectId name)
Constructs a specific variable with the "name" equal to the passed object identifier.SnmpVarBind(SnmpObjectId name, SnmpSyntax value)
Constructs a variable with the passed name and value.SnmpVarBind(SnmpVarBind second)
Class copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
clone()
Returns a newly created duplicate object to the callerint
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 callerint
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(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 variableString
toString()
Converts the object to a string representationbyte
typeId()
Returns the ASN.1 type id for the object.
-
-
-
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()
The default class constructor. Constructs an SnmpVarBind with a default object identifier and a null value
-
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 namevalue
- The syntax object.
-
SnmpVarBind
public SnmpVarBind(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(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 namevalue
- 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(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 interfaceSnmpSyntax
- 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 interfaceSnmpSyntax
- Parameters:
buf
- Storeage for the encoded dataoffset
- Offset to start encoding dataencoder
- 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 interfaceSnmpSyntax
- Parameters:
buf
- Encoded ASN.1 dataoffset
- Offset to first byte of encoded dataencoder
- 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 interfaceSnmpSyntax
- Returns:
- A newly created variable
-
clone
public Object clone()
Returns a newly created duplicate object to the caller
-
-