FileDocCategorySizeDatePackage
ObjectIdentifier.javaAPI DocAndroid 1.5 API5994Wed May 06 22:41:06 BST 2009org.apache.harmony.security.utils

ObjectIdentifier

public final class ObjectIdentifier extends Object
Instance of this class represents ObjectIdentifier (OID). OID is represented as a sequence of subidentifier. Each subidentifier is represented as non negative integer value. There are at least 2 subidentifiers in the sequence. Valid values for first subidentifier are 0, 1 and 2. If the first subidentifier has 0 or 1 value the second subidentifier MUST be less then 40.
see
ASN.1

Fields Summary
private final int[]
oid
private int
hash
private String
soid
private String
sOID
private String
name
private Object
group
Constructors Summary
public ObjectIdentifier(int[] oid)
Creates ObjectIdentifier(OID) from array of integers.

param
oid - array of integers
return
- OID object
throws
NullPointerException - if oid is null
throws
IllegalArgumentException - if oid is invalid


                                            
       

        validateOid(oid);

        this.oid = oid;
    
public ObjectIdentifier(int[] oid, String name, Object oidGroup)
Creates ObjectIdentifier(OID) from array of integers.

param
oid - array of integers
param
name - name of OID
param
oidGroup - OID's group. Is used to separate different OID's
return
- OID object
throws
NullPointerException - if oid is null
throws
IllegalArgumentException - if oid is invalid

        this(oid);

        if (oidGroup == null) {
            throw new NullPointerException(Messages.getString("security.172")); //$NON-NLS-1$
        }
        this.group = oidGroup;

        this.name = name;
        toOIDString(); // init soid & sOID
    
Methods Summary
public booleanequals(java.lang.Object o)
Compares object with OID for equality.

return
true if object is ObjectIdentifier and it has the same representation as array of integers, otherwise false

        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        return Arrays.equals(oid, ((ObjectIdentifier) o).oid);
    
public java.lang.ObjectgetGroup()
Gets OID's group.

return
group

        return group;
    
public java.lang.StringgetName()
Gets OID's name.

return
name

        return name;
    
public int[]getOid()
Gets OID.

return
oid

        return oid;
    
public inthashCode()

see
java.lang.Object#hashCode()

        if (hash == -1) {
            hash = hashIntArray(oid);
        }
        return hash;
    
public static inthashIntArray(int[] array)
Returns hash code for array of integers

param
oid - array of integers

        int intHash = 0;
        for (int i = 0; i < array.length && i < 4; i++) {
            intHash += array[i] << (8 * i); //TODO what about to find better one?
        }
        return intHash & 0x7FFFFFFF; // only positive
    
public java.lang.StringtoOIDString()
Add "OID." to the beginning of string representation.

return
oid as string

        if (sOID == null) {
            sOID = "OID." + toString(); //$NON-NLS-1$
        }
        return sOID;
    
public java.lang.StringtoString()
Overrides Object.toString()

return
oid as string

        if (soid == null) {
            StringBuffer sb = new StringBuffer(4 * oid.length);

            for (int i = 0; i < oid.length - 1; ++i) {
                sb.append(oid[i]);
                sb.append('.");
            }
            sb.append(oid[oid.length - 1]);
            soid = sb.toString();
        }
        return soid;
    
public static voidvalidateOid(int[] oid)
Validates ObjectIdentifier (OID).

param
oid - oid as array of integers
throws
NullPointerException - if oid is null
throws
IllegalArgumentException - if oid is invalid


        if (oid == null) {
            throw new NullPointerException(Messages.getString("security.98")); //$NON-NLS-1$
        }

        if (oid.length < 2) {
            throw new IllegalArgumentException(
                    Messages.getString("security.99")); //$NON-NLS-1$
        }

        if (oid[0] > 2) {
            throw new IllegalArgumentException(
                    Messages.getString("security.9A")); //$NON-NLS-1$
        } else if (oid[0] != 2 && oid[1] > 39) {
            throw new IllegalArgumentException(
                    Messages.getString("security.9B")); //$NON-NLS-1$
        }