001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    
019    package org.apache.geronimo.util.asn1.x509;
020    
021    import java.util.Enumeration;
022    import java.util.Vector;
023    
024    import org.apache.geronimo.util.asn1.ASN1Encodable;
025    import org.apache.geronimo.util.asn1.ASN1EncodableVector;
026    import org.apache.geronimo.util.asn1.ASN1Sequence;
027    import org.apache.geronimo.util.asn1.DERInteger;
028    import org.apache.geronimo.util.asn1.DERObject;
029    import org.apache.geronimo.util.asn1.DERSequence;
030    
031    /**
032     * <code>NoticeReference</code> class, used in
033     * <code>CertificatePolicies</code> X509 V3 extensions
034     * (in policy qualifiers).
035     *
036     * <pre>
037     *  NoticeReference ::= SEQUENCE {
038     *      organization     DisplayText,
039     *      noticeNumbers    SEQUENCE OF INTEGER }
040     *
041     * </pre>
042     *
043     * @see PolicyQualifierInfo
044     * @see PolicyInformation
045     */
046    public class NoticeReference
047        extends ASN1Encodable
048    {
049       DisplayText organization;
050       ASN1Sequence noticeNumbers;
051    
052       /**
053        * Creates a new <code>NoticeReference</code> instance.
054        *
055        * @param orgName a <code>String</code> value
056        * @param numbers a <code>Vector</code> value
057        */
058       public NoticeReference (String orgName, Vector numbers)
059       {
060          organization = new DisplayText(orgName);
061    
062          Object o = numbers.elementAt(0);
063    
064          ASN1EncodableVector av = new ASN1EncodableVector();
065          if (o instanceof Integer) {
066             Enumeration it = numbers.elements();
067    
068             while (it.hasMoreElements()) {
069                Integer nm = (Integer) it.nextElement();
070                   DERInteger di = new DERInteger(nm.intValue());
071                av.add (di);
072             }
073          }
074    
075          noticeNumbers = new DERSequence(av);
076       }
077    
078       /**
079        * Creates a new <code>NoticeReference</code> instance.
080        *
081        * @param orgName a <code>String</code> value
082        * @param numbers an <code>ASN1EncodableVector</code> value
083        */
084       public NoticeReference (String orgName, ASN1Sequence numbers)
085       {
086          organization = new DisplayText (orgName);
087          noticeNumbers = numbers;
088       }
089    
090       /**
091        * Creates a new <code>NoticeReference</code> instance.
092        *
093        * @param displayTextType an <code>int</code> value
094        * @param orgName a <code>String</code> value
095        * @param numbers an <code>ASN1EncodableVector</code> value
096        */
097       public NoticeReference (int displayTextType,
098                               String orgName, ASN1Sequence numbers)
099       {
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 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("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    }