KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > novosec > pkix > asn1 > cmp > GenMsgContent


1 // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
2
//
3
// Author: Maik Stohn
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
6
// software and associated documentation files (the "Software"), to deal in the Software
7
// without restriction, including without limitation the rights to use, copy, modify, merge,
8
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
9
// to whom the Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included in all copies or
12
// substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
15
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19

20 package com.novosec.pkix.asn1.cmp;
21
22 import java.util.Enumeration JavaDoc;
23 import java.util.Vector JavaDoc;
24
25 import org.bouncycastle.asn1.ASN1EncodableVector;
26 import org.bouncycastle.asn1.ASN1Sequence;
27 import org.bouncycastle.asn1.ASN1TaggedObject;
28 import org.bouncycastle.asn1.DEREncodable;
29 import org.bouncycastle.asn1.DERObject;
30 import org.bouncycastle.asn1.DERSequence;
31
32 /**
33  * ASN.1 structure DER En/DeCoder.
34  *
35  * <pre>
36  * GenMsgContent ::= SEQUENCE OF InfoTypeAndValue
37  *
38  * </pre>
39  */

40 public class GenMsgContent implements DEREncodable
41 {
42     Vector JavaDoc infoTypesAndValues = new Vector JavaDoc();
43
44     public static GenMsgContent getInstance( ASN1TaggedObject obj, boolean explicit )
45     {
46         return getInstance(ASN1Sequence.getInstance(obj, explicit));
47     }
48
49     public static GenMsgContent getInstance( Object JavaDoc obj )
50     {
51         if (obj instanceof GenMsgContent)
52         {
53             return (GenMsgContent)obj;
54         }
55         else if (obj instanceof ASN1Sequence)
56         {
57             return new GenMsgContent((ASN1Sequence)obj);
58         }
59
60         throw new IllegalArgumentException JavaDoc("unknown object in factory");
61     }
62
63     public GenMsgContent( ASN1Sequence seq )
64     {
65         Enumeration JavaDoc e = seq.getObjects();
66         while (e.hasMoreElements())
67         {
68             InfoTypeAndValue s = InfoTypeAndValue.getInstance(e.nextElement());
69             infoTypesAndValues.addElement(s);
70         }
71     }
72
73     public GenMsgContent( InfoTypeAndValue infoTypeAndValue )
74     {
75       infoTypesAndValues.addElement( infoTypeAndValue );
76     }
77
78     public void addInfoTypeAndValue( InfoTypeAndValue infoTypeAndValue )
79     {
80       infoTypesAndValues.addElement( infoTypeAndValue );
81     }
82     
83     public InfoTypeAndValue getInfoTypeAndValue(int nr)
84     {
85       if (infoTypesAndValues.size() > nr)
86         return (InfoTypeAndValue)infoTypesAndValues.elementAt(nr);
87
88       return null;
89     }
90
91     public DERObject getDERObject()
92     {
93         ASN1EncodableVector v = new ASN1EncodableVector();
94
95         for (int i=0;i<infoTypesAndValues.size();i++)
96         {
97           v.add((InfoTypeAndValue)infoTypesAndValues.elementAt(i));
98         }
99
100         return new DERSequence(v);
101     }
102
103     public String JavaDoc toString()
104     {
105         String JavaDoc p = null;
106         for (int i=0;i<infoTypesAndValues.size();i++)
107         {
108           if( p == null )
109             p = ((InfoTypeAndValue)infoTypesAndValues.elementAt(i)).toString();
110           else
111             p += (InfoTypeAndValue)infoTypesAndValues.elementAt(i);
112         }
113         return "GenMsgContent: "+p;
114     }
115 }
116
Popular Tags