OSDN Git Service

Bug fix on XerEncoder.
[bm-asn1/bm-asn1.git] / jp / bitmeister / asn1 / type / builtin / SEQUENCE_OF.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 java.util.ArrayList;
19 import java.util.Collection;
20
21 import jp.bitmeister.asn1.annotation.ASN1BuiltIn;
22 import jp.bitmeister.asn1.annotation.ASN1Identifier;
23 import jp.bitmeister.asn1.annotation.ASN1Tag;
24 import jp.bitmeister.asn1.annotation.ASN1XmlTypeName;
25 import jp.bitmeister.asn1.processor.ASN1Visitor;
26 import jp.bitmeister.asn1.type.ASN1TagClass;
27 import jp.bitmeister.asn1.type.ASN1TagMode;
28 import jp.bitmeister.asn1.type.ASN1Type;
29 import jp.bitmeister.asn1.type.CollectionType;
30
31 /**
32  * Represents ASN.1 'SEQUENCE OF' type.
33  * 
34  * <p>
35  * This is the class used for defining 'SEQUENCE OF' types. Generic type
36  * parameter {@code T} indicates component type of the 'SEQUENCE OF' type.
37  * Constructors of a sub-class of {@code SEQUENCE_OF} must call parent
38  * constructor with {@code componentType} parameter that is the class object of
39  * {@code T} in them.
40  * </p>
41  * 
42  * @author WATANABE, Jun. <jwat at bitmeister.jp>
43  */
44 @ASN1BuiltIn
45 @ASN1Identifier("SEQUENCE")
46 @ASN1XmlTypeName("SEQUENCE_OF")
47 @ASN1Tag(tagClass = ASN1TagClass.UNIVERSAL, value = 16, tagMode = ASN1TagMode.IMPLICIT)
48 public abstract class SEQUENCE_OF<T extends ASN1Type> extends CollectionType<T> {
49
50         /**
51          * Instantiate an empty {@code SEQUENCE_OF}.
52          * 
53          * @param componentType
54          *            The class instance of component type.
55          */
56         public SEQUENCE_OF(Class<T> componentType) {
57                 super(componentType);
58         }
59
60         /**
61          * Instantiate a {@code SEQUENCE_OF} and initialize it with the components.
62          * 
63          * @param componentType
64          *            The class instance of component type.
65          * @param components
66          *            Components to be set this instance.
67          */
68         public SEQUENCE_OF(Class<T> componentType, T... components) {
69                 super(componentType, components);
70         }
71
72         /*
73          * (non-Javadoc)
74          * 
75          * @see jp.bitmeister.asn1.type.CollectionType#newCollection()
76          */
77         @Override
78         protected Collection<T> newCollection() {
79                 return new ArrayList<T>();
80         }
81
82         /*
83          * (non-Javadoc)
84          * 
85          * @see
86          * jp.bitmeister.asn1.type.ASN1Type#accept(jp.bitmeister.asn1.processor.
87          * ASN1Visitor)
88          */
89         @Override
90         public <R, E extends Throwable> R accept(ASN1Visitor<R, E> visitor)
91                         throws E {
92                 return visitor.visit(this);
93         }
94
95 }