001: package org.bouncycastle.asn1.isismtt.x509;
002:
003: import org.bouncycastle.asn1.ASN1Encodable;
004: import org.bouncycastle.asn1.ASN1EncodableVector;
005: import org.bouncycastle.asn1.ASN1Sequence;
006: import org.bouncycastle.asn1.ASN1TaggedObject;
007: import org.bouncycastle.asn1.DEREncodable;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.DERSequence;
010: import org.bouncycastle.asn1.DERTaggedObject;
011: import org.bouncycastle.asn1.x509.GeneralName;
012:
013: import java.util.Enumeration;
014:
015: /**
016: * An Admissions structure.
017: * <p/>
018: * <pre>
019: * Admissions ::= SEQUENCE
020: * {
021: * admissionAuthority [0] EXPLICIT GeneralName OPTIONAL
022: * namingAuthority [1] EXPLICIT NamingAuthority OPTIONAL
023: * professionInfos SEQUENCE OF ProfessionInfo
024: * }
025: * <p/>
026: * </pre>
027: *
028: * @see org.bouncycastle.asn1.isismtt.x509.AdmissionSyntax
029: * @see org.bouncycastle.asn1.isismtt.x509.ProfessionInfo
030: * @see org.bouncycastle.asn1.isismtt.x509.NamingAuthority
031: */
032: public class Admissions extends ASN1Encodable {
033:
034: private GeneralName admissionAuthority;
035:
036: private NamingAuthority namingAuthority;
037:
038: private ASN1Sequence professionInfos;
039:
040: public static Admissions getInstance(Object obj) {
041: if (obj == null || obj instanceof Admissions) {
042: return (Admissions) obj;
043: }
044:
045: if (obj instanceof ASN1Sequence) {
046: return new Admissions((ASN1Sequence) obj);
047: }
048:
049: throw new IllegalArgumentException(
050: "illegal object in getInstance: "
051: + obj.getClass().getName());
052: }
053:
054: /**
055: * Constructor from ASN1Sequence.
056: * <p/>
057: * The sequence is of type ProcurationSyntax:
058: * <p/>
059: * <pre>
060: * Admissions ::= SEQUENCE
061: * {
062: * admissionAuthority [0] EXPLICIT GeneralName OPTIONAL
063: * namingAuthority [1] EXPLICIT NamingAuthority OPTIONAL
064: * professionInfos SEQUENCE OF ProfessionInfo
065: * }
066: * </pre>
067: *
068: * @param seq The ASN.1 sequence.
069: */
070: private Admissions(ASN1Sequence seq) {
071: if (seq.size() > 3) {
072: throw new IllegalArgumentException("Bad sequence size: "
073: + seq.size());
074: }
075: Enumeration e = seq.getObjects();
076:
077: DEREncodable o = (DEREncodable) e.nextElement();
078: if (o instanceof ASN1TaggedObject) {
079: switch (((ASN1TaggedObject) o).getTagNo()) {
080: case 0:
081: admissionAuthority = GeneralName.getInstance(
082: (ASN1TaggedObject) o, true);
083: break;
084: case 1:
085: namingAuthority = NamingAuthority.getInstance(
086: (ASN1TaggedObject) o, true);
087: break;
088: default:
089: throw new IllegalArgumentException("Bad tag number: "
090: + ((ASN1TaggedObject) o).getTagNo());
091: }
092: o = (DEREncodable) e.nextElement();
093: }
094: if (o instanceof ASN1TaggedObject) {
095: switch (((ASN1TaggedObject) o).getTagNo()) {
096: case 1:
097: namingAuthority = NamingAuthority.getInstance(
098: (ASN1TaggedObject) o, true);
099: break;
100: default:
101: throw new IllegalArgumentException("Bad tag number: "
102: + ((ASN1TaggedObject) o).getTagNo());
103: }
104: o = (DEREncodable) e.nextElement();
105: }
106: professionInfos = ASN1Sequence.getInstance(o);
107: if (e.hasMoreElements()) {
108: throw new IllegalArgumentException(
109: "Bad object encountered: "
110: + e.nextElement().getClass());
111: }
112: }
113:
114: /**
115: * Constructor from a given details.
116: * <p/>
117: * Parameter <code>professionInfos</code> is mandatory.
118: *
119: * @param admissionAuthority The admission authority.
120: * @param namingAuthority The naming authority.
121: * @param professionInfos The profession infos.
122: */
123: public Admissions(GeneralName admissionAuthority,
124: NamingAuthority namingAuthority,
125: ProfessionInfo[] professionInfos) {
126: this .admissionAuthority = admissionAuthority;
127: this .namingAuthority = namingAuthority;
128: this .professionInfos = new DERSequence(professionInfos);
129: }
130:
131: public GeneralName getAdmissionAuthority() {
132: return admissionAuthority;
133: }
134:
135: public NamingAuthority getNamingAuthority() {
136: return namingAuthority;
137: }
138:
139: public ProfessionInfo[] getProfessionInfos() {
140: ProfessionInfo[] infos = new ProfessionInfo[professionInfos
141: .size()];
142: int count = 0;
143: for (Enumeration e = professionInfos.getObjects(); e
144: .hasMoreElements();) {
145: infos[count++] = ProfessionInfo
146: .getInstance(e.nextElement());
147: }
148: return infos;
149: }
150:
151: /**
152: * Produce an object suitable for an ASN1OutputStream.
153: * <p/>
154: * Returns:
155: * <p/>
156: * <pre>
157: * Admissions ::= SEQUENCE
158: * {
159: * admissionAuthority [0] EXPLICIT GeneralName OPTIONAL
160: * namingAuthority [1] EXPLICIT NamingAuthority OPTIONAL
161: * professionInfos SEQUENCE OF ProfessionInfo
162: * }
163: * <p/>
164: * </pre>
165: *
166: * @return a DERObject
167: */
168: public DERObject toASN1Object() {
169: ASN1EncodableVector vec = new ASN1EncodableVector();
170:
171: if (admissionAuthority != null) {
172: vec.add(new DERTaggedObject(true, 0, admissionAuthority));
173: }
174: if (namingAuthority != null) {
175: vec.add(new DERTaggedObject(true, 1, namingAuthority));
176: }
177: vec.add(professionInfos);
178:
179: return new DERSequence(vec);
180: }
181: }
|