org.jasn
Class ObjectIdentifier

java.lang.Object
  extended byorg.jasn.ObjectIdentifier

public final class ObjectIdentifier
extends Object

This class represents an ASN.1 OBJECT IDENTIFIER.

An OBJECT IDENTIFIER value is an ordered list of non-negative numbers that represents a hierarchically globally-interpretable identifiers. Each number in the list is referred to as an arc.

All ObjectIdentifiers must have at least two arcs, where the value of the first arc must be 0, 1 or 2 and the value of the second arc must be at most 39 if the value of the first arc is 0 or 1.

Author:
Nicolas Vraux
To do:
complete the documentation, cache the hashCode() and toString() results

Constructor Summary
ObjectIdentifier(int[] oid)
          Creates an object identifier from the specified list of component values (or arcs).
ObjectIdentifier(String s)
          Constructs an ASN.1 object identifier from a string representation of its arcs.
 
Method Summary
 ObjectIdentifier append(int arc)
          Concatenates the specified arc value to the end of this ObjectIdentifier arc sequence.
 ObjectIdentifier append(int[] roid)
          Concatenates the specified arc array to the end of this ObjectIdentifier arc list.
 boolean equals(Object o)
          Compares this object identifier to the specified object identifier.
 int getComponent(int index)
          Returns the arc value at the specified index.
 int hashCode()
          Returns a hashcode for this object identifier.
 int length()
          Returns the number of arcs contained in this ObjectIdentifier.
 byte[] toBER()
          Returns the BER encoding of this ObjectIdentifier.
 String toString()
          Returns a string form of this object identifier.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectIdentifier

public ObjectIdentifier(String s)
Constructs an ASN.1 object identifier from a string representation of its arcs. This string should be of the form
 arc[0] "." arc[1] "." ... "." arc[n-1]
 

Parameters:
s - the dot separated string representation of the object identifier.
Throws:
IllegalArgumentException - if the specified string is incorrectly formated.

ObjectIdentifier

public ObjectIdentifier(int[] oid)
Creates an object identifier from the specified list of component values (or arcs).

Parameters:
oid - the list of arcs.
Throws:
IllegalArgumentException - if the specified array has a length less that 2 or if one of the array values is negative or if
Method Detail

append

public ObjectIdentifier append(int[] roid)
Concatenates the specified arc array to the end of this ObjectIdentifier arc list.

If the length of the argument array is 0, then this ObjectIdentifier object is returned. Otherwise, a new ObjectIdentifier object is created, representing an ordered list of arc numbers that is the concatenation of the arc sequence represented by this ObjectIdentifier object and the arc sequence represented by the argument array.

Parameters:
roid - the array of arc numbers that is concatenated to the end of this ObjectIdentifier arc list.
Returns:
an object identifier that represents the concatenation of this object's characters followed by the string argument's characters.

append

public ObjectIdentifier append(int arc)
Concatenates the specified arc value to the end of this ObjectIdentifier arc sequence.

Parameters:
arc - the arc value that is concatenated to the end of this ObjectIdentifier arc sequence.
Returns:
an object identifier that represents the concatenation of this object's arc sequence followed by specified arc.
Throws:
IllegalArgumentException - if the specified arc value is negative.

length

public int length()
Returns the number of arcs contained in this ObjectIdentifier.

Returns:
the number of arcs contained in this ObjectIdentifier.

getComponent

public int getComponent(int index)
Returns the arc value at the specified index.

Parameters:
index - the index of arc.
Returns:
the arc at the specified index.
Throws:
IndexOutOfBoundsException - if the index argument is negative or not less than the length of this object identifier.

toString

public String toString()
Returns a string form of this object identifier. The format is the conventional "dot" notation for such IDs, without any user-friendly descriptive strings, since those strings will not be understood everywhere.


toBER

public byte[] toBER()
Returns the BER encoding of this ObjectIdentifier.

Returns:
a newly allocated byte array whose contents are initialized to contain the BER encoding of this ObjectIdentifier.

equals

public boolean equals(Object o)
Compares this object identifier to the specified object identifier. The result is true if and only if the argument is not null and is an ObjectIdentifier object that represents the same sequence of arcs as this object.

Parameters:
o - the object to compare this ObjectIdentifier against.
Returns:
true if the ObjectIdentifier objects are equal; false otherwise.

hashCode

public int hashCode()
Returns a hashcode for this object identifier. The hashcode for an ObjectIdentifier object is computed as
 arc[0]^arc[1]^...^arc[n-1]
 

Returns:
a hash code value for this object.


Copyright © 2004 Nicolas Vraux. All Rights Reserved.