codec.asn1
Class ASN1ObjectIdentifier

java.lang.Object
  |
  +--codec.asn1.ASN1AbstractType
        |
        +--codec.asn1.ASN1ObjectIdentifier
All Implemented Interfaces:
ASN1Type, Cloneable, Comparable, Externalizable, Serializable

public class ASN1ObjectIdentifier
extends ASN1AbstractType
implements Cloneable, Comparable

Represents an ASN.1 OBJECT IDENTIFIER type. The corresponding Java type is int[]. Constraints are checked for this type only at the end of method decode.

Version:
"$Id: ASN1ObjectIdentifier.java,v 1.4 2005/03/22 14:57:58 flautens Exp $"
Author:
Volker Roth
See Also:
Serialized Form

Constructor Summary
ASN1ObjectIdentifier()
          Creates a new ASN1ObjectIdentifier object.
ASN1ObjectIdentifier(int[] oid)
          Creates an instance with the given array of integers as elements.
ASN1ObjectIdentifier(String s)
          Creates an ASN.1 OBJECT IDENTIFIER instance initialized from the given OID string representation.
 
Method Summary
 Object clone()
          Returns a clone of this instance.
 int compareTo(Object o)
          This method compares two OID and returns -1, 0, 1 if this OID is less than, equal or greater than the given one.
 void decode(Decoder dec)
          Decodes to this ASN1ObjectIdentifier.
 int elementCount()
          Returns the number of elements of the oid.
 void encode(Encoder enc)
          Encodes this ASN1ObjectIdentifier.
 boolean equals(Object o)
          Compares two OIDs for equality.
 int[] getOID()
          DOCUMENT ME!
 int getTag()
          DOCUMENT ME!
 Object getValue()
          DOCUMENT ME!
 int hashCode()
          This method computes the hash code of this instance.
 boolean isPrefixOf(ASN1ObjectIdentifier o)
          This method determines whether the given OID is part of the OID family defined by this OID prefix.
 void setOID(int[] oid)
          DOCUMENT ME!
 String toString()
          Returns the string representation of this OID.
 
Methods inherited from class codec.asn1.ASN1AbstractType
checkConstraints, getConstraint, getTagClass, isExplicit, isOptional, isType, readExternal, setConstraint, setExplicit, setOptional, writeExternal
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ASN1ObjectIdentifier

public ASN1ObjectIdentifier()
Creates a new ASN1ObjectIdentifier object.

ASN1ObjectIdentifier

public ASN1ObjectIdentifier(int[] oid)
Creates an instance with the given array of integers as elements. No constraints are checked by this constructor.
Parameters:
oid - The array of consecutive integers of the OID.
Throws:
NullPointerException - if the given oid is null.
IllegalArgumentException - if the given oid is not well-formed. For instance, a bad oid might have a value greater than 2 as its first element.

ASN1ObjectIdentifier

public ASN1ObjectIdentifier(String s)
                     throws NumberFormatException
Creates an ASN.1 OBJECT IDENTIFIER instance initialized from the given OID string representation. The format must be either OID.1.2.3.4, oid.1.2.3.4, or 1.2.3.4 for the initiliser to work properly. Trailing dots are ignored.
Parameters:
s - string representation of oid
Throws:
NumberFormatException - if some element of the OID string is not an integer number.
IllegalArgumentException - if the string is not a well-formed OID.
Method Detail

getValue

public Object getValue()
DOCUMENT ME!
Overrides:
getValue in class ASN1AbstractType
Returns:
DOCUMENT ME!

getOID

public int[] getOID()
DOCUMENT ME!
Returns:
DOCUMENT ME!

setOID

public void setOID(int[] oid)
            throws ConstraintException
DOCUMENT ME!
Parameters:
oid - DOCUMENT ME!
Throws:
ConstraintException - DOCUMENT ME!

elementCount

public int elementCount()
Returns the number of elements of the oid.
Returns:
the number of elements

getTag

public int getTag()
DOCUMENT ME!
Overrides:
getTag in class ASN1AbstractType
Returns:
DOCUMENT ME!

encode

public void encode(Encoder enc)
            throws ASN1Exception,
                   IOException
Encodes this ASN1ObjectIdentifier.
Overrides:
encode in class ASN1AbstractType
Parameters:
enc - The encoder to encode to.
Throws:
ASN1Exception -  
IOException -  

decode

public void decode(Decoder dec)
            throws ASN1Exception,
                   IOException
Decodes to this ASN1ObjectIdentifier.
Overrides:
decode in class ASN1AbstractType
Parameters:
dec - DOCUMENT ME!
Throws:
ASN1Exception -  
IOException -  

toString

public String toString()
Returns the string representation of this OID. The string consists of the numerical elements of the OID separated by periods.
Overrides:
toString in class Object
Returns:
The string representation of the OID.

equals

public boolean equals(Object o)
Compares two OIDs for equality. Two OIDs are equal if the have the same number of elements and all corresponding elements are equal.
Overrides:
equals in class Object
Parameters:
o - The object to compare to.
Returns:
true iff the given object is an ASN1ObjectIdentifier and iff it equals this one.

hashCode

public int hashCode()
This method computes the hash code of this instance. The hash code of this instance is defined as a hash function of the underlying integer array.
Overrides:
hashCode in class Object
Returns:
the hash code of this instance.

compareTo

public int compareTo(Object o)
This method compares two OID and returns -1, 0, 1 if this OID is less than, equal or greater than the given one. OID are interpreted as strings of numbers. An OID that is a prefix of another is always smaller than the other.
Specified by:
compareTo in interface Comparable
Parameters:
o - The OID to compare to.
Returns:
-1, 0, 1 if this OID is smaller than, equal to, or greater than the given OID.
Throws:
ClassCastException - iff o is not an ASN1ObjectIdentifier.

isPrefixOf

public boolean isPrefixOf(ASN1ObjectIdentifier o)
This method determines whether the given OID is part of the OID family defined by this OID prefix. In other words, this method returns true if this OID is a prefix of the given one.
Parameters:
o - the oid to check
Returns:
true if this OID is a prefix of the given one.

clone

public Object clone()
Returns a clone of this instance. This method is not thread safe. The constraints are copied by reference.
Overrides:
clone in class Object
Returns:
The clone.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.