KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.geronimo.util.asn1.x509;
19
20 import org.apache.geronimo.util.asn1.ASN1Encodable;
21 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
22 import org.apache.geronimo.util.asn1.ASN1Sequence;
23 import org.apache.geronimo.util.asn1.DERObject;
24 import org.apache.geronimo.util.asn1.DERSequence;
25
26 /**
27  * <code>UserNotice</code> class, used in
28  * <code>CertificatePolicies</code> X509 extensions (in policy
29  * qualifiers).
30  * <pre>
31  * UserNotice ::= SEQUENCE {
32  * noticeRef NoticeReference OPTIONAL,
33  * explicitText DisplayText OPTIONAL}
34  *
35  * </pre>
36  *
37  * @see PolicyQualifierId
38  * @see PolicyInformation
39  */

40 public class UserNotice
41     extends ASN1Encodable
42 {
43     NoticeReference noticeRef;
44     DisplayText explicitText;
45
46     /**
47      * Creates a new <code>UserNotice</code> instance.
48      *
49      * @param noticeRef a <code>NoticeReference</code> value
50      * @param explicitText a <code>DisplayText</code> value
51      */

52     public UserNotice(
53         NoticeReference noticeRef,
54         DisplayText explicitText)
55     {
56         this.noticeRef = noticeRef;
57         this.explicitText = explicitText;
58     }
59
60     /**
61      * Creates a new <code>UserNotice</code> instance.
62      *
63      * @param noticeRef a <code>NoticeReference</code> value
64      * @param str the explicitText field as a String.
65      */

66     public UserNotice(
67         NoticeReference noticeRef,
68         String JavaDoc str)
69     {
70         this.noticeRef = noticeRef;
71         this.explicitText = new DisplayText(str);
72     }
73
74    /**
75     * Creates a new <code>UserNotice</code> instance.
76     * <p>Useful from reconstructing a <code>UserNotice</code> instance
77     * from its encodable/encoded form.
78     *
79     * @param as an <code>ASN1Sequence</code> value obtained from either
80     * calling @{link toASN1Object()} for a <code>UserNotice</code>
81     * instance or from parsing it from a DER-encoded stream.
82     */

83    public UserNotice(
84        ASN1Sequence as)
85    {
86        if (as.size() == 2)
87        {
88            noticeRef = NoticeReference.getInstance(as.getObjectAt(0));
89            explicitText = DisplayText.getInstance(as.getObjectAt(1));
90        }
91        else if (as.size() == 1)
92        {
93            if (as.getObjectAt(0).getDERObject() instanceof ASN1Sequence)
94            {
95                noticeRef = NoticeReference.getInstance(as.getObjectAt(0));
96            }
97            else
98            {
99                explicitText = DisplayText.getInstance(as.getObjectAt(0));
100            }
101        }
102     }
103
104     public DERObject toASN1Object()
105     {
106         ASN1EncodableVector av = new ASN1EncodableVector();
107
108         if (noticeRef != null)
109         {
110             av.add(noticeRef);
111         }
112
113         if (explicitText != null)
114         {
115             av.add(explicitText);
116         }
117
118         return new DERSequence(av);
119     }
120 }
121
Popular Tags