KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.math.BigInteger JavaDoc;
21
22 import org.apache.geronimo.util.asn1.ASN1Encodable;
23 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
24 import org.apache.geronimo.util.asn1.ASN1Sequence;
25 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
26 import org.apache.geronimo.util.asn1.DERInteger;
27 import org.apache.geronimo.util.asn1.DERObject;
28 import org.apache.geronimo.util.asn1.DERSequence;
29 import org.apache.geronimo.util.asn1.DERTaggedObject;
30
31 public class GeneralSubtree
32     extends ASN1Encodable
33 {
34     private GeneralName base;
35     private DERInteger minimum;
36     private DERInteger maximum;
37
38     public GeneralSubtree(
39         ASN1Sequence seq)
40     {
41         base = GeneralName.getInstance(seq.getObjectAt(0));
42
43         switch (seq.size())
44         {
45         case 1:
46             break;
47         case 2:
48             ASN1TaggedObject o = (ASN1TaggedObject)seq.getObjectAt(1);
49             switch (o.getTagNo())
50             {
51             case 0 :
52                 minimum = DERInteger.getInstance(o, false);
53                 break;
54             case 1 :
55                 maximum = DERInteger.getInstance(o, false);
56                 break;
57             default:
58                 throw new IllegalArgumentException JavaDoc("Bad tag number: " + o.getTagNo());
59             }
60             break;
61         case 3 :
62             minimum = DERInteger.getInstance((ASN1TaggedObject)seq.getObjectAt(1), false);
63             maximum = DERInteger.getInstance((ASN1TaggedObject)seq.getObjectAt(2), false);
64             break;
65         default:
66             throw new IllegalArgumentException JavaDoc("Bad sequence size: " + seq.size());
67         }
68     }
69
70     public static GeneralSubtree getInstance(
71         ASN1TaggedObject o,
72         boolean explicit)
73     {
74         return new GeneralSubtree(ASN1Sequence.getInstance(o, explicit));
75     }
76
77     public static GeneralSubtree getInstance(
78         Object JavaDoc obj)
79     {
80         if (obj == null)
81         {
82             return null;
83         }
84
85         if (obj instanceof GeneralSubtree)
86         {
87             return (GeneralSubtree)obj;
88         }
89
90         return new GeneralSubtree(ASN1Sequence.getInstance(obj));
91     }
92
93     public GeneralName getBase()
94     {
95         return base;
96     }
97
98     public BigInteger JavaDoc getMinimum()
99     {
100         if (minimum == null)
101         {
102             return BigInteger.valueOf(0);
103         }
104
105         return minimum.getValue();
106     }
107
108     public BigInteger JavaDoc getMaximum()
109     {
110         if (maximum == null)
111         {
112             return null;
113         }
114
115         return maximum.getValue();
116     }
117
118     /*
119      * GeneralSubtree ::= SEQUENCE {
120      * base GeneralName,
121      * minimum [0] BaseDistance DEFAULT 0,
122      * maximum [1] BaseDistance OPTIONAL }
123      */

124     public DERObject toASN1Object()
125     {
126         ASN1EncodableVector v = new ASN1EncodableVector();
127
128         v.add(base);
129
130         if (minimum != null)
131         {
132             v.add(new DERTaggedObject(false, 0, minimum));
133         }
134
135         if (maximum != null)
136         {
137             v.add(new DERTaggedObject(false, 1, maximum));
138         }
139
140         return new DERSequence(v);
141     }
142 }
143
Popular Tags