OSDN Git Service

Version 0.11
[bm-asn1/bm-asn1.git] / jp / bitmeister / asn1 / type / builtin / OBJECT_IDENTIFIER.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.List;
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.processor.ASN1Visitor;
25 import jp.bitmeister.asn1.type.ASN1TagClass;
26 import jp.bitmeister.asn1.type.ASN1TagMode;
27 import jp.bitmeister.asn1.type.PrimitiveType;
28
29 /**
30  * Represents ASN.1 'OBJECT IDENTIFIER' type.
31  * 
32  * <p>
33  * An instance of this class represents an 'OBJECT IDENTIFIER' type data and
34  * contains a {@code List} of {@code Integer}. Each element of the {@code List}
35  * represents an object id component.
36  * </p>
37  * 
38  * @author WATANABE, Jun. <jwat at bitmeister.jp>
39  */
40 @ASN1BuiltIn
41 @ASN1Identifier("OBJECT IDENTIFIER")
42 @ASN1Tag(tagClass = ASN1TagClass.UNIVERSAL, value = 6, tagMode = ASN1TagMode.IMPLICIT)
43 public class OBJECT_IDENTIFIER extends PrimitiveType<List<Integer>> {
44
45         /**
46          * Instantiates an empty {@code OBJECT_IDENTIFIER}.
47          */
48         public OBJECT_IDENTIFIER() {
49         }
50
51         /**
52          * Instantiates an {@code OBJECT_IDENTIFIER} and initialize it with the
53          * {@code List<Integer>} value.
54          * 
55          * @param value
56          *            the {@code List} of {@code Integer} represents an object
57          *            identifier.
58          */
59         public OBJECT_IDENTIFIER(List<Integer> value) {
60                 set(value);
61         }
62
63         /**
64          * Instantiates an {@code OBJECT_IDENTIFIER} and initialize it with the
65          * array of {@code int} value.
66          * 
67          * @param value
68          *            the array of {@code int} represents an object identifier.
69          */
70         public OBJECT_IDENTIFIER(int... value) {
71                 set(value);
72         }
73
74         /**
75          * Sets the array of {@code int} to the data.
76          * 
77          * @param value
78          *            the array of {@code int} represents an object identifier.
79          */
80         public void set(int... value) {
81                 List<Integer> oids = new ArrayList<Integer>();
82                 for (int i : value) {
83                         oids.add(i);
84                 }
85                 set(oids);
86         }
87
88         /*
89          * (non-Javadoc)
90          * 
91          * @see jp.bitmeister.asn1.type.PrimitiveType#cloneValue()
92          */
93         @Override
94         protected List<Integer> cloneValue() {
95                 List<Integer> clone = new ArrayList<Integer>();
96                 clone.addAll(value());
97                 return clone;
98         }
99
100         /*
101          * (non-Javadoc)
102          * 
103          * @see
104          * jp.bitmeister.asn1.type.ASN1Type#accept(jp.bitmeister.asn1.processor.
105          * ASN1Visitor)
106          */
107         @Override
108         public <R, E extends Throwable> R accept(ASN1Visitor<R, E> visitor) throws E {
109                 return visitor.visit(this);
110         }
111
112 }