com.adventnet.snmp.snmp2
Class SnmpOID

java.lang.Object
  extended by com.adventnet.snmp.snmp2.SnmpVar
      extended by com.adventnet.snmp.snmp2.SnmpOID
All Implemented Interfaces:
java.io.Serializable

public class SnmpOID
extends SnmpVar

Class of SNMP Object ID - Sub-class of SnmpVar This class can be used to create an SnmpVar object of type OBJECT IDENTIFIER. It also has methods to retrieve the value in different forms(eg. String, byte array, int array, long array).

Some examples for valid OID are:
SnmpOID oid1 = new SnmpOID("1.1.0");
SnmpOID oid2 = new SnmpOID(".1.3.6.1.2.1.1.1.0");

An Invalid oid will be
SnmpOID oid3 = new SnmpOID(".iso.org.dod.internet.mgmt.mib-2.system.sysDescr");
as the argument will not accept names in the OID.

Note:
Since the constructor does not report about the invalidity of the arguments, a better way to identify whether an SnmpOID is constructed succesfully or not is:
SnmpOID oid4 = new SnmpOID("1.1.0");
if(oid4.toValue() != null)
{
    System.out.println("SnmpOID successfully created");
}
else
{
    System.out.println("There is some problem in creating SnmpOID");
}

See Also:
Serialized Form

Field Summary
(package private)  byte[] byteValue
           
(package private)  int[] value
          The value of the Object ID
 
Fields inherited from class com.adventnet.snmp.snmp2.SnmpVar
Type, varbindErrorVal
 
Constructor Summary
SnmpOID()
          Constructs a new SnmpOID with the value null.
SnmpOID(int[] oid)
          Constructs a new SnmpOID by taking an array of ints as an argument.
SnmpOID(java.lang.String s)
          Constructs a new SnmpOID which requires the argument to be a String OID of the form .N.N.N, or N.N.N.
 
Method Summary
(package private)  long[] convertIntArrayToLongArray(int[] intArray)
          Converts an int array to a long array
(package private)  int encode(byte[] buff, int space)
          ASN encoder
 boolean equals(java.lang.Object anObject)
          Compares this SnmpOID to the specified object.
static SnmpOID getLexicographicallyFirstOID(SnmpOID[] oids)
          The method finds the lexicographically first oid in the list of two oids given.
static SnmpOID getLexicographicallyFirstOID(SnmpOID oid1, SnmpOID oid2)
          The method finds the lexicographically first oid in the list of two oids given.
 java.lang.String getNumericValueAsString()
          This method will throw UnsupportedOperationException since this is not a numeric data type.
 java.lang.Object getVarObject()
          Returns the value of this SnmpOID as a printable string.
 int hashCode()
          Returns a hash code value for this SnmpOID.
(package private) static SnmpOID newInstance(int[] oid)
          Factory method for decode
 byte[] toBytes()
          Returns the value of this SnmpOID as raw bytes.
 int[] toIntArray()
          
Returns the value of this SnmpOID value as an array of integers.
 long[] toLongArray()
          Returns the value of this SnmpOID as an array of long.
 java.lang.String toString()
          Converts the value of this SnmpOID object to a printable string used in printing.
 java.lang.String toTagString()
          Converts the value of this SnmpOID object to a printable string where the type is tagged before the value with a tag "Object ID: ".
 java.lang.Object toValue()
          Returns the value of this SnmpOID object as an array of ints.
 
Methods inherited from class com.adventnet.snmp.snmp2.SnmpVar
createVariable, getError, getType, getTypeString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

value

int[] value
The value of the Object ID


byteValue

byte[] byteValue
Constructor Detail

SnmpOID

SnmpOID()
Constructs a new SnmpOID with the value null.


SnmpOID

public SnmpOID(java.lang.String s)
Constructs a new SnmpOID which requires the argument to be a String OID of the form .N.N.N, or N.N.N. If the given OID does not start with a dot then the static Standard_Prefix(.1.3.6.1.2.1.) in the SnmpAPI class will be prepended with the given OID. Here N should be a number, not a name.

Parameters:
s - A String OID of the form .N.N.N, or N.N.N where N is a number and not a name.

SnmpOID

public SnmpOID(int[] oid)
Constructs a new SnmpOID by taking an array of ints as an argument. The array of integers is the complete OID and method does not take any standard prefixes.

Parameters:
oid - The array of int values representing the OID's sub-identifiers.
Method Detail

newInstance

static SnmpOID newInstance(int[] oid)
Factory method for decode

Parameters:
oid - An integer array containing the sub-ids of an object-identifier.
Returns:
The SnmpOID

encode

int encode(byte[] buff,
           int space)
     throws java.lang.ArrayIndexOutOfBoundsException
Description copied from class: SnmpVar
ASN encoder

Specified by:
encode in class SnmpVar
Parameters:
buff - The buffer into which the value is to be encoded
space - The number of free bytes in the buffer
Returns:
The number of free bytes in the buffer
Throws:
throws - ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException

toValue

public java.lang.Object toValue()
Returns the value of this SnmpOID object as an array of ints. This method is same as that of toIntArray.

Specified by:
toValue in class SnmpVar
Returns:
the value of this SnmpOID object as an array of ints. will return `null', if this SnmpOID object has not constructed successfully.

toIntArray

public int[] toIntArray()


Returns the value of this SnmpOID value as an array of integers. The number of subOIDs in the OID is limited to a maximum of 128. The value of an OID component also ranges from 0 to 2**32 -1. That is, it ranges from 0 to 4294967295. All the sub-identifiers that are greater than 2147483647 will wrap around to the negative side of the `int'.


example 1:
SnmpOID oid1 = new SnmpOID(".1.0");
int[] first_arr = oid1.toIntArray();
now this array will contain the following
first_arr[0] = 1
first_arr[1] = 0


example 2:
SnmpOID oid2 = new SnmpOID(".1.2147483647");
int[] second_arr = oid2.toIntArray();
now this array will contain the following
second_arr[0] = 1
second_arr[1] = 2147483647


example 3:
SnmpOID oid3 = new SnmpOID(".1.2147483648");
int[] third_arr = oid3.toIntArray();
now this array will contain the following
third_arr[0] = 1
third_arr[1] = -2147483648


If the sub-identifiers are greater than 2147483647 than "toLongArray" can be used.

Returns:
The Object ID value of this SnmpOID as an array of ints will return `null', if this SnmpOID object has not constructed successfully.

toLongArray

public long[] toLongArray()
Returns the value of this SnmpOID as an array of long.

Returns:
the value of this SnmpOID as an array of long. will return `null', if this SnmpOID object has not constructed successfully.

convertIntArrayToLongArray

long[] convertIntArrayToLongArray(int[] intArray)
Converts an int array to a long array

Parameters:
intArray - Interger OID
Returns:
Long OID

toBytes

public byte[] toBytes()
Returns the value of this SnmpOID as raw bytes. The raw bytes are obtained by expressing each of the sub-identifier as 4 bytes.
 For example, if the oid is ".1.3.6", then the raw bytes will be
 rawBytes[0]  = 0;
 rawBytes[1]  = 0;
 rawBytes[2]  = 0;
 rawBytes[3]  = 1;

 rawBytes[4]  = 0;
 rawBytes[5]  = 0;
 rawBytes[6]  = 0;
 rawBytes[7]  = 3;

 rawBytes[8]  = 0;
 rawBytes[9]  = 0;
 rawBytes[10] = 0;
 rawBytes[11] = 6;
 

Specified by:
toBytes in class SnmpVar
Returns:
the value of this SnmpOID as raw bytes.

getLexicographicallyFirstOID

public static SnmpOID getLexicographicallyFirstOID(SnmpOID oid1,
                                                   SnmpOID oid2)
The method finds the lexicographically first oid in the list of two oids given. For example, if oid1 is .1.3.6.1.2.1.1.1.0 and oid½ is .1.3.6.1.2.1.1.2.0, then the method will return oid1, since oid1 is lesser than oid2 lexicographically.

Parameters:
oid1 - The SnmpOID for which the lexicographic order should be found
oid2 - The SnmpOID for which the lexicographic order should be found
Returns:
returns the lexicographically first oid among the two arguments. If any of the input arguments is null, then the method will return null.

getLexicographicallyFirstOID

public static SnmpOID getLexicographicallyFirstOID(SnmpOID[] oids)
The method finds the lexicographically first oid in the list of two oids given. For example, if oid1 is .1.3.6.1.2.1.1.1.0 and oid½ is .1.3.6.1.2.1.1.2.0, then the method will return oid1, since oid1 is lesser than oid2 lexicographically.

Parameters:
oids - The SnmpOID list in which the lexicographically first oid should be found.
Returns:
returns the lexicographically first oid among the OID array. If the input argument is null or of size 1, then the method will return null.

getVarObject

public java.lang.Object getVarObject()
Returns the value of this SnmpOID as a printable string. Eg. If OID is .1.3.6, then this method returns the ObjectID ".1.3.6" as a String Object. This method is the same as toString().

Specified by:
getVarObject in class SnmpVar
Returns:
the value of this SnmpOID as a printable string.

toString

public java.lang.String toString()
Converts the value of this SnmpOID object to a printable string used in printing. Eg. If OID is "1.1.0", then this method returns the ObjectID ".1.3.6.1.2.1.1.1.0" as a String Object.

Specified by:
toString in class SnmpVar
Returns:
the value of this SnmpOID as a printable string.

toTagString

public java.lang.String toTagString()
Converts the value of this SnmpOID object to a printable string where the type is tagged before the value with a tag "Object ID: ". For e.g if the SnmpOID has the value "1.1.0", then this method will return - "Object ID: .1.3.6.1.2.1.1.1.0" .

Specified by:
toTagString in class SnmpVar
Returns:
the value of SnmpOID object as a printable string where the type is tagged before the value with a Tag - "Object ID: ".

hashCode

public int hashCode()
Returns a hash code value for this SnmpOID. The hashCode is computed as follows:
If the oid is
String s = ".1.3.6.1.2.1.1.1.0";
then the hashCode is
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
using int arithmetic, where s[i] is the ith character of the string, n is the length of the string, and ^ indicates exponentiation. (The hash value of the empty string is zero.)

Overrides:
hashCode in class java.lang.Object
Returns:
The hash code value for this object.

equals

public boolean equals(java.lang.Object anObject)
Compares this SnmpOID to the specified object. The result is true only if the argument is not null and is an SnmpOID object that represents the same value as this object.

Overrides:
equals in class java.lang.Object
Parameters:
anObject - the object to compare this SnmpOID against.
Returns:
true if the SnmpOIDs are equal; false otherwise.

getNumericValueAsString

public java.lang.String getNumericValueAsString()
This method will throw UnsupportedOperationException since this is not a numeric data type.

Overrides:
getNumericValueAsString in class SnmpVar
Returns:
Nothing is returned since this method throws an exception.
Throws:
java.lang.UnsupportedOperationException - Since this is not a numeric data type.