blob: 76b8ca21963a500f3c58e9467fbea464809a4b4f [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;
24
25/*-
26 * Reference RFC 6020.
27 *
28 * The "case" statement is used to define branches of the choice. It takes as an
29 * argument an identifier, followed by a block of sub-statements that holds
30 * detailed case information.
31 *
32 * The identifier is used to identify the case node in the schema tree. A case
33 * node does not exist in the data tree.
34 *
35 * Within a "case" statement, the "anyxml", "choice", "container", "leaf",
36 * "list", "leaf-list", and "uses" statements can be used to define child nodes
37 * to the case node. The identifiers of all these child nodes MUST be unique
38 * within all cases in a choice. For example, the following is illegal:
39 *
40 * choice interface-type { // This example is illegal YANG
41 * case a {
42 * leaf ethernet { ... }
43 * }
44 * case b {
45 * container ethernet { ...}
46 * }
47 * }
48 *
49 * As a shorthand, the "case" statement can be omitted if the branch
50 * contains a single "anyxml", "container", "leaf", "list", or
51 * "leaf-list" statement. In this case, the identifier of the case node
52 * is the same as the identifier in the branch statement. The following
53 * example:
54 *
55 * choice interface-type {
56 * container ethernet { ... }
57 * }
58 *
59 * is equivalent to:
60 *
61 * choice interface-type {
62 * case ethernet {
63 * container ethernet { ... }
64 * }
65 * }
66 *
67 * The case identifier MUST be unique within a choice.
68 *
69 * The case's sub-statements
70 *
71 * +--------------+---------+-------------+------------------+
72 * | substatement | section | cardinality |data model mapping|
73 * +--------------+---------+-------------+------------------+
74 * | anyxml | 7.10 | 0..n |-not supported |
75 * | choice | 7.9 | 0..n |-child nodes |
76 * | container | 7.5 | 0..n |-child nodes |
77 * | description | 7.19.3 | 0..1 |-string |
78 * | if-feature | 7.18.2 | 0..n |-TODO |
79 * | leaf | 7.6 | 0..n |-YangLeaf |
80 * | leaf-list | 7.7 | 0..n |-YangLeafList |
81 * | list | 7.8 | 0..n |-child nodes |
82 * | reference | 7.19.4 | 0..1 |-string |
83 * | status | 7.19.2 | 0..1 |-YangStatus |
84 * | uses | 7.12 | 0..n |-child node |
85 * | when | 7.19.5 | 0..1 |-TODO |
86 * +--------------+---------+-------------+------------------+
87 */
88/**
89 * Data model node to maintain information defined in YANG case.
90 */
Bharat saraswal870c56f2016-02-20 21:57:16 +053091public class YangCase extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +053092
93 /**
94 * Case name.
95 */
96 private String name;
97
98 // TODO: default field identification for the case
99
100 /**
101 * Description of container.
102 */
103 private String description;
104
105 /**
106 * List of leaves.
107 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530108 private List<YangLeaf<?>> listOfLeaf;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530109
110 /**
111 * List of leaf lists.
112 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530113 private List<YangLeafList<?>> listOfLeafList;
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530114
115 /**
116 * Reference of the module.
117 */
118 private String reference;
119
120 /**
121 * Status of the node.
122 */
123 private YangStatusType status;
124
125 /**
126 * Create a choice node.
127 */
128 public YangCase() {
129 super(YangNodeType.CASE_NODE);
130 }
131
132 /* (non-Javadoc)
133 * @see org.onosproject.yangutils.datamodel.YangNode#getName()
134 */
135 @Override
136 public String getName() {
137 return name;
138 }
139
140 /* (non-Javadoc)
141 * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
142 */
143 @Override
144 public void setName(String name) {
145 this.name = name;
146 }
147
148 /**
149 * Get the description.
150 *
151 * @return the description.
152 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530153 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530154 public String getDescription() {
155 return description;
156 }
157
158 /**
159 * Set the description.
160 *
161 * @param description set the description.
162 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530163 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530164 public void setDescription(String description) {
165 this.description = description;
166 }
167
168 /**
169 * Get the list of leaves.
170 *
171 * @return the list of leaves.
172 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530173 @Override
174 public List<YangLeaf<?>> getListOfLeaf() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530175 return listOfLeaf;
176 }
177
178 /**
179 * Set the list of leaves.
180 *
181 * @param leafsList the list of leaf to set.
182 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530183 private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530184 listOfLeaf = leafsList;
185 }
186
187 /**
188 * Add a leaf.
189 *
190 * @param leaf the leaf to be added.
191 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530192 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530193 public void addLeaf(YangLeaf<?> leaf) {
194 if (getListOfLeaf() == null) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530195 setListOfLeaf(new LinkedList<YangLeaf<?>>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530196 }
197
198 getListOfLeaf().add(leaf);
199 }
200
201 /**
202 * Get the list of leaf-list.
203 *
204 * @return the list of leaf-list.
205 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530206 @Override
207 public List<YangLeafList<?>> getListOfLeafList() {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530208 return listOfLeafList;
209 }
210
211 /**
212 * Set the list of leaf-list.
213 *
214 * @param listOfLeafList the list of leaf-list to set.
215 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530216 private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530217 this.listOfLeafList = listOfLeafList;
218 }
219
220 /**
221 * Add a leaf-list.
222 *
223 * @param leafList the leaf-list to be added.
224 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530225 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530226 public void addLeafList(YangLeafList<?> leafList) {
227 if (getListOfLeafList() == null) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530228 setListOfLeafList(new LinkedList<YangLeafList<?>>());
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530229 }
230
231 getListOfLeafList().add(leafList);
232 }
233
234 /**
235 * Get the textual reference.
236 *
237 * @return the reference.
238 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530239 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530240 public String getReference() {
241 return reference;
242 }
243
244 /**
245 * Set the textual reference.
246 *
247 * @param reference the reference to set.
248 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530249 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530250 public void setReference(String reference) {
251 this.reference = reference;
252 }
253
254 /**
255 * Get the status.
256 *
257 * @return the status.
258 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530259 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530260 public YangStatusType getStatus() {
261 return status;
262 }
263
264 /**
265 * Set the status.
266 *
267 * @param status the status to set.
268 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530269 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530270 public void setStatus(YangStatusType status) {
271 this.status = status;
272 }
273
274 /**
275 * Returns the type of the data.
276 *
277 * @return returns CASE_DATA
278 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530279 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530280 public ParsableDataType getParsableDataType() {
281 return ParsableDataType.CASE_DATA;
282 }
283
284 /**
285 * Validate the data on entering the corresponding parse tree node.
286 *
287 * @throws DataModelException a violation of data model rules.
288 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530289 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530290 public void validateDataOnEntry() throws DataModelException {
291 // TODO auto-generated method stub, to be implemented by parser
292 }
293
294 /**
295 * Validate the data on exiting the corresponding parse tree node.
296 *
297 * @throws DataModelException a violation of data model rules.
298 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530299 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530300 public void validateDataOnExit() throws DataModelException {
301 // TODO auto-generated method stub, to be implemented by parser
302 }
303
304 /* (non-Javadoc)
305 * @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
306 */
307 @Override
308 public String getPackage() {
309 // TODO Auto-generated method stub
310 return null;
311 }
312
313 /* (non-Javadoc)
314 * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
315 */
316 @Override
317 public void setPackage(String pkg) {
318 // TODO Auto-generated method stub
319
320 }
321
322 /* (non-Javadoc)
323 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
324 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530325 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530326 public void generateJavaCodeEntry() {
327 // TODO Auto-generated method stub
328
329 }
330
331 /* (non-Javadoc)
332 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
333 */
Bharat saraswal870c56f2016-02-20 21:57:16 +0530334 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530335 public void generateJavaCodeExit() {
336 // TODO Auto-generated method stub
337
338 }
339}