OSDN Git Service

modifications for Java1.5
[bm-asn1/bm-asn1.git] / jp / bitmeister / asn1 / type / builtin / ANY.java
1 /*
2  * Copyright 2011 BitMeister Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package jp.bitmeister.asn1.type.builtin;
17
18 import jp.bitmeister.asn1.annotation.ASN1BuiltIn;
19 import jp.bitmeister.asn1.processor.ASN1Visitor;
20 import jp.bitmeister.asn1.type.ASN1TagClass;
21 import jp.bitmeister.asn1.type.ASN1Type;
22 import jp.bitmeister.asn1.type.PrimitiveType;
23
24 /**
25  * Represents ASN.1 'ANY' type.
26  * 
27  * <p>
28  * An instance of this class represents an 'ANY' type data, and has an
29  * {@code ASN1Type} value to contain any type of ASN.1 data.
30  * </p>
31  * 
32  * @author WATANABE, Jun. <jwat at bitmeister.jp>
33  */
34 @ASN1BuiltIn
35 public class ANY extends PrimitiveType<ASN1Type> {
36
37         /**
38          * Instantiates an empty {@code ANY}.
39          */
40         public ANY() {
41         }
42
43         /**
44          * Instantiates an {@code ANY} and initialize it with the {@code ASN1Type}
45          * value.
46          * 
47          * @param value
48          *            The ASN.1 data to be assigned.
49          */
50         public ANY(ASN1Type value) {
51                 set(value);
52         }
53
54         /*
55          * (non-Javadoc)
56          * 
57          * @see jp.bitmeister.asn1.type.PrimitiveType#hasValue()
58          */
59         @Override
60         public boolean hasValue() {
61                 if (value() != null) {
62                         return value().hasValue();
63                 }
64                 return false;
65         }
66
67         /*
68          * (non-Javadoc)
69          * 
70          * @see jp.bitmeister.asn1.type.ASN1Type#validate()
71          */
72         @Override
73         public void validate() {
74                 value().validate();
75         }
76
77         /*
78          * (non-Javadoc)
79          * 
80          * @see
81          * jp.bitmeister.asn1.type.ASN1Type#matches(jp.bitmeister.asn1.type.ASN1TagClass
82          * , int)
83          */
84         @Override
85         public boolean matches(ASN1TagClass tagClass, int tagNumber) {
86                 return true;
87         }
88
89         /* 
90          * (non-Javadoc)
91          * 
92          * @see jp.bitmeister.asn1.type.PrimitiveType#hashCode()
93          */
94         @Override
95         public int hashCode() {
96                 return 0;
97         }
98
99         /*
100          * (non-Javadoc)
101          * 
102          * @see
103          * jp.bitmeister.asn1.type.ASN1Type#accept(jp.bitmeister.asn1.processor.
104          * ASN1Visitor)
105          */
106         @Override
107         public <R, E extends Throwable> R accept(ASN1Visitor<R, E> visitor) throws E {
108                 return visitor.visit(this);
109         }
110
111 }