blob: be4703989edf46c5b48f6185b41124431b47f867 [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 "choice" statement defines a set of alternatives, only one of
30 * which may exist at any one time. The argument is an identifier,
31 * followed by a block of sub-statements that holds detailed choice
32 * information. The identifier is used to identify the choice node in
33 * the schema tree. A choice node does not exist in the data tree.
34 *
35 * A choice consists of a number of branches, defined with the "case"
36 * sub-statement. Each branch contains a number of child nodes. The
37 * nodes from at most one of the choice's branches exist at the same
38 * time.
39 *
40 * The choice's sub-statements
41 *
42 * +--------------+---------+-------------+------------------+
43 * | substatement | section | cardinality |data model mapping|
44 * +--------------+---------+-------------+------------------+
45 * | anyxml | 7.10 | 0..n |-not supported |
46 * | case | 7.9.2 | 0..n |-YangChoice |
47 * | config | 7.19.1 | 0..1 |-boolean |
48 * | container | 7.5 | 0..n |-child case nodes |
49 * | default | 7.9.3 | 0..1 |-string |
50 * | description | 7.19.3 | 0..1 |-string |
51 * | if-feature | 7.18.2 | 0..n |-TODO |
52 * | leaf | 7.6 | 0..n |-child case nodes |
53 * | leaf-list | 7.7 | 0..n |-child case nodes |
54 * | list | 7.8 | 0..n |-child case nodes |
55 * | mandatory | 7.9.4 | 0..1 |-string |
56 * | reference | 7.19.4 | 0..1 |-string |
57 * | status | 7.19.2 | 0..1 |-string |
58 * | when | 7.19.5 | 0..1 |-TODO |
59 * +--------------+---------+-------------+------------------+
60 */
61/**
62 * Data model node to maintain information defined in YANG choice.
63 */
64public class YangChoice extends YangNode implements YangCommonInfo, Parsable {
65
66 /**
67 * Name of choice.
68 */
69 private String name;
70
71 /**
72 * List of cases for the current choice.
73 */
74 private List<YangCase> caseList;
75
76 /**
77 * If the choice represents config data.
78 */
79 private boolean isConfig;
80
81 /**
82 * Reference RFC 6020.
83 *
84 * The "default" statement indicates if a case should be considered as the
85 * default if no child nodes from any of the choice's cases exist. The
86 * argument is the identifier of the "case" statement. If the "default"
87 * statement is missing, there is no default case.
88 *
89 * The "default" statement MUST NOT be present on choices where "mandatory"
90 * is true.
91 *
92 * The default case is only important when considering the default values of
93 * nodes under the cases. The default values for nodes under the default
94 * case are used if none of the nodes under any of the cases are present.
95 *
96 * There MUST NOT be any mandatory nodes directly under the default case.
97 *
98 * Default values for child nodes under a case are only used if one of the
99 * nodes under that case is present, or if that case is the default case. If
100 * none of the nodes under a case are present and the case is not the
101 * default case, the default values of the cases' child nodes are ignored.
102 *
103 * the default case to be used if no case members is present.
104 */
105 private String defaultCase;
106
107 /**
108 * Description.
109 */
110 private String description;
111
112 /**
113 * Reference RFC 6020.
114 *
115 * The "mandatory" statement, which is optional, takes as an argument the
116 * string "true" or "false", and puts a constraint on valid data. If
117 * "mandatory" is "true", at least one node from exactly one of the choice's
118 * case branches MUST exist.
119 *
120 * If not specified, the default is "false".
121 *
122 * The behavior of the constraint depends on the type of the choice's
123 * closest ancestor node in the schema tree which is not a non-presence
124 * container:
125 *
126 * o If this ancestor is a case node, the constraint is enforced if any
127 * other node from the case exists.
128 *
129 * o Otherwise, it is enforced if the ancestor node exists.
130 */
131 private String mandatory;
132
133 /**
134 * reference of the choice.
135 */
136 private String reference;
137
138 /**
139 * Status of the node.
140 */
141 private YangStatusType status;
142
143 /**
144 * Create a Choice node.
145 */
146 public YangChoice() {
147 super(YangNodeType.CHOICE_NODE);
148 }
149
150 /* (non-Javadoc)
151 * @see org.onosproject.yangutils.datamodel.YangNode#getName()
152 */
153 @Override
154 public String getName() {
155 return name;
156 }
157
158 /* (non-Javadoc)
159 * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
160 */
161 @Override
162 public void setName(String name) {
163 this.name = name;
164 }
165
166 /**
167 * Get the list of cases.
168 *
169 * @return the case list
170 */
171 public List<YangCase> getCaseList() {
172 return caseList;
173 }
174
175 /**
176 * Set the list of cases.
177 *
178 * @param caseList list of cases.
179 */
180 private void setCaseList(List<YangCase> caseList) {
181 this.caseList = caseList;
182 }
183
184 /**
185 * Add a case.
186 *
187 * @param newCase new case for the choice
188 */
189 public void addCase(YangCase newCase) {
190 if (getCaseList() == null) {
191 setCaseList(new LinkedList<YangCase>());
192 }
193
194 getCaseList().add(newCase);
195 }
196
197 /**
198 * Get config flag.
199 *
200 * @return the config flag.
201 */
202 public boolean isConfig() {
203 return isConfig;
204 }
205
206 /**
207 * Set config flag.
208 *
209 * @param isCfg the config flag.
210 */
211 public void setConfig(boolean isCfg) {
212 isConfig = isCfg;
213 }
214
215 /**
216 * Get the default case.
217 *
218 * @return the default case.
219 */
220 public String getDefaultCase() {
221 return defaultCase;
222 }
223
224 /**
225 * Set the default case.
226 *
227 * @param defaultCase the default case to set
228 */
229 public void setDefaultCase(String defaultCase) {
230 this.defaultCase = defaultCase;
231 }
232
233 /**
234 * Get the mandatory status.
235 *
236 * @return the mandatory status.
237 */
238 public String getMandatory() {
239 return mandatory;
240 }
241
242 /**
243 * Set the mandatory status.
244 *
245 * @param mandatory the mandatory status.
246 */
247 public void setMandatory(String mandatory) {
248 this.mandatory = mandatory;
249 }
250
251 /**
252 * Get the description.
253 *
254 * @return the description.
255 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530256 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530257 public String getDescription() {
258 return description;
259 }
260
261 /**
262 * Set the description.
263 *
264 * @param description set the description.
265 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530266 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530267 public void setDescription(String description) {
268 this.description = description;
269 }
270
271 /**
272 * Get the textual reference.
273 *
274 * @return the reference.
275 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530276 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530277 public String getReference() {
278 return reference;
279 }
280
281 /**
282 * Set the textual reference.
283 *
284 * @param reference the reference to set.
285 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530286 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530287 public void setReference(String reference) {
288 this.reference = reference;
289 }
290
291 /**
292 * Get the status.
293 *
294 * @return the status.
295 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530296 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530297 public YangStatusType getStatus() {
298 return status;
299 }
300
301 /**
302 * Set the status.
303 *
304 * @param status the status to set.
305 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530306 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530307 public void setStatus(YangStatusType status) {
308 this.status = status;
309 }
310
311 /**
312 * Returns the type of the data.
313 *
314 * @return returns CHOICE_DATA
315 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530316 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530317 public ParsableDataType getParsableDataType() {
318 return ParsableDataType.CHOICE_DATA;
319 }
320
321 /**
322 * Validate the data on entering the corresponding parse tree node.
323 *
324 * @throws DataModelException a violation of data model rules.
325 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530326 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530327 public void validateDataOnEntry() throws DataModelException {
328 // TODO auto-generated method stub, to be implemented by parser
329 }
330
331 /**
332 * Validate the data on exiting the corresponding parse tree node.
333 *
334 * @throws DataModelException a violation of data model rules.
335 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530336 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530337 public void validateDataOnExit() throws DataModelException {
338 // TODO auto-generated method stub, to be implemented by parser
339 }
340
341 /* (non-Javadoc)
342 * @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
343 */
344 @Override
345 public String getPackage() {
346 // TODO Auto-generated method stub
347 return null;
348 }
349
350 /* (non-Javadoc)
351 * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
352 */
353 @Override
354 public void setPackage(String pkg) {
355 // TODO Auto-generated method stub
356
357 }
358
359 /* (non-Javadoc)
360 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
361 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530362 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530363 public void generateJavaCodeEntry() {
364 // TODO Auto-generated method stub
365
366 }
367
368 /* (non-Javadoc)
369 * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
370 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530371 @Override
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530372 public void generateJavaCodeExit() {
373 // TODO Auto-generated method stub
374
375 }
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530376
377 @Override
378 public CachedFileHandle getFileHandle() {
379 // TODO Auto-generated method stub
380 return null;
381 }
382
383 @Override
384 public void setFileHandle(CachedFileHandle fileHandle) {
385 // TODO Auto-generated method stub
386
387 }
Vinod Kumar S2ff139c2016-02-16 01:37:16 +0530388}