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 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 20 | import org.onosproject.yangutils.parser.Parsable; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.utils.YangConstructType; |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * Reference:RFC 6020. |
| 25 | * The "type" statement takes as an argument a string that is the name |
| 26 | * of a YANG built-in type or a derived type, followed by an optional |
| 27 | * block of sub-statements that are used to put further restrictions |
| 28 | * on the type. |
| 29 | * |
| 30 | * The restrictions that can be applied depend on the type being restricted. |
| 31 | * The type's sub-statements |
| 32 | * |
| 33 | * +------------------+---------+-------------+------------------------------------+ |
| 34 | * | substatement | section | cardinality | mapped data type | |
| 35 | * +------------------+---------+-------------+------------------------------------+ |
| 36 | * | bit | 9.7.4 | 0..n | - YangBit used in YangBits | |
| 37 | * | enum | 9.6.4 | 0..n | - YangEnum used in YangEnumeration | |
| 38 | * | length | 9.4.4 | 0..1 | - used for string | |
| 39 | * | path | 9.9.2 | 0..1 | - TODO leaf-ref | |
| 40 | * | pattern | 9.4.6 | 0..n | - used for string | |
| 41 | * | range | 9.2.4 | 0..1 | - used for integer data type | |
| 42 | * | require-instance | 9.13.2 | 0..1 | - TODO instance-identifier | |
| 43 | * | type | 7.4 | 0..n | - TODO union | |
| 44 | * +------------------+---------+-------------+------------------------------------+ |
| 45 | */ |
| 46 | |
| 47 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 48 | * Represents the data type information. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 49 | * |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 50 | * @param <T> YANG data type info |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 51 | */ |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 52 | public class YangType<T> implements Parsable, Resolvable { |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 53 | |
| 54 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 55 | * YANG node identifier. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 56 | */ |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 57 | private YangNodeIdentifier nodeIdentifier; |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 58 | |
| 59 | /** |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 60 | * Java package in which the Java type is defined. |
| 61 | */ |
| 62 | private String javaPackage; |
| 63 | |
| 64 | /** |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 65 | * YANG data type. |
| 66 | */ |
| 67 | private YangDataTypes dataType; |
| 68 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 69 | /** |
| 70 | * Additional information about data type, example restriction info, named |
| 71 | * values, etc. The extra information is based on the data type. Based on |
| 72 | * the data type, the extended info can vary. |
| 73 | */ |
| 74 | private T dataTypeExtendedInfo; |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 75 | |
| 76 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 77 | * Effective built-in type, requried in case type of typedef is again a |
| 78 | * derived type. This information is to be added during linking. |
| 79 | */ |
| 80 | private YangDataTypes effectiveBuiltInType; |
| 81 | |
| 82 | /** |
| 83 | * Effective pattern restriction, requried in case type of typedef is again |
| 84 | * a derived type. This information is to be added during linking. |
| 85 | */ |
| 86 | private YangPatternRestriction effectivePatternRestriction; |
| 87 | |
| 88 | /** |
| 89 | * Status of resolution. If completely resolved enum value is "RESOLVED", |
| 90 | * if not enum value is "UNRESOLVED", in case reference of grouping/typedef |
| 91 | * is added to uses/type but it's not resolved value of enum should be |
| 92 | * "PARTIALLY_RESOLVED". |
| 93 | */ |
| 94 | private ResolvableStatus resolvableStatus; |
| 95 | |
| 96 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 97 | * Creates a YANG type object. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 98 | */ |
| 99 | public YangType() { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 100 | |
| 101 | nodeIdentifier = new YangNodeIdentifier(); |
| 102 | resolvableStatus = ResolvableStatus.UNRESOLVED; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Returns prefix associated with data type name. |
| 107 | * |
| 108 | * @return prefix associated with data type name |
| 109 | */ |
| 110 | public String getPrefix() { |
| 111 | return nodeIdentifier.getPrefix(); |
| 112 | } |
| 113 | |
| 114 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 115 | * Sets prefix associated with data type name. |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 116 | * |
| 117 | * @param prefix prefix associated with data type name |
| 118 | */ |
| 119 | public void setPrefix(String prefix) { |
| 120 | nodeIdentifier.setPrefix(prefix); |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 124 | * Returns the name of data type. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 125 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 126 | * @return the name of data type |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 127 | */ |
| 128 | public String getDataTypeName() { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 129 | return nodeIdentifier.getName(); |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 133 | * Sets the name of the data type. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 134 | * |
| 135 | * @param typeName the name to set |
| 136 | */ |
| 137 | public void setDataTypeName(String typeName) { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 138 | nodeIdentifier.setName(typeName); |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 142 | * Returns the Java package where the type is defined. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 143 | * |
| 144 | * @return Java package where the type is defined |
| 145 | */ |
| 146 | public String getJavaPackage() { |
| 147 | return javaPackage; |
| 148 | } |
| 149 | |
| 150 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 151 | * Sets Java package where the type is defined. |
Bharat saraswal | 022dae9 | 2016-03-04 20:08:09 +0530 | [diff] [blame] | 152 | * |
| 153 | * @param javaPackage Java package where the type is defined |
| 154 | */ |
| 155 | public void setJavaPackage(String javaPackage) { |
| 156 | this.javaPackage = javaPackage; |
| 157 | } |
| 158 | |
| 159 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 160 | * Returns the type of data. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 161 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 162 | * @return the data type |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 163 | */ |
| 164 | public YangDataTypes getDataType() { |
| 165 | return dataType; |
| 166 | } |
| 167 | |
| 168 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 169 | * Sets the type of data. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 170 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 171 | * @param dataType data type |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 172 | */ |
| 173 | public void setDataType(YangDataTypes dataType) { |
| 174 | this.dataType = dataType; |
| 175 | } |
| 176 | |
| 177 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 178 | * Returns the data type meta data. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 179 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 180 | * @return the data type meta data |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 181 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 182 | public T getDataTypeExtendedInfo() { |
| 183 | return dataTypeExtendedInfo; |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 187 | * Sets the data type meta data. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 188 | * |
| 189 | * @param dataTypeInfo the meta data to set |
| 190 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 191 | public void setDataTypeExtendedInfo(T dataTypeInfo) { |
| 192 | this.dataTypeExtendedInfo = dataTypeInfo; |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /** |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 196 | * Returns node identifier. |
| 197 | * |
| 198 | * @return node identifier |
| 199 | */ |
| 200 | public YangNodeIdentifier getNodeIdentifier() { |
| 201 | return nodeIdentifier; |
| 202 | } |
| 203 | |
| 204 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 205 | * Sets node identifier. |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 206 | * |
| 207 | * @param nodeIdentifier the node identifier |
| 208 | */ |
| 209 | public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) { |
| 210 | this.nodeIdentifier = nodeIdentifier; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Return effective built-in type. |
| 215 | * |
| 216 | * @return effective built-in type |
| 217 | */ |
| 218 | public YangDataTypes getEffectiveBuiltInType() { |
| 219 | return effectiveBuiltInType; |
| 220 | } |
| 221 | |
| 222 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 223 | * Sets effective built-in type. |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 224 | * |
| 225 | * @param effectiveBuiltInType effective built-in type |
| 226 | */ |
| 227 | public void setEffectiveBuiltInType(YangDataTypes effectiveBuiltInType) { |
| 228 | this.effectiveBuiltInType = effectiveBuiltInType; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Returns effective pattern restriction. |
| 233 | * |
| 234 | * @return effective pattern restriction |
| 235 | */ |
| 236 | public YangPatternRestriction getEffectivePatternRestriction() { |
| 237 | return effectivePatternRestriction; |
| 238 | } |
| 239 | |
| 240 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 241 | * Sets effective pattern restriction. |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 242 | * |
| 243 | * @param effectivePatternRestriction effective pattern restriction |
| 244 | */ |
| 245 | public void setEffectivePatternRestriction(YangPatternRestriction effectivePatternRestriction) { |
| 246 | this.effectivePatternRestriction = effectivePatternRestriction; |
| 247 | } |
| 248 | |
| 249 | /** |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 250 | * Returns the type of the parsed data. |
| 251 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 252 | * @return returns TYPE_DATA |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 253 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 254 | @Override |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 255 | public YangConstructType getYangConstructType() { |
| 256 | return YangConstructType.TYPE_DATA; |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 260 | * Validates the data on entering the corresponding parse tree node. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 261 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 262 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 263 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 264 | @Override |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 265 | public void validateDataOnEntry() throws DataModelException { |
| 266 | // TODO auto-generated method stub, to be implemented by parser |
| 267 | |
| 268 | } |
| 269 | |
| 270 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 271 | * Validates the data on exiting the corresponding parse tree node. |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 272 | * |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 273 | * @throws DataModelException a violation of data model rules |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 274 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 275 | @Override |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 276 | public void validateDataOnExit() throws DataModelException { |
| 277 | // TODO auto-generated method stub, to be implemented by parser |
| 278 | |
| 279 | } |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 280 | |
| 281 | @Override |
| 282 | public ResolvableStatus getResolvableStatus() { |
| 283 | return resolvableStatus; |
| 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void setResolvableStatus(ResolvableStatus resolvableStatus) { |
| 288 | this.resolvableStatus = resolvableStatus; |
| 289 | } |
| 290 | |
| 291 | @Override |
| 292 | public void resolve() { |
| 293 | //TODO: implement the method. |
| 294 | } |
Vinod Kumar S | cd48133 | 2016-02-09 19:53:45 +0530 | [diff] [blame] | 295 | } |