blob: b3a17bd6fe2140140f4568142073bb488948d698 [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 */
91public class YangCase extends YangNode
92 implements YangLeavesHolder, YangCommonInfo, Parsable {
93
94 /**
95 * Case name.
96 */
97 private String name;
98
99 // TODO: default field identification for the case
100
101 /**
102 * Description of container.
103 */
104 private String description;
105
106 /**
107 * List of leaves.
108 */
109 @SuppressWarnings("rawtypes")
110 private List<YangLeaf> listOfLeaf;
111
112 /**
113 * List of leaf lists.
114 */
115 @SuppressWarnings("rawtypes")
116 private List<YangLeafList> listOfLeafList;
117
118 /**
119 * Reference of the module.
120 */
121 private String reference;
122
123 /**
124 * Status of the node.
125 */
126 private YangStatusType status;
127
128 /**
129 * Create a choice node.
130 */
131 public YangCase() {
132 super(YangNodeType.CASE_NODE);
133 }
134
135 /* (non-Javadoc)
136 * @see org.onosproject.yangutils.datamodel.YangNode#getName()
137 */
138 @Override
139 public String getName() {
140 return name;
141 }
142
143 /* (non-Javadoc)
144 * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
145 */
146 @Override
147 public void setName(String name) {
148 this.name = name;
149 }
150
151 /**
152 * Get the description.
153 *
154 * @return the description.
155 */
156 public String getDescription() {
157 return description;
158 }
159
160 /**
161 * Set the description.
162 *
163 * @param description set the description.
164 */
165 public void setDescription(String description) {
166 this.description = description;
167 }
168
169 /**
170 * Get the list of leaves.
171 *
172 * @return the list of leaves.
173 */
174 @SuppressWarnings("rawtypes")
175 public List<YangLeaf> getListOfLeaf() {
176 return listOfLeaf;
177 }
178
179 /**
180 * Set the list of leaves.
181 *
182 * @param leafsList the list of leaf to set.
183 */
184 @SuppressWarnings("rawtypes")
185 private void setListOfLeaf(List<YangLeaf> leafsList) {
186 listOfLeaf = leafsList;
187 }
188
189 /**
190 * Add a leaf.
191 *
192 * @param leaf the leaf to be added.
193 */
194 @SuppressWarnings("rawtypes")
195 public void addLeaf(YangLeaf<?> leaf) {
196 if (getListOfLeaf() == null) {
197 setListOfLeaf(new LinkedList<YangLeaf>());
198 }
199
200 getListOfLeaf().add(leaf);
201 }
202
203 /**
204 * Get the list of leaf-list.
205 *
206 * @return the list of leaf-list.
207 */
208 @SuppressWarnings("rawtypes")
209 public List<YangLeafList> getListOfLeafList() {
210 return listOfLeafList;
211 }
212
213 /**
214 * Set the list of leaf-list.
215 *
216 * @param listOfLeafList the list of leaf-list to set.
217 */
218 @SuppressWarnings("rawtypes")
219 private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
220 this.listOfLeafList = listOfLeafList;
221 }
222
223 /**
224 * Add a leaf-list.
225 *
226 * @param leafList the leaf-list to be added.
227 */
228 @SuppressWarnings("rawtypes")
229 public void addLeafList(YangLeafList<?> leafList) {
230 if (getListOfLeafList() == null) {
231 setListOfLeafList(new LinkedList<YangLeafList>());
232 }
233
234 getListOfLeafList().add(leafList);
235 }
236
237 /**
238 * Get the textual reference.
239 *
240 * @return the reference.
241 */
242 public String getReference() {
243 return reference;
244 }
245
246 /**
247 * Set the textual reference.
248 *
249 * @param reference the reference to set.
250 */
251 public void setReference(String reference) {
252 this.reference = reference;
253 }
254
255 /**
256 * Get the status.
257 *
258 * @return the status.
259 */
260 public YangStatusType getStatus() {
261 return status;
262 }
263
264 /**
265 * Set the status.
266 *
267 * @param status the status to set.
268 */
269 public void setStatus(YangStatusType status) {
270 this.status = status;
271 }
272
273 /**
274 * Returns the type of the data.
275 *
276 * @return returns CASE_DATA
277 */
278 public ParsableDataType getParsableDataType() {
279 return ParsableDataType.CASE_DATA;
280 }
281
282 /**
283 * Validate the data on entering the corresponding parse tree node.
284 *
285 * @throws DataModelException a violation of data model rules.
286 */
287 public void validateDataOnEntry() throws DataModelException {
288 // TODO auto-generated method stub, to be implemented by parser
289 }
290
291 /**
292 * Validate the data on exiting the corresponding parse tree node.
293 *
294 * @throws DataModelException a violation of data model rules.
295 */
296 public void validateDataOnExit() throws DataModelException {
297 // TODO auto-generated method stub, to be implemented by parser
298 }
299
300 /* (non-Javadoc)
301 * @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
302 */
303 @Override
304 public String getPackage() {
305 // TODO Auto-generated method stub
306 return null;
307 }
308
309 /* (non-Javadoc)
310 * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
311 */
312 @Override
313 public void setPackage(String pkg) {
314 // TODO Auto-generated method stub
315
316 }
317
318 /* (non-Javadoc)
319 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
320 */
321 public void generateJavaCodeEntry() {
322 // TODO Auto-generated method stub
323
324 }
325
326 /* (non-Javadoc)
327 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
328 */
329 public void generateJavaCodeExit() {
330 // TODO Auto-generated method stub
331
332 }
333}