OSDN Git Service

* Add size restricted 'INTEGER' and 'ENUMERATED' types which contain a Long value.
[bm-asn1/bm-asn1.git] / jp / bitmeister / asn1 / type / builtin / CHOICE.java
1 /*
2  * Copyright 2011-2012 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.ASN1Alternative;
19 import jp.bitmeister.asn1.annotation.ASN1BuiltIn;
20 import jp.bitmeister.asn1.processor.ASN1Visitor;
21 import jp.bitmeister.asn1.type.ASN1TagClass;
22 import jp.bitmeister.asn1.type.ASN1Type;
23 import jp.bitmeister.asn1.type.SelectiveType;
24
25 /**
26  * Represents ASN.1 'CHOICE' type.
27  * 
28  * <p>
29  * This is the base class used for defining 'CHOICE' types. A sub-class of
30  * {@code CHOICE} shall have one or more fields annotated as
31  * {@code @ASN1Alternative}. When a value is assigned to one of the
32  * {@code @ASN1Alternative} fields of an instance, the field becomes selected
33  * field. If an instance has more than two fields which assigned value, the
34  * instance can't be encoded.
35  * </p>
36  * 
37  * @author WATANABE, Jun. <jwat at bitmeister.jp>
38  * 
39  * @see ASN1Alternative
40  */
41 @ASN1BuiltIn
42 public abstract class CHOICE extends SelectiveType {
43
44         /**
45          * Instantiates an empty {@code CHOICE}.
46          */
47         public CHOICE() {
48         }
49
50         /**
51          * Instantiates a {@code CHOICE} and initialize it with the parameter. The
52          * ASN.1 type of the data is used for select an alternative.
53          * 
54          * @param data
55          *            The data to be assigned.
56          */
57         public CHOICE(ASN1Type data) {
58                 super(data);
59         }
60
61         /**
62          * Instantiates a {@code CHOICE} and initialize it with parameters.
63          * 
64          * @param tagClass
65          *            The tag class used for select an alternative.
66          * @param tagNumber
67          *            The tag number used for select an alternative.
68          * @param data
69          *            The data to be assigned.
70          */
71         public CHOICE(ASN1TagClass tagClass, int tagNumber, ASN1Type data) {
72                 super(tagClass, tagNumber, data);
73         }
74
75         /**
76          * Instantiates a {@code CHOICE} and initialize it with parameters.
77          * 
78          * @param elementName
79          *            The element name used for select an alternative.
80          * @param data
81          *            The data to be assigned.
82          */
83         public CHOICE(String elementName, ASN1Type data) {
84                 super(elementName, data);
85         }
86
87         /*
88          * (non-Javadoc)
89          * 
90          * @see
91          * jp.bitmeister.asn1.type.ASN1Type#accept(jp.bitmeister.asn1.processor.
92          * ASN1Visitor)
93          */
94         @Override
95         public <R, E extends Throwable> R accept(ASN1Visitor<R, E> visitor)
96                         throws E {
97                 return visitor.visit(this);
98         }
99
100 }