2 * Copyright 2011 BitMeister Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package jp.bitmeister.asn1.type.builtin;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
23 import jp.bitmeister.asn1.annotation.ASN1BuiltIn;
24 import jp.bitmeister.asn1.annotation.ASN1Identifier;
25 import jp.bitmeister.asn1.annotation.ASN1Tag;
26 import jp.bitmeister.asn1.annotation.ASN1XmlTypeName;
27 import jp.bitmeister.asn1.exception.ASN1IllegalArgument;
28 import jp.bitmeister.asn1.processor.ASN1Visitor;
29 import jp.bitmeister.asn1.type.ASN1TagClass;
30 import jp.bitmeister.asn1.type.ASN1TagMode;
31 import jp.bitmeister.asn1.type.PrimitiveType;
34 * Represents ASN.1 'OBJECT IDENTIFIER' type.
37 * An instance of this class represents an 'OBJECT IDENTIFIER' type data and
38 * contains a {@code List} of {@code Integer}. Each element of the {@code List}
39 * represents an object id component.
42 * @author WATANABE, Jun. <jwat at bitmeister.jp>
45 @ASN1Identifier("OBJECT IDENTIFIER")
46 @ASN1XmlTypeName("OBJECT_IDENTIFIER")
47 @ASN1Tag(tagClass = ASN1TagClass.UNIVERSAL, value = 6, tagMode = ASN1TagMode.IMPLICIT)
48 public class OBJECT_IDENTIFIER extends PrimitiveType<List<Integer>> {
50 private static Map<String, Integer> NAMES_ROOT = new HashMap<String, Integer>();
51 private static Map<String, Integer> NAMES_ITU_T = new HashMap<String, Integer>();
52 private static Map<String, Integer> NAMES_ISO = new HashMap<String, Integer>();
53 private static Map<String, Integer> NAMES_ITU_T_REC = new HashMap<String, Integer>();
57 NAMES_ROOT.put("itu-t", 0);
58 NAMES_ROOT.put("ccitt", 0);
59 NAMES_ROOT.put("iso", 1);
60 NAMES_ROOT.put("joint-iso-itu-t", 2);
61 NAMES_ROOT.put("joint-iso-ccitt", 2);
63 NAMES_ITU_T.put("recommendation", 0);
64 NAMES_ITU_T.put("question", 1);
65 NAMES_ITU_T.put("administration", 2);
66 NAMES_ITU_T.put("network-operator", 3);
67 NAMES_ITU_T.put("identified-organization", 4);
68 NAMES_ITU_T.put("r-recommendation", 5);
70 NAMES_ISO.put("standard", 0);
71 NAMES_ISO.put("registration-authority", 1);
72 NAMES_ISO.put("member-body", 2);
73 NAMES_ISO.put("identified-organization", 3);
74 // itu-t recommendation
75 for (char c = 'a'; c <= 'z'; c++) {
76 NAMES_ITU_T_REC.put(String.valueOf(c), c - 'a');
80 public static int nameFormToInt(List<Integer> list, String nameForm) {
81 Integer number = null;
82 if (list.size() == 0) {
83 number = NAMES_ROOT.get(nameForm);
85 else if (list.size() == 1) {
86 if (list.get(0) == 0) {
87 number = NAMES_ITU_T.get(nameForm);
89 else if (list.get(0) == 1) {
90 number = NAMES_ISO.get(nameForm);
93 else if (list.size() == 2 && list.get(0) == 0 && list.get(1) == 0) {
94 number = NAMES_ITU_T_REC.get(nameForm);
97 ASN1IllegalArgument e = new ASN1IllegalArgument();
98 e.setMessage("Invalid OID name form '" + nameForm + "'.", null, OBJECT_IDENTIFIER.class, null, null);
105 * Instantiates an empty {@code OBJECT_IDENTIFIER}.
107 public OBJECT_IDENTIFIER() {
111 * Instantiates an {@code OBJECT_IDENTIFIER} and initialize it with the
112 * {@code List<Integer>} value.
115 * the {@code List} of {@code Integer} represents an object
118 public OBJECT_IDENTIFIER(List<Integer> value) {
123 * Instantiates an {@code OBJECT_IDENTIFIER} and initialize it with the
124 * array of {@code int} value.
127 * the array of {@code int} represents an object identifier.
129 public OBJECT_IDENTIFIER(int... value) {
134 * Sets the array of {@code int} to the data.
137 * the array of {@code int} represents an object identifier.
139 public void set(int... value) {
140 List<Integer> oids = new ArrayList<Integer>();
141 for (int i : value) {
150 * @see jp.bitmeister.asn1.type.PrimitiveType#cloneValue()
153 protected List<Integer> cloneValue() {
154 List<Integer> clone = new ArrayList<Integer>();
155 clone.addAll(value());
163 * jp.bitmeister.asn1.type.ASN1Type#accept(jp.bitmeister.asn1.processor.
167 public <R, E extends Throwable> R accept(ASN1Visitor<R, E> visitor) throws E {
168 return visitor.visit(this);