View Javadoc

1   /**
2    *
3    *  Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  
19  
20  package org.apache.geronimo.util.asn1.x509;
21  
22  import java.util.Enumeration;
23  import java.util.Vector;
24  
25  import org.apache.geronimo.util.asn1.ASN1Encodable;
26  import org.apache.geronimo.util.asn1.ASN1EncodableVector;
27  import org.apache.geronimo.util.asn1.ASN1Sequence;
28  import org.apache.geronimo.util.asn1.DERInteger;
29  import org.apache.geronimo.util.asn1.DERObject;
30  import org.apache.geronimo.util.asn1.DERSequence;
31  
32  /**
33   * <code>NoticeReference</code> class, used in
34   * <code>CertificatePolicies</code> X509 V3 extensions
35   * (in policy qualifiers).
36   *
37   * <pre>
38   *  NoticeReference ::= SEQUENCE {
39   *      organization     DisplayText,
40   *      noticeNumbers    SEQUENCE OF INTEGER }
41   *
42   * </pre>
43   *
44   * @see PolicyQualifierInfo
45   * @see PolicyInformation
46   */
47  public class NoticeReference
48      extends ASN1Encodable
49  {
50     DisplayText organization;
51     ASN1Sequence noticeNumbers;
52  
53     /**
54      * Creates a new <code>NoticeReference</code> instance.
55      *
56      * @param orgName a <code>String</code> value
57      * @param numbers a <code>Vector</code> value
58      */
59     public NoticeReference (String orgName, Vector numbers)
60     {
61        organization = new DisplayText(orgName);
62  
63        Object o = numbers.elementAt(0);
64  
65        ASN1EncodableVector av = new ASN1EncodableVector();
66        if (o instanceof Integer) {
67           Enumeration it = numbers.elements();
68  
69           while (it.hasMoreElements()) {
70              Integer nm = (Integer) it.nextElement();
71                 DERInteger di = new DERInteger(nm.intValue());
72              av.add (di);
73           }
74        }
75  
76        noticeNumbers = new DERSequence(av);
77     }
78  
79     /**
80      * Creates a new <code>NoticeReference</code> instance.
81      *
82      * @param orgName a <code>String</code> value
83      * @param numbers an <code>ASN1EncodableVector</code> value
84      */
85     public NoticeReference (String orgName, ASN1Sequence numbers)
86     {
87        organization = new DisplayText (orgName);
88        noticeNumbers = numbers;
89     }
90  
91     /**
92      * Creates a new <code>NoticeReference</code> instance.
93      *
94      * @param displayTextType an <code>int</code> value
95      * @param orgName a <code>String</code> value
96      * @param numbers an <code>ASN1EncodableVector</code> value
97      */
98     public NoticeReference (int displayTextType,
99                             String orgName, ASN1Sequence numbers)
100    {
101       organization = new DisplayText(displayTextType,
102                                      orgName);
103       noticeNumbers = numbers;
104    }
105 
106    /**
107     * Creates a new <code>NoticeReference</code> instance.
108     * <p>Useful for reconstructing a <code>NoticeReference</code>
109     * instance from its encodable/encoded form.
110     *
111     * @param as an <code>ASN1Sequence</code> value obtained from either
112     * calling @{link toASN1Object()} for a <code>NoticeReference</code>
113     * instance or from parsing it from a DER-encoded stream.
114     */
115    public NoticeReference (ASN1Sequence as)
116    {
117       organization = DisplayText.getInstance(as.getObjectAt(0));
118       noticeNumbers = (ASN1Sequence) as.getObjectAt(1);
119    }
120 
121    public static NoticeReference getInstance (Object as)
122    {
123       if (as instanceof NoticeReference)
124       {
125           return (NoticeReference)as;
126       }
127       else if (as instanceof ASN1Sequence)
128       {
129           return new NoticeReference((ASN1Sequence)as);
130       }
131 
132       throw new IllegalArgumentException("unknown object in getInstance.");
133    }
134 
135    /**
136     * Describe <code>toASN1Object</code> method here.
137     *
138     * @return a <code>DERObject</code> value
139     */
140    public DERObject toASN1Object()
141    {
142       ASN1EncodableVector av = new ASN1EncodableVector();
143       av.add (organization);
144       av.add (noticeNumbers);
145       return new DERSequence (av);
146    }
147 }