com.adventnet.snmp.snmp2
Class SnmpOID

java.lang.Object
  |
  +--com.adventnet.snmp.snmp2.SnmpVar
        |
        +--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 SnmpOID. 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:
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

Constructor Summary
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
 boolean equals(java.lang.Object anObject)
          Compares this SnmpOID to the specified object.
 java.lang.Object getVarObject()
          Returns the value of this SnmpOID as a printable string.
 int hashCode()
          Returns a hash code value for this SnmpOID.
 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
 

Constructor Detail

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 OIDs.
Method Detail

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.
Overrides:
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] = 2147483647


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.

toBytes

public byte[] toBytes()
Returns the value of this SnmpOID as raw bytes.
Overrides:
toBytes in class SnmpVar
Returns:
the value of this SnmpOID as raw bytes.

getVarObject

public java.lang.Object getVarObject()
Returns the value of this SnmpOID as a printable string. Eg. If OID is 1.1.0, then this method returns the ObjectID "1.1.0" as a String Object. This method is the same as toString().
Overrides:
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.
Overrides:
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" .
Overrides:
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.


Copyright (c)AdventNet Inc., 1996-2004