Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 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 org.onosproject.yangutils.datamodel; |
| 17 | |
| 18 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
| 19 | import org.onosproject.yangutils.parser.Parsable; |
| 20 | import org.onosproject.yangutils.parser.ParsableDataType; |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.translator.CachedFileHandle; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 22 | |
| 23 | /*- |
| 24 | * Reference RFC 6020. |
| 25 | * |
| 26 | * The "typedef" statement defines a new type that may be used locally in the |
| 27 | * module, in modules or submodules which include it, and by other modules that |
| 28 | * import from it. The new type is called the "derived type", and the type from |
| 29 | * which it was derived is called the "base type". All derived types can be |
| 30 | * traced back to a YANG built-in type. |
| 31 | * |
| 32 | * The "typedef" statement's argument is an identifier that is the name of the |
| 33 | * type to be defined, and MUST be followed by a block of sub-statements that |
| 34 | * holds detailed typedef information. |
| 35 | * |
| 36 | * The name of the type MUST NOT be one of the YANG built-in types. If the |
| 37 | * typedef is defined at the top level of a YANG module or submodule, the name |
| 38 | * of the type to be defined MUST be unique within the module. |
| 39 | * The typedef's sub-statements |
| 40 | * |
| 41 | * +--------------+---------+-------------+------------------+ |
| 42 | * | substatement | section | cardinality |data model mapping| |
| 43 | * +--------------+---------+-------------+------------------+ |
| 44 | * | default | 7.3.4 | 0..1 |-string | |
| 45 | * | description | 7.19.3 | 0..1 |-string | |
| 46 | * | reference | 7.19.4 | 0..1 |-string | |
| 47 | * | status | 7.19.2 | 0..1 |-YangStatus | |
| 48 | * | type | 7.3.2 | 1 |-yangType | |
| 49 | * | units | 7.3.3 | 0..1 |-string | |
| 50 | * +--------------+---------+-------------+------------------+ |
| 51 | */ |
| 52 | /** |
| 53 | * Data model node to maintain information defined in YANG typedef. |
| 54 | */ |
| 55 | public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { |
| 56 | |
| 57 | /** |
| 58 | * Name of derived data type. |
| 59 | */ |
| 60 | private String derivedName; |
| 61 | |
| 62 | /** |
| 63 | * Default value in string, needs to be converted to the target object, |
| 64 | * based on the type. |
| 65 | */ |
| 66 | private String defaultValueInString; |
| 67 | |
| 68 | /** |
| 69 | * Description of new type. |
| 70 | */ |
| 71 | private String description; |
| 72 | |
| 73 | /** |
| 74 | * reference string. |
| 75 | */ |
| 76 | private String reference; |
| 77 | |
| 78 | /** |
| 79 | * Status of the data type. |
| 80 | */ |
| 81 | private YangStatusType status; |
| 82 | |
| 83 | /** |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 84 | * Derived data type. The type will be set when the parser detects the type |
| 85 | * parsing. Hence it is of raw type and it not know at the time of creation |
| 86 | * of the object. i.e. in entry parse, it will not be know, in the exit |
| 87 | * parse we may know the type implicitly based on the restriction. We must |
| 88 | * know and validate the base built in type, by the linking phase. It is a |
| 89 | * RAW type and it usage needs to be validate in linking phase. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 90 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 91 | private YangType<?> derivedType; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Units of the data type. |
| 95 | */ |
| 96 | private String units; |
| 97 | |
| 98 | /** |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 99 | * YANG base built in data type. |
| 100 | */ |
| 101 | private YangDataTypes baseBuiltInType; |
| 102 | |
| 103 | /** |
| 104 | * package of the generated java code. |
| 105 | */ |
| 106 | private String pkg; |
| 107 | |
| 108 | /** |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 109 | * Create a typedef node. |
| 110 | */ |
| 111 | public YangTypeDef() { |
| 112 | super(YangNodeType.TYPEDEF_NODE); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Get the data type name. |
| 117 | * |
| 118 | * @return the data type name. |
| 119 | */ |
| 120 | public String getDerivedName() { |
| 121 | return derivedName; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Set the data type name. |
| 126 | * |
| 127 | * @param derrivedName data type name. |
| 128 | */ |
| 129 | public void setDerivedName(String derrivedName) { |
| 130 | derivedName = derrivedName; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Get the default value. |
| 135 | * |
| 136 | * @return the default value. |
| 137 | */ |
| 138 | public String getDefaultValueInString() { |
| 139 | return defaultValueInString; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Set the default value. |
| 144 | * |
| 145 | * @param defaultValueInString the default value. |
| 146 | */ |
| 147 | public void setDefaultValueInString(String defaultValueInString) { |
| 148 | this.defaultValueInString = defaultValueInString; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Get the description. |
| 153 | * |
| 154 | * @return the description. |
| 155 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 156 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 157 | public String getDescription() { |
| 158 | return description; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Set the description. |
| 163 | * |
| 164 | * @param description set the description. |
| 165 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 166 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 167 | public void setDescription(String description) { |
| 168 | this.description = description; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Get the textual reference. |
| 173 | * |
| 174 | * @return the reference. |
| 175 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 176 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 177 | public String getReference() { |
| 178 | return reference; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Set the textual reference. |
| 183 | * |
| 184 | * @param reference the reference to set. |
| 185 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 186 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 187 | public void setReference(String reference) { |
| 188 | this.reference = reference; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Get the status. |
| 193 | * |
| 194 | * @return the status. |
| 195 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 196 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 197 | public YangStatusType getStatus() { |
| 198 | return status; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Set the status. |
| 203 | * |
| 204 | * @param status the status to set. |
| 205 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 206 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 207 | public void setStatus(YangStatusType status) { |
| 208 | this.status = status; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Get the referenced type. |
| 213 | * |
| 214 | * @return the referenced type. |
| 215 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 216 | public YangType<?> getDerivedType() { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 217 | return derivedType; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Get the referenced type. |
| 222 | * |
| 223 | * @param derivedType the referenced type. |
| 224 | */ |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 225 | public void setDerivedType(YangType<?> derivedType) { |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 226 | this.derivedType = derivedType; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Get the unit. |
| 231 | * |
| 232 | * @return the units |
| 233 | */ |
| 234 | public String getUnits() { |
| 235 | return units; |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Set the unit. |
| 240 | * |
| 241 | * @param units the units to set |
| 242 | */ |
| 243 | public void setUnits(String units) { |
| 244 | this.units = units; |
| 245 | } |
| 246 | |
| 247 | /** |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 248 | * Get the base built in YANG data type. |
| 249 | * |
| 250 | * @return base built in YANG data type. |
| 251 | */ |
| 252 | public YangDataTypes getBaseBuiltInType() { |
| 253 | return baseBuiltInType; |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Set the base built in YANG data type. |
| 258 | * |
| 259 | * @param baseBuiltInType base built in YANG data type. |
| 260 | */ |
| 261 | public void setBaseBuiltInType(YangDataTypes baseBuiltInType) { |
| 262 | this.baseBuiltInType = baseBuiltInType; |
| 263 | } |
| 264 | |
| 265 | /** |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 266 | * Returns the type of the data. |
| 267 | * |
| 268 | * @return returns TYPEDEF_DATA |
| 269 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 270 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 271 | public ParsableDataType getParsableDataType() { |
| 272 | return ParsableDataType.TYPEDEF_DATA; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Validate the data on entering the corresponding parse tree node. |
| 277 | * |
| 278 | * @throws DataModelException a violation of data model rules. |
| 279 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 280 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 281 | public void validateDataOnEntry() throws DataModelException { |
| 282 | // TODO auto-generated method stub, to be implemented by parser |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Validate the data on exiting the corresponding parse tree node. |
| 287 | * |
| 288 | * @throws DataModelException a violation of data model rules. |
| 289 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 290 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 291 | public void validateDataOnExit() throws DataModelException { |
| 292 | // TODO auto-generated method stub, to be implemented by parser |
| 293 | } |
| 294 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 295 | /** |
| 296 | * Get the YANG name of the typedef. |
| 297 | * |
| 298 | * @return YANG name of the typedef. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 299 | */ |
| 300 | @Override |
| 301 | public String getName() { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 302 | return derivedName; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 303 | } |
| 304 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 305 | /** |
| 306 | * Set YANG name of the typedef. |
| 307 | * |
| 308 | * @param name YANG name of the typedef. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 309 | */ |
| 310 | @Override |
| 311 | public void setName(String name) { |
| 312 | // TODO Auto-generated method stub |
| 313 | |
| 314 | } |
| 315 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 316 | /** |
| 317 | * Generate java code snippet corresponding to YANG typedef. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 318 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 319 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 320 | public void generateJavaCodeEntry() { |
| 321 | // TODO Auto-generated method stub |
| 322 | |
| 323 | } |
| 324 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 325 | /** |
| 326 | * Free resource used for code generation of YANG typedef. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 327 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 328 | @Override |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 329 | public void generateJavaCodeExit() { |
| 330 | // TODO Auto-generated method stub |
| 331 | |
| 332 | } |
| 333 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 334 | /** |
| 335 | * Get the mapped java package. |
| 336 | * |
| 337 | * @return the java package |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 338 | */ |
| 339 | @Override |
| 340 | public String getPackage() { |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 341 | return pkg; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 342 | } |
| 343 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 344 | /** |
| 345 | * Set the mapped java package. |
| 346 | * |
| 347 | * @param pakg mapped java package. |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 348 | */ |
| 349 | @Override |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 350 | public void setPackage(String pakg) { |
| 351 | pkg = pakg; |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 352 | |
| 353 | } |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 354 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 355 | /** |
| 356 | * Get the file handle of the cached file used during code generation. |
| 357 | * |
| 358 | * @return cached file handle. |
| 359 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 360 | @Override |
| 361 | public CachedFileHandle getFileHandle() { |
| 362 | // TODO Auto-generated method stub |
| 363 | return null; |
| 364 | } |
| 365 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame^] | 366 | /** |
| 367 | * Set the file handle to be used used for code generation. |
| 368 | * |
| 369 | * @param fileHandle cached file handle. |
| 370 | */ |
Bharat saraswal | 5e3c45c | 2016-02-22 22:15:21 +0530 | [diff] [blame] | 371 | @Override |
| 372 | public void setFileHandle(CachedFileHandle fileHandle) { |
| 373 | // TODO Auto-generated method stub |
| 374 | |
| 375 | } |
Vinod Kumar S | 5a39e01 | 2016-02-16 01:37:16 +0530 | [diff] [blame] | 376 | } |