Methods Summary |
---|
public void | addToOid(java.lang.String s)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.
SnmpOid suffix= new SnmpOid(s);
this.append(suffix);
|
public void | addToOid(long[] oid)Adds the specified array of longs to the end of this SnmpOid .
SnmpOid suffix= new SnmpOid(oid);
this.append(suffix);
|
public void | append(com.sun.jmx.snmp.SnmpOid oid)Appends the specified SnmpOid to the end of this SnmpOid .
enlargeIfNeeded(oid.componentCount) ;
for (int i = 0 ; i < oid.componentCount ; i++) {
components[componentCount + i] = oid.components[i] ;
}
componentCount += oid.componentCount ;
|
public void | append(long id)Appends the specified long to the end of this SnmpOid .
enlargeIfNeeded(1) ;
components[componentCount] = id ;
componentCount++ ;
|
public static void | appendToOid(com.sun.jmx.snmp.SnmpOid source, com.sun.jmx.snmp.SnmpOid dest)Appends an SnmpOid representing an SnmpOid to another OID.
dest.append(source.getLength()) ;
dest.append(source) ;
|
public java.lang.Object | clone()Clones the SnmpOid object, making a copy of its data.
try {
SnmpOid obj = (SnmpOid)super.clone() ;
obj.components = new long[this.componentCount] ;
System.arraycopy(this.components, 0, obj.components, 0,
this.componentCount) ;
return obj ;
} catch (CloneNotSupportedException e) {
throw new InternalError() ; // should never happen. VM bug.
}
|
public int | compareTo(com.sun.jmx.snmp.SnmpOid other)Compares two OIDs lexicographically.
int result = 0 ;
int i = 0 ;
int cmplen = Math.min(componentCount, other.componentCount) ;
long[] otheroid = other.components;
for (i = 0; i < cmplen; i++) {
if (components[i] != otheroid[i]) {
break ;
}
}
if ((i == componentCount) && (i == other.componentCount)) {
result = 0 ;
}
else if (i == componentCount) {
result = -1 ;
}
else if (i == other.componentCount) {
result = 1 ;
}
else {
result = (components[i] < otheroid[i]) ? -1 : 1 ;
}
return result ;
|
public final synchronized SnmpValue | duplicate()Performs a clone action. This provides a workaround for the
SnmpValue interface.
return (SnmpValue)clone() ;
|
private 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.
int neededSize = components.length ;
while (componentCount + n > neededSize) {
neededSize = neededSize * 2 ;
}
if (neededSize > components.length) {
long[] newComponents = new long[neededSize] ;
for (int i = 0 ; i < components.length ; i++) {
newComponents[i] = components[i] ;
}
components = newComponents ;
}
|
public boolean | equals(java.lang.Object o)Checks whether the specified Object is equal to this SnmpOid .
boolean result = false ;
if (o instanceof SnmpOid) {
SnmpOid oid = (SnmpOid)o ;
if (oid.componentCount == componentCount) {
int i = 0 ;
long[] objoid = oid.components;
while ((i < componentCount) && (components[i] == objoid[i]))
i++ ;
result = (i == componentCount) ;
}
}
return result ;
|
public int | getLength()Gets the number of components in this OID.
return componentCount ;
|
public final long | getOidArc(int pos)Returns the value of the OID arc found at the requested position
in the components array. The first element is at
position 0 .
try {
return components[pos];
} catch(Exception e) {
throw new SnmpStatusException(SnmpStatusException.noAccess);
}
|
public static SnmpOidTable | getSnmpOidTable()Returns the MIB table used for resolving MIB variable names.
return meta;
|
public java.lang.String | getTypeName()Returns a textual description of the type object.
return name ;
|
private java.lang.String | handleLong(java.lang.String oid, int index)
String str;
if (index >0) {
str= oid.substring(0, index);
} else {
str= oid ;
}
// just parse the element.
//
Long.parseLong(str);
return oid;
|
public int | hashCode()The hashCode is computed from the OID components.
long acc=0;
for (int i=0;i<componentCount;i++) {
acc = acc*31+components[i];
}
return (int)acc;
|
public void | insert(long id)Inserts a subid at the beginning of this SnmpOid .
enlargeIfNeeded(1) ;
for (int i = componentCount - 1 ; i >= 0 ; i--) {
components[i + 1] = components[i] ;
}
components[0] = id ;
componentCount++ ;
|
public void | insert(int id)Inserts a subid at the beginning of this SnmpOid .
insert((long)id) ;
|
public boolean | isValid()Checks the validity of the OID.
return ((componentCount >= 2) &&
((0 <= components[0]) && (components[0] < 3)) &&
((0 <= components[1]) && (components[1] < 40))) ;
|
public long[] | longValue()Returns a copy of the components array of this SnmpOid .
long[] result = new long[componentCount] ;
System.arraycopy(components,0,result,0,componentCount);
return result ;
|
public final long[] | longValue(boolean duplicate)Returns the components array of this SnmpOid .
If duplicate is true, a copy is returned.
Otherwise, a reference to the internal array is returned,
in which case the caller shall not modify this array.
This method is provided to optimize processing in those cases
where the caller needs only to read the components array.
if (duplicate) return longValue();
if (componentCount == components.length) return components ;
components = longValue();
componentCount = components.length;
return components ;
|
public static int | nextOid(long[] index, int start)Scans an index OID, skips the OID value and returns the position
of the next value.
try {
if (index[start] > Integer.MAX_VALUE) {
throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
}
int idCount = (int)index[start++] ;
start += idCount ;
if (start <= index.length) {
return start ;
}
else {
throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
}
}
catch(IndexOutOfBoundsException e) {
throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
}
|
public java.lang.String | resolveVarName(java.lang.String s)Resolves a MIB variable String with the MIB database.
int index = s.indexOf('.") ;
// First handle the case where oid is expressed as 1.2.3.4
//
try {
return handleLong(s, index);
} catch(NumberFormatException e) {}
// if we are here, it means we have something to resolve..
//
if (meta == null)
throw new SnmpStatusException(SnmpStatusException.noSuchName);
// Ok assume there is a variable name to resolve ...
//
if (index <= 0) {
SnmpOidRecord rec = meta.resolveVarName(s);
return rec.getOid();
} else {
SnmpOidRecord rec = meta.resolveVarName(s.substring(0, index));
return (rec.getOid()+ s.substring(index));
}
|
public static void | setSnmpOidTable(SnmpOidTable db)Sets the MIB table to use for resolving MIB variable names.
If no mib table is available, the class will not be able to resolve
names contained in the Object Identifier.
meta = db;
|
public java.lang.Boolean | toBoolean()Converts the OID value to its Boolean form.
if ((componentCount != 1) && (components[0] != 1) && (components[0] != 2)) {
throw new IllegalArgumentException() ;
}
return new Boolean(components[0] == 1) ;
|
public java.lang.Byte[] | toByte()Converts the OID value to its array of Bytes form.
Byte[] result = new Byte[componentCount] ;
for (int i =0 ; i < componentCount ; i++) {
if (components[0] > 255) {
throw new IllegalArgumentException() ;
}
result[i] = new Byte((byte)components[i]) ;
}
return result ;
|
public java.lang.Integer | toInteger()Converts the OID value to its Integer form.
if ((componentCount != 1) || (components[0] > Integer.MAX_VALUE)) {
throw new IllegalArgumentException() ;
}
return new Integer((int)components[0]) ;
|
public java.lang.Long | toLong()Converts the OID value to its Long form.
if (componentCount != 1) {
throw new IllegalArgumentException() ;
}
return new Long(components[0]) ;
|
public java.lang.String | toOctetString()Converts an OID index converted string back to a DisplayString
return new String(tobyte()) ;
|
public com.sun.jmx.snmp.SnmpOid | toOid()Converts the OID value to its SnmpOid form.
long[] ids = new long[componentCount] ;
for (int i = 0 ; i < componentCount ; i++) {
ids[i] = components[i] ;
}
return new SnmpOid(ids) ;
|
public static com.sun.jmx.snmp.SnmpOid | toOid(long[] index, int start)Extracts the OID from an index OID and returns its
value converted as an SnmpOid .
try {
if (index[start] > Integer.MAX_VALUE) {
throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
}
int idCount = (int)index[start++] ;
long[] ids = new long[idCount] ;
for (int i = 0 ; i < idCount ; i++) {
ids[i] = index[start + i] ;
}
return new SnmpOid(ids) ;
}
catch(IndexOutOfBoundsException e) {
throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
}
|
public java.lang.String | toString()Converts the OID value to its String form.
String result = "" ;
if (componentCount >= 1) {
for (int i = 0 ; i < componentCount - 1 ; i++) {
result = result + components[i] + "." ;
}
result = result + components[componentCount - 1] ;
}
return result ;
|
private byte[] | tobyte()convert the components array into a byte array
byte[] result = new byte[componentCount] ;
for (int i =0 ; i < componentCount ; i++) {
if (components[0] > 255) {
throw new IllegalArgumentException() ;
}
result[i] = (byte)components[i] ;
}
return result ;
|