com.sun.jaw.snmp.common
Class SnmpOid

java.lang.Object
  |
  +--com.sun.jaw.snmp.common.SnmpValue
        |
        +--com.sun.jaw.snmp.common.SnmpOid
Direct Known Subclasses:
SnmpIpAddress

public class SnmpOid
extends SnmpValue

The SnmpOid class represents an SNMP oid.

See Also:
Serialized Form

Field Summary
protected  int componentCount
          The length of the components array.
protected  long[] components
          The components array.
static MibStoreIfSrv meta
          Reference to a mib store service.
 
Constructor Summary
SnmpOid()
          Constructs a new SnmpOid with no components.
SnmpOid(long id)
          Constructs a new SnmpOid containing one component with the specified value.
SnmpOid(long[] oidComponents)
          Constructs a new SnmpOid from the specified component array.
SnmpOid(long id1, long id2, long id3, long id4)
          Constructs a new SnmpOid containing four components with the specified values.
SnmpOid(java.lang.String s)
          Constructs a new SnmpOid from a dot-formatted String or a MIB variable name.
 
Method Summary
 void addToOid(long[] oid)
          Adds the specified array of longs to the end of this SnmpOid.
 void addToOid(java.lang.String s)
          Adds the specified dot-formatted oid String to the end of this SnmpOid.
 void append(long id)
          Appends the specified long to the end of this SnmpOid.
 void append(SnmpOid oid)
          Appends the specified SnmpOid to the end of this SnmpOid.
static void appendToOid(SnmpOid source, SnmpOid dest)
          Appends an SnmpOid representing an SnmpOid to another oid.
 java.lang.Object clone()
          Clones the SnmpOid object, making a copy of its data.
 int compareTo(SnmpOid other)
          Compares two oids lexicographically.
 SnmpValue duplicate()
          Performs a clone action.
protected  void enlargeIfNeeded(int n)
          Checks if there is enough space in the components array to insert n new subids.
 boolean equals(java.lang.Object o)
          Checks if the specified Object is equal to this SnmpOid.
 int getLength()
          Gets the number of components in this oid.
 java.lang.String getTypeName()
          Returns a textual description of the type object.
 int hashCode()
          Returns a hashcode for this SnmpOid.
 void insert(int id)
          Inserts a subid at the beginning of this SnmpOid.
 void insert(long id)
          Inserts a subid at the beginning of this SnmpOid.
 boolean isValid()
          Checks the validity of the oid.
 long[] longValue()
          Returns a copy of the components array of this SnmpOid.
static int nextOid(long[] index, int start)
          Scans an index oid, skips the oid value and returns the position of the next value.
 java.lang.String resolveVarName(java.lang.String s)
          Resolves a MIB variable String with the MIB database.
 java.lang.Boolean toBoolean()
          Converts the oid value to its Boolean form.
 java.lang.Byte[] toByte()
          Converts the oid value to its array of Bytes form.
 java.lang.Integer toInteger()
          Converts the oid value to its Integer form.
 java.lang.Long toLong()
          Converts the oid value to its Long form.
 SnmpOid toOid()
          Converts the oid value to its SnmpOid form.
static SnmpOid toOid(long[] index, int start)
          Extracts the oid from an index oid and returns its value converted as an SnmpOid.
 java.lang.String toString()
          Converts the oid value to its String form.
 
Methods inherited from class com.sun.jaw.snmp.common.SnmpValue
toAsn1String
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

components

protected long[] components
The components array.

componentCount

protected int componentCount
The length of the components array.

meta

public static MibStoreIfSrv meta
Reference to a mib store service. If no mib store service is available, the class will not be able to resolve names contained in the Object Identifier.
Constructor Detail

SnmpOid

public SnmpOid()
Constructs a new SnmpOid with no components.

SnmpOid

public SnmpOid(long[] oidComponents)
Constructs a new SnmpOid from the specified component array.
Parameters:
oidComponents - The initialization component array.

SnmpOid

public SnmpOid(long id)
Constructs a new SnmpOid containing one component with the specified value.
Parameters:
id - The initialization component value.

SnmpOid

public SnmpOid(long id1,
               long id2,
               long id3,
               long id4)
Constructs a new SnmpOid containing four components with the specified values.
Parameters:
idx - The initialization component values.

SnmpOid

public SnmpOid(java.lang.String s)
        throws java.lang.IllegalArgumentException
Constructs a new SnmpOid from a dot-formatted String or a MIB variable name. It generates an exception if the variable name cannot be resolved or if the dot-formatted String has invalid subidentifier. This constructor helps build an oid object with a String like .1.2.3.4 or 1.2.3.4 or ifInOctets or ifInOctets.0.
Parameters:
s - String or MIB variable of the form .1.2.3 or 1.2.3 or ifInOctets.
Throws:
java.lang.IllegalArgumentException - The subidentifier is neither a numeric String nor a String of the MIB database.
Method Detail

getLength

public int getLength()
Gets the number of components in this oid.
Returns:
The number of components.

longValue

public long[] longValue()
Returns a copy of the components array of this SnmpOid.
Returns:
The copy of the components array.

toLong

public java.lang.Long toLong()
Converts the oid value to its Long form.
Returns:
The Long representation of the value.

toInteger

public java.lang.Integer toInteger()
Converts the oid value to its Integer form.
Returns:
The Integer representation of the value.

toString

public java.lang.String toString()
Converts the oid value to its String form.
Returns:
The String representation of the value.
Overrides:
toString in class java.lang.Object

toBoolean

public java.lang.Boolean toBoolean()
Converts the oid value to its Boolean form.
Returns:
The Boolean representation of the value.

toByte

public java.lang.Byte[] toByte()
Converts the oid value to its array of Bytes form.
Returns:
The array of Bytes representation of the value.

toOid

public SnmpOid toOid()
Converts the oid value to its SnmpOid form.
Returns:
The oid representation of the value.
Overrides:
toOid in class SnmpValue

hashCode

public int hashCode()
Returns a hashcode for this SnmpOid.
Returns:
A hashcode.
Overrides:
hashCode in class java.lang.Object

toOid

public static SnmpOid toOid(long[] index,
                            int start)
                     throws SnmpStatusException
Extracts the oid from an index oid and returns its value converted as an SnmpOid.
Parameters:
index - The index array.
start - The position in the index array.
Returns:
The oid representing the oid value.
Throws:
SnmpStatusException - There is no oid value available at start position.

nextOid

public static int nextOid(long[] index,
                          int start)
                   throws SnmpStatusException
Scans an index oid, skips the oid value and returns the position of the next value.
Parameters:
index - The index array.
start - The position in the index array.
Returns:
The position of the next value.
Throws:
SnmpStatusException - There is no oid value available at start position.

appendToOid

public static void appendToOid(SnmpOid source,
                               SnmpOid dest)
Appends an SnmpOid representing an SnmpOid to another oid.
Parameters:
source - An oid representing an SnmpOid value.
dest - Where source should be appened.

duplicate

public final SnmpValue duplicate()
Performs a clone action. This provides a workaround for the SnmpValue interface.
Returns:
The SnmpValue clone.
Overrides:
duplicate in class SnmpValue

clone

public java.lang.Object clone()
Clones the SnmpOid object, making a copy of its data.
Returns:
The Object clone.
Overrides:
clone in class java.lang.Object

insert

public void insert(long id)
Inserts a subid at the beginning of this SnmpOid.
Parameters:
id - The long subid to insert.

insert

public void insert(int id)
Inserts a subid at the beginning of this SnmpOid.
Parameters:
id - The integer subid to insert.

append

public void append(SnmpOid oid)
Appends the specified SnmpOid to the end of this SnmpOid.
Parameters:
oid - The oid to append.

append

public void append(long id)
Appends the specified long to the end of this SnmpOid.
Parameters:
id - The long to append.

addToOid

public void addToOid(java.lang.String s)
              throws SnmpStatusException
Adds the specified dot-formatted oid String to the end of this SnmpOid. The subidentifiers can be expressed as a dot-formatted String or a MIB variable name.
Parameters:
s - Variable name of the form .1.2.3 or 1.2.3 or ifInOctets.
Throws:
SnmpStatusException - An error occurred while accessing a MIB node.

addToOid

public void addToOid(long[] oid)
              throws SnmpStatusException
Adds the specified array of longs to the end of this SnmpOid.
Parameters:
oid - An array of longs.
Throws:
SnmpStatusException - An error occurred while accessing a MIB node.

isValid

public boolean isValid()
Checks the validity of the oid.
Returns:
True if the oid is valid; false otherwise.

equals

public boolean equals(java.lang.Object o)
Checks if the specified Object is equal to this SnmpOid.
Parameters:
o - The Object to be compared.
Returns:
True if o is an SnmpOid instance and equals to this; false otherwise.
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(SnmpOid other)
Compares two oids lexicographically.
Parameters:
other - The oid to be compared.
Returns:
The value 0 if the argument other is equal to this SnmpOid. A value smaller than 0 if this SnmpOid is lexicographically smaller than other. A value larger than 0 if this SnmpOid is lexicographically larger than other.

resolveVarName

public java.lang.String resolveVarName(java.lang.String s)
                                throws SnmpStatusException
Resolves a MIB variable String with the MIB database.
Parameters:
s - The variable name to resolve.
Throws:
SnmpStatusException - If the variable is not found in MIB database.

getTypeName

public java.lang.String getTypeName()
Returns a textual description of the type object.
Returns:
ASN.1 textual description.
Overrides:
getTypeName in class SnmpValue

enlargeIfNeeded

protected void enlargeIfNeeded(int n)
Checks if there is enough space in the components array to insert n new subids. If not, it increases the size of the array. In fact it reallocates a new array and copy the old one into the new one.
Parameters:
n - The number of subids to insert.