Vidyashree Rama
Committed by Gerrit Code Review

YANG sub module linking + unsupported yang construct + defect fix

Change-Id: I224c8c14ee2111f6844278cb540c48651544f59b
Showing 55 changed files with 1391 additions and 152 deletions
...@@ -57,6 +57,11 @@ public class YangBelongsTo implements Parsable { ...@@ -57,6 +57,11 @@ public class YangBelongsTo implements Parsable {
57 private String belongsToModuleName; 57 private String belongsToModuleName;
58 58
59 /** 59 /**
60 + * Module node to which sub-module belongs to.
61 + */
62 + private YangNode moduleNode;
63 +
64 + /**
60 * Reference RFC 6020. 65 * Reference RFC 6020.
61 * 66 *
62 * The mandatory "prefix" substatement assigns a prefix for the module to 67 * The mandatory "prefix" substatement assigns a prefix for the module to
...@@ -110,6 +115,24 @@ public class YangBelongsTo implements Parsable { ...@@ -110,6 +115,24 @@ public class YangBelongsTo implements Parsable {
110 } 115 }
111 116
112 /** 117 /**
118 + * Returns the module data model node.
119 + *
120 + * @return the module data model node
121 + */
122 + public YangNode getModuleNode() {
123 + return moduleNode;
124 + }
125 +
126 + /**
127 + * Sets the module node.
128 + *
129 + * @param moduleNode module data model node
130 + */
131 + public void setModuleNode(YangNode moduleNode) {
132 + this.moduleNode = moduleNode;
133 + }
134 +
135 + /**
113 * Returns the type of the data as belongs-to. 136 * Returns the type of the data as belongs-to.
114 * 137 *
115 * @return ParsedDataType returns BELONGS_TO_DATA 138 * @return ParsedDataType returns BELONGS_TO_DATA
......
...@@ -135,6 +135,12 @@ public class YangChoice extends YangNode ...@@ -135,6 +135,12 @@ public class YangChoice extends YangNode
135 private YangStatusType status; 135 private YangStatusType status;
136 136
137 /** 137 /**
138 + * Default value in string, needs to be converted to the target object,
139 + * based on the type.
140 + */
141 + private String defaultValueInString;
142 +
143 + /**
138 * Create a choice node. 144 * Create a choice node.
139 */ 145 */
140 public YangChoice() { 146 public YangChoice() {
...@@ -276,6 +282,24 @@ public class YangChoice extends YangNode ...@@ -276,6 +282,24 @@ public class YangChoice extends YangNode
276 } 282 }
277 283
278 /** 284 /**
285 + * Returns the default value.
286 + *
287 + * @return the default value
288 + */
289 + public String getDefaultValueInString() {
290 + return defaultValueInString;
291 + }
292 +
293 + /**
294 + * Sets the default value.
295 + *
296 + * @param defaultValueInString the default value
297 + */
298 + public void setDefaultValueInString(String defaultValueInString) {
299 + this.defaultValueInString = defaultValueInString;
300 + }
301 +
302 + /**
279 * Returns the type of the data. 303 * Returns the type of the data.
280 * 304 *
281 * @return choice data 305 * @return choice data
......
...@@ -101,6 +101,12 @@ public class YangLeaf ...@@ -101,6 +101,12 @@ public class YangLeaf
101 private YangType<?> dataType; 101 private YangType<?> dataType;
102 102
103 /** 103 /**
104 + * Default value in string, needs to be converted to the target object,
105 + * based on the type.
106 + */
107 + private String defaultValueInString;
108 +
109 + /**
104 * Creates a YANG leaf. 110 * Creates a YANG leaf.
105 */ 111 */
106 public YangLeaf() { 112 public YangLeaf() {
...@@ -239,6 +245,24 @@ public class YangLeaf ...@@ -239,6 +245,24 @@ public class YangLeaf
239 } 245 }
240 246
241 /** 247 /**
248 + * Returns the default value.
249 + *
250 + * @return the default value
251 + */
252 + public String getDefaultValueInString() {
253 + return defaultValueInString;
254 + }
255 +
256 + /**
257 + * Sets the default value.
258 + *
259 + * @param defaultValueInString the default value
260 + */
261 + public void setDefaultValueInString(String defaultValueInString) {
262 + this.defaultValueInString = defaultValueInString;
263 + }
264 +
265 + /**
242 * Returns the data type. 266 * Returns the data type.
243 * 267 *
244 * @return the data type 268 * @return the data type
......
...@@ -445,16 +445,10 @@ public class YangList extends YangNode ...@@ -445,16 +445,10 @@ public class YangList extends YangNode
445 445
446 /* A list must have atleast one key leaf if config is true */ 446 /* A list must have atleast one key leaf if config is true */
447 if (isConfig 447 if (isConfig
448 - && (keys == null || leaves == null && leafLists == null)) { 448 + && (keys == null || leaves == null && leafLists == null && !isUsesPresentInList())) {
449 throw new DataModelException("A list must have atleast one key leaf if config is true;"); 449 throw new DataModelException("A list must have atleast one key leaf if config is true;");
450 } else if (keys != null) { 450 } else if (keys != null) {
451 - if (leaves != null) { 451 + validateKey(leaves, leafLists, keys);
452 - validateLeafKey(leaves, keys);
453 - }
454 -
455 - if (leafLists != null) {
456 - validateLeafListKey(leafLists, keys);
457 - }
458 } 452 }
459 } 453 }
460 454
...@@ -528,18 +522,22 @@ public class YangList extends YangNode ...@@ -528,18 +522,22 @@ public class YangList extends YangNode
528 * Validates key statement of list. 522 * Validates key statement of list.
529 * 523 *
530 * @param leaves list of leaf attributes of list 524 * @param leaves list of leaf attributes of list
525 + * @param leafLists list of leaf-list attributes of list
531 * @param keys list of key attributes of list 526 * @param keys list of key attributes of list
532 * @throws DataModelException a violation of data model rules 527 * @throws DataModelException a violation of data model rules
533 */ 528 */
534 - private void validateLeafKey(List<YangLeaf> leaves, List<String> keys) throws DataModelException { 529 + private void validateKey(List<YangLeaf> leaves, List<YangLeafList> leafLists, List<String> keys) throws
530 + DataModelException {
535 boolean leafFound = false; 531 boolean leafFound = false;
536 List<YangLeaf> keyLeaves = new LinkedList<>(); 532 List<YangLeaf> keyLeaves = new LinkedList<>();
533 + List<YangLeafList> keyLeafLists = new LinkedList<>();
537 534
538 /* 535 /*
539 * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf 536 * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf
540 * that is part of the key must not be the built-in type "empty". 537 * that is part of the key must not be the built-in type "empty".
541 */ 538 */
542 for (String key : keys) { 539 for (String key : keys) {
540 + if (leaves != null && !leaves.isEmpty()) {
543 for (YangLeaf leaf : leaves) { 541 for (YangLeaf leaf : leaves) {
544 if (key.equals(leaf.getName())) { 542 if (key.equals(leaf.getName())) {
545 if (leaf.getDataType().getDataType() == YangDataTypes.EMPTY) { 543 if (leaf.getDataType().getDataType() == YangDataTypes.EMPTY) {
...@@ -551,53 +549,24 @@ public class YangList extends YangNode ...@@ -551,53 +549,24 @@ public class YangList extends YangNode
551 break; 549 break;
552 } 550 }
553 } 551 }
554 - if (!leafFound) {
555 - throw new DataModelException("Leaf identifier must refer to a child leaf of the list");
556 - }
557 - leafFound = false;
558 - }
559 -
560 - /*
561 - * All key leafs in a list MUST have the same value for their "config"
562 - * as the list itself.
563 - */
564 - for (YangLeaf keyLeaf : keyLeaves) {
565 - if (isConfig != keyLeaf.isConfig()) {
566 - throw new DataModelException("All key leafs in a list must have the same value for their" +
567 - " \"config\" as the list itself.");
568 - }
569 - }
570 } 552 }
571 553
572 - /** 554 + if (leafLists != null && !leafLists.isEmpty()) {
573 - * Validates key statement of list.
574 - *
575 - * @param leafLists list of leaf-list attributes of list
576 - * @param keys list of key attributes of list
577 - * @throws DataModelException a violation of data model rules
578 - */
579 - private void validateLeafListKey(List<YangLeafList> leafLists, List<String> keys) throws DataModelException {
580 - boolean leafFound = false;
581 - List<YangLeafList> keyLeafLists = new LinkedList<>();
582 -
583 - /*
584 - * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf
585 - * that is part of the key must not be the built-in type "empty".
586 - */
587 - for (String key : keys) {
588 for (YangLeafList leafList : leafLists) { 555 for (YangLeafList leafList : leafLists) {
589 if (key.equals(leafList.getName())) { 556 if (key.equals(leafList.getName())) {
590 if (leafList.getDataType().getDataType() == YangDataTypes.EMPTY) { 557 if (leafList.getDataType().getDataType() == YangDataTypes.EMPTY) {
591 - throw new DataModelException(" A leaf-list that is part of the key must not be the built-in " + 558 + throw new DataModelException(" A leaf-list that is part of the key" +
592 - "type \"empty\"."); 559 + " must not be the built-in type \"empty\".");
593 } 560 }
594 leafFound = true; 561 leafFound = true;
595 keyLeafLists.add(leafList); 562 keyLeafLists.add(leafList);
596 break; 563 break;
597 } 564 }
598 } 565 }
599 - if (!leafFound) { 566 + }
600 - throw new DataModelException("Leaf-list identifier must refer to a child leaf of the list"); 567 +
568 + if (!leafFound && !isUsesPresentInList()) {
569 + throw new DataModelException("An identifier, in key, must refer to a child leaf of the list");
601 } 570 }
602 leafFound = false; 571 leafFound = false;
603 } 572 }
...@@ -606,6 +575,17 @@ public class YangList extends YangNode ...@@ -606,6 +575,17 @@ public class YangList extends YangNode
606 * All key leafs in a list MUST have the same value for their "config" 575 * All key leafs in a list MUST have the same value for their "config"
607 * as the list itself. 576 * as the list itself.
608 */ 577 */
578 + for (YangLeaf keyLeaf : keyLeaves) {
579 + if (isConfig != keyLeaf.isConfig()) {
580 + throw new DataModelException("All key leafs in a list must have the same value for their" +
581 + " \"config\" as the list itself.");
582 + }
583 + }
584 +
585 + /*
586 + * All key leafs in a list MUST have the same value for their "config"
587 + * as the list itself.
588 + */
609 for (YangLeafList keyLeafList : keyLeafLists) { 589 for (YangLeafList keyLeafList : keyLeafLists) {
610 if (isConfig() != keyLeafList.isConfig()) { 590 if (isConfig() != keyLeafList.isConfig()) {
611 throw new DataModelException("All key leaf-lists in a list must have the same value for their" + 591 throw new DataModelException("All key leaf-lists in a list must have the same value for their" +
...@@ -627,4 +607,16 @@ public class YangList extends YangNode ...@@ -627,4 +607,16 @@ public class YangList extends YangNode
627 getName() + "\""); 607 getName() + "\"");
628 } 608 }
629 } 609 }
610 +
611 + private boolean isUsesPresentInList() {
612 + YangNode node = this.getChild();
613 + while (node != null) {
614 + if (node instanceof YangUses) {
615 + return true;
616 + }
617 + node = node.getNextSibling();
618 + }
619 + return false;
620 + }
621 +
630 } 622 }
......
...@@ -19,6 +19,8 @@ package org.onosproject.yangutils.datamodel; ...@@ -19,6 +19,8 @@ package org.onosproject.yangutils.datamodel;
19 import java.util.LinkedList; 19 import java.util.LinkedList;
20 import java.util.List; 20 import java.util.List;
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22 +import org.onosproject.yangutils.parser.Parsable;
23 +import org.onosproject.yangutils.utils.YangConstructType;
22 import org.onosproject.yangutils.utils.builtindatatype.YangBuiltInDataTypeInfo; 24 import org.onosproject.yangutils.utils.builtindatatype.YangBuiltInDataTypeInfo;
23 25
24 import static org.onosproject.yangutils.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString; 26 import static org.onosproject.yangutils.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString;
...@@ -55,7 +57,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -55,7 +57,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
55 * @param <T> range type (data type) 57 * @param <T> range type (data type)
56 */ 58 */
57 public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> 59 public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
58 - implements YangDesc, YangReference, YangAppErrorInfo { 60 + implements YangDesc, YangReference, YangAppErrorInfo, Parsable {
59 61
60 /** 62 /**
61 * Ascending list of range interval restriction. If the restriction is a 63 * Ascending list of range interval restriction. If the restriction is a
...@@ -311,4 +313,19 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> ...@@ -311,4 +313,19 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
311 public void setErrorAppTag(String errTag) { 313 public void setErrorAppTag(String errTag) {
312 errorAppTag = errTag; 314 errorAppTag = errTag;
313 } 315 }
316 +
317 + @Override
318 + public YangConstructType getYangConstructType() {
319 + return YangConstructType.RANGE_DATA;
320 + }
321 +
322 + @Override
323 + public void validateDataOnEntry() throws DataModelException {
324 + //TODO: implement the method.
325 + }
326 +
327 + @Override
328 + public void validateDataOnExit() throws DataModelException {
329 + //TODO: implement the method.
330 + }
314 } 331 }
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
16 16
17 package org.onosproject.yangutils.datamodel; 17 package org.onosproject.yangutils.datamodel;
18 18
19 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20 +import org.onosproject.yangutils.parser.Parsable;
21 +import org.onosproject.yangutils.utils.YangConstructType;
19 import org.onosproject.yangutils.utils.builtindatatype.YangUint64; 22 import org.onosproject.yangutils.utils.builtindatatype.YangUint64;
20 23
21 /*- 24 /*-
...@@ -28,7 +31,7 @@ import org.onosproject.yangutils.utils.builtindatatype.YangUint64; ...@@ -28,7 +31,7 @@ import org.onosproject.yangutils.utils.builtindatatype.YangUint64;
28 /** 31 /**
29 * Represents the restriction for string data type. 32 * Represents the restriction for string data type.
30 */ 33 */
31 -public class YangStringRestriction { 34 +public class YangStringRestriction implements YangDesc, YangReference, YangAppErrorInfo, Parsable {
32 35
33 /*- 36 /*-
34 * Reference RFC 6020. 37 * Reference RFC 6020.
...@@ -77,6 +80,26 @@ public class YangStringRestriction { ...@@ -77,6 +80,26 @@ public class YangStringRestriction {
77 private YangPatternRestriction patternRestriction; 80 private YangPatternRestriction patternRestriction;
78 81
79 /** 82 /**
83 + * Textual reference.
84 + */
85 + private String reference;
86 +
87 + /**
88 + * Application's error message, to be used for data error.
89 + */
90 + private String errorMessage;
91 +
92 + /**
93 + * Application's error tag, to be filled in data validation error response.
94 + */
95 + private String errorAppTag;
96 +
97 + /**
98 + * Textual description.
99 + */
100 + private String description;
101 +
102 + /**
80 * Creates a YANG string restriction object. 103 * Creates a YANG string restriction object.
81 */ 104 */
82 public YangStringRestriction() { 105 public YangStringRestriction() {
...@@ -129,4 +152,101 @@ public class YangStringRestriction { ...@@ -129,4 +152,101 @@ public class YangStringRestriction {
129 } 152 }
130 getPatternRestriction().addPattern(newPattern); 153 getPatternRestriction().addPattern(newPattern);
131 } 154 }
155 +
156 + /**
157 + * Returns the textual reference of the string restriction.
158 + *
159 + * @return textual reference of the string restriction
160 + */
161 + @Override
162 + public String getReference() {
163 + return reference;
164 + }
165 +
166 + /**
167 + * Sets the textual reference of the string restriction.
168 + *
169 + * @param ref textual reference of the string restriction
170 + */
171 + @Override
172 + public void setReference(String ref) {
173 + reference = ref;
174 + }
175 +
176 + /**
177 + * Returns the description of the string restriction.
178 + *
179 + * @return description of the string restriction
180 + */
181 + @Override
182 + public String getDescription() {
183 + return description;
184 + }
185 +
186 + /**
187 + * Sets the description of the string restriction.
188 + *
189 + * @param desc description of the string restriction
190 + */
191 + @Override
192 + public void setDescription(String desc) {
193 + description = desc;
194 +
195 + }
196 +
197 + /**
198 + * Returns application's error message, to be used for data error.
199 + *
200 + * @return Application's error message, to be used for data error
201 + */
202 + @Override
203 + public String getGetErrorMessage() {
204 + return errorMessage;
205 + }
206 +
207 + /**
208 + * Sets Application's error message, to be used for data error.
209 + *
210 + * @param errMsg Application's error message, to be used for data error
211 + */
212 + @Override
213 + public void setErrorMessage(String errMsg) {
214 + errorMessage = errMsg;
215 +
216 + }
217 +
218 + /**
219 + * Returns application's error tag, to be used for data error.
220 + *
221 + * @return application's error tag, to be used for data error
222 + */
223 + @Override
224 + public String getGetErrorAppTag() {
225 + return errorAppTag;
226 + }
227 +
228 + /**
229 + * Sets application's error tag, to be used for data error.
230 + *
231 + * @param errTag application's error tag, to be used for data error.
232 + */
233 + @Override
234 + public void setErrorAppTag(String errTag) {
235 + errorAppTag = errTag;
236 + }
237 +
238 + @Override
239 + public YangConstructType getYangConstructType() {
240 + return YangConstructType.PATTERN_DATA;
241 + }
242 +
243 + @Override
244 + public void validateDataOnEntry() throws DataModelException {
245 + //TODO: implement the method.
246 + }
247 +
248 + @Override
249 + public void validateDataOnExit() throws DataModelException {
250 + //TODO: implement the method.
251 + }
132 } 252 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.yangutils.datamodel.utils; 17 package org.onosproject.yangutils.datamodel.utils;
18 18
19 +import java.util.Iterator;
19 import java.util.List; 20 import java.util.List;
20 21
21 import org.onosproject.yangutils.datamodel.CollisionDetector; 22 import org.onosproject.yangutils.datamodel.CollisionDetector;
...@@ -29,6 +30,7 @@ import org.onosproject.yangutils.datamodel.YangResolutionInfo; ...@@ -29,6 +30,7 @@ import org.onosproject.yangutils.datamodel.YangResolutionInfo;
29 import org.onosproject.yangutils.datamodel.YangRpc; 30 import org.onosproject.yangutils.datamodel.YangRpc;
30 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 31 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
31 import org.onosproject.yangutils.parser.Parsable; 32 import org.onosproject.yangutils.parser.Parsable;
33 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
32 import org.onosproject.yangutils.utils.YangConstructType; 34 import org.onosproject.yangutils.utils.YangConstructType;
33 35
34 /** 36 /**
...@@ -240,4 +242,26 @@ public final class DataModelUtils { ...@@ -240,4 +242,26 @@ public final class DataModelUtils {
240 } 242 }
241 return false; 243 return false;
242 } 244 }
245 +
246 + /**
247 + * Returns module's data model node to which sub-module belongs to.
248 + *
249 + * @param yangFileInfo YANG file information
250 + * @param belongsToModuleName name of the module to which sub-module belongs to
251 + * @return module node to which sub-module belongs to
252 + * @throws DataModelException when belongs to module node is not found
253 + */
254 + public static YangNode findBelongsToModuleNode(List<YangFileInfo> yangFileInfo,
255 + String belongsToModuleName) throws DataModelException {
256 + Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
257 + while (yangFileIterator.hasNext()) {
258 + YangFileInfo yangFile = yangFileIterator.next();
259 + YangNode yangNode = yangFile.getRootNode();
260 + if (yangNode.getName().equals(belongsToModuleName)) {
261 + return yangNode;
262 + }
263 + }
264 + throw new DataModelException("YANG file error : Module " + belongsToModuleName + " to which sub-module " +
265 + "belongs to is not found.");
266 + }
243 } 267 }
......
...@@ -26,6 +26,7 @@ import org.onosproject.yangutils.datamodel.YangModule; ...@@ -26,6 +26,7 @@ import org.onosproject.yangutils.datamodel.YangModule;
26 import org.onosproject.yangutils.datamodel.YangNode; 26 import org.onosproject.yangutils.datamodel.YangNode;
27 import org.onosproject.yangutils.datamodel.YangNotification; 27 import org.onosproject.yangutils.datamodel.YangNotification;
28 import org.onosproject.yangutils.datamodel.YangOutput; 28 import org.onosproject.yangutils.datamodel.YangOutput;
29 +import org.onosproject.yangutils.datamodel.YangSubModule;
29 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 30 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
30 import org.onosproject.yangutils.parser.Parsable; 31 import org.onosproject.yangutils.parser.Parsable;
31 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 32 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
...@@ -133,12 +134,11 @@ public final class ContainerListener { ...@@ -133,12 +134,11 @@ public final class ContainerListener {
133 } 134 }
134 135
135 Parsable curData = listener.getParsedDataStack().peek(); 136 Parsable curData = listener.getParsedDataStack().peek();
136 - if (curData instanceof YangModule || curData instanceof YangContainer 137 + if (curData instanceof YangModule || curData instanceof YangSubModule
137 - || curData instanceof YangList || curData instanceof YangCase 138 + || curData instanceof YangContainer || curData instanceof YangList
138 - || curData instanceof YangNotification 139 + || curData instanceof YangCase || curData instanceof YangNotification
139 || curData instanceof YangInput || curData instanceof YangOutput 140 || curData instanceof YangInput || curData instanceof YangOutput
140 - || curData instanceof YangAugment 141 + || curData instanceof YangAugment || curData instanceof YangGrouping) {
141 - || curData instanceof YangGrouping) {
142 YangNode curNode = (YangNode) curData; 142 YangNode curNode = (YangNode) curData;
143 try { 143 try {
144 curNode.addChild(container); 144 curNode.addChild(container);
......
...@@ -39,6 +39,8 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -39,6 +39,8 @@ package org.onosproject.yangutils.parser.impl.listeners;
39 * defaultStatement : DEFAULT_KEYWORD string STMTEND; 39 * defaultStatement : DEFAULT_KEYWORD string STMTEND;
40 */ 40 */
41 41
42 +import org.onosproject.yangutils.datamodel.YangChoice;
43 +import org.onosproject.yangutils.datamodel.YangLeaf;
42 import org.onosproject.yangutils.datamodel.YangTypeDef; 44 import org.onosproject.yangutils.datamodel.YangTypeDef;
43 import org.onosproject.yangutils.parser.Parsable; 45 import org.onosproject.yangutils.parser.Parsable;
44 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 46 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
...@@ -83,6 +85,16 @@ public final class DefaultListener { ...@@ -83,6 +85,16 @@ public final class DefaultListener {
83 typeDef.setDefaultValueInString(ctx.string().getText()); 85 typeDef.setDefaultValueInString(ctx.string().getText());
84 break; 86 break;
85 } 87 }
88 + case LEAF_DATA: {
89 + YangLeaf leaf = (YangLeaf) tmpNode;
90 + leaf.setDefaultValueInString(ctx.string().getText());
91 + break;
92 + }
93 + case CHOICE_DATA: {
94 + YangChoice choice = (YangChoice) tmpNode;
95 + choice.setDefaultValueInString(ctx.string().getText());
96 + break;
97 + }
86 default: 98 default:
87 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, 99 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
88 DEFAULT_DATA, ctx.string().getText(), ENTRY)); 100 DEFAULT_DATA, ctx.string().getText(), ENTRY));
......
...@@ -146,7 +146,14 @@ public final class EnumListener { ...@@ -146,7 +146,14 @@ public final class EnumListener {
146 boolean isValuePresent = false; 146 boolean isValuePresent = false;
147 147
148 for (YangEnum curEnum : yangEnumeration.getEnumSet()) { 148 for (YangEnum curEnum : yangEnumeration.getEnumSet()) {
149 - if (maxValue <= curEnum.getValue()) { 149 + if (curEnum.getValue() == Integer.MAX_VALUE) {
150 + ParserException parserException = new ParserException("YANG file error : "
151 + + "An enum value MUST be specified for enum substatements following the one"
152 + + "with the current highest value");
153 + parserException.setLine(ctx.getStart().getLine());
154 + parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
155 + throw parserException;
156 + } else if (maxValue <= curEnum.getValue()) {
150 maxValue = curEnum.getValue(); 157 maxValue = curEnum.getValue();
151 isValuePresent = true; 158 isValuePresent = true;
152 } 159 }
...@@ -161,8 +168,8 @@ public final class EnumListener { ...@@ -161,8 +168,8 @@ public final class EnumListener {
161 } catch (DataModelException e) { 168 } catch (DataModelException e) {
162 ParserException parserException = new ParserException(constructExtendedListenerErrorMessage( 169 ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
163 DUPLICATE_ENTRY, ENUM_DATA, ctx.string().getText(), EXIT, e.getMessage())); 170 DUPLICATE_ENTRY, ENUM_DATA, ctx.string().getText(), EXIT, e.getMessage()));
164 - parserException.setLine(ctx.string().STRING(0).getSymbol().getLine()); 171 + parserException.setLine(ctx.getStart().getLine());
165 - parserException.setCharPosition(ctx.string().STRING(0).getSymbol().getCharPositionInLine()); 172 + parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
166 throw parserException; 173 throw parserException;
167 } 174 }
168 break; 175 break;
...@@ -173,8 +180,7 @@ public final class EnumListener { ...@@ -173,8 +180,7 @@ public final class EnumListener {
173 } 180 }
174 } else { 181 } else {
175 throw new ParserException( 182 throw new ParserException(
176 - constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUM_DATA, ctx.string().getText(), 183 + constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUM_DATA, ctx.string().getText(), EXIT));
177 - EXIT));
178 } 184 }
179 } 185 }
180 } 186 }
......
...@@ -29,8 +29,10 @@ import org.onosproject.yangutils.utils.YangConstructType; ...@@ -29,8 +29,10 @@ import org.onosproject.yangutils.utils.YangConstructType;
29 29
30 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; 30 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
35 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 36 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
35 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 37 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
36 import static org.onosproject.yangutils.utils.RestrictionResolver.processLengthRestriction; 38 import static org.onosproject.yangutils.utils.RestrictionResolver.processLengthRestriction;
...@@ -86,7 +88,7 @@ public final class LengthRestrictionListener { ...@@ -86,7 +88,7 @@ public final class LengthRestrictionListener {
86 Parsable tmpData = listener.getParsedDataStack().peek(); 88 Parsable tmpData = listener.getParsedDataStack().peek();
87 if (tmpData.getYangConstructType() == TYPE_DATA) { 89 if (tmpData.getYangConstructType() == TYPE_DATA) {
88 YangType type = (YangType) tmpData; 90 YangType type = (YangType) tmpData;
89 - setLengthRestriction(type, ctx); 91 + setLengthRestriction(listener, type, ctx);
90 } else { 92 } else {
91 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LENGTH_DATA, 93 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LENGTH_DATA,
92 ctx.length().getText(), ENTRY)); 94 ctx.length().getText(), ENTRY));
...@@ -96,10 +98,11 @@ public final class LengthRestrictionListener { ...@@ -96,10 +98,11 @@ public final class LengthRestrictionListener {
96 /** 98 /**
97 * Sets the length restriction to type. 99 * Sets the length restriction to type.
98 * 100 *
101 + * @param listener listener's object
99 * @param type Yang type for which length restriction to be set 102 * @param type Yang type for which length restriction to be set
100 * @param ctx context object of the grammar rule 103 * @param ctx context object of the grammar rule
101 */ 104 */
102 - private static void setLengthRestriction(YangType type, 105 + private static void setLengthRestriction(TreeWalkListener listener, YangType type,
103 GeneratedYangParser.LengthStatementContext ctx) { 106 GeneratedYangParser.LengthStatementContext ctx) {
104 107
105 if (type.getDataType() == DERIVED) { 108 if (type.getDataType() == DERIVED) {
...@@ -132,5 +135,31 @@ public final class LengthRestrictionListener { ...@@ -132,5 +135,31 @@ public final class LengthRestrictionListener {
132 } 135 }
133 136
134 stringRestriction.setLengthRestriction(lengthRestriction); 137 stringRestriction.setLengthRestriction(lengthRestriction);
138 + listener.getParsedDataStack().push(lengthRestriction);
139 + }
140 +
141 + /**
142 + * Performs validation and updates the data model tree.
143 + * It is called when parser exits from grammar rule (length).
144 + *
145 + * @param listener listener's object
146 + * @param ctx context object of the grammar rule
147 + */
148 + public static void processLengthRestrictionExit(TreeWalkListener listener,
149 + GeneratedYangParser.LengthStatementContext ctx) {
150 +
151 + // Check for stack to be non empty.
152 + checkStackIsNotEmpty(listener, MISSING_HOLDER, LENGTH_DATA, ctx.length().getText(), EXIT);
153 +
154 + Parsable tmpData = listener.getParsedDataStack().peek();
155 + if (tmpData instanceof YangRangeRestriction) {
156 + listener.getParsedDataStack().pop();
157 + } else if (tmpData instanceof YangType
158 + && ((YangType) tmpData).getDataType() == DERIVED) {
159 + // TODO : need to handle in linker
160 + } else {
161 + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LENGTH_DATA,
162 + ctx.length().getText(), EXIT));
163 + }
135 } 164 }
136 } 165 }
......
...@@ -26,6 +26,7 @@ import org.onosproject.yangutils.datamodel.YangModule; ...@@ -26,6 +26,7 @@ import org.onosproject.yangutils.datamodel.YangModule;
26 import org.onosproject.yangutils.datamodel.YangNode; 26 import org.onosproject.yangutils.datamodel.YangNode;
27 import org.onosproject.yangutils.datamodel.YangNotification; 27 import org.onosproject.yangutils.datamodel.YangNotification;
28 import org.onosproject.yangutils.datamodel.YangOutput; 28 import org.onosproject.yangutils.datamodel.YangOutput;
29 +import org.onosproject.yangutils.datamodel.YangSubModule;
29 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 30 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
30 import org.onosproject.yangutils.parser.Parsable; 31 import org.onosproject.yangutils.parser.Parsable;
31 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 32 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
...@@ -141,7 +142,8 @@ public final class ListListener { ...@@ -141,7 +142,8 @@ public final class ListListener {
141 if (curData instanceof YangModule || curData instanceof YangContainer 142 if (curData instanceof YangModule || curData instanceof YangContainer
142 || curData instanceof YangList || curData instanceof YangCase 143 || curData instanceof YangList || curData instanceof YangCase
143 || curData instanceof YangNotification || curData instanceof YangInput 144 || curData instanceof YangNotification || curData instanceof YangInput
144 - || curData instanceof YangOutput || curData instanceof YangAugment || curData instanceof YangGrouping) { 145 + || curData instanceof YangOutput || curData instanceof YangAugment
146 + || curData instanceof YangGrouping || curData instanceof YangSubModule) {
145 curNode = (YangNode) curData; 147 curNode = (YangNode) curData;
146 try { 148 try {
147 curNode.addChild(yangList); 149 curNode.addChild(yangList);
......
...@@ -27,9 +27,12 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; ...@@ -27,9 +27,12 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
27 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 27 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
28 import org.onosproject.yangutils.utils.YangConstructType; 28 import org.onosproject.yangutils.utils.YangConstructType;
29 29
30 +import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
35 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 36 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 37 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
35 import static org.onosproject.yangutils.utils.YangConstructType.PATTERN_DATA; 38 import static org.onosproject.yangutils.utils.YangConstructType.PATTERN_DATA;
...@@ -84,7 +87,7 @@ public final class PatternRestrictionListener { ...@@ -84,7 +87,7 @@ public final class PatternRestrictionListener {
84 Parsable tmpData = listener.getParsedDataStack().peek(); 87 Parsable tmpData = listener.getParsedDataStack().peek();
85 if (tmpData.getYangConstructType() == TYPE_DATA) { 88 if (tmpData.getYangConstructType() == TYPE_DATA) {
86 YangType type = (YangType) tmpData; 89 YangType type = (YangType) tmpData;
87 - setPatternRestriction(type, ctx); 90 + setPatternRestriction(listener, type, ctx);
88 } else { 91 } else {
89 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PATTERN_DATA, 92 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PATTERN_DATA,
90 ctx.string().getText(), ENTRY)); 93 ctx.string().getText(), ENTRY));
...@@ -94,10 +97,11 @@ public final class PatternRestrictionListener { ...@@ -94,10 +97,11 @@ public final class PatternRestrictionListener {
94 /** 97 /**
95 * Sets the pattern restriction to type. 98 * Sets the pattern restriction to type.
96 * 99 *
100 + * @param listener listener's object
97 * @param type Yang type for which pattern restriction to be set 101 * @param type Yang type for which pattern restriction to be set
98 * @param ctx context object of the grammar rule 102 * @param ctx context object of the grammar rule
99 */ 103 */
100 - private static void setPatternRestriction(YangType type, 104 + private static void setPatternRestriction(TreeWalkListener listener, YangType type,
101 GeneratedYangParser.PatternStatementContext ctx) { 105 GeneratedYangParser.PatternStatementContext ctx) {
102 106
103 if (type.getDataType() != YangDataTypes.STRING && type.getDataType() != YangDataTypes.DERIVED) { 107 if (type.getDataType() != YangDataTypes.STRING && type.getDataType() != YangDataTypes.DERIVED) {
...@@ -121,6 +125,7 @@ public final class PatternRestrictionListener { ...@@ -121,6 +125,7 @@ public final class PatternRestrictionListener {
121 } else { 125 } else {
122 stringRestriction.addPattern(patternArgument); 126 stringRestriction.addPattern(patternArgument);
123 } 127 }
128 + listener.getParsedDataStack().push(stringRestriction);
124 } else { 129 } else {
125 YangPatternRestriction patternRestriction = (YangPatternRestriction) ((YangDerivedInfo<?>) type 130 YangPatternRestriction patternRestriction = (YangPatternRestriction) ((YangDerivedInfo<?>) type
126 .getDataTypeExtendedInfo()).getPatternRestriction(); 131 .getDataTypeExtendedInfo()).getPatternRestriction();
...@@ -134,4 +139,29 @@ public final class PatternRestrictionListener { ...@@ -134,4 +139,29 @@ public final class PatternRestrictionListener {
134 } 139 }
135 } 140 }
136 } 141 }
142 +
143 + /**
144 + * Performs validation and updates the data model tree.
145 + * It is called when parser exits from grammar rule (pattern).
146 + *
147 + * @param listener listener's object
148 + * @param ctx context object of the grammar rule
149 + */
150 + public static void processPatternRestrictionExit(TreeWalkListener listener,
151 + GeneratedYangParser.PatternStatementContext ctx) {
152 +
153 + // Check for stack to be non empty.
154 + checkStackIsNotEmpty(listener, MISSING_HOLDER, PATTERN_DATA, ctx.string().getText(), EXIT);
155 +
156 + Parsable tmpData = listener.getParsedDataStack().peek();
157 + if (tmpData instanceof YangStringRestriction) {
158 + listener.getParsedDataStack().pop();
159 + } else if (tmpData instanceof YangType
160 + && ((YangType) tmpData).getDataType() == DERIVED) {
161 + // TODO : need to handle in linker
162 + } else {
163 + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, PATTERN_DATA,
164 + ctx.string().getText(), EXIT));
165 + }
166 + }
137 } 167 }
......
...@@ -26,8 +26,10 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; ...@@ -26,8 +26,10 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
26 26
27 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; 27 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
29 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
29 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
33 import static org.onosproject.yangutils.utils.RestrictionResolver.isOfRangeRestrictedType; 35 import static org.onosproject.yangutils.utils.RestrictionResolver.isOfRangeRestrictedType;
...@@ -82,7 +84,7 @@ public final class RangeRestrictionListener { ...@@ -82,7 +84,7 @@ public final class RangeRestrictionListener {
82 Parsable tmpData = listener.getParsedDataStack().peek(); 84 Parsable tmpData = listener.getParsedDataStack().peek();
83 if (tmpData.getYangConstructType() == TYPE_DATA) { 85 if (tmpData.getYangConstructType() == TYPE_DATA) {
84 YangType type = (YangType) tmpData; 86 YangType type = (YangType) tmpData;
85 - setRangeRestriction(type, ctx); 87 + setRangeRestriction(listener, type, ctx);
86 } else { 88 } else {
87 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, RANGE_DATA, 89 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, RANGE_DATA,
88 ctx.range().getText(), ENTRY)); 90 ctx.range().getText(), ENTRY));
...@@ -92,10 +94,11 @@ public final class RangeRestrictionListener { ...@@ -92,10 +94,11 @@ public final class RangeRestrictionListener {
92 /** 94 /**
93 * Sets the range restriction to type. 95 * Sets the range restriction to type.
94 * 96 *
97 + * @param listener listener's object
95 * @param type YANG type for which range restriction to be added 98 * @param type YANG type for which range restriction to be added
96 * @param ctx context object of the grammar rule 99 * @param ctx context object of the grammar rule
97 */ 100 */
98 - private static void setRangeRestriction(YangType type, 101 + private static void setRangeRestriction(TreeWalkListener listener, YangType type,
99 GeneratedYangParser.RangeStatementContext ctx) { 102 GeneratedYangParser.RangeStatementContext ctx) {
100 103
101 if (type.getDataType() == DERIVED) { 104 if (type.getDataType() == DERIVED) {
...@@ -122,5 +125,31 @@ public final class RangeRestrictionListener { ...@@ -122,5 +125,31 @@ public final class RangeRestrictionListener {
122 if (rangeRestriction != null) { 125 if (rangeRestriction != null) {
123 type.setDataTypeExtendedInfo(rangeRestriction); 126 type.setDataTypeExtendedInfo(rangeRestriction);
124 } 127 }
128 + listener.getParsedDataStack().push(rangeRestriction);
129 + }
130 +
131 + /**
132 + * Performs validation and updates the data model tree.
133 + * It is called when parser exits from grammar rule (range).
134 + *
135 + * @param listener listener's object
136 + * @param ctx context object of the grammar rule
137 + */
138 + public static void processRangeRestrictionExit(TreeWalkListener listener,
139 + GeneratedYangParser.RangeStatementContext ctx) {
140 +
141 + // Check for stack to be non empty.
142 + checkStackIsNotEmpty(listener, MISSING_HOLDER, RANGE_DATA, ctx.range().getText(), EXIT);
143 +
144 + Parsable tmpData = listener.getParsedDataStack().peek();
145 + if (tmpData instanceof YangRangeRestriction) {
146 + listener.getParsedDataStack().pop();
147 + } else if (tmpData instanceof YangType
148 + && ((YangType) tmpData).getDataType() == DERIVED) {
149 + // TODO : need to handle in linker
150 + } else {
151 + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, RANGE_DATA,
152 + ctx.range().getText(), EXIT));
153 + }
125 } 154 }
126 } 155 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -38,6 +38,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMes ...@@ -38,6 +38,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMes
38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
40 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 40 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
41 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIntegerValue;
41 import static org.onosproject.yangutils.utils.YangConstructType.VALUE_DATA; 42 import static org.onosproject.yangutils.utils.YangConstructType.VALUE_DATA;
42 43
43 /** 44 /**
...@@ -62,25 +63,28 @@ public final class ValueListener { ...@@ -62,25 +63,28 @@ public final class ValueListener {
62 public static void processValueEntry(TreeWalkListener listener, GeneratedYangParser.ValueStatementContext ctx) { 63 public static void processValueEntry(TreeWalkListener listener, GeneratedYangParser.ValueStatementContext ctx) {
63 64
64 // Check for stack to be non empty. 65 // Check for stack to be non empty.
65 - checkStackIsNotEmpty(listener, MISSING_HOLDER, VALUE_DATA, ctx.INTEGER().getText(), ENTRY); 66 + checkStackIsNotEmpty(listener, MISSING_HOLDER, VALUE_DATA, ctx.value().getText(), ENTRY);
67 +
68 + // Validate value
69 + int value = getValidIntegerValue(ctx.value().getText(), VALUE_DATA, ctx);
66 70
67 // Obtain the node of the stack. 71 // Obtain the node of the stack.
68 Parsable tmpNode = listener.getParsedDataStack().peek(); 72 Parsable tmpNode = listener.getParsedDataStack().peek();
69 switch (tmpNode.getYangConstructType()) { 73 switch (tmpNode.getYangConstructType()) {
70 case ENUM_DATA: { 74 case ENUM_DATA: {
71 YangEnum enumNode = (YangEnum) tmpNode; 75 YangEnum enumNode = (YangEnum) tmpNode;
72 - if (!isEnumValueValid(listener, ctx)) { 76 + if (!isEnumValueValid(listener, ctx, value)) {
73 ParserException parserException = new ParserException("Duplicate Value Entry"); 77 ParserException parserException = new ParserException("Duplicate Value Entry");
74 - parserException.setLine(ctx.INTEGER().getSymbol().getLine()); 78 + parserException.setLine(ctx.getStart().getLine());
75 - parserException.setCharPosition(ctx.INTEGER().getSymbol().getCharPositionInLine()); 79 + parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
76 throw parserException; 80 throw parserException;
77 } 81 }
78 - enumNode.setValue(Integer.valueOf(ctx.INTEGER().getText())); 82 + enumNode.setValue(value);
79 break; 83 break;
80 } 84 }
81 default: 85 default:
82 throw new ParserException( 86 throw new ParserException(
83 - constructListenerErrorMessage(INVALID_HOLDER, VALUE_DATA, ctx.INTEGER().getText(), ENTRY)); 87 + constructListenerErrorMessage(INVALID_HOLDER, VALUE_DATA, ctx.value().getText(), ENTRY));
84 } 88 }
85 } 89 }
86 90
...@@ -89,20 +93,22 @@ public final class ValueListener { ...@@ -89,20 +93,22 @@ public final class ValueListener {
89 * 93 *
90 * @param listener Listener's object 94 * @param listener Listener's object
91 * @param ctx context object of the grammar rule 95 * @param ctx context object of the grammar rule
96 + * @param value enum value
92 * @return validation result 97 * @return validation result
93 */ 98 */
94 - private static boolean isEnumValueValid(TreeWalkListener listener, GeneratedYangParser.ValueStatementContext ctx) { 99 + private static boolean isEnumValueValid(TreeWalkListener listener, GeneratedYangParser.ValueStatementContext ctx,
100 + int value) {
95 Parsable enumNode = listener.getParsedDataStack().pop(); 101 Parsable enumNode = listener.getParsedDataStack().pop();
96 102
97 // Check for stack to be non empty. 103 // Check for stack to be non empty.
98 - checkStackIsNotEmpty(listener, MISSING_HOLDER, VALUE_DATA, ctx.INTEGER().getText(), ENTRY); 104 + checkStackIsNotEmpty(listener, MISSING_HOLDER, VALUE_DATA, ctx.value().getText(), ENTRY);
99 105
100 Parsable tmpNode = listener.getParsedDataStack().peek(); 106 Parsable tmpNode = listener.getParsedDataStack().peek();
101 switch (tmpNode.getYangConstructType()) { 107 switch (tmpNode.getYangConstructType()) {
102 case ENUMERATION_DATA: { 108 case ENUMERATION_DATA: {
103 YangEnumeration yangEnumeration = (YangEnumeration) tmpNode; 109 YangEnumeration yangEnumeration = (YangEnumeration) tmpNode;
104 for (YangEnum curEnum : yangEnumeration.getEnumSet()) { 110 for (YangEnum curEnum : yangEnumeration.getEnumSet()) {
105 - if (Integer.valueOf(ctx.INTEGER().getText()) == curEnum.getValue()) { 111 + if (value == curEnum.getValue()) {
106 listener.getParsedDataStack().push(enumNode); 112 listener.getParsedDataStack().push(enumNode);
107 return false; 113 return false;
108 } 114 }
...@@ -113,7 +119,7 @@ public final class ValueListener { ...@@ -113,7 +119,7 @@ public final class ValueListener {
113 default: 119 default:
114 listener.getParsedDataStack().push(enumNode); 120 listener.getParsedDataStack().push(enumNode);
115 throw new ParserException( 121 throw new ParserException(
116 - constructListenerErrorMessage(INVALID_HOLDER, VALUE_DATA, ctx.INTEGER().getText(), ENTRY)); 122 + constructListenerErrorMessage(INVALID_HOLDER, VALUE_DATA, ctx.value().getText(), ENTRY));
117 } 123 }
118 } 124 }
119 } 125 }
......
...@@ -29,6 +29,18 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; ...@@ -29,6 +29,18 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
29 import org.onosproject.yangutils.parser.exceptions.ParserException; 29 import org.onosproject.yangutils.parser.exceptions.ParserException;
30 import org.onosproject.yangutils.utils.YangConstructType; 30 import org.onosproject.yangutils.utils.YangConstructType;
31 31
32 +import static org.onosproject.yangutils.utils.UtilConstants.ADD;
33 +import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
34 +import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
35 +import static org.onosproject.yangutils.utils.UtilConstants.COLON;
36 +import static org.onosproject.yangutils.utils.UtilConstants.CARET;
37 +import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
38 +import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
39 +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
40 +import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
41 +import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
42 +import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR;
43 +
32 /** 44 /**
33 * Represents an utility for listener. 45 * Represents an utility for listener.
34 */ 46 */
...@@ -37,18 +49,10 @@ public final class ListenerUtil { ...@@ -37,18 +49,10 @@ public final class ListenerUtil {
37 private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_.-]*"); 49 private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_.-]*");
38 private static final String DATE_PATTERN = "[0-9]{4}-([0-9]{2}|[0-9])-([0-9]{2}|[0-9])"; 50 private static final String DATE_PATTERN = "[0-9]{4}-([0-9]{2}|[0-9])-([0-9]{2}|[0-9])";
39 private static final String NON_NEGATIVE_INTEGER_PATTERN = "[0-9]+"; 51 private static final String NON_NEGATIVE_INTEGER_PATTERN = "[0-9]+";
40 - private static final String PLUS = "+"; 52 + private static final Pattern INTEGER_PATTERN = Pattern.compile("[-][0-9]+|[0-9]+");
41 private static final String ONE = "1"; 53 private static final String ONE = "1";
42 - private static final String TRUE_KEYWORD = "true";
43 - private static final String FALSE_KEYWORD = "false";
44 private static final int IDENTIFIER_LENGTH = 64; 54 private static final int IDENTIFIER_LENGTH = 64;
45 private static final String DATE_FORMAT = "yyyy-MM-dd"; 55 private static final String DATE_FORMAT = "yyyy-MM-dd";
46 - private static final String EMPTY_STRING = "";
47 - private static final String HYPHEN = "-";
48 - private static final String SLASH = "/";
49 - private static final String SPACE = " ";
50 - private static final String COLON = ":";
51 - private static final String CARET = "^";
52 56
53 /** 57 /**
54 * Creates a new listener util. 58 * Creates a new listener util.
...@@ -65,7 +69,7 @@ public final class ListenerUtil { ...@@ -65,7 +69,7 @@ public final class ListenerUtil {
65 public static String removeQuotesAndHandleConcat(String yangStringData) { 69 public static String removeQuotesAndHandleConcat(String yangStringData) {
66 70
67 yangStringData = yangStringData.replace("\"", EMPTY_STRING); 71 yangStringData = yangStringData.replace("\"", EMPTY_STRING);
68 - String[] tmpData = yangStringData.split(Pattern.quote(PLUS)); 72 + String[] tmpData = yangStringData.split(Pattern.quote(ADD));
69 StringBuilder builder = new StringBuilder(); 73 StringBuilder builder = new StringBuilder();
70 for (String yangString : tmpData) { 74 for (String yangString : tmpData) {
71 builder.append(yangString); 75 builder.append(yangString);
...@@ -171,6 +175,41 @@ public final class ListenerUtil { ...@@ -171,6 +175,41 @@ public final class ListenerUtil {
171 } 175 }
172 176
173 /** 177 /**
178 + * Validates integer value.
179 + *
180 + * @param integerValue integer to be validated
181 + * @param yangConstruct yang construct for creating error message
182 + * @param ctx context object of the grammar rule
183 + * @return valid integer value
184 + */
185 + public static int getValidIntegerValue(String integerValue, YangConstructType yangConstruct,
186 + ParserRuleContext ctx) {
187 +
188 + String value = removeQuotesAndHandleConcat(integerValue);
189 + if (!INTEGER_PATTERN.matcher(value).matches()) {
190 + ParserException parserException = new ParserException("YANG file error : " +
191 + YangConstructType.getYangConstructType(yangConstruct) + " value " + value + " is not " +
192 + "valid.");
193 + parserException.setLine(ctx.getStart().getLine());
194 + parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
195 + throw parserException;
196 + }
197 +
198 + int valueInInteger;
199 + try {
200 + valueInInteger = Integer.parseInt(value);
201 + } catch (NumberFormatException e) {
202 + ParserException parserException = new ParserException("YANG file error : " +
203 + YangConstructType.getYangConstructType(yangConstruct) + " value " + value + " is not " +
204 + "valid.");
205 + parserException.setLine(ctx.getStart().getLine());
206 + parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
207 + throw parserException;
208 + }
209 + return valueInInteger;
210 + }
211 +
212 + /**
174 * Validates boolean value. 213 * Validates boolean value.
175 * 214 *
176 * @param booleanValue value to be validated 215 * @param booleanValue value to be validated
...@@ -182,9 +221,9 @@ public final class ListenerUtil { ...@@ -182,9 +221,9 @@ public final class ListenerUtil {
182 ParserRuleContext ctx) { 221 ParserRuleContext ctx) {
183 222
184 String value = removeQuotesAndHandleConcat(booleanValue); 223 String value = removeQuotesAndHandleConcat(booleanValue);
185 - if (value.equals(TRUE_KEYWORD)) { 224 + if (value.equals(TRUE)) {
186 return true; 225 return true;
187 - } else if (value.equals(FALSE_KEYWORD)) { 226 + } else if (value.equals(FALSE)) {
188 return false; 227 return false;
189 } else { 228 } else {
190 ParserException parserException = new ParserException("YANG file error : " + 229 ParserException parserException = new ParserException("YANG file error : " +
...@@ -272,4 +311,21 @@ public final class ListenerUtil { ...@@ -272,4 +311,21 @@ public final class ListenerUtil {
272 } 311 }
273 return targetNodes; 312 return targetNodes;
274 } 313 }
314 +
315 + /**
316 + * Throws parser exception for unsupported YANG constructs.
317 + *
318 + * @param yangConstructType yang construct for creating error message
319 + * @param ctx yang construct's context to get the line number and character position
320 + * @param errorInfo error information
321 + */
322 + public static void handleUnsupportedYangConstruct(YangConstructType yangConstructType,
323 + ParserRuleContext ctx, String errorInfo) {
324 + ParserException parserException = new ParserException(YANG_FILE_ERROR
325 + + QUOTES + YangConstructType.getYangConstructType(yangConstructType) + QUOTES
326 + + errorInfo);
327 + parserException.setLine(ctx.getStart().getLine());
328 + parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
329 + throw parserException;
330 + }
275 } 331 }
...\ No newline at end of file ...\ No newline at end of file
......
1 +/*
2 + * Copyright 2016-present 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 + */
16 +
17 +package org.onosproject.yangutils.plugin.manager;
18 +
19 +import org.onosproject.yangutils.datamodel.YangNode;
20 +
21 +/**
22 + * Represents YANG file information.
23 + */
24 +public class YangFileInfo {
25 +
26 + /**
27 + * YANG file name.
28 + */
29 + private String yangFileName;
30 +
31 + /**
32 + * Data model node after parsing YANG file.
33 + */
34 + private YangNode rootNode;
35 +
36 + /**
37 + * Returns data model node for YANG file.
38 + *
39 + * @return data model node for YANG file
40 + */
41 + public YangNode getRootNode() {
42 + return rootNode;
43 + }
44 +
45 + /**
46 + * Sets data model node for YANG file.
47 + *
48 + * @param rootNode of the Yang file
49 + */
50 + public void setRootNode(YangNode rootNode) {
51 + this.rootNode = rootNode;
52 + }
53 +
54 + /**
55 + * Returns YANG file name.
56 + *
57 + * @return yangFileName YANG file name
58 + */
59 + public String getYangFileName() {
60 + return yangFileName;
61 + }
62 +
63 + /**
64 + * Sets YANG file name.
65 + *
66 + * @param yangFileName YANG file name
67 + */
68 + public void setYangFileName(String yangFileName) {
69 + this.yangFileName = yangFileName;
70 + }
71 +}
...@@ -28,6 +28,8 @@ import org.apache.maven.plugins.annotations.Mojo; ...@@ -28,6 +28,8 @@ import org.apache.maven.plugins.annotations.Mojo;
28 import org.apache.maven.plugins.annotations.Parameter; 28 import org.apache.maven.plugins.annotations.Parameter;
29 import org.apache.maven.project.MavenProject; 29 import org.apache.maven.project.MavenProject;
30 import org.onosproject.yangutils.datamodel.YangNode; 30 import org.onosproject.yangutils.datamodel.YangNode;
31 +import org.onosproject.yangutils.datamodel.YangSubModule;
32 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
31 import org.onosproject.yangutils.parser.YangUtilsParser; 33 import org.onosproject.yangutils.parser.YangUtilsParser;
32 import org.onosproject.yangutils.parser.exceptions.ParserException; 34 import org.onosproject.yangutils.parser.exceptions.ParserException;
33 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 35 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
...@@ -49,6 +51,7 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource; ...@@ -49,6 +51,7 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource;
49 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory; 51 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
50 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget; 52 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget;
51 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory; 53 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory;
54 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findBelongsToModuleNode;
52 55
53 /** 56 /**
54 * Represents ONOS YANG utility maven plugin. 57 * Represents ONOS YANG utility maven plugin.
...@@ -137,17 +140,22 @@ public class YangUtilManager extends AbstractMojo { ...@@ -137,17 +140,22 @@ public class YangUtilManager extends AbstractMojo {
137 conflictResolver.setReplacementForPeriod(replacementForPeriod); 140 conflictResolver.setReplacementForPeriod(replacementForPeriod);
138 conflictResolver.setReplacementForHyphen(replacementForHyphen); 141 conflictResolver.setReplacementForHyphen(replacementForHyphen);
139 conflictResolver.setReplacementForUnderscore(replacementForUnderscore); 142 conflictResolver.setReplacementForUnderscore(replacementForUnderscore);
140 - List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); 143 + List<YangFileInfo> yangFileInfo = YangFileScanner.getYangFiles(searchDir);
144 + if (yangFileInfo == null || yangFileInfo.isEmpty()) {
145 + // no files to translate
146 + return;
147 + }
141 YangPluginConfig yangPlugin = new YangPluginConfig(); 148 YangPluginConfig yangPlugin = new YangPluginConfig();
142 yangPlugin.setCodeGenDir(codeGenDir); 149 yangPlugin.setCodeGenDir(codeGenDir);
143 yangPlugin.setConflictResolver(conflictResolver); 150 yangPlugin.setConflictResolver(conflictResolver);
144 - Iterator<String> yangFileIterator = yangFiles.iterator(); 151 +
152 + Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
145 while (yangFileIterator.hasNext()) { 153 while (yangFileIterator.hasNext()) {
146 - String yangFile = yangFileIterator.next(); 154 + YangFileInfo yangFile = yangFileIterator.next();
147 try { 155 try {
148 - YangNode yangNode = yangUtilsParser.getDataModel(yangFile); 156 + YangNode yangNode = yangUtilsParser.getDataModel(yangFile.getYangFileName());
157 + yangFile.setRootNode(yangNode);
149 setRootNode(yangNode); 158 setRootNode(yangNode);
150 - generateJavaCode(yangNode, yangPlugin, yangFile);
151 } catch (ParserException e) { 159 } catch (ParserException e) {
152 String logInfo = "Error in file: " + e.getFileName(); 160 String logInfo = "Error in file: " + e.getFileName();
153 if (e.getLineNumber() != 0) { 161 if (e.getLineNumber() != 0) {
...@@ -163,8 +171,12 @@ public class YangUtilManager extends AbstractMojo { ...@@ -163,8 +171,12 @@ public class YangUtilManager extends AbstractMojo {
163 } 171 }
164 } 172 }
165 173
174 + resolveLinkingForSubModule(yangFileInfo);
175 +
176 + translateToJava(yangFileInfo, yangPlugin);
177 +
166 addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context); 178 addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context);
167 - copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project); 179 + copyYangFilesToTarget(yangFileInfo, getDirectory(baseDir, outputDirectory), project);
168 } catch (Exception e) { 180 } catch (Exception e) {
169 String fileName = ""; 181 String fileName = "";
170 if (e instanceof TranslatorException) { 182 if (e instanceof TranslatorException) {
...@@ -220,4 +232,40 @@ public class YangUtilManager extends AbstractMojo { ...@@ -220,4 +232,40 @@ public class YangUtilManager extends AbstractMojo {
220 this.rootNode = rootNode; 232 this.rootNode = rootNode;
221 } 233 }
222 234
235 + /**
236 + * Translates to java code corresponding to the YANG schema.
237 + *
238 + * @param yangFileInfo YANG file information
239 + * @param yangPlugin YANG plugin config
240 + * @throws IOException when fails to generate java code file the current
241 + * node
242 + */
243 + public static void translateToJava(List<YangFileInfo> yangFileInfo, YangPluginConfig yangPlugin)
244 + throws IOException {
245 + Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
246 + while (yangFileIterator.hasNext()) {
247 + YangFileInfo yangFile = yangFileIterator.next();
248 + generateJavaCode(yangFile.getRootNode(), yangPlugin, yangFile.getYangFileName());
249 + }
250 + }
251 +
252 + /**
253 + * Resolves sub-module linking.
254 + *
255 + * @param yangFileInfo YANG file information
256 + * @throws DataModelException when belongs-to module node is not found
257 + */
258 + public static void resolveLinkingForSubModule(List<YangFileInfo> yangFileInfo) throws DataModelException {
259 + Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
260 + while (yangFileIterator.hasNext()) {
261 + YangFileInfo yangFile = yangFileIterator.next();
262 + YangNode yangNode = yangFile.getRootNode();
263 + if (yangNode instanceof YangSubModule) {
264 + String belongsToModuleName = ((YangSubModule) yangNode).getBelongsTo()
265 + .getBelongsToModuleName();
266 + YangNode moduleNode = findBelongsToModuleNode(yangFileInfo, belongsToModuleName);
267 + ((YangSubModule) yangNode).getBelongsTo().setModuleNode(moduleNode);
268 + }
269 + }
270 + }
223 } 271 }
......
...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; ...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
18 import java.io.IOException; 18 import java.io.IOException;
19 19
20 import org.onosproject.yangutils.datamodel.YangBelongsTo; 20 import org.onosproject.yangutils.datamodel.YangBelongsTo;
21 +import org.onosproject.yangutils.datamodel.YangModule;
21 import org.onosproject.yangutils.datamodel.YangSubModule; 22 import org.onosproject.yangutils.datamodel.YangSubModule;
22 import org.onosproject.yangutils.translator.exception.TranslatorException; 23 import org.onosproject.yangutils.translator.exception.TranslatorException;
23 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; 24 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
...@@ -108,8 +109,7 @@ public class YangJavaSubModule ...@@ -108,8 +109,7 @@ public class YangJavaSubModule
108 * @return the name space string of the module. 109 * @return the name space string of the module.
109 */ 110 */
110 private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) { 111 private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
111 - // TODO Auto-generated method stub 112 + return ((YangModule) belongsToInfo.getModuleNode()).getNameSpace().getUri();
112 - return "";
113 } 113 }
114 114
115 /** 115 /**
......
...@@ -257,6 +257,16 @@ public final class UtilConstants { ...@@ -257,6 +257,16 @@ public final class UtilConstants {
257 public static final String LISTENER_PKG = "org.onosproject.event"; 257 public static final String LISTENER_PKG = "org.onosproject.event";
258 258
259 /** 259 /**
260 + * Static attribute for colon.
261 + */
262 + public static final String COLON = ":";
263 +
264 + /**
265 + * Static attribute for caret.
266 + */
267 + public static final String CARET = "^";
268 +
269 + /**
260 * Static attribute for input string. 270 * Static attribute for input string.
261 */ 271 */
262 public static final String INPUT = "input"; 272 public static final String INPUT = "input";
...@@ -932,6 +942,22 @@ public final class UtilConstants { ...@@ -932,6 +942,22 @@ public final class UtilConstants {
932 public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code"; 942 public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
933 943
934 /** 944 /**
945 + * Static attribute for YANG file error.
946 + */
947 + public static final String YANG_FILE_ERROR = "YANG file error : ";
948 +
949 + /**
950 + * Static attribute for unsupported error information.
951 + */
952 + public static final String UNSUPPORTED_YANG_CONSTRUCT = " is not supported.";
953 +
954 + /**
955 + * Static attribute for currently unsupported error information.
956 + */
957 + public static final String CURRENTLY_UNSUPPORTED = " is not supported in current version, please check wiki" +
958 + " for YANG utils road map.";
959 +
960 + /**
935 * Creates an instance of util constants. 961 * Creates an instance of util constants.
936 */ 962 */
937 private UtilConstants() { 963 private UtilConstants() {
......
...@@ -287,7 +287,77 @@ public enum YangConstructType { ...@@ -287,7 +287,77 @@ public enum YangConstructType {
287 /** 287 /**
288 * Identifies the YANG pattern element parsed data. 288 * Identifies the YANG pattern element parsed data.
289 */ 289 */
290 - PATTERN_DATA; 290 + PATTERN_DATA,
291 +
292 + /**
293 + * Identifies the YANG extension element parsed data.
294 + */
295 + EXTENSION_DATA,
296 +
297 + /**
298 + * Identifies the YANG identity element parsed data.
299 + */
300 + IDENTITY_DATA,
301 +
302 + /**
303 + * Identifies the YANG base element parsed data.
304 + */
305 + BASE_DATA,
306 +
307 + /**
308 + * Identifies the YANG feature element parsed data.
309 + */
310 + FEATURE_DATA,
311 +
312 + /**
313 + * Identifies the YANG if-feature element parsed data.
314 + */
315 + IF_FEATURE_DATA,
316 +
317 + /**
318 + * Identifies the YANG path element parsed data.
319 + */
320 + PATH_DATA,
321 +
322 + /**
323 + * Identifies the YANG require-instance element parsed data.
324 + */
325 + REQUIRE_INSTANCE_DATA,
326 +
327 + /**
328 + * Identifies the YANG ordered-by element parsed data.
329 + */
330 + ORDERED_BY_DATA,
331 +
332 + /**
333 + * Identifies the YANG error-message element parsed data.
334 + */
335 + ERROR_MESSAGE_DATA,
336 +
337 + /**
338 + * Identifies the YANG error-app-tag element parsed data.
339 + */
340 + ERROR_APP_TAG_DATA,
341 +
342 + /**
343 + * Identifies the YANG unique element parsed data.
344 + */
345 + UNIQUE_DATA,
346 +
347 + /**
348 + * Identifies the YANG refine element parsed data.
349 + */
350 + REFINE_DATA,
351 +
352 + /**
353 + * Identifies the YANG deviation element parsed data.
354 + */
355 + DEVIATION_DATA,
356 +
357 + /**
358 + * Identifies the YANG anyxml element parsed data.
359 + */
360 + ANYXML_DATA;
291 361
292 /** 362 /**
293 * Returns the YANG construct keyword corresponding to enum values. 363 * Returns the YANG construct keyword corresponding to enum values.
...@@ -406,6 +476,34 @@ public enum YangConstructType { ...@@ -406,6 +476,34 @@ public enum YangConstructType {
406 return "length"; 476 return "length";
407 case PATTERN_DATA: 477 case PATTERN_DATA:
408 return "pattern"; 478 return "pattern";
479 + case EXTENSION_DATA:
480 + return "extension";
481 + case IDENTITY_DATA:
482 + return "identity";
483 + case BASE_DATA:
484 + return "base";
485 + case FEATURE_DATA:
486 + return "feature";
487 + case IF_FEATURE_DATA:
488 + return "if-feature";
489 + case PATH_DATA:
490 + return "path";
491 + case REQUIRE_INSTANCE_DATA:
492 + return "require-instance";
493 + case ORDERED_BY_DATA:
494 + return "ordered-by";
495 + case ERROR_MESSAGE_DATA:
496 + return "error-message";
497 + case ERROR_APP_TAG_DATA:
498 + return "error-app-tag";
499 + case UNIQUE_DATA:
500 + return "unique";
501 + case REFINE_DATA:
502 + return "refine";
503 + case DEVIATION_DATA:
504 + return "deviation";
505 + case ANYXML_DATA:
506 + return "anyxml";
409 default: 507 default:
410 return "yang"; 508 return "yang";
411 } 509 }
......
...@@ -21,6 +21,7 @@ import java.io.IOException; ...@@ -21,6 +21,7 @@ import java.io.IOException;
21 import java.util.LinkedList; 21 import java.util.LinkedList;
22 import java.util.List; 22 import java.util.List;
23 import java.util.Stack; 23 import java.util.Stack;
24 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
24 25
25 /** 26 /**
26 * Represents utility for searching the files in a directory. 27 * Represents utility for searching the files in a directory.
...@@ -51,17 +52,23 @@ public final class YangFileScanner { ...@@ -51,17 +52,23 @@ public final class YangFileScanner {
51 } 52 }
52 53
53 /** 54 /**
54 - * Returns the list of YANG files. 55 + * Returns the list of YANG file information.
55 * 56 *
56 * @param root specified directory 57 * @param root specified directory
57 - * @return list of YANG files 58 + * @return list of YANG file information
58 * @throws NullPointerException when no files are there 59 * @throws NullPointerException when no files are there
59 * @throws IOException when files get deleted while performing the 60 * @throws IOException when files get deleted while performing the
60 * operations 61 * operations
61 */ 62 */
62 - public static List<String> getYangFiles(String root) throws IOException { 63 + public static List<YangFileInfo> getYangFiles(String root) throws IOException {
63 - 64 + List<String> yangFiles = getFiles(root, YANG_FILE_EXTENTION);
64 - return getFiles(root, YANG_FILE_EXTENTION); 65 + List<YangFileInfo> fileInfo = new LinkedList<>();
66 + for (String yangFile : yangFiles) {
67 + YangFileInfo yangFileInfo = new YangFileInfo();
68 + yangFileInfo.setYangFileName(yangFile);
69 + fileInfo.add(yangFileInfo);
70 + }
71 + return fileInfo;
65 } 72 }
66 73
67 /** 74 /**
......
...@@ -24,6 +24,7 @@ import java.nio.file.Files; ...@@ -24,6 +24,7 @@ import java.nio.file.Files;
24 import java.nio.file.StandardCopyOption; 24 import java.nio.file.StandardCopyOption;
25 import java.util.ArrayList; 25 import java.util.ArrayList;
26 import java.util.LinkedList; 26 import java.util.LinkedList;
27 +import java.util.Iterator;
27 import java.util.List; 28 import java.util.List;
28 import java.util.Stack; 29 import java.util.Stack;
29 30
...@@ -33,6 +34,7 @@ import org.apache.maven.project.MavenProject; ...@@ -33,6 +34,7 @@ import org.apache.maven.project.MavenProject;
33 import org.slf4j.Logger; 34 import org.slf4j.Logger;
34 import org.sonatype.plexus.build.incremental.BuildContext; 35 import org.sonatype.plexus.build.incremental.BuildContext;
35 36
37 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
36 import static org.onosproject.yangutils.utils.UtilConstants.COMMA; 38 import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
37 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 39 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
38 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 40 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
...@@ -245,15 +247,15 @@ public final class YangIoUtils { ...@@ -245,15 +247,15 @@ public final class YangIoUtils {
245 /** 247 /**
246 * Copies YANG files to the current project's output directory. 248 * Copies YANG files to the current project's output directory.
247 * 249 *
248 - * @param yangFiles list of YANG files 250 + * @param yangFileInfo list of YANG files
249 * @param outputDir project's output directory 251 * @param outputDir project's output directory
250 * @param project maven project 252 * @param project maven project
251 * @throws IOException when fails to copy files to destination resource directory 253 * @throws IOException when fails to copy files to destination resource directory
252 */ 254 */
253 - public static void copyYangFilesToTarget(List<String> yangFiles, String outputDir, MavenProject project) 255 + public static void copyYangFilesToTarget(List<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
254 throws IOException { 256 throws IOException {
255 257
256 - List<File> files = getListOfFile(yangFiles); 258 + List<File> files = getListOfFile(yangFileInfo);
257 259
258 String path = outputDir + TARGET_RESOURCE_PATH; 260 String path = outputDir + TARGET_RESOURCE_PATH;
259 File targetDir = new File(path); 261 File targetDir = new File(path);
...@@ -272,13 +274,15 @@ public final class YangIoUtils { ...@@ -272,13 +274,15 @@ public final class YangIoUtils {
272 /** 274 /**
273 * Provides a list of files from list of strings. 275 * Provides a list of files from list of strings.
274 * 276 *
275 - * @param strings list of strings 277 + * @param yangFileInfo list of yang file information
276 * @return list of files 278 * @return list of files
277 */ 279 */
278 - private static List<File> getListOfFile(List<String> strings) { 280 + private static List<File> getListOfFile(List<YangFileInfo> yangFileInfo) {
279 List<File> files = new ArrayList<>(); 281 List<File> files = new ArrayList<>();
280 - for (String file : strings) { 282 + Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
281 - files.add(new File(file)); 283 + while (yangFileIterator.hasNext()) {
284 + YangFileInfo yangFile = yangFileIterator.next();
285 + files.add(new File(yangFile.getYangFileName()));
282 } 286 }
283 return files; 287 return files;
284 } 288 }
......
...@@ -380,6 +380,7 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -380,6 +380,7 @@ package org.onosproject.yangutils.parser.antlrgencode;
380 | leafListStatement 380 | leafListStatement
381 | listStatement 381 | listStatement
382 | choiceStatement 382 | choiceStatement
383 + | anyxmlStatement
383 | usesStatement; 384 | usesStatement;
384 385
385 /** 386 /**
...@@ -429,13 +430,26 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -429,13 +430,26 @@ package org.onosproject.yangutils.parser.antlrgencode;
429 * instance-identifier-specification / 430 * instance-identifier-specification /
430 * bits-specification / 431 * bits-specification /
431 * union-specification 432 * union-specification
432 - * TODO : decimal64-specification to be added 433 + *
433 */ 434 */
434 - typeBodyStatements : numericalRestrictions | stringRestrictions | enumSpecification 435 + typeBodyStatements : numericalRestrictions | decimal64Specification | stringRestrictions | enumSpecification
435 | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification 436 | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
436 | bitsSpecification | unionSpecification; 437 | bitsSpecification | unionSpecification;
437 438
438 /** 439 /**
440 + * fraction-digits-stmt = fraction-digits-keyword sep
441 + * fraction-digits-arg-str stmtend
442 + *
443 + * fraction-digits-arg-str = < a string that matches the rule
444 + * fraction-digits-arg >
445 + *
446 + * fraction-digits-arg = ("1" ["0" / "1" / "2" / "3" / "4" /
447 + * "5" / "6" / "7" / "8"])
448 + * / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
449 + */
450 + decimal64Specification : FRACTION_DIGITS_KEYWORD fraction STMTEND;
451 +
452 + /**
439 * numerical-restrictions = range-stmt stmtsep 453 * numerical-restrictions = range-stmt stmtsep
440 */ 454 */
441 numericalRestrictions : rangeStatement; 455 numericalRestrictions : rangeStatement;
...@@ -746,7 +760,7 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -746,7 +760,7 @@ package org.onosproject.yangutils.parser.antlrgencode;
746 /** 760 /**
747 * value-stmt = value-keyword sep integer-value stmtend 761 * value-stmt = value-keyword sep integer-value stmtend
748 */ 762 */
749 - valueStatement : VALUE_KEYWORD ((MINUS INTEGER) | INTEGER) STMTEND; 763 + valueStatement : VALUE_KEYWORD value STMTEND;
750 764
751 /** 765 /**
752 * grouping-stmt = grouping-keyword sep identifier-arg-str optsep 766 * grouping-stmt = grouping-keyword sep identifier-arg-str optsep
...@@ -899,7 +913,7 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -899,7 +913,7 @@ package org.onosproject.yangutils.parser.antlrgencode;
899 * list-stmt / 913 * list-stmt /
900 * anyxml-stmt 914 * anyxml-stmt
901 */ 915 */
902 - shortCaseStatement : containerStatement | leafStatement | leafListStatement | listStatement; 916 + shortCaseStatement : containerStatement | leafStatement | leafListStatement | listStatement | anyxmlStatement;
903 917
904 /** 918 /**
905 * case-stmt = case-keyword sep identifier-arg-str optsep 919 * case-stmt = case-keyword sep identifier-arg-str optsep
...@@ -919,6 +933,25 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -919,6 +933,25 @@ package org.onosproject.yangutils.parser.antlrgencode;
919 | descriptionStatement | referenceStatement | dataDefStatement)* RIGHT_CURLY_BRACE); 933 | descriptionStatement | referenceStatement | dataDefStatement)* RIGHT_CURLY_BRACE);
920 934
921 /** 935 /**
936 + * anyxml-stmt = anyxml-keyword sep identifier-arg-str optsep
937 + * (";" /
938 + * "{" stmtsep
939 + * ;; these stmts can appear in any order
940 + * [when-stmt stmtsep]
941 + * *(if-feature-stmt stmtsep)
942 + * *(must-stmt stmtsep)
943 + * [config-stmt stmtsep]
944 + * [mandatory-stmt stmtsep]
945 + * [status-stmt stmtsep]
946 + * [description-stmt stmtsep]
947 + * [reference-stmt stmtsep]
948 + * "}")
949 + */
950 + anyxmlStatement : ANYXML_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement
951 + | mustStatement | configStatement | mandatoryStatement | statusStatement | descriptionStatement
952 + | referenceStatement)* RIGHT_CURLY_BRACE);
953 +
954 + /**
922 * uses-stmt = uses-keyword sep identifier-ref-arg-str optsep 955 * uses-stmt = uses-keyword sep identifier-ref-arg-str optsep
923 * (";" / 956 * (";" /
924 * "{" stmtsep 957 * "{" stmtsep
...@@ -934,7 +967,7 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -934,7 +967,7 @@ package org.onosproject.yangutils.parser.antlrgencode;
934 * TODO : 0..1 occurance to be checked in listener 967 * TODO : 0..1 occurance to be checked in listener
935 */ 968 */
936 usesStatement : USES_KEYWORD string (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | statusStatement 969 usesStatement : USES_KEYWORD string (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | statusStatement
937 - | descriptionStatement | referenceStatement | refineStatement | usesAugmentStatement)* RIGHT_CURLY_BRACE); 970 + | descriptionStatement | referenceStatement | refineStatement | augmentStatement)* RIGHT_CURLY_BRACE);
938 971
939 /** 972 /**
940 * refine-stmt = refine-keyword sep refine-arg-str optsep 973 * refine-stmt = refine-keyword sep refine-arg-str optsep
...@@ -951,7 +984,7 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -951,7 +984,7 @@ package org.onosproject.yangutils.parser.antlrgencode;
951 */ 984 */
952 refineStatement : REFINE_KEYWORD refine (STMTEND | LEFT_CURLY_BRACE (refineContainerStatements 985 refineStatement : REFINE_KEYWORD refine (STMTEND | LEFT_CURLY_BRACE (refineContainerStatements
953 | refineLeafStatements | refineLeafListStatements | refineListStatements | refineChoiceStatements 986 | refineLeafStatements | refineLeafListStatements | refineListStatements | refineChoiceStatements
954 - | refineCaseStatements) RIGHT_CURLY_BRACE); 987 + | refineCaseStatements | refineAnyxmlStatements) RIGHT_CURLY_BRACE);
955 988
956 /** 989 /**
957 * refine-container-stmts = 990 * refine-container-stmts =
...@@ -1024,22 +1057,15 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -1024,22 +1057,15 @@ package org.onosproject.yangutils.parser.antlrgencode;
1024 refineCaseStatements : (descriptionStatement | referenceStatement)? | (referenceStatement | descriptionStatement)?; 1057 refineCaseStatements : (descriptionStatement | referenceStatement)? | (referenceStatement | descriptionStatement)?;
1025 1058
1026 /** 1059 /**
1027 - * uses-augment-stmt = augment-keyword sep uses-augment-arg-str optsep 1060 + * refine-anyxml-stmts = ;; these stmts can appear in any order
1028 - * "{" stmtsep 1061 + * *(must-stmt stmtsep)
1029 - * ;; these stmts can appear in any order 1062 + * [config-stmt stmtsep]
1030 - * [when-stmt stmtsep] 1063 + * [mandatory-stmt stmtsep]
1031 - * *(if-feature-stmt stmtsep)
1032 - * [status-stmt stmtsep]
1033 * [description-stmt stmtsep] 1064 * [description-stmt stmtsep]
1034 * [reference-stmt stmtsep] 1065 * [reference-stmt stmtsep]
1035 - * 1*((data-def-stmt stmtsep) /
1036 - * (case-stmt stmtsep))
1037 - * "}"
1038 - * TODO : 0..1 occurance to be checked in listener
1039 */ 1066 */
1040 - usesAugmentStatement : AUGMENT_KEYWORD augment LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement 1067 + refineAnyxmlStatements : (mustStatement | configStatement | mandatoryStatement | descriptionStatement
1041 - | statusStatement | descriptionStatement | referenceStatement | dataDefStatement 1068 + | referenceStatement)*;
1042 - | caseStatement)* RIGHT_CURLY_BRACE;
1043 1069
1044 /** 1070 /**
1045 * augment-stmt = augment-keyword sep augment-arg-str optsep 1071 * augment-stmt = augment-keyword sep augment-arg-str optsep
...@@ -1251,6 +1277,10 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -1251,6 +1277,10 @@ package org.onosproject.yangutils.parser.antlrgencode;
1251 1277
1252 deviation : string; 1278 deviation : string;
1253 1279
1280 + value : string;
1281 +
1282 + fraction : string;
1283 +
1254 yangConstruct : ANYXML_KEYWORD | ARGUMENT_KEYWORD | AUGMENT_KEYWORD | BASE_KEYWORD | BELONGS_TO_KEYWORD 1284 yangConstruct : ANYXML_KEYWORD | ARGUMENT_KEYWORD | AUGMENT_KEYWORD | BASE_KEYWORD | BELONGS_TO_KEYWORD
1255 | BIT_KEYWORD | CASE_KEYWORD | CHOICE_KEYWORD | CONFIG_KEYWORD | CONTACT_KEYWORD | CONTAINER_KEYWORD 1285 | BIT_KEYWORD | CASE_KEYWORD | CHOICE_KEYWORD | CONFIG_KEYWORD | CONTACT_KEYWORD | CONTAINER_KEYWORD
1256 | DEFAULT_KEYWORD | DESCRIPTION_KEYWORD | ENUM_KEYWORD ERROR_APP_TAG_KEYWORD | ERROR_MESSAGE_KEYWORD 1286 | DEFAULT_KEYWORD | DESCRIPTION_KEYWORD | ENUM_KEYWORD ERROR_APP_TAG_KEYWORD | ERROR_MESSAGE_KEYWORD
......
1 +/*
2 + * Copyright 2016-present 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 + */
16 +
17 +package org.onosproject.yangutils.parser.impl;
18 +
19 +import java.io.IOException;
20 +
21 +import org.junit.Rule;
22 +import org.junit.Test;
23 +import org.junit.rules.ExpectedException;
24 +import org.onosproject.yangutils.parser.exceptions.ParserException;
25 +
26 +/**
27 + * Test cases for testing tree walk listener functionality.
28 + */
29 +public class TreeWalkListenerTest {
30 +
31 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
32 +
33 + @Rule
34 + public ExpectedException thrown = ExpectedException.none();
35 + /**
36 + * Checks whether exception is thrown for ordered statement.
37 + */
38 + @Test
39 + public void processOrderedByStatement() throws IOException, ParserException {
40 + thrown.expect(ParserException.class);
41 + thrown.expectMessage("YANG file error : \"ordered-by\" is not supported in current version, please check wiki" +
42 + " for YANG utils road map.");
43 + manager.getDataModel("src/test/resources/OrderedByStatement.yang");
44 + }
45 +
46 + /**
47 + * Checks whether exception is thrown for anyxml statement.
48 + */
49 + @Test
50 + public void processAnyXmlStatement() throws IOException, ParserException {
51 + thrown.expect(ParserException.class);
52 + thrown.expectMessage("YANG file error : \"anyxml\" is not supported.");
53 + manager.getDataModel("src/test/resources/AnyxmlStatement.yang");
54 + }
55 +}
...@@ -134,9 +134,9 @@ public class ConfigListenerTest { ...@@ -134,9 +134,9 @@ public class ConfigListenerTest {
134 @Test 134 @Test
135 public void processModuleSubStatementConfig() throws IOException, ParserException { 135 public void processModuleSubStatementConfig() throws IOException, ParserException {
136 thrown.expect(ParserException.class); 136 thrown.expect(ParserException.class);
137 - thrown.expectMessage("mismatched input 'config' expecting {'augment', 'choice', 'contact', 'container'," 137 + thrown.expectMessage("mismatched input 'config' expecting {'anyxml', 'augment', 'choice', 'contact', "
138 - + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include', " 138 + + "'container', 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import',"
139 - + "'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference'," 139 + + " 'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference',"
140 + " 'revision', 'rpc', 'typedef', 'uses', '}'}"); 140 + " 'revision', 'rpc', 'typedef', 'uses', '}'}");
141 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementConfig.yang"); 141 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementConfig.yang");
142 } 142 }
......
1 +/*
2 + * Copyright 2016-present 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 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import java.io.IOException;
20 +import java.util.ListIterator;
21 +
22 +import org.junit.Test;
23 +import org.onosproject.yangutils.datamodel.YangNode;
24 +import org.onosproject.yangutils.datamodel.YangModule;
25 +import org.onosproject.yangutils.datamodel.YangLeaf;
26 +import org.onosproject.yangutils.datamodel.YangChoice;
27 +import org.onosproject.yangutils.datamodel.YangContainer;
28 +import org.onosproject.yangutils.datamodel.YangNodeType;
29 +import org.onosproject.yangutils.parser.exceptions.ParserException;
30 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
31 +
32 +import static org.hamcrest.core.Is.is;
33 +import static org.junit.Assert.assertThat;
34 +
35 +/**
36 + * Test cases for testing default listener functionality.
37 + */
38 +public class DefaultListenerTest {
39 +
40 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
41 +
42 + /**
43 + * Checks if default value is set correctly.
44 + */
45 + @Test
46 + public void processLeafSubStatementDefault() throws IOException, ParserException {
47 +
48 + YangNode node = manager.getDataModel("src/test/resources/LeafSubStatementDefault.yang");
49 + // Check whether the data model tree returned is of type module.
50 + assertThat((node instanceof YangModule), is(true));
51 +
52 + // Check whether the node type is set properly to module.
53 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
54 +
55 + // Check whether the module name is set correctly.
56 + YangModule yangNode = (YangModule) node;
57 + assertThat(yangNode.getName(), is("Test"));
58 +
59 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
60 + YangLeaf leafInfo = leafIterator.next();
61 +
62 + assertThat(leafInfo.getName(), is("invalid-interval"));
63 + assertThat(leafInfo.getDefaultValueInString(), is("\"1\""));
64 + }
65 +
66 + /**
67 + * Checks if default value is set correctly.
68 + */
69 + @Test
70 + public void processChoiceSubStatementDefault() throws IOException, ParserException {
71 +
72 + YangNode node = manager.getDataModel("src/test/resources/ChoiceSubStatementDefault.yang");
73 + // Check whether the data model tree returned is of type module.
74 + assertThat((node instanceof YangModule), is(true));
75 +
76 + // Check whether the node type is set properly to module.
77 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
78 +
79 + // Check whether the module name is set correctly.
80 + YangModule yangNode = (YangModule) node;
81 + assertThat(yangNode.getName(), is("Test"));
82 +
83 + YangContainer yangContainer = (YangContainer) yangNode.getChild();
84 + assertThat(yangContainer.getName(), is("food"));
85 +
86 + YangChoice yangChoice = (YangChoice) yangContainer.getChild();
87 + assertThat(yangChoice.getName(), is("snack"));
88 + assertThat(yangChoice.getDefaultValueInString(), is("\"hello\""));
89 + }
90 +}
...@@ -18,7 +18,10 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -18,7 +18,10 @@ package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 import static org.hamcrest.MatcherAssert.assertThat; 19 import static org.hamcrest.MatcherAssert.assertThat;
20 import static org.hamcrest.core.Is.is; 20 import static org.hamcrest.core.Is.is;
21 +
22 +import org.junit.Rule;
21 import org.junit.Test; 23 import org.junit.Test;
24 +import org.junit.rules.ExpectedException;
22 import org.onosproject.yangutils.datamodel.YangDataTypes; 25 import org.onosproject.yangutils.datamodel.YangDataTypes;
23 import org.onosproject.yangutils.datamodel.YangEnum; 26 import org.onosproject.yangutils.datamodel.YangEnum;
24 import org.onosproject.yangutils.datamodel.YangEnumeration; 27 import org.onosproject.yangutils.datamodel.YangEnumeration;
...@@ -38,6 +41,9 @@ import java.util.Set; ...@@ -38,6 +41,9 @@ import java.util.Set;
38 */ 41 */
39 public class EnumListenerTest { 42 public class EnumListenerTest {
40 43
44 + @Rule
45 + public ExpectedException thrown = ExpectedException.none();
46 +
41 private final YangUtilsParserManager manager = new YangUtilsParserManager(); 47 private final YangUtilsParserManager manager = new YangUtilsParserManager();
42 48
43 /** 49 /**
...@@ -84,7 +90,28 @@ public class EnumListenerTest { ...@@ -84,7 +90,28 @@ public class EnumListenerTest {
84 */ 90 */
85 @Test(expected = ParserException.class) 91 @Test(expected = ParserException.class)
86 public void processEnumWithDuplicateName() throws IOException, ParserException { 92 public void processEnumWithDuplicateName() throws IOException, ParserException {
87 -
88 YangNode node = manager.getDataModel("src/test/resources/EnumWithDuplicateName.yang"); 93 YangNode node = manager.getDataModel("src/test/resources/EnumWithDuplicateName.yang");
89 } 94 }
95 +
96 + /**
97 + * Checks enum boundary value.
98 + */
99 + @Test
100 + public void processEnumBoundaryValue() throws IOException, ParserException {
101 + thrown.expect(ParserException.class);
102 + thrown.expectMessage("YANG file error : value value 21474836472147483647 is not valid.");
103 + YangNode node = manager.getDataModel("src/test/resources/EnumBoundaryValue.yang");
104 + }
105 +
106 + /**
107 + * Checks whether exception is thrown if value is not specified following max enum value.
108 + */
109 + @Test
110 + public void processEnumMaxNextValue() throws IOException, ParserException {
111 + thrown.expect(ParserException.class);
112 + thrown.expectMessage("YANG file error : "
113 + + "An enum value MUST be specified for enum substatements following the one"
114 + + "with the current highest value");
115 + YangNode node = manager.getDataModel("src/test/resources/EnumMaxNextValue.yang");
116 + }
90 } 117 }
......
...@@ -203,12 +203,32 @@ public class KeyListenerTest { ...@@ -203,12 +203,32 @@ public class KeyListenerTest {
203 } 203 }
204 204
205 /** 205 /**
206 + * Checks key values are set correctly.
207 + */
208 + @Test
209 + public void processKeyWithUsesInList() throws IOException, ParserException {
210 + YangNode node = manager.getDataModel("src/test/resources/KeyWithUsesInList.yang");
211 +
212 + assertThat((node instanceof YangModule), is(true));
213 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
214 + YangModule yangNode = (YangModule) node;
215 + assertThat(yangNode.getName(), is("Test"));
216 +
217 + // Check whether the list is child of module
218 + YangList yangList = (YangList) yangNode.getChild().getNextSibling();
219 + assertThat(yangList.getName(), is("valid"));
220 +
221 + ListIterator<String> keyList = yangList.getKeyList().listIterator();
222 + assertThat(keyList.next(), is("invalid-interval"));
223 + }
224 +
225 + /**
206 * Checks whether exception is thrown when key leaf identifier is not found in list. 226 * Checks whether exception is thrown when key leaf identifier is not found in list.
207 */ 227 */
208 @Test 228 @Test
209 public void processInvalidLeafIdentifier() throws IOException, ParserException { 229 public void processInvalidLeafIdentifier() throws IOException, ParserException {
210 thrown.expect(ParserException.class); 230 thrown.expect(ParserException.class);
211 - thrown.expectMessage("Leaf identifier must refer to a child leaf of the list"); 231 + thrown.expectMessage("An identifier, in key, must refer to a child leaf of the list");
212 YangNode node = manager.getDataModel("src/test/resources/InvalidLeafIdentifier.yang"); 232 YangNode node = manager.getDataModel("src/test/resources/InvalidLeafIdentifier.yang");
213 } 233 }
214 234
...@@ -218,7 +238,7 @@ public class KeyListenerTest { ...@@ -218,7 +238,7 @@ public class KeyListenerTest {
218 @Test 238 @Test
219 public void processInvalidLeafListIdentifier() throws IOException, ParserException { 239 public void processInvalidLeafListIdentifier() throws IOException, ParserException {
220 thrown.expect(ParserException.class); 240 thrown.expect(ParserException.class);
221 - thrown.expectMessage("Leaf-list identifier must refer to a child leaf of the list"); 241 + thrown.expectMessage("An identifier, in key, must refer to a child leaf of the list");
222 YangNode node = manager.getDataModel("src/test/resources/InvalidLeafListIdentifier.yang"); 242 YangNode node = manager.getDataModel("src/test/resources/InvalidLeafListIdentifier.yang");
223 } 243 }
224 244
......
...@@ -94,9 +94,9 @@ public class LeafListListenerTest { ...@@ -94,9 +94,9 @@ public class LeafListListenerTest {
94 @Test 94 @Test
95 public void processLeafListInvalidStatement() throws IOException, ParserException { 95 public void processLeafListInvalidStatement() throws IOException, ParserException {
96 thrown.expect(ParserException.class); 96 thrown.expect(ParserException.class);
97 - thrown.expectMessage("mismatched input 'leaflist' expecting {'augment', 'choice', 'contact', 'container'," 97 + thrown.expectMessage("mismatched input 'leaflist' expecting {'anyxml', 'augment', 'choice', 'contact', "
98 - + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," 98 + + "'container', 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import',"
99 - + " 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference'," 99 + + " 'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference',"
100 + " 'revision', 'rpc', 'typedef', 'uses', '}'}"); 100 + " 'revision', 'rpc', 'typedef', 'uses', '}'}");
101 YangNode node = manager.getDataModel("src/test/resources/LeafListInvalidStatement.yang"); 101 YangNode node = manager.getDataModel("src/test/resources/LeafListInvalidStatement.yang");
102 } 102 }
......
...@@ -95,9 +95,9 @@ public class LeafListenerTest { ...@@ -95,9 +95,9 @@ public class LeafListenerTest {
95 @Test 95 @Test
96 public void processLeafInvalidStatement() throws IOException, ParserException { 96 public void processLeafInvalidStatement() throws IOException, ParserException {
97 thrown.expect(ParserException.class); 97 thrown.expect(ParserException.class);
98 - thrown.expectMessage("mismatched input 'leafs' expecting {'augment', 'choice', 'contact', 'container'," 98 + thrown.expectMessage("mismatched input 'leafs' expecting {'anyxml', 'augment', 'choice', 'contact', "
99 - + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," 99 + + "'container', 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import',"
100 - + " 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference'," 100 + + " 'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference',"
101 + " 'revision', 'rpc', 'typedef', 'uses', '}'}"); 101 + " 'revision', 'rpc', 'typedef', 'uses', '}'}");
102 YangNode node = manager.getDataModel("src/test/resources/LeafInvalidStatement.yang"); 102 YangNode node = manager.getDataModel("src/test/resources/LeafInvalidStatement.yang");
103 } 103 }
......
...@@ -232,4 +232,39 @@ public class LengthRestrictionListenerTest { ...@@ -232,4 +232,39 @@ public class LengthRestrictionListenerTest {
232 " 18446744073709551615."); 232 " 18446744073709551615.");
233 YangNode node = manager.getDataModel("src/test/resources/LengthWithInvalidInterval.yang"); 233 YangNode node = manager.getDataModel("src/test/resources/LengthWithInvalidInterval.yang");
234 } 234 }
235 +
236 + /**
237 + * Checks valid length substatements.
238 + */
239 + @Test
240 + public void processLengthSubStatements() throws IOException, ParserException {
241 +
242 + YangNode node = manager.getDataModel("src/test/resources/LengthSubStatements.yang");
243 +
244 + assertThat((node instanceof YangModule), is(true));
245 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
246 + YangModule yangNode = (YangModule) node;
247 + assertThat(yangNode.getName(), is("Test"));
248 +
249 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
250 + YangLeaf leafInfo = leafIterator.next();
251 +
252 + assertThat(leafInfo.getName(), is("invalid-interval"));
253 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
254 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
255 + YangStringRestriction stringRestriction = (YangStringRestriction) leafInfo
256 + .getDataType().getDataTypeExtendedInfo();
257 + YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction();
258 +
259 + assertThat(lengthRestriction.getDescription(), is("\"length description\""));
260 + assertThat(lengthRestriction.getReference(), is("\"length reference\""));
261 +
262 + ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
263 + .listIterator();
264 +
265 + YangRangeInterval rangeInterval = lengthListIterator.next();
266 +
267 + assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0)));
268 + assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100)));
269 + }
235 } 270 }
......
...@@ -148,9 +148,9 @@ public class MandatoryListenerTest { ...@@ -148,9 +148,9 @@ public class MandatoryListenerTest {
148 @Test 148 @Test
149 public void processModuleSubStatementMandatory() throws IOException, ParserException { 149 public void processModuleSubStatementMandatory() throws IOException, ParserException {
150 thrown.expect(ParserException.class); 150 thrown.expect(ParserException.class);
151 - thrown.expectMessage("mismatched input 'mandatory' expecting {'augment', 'choice', 'contact', 'container'," 151 + thrown.expectMessage("mismatched input 'mandatory' expecting {'anyxml', 'augment', 'choice', 'contact',"
152 - + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," 152 + + " 'container', 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import',"
153 - + " 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference'," 153 + + " 'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference',"
154 + " 'revision', 'rpc', 'typedef', 'uses', '}'}"); 154 + " 'revision', 'rpc', 'typedef', 'uses', '}'}");
155 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementMandatory.yang"); 155 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementMandatory.yang");
156 } 156 }
......
...@@ -166,4 +166,32 @@ public class PatternRestrictionListenerTest { ...@@ -166,4 +166,32 @@ public class PatternRestrictionListenerTest {
166 .getPatternList().listIterator(); 166 .getPatternList().listIterator();
167 assertThat(patternListIterator.next(), is("-[0-9]+|[0-9]+")); 167 assertThat(patternListIterator.next(), is("-[0-9]+|[0-9]+"));
168 } 168 }
169 +
170 + /**
171 + * Checks valid pattern substatement.
172 + */
173 + @Test
174 + public void processPatternSubStatements() throws IOException, ParserException {
175 +
176 + YangNode node = manager.getDataModel("src/test/resources/PatternSubStatements.yang");
177 +
178 + assertThat((node instanceof YangModule), is(true));
179 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
180 + YangModule yangNode = (YangModule) node;
181 + assertThat(yangNode.getName(), is("Test"));
182 +
183 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
184 + YangLeaf leafInfo = leafIterator.next();
185 +
186 + assertThat(leafInfo.getName(), is("invalid-interval"));
187 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
188 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
189 + YangStringRestriction stringRestriction = (YangStringRestriction) leafInfo
190 + .getDataType().getDataTypeExtendedInfo();
191 + assertThat(stringRestriction.getDescription(), is("\"pattern description\""));
192 + assertThat(stringRestriction.getReference(), is("\"pattern reference\""));
193 + ListIterator<String> patternListIterator = stringRestriction.getPatternRestriction()
194 + .getPatternList().listIterator();
195 + assertThat(patternListIterator.next(), is("[a-zA-Z]"));
196 + }
169 } 197 }
......
...@@ -174,4 +174,37 @@ public class RangeRestrictionListenerTest { ...@@ -174,4 +174,37 @@ public class RangeRestrictionListenerTest {
174 thrown.expectMessage("YANG file error : Input value \"a\" is not a valid int32."); 174 thrown.expectMessage("YANG file error : Input value \"a\" is not a valid int32.");
175 YangNode node = manager.getDataModel("src/test/resources/RangeWithInvalidIntegerPattern.yang"); 175 YangNode node = manager.getDataModel("src/test/resources/RangeWithInvalidIntegerPattern.yang");
176 } 176 }
177 +
178 + /**
179 + * Checks valid range statement with description.
180 + */
181 + @Test
182 + public void processRangeSubStatements() throws IOException, ParserException {
183 +
184 + YangNode node = manager.getDataModel("src/test/resources/RangeSubStatements.yang");
185 +
186 + assertThat((node instanceof YangModule), is(true));
187 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
188 + YangModule yangNode = (YangModule) node;
189 + assertThat(yangNode.getName(), is("Test"));
190 +
191 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
192 + YangLeaf leafInfo = leafIterator.next();
193 +
194 + assertThat(leafInfo.getName(), is("invalid-interval"));
195 + assertThat(leafInfo.getDataType().getDataTypeName(), is("int32"));
196 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.INT32));
197 + YangRangeRestriction rangeRestriction = (YangRangeRestriction) leafInfo
198 + .getDataType().getDataTypeExtendedInfo();
199 +
200 + assertThat(rangeRestriction.getDescription(), is("\"range description\""));
201 + assertThat(rangeRestriction.getReference(), is("\"range reference\""));
202 +
203 + ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
204 + .listIterator();
205 + YangRangeInterval rangeInterval = rangeListIterator.next();
206 + assertThat(((YangInt32) rangeInterval.getStartValue()).getValue(), is(1));
207 + assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4));
208 + assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4));
209 + }
177 } 210 }
......
...@@ -150,9 +150,9 @@ public class StatusListenerTest { ...@@ -150,9 +150,9 @@ public class StatusListenerTest {
150 @Test 150 @Test
151 public void processModuleSubStatementStatus() throws IOException, ParserException { 151 public void processModuleSubStatementStatus() throws IOException, ParserException {
152 thrown.expect(ParserException.class); 152 thrown.expect(ParserException.class);
153 - thrown.expectMessage("mismatched input 'status' expecting {'augment', 'choice', 'contact', 'container', " 153 + thrown.expectMessage("mismatched input 'status' expecting {'anyxml', 'augment', 'choice', 'contact', "
154 - + "'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," 154 + + "'container', 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import',"
155 - + " 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference', " 155 + + " 'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference', "
156 + "'revision', 'rpc', 'typedef', 'uses', '}'}"); 156 + "'revision', 'rpc', 'typedef', 'uses', '}'}");
157 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementStatus.yang"); 157 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementStatus.yang");
158 } 158 }
......
...@@ -76,9 +76,9 @@ public class UnitsListenerTest { ...@@ -76,9 +76,9 @@ public class UnitsListenerTest {
76 @Test 76 @Test
77 public void processModuleSubStatementUnits() throws IOException, ParserException { 77 public void processModuleSubStatementUnits() throws IOException, ParserException {
78 thrown.expect(ParserException.class); 78 thrown.expect(ParserException.class);
79 - thrown.expectMessage("mismatched input 'type' expecting {'augment', 'choice', 'contact', 'container', " 79 + thrown.expectMessage("mismatched input 'type' expecting {'anyxml', 'augment', 'choice', 'contact', "
80 - + "'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', " 80 + + "'container', 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity',"
81 - + "'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', " 81 + + " 'import', 'include', 'leaf', 'leaf-list', 'list', 'notification', 'organization', "
82 + "'reference', 'revision', 'rpc', 'typedef', 'uses', '}'}"); 82 + "'reference', 'revision', 'rpc', 'typedef', 'uses', '}'}");
83 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementUnits.yang"); 83 YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementUnits.yang");
84 } 84 }
......
...@@ -80,6 +80,84 @@ public class ValueListenerTest { ...@@ -80,6 +80,84 @@ public class ValueListenerTest {
80 } 80 }
81 81
82 /** 82 /**
83 + * Checks explicitly configured negative value.
84 + */
85 + @Test
86 + public void processValueStatementWithNegativeValue() throws IOException, ParserException {
87 +
88 + YangNode node = manager.getDataModel("src/test/resources/ValueStatementWithNegativeValue.yang");
89 +
90 + // Check whether the data model tree returned is of type module.
91 + assertThat((node instanceof YangModule), is(true));
92 +
93 + // Check whether the node type is set properly to module.
94 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
95 +
96 + // Check whether the module name is set correctly.
97 + YangModule yangNode = (YangModule) node;
98 + assertThat(yangNode.getName(), is("Test"));
99 +
100 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
101 + YangLeaf leafInfo = leafIterator.next();
102 +
103 + assertThat(leafInfo.getName(), is("speed"));
104 + assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
105 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
106 + assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
107 + is("speed_enum"));
108 +
109 + Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
110 + for (YangEnum tmp : enumSet) {
111 + if (tmp.getNamedValue().equals("10m")) {
112 + assertThat(tmp.getValue(), is(-2));
113 + } else if (tmp.getNamedValue().equals("100m")) {
114 + assertThat(tmp.getValue(), is(-1));
115 + } else if (tmp.getNamedValue().equals("auto")) {
116 + assertThat(tmp.getValue(), is(0));
117 + }
118 + }
119 + }
120 +
121 + /**
122 + * Checks explicitly configured value with double quotes.
123 + */
124 + @Test
125 + public void processValueStatementWithQuotes() throws IOException, ParserException {
126 +
127 + YangNode node = manager.getDataModel("src/test/resources/ValueStatementWithQuotes.yang");
128 +
129 + // Check whether the data model tree returned is of type module.
130 + assertThat((node instanceof YangModule), is(true));
131 +
132 + // Check whether the node type is set properly to module.
133 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
134 +
135 + // Check whether the module name is set correctly.
136 + YangModule yangNode = (YangModule) node;
137 + assertThat(yangNode.getName(), is("Test"));
138 +
139 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
140 + YangLeaf leafInfo = leafIterator.next();
141 +
142 + assertThat(leafInfo.getName(), is("speed"));
143 + assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
144 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
145 + assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
146 + is("speed_enum"));
147 +
148 + Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
149 + for (YangEnum tmp : enumSet) {
150 + if (tmp.getNamedValue().equals("10m")) {
151 + assertThat(tmp.getValue(), is(10));
152 + } else if (tmp.getNamedValue().equals("100m")) {
153 + assertThat(tmp.getValue(), is(100));
154 + } else if (tmp.getNamedValue().equals("auto")) {
155 + assertThat(tmp.getValue(), is(1000));
156 + }
157 + }
158 + }
159 +
160 + /**
83 * Checks explicit value and auto generated value. 161 * Checks explicit value and auto generated value.
84 */ 162 */
85 @Test 163 @Test
......
...@@ -26,6 +26,7 @@ import java.util.List; ...@@ -26,6 +26,7 @@ import java.util.List;
26 import org.junit.Rule; 26 import org.junit.Rule;
27 import org.junit.Test; 27 import org.junit.Test;
28 import org.junit.rules.ExpectedException; 28 import org.junit.rules.ExpectedException;
29 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
29 30
30 import static org.hamcrest.core.Is.is; 31 import static org.hamcrest.core.Is.is;
31 import static org.hamcrest.core.IsNot.not; 32 import static org.hamcrest.core.IsNot.not;
...@@ -135,7 +136,7 @@ public final class YangFileScannerTest { ...@@ -135,7 +136,7 @@ public final class YangFileScannerTest {
135 136
136 String emptyYangDir = baseDir + separator + "scanner1"; 137 String emptyYangDir = baseDir + separator + "scanner1";
137 File path = createDirectory(emptyYangDir); 138 File path = createDirectory(emptyYangDir);
138 - List<String> emptyDirContents = getYangFiles(path.toString()); 139 + List<YangFileInfo> emptyDirContents = getYangFiles(path.toString());
139 List<String> expectedContents = new LinkedList<>(); 140 List<String> expectedContents = new LinkedList<>();
140 assertThat(true, is(emptyDirContents.equals(expectedContents))); 141 assertThat(true, is(emptyDirContents.equals(expectedContents)));
141 } 142 }
......
1 +module event {
2 +
3 + namespace "http://example.com/event";
4 + prefix "ev";
5 +
6 + notification event {
7 + leaf event-class {
8 + type string;
9 + }
10 + anyxml reporting-entity;
11 + leaf severity {
12 + type string;
13 + }
14 + }
15 +}
16 +
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container food {
6 + choice snack {
7 + case sports-arena {
8 + leaf pretzel {
9 + type string;
10 + }
11 + leaf beer {
12 + type string;
13 + }
14 + }
15 + case late-night {
16 + leaf chocolate {
17 + type string;
18 + }
19 + }
20 + default "hello";
21 + }
22 + }
23 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf ifType {
6 + type enumeration {
7 + enum "unbounded";
8 + enum ZERO;
9 + enum two;
10 + enum four;
11 + enum seven {
12 + value 21474836472147483647;
13 + }
14 + }
15 + }
16 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf ifType {
6 + type enumeration {
7 + enum "unbounded";
8 + enum ZERO;
9 + enum two;
10 + enum four;
11 + enum seven {
12 + value 2147483647;
13 + }
14 + enum five;
15 +
16 + }
17 + }
18 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + grouping network {
6 + leaf invalid-interval {
7 + type "string";
8 + units "seconds";
9 + status current;
10 + reference "RFC 6020";
11 + }
12 + }
13 + list valid {
14 + key "invalid-interval";
15 + leaf invalid {
16 + type "string";
17 + units "seconds";
18 + status current;
19 + reference "RFC 6020";
20 + }
21 + uses "network";
22 + }
23 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + default "1";
9 + description "Interval before a route is declared invalid";
10 + config true;
11 + mandatory true;
12 + status current;
13 + reference "RFC 6020";
14 + }
15 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type string {
7 + length "0..100" {
8 + description "length description";
9 + reference "length reference";
10 + }
11 + }
12 + }
13 +}
1 +module rock {
2 + namespace "http://example.net/rock";
3 + prefix "rock";
4 + leaf-list cipher {
5 + type string;
6 + ordered-by user;
7 + description "A list of ciphers";
8 + }
9 +}
10 +
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type string {
7 + pattern "[a-zA-Z]" {
8 + description "pattern description";
9 + reference "pattern reference";
10 + }
11 + }
12 + }
13 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type int32 {
7 + range "1..4 | 10..20" {
8 + description "range description";
9 + reference "range reference";
10 + }
11 + }
12 + }
13 +}
14 +
...@@ -10,7 +10,6 @@ module Test { ...@@ -10,7 +10,6 @@ module Test {
10 prefix "P"; 10 prefix "P";
11 } 11 }
12 augment "/if:interfaces/if:ifEntry" { 12 augment "/if:interfaces/if:ifEntry" {
13 - when "if:ifType='ds0'";
14 leaf ds0ChannelNumber { 13 leaf ds0ChannelNumber {
15 type P:ChannelNumber; 14 type P:ChannelNumber;
16 } 15 }
......
...@@ -14,9 +14,7 @@ module rock { ...@@ -14,9 +14,7 @@ module rock {
14 type int32; 14 type int32;
15 } 15 }
16 leaf if-name { 16 leaf if-name {
17 - type leafref { 17 + type leafref;
18 - path "/interface/name";
19 - }
20 } 18 }
21 leaf if-admin-status { 19 leaf if-admin-status {
22 type P:admin-status; 20 type P:admin-status;
......
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf speed {
6 + type enumeration {
7 + enum 10m {
8 + value -2;
9 + }
10 + enum 100m {
11 + value "-1";
12 + }
13 + enum auto {
14 + value 0;
15 + }
16 + }
17 + }
18 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf speed {
6 + type enumeration {
7 + enum 10m {
8 + value "10";
9 + }
10 + enum 100m {
11 + value "100";
12 + }
13 + enum auto {
14 + value "1000";
15 + }
16 + }
17 + }
18 +}