FileDocCategorySizeDatePackage
RoleSyntax.javaAPI DocAndroid 1.5 API7354Wed May 06 22:41:06 BST 2009org.bouncycastle.asn1.x509

RoleSyntax

public class RoleSyntax extends org.bouncycastle.asn1.ASN1Encodable
Implementation of the RoleSyntax object as specified by the RFC3281.
RoleSyntax ::= SEQUENCE {
roleAuthority [0] GeneralNames OPTIONAL,
roleName [1] GeneralName
}

Fields Summary
private GeneralNames
roleAuthority
private GeneralName
roleName
Constructors Summary
public RoleSyntax(GeneralNames roleAuthority, GeneralName roleName)
Constructor.

param
roleAuthority the role authority of this RoleSyntax.
param
roleName the role name of this RoleSyntax.

        if(roleName == null || 
                roleName.getTagNo() != GeneralName.uniformResourceIdentifier ||
                ((DERString)roleName.getName()).getString().equals(""))
        {
            throw new IllegalArgumentException("the role name MUST be non empty and MUST " +
                    "use the URI option of GeneralName");
        }
        this.roleAuthority = roleAuthority;
        this.roleName = roleName;
    
public RoleSyntax(GeneralName roleName)
Constructor. Invoking this constructor is the same as invoking new RoleSyntax(null, roleName).

param
roleName the role name of this RoleSyntax.

        this(null, roleName);
    
public RoleSyntax(String roleName)
Utility constructor. Takes a String argument representing the role name, builds a GeneralName to hold the role name and calls the constructor that takes a GeneralName.

param
roleName

        this(new GeneralName(GeneralName.uniformResourceIdentifier,
                (roleName == null)? "": roleName));
    
public RoleSyntax(org.bouncycastle.asn1.ASN1Sequence seq)
Constructor that builds an instance of RoleSyntax by extracting the encoded elements from the ASN1Sequence object supplied.

param
seq an instance of ASN1Sequence that holds the encoded elements used to build this RoleSyntax.

        if (seq.size() < 1 || seq.size() > 2)
        {
            throw new IllegalArgumentException("Bad sequence size: "
                    + seq.size());
        }

        for (int i = 0; i != seq.size(); i++)
        {
            ASN1TaggedObject taggedObject = ASN1TaggedObject.getInstance(seq.getObjectAt(i));
            switch (taggedObject.getTagNo())
            {
            case 0:
                roleAuthority = GeneralNames.getInstance(taggedObject, false);
                break;
            case 1:
                roleName = GeneralName.getInstance(taggedObject, false);
                break;
            default:
                throw new IllegalArgumentException("Unknown tag in RoleSyntax");
            }
        }
    
Methods Summary
public static org.bouncycastle.asn1.x509.RoleSyntaxgetInstance(java.lang.Object obj)
RoleSyntax factory method.

param
obj the object used to construct an instance of RoleSyntax. It must be an instance of RoleSyntax or ASN1Sequence.
return
the instance of RoleSyntax built from the supplied object.
throws
java.lang.IllegalArgumentException if the object passed to the factory is not an instance of RoleSyntax or ASN1Sequence.

        
        if(obj == null || obj instanceof RoleSyntax)
        {
            return (RoleSyntax)obj;
        }
        else if(obj instanceof ASN1Sequence)
        {
            return new RoleSyntax((ASN1Sequence)obj);
        }
        throw new IllegalArgumentException("Unknown object in RoleSyntax factory.");
    
public GeneralNamesgetRoleAuthority()
Gets the role authority of this RoleSyntax.

return
an instance of GeneralNames holding the role authority of this RoleSyntax.

        return this.roleAuthority;
    
public java.lang.String[]getRoleAuthorityAsString()
Gets the role authority as a String[] object.

return
the role authority of this RoleSyntax represented as a String[] array.

        if(roleAuthority == null) 
        {
            return new String[0];
        }
        
        GeneralName[] names = roleAuthority.getNames();
        String[] namesString = new String[names.length];
        for(int i = 0; i < names.length; i++) 
        {
            DEREncodable value = names[i].getName();
            if(value instanceof DERString)
            {
                namesString[i] = ((DERString)value).getString();
            }
            else
            {
                namesString[i] = value.toString();
            }
        }
        return namesString;
    
public GeneralNamegetRoleName()
Gets the role name of this RoleSyntax.

return
an instance of GeneralName holding the role name of this RoleSyntax.

        return this.roleName;
    
public java.lang.StringgetRoleNameAsString()
Gets the role name as a java.lang.String object.

return
the role name of this RoleSyntax represented as a java.lang.String object.

        DERString str = (DERString)this.roleName.getName();
        
        return str.getString();
    
public org.bouncycastle.asn1.DERObjecttoASN1Object()
Implementation of the method toASN1Object as required by the superclass ASN1Encodable.
RoleSyntax ::= SEQUENCE {
roleAuthority [0] GeneralNames OPTIONAL,
roleName [1] GeneralName
}

        ASN1EncodableVector v = new ASN1EncodableVector();
        if(this.roleAuthority != null)
        {
            v.add(new DERTaggedObject(false, 0, roleAuthority));
        }
        v.add(new DERTaggedObject(false, 1, roleName));
        
        return new DERSequence(v);
    
public java.lang.StringtoString()

        StringBuffer buff = new StringBuffer("Name: " + this.getRoleNameAsString() +
                " - Auth: ");
        if(this.roleAuthority == null || roleAuthority.getNames().length == 0)
        {
            buff.append("N/A");
        }
        else 
        {
            String[] names = this.getRoleAuthorityAsString();
            buff.append('[").append(names[0]);
            for(int i = 1; i < names.length; i++) 
            {
                    buff.append(", ").append(names[i]);
            }
            buff.append(']");
        }
        return buff.toString();