blob: dc9f36b31950fb209018f07878f32baa06d047bc [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 java.util.LinkedList;
19import java.util.List;
20
21import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22import org.onosproject.yangutils.parser.Parsable;
23import org.onosproject.yangutils.parser.ParsableDataType;
Bharat saraswal594bc6d2016-02-22 22:15:21 +053024import org.onosproject.yangutils.translator.CachedFileHandle;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053025
26/*-
27 * Reference RFC 6020.
28 *
29 * The "case" statement is used to define branches of the choice. It takes as an
30 * argument an identifier, followed by a block of sub-statements that holds
31 * detailed case information.
32 *
33 * The identifier is used to identify the case node in the schema tree. A case
34 * node does not exist in the data tree.
35 *
36 * Within a "case" statement, the "anyxml", "choice", "container", "leaf",
37 * "list", "leaf-list", and "uses" statements can be used to define child nodes
38 * to the case node. The identifiers of all these child nodes MUST be unique
39 * within all cases in a choice. For example, the following is illegal:
40 *
41 * choice interface-type { // This example is illegal YANG
42 * case a {
43 * leaf ethernet { ... }
44 * }
45 * case b {
46 * container ethernet { ...}
47 * }
48 * }
49 *
50 * As a shorthand, the "case" statement can be omitted if the branch
51 * contains a single "anyxml", "container", "leaf", "list", or
52 * "leaf-list" statement. In this case, the identifier of the case node
53 * is the same as the identifier in the branch statement. The following
54 * example:
55 *
56 * choice interface-type {
57 * container ethernet { ... }
58 * }
59 *
60 * is equivalent to:
61 *
62 * choice interface-type {
63 * case ethernet {
64 * container ethernet { ... }
65 * }
66 * }
67 *
68 * The case identifier MUST be unique within a choice.
69 *
70 * The case's sub-statements
71 *
72 * +--------------+---------+-------------+------------------+
73 * | substatement | section | cardinality |data model mapping|
74 * +--------------+---------+-------------+------------------+
75 * | anyxml | 7.10 | 0..n |-not supported |
76 * | choice | 7.9 | 0..n |-child nodes |
77 * | container | 7.5 | 0..n |-child nodes |
78 * | description | 7.19.3 | 0..1 |-string |
79 * | if-feature | 7.18.2 | 0..n |-TODO |
80 * | leaf | 7.6 | 0..n |-YangLeaf |
81 * | leaf-list | 7.7 | 0..n |-YangLeafList |
82 * | list | 7.8 | 0..n |-child nodes |
83 * | reference | 7.19.4 | 0..1 |-string |
84 * | status | 7.19.2 | 0..1 |-YangStatus |
85 * | uses | 7.12 | 0..n |-child node |
86 * | when | 7.19.5 | 0..1 |-TODO |
87 * +--------------+---------+-------------+------------------+
88 */
89/**
90 * Data model node to maintain information defined in YANG case.
91 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +053092public class YangCase extends YangNode
93 implements YangLeavesHolder, YangCommonInfo, Parsable {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053094
95 /**
96 * Case name.
97 */
98 private String name;
99
100 // TODO: default field identification for the case
101
102 /**
103 * Description of container.
104 */
105 private String description;
106
107 /**
108 * List of leaves.
109 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530110 private List<YangLeaf> listOfLeaf;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530111
112 /**
113 * List of leaf lists.
114 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530115 private List<YangLeafList> listOfLeafList;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530116
117 /**
118 * Reference of the module.
119 */
120 private String reference;
121
122 /**
123 * Status of the node.
124 */
125 private YangStatusType status;
126
127 /**
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530128 * package of the generated java code.
129 */
130 private String pkg;
131
132 /**
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530133 * Create a choice node.
134 */
135 public YangCase() {
136 super(YangNodeType.CASE_NODE);
137 }
138
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530139 /**
140 * Get the case name.
141 *
142 * @return case name.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530143 */
144 @Override
145 public String getName() {
146 return name;
147 }
148
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530149 /**
150 * Set the case name.
151 *
152 * @param name case name.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530153 */
154 @Override
155 public void setName(String name) {
156 this.name = name;
157 }
158
159 /**
160 * Get the description.
161 *
162 * @return the description.
163 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530164 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530165 public String getDescription() {
166 return description;
167 }
168
169 /**
170 * Set the description.
171 *
172 * @param description set the description.
173 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530174 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530175 public void setDescription(String description) {
176 this.description = description;
177 }
178
179 /**
180 * Get the list of leaves.
181 *
182 * @return the list of leaves.
183 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530184 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530185 public List<YangLeaf> getListOfLeaf() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530186 return listOfLeaf;
187 }
188
189 /**
190 * Set the list of leaves.
191 *
192 * @param leafsList the list of leaf to set.
193 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530194 private void setListOfLeaf(List<YangLeaf> leafsList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530195 listOfLeaf = leafsList;
196 }
197
198 /**
199 * Add a leaf.
200 *
201 * @param leaf the leaf to be added.
202 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530203 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530204 public void addLeaf(YangLeaf leaf) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530205 if (getListOfLeaf() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530206 setListOfLeaf(new LinkedList<YangLeaf>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530207 }
208
209 getListOfLeaf().add(leaf);
210 }
211
212 /**
213 * Get the list of leaf-list.
214 *
215 * @return the list of leaf-list.
216 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530217 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530218 public List<YangLeafList> getListOfLeafList() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530219 return listOfLeafList;
220 }
221
222 /**
223 * Set the list of leaf-list.
224 *
225 * @param listOfLeafList the list of leaf-list to set.
226 */
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530227 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530228 this.listOfLeafList = listOfLeafList;
229 }
230
231 /**
232 * Add a leaf-list.
233 *
234 * @param leafList the leaf-list to be added.
235 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530236 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530237 public void addLeafList(YangLeafList leafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530238 if (getListOfLeafList() == null) {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530239 setListOfLeafList(new LinkedList<YangLeafList>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530240 }
241
242 getListOfLeafList().add(leafList);
243 }
244
245 /**
246 * Get the textual reference.
247 *
248 * @return the reference.
249 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530250 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530251 public String getReference() {
252 return reference;
253 }
254
255 /**
256 * Set the textual reference.
257 *
258 * @param reference the reference to set.
259 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530260 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530261 public void setReference(String reference) {
262 this.reference = reference;
263 }
264
265 /**
266 * Get the status.
267 *
268 * @return the status.
269 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530270 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530271 public YangStatusType getStatus() {
272 return status;
273 }
274
275 /**
276 * Set the status.
277 *
278 * @param status the status to set.
279 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530280 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530281 public void setStatus(YangStatusType status) {
282 this.status = status;
283 }
284
285 /**
286 * Returns the type of the data.
287 *
288 * @return returns CASE_DATA
289 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530290 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530291 public ParsableDataType getParsableDataType() {
292 return ParsableDataType.CASE_DATA;
293 }
294
295 /**
296 * Validate the data on entering the corresponding parse tree node.
297 *
298 * @throws DataModelException a violation of data model rules.
299 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530300 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530301 public void validateDataOnEntry() throws DataModelException {
302 // TODO auto-generated method stub, to be implemented by parser
303 }
304
305 /**
306 * Validate the data on exiting the corresponding parse tree node.
307 *
308 * @throws DataModelException a violation of data model rules.
309 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530310 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530311 public void validateDataOnExit() throws DataModelException {
312 // TODO auto-generated method stub, to be implemented by parser
313 }
314
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530315 /**
316 * Get the mapped java package.
317 *
318 * @return the java package
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530319 */
320 @Override
321 public String getPackage() {
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530322 return pkg;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530323 }
324
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530325 /**
326 * Set the mapped java package.
327 *
328 * @param pakg the package to set
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530329 */
330 @Override
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530331 public void setPackage(String pakg) {
332 pkg = pakg;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530333
334 }
335
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530336 /**
337 * Generate the code corresponding to YANG case info.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530338 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530339 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530340 public void generateJavaCodeEntry() {
341 // TODO Auto-generated method stub
342
343 }
344
Vinod Kumar S0c330cd2016-02-23 22:36:57 +0530345 /**
346 * Free resource used for generating code and generate valid java files
347 * corresponding to YANG case info.
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530348 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530349 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530350 public void generateJavaCodeExit() {
351 // TODO Auto-generated method stub
352
353 }
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530354
355 @Override
356 public CachedFileHandle getFileHandle() {
357 // TODO Auto-generated method stub
358 return null;
359 }
360
361 @Override
362 public void setFileHandle(CachedFileHandle fileHandle) {
363 // TODO Auto-generated method stub
364
365 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530366}