blob: 0ce074ef41a1861890c46b637e77106eff47ac28 [file] [log] [blame]
Vinod Kumar S2ff139c2016-02-16 01:37:16 +05301/*
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 */
16package org.onosproject.yangutils.datamodel;
17
18import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19import org.onosproject.yangutils.parser.Parsable;
20import org.onosproject.yangutils.parser.ParsableDataType;
Bharat saraswal594bc6d2016-02-22 22:15:21 +053021import org.onosproject.yangutils.translator.CachedFileHandle;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053022
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 */
55public 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 S0c330cd2016-02-23 22:36:57 +053084 * 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 S2ff139c2016-02-16 01:37:16 +053090 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053091 private YangType<?> derivedType;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053092
93 /**
94 * Units of the data type.
95 */
96 private String units;
97
98 /**
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053099 * 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 S2ff139c2016-02-16 01:37:16 +0530109 * 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 saraswal594bc6d2016-02-22 22:15:21 +0530156 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530157 public String getDescription() {
158 return description;
159 }
160
161 /**
162 * Set the description.
163 *
164 * @param description set the description.
165 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530166 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530167 public void setDescription(String description) {
168 this.description = description;
169 }
170
171 /**
172 * Get the textual reference.
173 *
174 * @return the reference.
175 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530176 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530177 public String getReference() {
178 return reference;
179 }
180
181 /**
182 * Set the textual reference.
183 *
184 * @param reference the reference to set.
185 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530186 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530187 public void setReference(String reference) {
188 this.reference = reference;
189 }
190
191 /**
192 * Get the status.
193 *
194 * @return the status.
195 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530196 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530197 public YangStatusType getStatus() {
198 return status;
199 }
200
201 /**
202 * Set the status.
203 *
204 * @param status the status to set.
205 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530206 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530207 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 S0c330cd2016-02-23 22:36:57 +0530216 public YangType<?> getDerivedType() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530217 return derivedType;
218 }
219
220 /**
221 * Get the referenced type.
222 *
223 * @param derivedType the referenced type.
224 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530225 public void setDerivedType(YangType<?> derivedType) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530226 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 S0c330cd2016-02-23 22:36:57 +0530248 * 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 S2ff139c2016-02-16 01:37:16 +0530266 * Returns the type of the data.
267 *
268 * @return returns TYPEDEF_DATA
269 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530270 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530271 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 saraswal594bc6d2016-02-22 22:15:21 +0530280 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530281 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 saraswal594bc6d2016-02-22 22:15:21 +0530290 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530291 public void validateDataOnExit() throws DataModelException {
292 // TODO auto-generated method stub, to be implemented by parser
293 }
294
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530295 /**
296 * Get the YANG name of the typedef.
297 *
298 * @return YANG name of the typedef.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530299 */
300 @Override
301 public String getName() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530302 return derivedName;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530303 }
304
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530305 /**
306 * Set YANG name of the typedef.
307 *
308 * @param name YANG name of the typedef.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530309 */
310 @Override
311 public void setName(String name) {
312 // TODO Auto-generated method stub
313
314 }
315
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530316 /**
317 * Generate java code snippet corresponding to YANG typedef.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530318 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530319 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530320 public void generateJavaCodeEntry() {
321 // TODO Auto-generated method stub
322
323 }
324
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530325 /**
326 * Free resource used for code generation of YANG typedef.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530327 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530328 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530329 public void generateJavaCodeExit() {
330 // TODO Auto-generated method stub
331
332 }
333
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530334 /**
335 * Get the mapped java package.
336 *
337 * @return the java package
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530338 */
339 @Override
340 public String getPackage() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530341 return pkg;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530342 }
343
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530344 /**
345 * Set the mapped java package.
346 *
347 * @param pakg mapped java package.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530348 */
349 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530350 public void setPackage(String pakg) {
351 pkg = pakg;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530352
353 }
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530354
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530355 /**
356 * Get the file handle of the cached file used during code generation.
357 *
358 * @return cached file handle.
359 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530360 @Override
361 public CachedFileHandle getFileHandle() {
362 // TODO Auto-generated method stub
363 return null;
364 }
365
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530366 /**
367 * Set the file handle to be used used for code generation.
368 *
369 * @param fileHandle cached file handle.
370 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530371 @Override
372 public void setFileHandle(CachedFileHandle fileHandle) {
373 // TODO Auto-generated method stub
374
375 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530376}