OSDN Git Service

X.690 Amendment1 (10/2003)
[bm-asn1/bm-asn1.git] / jp / bitmeister / asn1 / annotation / ASN1Alternative.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.annotation;
17
18 import java.lang.annotation.ElementType;
19 import java.lang.annotation.Retention;
20 import java.lang.annotation.RetentionPolicy;
21 import java.lang.annotation.Target;
22
23 import jp.bitmeister.asn1.type.SelectiveType;
24 import jp.bitmeister.asn1.type.builtin.CHOICE;
25
26 /**
27  * Indicates that a field is a 'CHOICE' alternative.
28  * 
29  * <p>
30  * If an {@code @ASN1Alternative} annotation is present on a field, the field is
31  * treated as an alternative of a sub-class of {@code SelectiveType}. A field
32  * annotated as {@code @ASN1Alternative} must be declared as {@code public}
33  * non-{@code final} non-{@code static}, and the type shall be a sub-class of
34  * {@code ASN1Type}. The {@code value} parameter represents an order of
35  * appearance of a field in an ASN.1 type definition and is used for automatic
36  * tagging.
37  * </p>
38  * <p>
39  * For example, following ASN.1 definition :
40  * 
41  * <pre>
42  * Sample ::= CHOICE {
43  *      number  INTEGER,
44  *      bool    BOOLEAN }
45  * </pre>
46  * 
47  * can be translated as :
48  * 
49  * <code><pre>
50  * public class Sample extends CHOICE {
51  * 
52  *      &#064;ASN1Alternative(0)
53  *      public INTEGER number;
54  * 
55  *      &#064;ASN1Alternative(1)
56  *      public BOOLEAN bool;
57  * 
58  * }
59  * </pre></code>
60  * 
61  * @author WATANABE, Jun. <jwat at bitmeister.jp>
62  * 
63  * @see SelectiveType
64  * @see CHOICE
65  */
66 @Target(ElementType.FIELD)
67 @Retention(RetentionPolicy.RUNTIME)
68 public @interface ASN1Alternative {
69
70         /**
71          * Indicates defined order of this element.
72          * 
73          * @return Order of this element.
74          */
75         public int value() default 0;
76
77 }