Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.yangutils.datamodel; |
| 18 | |
| 19 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 20 | * Represents ENUM to identify the YANG data type. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 21 | */ |
| 22 | public enum YangDataTypes { |
| 23 | /** |
| 24 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 25 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 26 | * int8 represents integer values between -128 and 127, inclusively. |
| 27 | */ |
| 28 | INT8, |
| 29 | |
| 30 | /** |
| 31 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 32 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 33 | * int16 represents integer values between -32768 and 32767, inclusively. |
| 34 | */ |
| 35 | INT16, |
| 36 | |
| 37 | /** |
| 38 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 39 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 40 | * int32 represents integer values between -2147483648 and 2147483647, |
| 41 | * inclusively. |
| 42 | */ |
| 43 | INT32, |
| 44 | |
| 45 | /** |
| 46 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 47 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 48 | * int64 represents integer values between -9223372036854775808 and |
| 49 | * 9223372036854775807, inclusively. |
| 50 | */ |
| 51 | INT64, |
| 52 | |
| 53 | /** |
| 54 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 55 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 56 | * uint8 represents integer values between 0 and 255, inclusively. |
| 57 | */ |
| 58 | UINT8, |
| 59 | |
| 60 | /** |
| 61 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 62 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 63 | * uint16 represents integer values between 0 and 65535, inclusively. |
| 64 | */ |
| 65 | UINT16, |
| 66 | |
| 67 | /** |
| 68 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 69 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 70 | * uint32 represents integer values between 0 and 4294967295, inclusively. |
| 71 | */ |
| 72 | UINT32, |
| 73 | |
| 74 | /** |
| 75 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 76 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 77 | * uint64 represents integer values between 0 and 18446744073709551615, |
| 78 | * inclusively. |
| 79 | */ |
| 80 | UINT64, |
| 81 | |
| 82 | /** |
| 83 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 84 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 85 | * 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 | */ |
| 91 | DECIMAL64, // TODO: need to implement in type. |
| 92 | |
| 93 | /** |
| 94 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 95 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 96 | * 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 | */ |
| 100 | STRING, |
| 101 | |
| 102 | /** |
| 103 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 104 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 105 | * The boolean built-in type represents a boolean value. |
| 106 | */ |
| 107 | BOOLEAN, |
| 108 | |
| 109 | /** |
| 110 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 111 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 112 | * The enumeration built-in type represents values from a set of assigned |
| 113 | * names. |
| 114 | */ |
| 115 | ENUMERATION, |
| 116 | |
| 117 | /** |
| 118 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 119 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 120 | * 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 | */ |
| 124 | BITS, |
| 125 | |
| 126 | /** |
| 127 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 128 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 129 | * The binary built-in type represents any binary data, i.e., a sequence of |
| 130 | * octets. |
| 131 | */ |
| 132 | BINARY, |
| 133 | |
| 134 | /** |
| 135 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 136 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 137 | * 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 | */ |
| 153 | LEAFREF, // TODO: need to implement in type. |
| 154 | |
| 155 | /** |
| 156 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 157 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 158 | * The identityref type is used to reference an existing identity. |
| 159 | */ |
| 160 | IDENTITYREF, |
| 161 | |
| 162 | /** |
| 163 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 164 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 165 | * 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 | */ |
| 170 | EMPTY, |
| 171 | |
| 172 | /** |
| 173 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 174 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 175 | * 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 | */ |
| 192 | UNION, |
| 193 | |
| 194 | /** |
| 195 | * Reference:RFC 6020. |
Vinod Kumar S | 6a6ce4c | 2016-02-11 20:13:28 +0530 | [diff] [blame] | 196 | * |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 197 | * 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 | */ |
| 215 | INSTANCE_IDENTIFIER, |
| 216 | |
| 217 | /** |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 218 | * Derived data type. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 219 | */ |
Vidyashree Rama | b24ca90 | 2016-02-13 21:47:58 +0530 | [diff] [blame] | 220 | DERIVED; |
| 221 | |
| 222 | /** |
| 223 | * Returns YANG data type for corresponding type name. |
| 224 | * |
| 225 | * @param name type name from YANG file. |
| 226 | * @return YANG data type for corresponding type name. |
| 227 | */ |
| 228 | public static YangDataTypes getType(String name) { |
| 229 | name = name.replace("\"", ""); |
| 230 | for (YangDataTypes yangDataType : values()) { |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 231 | if (yangDataType.name().toLowerCase().equals(name)) { |
Vidyashree Rama | b24ca90 | 2016-02-13 21:47:58 +0530 | [diff] [blame] | 232 | return yangDataType; |
| 233 | } |
| 234 | } |
| 235 | return YangDataTypes.DERIVED; |
| 236 | } |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 237 | } |