KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > x509 > NoticeReference


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.geronimo.util.asn1.x509;
20
21 import java.util.Enumeration JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 import org.apache.geronimo.util.asn1.ASN1Encodable;
25 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
26 import org.apache.geronimo.util.asn1.ASN1Sequence;
27 import org.apache.geronimo.util.asn1.DERInteger;
28 import org.apache.geronimo.util.asn1.DERObject;
29 import org.apache.geronimo.util.asn1.DERSequence;
30
31 /**
32  * <code>NoticeReference</code> class, used in
33  * <code>CertificatePolicies</code> X509 V3 extensions
34  * (in policy qualifiers).
35  *
36  * <pre>
37  * NoticeReference ::= SEQUENCE {
38  * organization DisplayText,
39  * noticeNumbers SEQUENCE OF INTEGER }
40  *
41  * </pre>
42  *
43  * @see PolicyQualifierInfo
44  * @see PolicyInformation
45  */

46 public class NoticeReference
47     extends ASN1Encodable
48 {
49    DisplayText organization;
50    ASN1Sequence noticeNumbers;
51
52    /**
53     * Creates a new <code>NoticeReference</code> instance.
54     *
55     * @param orgName a <code>String</code> value
56     * @param numbers a <code>Vector</code> value
57     */

58    public NoticeReference (String JavaDoc orgName, Vector JavaDoc numbers)
59    {
60       organization = new DisplayText(orgName);
61
62       Object JavaDoc o = numbers.elementAt(0);
63
64       ASN1EncodableVector av = new ASN1EncodableVector();
65       if (o instanceof Integer JavaDoc) {
66          Enumeration JavaDoc it = numbers.elements();
67
68          while (it.hasMoreElements()) {
69             Integer JavaDoc nm = (Integer JavaDoc) it.nextElement();
70                DERInteger di = new DERInteger(nm.intValue());
71             av.add (di);
72          }
73       }
74
75       noticeNumbers = new DERSequence(av);
76    }
77
78    /**
79     * Creates a new <code>NoticeReference</code> instance.
80     *
81     * @param orgName a <code>String</code> value
82     * @param numbers an <code>ASN1EncodableVector</code> value
83     */

84    public NoticeReference (String JavaDoc orgName, ASN1Sequence numbers)
85    {
86       organization = new DisplayText (orgName);
87       noticeNumbers = numbers;
88    }
89
90    /**
91     * Creates a new <code>NoticeReference</code> instance.
92     *
93     * @param displayTextType an <code>int</code> value
94     * @param orgName a <code>String</code> value
95     * @param numbers an <code>ASN1EncodableVector</code> value
96     */

97    public NoticeReference (int displayTextType,
98                            String JavaDoc orgName, ASN1Sequence numbers)
99    {
100       organization = new DisplayText(displayTextType,
101                                      orgName);
102       noticeNumbers = numbers;
103    }
104
105    /**
106     * Creates a new <code>NoticeReference</code> instance.
107     * <p>Useful for reconstructing a <code>NoticeReference</code>
108     * instance from its encodable/encoded form.
109     *
110     * @param as an <code>ASN1Sequence</code> value obtained from either
111     * calling @{link toASN1Object()} for a <code>NoticeReference</code>
112     * instance or from parsing it from a DER-encoded stream.
113     */

114    public NoticeReference (ASN1Sequence as)
115    {
116       organization = DisplayText.getInstance(as.getObjectAt(0));
117       noticeNumbers = (ASN1Sequence) as.getObjectAt(1);
118    }
119
120    public static NoticeReference getInstance (Object JavaDoc as)
121    {
122       if (as instanceof NoticeReference)
123       {
124           return (NoticeReference)as;
125       }
126       else if (as instanceof ASN1Sequence)
127       {
128           return new NoticeReference((ASN1Sequence)as);
129       }
130
131       throw new IllegalArgumentException JavaDoc("unknown object in getInstance.");
132    }
133
134    /**
135     * Describe <code>toASN1Object</code> method here.
136     *
137     * @return a <code>DERObject</code> value
138     */

139    public DERObject toASN1Object()
140    {
141       ASN1EncodableVector av = new ASN1EncodableVector();
142       av.add (organization);
143       av.add (noticeNumbers);
144       return new DERSequence (av);
145    }
146 }
147
Popular Tags