Committed by
Gerrit Code Review
[ONOS-3892,3895,3882,3883,3896]Implementation of yang container, list, leaf, leaf-list parser
Change-Id: Id51839bc434044be8273382f80f15b12f0ec8709
Showing
17 changed files
with
830 additions
and
141 deletions
... | @@ -217,5 +217,21 @@ public enum YangDataTypes { | ... | @@ -217,5 +217,21 @@ public enum YangDataTypes { |
217 | /** | 217 | /** |
218 | * Derived Data type. | 218 | * Derived Data type. |
219 | */ | 219 | */ |
220 | - DERIVED | 220 | + DERIVED; |
221 | + | ||
222 | + /** | ||
223 | + * Returns YANG data type for corresponding type name. | ||
224 | + * | ||
225 | + * @param name type name from YANG file. | ||
226 | + * @return YANG data type for corresponding type name. | ||
227 | + */ | ||
228 | + public static YangDataTypes getType(String name) { | ||
229 | + name = name.replace("\"", ""); | ||
230 | + for (YangDataTypes yangDataType : values()) { | ||
231 | + if (yangDataType.name().equalsIgnoreCase(name)) { | ||
232 | + return yangDataType; | ||
233 | + } | ||
234 | + } | ||
235 | + return YangDataTypes.DERIVED; | ||
236 | + } | ||
221 | } | 237 | } | ... | ... |
... | @@ -36,6 +36,8 @@ import java.io.IOException; | ... | @@ -36,6 +36,8 @@ import java.io.IOException; |
36 | */ | 36 | */ |
37 | public class YangUtilsParserManager implements YangUtilsParser { | 37 | public class YangUtilsParserManager implements YangUtilsParser { |
38 | 38 | ||
39 | + public static final int SUB_STATEMENT_CARDINALITY = 1; | ||
40 | + | ||
39 | @Override | 41 | @Override |
40 | public YangNode getDataModel(String yangFile) throws IOException, ParserException { | 42 | public YangNode getDataModel(String yangFile) throws IOException, ParserException { |
41 | 43 | ... | ... |
... | @@ -16,8 +16,19 @@ | ... | @@ -16,8 +16,19 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
20 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
21 | +import org.onosproject.yangutils.datamodel.YangLeafList; | ||
22 | +import org.onosproject.yangutils.datamodel.YangList; | ||
23 | +import org.onosproject.yangutils.parser.Parsable; | ||
24 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 25 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
26 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 27 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
29 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
30 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
31 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 32 | ||
22 | /* | 33 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 34 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -55,18 +66,41 @@ public final class ConfigListener { | ... | @@ -55,18 +66,41 @@ public final class ConfigListener { |
55 | */ | 66 | */ |
56 | public static void processConfigEntry(TreeWalkListener listener, | 67 | public static void processConfigEntry(TreeWalkListener listener, |
57 | GeneratedYangParser.ConfigStatementContext ctx) { | 68 | GeneratedYangParser.ConfigStatementContext ctx) { |
58 | - // TODO method implementation | 69 | + boolean isConfig = false; |
59 | - } | ||
60 | 70 | ||
61 | - /** | 71 | + // Check for stack to be non empty. |
62 | - * It is called when parser exits from grammar rule (config), it performs | 72 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, |
63 | - * validation and updates the data model tree. | 73 | + ParsableDataType.CONFIG_DATA, "", ListenerErrorLocation.ENTRY); |
64 | - * | 74 | + |
65 | - * @param listener listener's object. | 75 | + if (ctx.TRUE_KEYWORD() != null) { |
66 | - * @param ctx context object of the grammar rule. | 76 | + isConfig = true; |
67 | - */ | 77 | + } |
68 | - public static void processConfigExit(TreeWalkListener listener, | 78 | + |
69 | - GeneratedYangParser.ConfigStatementContext ctx) { | 79 | + Parsable tmpData = listener.getParsedDataStack().peek(); |
70 | - // TODO method implementation | 80 | + switch (tmpData.getParsableDataType()) { |
81 | + case LEAF_DATA: | ||
82 | + YangLeaf leaf = (YangLeaf) tmpData; | ||
83 | + leaf.setConfig(isConfig); | ||
84 | + break; | ||
85 | + case CONTAINER_DATA: | ||
86 | + YangContainer container = (YangContainer) tmpData; | ||
87 | + container.setConfig(isConfig); | ||
88 | + break; | ||
89 | + case LEAF_LIST_DATA: | ||
90 | + YangLeafList leafList = (YangLeafList) tmpData; | ||
91 | + leafList.setConfig(isConfig); | ||
92 | + break; | ||
93 | + case LIST_DATA: | ||
94 | + YangList yangList = (YangList) tmpData; | ||
95 | + yangList.setConfig(isConfig); | ||
96 | + break; | ||
97 | + case CHOICE_DATA: // TODO | ||
98 | + break; | ||
99 | + default: | ||
100 | + throw new ParserException(ListenerErrorMessageConstruction | ||
101 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
102 | + ParsableDataType.CONFIG_DATA, | ||
103 | + "", ListenerErrorLocation.ENTRY)); | ||
104 | + } | ||
71 | } | 105 | } |
72 | } | 106 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContainerListener.java
... | @@ -15,9 +15,20 @@ | ... | @@ -15,9 +15,20 @@ |
15 | */ | 15 | */ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
19 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
20 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
21 | +import org.onosproject.yangutils.parser.Parsable; | ||
18 | 22 | ||
23 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 24 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
25 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 26 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
27 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
29 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
30 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
31 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 32 | ||
22 | /* | 33 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 34 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -54,6 +65,8 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ... | @@ -54,6 +65,8 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
54 | */ | 65 | */ |
55 | public final class ContainerListener { | 66 | public final class ContainerListener { |
56 | 67 | ||
68 | + private static ParsableDataType yangConstruct; | ||
69 | + | ||
57 | /** | 70 | /** |
58 | * Creates a new container listener. | 71 | * Creates a new container listener. |
59 | */ | 72 | */ |
... | @@ -70,7 +83,44 @@ public final class ContainerListener { | ... | @@ -70,7 +83,44 @@ public final class ContainerListener { |
70 | */ | 83 | */ |
71 | public static void processContainerEntry(TreeWalkListener listener, | 84 | public static void processContainerEntry(TreeWalkListener listener, |
72 | GeneratedYangParser.ContainerStatementContext ctx) { | 85 | GeneratedYangParser.ContainerStatementContext ctx) { |
73 | - // TODO method implementation | 86 | + |
87 | + // Check for stack to be non empty. | ||
88 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, | ||
89 | + ParsableDataType.CONTAINER_DATA, String.valueOf(ctx.IDENTIFIER().getText()), | ||
90 | + ListenerErrorLocation.ENTRY); | ||
91 | + | ||
92 | + boolean result = validateSubStatementsCardinality(ctx); | ||
93 | + if (!result) { | ||
94 | + throw new ParserException(ListenerErrorMessageConstruction | ||
95 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_CARDINALITY, | ||
96 | + yangConstruct, "", ListenerErrorLocation.ENTRY)); | ||
97 | + } | ||
98 | + | ||
99 | + YangContainer container = new YangContainer(); | ||
100 | + container.setName(ctx.IDENTIFIER().getText()); | ||
101 | + | ||
102 | + Parsable curData = listener.getParsedDataStack().peek(); | ||
103 | + | ||
104 | + if (curData instanceof YangNode) { | ||
105 | + YangNode curNode = (YangNode) curData; | ||
106 | + try { | ||
107 | + curNode.addChild(container); | ||
108 | + } catch (DataModelException e) { | ||
109 | + throw new ParserException(ListenerErrorMessageConstruction | ||
110 | + .constructExtendedListenerErrorMessage(ListenerErrorType.UNHANDLED_PARSED_DATA, | ||
111 | + ParsableDataType.CONTAINER_DATA, | ||
112 | + String.valueOf(ctx.IDENTIFIER().getText()), | ||
113 | + ListenerErrorLocation.ENTRY, | ||
114 | + e.getMessage())); | ||
115 | + } | ||
116 | + listener.getParsedDataStack().push(container); | ||
117 | + } else { | ||
118 | + throw new ParserException(ListenerErrorMessageConstruction | ||
119 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
120 | + ParsableDataType.CONTAINER_DATA, | ||
121 | + String.valueOf(ctx.IDENTIFIER().getText()), | ||
122 | + ListenerErrorLocation.ENTRY)); | ||
123 | + } | ||
74 | } | 124 | } |
75 | 125 | ||
76 | /** | 126 | /** |
... | @@ -82,6 +132,61 @@ public final class ContainerListener { | ... | @@ -82,6 +132,61 @@ public final class ContainerListener { |
82 | */ | 132 | */ |
83 | public static void processContainerExit(TreeWalkListener listener, | 133 | public static void processContainerExit(TreeWalkListener listener, |
84 | GeneratedYangParser.ContainerStatementContext ctx) { | 134 | GeneratedYangParser.ContainerStatementContext ctx) { |
85 | - //TODO method implementation | 135 | + |
136 | + // Check for stack to be non empty. | ||
137 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, | ||
138 | + ParsableDataType.CONTAINER_DATA, String.valueOf(ctx.IDENTIFIER().getText()), | ||
139 | + ListenerErrorLocation.EXIT); | ||
140 | + | ||
141 | + if (listener.getParsedDataStack().peek() instanceof YangContainer) { | ||
142 | + listener.getParsedDataStack().pop(); | ||
143 | + } else { | ||
144 | + throw new ParserException(ListenerErrorMessageConstruction | ||
145 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
146 | + ParsableDataType.CONTAINER_DATA, | ||
147 | + String.valueOf(ctx.IDENTIFIER().getText()), | ||
148 | + ListenerErrorLocation.EXIT)); | ||
149 | + } | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * Validates the cardinality of container sub-statements as per grammar. | ||
154 | + * | ||
155 | + * @param ctx context object of the grammar rule. | ||
156 | + * @return true/false validation success or failure. | ||
157 | + */ | ||
158 | + public static boolean validateSubStatementsCardinality(GeneratedYangParser.ContainerStatementContext ctx) { | ||
159 | + | ||
160 | + if ((!ctx.presenceStatement().isEmpty()) | ||
161 | + && (ctx.presenceStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
162 | + yangConstruct = ParsableDataType.PRESENCE_DATA; | ||
163 | + return false; | ||
164 | + } | ||
165 | + | ||
166 | + if ((!ctx.configStatement().isEmpty()) | ||
167 | + && (ctx.configStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
168 | + yangConstruct = ParsableDataType.CONFIG_DATA; | ||
169 | + return false; | ||
170 | + } | ||
171 | + | ||
172 | + if ((!ctx.descriptionStatement().isEmpty()) | ||
173 | + && (ctx.descriptionStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
174 | + yangConstruct = ParsableDataType.DESCRIPTION_DATA; | ||
175 | + return false; | ||
176 | + } | ||
177 | + | ||
178 | + if ((!ctx.referenceStatement().isEmpty()) | ||
179 | + && (ctx.referenceStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
180 | + yangConstruct = ParsableDataType.REFERENCE_DATA; | ||
181 | + return false; | ||
182 | + } | ||
183 | + | ||
184 | + if ((!ctx.statusStatement().isEmpty()) | ||
185 | + && (ctx.statusStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
186 | + yangConstruct = ParsableDataType.STATUS_DATA; | ||
187 | + return false; | ||
188 | + } | ||
189 | + | ||
190 | + return true; | ||
86 | } | 191 | } |
87 | } | 192 | } | ... | ... |
... | @@ -16,8 +16,16 @@ | ... | @@ -16,8 +16,16 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangDesc; | ||
20 | +import org.onosproject.yangutils.parser.Parsable; | ||
21 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 22 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
23 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 24 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
25 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
26 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
27 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 29 | ||
22 | /* | 30 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 31 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -51,18 +59,22 @@ public final class DescriptionListener { | ... | @@ -51,18 +59,22 @@ public final class DescriptionListener { |
51 | */ | 59 | */ |
52 | public static void processDescriptionEntry(TreeWalkListener listener, | 60 | public static void processDescriptionEntry(TreeWalkListener listener, |
53 | GeneratedYangParser.DescriptionStatementContext ctx) { | 61 | GeneratedYangParser.DescriptionStatementContext ctx) { |
54 | - // TODO method implementation | ||
55 | - } | ||
56 | 62 | ||
57 | - /** | 63 | + // Check for stack to be non empty. |
58 | - * It is called when parser exits from grammar rule (description), it perform | 64 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, |
59 | - * validations and updates the data model tree. | 65 | + ParsableDataType.DESCRIPTION_DATA, String.valueOf(ctx.string().getText()), |
60 | - * | 66 | + ListenerErrorLocation.ENTRY); |
61 | - * @param listener listener's object. | 67 | + |
62 | - * @param ctx context object of the grammar rule. | 68 | + Parsable tmpData = listener.getParsedDataStack().peek(); |
63 | - */ | 69 | + if (tmpData instanceof YangDesc) { |
64 | - public static void processDescriptionExit(TreeWalkListener listener, | 70 | + YangDesc description = (YangDesc) tmpData; |
65 | - GeneratedYangParser.DescriptionStatementContext ctx) { | 71 | + description.setDescription(ctx.string().getText()); |
66 | - // TODO method implementation | 72 | + } else { |
73 | + throw new ParserException(ListenerErrorMessageConstruction | ||
74 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
75 | + ParsableDataType.DESCRIPTION_DATA, | ||
76 | + String.valueOf(ctx.string().getText()), | ||
77 | + ListenerErrorLocation.ENTRY)); | ||
78 | + } | ||
67 | } | 79 | } |
68 | } | 80 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,8 +16,16 @@ | ... | @@ -16,8 +16,16 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangList; | ||
20 | +import org.onosproject.yangutils.parser.Parsable; | ||
21 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 22 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
23 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 24 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
25 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
26 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
27 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 29 | ||
22 | /* | 30 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 31 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -51,18 +59,30 @@ public final class KeyListener { | ... | @@ -51,18 +59,30 @@ public final class KeyListener { |
51 | */ | 59 | */ |
52 | public static void processKeyEntry(TreeWalkListener listener, | 60 | public static void processKeyEntry(TreeWalkListener listener, |
53 | GeneratedYangParser.KeyStatementContext ctx) { | 61 | GeneratedYangParser.KeyStatementContext ctx) { |
54 | - // TODO method implementation | ||
55 | - } | ||
56 | 62 | ||
57 | - /** | 63 | + // Check for stack to be non empty. |
58 | - * It is called when parser exits from grammar rule (key), it perform | 64 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, |
59 | - * validations and updates the data model tree. | 65 | + ParsableDataType.KEY_DATA, String.valueOf(ctx.string().getText()), |
60 | - * | 66 | + ListenerErrorLocation.ENTRY); |
61 | - * @param listener listener's object. | 67 | + |
62 | - * @param ctx context object of the grammar rule. | 68 | + Parsable tmpData = listener.getParsedDataStack().peek(); |
63 | - */ | 69 | + if (listener.getParsedDataStack().peek() instanceof YangList) { |
64 | - public static void processKeyExit(TreeWalkListener listener, | 70 | + YangList yangList = (YangList) tmpData; |
65 | - GeneratedYangParser.KeyStatementContext ctx) { | 71 | + String tmpKeyValue = ctx.string().getText().replace("\"", ""); |
66 | - // TODO method implementation | 72 | + if (tmpKeyValue.contains(" ")) { |
73 | + String[] keyValues = tmpKeyValue.split(" "); | ||
74 | + for (String keyValue : keyValues) { | ||
75 | + yangList.addKey(keyValue); | ||
76 | + } | ||
77 | + } else { | ||
78 | + yangList.addKey(tmpKeyValue); | ||
79 | + } | ||
80 | + } else { | ||
81 | + throw new ParserException(ListenerErrorMessageConstruction | ||
82 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
83 | + ParsableDataType.KEY_DATA, | ||
84 | + String.valueOf(ctx.string().getText()), | ||
85 | + ListenerErrorLocation.ENTRY)); | ||
86 | + } | ||
67 | } | 87 | } |
68 | } | 88 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,8 +16,18 @@ | ... | @@ -16,8 +16,18 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangLeafList; | ||
20 | +import org.onosproject.yangutils.datamodel.YangLeavesHolder; | ||
21 | +import org.onosproject.yangutils.parser.Parsable; | ||
22 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 23 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
24 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
26 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
27 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
29 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
30 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 31 | ||
22 | /* | 32 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 33 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -52,6 +62,8 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ... | @@ -52,6 +62,8 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
52 | */ | 62 | */ |
53 | public final class LeafListListener { | 63 | public final class LeafListListener { |
54 | 64 | ||
65 | + private static ParsableDataType yangConstruct; | ||
66 | + | ||
55 | /** | 67 | /** |
56 | * Creates a new leaf list listener. | 68 | * Creates a new leaf list listener. |
57 | */ | 69 | */ |
... | @@ -68,7 +80,36 @@ public final class LeafListListener { | ... | @@ -68,7 +80,36 @@ public final class LeafListListener { |
68 | */ | 80 | */ |
69 | public static void processLeafListEntry(TreeWalkListener listener, | 81 | public static void processLeafListEntry(TreeWalkListener listener, |
70 | GeneratedYangParser.LeafListStatementContext ctx) { | 82 | GeneratedYangParser.LeafListStatementContext ctx) { |
71 | - // TODO method implementation | 83 | + |
84 | + // Check for stack to be non empty. | ||
85 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, | ||
86 | + ParsableDataType.LEAF_LIST_DATA, String.valueOf(ctx.IDENTIFIER().getText()), | ||
87 | + ListenerErrorLocation.ENTRY); | ||
88 | + | ||
89 | + boolean result = validateSubStatementsCardinality(ctx); | ||
90 | + if (!result) { | ||
91 | + throw new ParserException(ListenerErrorMessageConstruction | ||
92 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_CARDINALITY, | ||
93 | + yangConstruct, "", ListenerErrorLocation.ENTRY)); | ||
94 | + } | ||
95 | + | ||
96 | + YangLeafList leafList = new YangLeafList(); | ||
97 | + leafList.setLeafName(ctx.IDENTIFIER().getText()); | ||
98 | + | ||
99 | + Parsable tmpData = listener.getParsedDataStack().peek(); | ||
100 | + YangLeavesHolder leaves; | ||
101 | + | ||
102 | + if (tmpData instanceof YangLeavesHolder) { | ||
103 | + leaves = (YangLeavesHolder) tmpData; | ||
104 | + leaves.addLeafList(leafList); | ||
105 | + } else { | ||
106 | + throw new ParserException(ListenerErrorMessageConstruction | ||
107 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
108 | + ParsableDataType.LEAF_LIST_DATA, | ||
109 | + String.valueOf(ctx.IDENTIFIER().getText()), | ||
110 | + ListenerErrorLocation.ENTRY)); | ||
111 | + } | ||
112 | + listener.getParsedDataStack().push(leafList); | ||
72 | } | 113 | } |
73 | 114 | ||
74 | /** | 115 | /** |
... | @@ -80,6 +121,80 @@ public final class LeafListListener { | ... | @@ -80,6 +121,80 @@ public final class LeafListListener { |
80 | */ | 121 | */ |
81 | public static void processLeafListExit(TreeWalkListener listener, | 122 | public static void processLeafListExit(TreeWalkListener listener, |
82 | GeneratedYangParser.LeafListStatementContext ctx) { | 123 | GeneratedYangParser.LeafListStatementContext ctx) { |
83 | - // TODO method implementation | 124 | + |
125 | + // Check for stack to be non empty. | ||
126 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, | ||
127 | + ParsableDataType.LEAF_LIST_DATA, String.valueOf(ctx.IDENTIFIER().getText()), | ||
128 | + ListenerErrorLocation.EXIT); | ||
129 | + | ||
130 | + if (listener.getParsedDataStack().peek() instanceof YangLeafList) { | ||
131 | + listener.getParsedDataStack().pop(); | ||
132 | + } else { | ||
133 | + throw new ParserException(ListenerErrorMessageConstruction | ||
134 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
135 | + ParsableDataType.LEAF_LIST_DATA, | ||
136 | + String.valueOf(ctx.IDENTIFIER().getText()), | ||
137 | + ListenerErrorLocation.EXIT)); | ||
138 | + } | ||
139 | + } | ||
140 | + | ||
141 | + /** | ||
142 | + * Validates the cardinality of leaf-list sub-statements as per grammar. | ||
143 | + * | ||
144 | + * @param ctx context object of the grammar rule. | ||
145 | + * @return true/false validation success or failure. | ||
146 | + */ | ||
147 | + public static boolean validateSubStatementsCardinality(GeneratedYangParser | ||
148 | + .LeafListStatementContext ctx) { | ||
149 | + | ||
150 | + if (ctx.typeStatement().isEmpty() | ||
151 | + || (ctx.typeStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
152 | + yangConstruct = ParsableDataType.TYPE_DATA; | ||
153 | + return false; | ||
154 | + } | ||
155 | + | ||
156 | + if ((!ctx.unitsStatement().isEmpty()) | ||
157 | + && (ctx.unitsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
158 | + yangConstruct = ParsableDataType.UNITS_DATA; | ||
159 | + return false; | ||
160 | + } | ||
161 | + | ||
162 | + if ((!ctx.configStatement().isEmpty()) | ||
163 | + && (ctx.configStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
164 | + yangConstruct = ParsableDataType.CONFIG_DATA; | ||
165 | + return false; | ||
166 | + } | ||
167 | + | ||
168 | + if ((!ctx.maxElementsStatement().isEmpty()) | ||
169 | + && (ctx.maxElementsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
170 | + yangConstruct = ParsableDataType.MAX_ELEMENT_DATA; | ||
171 | + return false; | ||
172 | + } | ||
173 | + | ||
174 | + if ((!ctx.minElementsStatement().isEmpty()) | ||
175 | + && (ctx.minElementsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
176 | + yangConstruct = ParsableDataType.MIN_ELEMENT_DATA; | ||
177 | + return false; | ||
178 | + } | ||
179 | + | ||
180 | + if ((!ctx.descriptionStatement().isEmpty()) | ||
181 | + && (ctx.descriptionStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
182 | + yangConstruct = ParsableDataType.DESCRIPTION_DATA; | ||
183 | + return false; | ||
184 | + } | ||
185 | + | ||
186 | + if ((!ctx.referenceStatement().isEmpty()) | ||
187 | + && (ctx.referenceStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
188 | + yangConstruct = ParsableDataType.REFERENCE_DATA; | ||
189 | + return false; | ||
190 | + } | ||
191 | + | ||
192 | + if ((!ctx.statusStatement().isEmpty()) | ||
193 | + && (ctx.statusStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
194 | + yangConstruct = ParsableDataType.STATUS_DATA; | ||
195 | + return false; | ||
196 | + } | ||
197 | + | ||
198 | + return true; | ||
84 | } | 199 | } |
85 | } | 200 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -20,8 +20,18 @@ | ... | @@ -20,8 +20,18 @@ |
20 | */ | 20 | */ |
21 | package org.onosproject.yangutils.parser.impl.listeners; | 21 | package org.onosproject.yangutils.parser.impl.listeners; |
22 | 22 | ||
23 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
24 | +import org.onosproject.yangutils.parser.Parsable; | ||
25 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
23 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 26 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
27 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
24 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 28 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
29 | +import org.onosproject.yangutils.datamodel.YangLeavesHolder; | ||
30 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
31 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
32 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
33 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
34 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
25 | 35 | ||
26 | /* | 36 | /* |
27 | * Reference: RFC6020 and YANG ANTLR Grammar | 37 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -55,6 +65,8 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ... | @@ -55,6 +65,8 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
55 | */ | 65 | */ |
56 | public final class LeafListener { | 66 | public final class LeafListener { |
57 | 67 | ||
68 | + private static ParsableDataType yangConstruct; | ||
69 | + | ||
58 | /** | 70 | /** |
59 | * Creates a new leaf listener. | 71 | * Creates a new leaf listener. |
60 | */ | 72 | */ |
... | @@ -71,7 +83,37 @@ public final class LeafListener { | ... | @@ -71,7 +83,37 @@ public final class LeafListener { |
71 | */ | 83 | */ |
72 | public static void processLeafEntry(TreeWalkListener listener, | 84 | public static void processLeafEntry(TreeWalkListener listener, |
73 | GeneratedYangParser.LeafStatementContext ctx) { | 85 | GeneratedYangParser.LeafStatementContext ctx) { |
74 | - // TODO method implementation | 86 | + |
87 | + // Check for stack to be non empty. | ||
88 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, | ||
89 | + ParsableDataType.LEAF_DATA, String.valueOf(ctx.IDENTIFIER().getText()), | ||
90 | + ListenerErrorLocation.ENTRY); | ||
91 | + | ||
92 | + boolean result = validateSubStatementsCardinality(ctx); | ||
93 | + if (!result) { | ||
94 | + throw new ParserException(ListenerErrorMessageConstruction | ||
95 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_CARDINALITY, | ||
96 | + yangConstruct, "", ListenerErrorLocation.ENTRY)); | ||
97 | + } | ||
98 | + | ||
99 | + YangLeaf leaf = new YangLeaf(); | ||
100 | + leaf.setLeafName(ctx.IDENTIFIER().getText()); | ||
101 | + | ||
102 | + Parsable tmpData = listener.getParsedDataStack().peek(); | ||
103 | + YangLeavesHolder leaves; | ||
104 | + | ||
105 | + if (tmpData instanceof YangLeavesHolder) { | ||
106 | + leaves = (YangLeavesHolder) tmpData; | ||
107 | + leaves.addLeaf(leaf); | ||
108 | + } else { | ||
109 | + throw new ParserException(ListenerErrorMessageConstruction | ||
110 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
111 | + ParsableDataType.LEAF_DATA, | ||
112 | + String.valueOf(ctx.IDENTIFIER().getText()), | ||
113 | + ListenerErrorLocation.ENTRY)); | ||
114 | + } | ||
115 | + | ||
116 | + listener.getParsedDataStack().push(leaf); | ||
75 | } | 117 | } |
76 | 118 | ||
77 | /** | 119 | /** |
... | @@ -83,6 +125,74 @@ public final class LeafListener { | ... | @@ -83,6 +125,74 @@ public final class LeafListener { |
83 | */ | 125 | */ |
84 | public static void processLeafExit(TreeWalkListener listener, | 126 | public static void processLeafExit(TreeWalkListener listener, |
85 | GeneratedYangParser.LeafStatementContext ctx) { | 127 | GeneratedYangParser.LeafStatementContext ctx) { |
86 | - // TODO method implementation | 128 | + |
129 | + // Check for stack to be non empty. | ||
130 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, | ||
131 | + ParsableDataType.LEAF_DATA, String.valueOf(ctx.IDENTIFIER().getText()), | ||
132 | + ListenerErrorLocation.EXIT); | ||
133 | + | ||
134 | + if (listener.getParsedDataStack().peek() instanceof YangLeaf) { | ||
135 | + listener.getParsedDataStack().pop(); | ||
136 | + } else { | ||
137 | + throw new ParserException(ListenerErrorMessageConstruction | ||
138 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
139 | + ParsableDataType.LEAF_DATA, | ||
140 | + String.valueOf(ctx.IDENTIFIER().getText()), | ||
141 | + ListenerErrorLocation.EXIT)); | ||
142 | + } | ||
143 | + } | ||
144 | + | ||
145 | + /** | ||
146 | + * Validates the cardinality of leaf sub-statements as per grammar. | ||
147 | + * | ||
148 | + * @param ctx context object of the grammar rule. | ||
149 | + * @return true/false validation success or failure. | ||
150 | + */ | ||
151 | + public static boolean validateSubStatementsCardinality(GeneratedYangParser | ||
152 | + .LeafStatementContext ctx) { | ||
153 | + | ||
154 | + if (ctx.typeStatement().isEmpty() | ||
155 | + || (ctx.typeStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
156 | + yangConstruct = ParsableDataType.TYPE_DATA; | ||
157 | + return false; | ||
158 | + } | ||
159 | + | ||
160 | + if ((!ctx.unitsStatement().isEmpty()) | ||
161 | + && (ctx.unitsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
162 | + yangConstruct = ParsableDataType.UNITS_DATA; | ||
163 | + return false; | ||
164 | + } | ||
165 | + | ||
166 | + if ((!ctx.configStatement().isEmpty()) | ||
167 | + && (ctx.configStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
168 | + yangConstruct = ParsableDataType.CONFIG_DATA; | ||
169 | + return false; | ||
170 | + } | ||
171 | + | ||
172 | + if ((!ctx.mandatoryStatement().isEmpty()) | ||
173 | + && (ctx.mandatoryStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
174 | + yangConstruct = ParsableDataType.MANDATORY_DATA; | ||
175 | + return false; | ||
176 | + } | ||
177 | + | ||
178 | + if ((!ctx.descriptionStatement().isEmpty()) | ||
179 | + && (ctx.descriptionStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
180 | + yangConstruct = ParsableDataType.DESCRIPTION_DATA; | ||
181 | + return false; | ||
182 | + } | ||
183 | + | ||
184 | + if ((!ctx.referenceStatement().isEmpty()) | ||
185 | + && (ctx.referenceStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
186 | + yangConstruct = ParsableDataType.REFERENCE_DATA; | ||
187 | + return false; | ||
188 | + } | ||
189 | + | ||
190 | + if ((!ctx.statusStatement().isEmpty()) | ||
191 | + && (ctx.statusStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
192 | + yangConstruct = ParsableDataType.STATUS_DATA; | ||
193 | + return false; | ||
194 | + } | ||
195 | + | ||
196 | + return true; | ||
87 | } | 197 | } |
88 | } | 198 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,8 +16,20 @@ | ... | @@ -16,8 +16,20 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangList; | ||
20 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
21 | +import org.onosproject.yangutils.datamodel.YangNodeType; | ||
22 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
23 | +import org.onosproject.yangutils.parser.Parsable; | ||
24 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 25 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
26 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 27 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
28 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
29 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
30 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
31 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
32 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 33 | ||
22 | /* | 34 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 35 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -56,6 +68,8 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ... | @@ -56,6 +68,8 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
56 | */ | 68 | */ |
57 | public final class ListListener { | 69 | public final class ListListener { |
58 | 70 | ||
71 | + private static ParsableDataType yangConstruct; | ||
72 | + | ||
59 | /** | 73 | /** |
60 | * Creates a new list listener. | 74 | * Creates a new list listener. |
61 | */ | 75 | */ |
... | @@ -72,7 +86,44 @@ public final class ListListener { | ... | @@ -72,7 +86,44 @@ public final class ListListener { |
72 | */ | 86 | */ |
73 | public static void processListEntry(TreeWalkListener listener, | 87 | public static void processListEntry(TreeWalkListener listener, |
74 | GeneratedYangParser.ListStatementContext ctx) { | 88 | GeneratedYangParser.ListStatementContext ctx) { |
75 | - // TODO | 89 | + |
90 | + YangNode curNode; | ||
91 | + | ||
92 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, | ||
93 | + ParsableDataType.LIST_DATA, String.valueOf(ctx.IDENTIFIER().getText()), | ||
94 | + ListenerErrorLocation.ENTRY); | ||
95 | + | ||
96 | + boolean result = validateSubStatementsCardinality(ctx); | ||
97 | + if (!result) { | ||
98 | + throw new ParserException(ListenerErrorMessageConstruction | ||
99 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_CARDINALITY, | ||
100 | + yangConstruct, "", ListenerErrorLocation.ENTRY)); | ||
101 | + } | ||
102 | + | ||
103 | + YangList yangList = new YangList(YangNodeType.LIST_NODE); | ||
104 | + yangList.setName(ctx.IDENTIFIER().getText()); | ||
105 | + | ||
106 | + Parsable curData = listener.getParsedDataStack().peek(); | ||
107 | + if (curData instanceof YangNode) { | ||
108 | + curNode = (YangNode) curData; | ||
109 | + try { | ||
110 | + curNode.addChild(yangList); | ||
111 | + } catch (DataModelException e) { | ||
112 | + throw new ParserException(ListenerErrorMessageConstruction | ||
113 | + .constructExtendedListenerErrorMessage(ListenerErrorType.UNHANDLED_PARSED_DATA, | ||
114 | + ParsableDataType.LIST_DATA, | ||
115 | + String.valueOf(ctx.IDENTIFIER().getText()), | ||
116 | + ListenerErrorLocation.ENTRY, | ||
117 | + e.getMessage())); | ||
118 | + } | ||
119 | + listener.getParsedDataStack().push(yangList); | ||
120 | + } else { | ||
121 | + throw new ParserException(ListenerErrorMessageConstruction | ||
122 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
123 | + ParsableDataType.LIST_DATA, | ||
124 | + String.valueOf(ctx.IDENTIFIER().getText()), | ||
125 | + ListenerErrorLocation.ENTRY)); | ||
126 | + } | ||
76 | } | 127 | } |
77 | 128 | ||
78 | /** | 129 | /** |
... | @@ -84,6 +135,77 @@ public final class ListListener { | ... | @@ -84,6 +135,77 @@ public final class ListListener { |
84 | */ | 135 | */ |
85 | public static void processListExit(TreeWalkListener listener, | 136 | public static void processListExit(TreeWalkListener listener, |
86 | GeneratedYangParser.ListStatementContext ctx) { | 137 | GeneratedYangParser.ListStatementContext ctx) { |
87 | - // TODO | 138 | + |
139 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, | ||
140 | + ParsableDataType.LIST_DATA, String.valueOf(ctx.IDENTIFIER().getText()), | ||
141 | + ListenerErrorLocation.EXIT); | ||
142 | + | ||
143 | + if (listener.getParsedDataStack().peek() instanceof YangList) { | ||
144 | + listener.getParsedDataStack().pop(); | ||
145 | + } else { | ||
146 | + throw new ParserException(ListenerErrorMessageConstruction | ||
147 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
148 | + ParsableDataType.LIST_DATA, | ||
149 | + String.valueOf(ctx.IDENTIFIER().getText()), | ||
150 | + ListenerErrorLocation.EXIT)); | ||
151 | + } | ||
152 | + } | ||
153 | + | ||
154 | + /** | ||
155 | + * Validates the cardinality of list sub-statements as per grammar. | ||
156 | + * | ||
157 | + * @param ctx context object of the grammar rule. | ||
158 | + * @return true/false validation success or failure. | ||
159 | + */ | ||
160 | + public static boolean validateSubStatementsCardinality(GeneratedYangParser.ListStatementContext ctx) { | ||
161 | + | ||
162 | + if ((!ctx.keyStatement().isEmpty()) | ||
163 | + && (ctx.keyStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
164 | + yangConstruct = ParsableDataType.KEY_DATA; | ||
165 | + return false; | ||
166 | + } | ||
167 | + | ||
168 | + if ((!ctx.configStatement().isEmpty()) | ||
169 | + && (ctx.configStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
170 | + yangConstruct = ParsableDataType.CONFIG_DATA; | ||
171 | + return false; | ||
172 | + } | ||
173 | + | ||
174 | + if ((!ctx.maxElementsStatement().isEmpty()) | ||
175 | + && (ctx.maxElementsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
176 | + yangConstruct = ParsableDataType.MAX_ELEMENT_DATA; | ||
177 | + return false; | ||
178 | + } | ||
179 | + | ||
180 | + if ((!ctx.minElementsStatement().isEmpty()) | ||
181 | + && (ctx.minElementsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
182 | + yangConstruct = ParsableDataType.MIN_ELEMENT_DATA; | ||
183 | + return false; | ||
184 | + } | ||
185 | + | ||
186 | + if ((!ctx.descriptionStatement().isEmpty()) | ||
187 | + && (ctx.descriptionStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
188 | + yangConstruct = ParsableDataType.DESCRIPTION_DATA; | ||
189 | + return false; | ||
190 | + } | ||
191 | + | ||
192 | + if ((!ctx.referenceStatement().isEmpty()) | ||
193 | + && (ctx.referenceStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
194 | + yangConstruct = ParsableDataType.REFERENCE_DATA; | ||
195 | + return false; | ||
196 | + } | ||
197 | + | ||
198 | + if ((!ctx.statusStatement().isEmpty()) | ||
199 | + && (ctx.statusStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) { | ||
200 | + yangConstruct = ParsableDataType.STATUS_DATA; | ||
201 | + return false; | ||
202 | + } | ||
203 | + | ||
204 | + if (ctx.dataDefStatement().isEmpty()) { | ||
205 | + yangConstruct = ParsableDataType.LIST_DATA; | ||
206 | + return false; | ||
207 | + } | ||
208 | + | ||
209 | + return true; | ||
88 | } | 210 | } |
89 | } | 211 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MandatoryListener.java
... | @@ -16,8 +16,16 @@ | ... | @@ -16,8 +16,16 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
20 | +import org.onosproject.yangutils.parser.Parsable; | ||
21 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 22 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
23 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 24 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
25 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
26 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
27 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 29 | ||
22 | /* | 30 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 31 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -57,18 +65,27 @@ public final class MandatoryListener { | ... | @@ -57,18 +65,27 @@ public final class MandatoryListener { |
57 | */ | 65 | */ |
58 | public static void processMandatoryEntry(TreeWalkListener listener, | 66 | public static void processMandatoryEntry(TreeWalkListener listener, |
59 | GeneratedYangParser.MandatoryStatementContext ctx) { | 67 | GeneratedYangParser.MandatoryStatementContext ctx) { |
60 | - // TODO method implementation | ||
61 | - } | ||
62 | 68 | ||
63 | - /** | 69 | + // Check for stack to be non empty. |
64 | - * It is called when parser exits from grammar rule (mandatory), it performs | 70 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, |
65 | - * validation and updates the data model tree. | 71 | + ParsableDataType.MANDATORY_DATA, "", ListenerErrorLocation.ENTRY); |
66 | - * | 72 | + |
67 | - * @param listener listener's object. | 73 | + Parsable tmpNode = listener.getParsedDataStack().peek(); |
68 | - * @param ctx context object of the grammar rule. | 74 | + switch (tmpNode.getParsableDataType()) { |
69 | - */ | 75 | + case LEAF_DATA: |
70 | - public static void processMandatoryExit(TreeWalkListener listener, | 76 | + YangLeaf leaf = (YangLeaf) tmpNode; |
71 | - GeneratedYangParser.MandatoryStatementContext ctx) { | 77 | + if (ctx.TRUE_KEYWORD() != null) { |
72 | - // TODO method implementation | 78 | + leaf.setMandatory(true); |
79 | + } else { | ||
80 | + leaf.setMandatory(false); | ||
81 | + } | ||
82 | + break; | ||
83 | + case CHOICE_DATA: // TODO | ||
84 | + break; | ||
85 | + default: | ||
86 | + throw new ParserException(ListenerErrorMessageConstruction | ||
87 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
88 | + ParsableDataType.MANDATORY_DATA, "", ListenerErrorLocation.ENTRY)); | ||
89 | + } | ||
73 | } | 90 | } |
74 | } | 91 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,8 +16,17 @@ | ... | @@ -16,8 +16,17 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangLeafList; | ||
20 | +import org.onosproject.yangutils.datamodel.YangList; | ||
21 | +import org.onosproject.yangutils.parser.Parsable; | ||
22 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 23 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
24 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
26 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
27 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
29 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 30 | ||
22 | /* | 31 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 32 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -54,18 +63,33 @@ public final class MaxElementsListener { | ... | @@ -54,18 +63,33 @@ public final class MaxElementsListener { |
54 | */ | 63 | */ |
55 | public static void processMaxElementsEntry(TreeWalkListener listener, | 64 | public static void processMaxElementsEntry(TreeWalkListener listener, |
56 | GeneratedYangParser.MaxElementsStatementContext ctx) { | 65 | GeneratedYangParser.MaxElementsStatementContext ctx) { |
57 | - // TODO method implementation | 66 | + int maxElementsValue; |
58 | - } | ||
59 | 67 | ||
60 | - /** | 68 | + // Check for stack to be non empty. |
61 | - * It is called when parser exits from grammar rule (max-elements), it performs | 69 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, |
62 | - * validation and updates the data model tree. | 70 | + ParsableDataType.MAX_ELEMENT_DATA, "", ListenerErrorLocation.ENTRY); |
63 | - * | 71 | + |
64 | - * @param listener listener's object. | 72 | + if (ctx.maxValueArgument().UNBOUNDED_KEYWORD() != null) { |
65 | - * @param ctx context object of the grammar rule. | 73 | + maxElementsValue = Integer.MAX_VALUE; |
66 | - */ | 74 | + } else { |
67 | - public static void processMaxElementsExit(TreeWalkListener listener, | 75 | + maxElementsValue = Integer.parseInt(ctx.maxValueArgument().INTEGER().getText()); |
68 | - GeneratedYangParser.MaxElementsStatementContext ctx) { | 76 | + } |
69 | - // TODO method implementation | 77 | + |
78 | + Parsable tmpData = listener.getParsedDataStack().peek(); | ||
79 | + switch (tmpData.getParsableDataType()) { | ||
80 | + case LEAF_LIST_DATA: | ||
81 | + YangLeafList leafList = (YangLeafList) tmpData; | ||
82 | + leafList.setMaxElelements(maxElementsValue); | ||
83 | + break; | ||
84 | + case LIST_DATA: | ||
85 | + YangList yangList = (YangList) tmpData; | ||
86 | + yangList.setMaxElelements(maxElementsValue); | ||
87 | + break; | ||
88 | + default: | ||
89 | + throw new ParserException(ListenerErrorMessageConstruction | ||
90 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
91 | + ParsableDataType.MAX_ELEMENT_DATA, | ||
92 | + "", ListenerErrorLocation.ENTRY)); | ||
93 | + } | ||
70 | } | 94 | } |
71 | } | 95 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,8 +16,17 @@ | ... | @@ -16,8 +16,17 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangLeafList; | ||
20 | +import org.onosproject.yangutils.datamodel.YangList; | ||
21 | +import org.onosproject.yangutils.parser.Parsable; | ||
22 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 23 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
24 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
26 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
27 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
29 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 30 | ||
22 | /* | 31 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 32 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -55,18 +64,28 @@ public final class MinElementsListener { | ... | @@ -55,18 +64,28 @@ public final class MinElementsListener { |
55 | */ | 64 | */ |
56 | public static void processMinElementsEntry(TreeWalkListener listener, | 65 | public static void processMinElementsEntry(TreeWalkListener listener, |
57 | GeneratedYangParser.MinElementsStatementContext ctx) { | 66 | GeneratedYangParser.MinElementsStatementContext ctx) { |
58 | - // TODO method implementation | ||
59 | - } | ||
60 | 67 | ||
61 | - /** | 68 | + // Check for stack to be non empty. |
62 | - * It is called when parser exits from grammar rule (min-elements), it performs | 69 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, |
63 | - * validation and updates the data model tree. | 70 | + ParsableDataType.MIN_ELEMENT_DATA, String.valueOf(ctx.INTEGER().getText()), |
64 | - * | 71 | + ListenerErrorLocation.ENTRY); |
65 | - * @param listener listener's object. | 72 | + |
66 | - * @param ctx context object of the grammar rule. | 73 | + Parsable tmpData = listener.getParsedDataStack().peek(); |
67 | - */ | 74 | + switch (tmpData.getParsableDataType()) { |
68 | - public static void processMinElementsExit(TreeWalkListener listener, | 75 | + case LEAF_LIST_DATA: |
69 | - GeneratedYangParser.MinElementsStatementContext ctx) { | 76 | + YangLeafList leafList = (YangLeafList) tmpData; |
70 | - // TODO method implementation | 77 | + leafList.setMinElements(Integer.parseInt(ctx.INTEGER().getText())); |
78 | + break; | ||
79 | + case LIST_DATA: | ||
80 | + YangList yangList = (YangList) tmpData; | ||
81 | + yangList.setMinElements(Integer.parseInt(ctx.INTEGER().getText())); | ||
82 | + break; | ||
83 | + default: | ||
84 | + throw new ParserException(ListenerErrorMessageConstruction | ||
85 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
86 | + ParsableDataType.MIN_ELEMENT_DATA, | ||
87 | + String.valueOf(ctx.INTEGER().getText()), | ||
88 | + ListenerErrorLocation.ENTRY)); | ||
89 | + } | ||
71 | } | 90 | } |
72 | } | 91 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,8 +16,16 @@ | ... | @@ -16,8 +16,16 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
20 | +import org.onosproject.yangutils.parser.Parsable; | ||
21 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 22 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
23 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 24 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
25 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
26 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
27 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 29 | ||
22 | /* | 30 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 31 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -51,18 +59,22 @@ public final class PresenceListener { | ... | @@ -51,18 +59,22 @@ public final class PresenceListener { |
51 | */ | 59 | */ |
52 | public static void processPresenceEntry(TreeWalkListener listener, | 60 | public static void processPresenceEntry(TreeWalkListener listener, |
53 | GeneratedYangParser.PresenceStatementContext ctx) { | 61 | GeneratedYangParser.PresenceStatementContext ctx) { |
54 | - // TODO method implementation | ||
55 | - } | ||
56 | 62 | ||
57 | - /** | 63 | + // Check for stack to be non empty. |
58 | - * It is called when parser exits from grammar rule (presence), it performs | 64 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, |
59 | - * validation and updates the data model tree. | 65 | + ParsableDataType.PRESENCE_DATA, String.valueOf(ctx.string().getText()), |
60 | - * | 66 | + ListenerErrorLocation.ENTRY); |
61 | - * @param listener listener's object. | 67 | + |
62 | - * @param ctx context object of the grammar rule. | 68 | + Parsable tmpData = listener.getParsedDataStack().peek(); |
63 | - */ | 69 | + if (tmpData.getParsableDataType() == ParsableDataType.CONTAINER_DATA) { |
64 | - public static void processPresenceExit(TreeWalkListener listener, | 70 | + YangContainer container = (YangContainer) tmpData; |
65 | - GeneratedYangParser.PresenceStatementContext ctx) { | 71 | + container.setPresence(ctx.string().getText()); |
66 | - // TODO method implementation | 72 | + } else { |
73 | + throw new ParserException(ListenerErrorMessageConstruction | ||
74 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
75 | + ParsableDataType.PRESENCE_DATA, | ||
76 | + String.valueOf(ctx.string().getText()), | ||
77 | + ListenerErrorLocation.ENTRY)); | ||
78 | + } | ||
67 | } | 79 | } |
68 | } | 80 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ReferenceListener.java
... | @@ -16,8 +16,16 @@ | ... | @@ -16,8 +16,16 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangReference; | ||
20 | +import org.onosproject.yangutils.parser.Parsable; | ||
21 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 22 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
23 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 24 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
25 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
26 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
27 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 29 | ||
22 | /* | 30 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 31 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -51,18 +59,22 @@ public final class ReferenceListener { | ... | @@ -51,18 +59,22 @@ public final class ReferenceListener { |
51 | */ | 59 | */ |
52 | public static void processReferenceEntry(TreeWalkListener listener, | 60 | public static void processReferenceEntry(TreeWalkListener listener, |
53 | GeneratedYangParser.ReferenceStatementContext ctx) { | 61 | GeneratedYangParser.ReferenceStatementContext ctx) { |
54 | - // TODO method implementation | ||
55 | - } | ||
56 | 62 | ||
57 | - /** | 63 | + // Check for stack to be non empty. |
58 | - * It is called when parser exits from grammar rule (reference), it performs | 64 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, |
59 | - * validation and updates the data model tree. | 65 | + ParsableDataType.REFERENCE_DATA, String.valueOf(ctx.string().getText()), |
60 | - * | 66 | + ListenerErrorLocation.ENTRY); |
61 | - * @param listener listener's object. | 67 | + |
62 | - * @param ctx context object of the grammar rule. | 68 | + Parsable tmpData = listener.getParsedDataStack().peek(); |
63 | - */ | 69 | + if (tmpData instanceof YangReference) { |
64 | - public static void processReferenceExit(TreeWalkListener listener, | 70 | + YangReference reference = (YangReference) tmpData; |
65 | - GeneratedYangParser.ReferenceStatementContext ctx) { | 71 | + reference.setReference(ctx.string().getText()); |
66 | - // TODO method implementation | 72 | + } else { |
73 | + throw new ParserException(ListenerErrorMessageConstruction | ||
74 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
75 | + ParsableDataType.REFERENCE_DATA, | ||
76 | + String.valueOf(ctx.string().getText()), | ||
77 | + ListenerErrorLocation.ENTRY)); | ||
78 | + } | ||
67 | } | 79 | } |
68 | } | 80 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,8 +16,17 @@ | ... | @@ -16,8 +16,17 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangStatus; | ||
20 | +import org.onosproject.yangutils.datamodel.YangStatusType; | ||
21 | +import org.onosproject.yangutils.parser.Parsable; | ||
22 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 23 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
24 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
26 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
27 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
29 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 30 | ||
22 | /* | 31 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 32 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -56,18 +65,28 @@ public final class StatusListener { | ... | @@ -56,18 +65,28 @@ public final class StatusListener { |
56 | */ | 65 | */ |
57 | public static void processStatusEntry(TreeWalkListener listener, | 66 | public static void processStatusEntry(TreeWalkListener listener, |
58 | GeneratedYangParser.StatusStatementContext ctx) { | 67 | GeneratedYangParser.StatusStatementContext ctx) { |
59 | - // TODO method implementation | 68 | + YangStatusType status; |
60 | - } | ||
61 | 69 | ||
62 | - /** | 70 | + // Check for stack to be non empty. |
63 | - * It is called when parser exits from grammar rule (status), it performs | 71 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, |
64 | - * validation and updates the data model tree. | 72 | + ParsableDataType.STATUS_DATA, "", ListenerErrorLocation.ENTRY); |
65 | - * | 73 | + |
66 | - * @param listener listener's object. | 74 | + if (ctx.CURRENT_KEYWORD() != null) { |
67 | - * @param ctx context object of the grammar rule. | 75 | + status = YangStatusType.CURRENT.CURRENT; |
68 | - */ | 76 | + } else if (ctx.DEPRECATED_KEYWORD() != null) { |
69 | - public static void processStatusExit(TreeWalkListener listener, | 77 | + status = YangStatusType.DEPRECATED; |
70 | - GeneratedYangParser.StatusStatementContext ctx) { | 78 | + } else { |
71 | - // TODO method implementation | 79 | + status = YangStatusType.OBSOLETE.OBSOLETE; |
80 | + } | ||
81 | + | ||
82 | + Parsable tmpData = listener.getParsedDataStack().peek(); | ||
83 | + if (tmpData instanceof YangStatus) { | ||
84 | + YangStatus yangStatus = (YangStatus) tmpData; | ||
85 | + yangStatus.setStatus(status); | ||
86 | + } else { | ||
87 | + throw new ParserException(ListenerErrorMessageConstruction | ||
88 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
89 | + ParsableDataType.STATUS_DATA, "", ListenerErrorLocation.ENTRY)); | ||
90 | + } | ||
72 | } | 91 | } |
73 | } | 92 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,8 +16,19 @@ | ... | @@ -16,8 +16,19 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangDataTypes; | ||
20 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
21 | +import org.onosproject.yangutils.datamodel.YangLeafList; | ||
22 | +import org.onosproject.yangutils.datamodel.YangType; | ||
23 | +import org.onosproject.yangutils.parser.Parsable; | ||
24 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 25 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
26 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 27 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
29 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
30 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
31 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 32 | ||
22 | /* | 33 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 34 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -55,18 +66,35 @@ public final class TypeListener { | ... | @@ -55,18 +66,35 @@ public final class TypeListener { |
55 | */ | 66 | */ |
56 | public static void processTypeEntry(TreeWalkListener listener, | 67 | public static void processTypeEntry(TreeWalkListener listener, |
57 | GeneratedYangParser.TypeStatementContext ctx) { | 68 | GeneratedYangParser.TypeStatementContext ctx) { |
58 | - // TODO method implementation | ||
59 | - } | ||
60 | 69 | ||
61 | - /** | 70 | + // Check for stack to be non empty. |
62 | - * It is called when parser exits from grammar rule (type), it performs | 71 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, |
63 | - * validation and updates the data model tree. | 72 | + ParsableDataType.TYPE_DATA, String.valueOf(ctx.string().getText()), |
64 | - * | 73 | + ListenerErrorLocation.ENTRY); |
65 | - * @param listener listener's object. | 74 | + |
66 | - * @param ctx context object of the grammar rule. | 75 | + YangType type = new YangType(); |
67 | - */ | 76 | + YangDataTypes yangDataTypes = YangDataTypes.getType(ctx.string().getText()); |
68 | - public static void processTypeExit(TreeWalkListener listener, | 77 | + type.setDataTypeName(ctx.string().getText()); |
69 | - GeneratedYangParser.TypeStatementContext ctx) { | 78 | + type.setDataType(yangDataTypes); |
70 | - // TODO method implementation | 79 | + |
80 | + Parsable tmpData = listener.getParsedDataStack().peek(); | ||
81 | + switch (tmpData.getParsableDataType()) { | ||
82 | + case LEAF_DATA: | ||
83 | + YangLeaf leaf = (YangLeaf) tmpData; | ||
84 | + leaf.setDataType(type); | ||
85 | + break; | ||
86 | + case LEAF_LIST_DATA: | ||
87 | + YangLeafList leafList = (YangLeafList) tmpData; | ||
88 | + leafList.setDataType(type); | ||
89 | + break; | ||
90 | + case TYPEDEF_DATA: //TODO | ||
91 | + break; | ||
92 | + default: | ||
93 | + throw new ParserException(ListenerErrorMessageConstruction | ||
94 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
95 | + ParsableDataType.TYPE_DATA, | ||
96 | + String.valueOf(ctx.string().getText()), | ||
97 | + ListenerErrorLocation.ENTRY)); | ||
98 | + } | ||
71 | } | 99 | } |
72 | } | 100 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,8 +16,17 @@ | ... | @@ -16,8 +16,17 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
20 | +import org.onosproject.yangutils.datamodel.YangLeafList; | ||
21 | +import org.onosproject.yangutils.parser.Parsable; | ||
22 | +import org.onosproject.yangutils.parser.ParsableDataType; | ||
19 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 23 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
24 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
20 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
26 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation; | ||
27 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction; | ||
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType; | ||
29 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
21 | 30 | ||
22 | /* | 31 | /* |
23 | * Reference: RFC6020 and YANG ANTLR Grammar | 32 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -51,18 +60,31 @@ public final class UnitsListener { | ... | @@ -51,18 +60,31 @@ public final class UnitsListener { |
51 | */ | 60 | */ |
52 | public static void processUnitsEntry(TreeWalkListener listener, | 61 | public static void processUnitsEntry(TreeWalkListener listener, |
53 | GeneratedYangParser.UnitsStatementContext ctx) { | 62 | GeneratedYangParser.UnitsStatementContext ctx) { |
54 | - // TODO method implementation | ||
55 | - } | ||
56 | 63 | ||
57 | - /** | 64 | + // Check for stack to be non empty. |
58 | - * It is called when parser exits from grammar rule (units), it performs | 65 | + ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, |
59 | - * validation and updates the data model tree. | 66 | + ParsableDataType.UNITS_DATA, String.valueOf(ctx.string().getText()), |
60 | - * | 67 | + ListenerErrorLocation.ENTRY); |
61 | - * @param listener listener's object. | 68 | + |
62 | - * @param ctx context object of the grammar rule. | 69 | + Parsable tmpData = listener.getParsedDataStack().peek(); |
63 | - */ | 70 | + switch (tmpData.getParsableDataType()) { |
64 | - public static void processUnitsExit(TreeWalkListener listener, | 71 | + case LEAF_DATA: |
65 | - GeneratedYangParser.UnitsStatementContext ctx) { | 72 | + YangLeaf leaf = (YangLeaf) tmpData; |
66 | - // TODO method implementation | 73 | + leaf.setUnits(ctx.string().getText()); |
74 | + break; | ||
75 | + case LEAF_LIST_DATA: | ||
76 | + YangLeafList leafList = (YangLeafList) tmpData; | ||
77 | + leafList.setUnits(ctx.string().getText()); | ||
78 | + break; | ||
79 | + case TYPEDEF_DATA: | ||
80 | + // TODO | ||
81 | + break; | ||
82 | + default: | ||
83 | + throw new ParserException(ListenerErrorMessageConstruction | ||
84 | + .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, | ||
85 | + ParsableDataType.UNITS_DATA, | ||
86 | + String.valueOf(ctx.string().getText()), | ||
87 | + ListenerErrorLocation.ENTRY)); | ||
88 | + } | ||
67 | } | 89 | } |
68 | } | 90 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment