KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > commons > security > asn1 > Context


1
2 package com.ca.commons.security.asn1;
3
4 /**
5  * This class represents ASN.1 context specifically tagged types.
6  * @see iss.security.asn1.ASN1Object
7  *
8  * @author who
9  */

10 public class Context extends ASN1Object implements java.io.Serializable JavaDoc
11 {
12
13     private ASN1Object value;
14     private boolean implicit; //explicit or implicit tagging
15
private int tag; //one byte 00xxxxxx
16

17     /**
18      * Default constructor.
19      */

20     public Context()
21     {}
22     
23     /**
24      * Creates a Context object.
25      * @param t the tag.
26      * @param imp the flag indicating whether the Context object is using
27      * implicit tagging or explicit tagging.
28      * @param o the underlying ASN1Object of the Context object. It can be
29      * a Primitive or Sequence object but cannot be another Context object.
30      * Otherwise an IllegalArgumentException is thrown.
31      */

32     public Context(int t, boolean imp, ASN1Object o)
33     {
34         asn1Type = ASN1Type.ContextSpecific;
35         byteArray = null;
36         tag = t;
37         implicit = imp;
38         
39         if (o instanceof Primitive)
40         {
41             value = o;
42         }
43         else if (o instanceof Sequence)
44         {
45             value = o;
46         }
47         else if (o instanceof Context)
48         {
49             value = o;
50         }
51         else
52         {
53             throw new IllegalArgumentException JavaDoc("invalid ContextSpecific"+
54                                                " underlying object");
55         }
56     }
57     
58     /**
59      * Initializes the Context object.
60      */

61     public void init(ASN1Type type)
62     {
63         asn1Type = type;
64         byteArray = null;
65         implicit = false;
66         tag = 0;
67         value = null;
68     }
69     
70     /**
71      * Sets the value of the Cotext object as the given object. If the given
72      * object is also a Context object, this method copies the content of
73      * the given object to this object. If the given object is not suitable
74      * for this operation, an IllegalArgumentException is thrown.
75      */

76     public void setValue(Object JavaDoc o)
77     {
78         if (o instanceof Context)
79         {
80             Context obj = (Context) o;
81             tag = obj.getTag();
82             value = (ASN1Object) (obj.getValue());
83             implicit = obj.implicit();
84         }
85         else
86         {
87             throw new IllegalArgumentException JavaDoc("incompatible type");
88         }
89     }
90     
91     /**
92      * Gets the value of the Cotext object.
93      */

94     public Object JavaDoc getValue()
95     {
96         return value;
97     }
98     
99     /**
100      * Gets the tag of the Cotext object.
101      */

102     public int getTag()
103     {
104         return tag;
105     }
106     
107     /**
108      * Gets the flag which indicates implicit/explicit tagging of the
109      * Cotext object.
110      */

111     public boolean implicit()
112     {
113         return implicit;
114     }
115     
116     /**
117      * Returns whether two objects are the same.
118     public boolean equals(Object o) {
119         if (!(o instanceof iss.security.asn1.Context)) {
120             return false;
121         }
122         if (!this.asn1Type.equals(o.asn1Type)) {
123             return false;
124         }
125         if (this.tag != o.tag) {
126             return false;
127         }
128         if (this.implicit != o.implicit) {
129             return false;
130         }
131         if (!this.value.equals(o.value)) {
132             return false;
133         }
134         return true;
135 }
136      */

137     
138     /**
139      * Gets the string description of the Cotext object.
140      */

141     public String JavaDoc toString()
142     {
143         String JavaDoc s = super.toString();
144         s += "\n\tcontext specific tag [" + tag + "] implicit? " + implicit;
145         s += "\n\tunderlying type: " + value.toString();
146         return s;
147     }
148 }
149
Popular Tags