001: package org.bouncycastle.asn1.x509.qualified;
002:
003: import java.util.Enumeration;
004:
005: import org.bouncycastle.asn1.ASN1Encodable;
006: import org.bouncycastle.asn1.ASN1Sequence;
007: import org.bouncycastle.asn1.ASN1EncodableVector;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.DERObjectIdentifier;
010: import org.bouncycastle.asn1.DERSequence;
011: import org.bouncycastle.asn1.x509.GeneralName;
012:
013: /**
014: * The SemanticsInformation object.
015: * <pre>
016: * SemanticsInformation ::= SEQUENCE {
017: * semanticsIdentifier OBJECT IDENTIFIER OPTIONAL,
018: * nameRegistrationAuthorities NameRegistrationAuthorities
019: * OPTIONAL }
020: * (WITH COMPONENTS {..., semanticsIdentifier PRESENT}|
021: * WITH COMPONENTS {..., nameRegistrationAuthorities PRESENT})
022: *
023: * NameRegistrationAuthorities ::= SEQUENCE SIZE (1..MAX) OF
024: * GeneralName
025: * </pre>
026: */
027: public class SemanticsInformation extends ASN1Encodable {
028: DERObjectIdentifier semanticsIdentifier;
029: GeneralName[] nameRegistrationAuthorities;
030:
031: public static SemanticsInformation getInstance(Object obj) {
032: if (obj == null || obj instanceof SemanticsInformation) {
033: return (SemanticsInformation) obj;
034: }
035:
036: if (obj instanceof ASN1Sequence) {
037: return new SemanticsInformation(ASN1Sequence
038: .getInstance(obj));
039: }
040:
041: throw new IllegalArgumentException(
042: "unknown object in getInstance");
043: }
044:
045: public SemanticsInformation(ASN1Sequence seq) {
046: Enumeration e = seq.getObjects();
047: if (seq.size() < 1) {
048: throw new IllegalArgumentException(
049: "no objects in SemanticsInformation");
050: }
051:
052: Object object = e.nextElement();
053: if (object instanceof DERObjectIdentifier) {
054: semanticsIdentifier = DERObjectIdentifier
055: .getInstance(object);
056: if (e.hasMoreElements()) {
057: object = e.nextElement();
058: } else {
059: object = null;
060: }
061: }
062:
063: if (object != null) {
064: ASN1Sequence generalNameSeq = ASN1Sequence
065: .getInstance(object);
066: nameRegistrationAuthorities = new GeneralName[generalNameSeq
067: .size()];
068: for (int i = 0; i < generalNameSeq.size(); i++) {
069: nameRegistrationAuthorities[i] = GeneralName
070: .getInstance(generalNameSeq.getObjectAt(i));
071: }
072: }
073: }
074:
075: public SemanticsInformation(
076: DERObjectIdentifier semanticsIdentifier,
077: GeneralName[] generalNames) {
078: this .semanticsIdentifier = semanticsIdentifier;
079: this .nameRegistrationAuthorities = generalNames;
080: }
081:
082: public SemanticsInformation(DERObjectIdentifier semanticsIdentifier) {
083: this .semanticsIdentifier = semanticsIdentifier;
084: this .nameRegistrationAuthorities = null;
085: }
086:
087: public SemanticsInformation(GeneralName[] generalNames) {
088: this .semanticsIdentifier = null;
089: this .nameRegistrationAuthorities = generalNames;
090: }
091:
092: public DERObjectIdentifier getSemanticsIdentifier() {
093: return semanticsIdentifier;
094: }
095:
096: public GeneralName[] getNameRegistrationAuthorities() {
097: return nameRegistrationAuthorities;
098: }
099:
100: public DERObject toASN1Object() {
101: ASN1EncodableVector seq = new ASN1EncodableVector();
102:
103: if (this .semanticsIdentifier != null) {
104: seq.add(semanticsIdentifier);
105: }
106: if (this .nameRegistrationAuthorities != null) {
107: ASN1EncodableVector seqname = new ASN1EncodableVector();
108: for (int i = 0; i < nameRegistrationAuthorities.length; i++) {
109: seqname.add(nameRegistrationAuthorities[i]);
110: }
111: seq.add(new DERSequence(seqname));
112: }
113:
114: return new DERSequence(seq);
115: }
116: }
|