KickJava   Java API By Example, From Geeks To Geeks.

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


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.ASN1TaggedObject;
24 import org.apache.geronimo.util.asn1.DERBitString;
25 import org.apache.geronimo.util.asn1.DERObject;
26 import org.apache.geronimo.util.asn1.DERSequence;
27 import org.apache.geronimo.util.asn1.DERTaggedObject;
28
29 /**
30  * The DistributionPoint object.
31  * <pre>
32  * DistributionPoint ::= SEQUENCE {
33  * distributionPoint [0] DistributionPointName OPTIONAL,
34  * reasons [1] ReasonFlags OPTIONAL,
35  * cRLIssuer [2] GeneralNames OPTIONAL
36  * }
37  * </pre>
38  */

39 public class DistributionPoint
40     extends ASN1Encodable
41 {
42     DistributionPointName distributionPoint;
43     ReasonFlags reasons;
44     GeneralNames cRLIssuer;
45
46     public static DistributionPoint getInstance(
47         ASN1TaggedObject obj,
48         boolean explicit)
49     {
50         return getInstance(ASN1Sequence.getInstance(obj, explicit));
51     }
52
53     public static DistributionPoint getInstance(
54         Object JavaDoc obj)
55     {
56         if(obj == null || obj instanceof DistributionPoint)
57         {
58             return (DistributionPoint)obj;
59         }
60
61         if(obj instanceof ASN1Sequence)
62         {
63             return new DistributionPoint((ASN1Sequence)obj);
64         }
65
66         throw new IllegalArgumentException JavaDoc("Invalid DistributionPoint: " + obj.getClass().getName());
67     }
68
69     public DistributionPoint(
70         ASN1Sequence seq)
71     {
72         for (int i = 0; i != seq.size(); i++)
73         {
74             ASN1TaggedObject t = (ASN1TaggedObject)seq.getObjectAt(i);
75             switch (t.getTagNo())
76             {
77             case 0:
78                 distributionPoint = DistributionPointName.getInstance(t, true);
79                 break;
80             case 1:
81                 reasons = new ReasonFlags(DERBitString.getInstance(t, false));
82                 break;
83             case 2:
84                 cRLIssuer = GeneralNames.getInstance(t, false);
85             }
86         }
87     }
88
89     public DistributionPoint(
90         DistributionPointName distributionPoint,
91         ReasonFlags reasons,
92         GeneralNames cRLIssuer)
93     {
94         this.distributionPoint = distributionPoint;
95         this.reasons = reasons;
96         this.cRLIssuer = cRLIssuer;
97     }
98
99     public DistributionPointName getDistributionPoint()
100     {
101         return distributionPoint;
102     }
103
104     public ReasonFlags getReasons()
105     {
106         return reasons;
107     }
108
109     public GeneralNames getCRLIssuer()
110     {
111         return cRLIssuer;
112     }
113
114     public DERObject toASN1Object()
115     {
116         ASN1EncodableVector v = new ASN1EncodableVector();
117
118         if (distributionPoint != null)
119         {
120             //
121
// as this is a CHOICE it must be explicitly tagged
122
//
123
v.add(new DERTaggedObject(0, distributionPoint));
124         }
125
126         if (reasons != null)
127         {
128             v.add(new DERTaggedObject(false, 1, reasons));
129         }
130
131         if (cRLIssuer != null)
132         {
133             v.add(new DERTaggedObject(false, 2, cRLIssuer));
134         }
135
136         return new DERSequence(v);
137     }
138 }
139
Popular Tags