FileDocCategorySizeDatePackage
Name.javaAPI DocAndroid 1.5 API7748Wed May 06 22:41:06 BST 2009org.apache.harmony.security.x501

Name

public class Name extends Object
X.501 Name

Fields Summary
private volatile byte[]
encoded
private String
rfc1779String
private String
rfc2253String
private String
canonicalString
private List
rdn
public static final org.apache.harmony.security.asn1.ASN1SetOf
ASN1_RDN
According to RFC 3280 (http://www.ietf.org/rfc/rfc3280.txt) X.501 Name structure is defined as follows: Name ::= CHOICE { RDNSequence } RDNSequence ::= SEQUENCE OF RelativeDistinguishedName RelativeDistinguishedName ::= SET OF AttributeTypeAndValue
public static final org.apache.harmony.security.asn1.ASN1SequenceOf
ASN1
Constructors Summary
public Name(byte[] encoding)
Creates new Name instance from its DER encoding

param
encoding - ASN.1 DER encoding
throws
IOException - if encoding is wrong


        DerInputStream in = new DerInputStream(encoding);

        if (in.getEndOffset() != encoding.length) {
            throw new IOException(Messages.getString("security.111")); //$NON-NLS-1$
        }

        ASN1.decode(in);

        this.rdn = (List) in.content;
    
public Name(String name)
Creates new Name instance

param
name - Name as String
throws
IOException - if string is wrong

        rdn = new DNParser(name).parse();
    
private Name(List rdn)

        this.rdn = rdn;
    
Methods Summary
public byte[]getEncoded()
Gets encoded form of DN

return
return encoding, no copying is performed

        if (encoded == null) {
            encoded = ASN1.encode(this);
        }
        return encoded;
    
public java.lang.StringgetName(java.lang.String format)
Returns Relative Distinguished Name as String according the format requested

param
format Name format requested
return
Relative Distinguished Name as String according the format requested


        //
        // check X500Principal constants first
        //
        if (format == X500Principal.RFC1779) {

            if (rfc1779String == null) {
                rfc1779String = getName0(format);
            }
            return rfc1779String;

        } else if (format == X500Principal.RFC2253) {

            if (rfc2253String == null) {
                rfc2253String = getName0(format);
            }
            return rfc2253String;

        } else if (format == X500Principal.CANONICAL) {

            if (canonicalString == null) {
                canonicalString = getName0(format);
            }
            return canonicalString;

        }
        //
        // compare ignore case
        //
        else if (X500Principal.RFC1779.equalsIgnoreCase(format)) {

            if (rfc1779String == null) {
                rfc1779String = getName0(X500Principal.RFC1779);
            }
            return rfc1779String;

        } else if (X500Principal.RFC2253.equalsIgnoreCase(format)) {

            if (rfc2253String == null) {
                rfc2253String = getName0(X500Principal.RFC2253);
            }
            return rfc2253String;

        } else if (X500Principal.CANONICAL.equalsIgnoreCase(format)) {

            if (canonicalString == null) {
                canonicalString = getName0(X500Principal.CANONICAL);
            }
            return canonicalString;

        } else {
            throw new IllegalArgumentException(Messages.getString("security.177", format)); //$NON-NLS-1$
        }
    
private java.lang.StringgetName0(java.lang.String format)
Returns Relative Distinguished Name as String according the format requested, format is int value

param
format Name format requested
return
Relative Distinguished Name as String according the format requested

        
        StringBuffer name = new StringBuffer();

        // starting with the last element and moving to the first.
        for (int i = rdn.size() - 1; i >= 0; i--) {
            List atavList = (List) rdn.get(i);

            if (X500Principal.CANONICAL == format) {
                List sortedList = new LinkedList(atavList);
                Collections.sort(sortedList,
                        new AttributeTypeAndValueComparator());
                atavList = sortedList;
            }

            // Relative Distinguished Name to string
            Iterator it = atavList.iterator();
            while (it.hasNext()) {
                AttributeTypeAndValue _ava = (AttributeTypeAndValue) it.next();
                _ava.appendName(format, name);
                if (it.hasNext()) {
                    // multi-valued RDN
                    if (X500Principal.RFC1779 == format) {
                        name.append(" + "); //$NON-NLS-1$
                    } else {
                        name.append('+");
                    }
                }
            }

            if (i != 0) {
                name.append(',");
                if (format == X500Principal.RFC1779) {
                    name.append(' ");
                }
            }
        }

        String sName = name.toString();
        if (format == X500Principal.CANONICAL) {
            sName = sName.toLowerCase(Locale.US);
        }
        return sName;
    
public javax.security.auth.x500.X500PrincipalgetX500Principal()
Returns X500Principal instance corresponding to this Name instance

return
equivalent X500Principal object

        return new X500Principal(getName0(X500Principal.RFC2253));