KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > DERConstructedSet


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;
19
20 import java.io.ByteArrayOutputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.util.Enumeration JavaDoc;
23
24 /**
25  *
26  * @deprecated use DERSet
27  */

28 public class DERConstructedSet
29     extends ASN1Set
30 {
31     public DERConstructedSet()
32     {
33     }
34
35     /**
36      * @param obj - a single object that makes up the set.
37      */

38     public DERConstructedSet(
39         DEREncodable obj)
40     {
41         this.addObject(obj);
42     }
43
44     /**
45      * @param v - a vector of objects making up the set.
46      */

47     public DERConstructedSet(
48         DEREncodableVector v)
49     {
50         for (int i = 0; i != v.size(); i++)
51         {
52             this.addObject(v.get(i));
53         }
54     }
55
56     public void addObject(
57         DEREncodable obj)
58     {
59         super.addObject(obj);
60     }
61
62     public int getSize()
63     {
64         return size();
65     }
66
67     /*
68      * A note on the implementation:
69      * <p>
70      * As DER requires the constructed, definite-length model to
71      * be used for structured types, this varies slightly from the
72      * ASN.1 descriptions given. Rather than just outputing SET,
73      * we also have to specify CONSTRUCTED, and the objects length.
74      */

75     void encode(
76         DEROutputStream out)
77         throws IOException JavaDoc
78     {
79         ByteArrayOutputStream JavaDoc bOut = new ByteArrayOutputStream JavaDoc();
80         DEROutputStream dOut = new DEROutputStream(bOut);
81         Enumeration JavaDoc e = this.getObjects();
82
83         while (e.hasMoreElements())
84         {
85             Object JavaDoc obj = e.nextElement();
86
87             dOut.writeObject(obj);
88         }
89
90         dOut.close();
91
92         byte[] bytes = bOut.toByteArray();
93
94         out.writeEncoded(SET | CONSTRUCTED, bytes);
95     }
96 }
97
Popular Tags