blob: 3506c56fb66e3c2fe30ce4ad30a8bd7c2abfe424 [file] [log] [blame]
Vinod Kumar Scf044422016-02-09 19:53:45 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vinod Kumar Scf044422016-02-09 19:53:45 +05303 *
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
Gaurav Agrawal72cd1b72016-06-30 13:28:14 +053017package org.onosproject.yangutils.datamodel.utils.builtindatatype;
Vinod Kumar Scf044422016-02-09 19:53:45 +053018
19/**
Bharat saraswald9822e92016-04-05 15:13:44 +053020 * Represents ENUM to identify the YANG data type.
Vinod Kumar Scf044422016-02-09 19:53:45 +053021 */
22public enum YangDataTypes {
23 /**
24 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053025 *
Vinod Kumar Scf044422016-02-09 19:53:45 +053026 * int8 represents integer values between -128 and 127, inclusively.
27 */
janani be18b5342016-07-13 21:06:41 +053028 INT8("int8"),
Vinod Kumar Scf044422016-02-09 19:53:45 +053029
30 /**
31 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053032 *
Vinod Kumar Scf044422016-02-09 19:53:45 +053033 * int16 represents integer values between -32768 and 32767, inclusively.
34 */
janani be18b5342016-07-13 21:06:41 +053035 INT16("int16"),
Vinod Kumar Scf044422016-02-09 19:53:45 +053036
37 /**
38 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053039 *
Vinod Kumar Scf044422016-02-09 19:53:45 +053040 * int32 represents integer values between -2147483648 and 2147483647,
41 * inclusively.
42 */
janani be18b5342016-07-13 21:06:41 +053043 INT32("int32"),
Vinod Kumar Scf044422016-02-09 19:53:45 +053044
45 /**
46 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053047 *
Vinod Kumar Scf044422016-02-09 19:53:45 +053048 * int64 represents integer values between -9223372036854775808 and
49 * 9223372036854775807, inclusively.
50 */
janani be18b5342016-07-13 21:06:41 +053051 INT64("int64"),
Vinod Kumar Scf044422016-02-09 19:53:45 +053052
53 /**
54 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053055 *
Vinod Kumar Scf044422016-02-09 19:53:45 +053056 * uint8 represents integer values between 0 and 255, inclusively.
57 */
janani be18b5342016-07-13 21:06:41 +053058 UINT8("uint8"),
Vinod Kumar Scf044422016-02-09 19:53:45 +053059
60 /**
61 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053062 *
Vinod Kumar Scf044422016-02-09 19:53:45 +053063 * uint16 represents integer values between 0 and 65535, inclusively.
64 */
janani be18b5342016-07-13 21:06:41 +053065 UINT16("uint16"),
Vinod Kumar Scf044422016-02-09 19:53:45 +053066
67 /**
68 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053069 *
Vinod Kumar Scf044422016-02-09 19:53:45 +053070 * uint32 represents integer values between 0 and 4294967295, inclusively.
71 */
janani be18b5342016-07-13 21:06:41 +053072 UINT32("uint32"),
Vinod Kumar Scf044422016-02-09 19:53:45 +053073
74 /**
75 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053076 *
Vinod Kumar Scf044422016-02-09 19:53:45 +053077 * uint64 represents integer values between 0 and 18446744073709551615,
78 * inclusively.
79 */
janani be18b5342016-07-13 21:06:41 +053080 UINT64("uint64"),
Vinod Kumar Scf044422016-02-09 19:53:45 +053081
82 /**
83 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053084 *
Vinod Kumar Scf044422016-02-09 19:53:45 +053085 * The decimal64 type represents a subset of the real numbers, which can be
86 * represented by decimal numerals. The value space of decimal64 is the set
87 * of numbers that can be obtained by multiplying a 64-bit signed integer by
88 * a negative power of ten, i.e., expressible as "i x 10^-n" where i is an
89 * integer64 and n is an integer between 1 and 18, inclusively.
90 */
janani be18b5342016-07-13 21:06:41 +053091 DECIMAL64("decimal64"), // TODO: need to implement in type.
Vinod Kumar Scf044422016-02-09 19:53:45 +053092
93 /**
94 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +053095 *
Vinod Kumar Scf044422016-02-09 19:53:45 +053096 * The string built-in type represents human-readable strings in YANG. Legal
97 * characters are tab, carriage return, line feed, and the legal characters
98 * of Unicode and ISO/IEC 10646
99 */
janani be18b5342016-07-13 21:06:41 +0530100 STRING("string"),
Vinod Kumar Scf044422016-02-09 19:53:45 +0530101
102 /**
103 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530104 *
Vinod Kumar Scf044422016-02-09 19:53:45 +0530105 * The boolean built-in type represents a boolean value.
106 */
janani be18b5342016-07-13 21:06:41 +0530107 BOOLEAN("boolean"),
Vinod Kumar Scf044422016-02-09 19:53:45 +0530108
109 /**
110 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530111 *
Vinod Kumar Scf044422016-02-09 19:53:45 +0530112 * The enumeration built-in type represents values from a set of assigned
113 * names.
114 */
janani be18b5342016-07-13 21:06:41 +0530115 ENUMERATION("enumeration"),
Vinod Kumar Scf044422016-02-09 19:53:45 +0530116
117 /**
118 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530119 *
Vinod Kumar Scf044422016-02-09 19:53:45 +0530120 * The bits built-in type represents a bit set. That is, a bits value is a
121 * set of flags identified by small integer position numbers starting at 0.
122 * Each bit number has an assigned name.
123 */
janani be18b5342016-07-13 21:06:41 +0530124 BITS("bits"),
Vinod Kumar Scf044422016-02-09 19:53:45 +0530125
126 /**
127 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530128 *
Vinod Kumar Scf044422016-02-09 19:53:45 +0530129 * The binary built-in type represents any binary data, i.e., a sequence of
130 * octets.
131 */
janani be18b5342016-07-13 21:06:41 +0530132 BINARY("binary"),
Vinod Kumar Scf044422016-02-09 19:53:45 +0530133
134 /**
135 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530136 *
Vinod Kumar Scf044422016-02-09 19:53:45 +0530137 * The leafref type is used to reference a particular leaf instance in the
138 * data tree. The "path" sub-statement (Section 9.9.2) selects a set of leaf
139 * instances, and the leafref value space is the set of values of these leaf
140 * instances.
141 *
142 * If the leaf with the leafref type represents configuration data, the leaf
143 * it refers to MUST also represent configuration. Such a leaf puts a
144 * constraint on valid data. All leafref nodes MUST reference existing leaf
145 * instances or leafs with default values in use for the data to be valid.
146 *
147 * There MUST NOT be any circular chains of leafrefs.
148 *
149 * If the leaf that the leafref refers to is conditional based on one or
150 * more features, then the leaf with the leafref type MUST also be
151 * conditional based on at least the same set of features.
152 */
janani be18b5342016-07-13 21:06:41 +0530153 LEAFREF("leafref"),
Vinod Kumar Scf044422016-02-09 19:53:45 +0530154
155 /**
156 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530157 *
Vinod Kumar Scf044422016-02-09 19:53:45 +0530158 * The identityref type is used to reference an existing identity.
159 */
janani be18b5342016-07-13 21:06:41 +0530160 IDENTITYREF("identityref"),
Vinod Kumar Scf044422016-02-09 19:53:45 +0530161
162 /**
163 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530164 *
Vinod Kumar Scf044422016-02-09 19:53:45 +0530165 * The empty built-in type represents a leaf that does not have any value,
166 * it conveys information by its presence or absence.
167 *
168 * An empty type cannot have a default value.
169 */
janani be18b5342016-07-13 21:06:41 +0530170 EMPTY("empty"),
Vinod Kumar Scf044422016-02-09 19:53:45 +0530171
172 /**
173 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530174 *
Vinod Kumar Scf044422016-02-09 19:53:45 +0530175 * The union built-in type represents a value that corresponds to one of its
176 * member types.
177 *
178 * When the type is "union", the "type" statement MUST be present. It is
179 * used to repeatedly specify each member type of the union. It takes as an
180 * argument a string that is the name of a member type.
181 *
182 * A member type can be of any built-in or derived type, except it MUST NOT
183 * be one of the built-in types "empty" or "leafref".
184 *
185 * When a string representing a union data type is validated, the string is
186 * validated against each member type, in the order they are specified in
187 * the "type" statement, until a match is found.
188 *
189 * Any default value or "units" property defined in the member types is not
190 * inherited by the union type.
191 */
janani be18b5342016-07-13 21:06:41 +0530192 UNION("union"),
Vinod Kumar Scf044422016-02-09 19:53:45 +0530193
194 /**
195 * Reference:RFC 6020.
Vinod Kumar S67e7be62016-02-11 20:13:28 +0530196 *
Vinod Kumar Scf044422016-02-09 19:53:45 +0530197 * The instance-identifier built-in type is used to uniquely identify a
198 * particular instance node in the data tree.
199 *
200 * The syntax for an instance-identifier is a subset of the XPath
201 * abbreviated syntax, formally defined by the rule "instance-identifier".
202 * It is used to uniquely identify a node in the data tree. Predicates are
203 * used only for specifying the values for the key nodes for list entries, a
204 * value of a leaf-list entry, or a positional index for a list without
205 * keys. For identifying list entries with keys, each predicate consists of
206 * one equality test per key, and each key MUST have a corresponding
207 * predicate.
208 *
209 * If the leaf with the instance-identifier type represents configuration
210 * data, and the "require-instance" property is "true", the node it refers
211 * to MUST also represent configuration. Such a leaf puts a constraint on
212 * valid data. All such leaf nodes MUST reference existing nodes or leaf
213 * nodes with their default value in use for the data to be valid.
214 */
janani be18b5342016-07-13 21:06:41 +0530215 INSTANCE_IDENTIFIER("instance-identifier"),
Vinod Kumar Scf044422016-02-09 19:53:45 +0530216
217 /**
Vinod Kumar S71cba682016-02-25 15:52:16 +0530218 * Derived data type.
Vinod Kumar Scf044422016-02-09 19:53:45 +0530219 */
janani be18b5342016-07-13 21:06:41 +0530220 DERIVED("derived");
221
222 /**
223 * Defined type from the enum value.
224 */
225 private String definedType;
226
227 /**
228 * Constructs type value from enum.
229 *
230 * @param definedType value of enum
231 */
232 YangDataTypes(String definedType) {
233 this.definedType = definedType;
234 }
Vidyashree Rama4f1f08b2016-02-13 21:47:58 +0530235
236 /**
237 * Returns YANG data type for corresponding type name.
238 *
239 * @param name type name from YANG file.
240 * @return YANG data type for corresponding type name.
241 */
242 public static YangDataTypes getType(String name) {
243 name = name.replace("\"", "");
244 for (YangDataTypes yangDataType : values()) {
janani be18b5342016-07-13 21:06:41 +0530245 if (yangDataType.definedType.toLowerCase().equals(name)) {
Vidyashree Rama4f1f08b2016-02-13 21:47:58 +0530246 return yangDataType;
247 }
248 }
249 return YangDataTypes.DERIVED;
250 }
Vinod Kumar Scf044422016-02-09 19:53:45 +0530251}