com.adventnet.snmp.snmp2
Class SnmpVar

java.lang.Object
  |
  +--com.adventnet.snmp.snmp2.SnmpVar
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
SnmpBitstring, SnmpCounter64, SnmpInt, SnmpIpv4Address, SnmpIpv6Address, SnmpNull, SnmpOID, SnmpString, SnmpUnsignedInt

public abstract class SnmpVar
extends java.lang.Object
implements java.io.Serializable

This class provides the abstract methods to present a uniform interface for applications working with the SNMP variables and is the base class for all SNMP Variable class(integer, IpAddress, etc). This and all its derived classes (called variable classes) are mainly concerned mainly with creating new SNMP variables, retrieve the value of the variable both as an object and in printable form.

Some explanation regarding the relationship between toValue and getVarObject methods: These methods do the same thing in all the SnmpVar classes except SnmpIpAddress, SnmpNetworkAddress and SnmpOID. For these three and its derived classes, the getVarObject and toString do the same thing. e.g.

S.No
Classname
toValue( )
getVarObject( )
1
SnmpIpAddressReturns IP address as String for byte[ ]
i.e 7F000001
Returns IP Address in dotted notation
as a String object. i.e 127.0.0.1
2
SnmpNetworkAddress Same as SnmpIpAddress Same as SnmpIpAddress
3
SnmpOID Returns int[ ] of the OID value
i.e int [ ] = {1, 3, 6, 1, 2, 1, 1, 1}
for sysDescr in RFC1213-MIB
Returns dotted OID as String object
i.e "1.3.6.1.2.1.1.1"
for sysDescr in RFC1213-MIB

For the rest of the SNMP variable classes namely SnmpBitString, SnmpCounter64, SnmpNull, SnmpInt, SnmpUnsignedInt, SnmpTimeticks, SnmpCounter, SnmpGauge, SnmpString, SnmpNsap and SnmpOpaque the toValue() and getVarObject() do the same thing.

See Also:
Serialized Form

Method Summary
static SnmpVar createVariable(java.lang.String value, byte type)
          Creates a new SnmpVar object with the specified type and value.
 byte getError()
          v2c and v3 only Used only by SnmpNULL at present to store the error value in case of snmpv2 response PDUs.
 java.lang.String getNumericValueAsString()
          This method returns the numeric value of the SNMP data types in decimal ( base 10 ) format.
 byte getType()
          Returns type, defined by SnmpAPI types, e.g.SnmpAPI.INTEGER .
 java.lang.String getTypeString()
          Returns type as a string, e.g.INTEGER, OCTET STRING based on the type of SnmpVar object.
abstract  java.lang.Object getVarObject()
          Abstract method which returns value of SNMP variable as an appropriate Object type, e.g.
abstract  byte[] toBytes()
          Abstract method to return the value as raw bytes.
abstract  java.lang.String toString()
          Abstract method to convert to printable string used in printing variables.
abstract  java.lang.String toTagString()
          Abstract method to convert to printable string with object type tag used in printing variables more descriptively, e.g.
abstract  java.lang.Object toValue()
          Abstract method which returns the value of SNMP variable as an appropriate Object type, e.g.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getType

public byte getType()
Returns type, defined by SnmpAPI types, e.g.SnmpAPI.INTEGER .

Returns:
the SNMP type of the SnmpVar object. The type is one from the constants in SnmpAPI.
See Also:
SnmpAPI

getTypeString

public java.lang.String getTypeString()
Returns type as a string, e.g.INTEGER, OCTET STRING based on the type of SnmpVar object.

Returns:
the SNMP type of the SnmpVar object as a string.

getError

public byte getError()
v2c and v3 only Used only by SnmpNULL at present to store the error value in case of snmpv2 response PDUs. Returns error Value, defined by SnmpAPI definitions

Returns:
the error Value, defined by SnmpAPI definitions.

getNumericValueAsString

public java.lang.String getNumericValueAsString()
This method returns the numeric value of the SNMP data types in decimal ( base 10 ) format. The various data-types that will return the numeric values are SnmpAPI.INTEGER, SNMPAPI.COUNTER, SnmpAPI.GAUGE, SnmpAPI.UNSIGNED32, SnmpAPI.TIMETICKS and SnmpAPI.COUNTER64. All these datatypes will return their respective numeric values in decimal format. The other data types will throw an UnsupportedOperationException if this method is called.

Returns:
The numeric value of the data type in decimal format.

getVarObject

public abstract java.lang.Object getVarObject()
Abstract method which returns value of SNMP variable as an appropriate Object type, e.g. Integer, String, etc. This method does the same thing as toValue() in all the SnmpVar classes except SnmpIpAddress, SnmpNetworkAddress and SnmpOID.

Returns:
The value of the SnmpVar object as an appropriate object

toValue

public abstract java.lang.Object toValue()
Abstract method which returns the value of SNMP variable as an appropriate Object type, e.g. Integer, String, etc.

Returns:
The value of the SnmpVar object as an appropriate object

toBytes

public abstract byte[] toBytes()
Abstract method to return the value as raw bytes.

Returns:
the value of this SnmpVar object as raw bytes.

toString

public abstract java.lang.String toString()
Abstract method to convert to printable string used in printing variables.

Overrides:
toString in class java.lang.Object
Returns:
the SnmpVar object as a printable string.

toTagString

public abstract java.lang.String toTagString()
Abstract method to convert to printable string with object type tag used in printing variables more descriptively, e.g. INTEGER: value.

Returns:
the SnmpVar object as a printable String more descriptively with type of the SnmpVar object.

createVariable

public static SnmpVar createVariable(java.lang.String value,
                                     byte type)
                              throws SnmpException
Creates a new SnmpVar object with the specified type and value.

Parameters:
value - The value for creating a new SnmpVar object.
type - The SNMP type (a constant from SnmpAPI) for creating a new SnmpVar object.
Returns:
the SnmpVar object created.
Throws:
SnmpException - is thrown when variable creation error occurs.


Copyright (c)ZOHO Corp. 1996-2012