Committed by
Gerrit Code Review
[ONOS-4650][ONOS-4726][ONOS-4727] [ONOS-4728]Implement must parser + when parser…
… + feature + if-feature + revision defect fix Change-Id: I0a3aee6c1c6b72ef7da7f7f565fd0f149fe3fd42
Showing
79 changed files
with
2967 additions
and
200 deletions
... | @@ -29,5 +29,10 @@ public enum ResolvableType { | ... | @@ -29,5 +29,10 @@ public enum ResolvableType { |
29 | /** | 29 | /** |
30 | * Identifies the uses. | 30 | * Identifies the uses. |
31 | */ | 31 | */ |
32 | - YANG_USES | 32 | + YANG_USES, |
33 | + | ||
34 | + /** | ||
35 | + * Identifies the if-feature. | ||
36 | + */ | ||
37 | + YANG_IF_FEATURE | ||
33 | } | 38 | } | ... | ... |
... | @@ -65,14 +65,14 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -65,14 +65,14 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
65 | * | choice | 7.9 | 0..n |-child nodes | | 65 | * | choice | 7.9 | 0..n |-child nodes | |
66 | * | container | 7.5 | 0..n |-child nodes | | 66 | * | container | 7.5 | 0..n |-child nodes | |
67 | * | description | 7.19.3 | 0..1 |-string | | 67 | * | description | 7.19.3 | 0..1 |-string | |
68 | - * | if-feature | 7.18.2 | 0..n |-TODO | | 68 | + * | if-feature | 7.18.2 | 0..n |-YangIfFeature | |
69 | * | leaf | 7.6 | 0..n |-YangLeaf | | 69 | * | leaf | 7.6 | 0..n |-YangLeaf | |
70 | * | leaf-list | 7.7 | 0..n |-YangLeafList | | 70 | * | leaf-list | 7.7 | 0..n |-YangLeafList | |
71 | * | list | 7.8 | 0..n |-child nodes | | 71 | * | list | 7.8 | 0..n |-child nodes | |
72 | * | reference | 7.19.4 | 0..1 |-String | | 72 | * | reference | 7.19.4 | 0..1 |-String | |
73 | * | status | 7.19.2 | 0..1 |-YangStatus | | 73 | * | status | 7.19.2 | 0..1 |-YangStatus | |
74 | * | uses | 7.12 | 0..n |-child nodes | | 74 | * | uses | 7.12 | 0..n |-child nodes | |
75 | - * | when | 7.19.5 | 0..1 |-TODO | | 75 | + * | when | 7.19.5 | 0..1 |-YangWhen | |
76 | * +--------------+---------+-------------+------------------+ | 76 | * +--------------+---------+-------------+------------------+ |
77 | */ | 77 | */ |
78 | 78 | ||
... | @@ -81,7 +81,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -81,7 +81,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
81 | */ | 81 | */ |
82 | public class YangAugment | 82 | public class YangAugment |
83 | extends YangNode | 83 | extends YangNode |
84 | - implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector { | 84 | + implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangWhenHolder, YangIfFeatureHolder { |
85 | 85 | ||
86 | private static final long serialVersionUID = 806201602L; | 86 | private static final long serialVersionUID = 806201602L; |
87 | 87 | ||
... | @@ -121,6 +121,16 @@ public class YangAugment | ... | @@ -121,6 +121,16 @@ public class YangAugment |
121 | private YangStatusType status; | 121 | private YangStatusType status; |
122 | 122 | ||
123 | /** | 123 | /** |
124 | + * When data of the node. | ||
125 | + */ | ||
126 | + private YangWhen when; | ||
127 | + | ||
128 | + /** | ||
129 | + * List of if-feature. | ||
130 | + */ | ||
131 | + private List<YangIfFeature> ifFeatureList; | ||
132 | + | ||
133 | + /** | ||
124 | * Create a YANG augment node. | 134 | * Create a YANG augment node. |
125 | */ | 135 | */ |
126 | public YangAugment() { | 136 | public YangAugment() { |
... | @@ -146,6 +156,26 @@ public class YangAugment | ... | @@ -146,6 +156,26 @@ public class YangAugment |
146 | } | 156 | } |
147 | 157 | ||
148 | /** | 158 | /** |
159 | + * Returns the when. | ||
160 | + * | ||
161 | + * @return the when | ||
162 | + */ | ||
163 | + @Override | ||
164 | + public YangWhen getWhen() { | ||
165 | + return when; | ||
166 | + } | ||
167 | + | ||
168 | + /** | ||
169 | + * Sets the when. | ||
170 | + * | ||
171 | + * @param when the when to set | ||
172 | + */ | ||
173 | + @Override | ||
174 | + public void setWhen(YangWhen when) { | ||
175 | + this.when = when; | ||
176 | + } | ||
177 | + | ||
178 | + /** | ||
149 | * Returns the description. | 179 | * Returns the description. |
150 | * | 180 | * |
151 | * @return the description | 181 | * @return the description |
... | @@ -341,4 +371,21 @@ public class YangAugment | ... | @@ -341,4 +371,21 @@ public class YangAugment |
341 | this.name = name; | 371 | this.name = name; |
342 | } | 372 | } |
343 | 373 | ||
374 | + @Override | ||
375 | + public List<YangIfFeature> getIfFeatureList() { | ||
376 | + return ifFeatureList; | ||
377 | + } | ||
378 | + | ||
379 | + @Override | ||
380 | + public void addIfFeatureList(YangIfFeature ifFeature) { | ||
381 | + if (getIfFeatureList() == null) { | ||
382 | + setIfFeatureList(new LinkedList<>()); | ||
383 | + } | ||
384 | + getIfFeatureList().add(ifFeature); | ||
385 | + } | ||
386 | + | ||
387 | + @Override | ||
388 | + public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | ||
389 | + this.ifFeatureList = ifFeatureList; | ||
390 | + } | ||
344 | } | 391 | } | ... | ... |
... | @@ -78,14 +78,14 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_D | ... | @@ -78,14 +78,14 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_D |
78 | * | choice | 7.9 | 0..n |-child nodes | | 78 | * | choice | 7.9 | 0..n |-child nodes | |
79 | * | container | 7.5 | 0..n |-child nodes | | 79 | * | container | 7.5 | 0..n |-child nodes | |
80 | * | description | 7.19.3 | 0..1 |-string | | 80 | * | description | 7.19.3 | 0..1 |-string | |
81 | - * | if-feature | 7.18.2 | 0..n |-TODO | | 81 | + * | if-feature | 7.18.2 | 0..n |-YangIfFeature | |
82 | * | leaf | 7.6 | 0..n |-YangLeaf | | 82 | * | leaf | 7.6 | 0..n |-YangLeaf | |
83 | * | leaf-list | 7.7 | 0..n |-YangLeafList | | 83 | * | leaf-list | 7.7 | 0..n |-YangLeafList | |
84 | * | list | 7.8 | 0..n |-child nodes | | 84 | * | list | 7.8 | 0..n |-child nodes | |
85 | * | reference | 7.19.4 | 0..1 |-string | | 85 | * | reference | 7.19.4 | 0..1 |-string | |
86 | * | status | 7.19.2 | 0..1 |-YangStatus | | 86 | * | status | 7.19.2 | 0..1 |-YangStatus | |
87 | * | uses | 7.12 | 0..n |-child node | | 87 | * | uses | 7.12 | 0..n |-child node | |
88 | - * | when | 7.19.5 | 0..1 |-TODO | | 88 | + * | when | 7.19.5 | 0..1 |-YangWhen | |
89 | * +--------------+---------+-------------+------------------+ | 89 | * +--------------+---------+-------------+------------------+ |
90 | */ | 90 | */ |
91 | 91 | ||
... | @@ -94,7 +94,8 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_D | ... | @@ -94,7 +94,8 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_D |
94 | */ | 94 | */ |
95 | public class YangCase | 95 | public class YangCase |
96 | extends YangNode | 96 | extends YangNode |
97 | - implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder { | 97 | + implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder, |
98 | + YangWhenHolder, YangIfFeatureHolder { | ||
98 | 99 | ||
99 | private static final long serialVersionUID = 806201603L; | 100 | private static final long serialVersionUID = 806201603L; |
100 | 101 | ||
... | @@ -131,6 +132,16 @@ public class YangCase | ... | @@ -131,6 +132,16 @@ public class YangCase |
131 | private YangStatusType status; | 132 | private YangStatusType status; |
132 | 133 | ||
133 | /** | 134 | /** |
135 | + * When data of the node. | ||
136 | + */ | ||
137 | + private YangWhen when; | ||
138 | + | ||
139 | + /** | ||
140 | + * List of if-feature. | ||
141 | + */ | ||
142 | + private List<YangIfFeature> ifFeatureList; | ||
143 | + | ||
144 | + /** | ||
134 | * Creates a choice node. | 145 | * Creates a choice node. |
135 | */ | 146 | */ |
136 | public YangCase() { | 147 | public YangCase() { |
... | @@ -138,6 +149,26 @@ public class YangCase | ... | @@ -138,6 +149,26 @@ public class YangCase |
138 | } | 149 | } |
139 | 150 | ||
140 | /** | 151 | /** |
152 | + * Returns the when. | ||
153 | + * | ||
154 | + * @return the when | ||
155 | + */ | ||
156 | + @Override | ||
157 | + public YangWhen getWhen() { | ||
158 | + return when; | ||
159 | + } | ||
160 | + | ||
161 | + /** | ||
162 | + * Sets the when. | ||
163 | + * | ||
164 | + * @param when the when to set | ||
165 | + */ | ||
166 | + @Override | ||
167 | + public void setWhen(YangWhen when) { | ||
168 | + this.when = when; | ||
169 | + } | ||
170 | + | ||
171 | + /** | ||
141 | * Returns the case name. | 172 | * Returns the case name. |
142 | * | 173 | * |
143 | * @return case name | 174 | * @return case name |
... | @@ -343,4 +374,22 @@ public class YangCase | ... | @@ -343,4 +374,22 @@ public class YangCase |
343 | // Asks helper to detect colliding child. | 374 | // Asks helper to detect colliding child. |
344 | detectCollidingChildUtil(identifierName, dataType, this); | 375 | detectCollidingChildUtil(identifierName, dataType, this); |
345 | } | 376 | } |
377 | + | ||
378 | + @Override | ||
379 | + public List<YangIfFeature> getIfFeatureList() { | ||
380 | + return ifFeatureList; | ||
381 | + } | ||
382 | + | ||
383 | + @Override | ||
384 | + public void addIfFeatureList(YangIfFeature ifFeature) { | ||
385 | + if (getIfFeatureList() == null) { | ||
386 | + setIfFeatureList(new LinkedList<>()); | ||
387 | + } | ||
388 | + getIfFeatureList().add(ifFeature); | ||
389 | + } | ||
390 | + | ||
391 | + @Override | ||
392 | + public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | ||
393 | + this.ifFeatureList = ifFeatureList; | ||
394 | + } | ||
346 | } | 395 | } | ... | ... |
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.yangutils.datamodel; | 16 | package org.onosproject.yangutils.datamodel; |
17 | 17 | ||
18 | +import java.util.LinkedList; | ||
19 | +import java.util.List; | ||
18 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 20 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
19 | import org.onosproject.yangutils.datamodel.utils.Parsable; | 21 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
20 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; | 22 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
... | @@ -46,21 +48,23 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE | ... | @@ -46,21 +48,23 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE |
46 | * | container | 7.5 | 0..n |-child case nodes | | 48 | * | container | 7.5 | 0..n |-child case nodes | |
47 | * | default | 7.9.3 | 0..1 |-string | | 49 | * | default | 7.9.3 | 0..1 |-string | |
48 | * | description | 7.19.3 | 0..1 |-string | | 50 | * | description | 7.19.3 | 0..1 |-string | |
49 | - * | if-feature | 7.18.2 | 0..n |-TODO | | 51 | + * | if-feature | 7.18.2 | 0..n |-YangIfFeature | |
50 | * | leaf | 7.6 | 0..n |-child case nodes | | 52 | * | leaf | 7.6 | 0..n |-child case nodes | |
51 | * | leaf-list | 7.7 | 0..n |-child case nodes | | 53 | * | leaf-list | 7.7 | 0..n |-child case nodes | |
52 | * | list | 7.8 | 0..n |-child case nodes | | 54 | * | list | 7.8 | 0..n |-child case nodes | |
53 | * | mandatory | 7.9.4 | 0..1 |-string | | 55 | * | mandatory | 7.9.4 | 0..1 |-string | |
54 | * | reference | 7.19.4 | 0..1 |-string | | 56 | * | reference | 7.19.4 | 0..1 |-string | |
55 | * | status | 7.19.2 | 0..1 |-string | | 57 | * | status | 7.19.2 | 0..1 |-string | |
56 | - * | when | 7.19.5 | 0..1 |-TODO | | 58 | + * | when | 7.19.5 | 0..1 |-YangWhen | |
57 | * +--------------+---------+-------------+------------------+ | 59 | * +--------------+---------+-------------+------------------+ |
58 | */ | 60 | */ |
61 | + | ||
59 | /** | 62 | /** |
60 | * Represents data model node to maintain information defined in YANG choice. | 63 | * Represents data model node to maintain information defined in YANG choice. |
61 | */ | 64 | */ |
62 | public class YangChoice extends YangNode | 65 | public class YangChoice extends YangNode |
63 | - implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder { | 66 | + implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder, YangWhenHolder, |
67 | + YangIfFeatureHolder { | ||
64 | 68 | ||
65 | private static final long serialVersionUID = 806201604L; | 69 | private static final long serialVersionUID = 806201604L; |
66 | 70 | ||
... | @@ -143,6 +147,16 @@ public class YangChoice extends YangNode | ... | @@ -143,6 +147,16 @@ public class YangChoice extends YangNode |
143 | private String defaultValueInString; | 147 | private String defaultValueInString; |
144 | 148 | ||
145 | /** | 149 | /** |
150 | + * When data of the node. | ||
151 | + */ | ||
152 | + private YangWhen when; | ||
153 | + | ||
154 | + /** | ||
155 | + * List of if-feature. | ||
156 | + */ | ||
157 | + private List<YangIfFeature> ifFeatureList; | ||
158 | + | ||
159 | + /** | ||
146 | * Create a choice node. | 160 | * Create a choice node. |
147 | */ | 161 | */ |
148 | public YangChoice() { | 162 | public YangChoice() { |
... | @@ -150,6 +164,26 @@ public class YangChoice extends YangNode | ... | @@ -150,6 +164,26 @@ public class YangChoice extends YangNode |
150 | } | 164 | } |
151 | 165 | ||
152 | /** | 166 | /** |
167 | + * Returns the when. | ||
168 | + * | ||
169 | + * @return the when | ||
170 | + */ | ||
171 | + @Override | ||
172 | + public YangWhen getWhen() { | ||
173 | + return when; | ||
174 | + } | ||
175 | + | ||
176 | + /** | ||
177 | + * Sets the when. | ||
178 | + * | ||
179 | + * @param when the when to set | ||
180 | + */ | ||
181 | + @Override | ||
182 | + public void setWhen(YangWhen when) { | ||
183 | + this.when = when; | ||
184 | + } | ||
185 | + | ||
186 | + /** | ||
153 | * Returns the choice name. | 187 | * Returns the choice name. |
154 | * | 188 | * |
155 | * @return choice name | 189 | * @return choice name |
... | @@ -365,4 +399,23 @@ public class YangChoice extends YangNode | ... | @@ -365,4 +399,23 @@ public class YangChoice extends YangNode |
365 | node = node.getNextSibling(); | 399 | node = node.getNextSibling(); |
366 | } | 400 | } |
367 | } | 401 | } |
402 | + | ||
403 | + @Override | ||
404 | + public List<YangIfFeature> getIfFeatureList() { | ||
405 | + return ifFeatureList; | ||
406 | + } | ||
407 | + | ||
408 | + @Override | ||
409 | + public void addIfFeatureList(YangIfFeature ifFeature) { | ||
410 | + if (getIfFeatureList() == null) { | ||
411 | + setIfFeatureList(new LinkedList<>()); | ||
412 | + } | ||
413 | + getIfFeatureList().add(ifFeature); | ||
414 | + } | ||
415 | + | ||
416 | + @Override | ||
417 | + public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | ||
418 | + this.ifFeatureList = ifFeatureList; | ||
419 | + } | ||
420 | + | ||
368 | } | 421 | } | ... | ... |
... | @@ -70,17 +70,17 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -70,17 +70,17 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
70 | * | container | 7.5 | 0..n | -child nodes | | 70 | * | container | 7.5 | 0..n | -child nodes | |
71 | * | description | 7.19.3 | 0..1 | -string | | 71 | * | description | 7.19.3 | 0..1 | -string | |
72 | * | grouping | 7.11 | 0..n | -child nodes | | 72 | * | grouping | 7.11 | 0..n | -child nodes | |
73 | - * | if-feature | 7.18.2 | 0..n | -TODO | | 73 | + * | if-feature | 7.18.2 | 0..n | -YangIfFeature | |
74 | * | leaf | 7.6 | 0..n | -YangLeaf | | 74 | * | leaf | 7.6 | 0..n | -YangLeaf | |
75 | * | leaf-list | 7.7 | 0..n | -YangLeafList | | 75 | * | leaf-list | 7.7 | 0..n | -YangLeafList | |
76 | * | list | 7.8 | 0..n | -child nodes | | 76 | * | list | 7.8 | 0..n | -child nodes | |
77 | - * | must | 7.5.3 | 0..n | -TODO | | 77 | + * | must | 7.5.3 | 0..n | -YangMust | |
78 | * | presence | 7.5.5 | 0..1 | -boolean | | 78 | * | presence | 7.5.5 | 0..1 | -boolean | |
79 | * | reference | 7.19.4 | 0..1 | -string | | 79 | * | reference | 7.19.4 | 0..1 | -string | |
80 | * | status | 7.19.2 | 0..1 | -YangStatus | | 80 | * | status | 7.19.2 | 0..1 | -YangStatus | |
81 | * | typedef | 7.3 | 0..n | -child nodes | | 81 | * | typedef | 7.3 | 0..n | -child nodes | |
82 | * | uses | 7.12 | 0..n | -child nodes | | 82 | * | uses | 7.12 | 0..n | -child nodes | |
83 | - * | when | 7.19.5 | 0..1 | -TODO | | 83 | + * | when | 7.19.5 | 0..1 | -YangWhen | |
84 | * +--------------+---------+-------------+------------------+ | 84 | * +--------------+---------+-------------+------------------+ |
85 | */ | 85 | */ |
86 | 86 | ||
... | @@ -89,7 +89,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -89,7 +89,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
89 | */ | 89 | */ |
90 | public class YangContainer | 90 | public class YangContainer |
91 | extends YangNode | 91 | extends YangNode |
92 | - implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder { | 92 | + implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder, |
93 | + YangMustHolder, YangWhenHolder, YangIfFeatureHolder { | ||
93 | 94 | ||
94 | private static final long serialVersionUID = 806201605L; | 95 | private static final long serialVersionUID = 806201605L; |
95 | 96 | ||
... | @@ -135,6 +136,21 @@ public class YangContainer | ... | @@ -135,6 +136,21 @@ public class YangContainer |
135 | private YangStatusType status = YangStatusType.CURRENT; | 136 | private YangStatusType status = YangStatusType.CURRENT; |
136 | 137 | ||
137 | /** | 138 | /** |
139 | + * List of must statement constraints. | ||
140 | + */ | ||
141 | + private List<YangMust> mustConstraintList; | ||
142 | + | ||
143 | + /** | ||
144 | + * When data of the node. | ||
145 | + */ | ||
146 | + private YangWhen when; | ||
147 | + | ||
148 | + /** | ||
149 | + * List of if-feature. | ||
150 | + */ | ||
151 | + private List<YangIfFeature> ifFeatureList; | ||
152 | + | ||
153 | + /** | ||
138 | * Create a container node. | 154 | * Create a container node. |
139 | */ | 155 | */ |
140 | public YangContainer() { | 156 | public YangContainer() { |
... | @@ -142,6 +158,26 @@ public class YangContainer | ... | @@ -142,6 +158,26 @@ public class YangContainer |
142 | } | 158 | } |
143 | 159 | ||
144 | /** | 160 | /** |
161 | + * Returns the when. | ||
162 | + * | ||
163 | + * @return the when | ||
164 | + */ | ||
165 | + @Override | ||
166 | + public YangWhen getWhen() { | ||
167 | + return when; | ||
168 | + } | ||
169 | + | ||
170 | + /** | ||
171 | + * Sets the when. | ||
172 | + * | ||
173 | + * @param when the when to set | ||
174 | + */ | ||
175 | + @Override | ||
176 | + public void setWhen(YangWhen when) { | ||
177 | + this.when = when; | ||
178 | + } | ||
179 | + | ||
180 | + /** | ||
145 | * Returns the YANG name of container. | 181 | * Returns the YANG name of container. |
146 | * | 182 | * |
147 | * @return the name of container as defined in YANG file | 183 | * @return the name of container as defined in YANG file |
... | @@ -445,4 +481,41 @@ public class YangContainer | ... | @@ -445,4 +481,41 @@ public class YangContainer |
445 | + getName() + "\""); | 481 | + getName() + "\""); |
446 | } | 482 | } |
447 | } | 483 | } |
484 | + | ||
485 | + @Override | ||
486 | + public List<YangIfFeature> getIfFeatureList() { | ||
487 | + return ifFeatureList; | ||
488 | + } | ||
489 | + | ||
490 | + @Override | ||
491 | + public void addIfFeatureList(YangIfFeature ifFeature) { | ||
492 | + if (getIfFeatureList() == null) { | ||
493 | + setIfFeatureList(new LinkedList<>()); | ||
494 | + } | ||
495 | + getIfFeatureList().add(ifFeature); | ||
496 | + } | ||
497 | + | ||
498 | + @Override | ||
499 | + public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | ||
500 | + this.ifFeatureList = ifFeatureList; | ||
501 | + } | ||
502 | + | ||
503 | + @Override | ||
504 | + public List<YangMust> getListOfMust() { | ||
505 | + return mustConstraintList; | ||
506 | + } | ||
507 | + | ||
508 | + @Override | ||
509 | + public void setListOfMust(List<YangMust> mustConstraintList) { | ||
510 | + this.mustConstraintList = mustConstraintList; | ||
511 | + } | ||
512 | + | ||
513 | + @Override | ||
514 | + public void addMust(YangMust must) { | ||
515 | + if (getListOfMust() == null) { | ||
516 | + setListOfMust(new LinkedList<>()); | ||
517 | + } | ||
518 | + getListOfMust().add(must); | ||
519 | + } | ||
520 | + | ||
448 | } | 521 | } | ... | ... |
utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangFeature.java
0 → 100644
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.datamodel; | ||
18 | + | ||
19 | +import java.io.Serializable; | ||
20 | +import java.util.LinkedList; | ||
21 | +import java.util.List; | ||
22 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
23 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
24 | +import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ||
25 | + | ||
26 | +/* | ||
27 | + * Reference RFC 6020. | ||
28 | + * | ||
29 | + * The "feature" statement is used to define a mechanism by which | ||
30 | + * portions of the schema are marked as conditional. A feature name is | ||
31 | + * defined that can later be referenced using the "if-feature" statement. | ||
32 | + * Schema nodes tagged with a feature are ignored by the device unless | ||
33 | + * the device supports the given feature. This allows portions of the | ||
34 | + * YANG module to be conditional based on conditions on the device. | ||
35 | + * The model can represent the abilities of the device within the model, | ||
36 | + * giving a richer model that allows for differing device abilities and roles. | ||
37 | + * | ||
38 | + * The argument to the "feature" statement is the name of the new | ||
39 | + * feature, and follows the rules for identifiers. This name is used by the | ||
40 | + * "if-feature" statement to tie the schema nodes to the feature. | ||
41 | + * | ||
42 | + * The feature's Substatements | ||
43 | + * | ||
44 | + * +--------------+---------+-------------+------------------+ | ||
45 | + * | substatement | section | cardinality |data model mapping| | ||
46 | + * +--------------+---------+-------------+------------------+ | ||
47 | + * | description | 7.19.3 | 0..1 | -string | | ||
48 | + * | if-feature | 7.18.2 | 0..n | -YangIfFeature | | ||
49 | + * | reference | 7.19.4 | 0..1 | -string | | ||
50 | + * | status | 7.19.2 | 0..1 | -YangStatus | | ||
51 | + * +--------------+---------+-------------+------------------+ | ||
52 | + */ | ||
53 | + | ||
54 | +/** | ||
55 | + * Represents data model node to maintain information defined in YANG feature. | ||
56 | + */ | ||
57 | +public class YangFeature implements YangCommonInfo, Parsable, YangIfFeatureHolder, Serializable { | ||
58 | + | ||
59 | + private static final long serialVersionUID = 806201635L; | ||
60 | + | ||
61 | + /** | ||
62 | + * Name of the feature. | ||
63 | + */ | ||
64 | + private String name; | ||
65 | + | ||
66 | + /** | ||
67 | + * Description of feature. | ||
68 | + */ | ||
69 | + private String description; | ||
70 | + | ||
71 | + /** | ||
72 | + * Reference of the feature. | ||
73 | + */ | ||
74 | + private String reference; | ||
75 | + | ||
76 | + /** | ||
77 | + * Status of feature. | ||
78 | + */ | ||
79 | + private YangStatusType statusType; | ||
80 | + | ||
81 | + /** | ||
82 | + * List of if-feature. | ||
83 | + */ | ||
84 | + private List<YangIfFeature> ifFeatureList; | ||
85 | + | ||
86 | + @Override | ||
87 | + public String getDescription() { | ||
88 | + return description; | ||
89 | + } | ||
90 | + | ||
91 | + @Override | ||
92 | + public void setDescription(String description) { | ||
93 | + this.description = description; | ||
94 | + } | ||
95 | + | ||
96 | + @Override | ||
97 | + public String getReference() { | ||
98 | + return reference; | ||
99 | + } | ||
100 | + | ||
101 | + @Override | ||
102 | + public void setReference(String reference) { | ||
103 | + this.reference = reference; | ||
104 | + } | ||
105 | + | ||
106 | + @Override | ||
107 | + public YangStatusType getStatus() { | ||
108 | + return statusType; | ||
109 | + } | ||
110 | + | ||
111 | + @Override | ||
112 | + public void setStatus(YangStatusType status) { | ||
113 | + this.statusType = status; | ||
114 | + } | ||
115 | + | ||
116 | + public String getName() { | ||
117 | + return name; | ||
118 | + } | ||
119 | + | ||
120 | + public void setName(String name) { | ||
121 | + this.name = name; | ||
122 | + } | ||
123 | + | ||
124 | + @Override | ||
125 | + public YangConstructType getYangConstructType() { | ||
126 | + return YangConstructType.FEATURE_DATA; | ||
127 | + } | ||
128 | + | ||
129 | + @Override | ||
130 | + public void validateDataOnEntry() throws DataModelException { | ||
131 | + //TODO : To be implemented | ||
132 | + } | ||
133 | + | ||
134 | + @Override | ||
135 | + public void validateDataOnExit() throws DataModelException { | ||
136 | + //TODO : To be implemented | ||
137 | + } | ||
138 | + | ||
139 | + @Override | ||
140 | + public List<YangIfFeature> getIfFeatureList() { | ||
141 | + return ifFeatureList; | ||
142 | + } | ||
143 | + | ||
144 | + @Override | ||
145 | + public void addIfFeatureList(YangIfFeature ifFeature) { | ||
146 | + if (getIfFeatureList() == null) { | ||
147 | + setIfFeatureList(new LinkedList<>()); | ||
148 | + } | ||
149 | + getIfFeatureList().add(ifFeature); | ||
150 | + } | ||
151 | + | ||
152 | + @Override | ||
153 | + public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | ||
154 | + this.ifFeatureList = ifFeatureList; | ||
155 | + } | ||
156 | +} |
utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangFeatureHolder.java
0 → 100644
1 | +/*Copyright 2016.year Open Networking Laboratory | ||
2 | + | ||
3 | +Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | +you may not use this file except in compliance with the License. | ||
5 | +You may obtain a copy of the License at | ||
6 | + | ||
7 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | +Unless required by applicable law or agreed to in writing, software | ||
10 | +distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | +See the License for the specific language governing permissions and | ||
13 | +limitations under the License.*/ | ||
14 | + | ||
15 | +package org.onosproject.yangutils.datamodel; | ||
16 | + | ||
17 | +import java.util.List; | ||
18 | + | ||
19 | +/** | ||
20 | + * Abstraction of feature entity. It is used to abstract the data holders of feature. | ||
21 | + */ | ||
22 | +public interface YangFeatureHolder { | ||
23 | + | ||
24 | + /** | ||
25 | + * Returns the list of feature from data holder like container / list. | ||
26 | + * | ||
27 | + * @return the list of feature | ||
28 | + */ | ||
29 | + List<YangFeature> getFeatureList(); | ||
30 | + | ||
31 | + /** | ||
32 | + * Adds feature in feature list. | ||
33 | + * | ||
34 | + * @param feature the feature to be added | ||
35 | + */ | ||
36 | + void addFeatureList(YangFeature feature); | ||
37 | + | ||
38 | + /** | ||
39 | + * Sets the list of feature. | ||
40 | + * | ||
41 | + * @param listOfFeature the list of feature to set | ||
42 | + */ | ||
43 | + void setListOfFeature(List<YangFeature> listOfFeature); | ||
44 | +} |
utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIfFeature.java
0 → 100644
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.datamodel; | ||
18 | + | ||
19 | +import java.io.Serializable; | ||
20 | +import java.util.Iterator; | ||
21 | +import java.util.List; | ||
22 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
23 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
24 | +import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; | ||
25 | +import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ||
26 | + | ||
27 | +/* | ||
28 | + * Reference RFC 6020. | ||
29 | + * | ||
30 | + * The "if-feature" statement makes its parent statement conditional. | ||
31 | + * The argument is the name of a feature, as defined by a "feature" | ||
32 | + * statement. The parent statement is implemented by servers that | ||
33 | + * support this feature. If a prefix is present on the feature name, it | ||
34 | + * refers to a feature defined in the module that was imported with that | ||
35 | + * prefix, or the local module if the prefix matches the local module's | ||
36 | + * prefix. Otherwise, a feature with the matching name MUST be defined | ||
37 | + * in the current module or an included submodule. | ||
38 | + * | ||
39 | + * Since submodules cannot include the parent module, any features in | ||
40 | + * the module that need to be exposed to submodules MUST be defined in a | ||
41 | + * submodule. Submodules can then include this submodule to find the | ||
42 | + * definition of the feature. | ||
43 | + */ | ||
44 | + | ||
45 | +/** | ||
46 | + * Represents data model node to maintain information defined in YANG if-feature. | ||
47 | + */ | ||
48 | +public class YangIfFeature implements Parsable, Resolvable, Serializable { | ||
49 | + | ||
50 | + private static final long serialVersionUID = 806201635L; | ||
51 | + | ||
52 | + /** | ||
53 | + * if-feature argument. | ||
54 | + */ | ||
55 | + YangNodeIdentifier name; | ||
56 | + | ||
57 | + /** | ||
58 | + * Referred feature information. | ||
59 | + */ | ||
60 | + YangFeature referredFeature; | ||
61 | + | ||
62 | + /** | ||
63 | + * Referred feature parent information. | ||
64 | + */ | ||
65 | + YangNode referredFeatureHolder; | ||
66 | + | ||
67 | + /** | ||
68 | + * Status of resolution. If completely resolved enum value is "RESOLVED", | ||
69 | + * if not enum value is "UNRESOLVED", in case reference of grouping/typedef | ||
70 | + * is added to uses/type but it's not resolved value of enum should be | ||
71 | + * "INTRA_FILE_RESOLVED". | ||
72 | + */ | ||
73 | + private ResolvableStatus resolvableStatus; | ||
74 | + | ||
75 | + /** | ||
76 | + * Returns referred feature holder. | ||
77 | + * | ||
78 | + * @return referred feature holder | ||
79 | + */ | ||
80 | + public YangNode getReferredFeatureHolder() { | ||
81 | + return referredFeatureHolder; | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Sets the referred feature holder. | ||
86 | + * | ||
87 | + * @param referredFeatureHolder referred feature holder | ||
88 | + */ | ||
89 | + public void setReferredFeatureHolder(YangNode referredFeatureHolder) { | ||
90 | + this.referredFeatureHolder = referredFeatureHolder; | ||
91 | + } | ||
92 | + | ||
93 | + /** | ||
94 | + * Returns prefix associated with identifier. | ||
95 | + * | ||
96 | + * @return prefix associated with identifier | ||
97 | + */ | ||
98 | + public String getPrefix() { | ||
99 | + return name.getPrefix(); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * Sets prefix associated with identifier. | ||
104 | + * | ||
105 | + * @param prefix prefix associated with identifier | ||
106 | + */ | ||
107 | + public void setPrefix(String prefix) { | ||
108 | + name.setPrefix(prefix); | ||
109 | + } | ||
110 | + | ||
111 | + /** | ||
112 | + * Returns referred feature associated with if-feature. | ||
113 | + * | ||
114 | + * @return referred feature associated with if-feature | ||
115 | + */ | ||
116 | + public YangFeature getReferredFeature() { | ||
117 | + return referredFeature; | ||
118 | + } | ||
119 | + | ||
120 | + /** | ||
121 | + * Sets referred feature associated with if-feature. | ||
122 | + * | ||
123 | + * @param referredFeature referred feature associated with if-feature | ||
124 | + */ | ||
125 | + public void setReferredFeature(YangFeature referredFeature) { | ||
126 | + this.referredFeature = referredFeature; | ||
127 | + } | ||
128 | + | ||
129 | + /** | ||
130 | + * Returns the YANG name of if-feature. | ||
131 | + * | ||
132 | + * @return the name of if-feature as defined in YANG file | ||
133 | + */ | ||
134 | + public YangNodeIdentifier getName() { | ||
135 | + return name; | ||
136 | + } | ||
137 | + | ||
138 | + /** | ||
139 | + * Sets the YANG name of if-feature. | ||
140 | + * | ||
141 | + * @param name the name of if-feature as defined in YANG file | ||
142 | + */ | ||
143 | + public void setName(YangNodeIdentifier name) { | ||
144 | + this.name = name; | ||
145 | + } | ||
146 | + | ||
147 | + @Override | ||
148 | + public YangConstructType getYangConstructType() { | ||
149 | + return YangConstructType.IF_FEATURE_DATA; | ||
150 | + } | ||
151 | + | ||
152 | + @Override | ||
153 | + public void validateDataOnEntry() throws DataModelException { | ||
154 | + // do nothing, no validation required for if-feature | ||
155 | + } | ||
156 | + | ||
157 | + @Override | ||
158 | + public void validateDataOnExit() throws DataModelException { | ||
159 | + // do nothing, no validation required for if-feature | ||
160 | + } | ||
161 | + | ||
162 | + @Override | ||
163 | + public ResolvableStatus getResolvableStatus() { | ||
164 | + return resolvableStatus; | ||
165 | + } | ||
166 | + | ||
167 | + @Override | ||
168 | + public void setResolvableStatus(ResolvableStatus resolvableStatus) { | ||
169 | + this.resolvableStatus = resolvableStatus; | ||
170 | + } | ||
171 | + | ||
172 | + @Override | ||
173 | + public void resolve() throws DataModelException { | ||
174 | + YangFeature feature = getReferredFeature(); | ||
175 | + | ||
176 | + // check whether feature has if-feature | ||
177 | + List<YangIfFeature> ifFeatureList = feature.getIfFeatureList(); | ||
178 | + if (ifFeatureList != null && !ifFeatureList.isEmpty()) { | ||
179 | + Iterator<YangIfFeature> ifFeatureIterator = ifFeatureList.iterator(); | ||
180 | + while (ifFeatureIterator.hasNext()) { | ||
181 | + YangIfFeature ifFeature = ifFeatureIterator.next(); | ||
182 | + if (ifFeature.getResolvableStatus() != ResolvableStatus.RESOLVED) { | ||
183 | + setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED); | ||
184 | + return; | ||
185 | + } | ||
186 | + } | ||
187 | + } | ||
188 | + } | ||
189 | +} |
utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIfFeatureHolder.java
0 → 100644
1 | +/*Copyright 2016.year Open Networking Laboratory | ||
2 | + | ||
3 | +Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | +you may not use this file except in compliance with the License. | ||
5 | +You may obtain a copy of the License at | ||
6 | + | ||
7 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | + | ||
9 | +Unless required by applicable law or agreed to in writing, software | ||
10 | +distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | +See the License for the specific language governing permissions and | ||
13 | +limitations under the License.*/ | ||
14 | + | ||
15 | +package org.onosproject.yangutils.datamodel; | ||
16 | + | ||
17 | +import java.util.List; | ||
18 | + | ||
19 | +/** | ||
20 | + * Abstraction of if-feature entity. It is used to abstract the data holders of if-feature. | ||
21 | + */ | ||
22 | +public interface YangIfFeatureHolder { | ||
23 | + | ||
24 | + /** | ||
25 | + * Returns the list of if-feature from data holder like container / list. | ||
26 | + * | ||
27 | + * @return the list of if-feature | ||
28 | + */ | ||
29 | + List<YangIfFeature> getIfFeatureList(); | ||
30 | + | ||
31 | + /** | ||
32 | + * Adds if-feature in if-feature list. | ||
33 | + * | ||
34 | + * @param ifFeature the if-feature to be added | ||
35 | + */ | ||
36 | + void addIfFeatureList(YangIfFeature ifFeature); | ||
37 | + | ||
38 | + /** | ||
39 | + * Sets the list of if-feature. | ||
40 | + * | ||
41 | + * @param ifFeatureList the list of if-feature to set | ||
42 | + */ | ||
43 | + void setIfFeatureList(List<YangIfFeature> ifFeatureList); | ||
44 | +} |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.yangutils.datamodel; | 16 | package org.onosproject.yangutils.datamodel; |
17 | 17 | ||
18 | import java.io.Serializable; | 18 | import java.io.Serializable; |
19 | +import java.util.Date; | ||
19 | import java.util.Set; | 20 | import java.util.Set; |
20 | 21 | ||
21 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
... | @@ -61,7 +62,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findRefer | ... | @@ -61,7 +62,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findRefer |
61 | * | substatement | section | cardinality |data model mapping| | 62 | * | substatement | section | cardinality |data model mapping| |
62 | * +---------------+---------+-------------+------------------+ | 63 | * +---------------+---------+-------------+------------------+ |
63 | * | prefix | 7.1.4 | 1 | string | | 64 | * | prefix | 7.1.4 | 1 | string | |
64 | - * | revision-date | 7.1.5.1 | 0..1 | string | | 65 | + * | revision-date | 7.1.5.1 | 0..1 | Date | |
65 | * +---------------+---------+-------------+------------------+ | 66 | * +---------------+---------+-------------+------------------+ |
66 | */ | 67 | */ |
67 | 68 | ||
... | @@ -91,7 +92,7 @@ public class YangImport | ... | @@ -91,7 +92,7 @@ public class YangImport |
91 | * the most recent "revision" statement in the imported module. organization | 92 | * the most recent "revision" statement in the imported module. organization |
92 | * which defined the YANG module. | 93 | * which defined the YANG module. |
93 | */ | 94 | */ |
94 | - private String revision; | 95 | + private Date revision; |
95 | 96 | ||
96 | /** | 97 | /** |
97 | * Reference to node which is imported. | 98 | * Reference to node which is imported. |
... | @@ -152,7 +153,7 @@ public class YangImport | ... | @@ -152,7 +153,7 @@ public class YangImport |
152 | * | 153 | * |
153 | * @return the revision of the imported module | 154 | * @return the revision of the imported module |
154 | */ | 155 | */ |
155 | - public String getRevision() { | 156 | + public Date getRevision() { |
156 | return revision; | 157 | return revision; |
157 | } | 158 | } |
158 | 159 | ||
... | @@ -161,7 +162,7 @@ public class YangImport | ... | @@ -161,7 +162,7 @@ public class YangImport |
161 | * | 162 | * |
162 | * @param rev set the revision of the imported module | 163 | * @param rev set the revision of the imported module |
163 | */ | 164 | */ |
164 | - public void setRevision(String rev) { | 165 | + public void setRevision(Date rev) { |
165 | revision = rev; | 166 | revision = rev; |
166 | } | 167 | } |
167 | 168 | ||
... | @@ -245,7 +246,7 @@ public class YangImport | ... | @@ -245,7 +246,7 @@ public class YangImport |
245 | */ | 246 | */ |
246 | public void addReferenceToImport(Set<YangNode> yangNodeSet) throws DataModelException { | 247 | public void addReferenceToImport(Set<YangNode> yangNodeSet) throws DataModelException { |
247 | String importedModuleName = getModuleName(); | 248 | String importedModuleName = getModuleName(); |
248 | - String importedModuleRevision = getRevision(); | 249 | + Date importedModuleRevision = getRevision(); |
249 | YangNode moduleNode = null; | 250 | YangNode moduleNode = null; |
250 | /* | 251 | /* |
251 | * Find the imported module node for a given module name with a | 252 | * Find the imported module node for a given module name with a |
... | @@ -266,7 +267,7 @@ public class YangImport | ... | @@ -266,7 +267,7 @@ public class YangImport |
266 | 267 | ||
267 | if (moduleNode != null) { | 268 | if (moduleNode != null) { |
268 | if (moduleNode instanceof YangModule) { | 269 | if (moduleNode instanceof YangModule) { |
269 | - if (getRevision() == null || getRevision().isEmpty()) { | 270 | + if (getRevision() == null) { |
270 | setImportedNode(moduleNode); | 271 | setImportedNode(moduleNode); |
271 | return; | 272 | return; |
272 | } | 273 | } | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.yangutils.datamodel; | 16 | package org.onosproject.yangutils.datamodel; |
17 | 17 | ||
18 | import java.io.Serializable; | 18 | import java.io.Serializable; |
19 | +import java.util.Date; | ||
19 | import java.util.Set; | 20 | import java.util.Set; |
20 | 21 | ||
21 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
... | @@ -56,7 +57,7 @@ public class YangInclude | ... | @@ -56,7 +57,7 @@ public class YangInclude |
56 | * The include's "revision-date" statement is used to specify the exact | 57 | * The include's "revision-date" statement is used to specify the exact |
57 | * version of the submodule to import. | 58 | * version of the submodule to import. |
58 | */ | 59 | */ |
59 | - private String revision; | 60 | + private Date revision; |
60 | 61 | ||
61 | /** | 62 | /** |
62 | * Reference to node which is included. | 63 | * Reference to node which is included. |
... | @@ -98,7 +99,7 @@ public class YangInclude | ... | @@ -98,7 +99,7 @@ public class YangInclude |
98 | * | 99 | * |
99 | * @return the revision | 100 | * @return the revision |
100 | */ | 101 | */ |
101 | - public String getRevision() { | 102 | + public Date getRevision() { |
102 | return revision; | 103 | return revision; |
103 | } | 104 | } |
104 | 105 | ||
... | @@ -107,7 +108,7 @@ public class YangInclude | ... | @@ -107,7 +108,7 @@ public class YangInclude |
107 | * | 108 | * |
108 | * @param revision the revision to set | 109 | * @param revision the revision to set |
109 | */ | 110 | */ |
110 | - public void setRevision(String revision) { | 111 | + public void setRevision(Date revision) { |
111 | this.revision = revision; | 112 | this.revision = revision; |
112 | } | 113 | } |
113 | 114 | ||
... | @@ -182,7 +183,7 @@ public class YangInclude | ... | @@ -182,7 +183,7 @@ public class YangInclude |
182 | */ | 183 | */ |
183 | public YangSubModule addReferenceToInclude(Set<YangNode> yangNodeSet) throws DataModelException { | 184 | public YangSubModule addReferenceToInclude(Set<YangNode> yangNodeSet) throws DataModelException { |
184 | String includedSubModuleName = getSubModuleName(); | 185 | String includedSubModuleName = getSubModuleName(); |
185 | - String includedSubModuleRevision = getRevision(); | 186 | + Date includedSubModuleRevision = getRevision(); |
186 | YangNode subModuleNode = null; | 187 | YangNode subModuleNode = null; |
187 | 188 | ||
188 | /* | 189 | /* |
... | @@ -204,7 +205,7 @@ public class YangInclude | ... | @@ -204,7 +205,7 @@ public class YangInclude |
204 | 205 | ||
205 | if (subModuleNode != null) { | 206 | if (subModuleNode != null) { |
206 | if (subModuleNode instanceof YangSubModule) { | 207 | if (subModuleNode instanceof YangSubModule) { |
207 | - if (getRevision() == null || getRevision().isEmpty()) { | 208 | + if (getRevision() == null) { |
208 | setIncludedNode(subModuleNode); | 209 | setIncludedNode(subModuleNode); |
209 | return (YangSubModule) subModuleNode; | 210 | return (YangSubModule) subModuleNode; |
210 | } | 211 | } | ... | ... |
... | @@ -17,7 +17,8 @@ | ... | @@ -17,7 +17,8 @@ |
17 | package org.onosproject.yangutils.datamodel; | 17 | package org.onosproject.yangutils.datamodel; |
18 | 18 | ||
19 | import java.io.Serializable; | 19 | import java.io.Serializable; |
20 | - | 20 | +import java.util.LinkedList; |
21 | +import java.util.List; | ||
21 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
22 | import org.onosproject.yangutils.datamodel.utils.Parsable; | 23 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
23 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; | 24 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
... | @@ -43,16 +44,16 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ... | @@ -43,16 +44,16 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
43 | * | substatement | section | cardinality |data model mapping| | 44 | * | substatement | section | cardinality |data model mapping| |
44 | * +--------------+---------+-------------+------------------+ | 45 | * +--------------+---------+-------------+------------------+ |
45 | * | config | 7.19.1 | 0..1 | - boolean | | 46 | * | config | 7.19.1 | 0..1 | - boolean | |
46 | - * | default | 7.6.4 | 0..1 | - TODO | | 47 | + * | default | 7.6.4 | 0..1 | - string | |
47 | * | description | 7.19.3 | 0..1 | - string | | 48 | * | description | 7.19.3 | 0..1 | - string | |
48 | - * | if-feature | 7.18.2 | 0..n | - TODO | | 49 | + * | if-feature | 7.18.2 | 0..n | - YangIfFeature | |
49 | * | mandatory | 7.6.5 | 0..1 | - boolean | | 50 | * | mandatory | 7.6.5 | 0..1 | - boolean | |
50 | - * | must | 7.5.3 | 0..n | - TODO | | 51 | + * | must | 7.5.3 | 0..n | - YangMust | |
51 | * | reference | 7.19.4 | 0..1 | - string | | 52 | * | reference | 7.19.4 | 0..1 | - string | |
52 | * | status | 7.19.2 | 0..1 | - YangStatus | | 53 | * | status | 7.19.2 | 0..1 | - YangStatus | |
53 | * | type | 7.6.3 | 1 | - YangType | | 54 | * | type | 7.6.3 | 1 | - YangType | |
54 | * | units | 7.3.3 | 0..1 | - String | | 55 | * | units | 7.3.3 | 0..1 | - String | |
55 | - * | when | 7.19.5 | 0..1 | - TODO | | 56 | + * | when | 7.19.5 | 0..1 | - YangWhen | |
56 | * +--------------+---------+-------------+------------------+ | 57 | * +--------------+---------+-------------+------------------+ |
57 | */ | 58 | */ |
58 | 59 | ||
... | @@ -60,7 +61,8 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ... | @@ -60,7 +61,8 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
60 | * Represents leaf data represented in YANG. | 61 | * Represents leaf data represented in YANG. |
61 | */ | 62 | */ |
62 | public class YangLeaf | 63 | public class YangLeaf |
63 | - implements YangCommonInfo, Parsable, Cloneable, Serializable { | 64 | + implements YangCommonInfo, Parsable, Cloneable, Serializable, |
65 | + YangMustHolder, YangIfFeatureHolder, YangWhenHolder { | ||
64 | 66 | ||
65 | private static final long serialVersionUID = 806201635L; | 67 | private static final long serialVersionUID = 806201635L; |
66 | 68 | ||
... | @@ -111,11 +113,26 @@ public class YangLeaf | ... | @@ -111,11 +113,26 @@ public class YangLeaf |
111 | private String defaultValueInString; | 113 | private String defaultValueInString; |
112 | 114 | ||
113 | /** | 115 | /** |
116 | + * When data of the leaf. | ||
117 | + */ | ||
118 | + private YangWhen when; | ||
119 | + | ||
120 | + /** | ||
114 | * YANG Node in which the leaf is contained. | 121 | * YANG Node in which the leaf is contained. |
115 | */ | 122 | */ |
116 | private transient YangLeavesHolder containedIn; | 123 | private transient YangLeavesHolder containedIn; |
117 | 124 | ||
118 | /** | 125 | /** |
126 | + * List of must statement constraints. | ||
127 | + */ | ||
128 | + private List<YangMust> mustConstraintList; | ||
129 | + | ||
130 | + /** | ||
131 | + * List of if-feature. | ||
132 | + */ | ||
133 | + private List<YangIfFeature> ifFeatureList; | ||
134 | + | ||
135 | + /** | ||
119 | * Creates a YANG leaf. | 136 | * Creates a YANG leaf. |
120 | */ | 137 | */ |
121 | public YangLeaf() { | 138 | public YangLeaf() { |
... | @@ -158,6 +175,26 @@ public class YangLeaf | ... | @@ -158,6 +175,26 @@ public class YangLeaf |
158 | } | 175 | } |
159 | 176 | ||
160 | /** | 177 | /** |
178 | + * Returns the when. | ||
179 | + * | ||
180 | + * @return the when | ||
181 | + */ | ||
182 | + @Override | ||
183 | + public YangWhen getWhen() { | ||
184 | + return when; | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * Sets the when. | ||
189 | + * | ||
190 | + * @param when the when to set | ||
191 | + */ | ||
192 | + @Override | ||
193 | + public void setWhen(YangWhen when) { | ||
194 | + this.when = when; | ||
195 | + } | ||
196 | + | ||
197 | + /** | ||
161 | * Returns the description. | 198 | * Returns the description. |
162 | * | 199 | * |
163 | * @return the description | 200 | * @return the description |
... | @@ -346,4 +383,40 @@ public class YangLeaf | ... | @@ -346,4 +383,40 @@ public class YangLeaf |
346 | // TODO auto-generated method stub, to be implemented by parser | 383 | // TODO auto-generated method stub, to be implemented by parser |
347 | 384 | ||
348 | } | 385 | } |
386 | + | ||
387 | + @Override | ||
388 | + public List<YangMust> getListOfMust() { | ||
389 | + return mustConstraintList; | ||
390 | + } | ||
391 | + | ||
392 | + @Override | ||
393 | + public void setListOfMust(List<YangMust> mustConstraintList) { | ||
394 | + this.mustConstraintList = mustConstraintList; | ||
395 | + } | ||
396 | + | ||
397 | + @Override | ||
398 | + public void addMust(YangMust must) { | ||
399 | + if (getListOfMust() == null) { | ||
400 | + setListOfMust(new LinkedList<>()); | ||
401 | + } | ||
402 | + getListOfMust().add(must); | ||
403 | + } | ||
404 | + | ||
405 | + @Override | ||
406 | + public List<YangIfFeature> getIfFeatureList() { | ||
407 | + return ifFeatureList; | ||
408 | + } | ||
409 | + | ||
410 | + @Override | ||
411 | + public void addIfFeatureList(YangIfFeature ifFeature) { | ||
412 | + if (getIfFeatureList() == null) { | ||
413 | + setIfFeatureList(new LinkedList<>()); | ||
414 | + } | ||
415 | + getIfFeatureList().add(ifFeature); | ||
416 | + } | ||
417 | + | ||
418 | + @Override | ||
419 | + public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | ||
420 | + this.ifFeatureList = ifFeatureList; | ||
421 | + } | ||
349 | } | 422 | } | ... | ... |
... | @@ -17,7 +17,8 @@ | ... | @@ -17,7 +17,8 @@ |
17 | package org.onosproject.yangutils.datamodel; | 17 | package org.onosproject.yangutils.datamodel; |
18 | 18 | ||
19 | import java.io.Serializable; | 19 | import java.io.Serializable; |
20 | - | 20 | +import java.util.LinkedList; |
21 | +import java.util.List; | ||
21 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 22 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
22 | import org.onosproject.yangutils.datamodel.utils.Parsable; | 23 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
23 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; | 24 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
... | @@ -39,16 +40,16 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ... | @@ -39,16 +40,16 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
39 | * +--------------+---------+-------------+------------------+ | 40 | * +--------------+---------+-------------+------------------+ |
40 | * | config | 7.19.1 | 0..1 | -boolean | | 41 | * | config | 7.19.1 | 0..1 | -boolean | |
41 | * | description | 7.19.3 | 0..1 | -string | | 42 | * | description | 7.19.3 | 0..1 | -string | |
42 | - * | if-feature | 7.18.2 | 0..n | -TODO | | 43 | + * | if-feature | 7.18.2 | 0..n | -YangIfFeature | |
43 | * | max-elements | 7.7.4 | 0..1 | -int | | 44 | * | max-elements | 7.7.4 | 0..1 | -int | |
44 | * | min-elements | 7.7.3 | 0..1 | -int | | 45 | * | min-elements | 7.7.3 | 0..1 | -int | |
45 | - * | must | 7.5.3 | 0..n | -TODO | | 46 | + * | must | 7.5.3 | 0..n | -YangMust | |
46 | * | ordered-by | 7.7.5 | 0..1 | -TODO | | 47 | * | ordered-by | 7.7.5 | 0..1 | -TODO | |
47 | * | reference | 7.19.4 | 0..1 | -string | | 48 | * | reference | 7.19.4 | 0..1 | -string | |
48 | * | status | 7.19.2 | 0..1 | -YangStatus | | 49 | * | status | 7.19.2 | 0..1 | -YangStatus | |
49 | * | type | 7.4 | 1 | -YangType | | 50 | * | type | 7.4 | 1 | -YangType | |
50 | * | units | 7.3.3 | 0..1 | -string | | 51 | * | units | 7.3.3 | 0..1 | -string | |
51 | - * | when | 7.19.5 | 0..1 | -TODO | | 52 | + * | when | 7.19.5 | 0..1 | -YangWhen | |
52 | * +--------------+---------+-------------+------------------+ | 53 | * +--------------+---------+-------------+------------------+ |
53 | */ | 54 | */ |
54 | 55 | ||
... | @@ -56,7 +57,8 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ... | @@ -56,7 +57,8 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
56 | * Represents leaf-list data represented in YANG. | 57 | * Represents leaf-list data represented in YANG. |
57 | */ | 58 | */ |
58 | public class YangLeafList | 59 | public class YangLeafList |
59 | - implements YangCommonInfo, Parsable, Cloneable, Serializable { | 60 | + implements YangCommonInfo, Parsable, Cloneable, Serializable, |
61 | + YangMustHolder, YangWhenHolder, YangIfFeatureHolder { | ||
60 | 62 | ||
61 | private static final long serialVersionUID = 806201637L; | 63 | private static final long serialVersionUID = 806201637L; |
62 | 64 | ||
... | @@ -133,6 +135,21 @@ public class YangLeafList | ... | @@ -133,6 +135,21 @@ public class YangLeafList |
133 | private transient YangLeavesHolder containedIn; | 135 | private transient YangLeavesHolder containedIn; |
134 | 136 | ||
135 | /** | 137 | /** |
138 | + * List of must statement constraints. | ||
139 | + */ | ||
140 | + private List<YangMust> mustConstraintList; | ||
141 | + | ||
142 | + /** | ||
143 | + * When data of the leaf. | ||
144 | + */ | ||
145 | + private YangWhen when; | ||
146 | + | ||
147 | + /** | ||
148 | + * List of if-feature. | ||
149 | + */ | ||
150 | + private List<YangIfFeature> ifFeatureList; | ||
151 | + | ||
152 | + /** | ||
136 | * Creates a YANG leaf-list. | 153 | * Creates a YANG leaf-list. |
137 | */ | 154 | */ |
138 | public YangLeafList() { | 155 | public YangLeafList() { |
... | @@ -175,6 +192,26 @@ public class YangLeafList | ... | @@ -175,6 +192,26 @@ public class YangLeafList |
175 | } | 192 | } |
176 | 193 | ||
177 | /** | 194 | /** |
195 | + * Returns the when. | ||
196 | + * | ||
197 | + * @return the when | ||
198 | + */ | ||
199 | + @Override | ||
200 | + public YangWhen getWhen() { | ||
201 | + return when; | ||
202 | + } | ||
203 | + | ||
204 | + /** | ||
205 | + * Sets the when. | ||
206 | + * | ||
207 | + * @param when the when to set | ||
208 | + */ | ||
209 | + @Override | ||
210 | + public void setWhen(YangWhen when) { | ||
211 | + this.when = when; | ||
212 | + } | ||
213 | + | ||
214 | + /** | ||
178 | * Returns the description. | 215 | * Returns the description. |
179 | * | 216 | * |
180 | * @return the description | 217 | * @return the description |
... | @@ -363,4 +400,40 @@ public class YangLeafList | ... | @@ -363,4 +400,40 @@ public class YangLeafList |
363 | // TODO auto-generated method stub, to be implemented by parser | 400 | // TODO auto-generated method stub, to be implemented by parser |
364 | 401 | ||
365 | } | 402 | } |
403 | + | ||
404 | + @Override | ||
405 | + public List<YangIfFeature> getIfFeatureList() { | ||
406 | + return ifFeatureList; | ||
407 | + } | ||
408 | + | ||
409 | + @Override | ||
410 | + public void addIfFeatureList(YangIfFeature ifFeature) { | ||
411 | + if (getIfFeatureList() == null) { | ||
412 | + setIfFeatureList(new LinkedList<>()); | ||
413 | + } | ||
414 | + getIfFeatureList().add(ifFeature); | ||
415 | + } | ||
416 | + | ||
417 | + @Override | ||
418 | + public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | ||
419 | + this.ifFeatureList = ifFeatureList; | ||
420 | + } | ||
421 | + | ||
422 | + @Override | ||
423 | + public List<YangMust> getListOfMust() { | ||
424 | + return mustConstraintList; | ||
425 | + } | ||
426 | + | ||
427 | + @Override | ||
428 | + public void setListOfMust(List<YangMust> mustConstraintList) { | ||
429 | + this.mustConstraintList = mustConstraintList; | ||
430 | + } | ||
431 | + | ||
432 | + @Override | ||
433 | + public void addMust(YangMust must) { | ||
434 | + if (getListOfMust() == null) { | ||
435 | + setListOfMust(new LinkedList<>()); | ||
436 | + } | ||
437 | + getListOfMust().add(must); | ||
438 | + } | ||
366 | } | 439 | } | ... | ... |
... | @@ -46,21 +46,21 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -46,21 +46,21 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
46 | * | container | 7.5 | 0..n |-child nodes | | 46 | * | container | 7.5 | 0..n |-child nodes | |
47 | * | description | 7.19.3 | 0..1 |-string | | 47 | * | description | 7.19.3 | 0..1 |-string | |
48 | * | grouping | 7.11 | 0..n |-child nodes | | 48 | * | grouping | 7.11 | 0..n |-child nodes | |
49 | - * | if-feature | 7.18.2 | 0..n |-TODO | | 49 | + * | if-feature | 7.18.2 | 0..n |-YangIfFeature | |
50 | * | key | 7.8.2 | 0..1 |-String list | | 50 | * | key | 7.8.2 | 0..1 |-String list | |
51 | * | leaf | 7.6 | 0..n |-YangLeaf | | 51 | * | leaf | 7.6 | 0..n |-YangLeaf | |
52 | * | leaf-list | 7.7 | 0..n |-YangLeafList | | 52 | * | leaf-list | 7.7 | 0..n |-YangLeafList | |
53 | * | list | 7.8 | 0..n |-child nodes | | 53 | * | list | 7.8 | 0..n |-child nodes | |
54 | * | max-elements | 7.7.4 | 0..1 |-int | | 54 | * | max-elements | 7.7.4 | 0..1 |-int | |
55 | * | min-elements | 7.7.3 | 0..1 |-int | | 55 | * | min-elements | 7.7.3 | 0..1 |-int | |
56 | - * | must | 7.5.3 | 0..n |-TODO | | 56 | + * | must | 7.5.3 | 0..n |-YangMust | |
57 | * | ordered-by | 7.7.5 | 0..1 |-TODO | | 57 | * | ordered-by | 7.7.5 | 0..1 |-TODO | |
58 | * | reference | 7.19.4 | 0..1 |-string | | 58 | * | reference | 7.19.4 | 0..1 |-string | |
59 | * | status | 7.19.2 | 0..1 |-YangStatus | | 59 | * | status | 7.19.2 | 0..1 |-YangStatus | |
60 | * | typedef | 7.3 | 0..n |-child nodes | | 60 | * | typedef | 7.3 | 0..n |-child nodes | |
61 | * | unique | 7.8.3 | 0..n |-TODO | | 61 | * | unique | 7.8.3 | 0..n |-TODO | |
62 | - * | uses | 7.12 | 0..n |-child nodes(TODO)| | 62 | + * | uses | 7.12 | 0..n |-child nodes | |
63 | - * | when | 7.19.5 | 0..1 |-TODO | | 63 | + * | when | 7.19.5 | 0..1 |-YangWhen | |
64 | * +--------------+---------+-------------+------------------+ | 64 | * +--------------+---------+-------------+------------------+ |
65 | */ | 65 | */ |
66 | 66 | ||
... | @@ -69,7 +69,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -69,7 +69,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
69 | */ | 69 | */ |
70 | public class YangList | 70 | public class YangList |
71 | extends YangNode | 71 | extends YangNode |
72 | - implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder { | 72 | + implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder, |
73 | + YangMustHolder, YangIfFeatureHolder { | ||
73 | 74 | ||
74 | private static final long serialVersionUID = 806201609L; | 75 | private static final long serialVersionUID = 806201609L; |
75 | 76 | ||
... | @@ -165,10 +166,24 @@ public class YangList | ... | @@ -165,10 +166,24 @@ public class YangList |
165 | /** | 166 | /** |
166 | * Status of the node. | 167 | * Status of the node. |
167 | */ | 168 | */ |
168 | - | ||
169 | private YangStatusType status = YangStatusType.CURRENT; | 169 | private YangStatusType status = YangStatusType.CURRENT; |
170 | 170 | ||
171 | /** | 171 | /** |
172 | + * List of must statement constraints. | ||
173 | + */ | ||
174 | + private List<YangMust> mustConstraintList; | ||
175 | + | ||
176 | + /** | ||
177 | + * When data of the node. | ||
178 | + */ | ||
179 | + private YangWhen when; | ||
180 | + | ||
181 | + /** | ||
182 | + * List of if-feature. | ||
183 | + */ | ||
184 | + private List<YangIfFeature> ifFeatureList; | ||
185 | + | ||
186 | + /** | ||
172 | * Creates a YANG list object. | 187 | * Creates a YANG list object. |
173 | */ | 188 | */ |
174 | public YangList() { | 189 | public YangList() { |
... | @@ -176,6 +191,24 @@ public class YangList | ... | @@ -176,6 +191,24 @@ public class YangList |
176 | } | 191 | } |
177 | 192 | ||
178 | /** | 193 | /** |
194 | + * Returns the when. | ||
195 | + * | ||
196 | + * @return the when | ||
197 | + */ | ||
198 | + public YangWhen getWhen() { | ||
199 | + return when; | ||
200 | + } | ||
201 | + | ||
202 | + /** | ||
203 | + * Sets the when. | ||
204 | + * | ||
205 | + * @param when the when to set | ||
206 | + */ | ||
207 | + public void setWhen(YangWhen when) { | ||
208 | + this.when = when; | ||
209 | + } | ||
210 | + | ||
211 | + /** | ||
179 | * Returns the YANG list name. | 212 | * Returns the YANG list name. |
180 | * | 213 | * |
181 | * @return YANG list name | 214 | * @return YANG list name |
... | @@ -643,4 +676,40 @@ public class YangList | ... | @@ -643,4 +676,40 @@ public class YangList |
643 | return false; | 676 | return false; |
644 | // TODO When grouping linking is done this method has to be modified. | 677 | // TODO When grouping linking is done this method has to be modified. |
645 | } | 678 | } |
679 | + | ||
680 | + @Override | ||
681 | + public List<YangIfFeature> getIfFeatureList() { | ||
682 | + return ifFeatureList; | ||
683 | + } | ||
684 | + | ||
685 | + @Override | ||
686 | + public void addIfFeatureList(YangIfFeature ifFeature) { | ||
687 | + if (getIfFeatureList() == null) { | ||
688 | + setIfFeatureList(new LinkedList<>()); | ||
689 | + } | ||
690 | + getIfFeatureList().add(ifFeature); | ||
691 | + } | ||
692 | + | ||
693 | + @Override | ||
694 | + public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | ||
695 | + this.ifFeatureList = ifFeatureList; | ||
696 | + } | ||
697 | + | ||
698 | + @Override | ||
699 | + public List<YangMust> getListOfMust() { | ||
700 | + return mustConstraintList; | ||
701 | + } | ||
702 | + | ||
703 | + @Override | ||
704 | + public void setListOfMust(List<YangMust> mustConstraintList) { | ||
705 | + this.mustConstraintList = mustConstraintList; | ||
706 | + } | ||
707 | + | ||
708 | + @Override | ||
709 | + public void addMust(YangMust must) { | ||
710 | + if (getListOfMust() == null) { | ||
711 | + setListOfMust(new LinkedList<>()); | ||
712 | + } | ||
713 | + getListOfMust().add(must); | ||
714 | + } | ||
646 | } | 715 | } | ... | ... |
... | @@ -74,7 +74,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi | ... | @@ -74,7 +74,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi |
74 | public class YangModule | 74 | public class YangModule |
75 | extends YangNode | 75 | extends YangNode |
76 | implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver, | 76 | implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver, |
77 | - RpcNotificationContainer { | 77 | + RpcNotificationContainer, YangFeatureHolder { |
78 | 78 | ||
79 | private static final long serialVersionUID = 806201610L; | 79 | private static final long serialVersionUID = 806201610L; |
80 | 80 | ||
... | @@ -85,7 +85,7 @@ public class YangModule | ... | @@ -85,7 +85,7 @@ public class YangModule |
85 | 85 | ||
86 | /** | 86 | /** |
87 | * Reference:RFC 6020. | 87 | * Reference:RFC 6020. |
88 | - * <p> | 88 | + * |
89 | * The "contact" statement provides contact information for the module. The | 89 | * The "contact" statement provides contact information for the module. The |
90 | * argument is a string that is used to specify contact information for the | 90 | * argument is a string that is used to specify contact information for the |
91 | * person or persons to whom technical queries concerning this module should | 91 | * person or persons to whom technical queries concerning this module should |
... | @@ -96,7 +96,7 @@ public class YangModule | ... | @@ -96,7 +96,7 @@ public class YangModule |
96 | 96 | ||
97 | /** | 97 | /** |
98 | * Reference:RFC 6020. | 98 | * Reference:RFC 6020. |
99 | - * <p> | 99 | + * |
100 | * The "description" statement takes as an argument a string that contains a | 100 | * The "description" statement takes as an argument a string that contains a |
101 | * human-readable textual description of this definition. The text is | 101 | * human-readable textual description of this definition. The text is |
102 | * provided in a language (or languages) chosen by the module developer; for | 102 | * provided in a language (or languages) chosen by the module developer; for |
... | @@ -125,13 +125,18 @@ public class YangModule | ... | @@ -125,13 +125,18 @@ public class YangModule |
125 | private List<YangLeafList> listOfLeafList; | 125 | private List<YangLeafList> listOfLeafList; |
126 | 126 | ||
127 | /** | 127 | /** |
128 | + * List of feature at root level in the module. | ||
129 | + */ | ||
130 | + private List<YangFeature> listOfFeature; | ||
131 | + | ||
132 | + /** | ||
128 | * Name space of the module. | 133 | * Name space of the module. |
129 | */ | 134 | */ |
130 | private YangNameSpace nameSpace; | 135 | private YangNameSpace nameSpace; |
131 | 136 | ||
132 | /** | 137 | /** |
133 | * Reference:RFC 6020. | 138 | * Reference:RFC 6020. |
134 | - * <p> | 139 | + * |
135 | * The "organization" statement defines the party responsible for this | 140 | * The "organization" statement defines the party responsible for this |
136 | * module. The argument is a string that is used to specify a textual | 141 | * module. The argument is a string that is used to specify a textual |
137 | * description of the organization(s) under whose auspices this module was | 142 | * description of the organization(s) under whose auspices this module was |
... | @@ -201,6 +206,11 @@ public class YangModule | ... | @@ -201,6 +206,11 @@ public class YangModule |
201 | private List<YangResolutionInfo> usesResolutionList; | 206 | private List<YangResolutionInfo> usesResolutionList; |
202 | 207 | ||
203 | /** | 208 | /** |
209 | + * if-feature resolution list. | ||
210 | + */ | ||
211 | + private List<YangResolutionInfo> ifFeatureResolutionList; | ||
212 | + | ||
213 | + /** | ||
204 | * Creates a YANG node of module type. | 214 | * Creates a YANG node of module type. |
205 | */ | 215 | */ |
206 | public YangModule() { | 216 | public YangModule() { |
... | @@ -208,6 +218,7 @@ public class YangModule | ... | @@ -208,6 +218,7 @@ public class YangModule |
208 | super(YangNodeType.MODULE_NODE); | 218 | super(YangNodeType.MODULE_NODE); |
209 | derivedTypeResolutionList = new LinkedList<>(); | 219 | derivedTypeResolutionList = new LinkedList<>(); |
210 | usesResolutionList = new LinkedList<>(); | 220 | usesResolutionList = new LinkedList<>(); |
221 | + ifFeatureResolutionList = new LinkedList<>(); | ||
211 | importList = new LinkedList<YangImport>(); | 222 | importList = new LinkedList<YangImport>(); |
212 | includeList = new LinkedList<YangInclude>(); | 223 | includeList = new LinkedList<YangInclude>(); |
213 | listOfLeaf = new LinkedList<YangLeaf>(); | 224 | listOfLeaf = new LinkedList<YangLeaf>(); |
... | @@ -373,6 +384,24 @@ public class YangModule | ... | @@ -373,6 +384,24 @@ public class YangModule |
373 | getListOfLeafList().add(leafList); | 384 | getListOfLeafList().add(leafList); |
374 | } | 385 | } |
375 | 386 | ||
387 | + @Override | ||
388 | + public List<YangFeature> getFeatureList() { | ||
389 | + return listOfFeature; | ||
390 | + } | ||
391 | + | ||
392 | + @Override | ||
393 | + public void addFeatureList(YangFeature feature) { | ||
394 | + if (getFeatureList() == null) { | ||
395 | + setListOfFeature(new LinkedList<>()); | ||
396 | + } | ||
397 | + getFeatureList().add(feature); | ||
398 | + } | ||
399 | + | ||
400 | + @Override | ||
401 | + public void setListOfFeature(List<YangFeature> listOfFeature) { | ||
402 | + this.listOfFeature = listOfFeature; | ||
403 | + } | ||
404 | + | ||
376 | /** | 405 | /** |
377 | * Returns the name space of module elements. | 406 | * Returns the name space of module elements. |
378 | * | 407 | * |
... | @@ -558,10 +587,11 @@ public class YangModule | ... | @@ -558,10 +587,11 @@ public class YangModule |
558 | public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) { | 587 | public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) { |
559 | if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) { | 588 | if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) { |
560 | return derivedTypeResolutionList; | 589 | return derivedTypeResolutionList; |
561 | - } else { | 590 | + } else if (type == ResolvableType.YANG_USES) { |
562 | return usesResolutionList; | 591 | return usesResolutionList; |
592 | + } else { | ||
593 | + return ifFeatureResolutionList; | ||
563 | } | 594 | } |
564 | - | ||
565 | } | 595 | } |
566 | 596 | ||
567 | @Override | 597 | @Override |
... | @@ -571,6 +601,8 @@ public class YangModule | ... | @@ -571,6 +601,8 @@ public class YangModule |
571 | derivedTypeResolutionList.add(resolutionInfo); | 601 | derivedTypeResolutionList.add(resolutionInfo); |
572 | } else if (type == ResolvableType.YANG_USES) { | 602 | } else if (type == ResolvableType.YANG_USES) { |
573 | usesResolutionList.add(resolutionInfo); | 603 | usesResolutionList.add(resolutionInfo); |
604 | + } else if (type == ResolvableType.YANG_IF_FEATURE) { | ||
605 | + ifFeatureResolutionList.add(resolutionInfo); | ||
574 | } | 606 | } |
575 | } | 607 | } |
576 | 608 | ||
... | @@ -581,6 +613,8 @@ public class YangModule | ... | @@ -581,6 +613,8 @@ public class YangModule |
581 | derivedTypeResolutionList = resolutionList; | 613 | derivedTypeResolutionList = resolutionList; |
582 | } else if (type == ResolvableType.YANG_USES) { | 614 | } else if (type == ResolvableType.YANG_USES) { |
583 | usesResolutionList = resolutionList; | 615 | usesResolutionList = resolutionList; |
616 | + } else if (type == ResolvableType.YANG_IF_FEATURE) { | ||
617 | + ifFeatureResolutionList.add((YangResolutionInfo) resolutionList); | ||
584 | } | 618 | } |
585 | 619 | ||
586 | } | 620 | } | ... | ... |
... | @@ -55,7 +55,7 @@ public class YangMust implements YangDesc, YangReference, Parsable, Serializable | ... | @@ -55,7 +55,7 @@ public class YangMust implements YangDesc, YangReference, Parsable, Serializable |
55 | /** | 55 | /** |
56 | * Constraint info. | 56 | * Constraint info. |
57 | */ | 57 | */ |
58 | - private String constratint; | 58 | + private String constraint; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Description string. | 61 | * Description string. |
... | @@ -78,17 +78,17 @@ public class YangMust implements YangDesc, YangReference, Parsable, Serializable | ... | @@ -78,17 +78,17 @@ public class YangMust implements YangDesc, YangReference, Parsable, Serializable |
78 | * | 78 | * |
79 | * @return the constraint | 79 | * @return the constraint |
80 | */ | 80 | */ |
81 | - public String getConstratint() { | 81 | + public String getConstraint() { |
82 | - return constratint; | 82 | + return constraint; |
83 | } | 83 | } |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * Sets the constraint. | 86 | * Sets the constraint. |
87 | * | 87 | * |
88 | - * @param constratint the constraint to set | 88 | + * @param constraint the constraint to set |
89 | */ | 89 | */ |
90 | - public void setConstratint(String constratint) { | 90 | + public void setConstraint(String constraint) { |
91 | - this.constratint = constratint; | 91 | + this.constraint = constraint; |
92 | } | 92 | } |
93 | 93 | ||
94 | /** | 94 | /** | ... | ... |
utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMustHolder.java
0 → 100644
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.datamodel; | ||
18 | + | ||
19 | +import java.util.List; | ||
20 | + | ||
21 | +/** | ||
22 | + * Abstraction of must entity. It is used to abstract the data holders of must. | ||
23 | + */ | ||
24 | +public interface YangMustHolder { | ||
25 | + | ||
26 | + /** | ||
27 | + * Returns the list of must from data holder like container / list. | ||
28 | + * | ||
29 | + * @return the list of must | ||
30 | + */ | ||
31 | + List<YangMust> getListOfMust(); | ||
32 | + | ||
33 | + /** | ||
34 | + * Sets the list of must. | ||
35 | + * | ||
36 | + * @param mustConstraintList the list of must to set | ||
37 | + */ | ||
38 | + void setListOfMust(List<YangMust> mustConstraintList); | ||
39 | + | ||
40 | + /** | ||
41 | + * Adds must in data holder like container / list. | ||
42 | + * | ||
43 | + * @param must the must to be added | ||
44 | + */ | ||
45 | + void addMust(YangMust must); | ||
46 | +} |
... | @@ -60,7 +60,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -60,7 +60,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
60 | * | container | 7.5 | 0..n | -child nodes | | 60 | * | container | 7.5 | 0..n | -child nodes | |
61 | * | description | 7.19.3 | 0..1 | -string | | 61 | * | description | 7.19.3 | 0..1 | -string | |
62 | * | grouping | 7.11 | 0..n | -child nodes | | 62 | * | grouping | 7.11 | 0..n | -child nodes | |
63 | - * | if-feature | 7.18.2 | 0..n | -TODO | | 63 | + * | if-feature | 7.18.2 | 0..n | -YangIfFeature | |
64 | * | leaf | 7.6 | 0..n | -YangLeaf | | 64 | * | leaf | 7.6 | 0..n | -YangLeaf | |
65 | * | leaf-list | 7.7 | 0..n | -YangLeafList | | 65 | * | leaf-list | 7.7 | 0..n | -YangLeafList | |
66 | * | list | 7.8 | 0..n | -child nodes | | 66 | * | list | 7.8 | 0..n | -child nodes | |
... | @@ -76,7 +76,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -76,7 +76,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
76 | */ | 76 | */ |
77 | public class YangNotification | 77 | public class YangNotification |
78 | extends YangNode | 78 | extends YangNode |
79 | - implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder { | 79 | + implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder, |
80 | + YangIfFeatureHolder { | ||
80 | 81 | ||
81 | private static final long serialVersionUID = 806201611L; | 82 | private static final long serialVersionUID = 806201611L; |
82 | 83 | ||
... | @@ -111,6 +112,11 @@ public class YangNotification | ... | @@ -111,6 +112,11 @@ public class YangNotification |
111 | private YangStatusType status = YangStatusType.CURRENT; | 112 | private YangStatusType status = YangStatusType.CURRENT; |
112 | 113 | ||
113 | /** | 114 | /** |
115 | + * List of if-feature. | ||
116 | + */ | ||
117 | + private List<YangIfFeature> ifFeatureList; | ||
118 | + | ||
119 | + /** | ||
114 | * Create a notification node. | 120 | * Create a notification node. |
115 | */ | 121 | */ |
116 | public YangNotification() { | 122 | public YangNotification() { |
... | @@ -221,4 +227,22 @@ public class YangNotification | ... | @@ -221,4 +227,22 @@ public class YangNotification |
221 | public void setStatus(YangStatusType status) { | 227 | public void setStatus(YangStatusType status) { |
222 | this.status = status; | 228 | this.status = status; |
223 | } | 229 | } |
230 | + | ||
231 | + @Override | ||
232 | + public List<YangIfFeature> getIfFeatureList() { | ||
233 | + return ifFeatureList; | ||
234 | + } | ||
235 | + | ||
236 | + @Override | ||
237 | + public void addIfFeatureList(YangIfFeature ifFeature) { | ||
238 | + if (getIfFeatureList() == null) { | ||
239 | + setIfFeatureList(new LinkedList<>()); | ||
240 | + } | ||
241 | + getIfFeatureList().add(ifFeature); | ||
242 | + } | ||
243 | + | ||
244 | + @Override | ||
245 | + public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | ||
246 | + this.ifFeatureList = ifFeatureList; | ||
247 | + } | ||
224 | } | 248 | } | ... | ... |
... | @@ -16,7 +16,7 @@ | ... | @@ -16,7 +16,7 @@ |
16 | package org.onosproject.yangutils.datamodel; | 16 | package org.onosproject.yangutils.datamodel; |
17 | 17 | ||
18 | import java.io.Serializable; | 18 | import java.io.Serializable; |
19 | - | 19 | +import java.util.Date; |
20 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 20 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
21 | import org.onosproject.yangutils.datamodel.utils.Parsable; | 21 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
22 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; | 22 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
... | @@ -41,6 +41,7 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ... | @@ -41,6 +41,7 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
41 | * | reference | 7.19.4 | 0..1 |sring | | 41 | * | reference | 7.19.4 | 0..1 |sring | |
42 | * +--------------+---------+-------------+------------------+ | 42 | * +--------------+---------+-------------+------------------+ |
43 | */ | 43 | */ |
44 | + | ||
44 | /** | 45 | /** |
45 | * Represents the information about the revision. | 46 | * Represents the information about the revision. |
46 | */ | 47 | */ |
... | @@ -51,7 +52,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable, Serializ | ... | @@ -51,7 +52,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable, Serializ |
51 | /** | 52 | /** |
52 | * Revision date. Date string in the format "YYYY-MM-DD" | 53 | * Revision date. Date string in the format "YYYY-MM-DD" |
53 | */ | 54 | */ |
54 | - private String revDate; | 55 | + private Date revDate; |
55 | 56 | ||
56 | /** | 57 | /** |
57 | * Description of revision. | 58 | * Description of revision. |
... | @@ -74,7 +75,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable, Serializ | ... | @@ -74,7 +75,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable, Serializ |
74 | * | 75 | * |
75 | * @return the revision date | 76 | * @return the revision date |
76 | */ | 77 | */ |
77 | - public String getRevDate() { | 78 | + public Date getRevDate() { |
78 | return revDate; | 79 | return revDate; |
79 | } | 80 | } |
80 | 81 | ||
... | @@ -83,7 +84,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable, Serializ | ... | @@ -83,7 +84,7 @@ public class YangRevision implements YangDesc, YangReference, Parsable, Serializ |
83 | * | 84 | * |
84 | * @param revDate the revision date to set | 85 | * @param revDate the revision date to set |
85 | */ | 86 | */ |
86 | - public void setRevDate(String revDate) { | 87 | + public void setRevDate(Date revDate) { |
87 | this.revDate = revDate; | 88 | this.revDate = revDate; |
88 | } | 89 | } |
89 | 90 | ... | ... |
... | @@ -16,6 +16,8 @@ | ... | @@ -16,6 +16,8 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.datamodel; | 17 | package org.onosproject.yangutils.datamodel; |
18 | 18 | ||
19 | +import java.util.LinkedList; | ||
20 | +import java.util.List; | ||
19 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 21 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
20 | import org.onosproject.yangutils.datamodel.utils.Parsable; | 22 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
21 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; | 23 | import org.onosproject.yangutils.datamodel.utils.YangConstructType; |
... | @@ -44,7 +46,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -44,7 +46,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
44 | * +--------------+---------+-------------+------------------+ | 46 | * +--------------+---------+-------------+------------------+ |
45 | * | description | 7.19.3 | 0..1 | -string | | 47 | * | description | 7.19.3 | 0..1 | -string | |
46 | * | grouping | 7.11 | 0..n | -child nodes | | 48 | * | grouping | 7.11 | 0..n | -child nodes | |
47 | - * | if-feature | 7.18.2 | 0..n | -TODO | | 49 | + * | if-feature | 7.18.2 | 0..n | -YangIfFeature | |
48 | * | input | 7.13.2 | 0..1 | -child nodes | | 50 | * | input | 7.13.2 | 0..1 | -child nodes | |
49 | * | output | 7.13.3 | 0..1 | -child nodes | | 51 | * | output | 7.13.3 | 0..1 | -child nodes | |
50 | * | reference | 7.19.4 | 0..1 | -string | | 52 | * | reference | 7.19.4 | 0..1 | -string | |
... | @@ -57,7 +59,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol | ... | @@ -57,7 +59,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol |
57 | * Represents data model node to maintain information defined in YANG rpc. | 59 | * Represents data model node to maintain information defined in YANG rpc. |
58 | */ | 60 | */ |
59 | public class YangRpc extends YangNode implements YangCommonInfo, Parsable, | 61 | public class YangRpc extends YangNode implements YangCommonInfo, Parsable, |
60 | - CollisionDetector { | 62 | + CollisionDetector, YangIfFeatureHolder { |
61 | 63 | ||
62 | private static final long serialVersionUID = 806201613L; | 64 | private static final long serialVersionUID = 806201613L; |
63 | 65 | ||
... | @@ -82,6 +84,11 @@ public class YangRpc extends YangNode implements YangCommonInfo, Parsable, | ... | @@ -82,6 +84,11 @@ public class YangRpc extends YangNode implements YangCommonInfo, Parsable, |
82 | private YangStatusType status = YangStatusType.CURRENT; | 84 | private YangStatusType status = YangStatusType.CURRENT; |
83 | 85 | ||
84 | /** | 86 | /** |
87 | + * List of if-feature. | ||
88 | + */ | ||
89 | + private List<YangIfFeature> ifFeatureList; | ||
90 | + | ||
91 | + /** | ||
85 | * Create a rpc node. | 92 | * Create a rpc node. |
86 | */ | 93 | */ |
87 | public YangRpc() { | 94 | public YangRpc() { |
... | @@ -156,4 +163,22 @@ public class YangRpc extends YangNode implements YangCommonInfo, Parsable, | ... | @@ -156,4 +163,22 @@ public class YangRpc extends YangNode implements YangCommonInfo, Parsable, |
156 | public void setStatus(YangStatusType status) { | 163 | public void setStatus(YangStatusType status) { |
157 | this.status = status; | 164 | this.status = status; |
158 | } | 165 | } |
166 | + | ||
167 | + @Override | ||
168 | + public List<YangIfFeature> getIfFeatureList() { | ||
169 | + return ifFeatureList; | ||
170 | + } | ||
171 | + | ||
172 | + @Override | ||
173 | + public void addIfFeatureList(YangIfFeature ifFeature) { | ||
174 | + if (getIfFeatureList() == null) { | ||
175 | + setIfFeatureList(new LinkedList<>()); | ||
176 | + } | ||
177 | + getIfFeatureList().add(ifFeature); | ||
178 | + } | ||
179 | + | ||
180 | + @Override | ||
181 | + public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | ||
182 | + this.ifFeatureList = ifFeatureList; | ||
183 | + } | ||
159 | } | 184 | } | ... | ... |
... | @@ -57,7 +57,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi | ... | @@ -57,7 +57,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi |
57 | * | description | 7.19.3 | 0..1 | - string | | 57 | * | description | 7.19.3 | 0..1 | - string | |
58 | * | deviation | 7.18.3 | 0..n | - TODO | | 58 | * | deviation | 7.18.3 | 0..n | - TODO | |
59 | * | extension | 7.17 | 0..n | - TODO | | 59 | * | extension | 7.17 | 0..n | - TODO | |
60 | - * | feature | 7.18.1 | 0..n | - TODO | | 60 | + * | feature | 7.18.1 | 0..n | - YangFeature | |
61 | * | grouping | 7.11 | 0..n | - child nodes | | 61 | * | grouping | 7.11 | 0..n | - child nodes | |
62 | * | identity | 7.16 | 0..n | - TODO | | 62 | * | identity | 7.16 | 0..n | - TODO | |
63 | * | import | 7.1.5 | 0..n | - YangImport | | 63 | * | import | 7.1.5 | 0..n | - YangImport | |
... | @@ -82,7 +82,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi | ... | @@ -82,7 +82,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi |
82 | public class YangSubModule | 82 | public class YangSubModule |
83 | extends YangNode | 83 | extends YangNode |
84 | implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver, | 84 | implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver, |
85 | - RpcNotificationContainer { | 85 | + RpcNotificationContainer, YangFeatureHolder { |
86 | 86 | ||
87 | private static final long serialVersionUID = 806201614L; | 87 | private static final long serialVersionUID = 806201614L; |
88 | 88 | ||
... | @@ -133,6 +133,11 @@ public class YangSubModule | ... | @@ -133,6 +133,11 @@ public class YangSubModule |
133 | private List<YangLeafList> listOfLeafList; | 133 | private List<YangLeafList> listOfLeafList; |
134 | 134 | ||
135 | /** | 135 | /** |
136 | + * List of feature at root level in the module. | ||
137 | + */ | ||
138 | + private List<YangFeature> listOfFeature; | ||
139 | + | ||
140 | + /** | ||
136 | * Organization owner of the sub-module. | 141 | * Organization owner of the sub-module. |
137 | */ | 142 | */ |
138 | private String organization; | 143 | private String organization; |
... | @@ -199,12 +204,18 @@ public class YangSubModule | ... | @@ -199,12 +204,18 @@ public class YangSubModule |
199 | private List<YangResolutionInfo> usesResolutionList; | 204 | private List<YangResolutionInfo> usesResolutionList; |
200 | 205 | ||
201 | /** | 206 | /** |
207 | + * if-feature resolution list. | ||
208 | + */ | ||
209 | + private List<YangResolutionInfo> ifFeatureResolutionList; | ||
210 | + | ||
211 | + /** | ||
202 | * Creates a sub module node. | 212 | * Creates a sub module node. |
203 | */ | 213 | */ |
204 | public YangSubModule() { | 214 | public YangSubModule() { |
205 | super(YangNodeType.SUB_MODULE_NODE); | 215 | super(YangNodeType.SUB_MODULE_NODE); |
206 | derivedTypeResolutionList = new LinkedList<>(); | 216 | derivedTypeResolutionList = new LinkedList<>(); |
207 | usesResolutionList = new LinkedList<>(); | 217 | usesResolutionList = new LinkedList<>(); |
218 | + ifFeatureResolutionList = new LinkedList<>(); | ||
208 | importList = new LinkedList<YangImport>(); | 219 | importList = new LinkedList<YangImport>(); |
209 | includeList = new LinkedList<YangInclude>(); | 220 | includeList = new LinkedList<YangInclude>(); |
210 | listOfLeaf = new LinkedList<YangLeaf>(); | 221 | listOfLeaf = new LinkedList<YangLeaf>(); |
... | @@ -538,8 +549,10 @@ public class YangSubModule | ... | @@ -538,8 +549,10 @@ public class YangSubModule |
538 | public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) { | 549 | public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) { |
539 | if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) { | 550 | if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) { |
540 | return derivedTypeResolutionList; | 551 | return derivedTypeResolutionList; |
541 | - } else { | 552 | + } else if (type == ResolvableType.YANG_USES) { |
542 | return usesResolutionList; | 553 | return usesResolutionList; |
554 | + } else { | ||
555 | + return ifFeatureResolutionList; | ||
543 | } | 556 | } |
544 | } | 557 | } |
545 | 558 | ||
... | @@ -550,6 +563,8 @@ public class YangSubModule | ... | @@ -550,6 +563,8 @@ public class YangSubModule |
550 | derivedTypeResolutionList.add(resolutionInfo); | 563 | derivedTypeResolutionList.add(resolutionInfo); |
551 | } else if (type == ResolvableType.YANG_USES) { | 564 | } else if (type == ResolvableType.YANG_USES) { |
552 | usesResolutionList.add(resolutionInfo); | 565 | usesResolutionList.add(resolutionInfo); |
566 | + } else if (type == ResolvableType.YANG_IF_FEATURE) { | ||
567 | + ifFeatureResolutionList.add(resolutionInfo); | ||
553 | } | 568 | } |
554 | } | 569 | } |
555 | 570 | ||
... | @@ -560,6 +575,8 @@ public class YangSubModule | ... | @@ -560,6 +575,8 @@ public class YangSubModule |
560 | derivedTypeResolutionList = resolutionList; | 575 | derivedTypeResolutionList = resolutionList; |
561 | } else if (type == ResolvableType.YANG_USES) { | 576 | } else if (type == ResolvableType.YANG_USES) { |
562 | usesResolutionList = resolutionList; | 577 | usesResolutionList = resolutionList; |
578 | + } else if (type == ResolvableType.YANG_IF_FEATURE) { | ||
579 | + ifFeatureResolutionList = resolutionList; | ||
563 | } | 580 | } |
564 | 581 | ||
565 | } | 582 | } |
... | @@ -601,4 +618,22 @@ public class YangSubModule | ... | @@ -601,4 +618,22 @@ public class YangSubModule |
601 | yangImport.addReferenceToImport(yangNodeSet); | 618 | yangImport.addReferenceToImport(yangNodeSet); |
602 | } | 619 | } |
603 | } | 620 | } |
621 | + | ||
622 | + @Override | ||
623 | + public List<YangFeature> getFeatureList() { | ||
624 | + return listOfFeature; | ||
625 | + } | ||
626 | + | ||
627 | + @Override | ||
628 | + public void addFeatureList(YangFeature feature) { | ||
629 | + if (getFeatureList() == null) { | ||
630 | + setListOfFeature(new LinkedList<>()); | ||
631 | + } | ||
632 | + getFeatureList().add(feature); | ||
633 | + } | ||
634 | + | ||
635 | + @Override | ||
636 | + public void setListOfFeature(List<YangFeature> listOfFeature) { | ||
637 | + this.listOfFeature = listOfFeature; | ||
638 | + } | ||
604 | } | 639 | } | ... | ... |
... | @@ -48,11 +48,11 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParent | ... | @@ -48,11 +48,11 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParent |
48 | * +--------------+---------+-------------+------------------+ | 48 | * +--------------+---------+-------------+------------------+ |
49 | * | augment | 7.15 | 0..1 | -child nodes | | 49 | * | augment | 7.15 | 0..1 | -child nodes | |
50 | * | description | 7.19.3 | 0..1 | -string | | 50 | * | description | 7.19.3 | 0..1 | -string | |
51 | - * | if-feature | 7.18.2 | 0..n | -TODO | | 51 | + * | if-feature | 7.18.2 | 0..n | -YangIfFeature | |
52 | * | refine | 7.12.2 | 0..1 | -TODO | | 52 | * | refine | 7.12.2 | 0..1 | -TODO | |
53 | * | reference | 7.19.4 | 0..1 | -string | | 53 | * | reference | 7.19.4 | 0..1 | -string | |
54 | * | status | 7.19.2 | 0..1 | -YangStatus | | 54 | * | status | 7.19.2 | 0..1 | -YangStatus | |
55 | - * | when | 7.19.5 | 0..1 | -TODO | | 55 | + * | when | 7.19.5 | 0..1 | -YangWhen | |
56 | * +--------------+---------+-------------+------------------+ | 56 | * +--------------+---------+-------------+------------------+ |
57 | */ | 57 | */ |
58 | 58 | ||
... | @@ -61,7 +61,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParent | ... | @@ -61,7 +61,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParent |
61 | */ | 61 | */ |
62 | public class YangUses | 62 | public class YangUses |
63 | extends YangNode | 63 | extends YangNode |
64 | - implements YangCommonInfo, Parsable, Resolvable, CollisionDetector { | 64 | + implements YangCommonInfo, Parsable, Resolvable, CollisionDetector, YangWhenHolder, |
65 | + YangIfFeatureHolder { | ||
65 | 66 | ||
66 | private static final long serialVersionUID = 806201617L; | 67 | private static final long serialVersionUID = 806201617L; |
67 | 68 | ||
... | @@ -91,6 +92,16 @@ public class YangUses | ... | @@ -91,6 +92,16 @@ public class YangUses |
91 | private YangStatusType status; | 92 | private YangStatusType status; |
92 | 93 | ||
93 | /** | 94 | /** |
95 | + * When data of the node. | ||
96 | + */ | ||
97 | + private YangWhen when; | ||
98 | + | ||
99 | + /** | ||
100 | + * List of if-feature. | ||
101 | + */ | ||
102 | + private List<YangIfFeature> ifFeatureList; | ||
103 | + | ||
104 | + /** | ||
94 | * Status of resolution. If completely resolved enum value is "RESOLVED", | 105 | * Status of resolution. If completely resolved enum value is "RESOLVED", |
95 | * if not enum value is "UNRESOLVED", in case reference of grouping/typedef | 106 | * if not enum value is "UNRESOLVED", in case reference of grouping/typedef |
96 | * is added to uses/type but it's not resolved value of enum should be | 107 | * is added to uses/type but it's not resolved value of enum should be |
... | @@ -144,6 +155,26 @@ public class YangUses | ... | @@ -144,6 +155,26 @@ public class YangUses |
144 | } | 155 | } |
145 | 156 | ||
146 | /** | 157 | /** |
158 | + * Returns the when. | ||
159 | + * | ||
160 | + * @return the when | ||
161 | + */ | ||
162 | + @Override | ||
163 | + public YangWhen getWhen() { | ||
164 | + return when; | ||
165 | + } | ||
166 | + | ||
167 | + /** | ||
168 | + * Sets the when. | ||
169 | + * | ||
170 | + * @param when the when to set | ||
171 | + */ | ||
172 | + @Override | ||
173 | + public void setWhen(YangWhen when) { | ||
174 | + this.when = when; | ||
175 | + } | ||
176 | + | ||
177 | + /** | ||
147 | * Returns the description. | 178 | * Returns the description. |
148 | * | 179 | * |
149 | * @return the description | 180 | * @return the description |
... | @@ -503,4 +534,22 @@ public class YangUses | ... | @@ -503,4 +534,22 @@ public class YangUses |
503 | public List<List<YangLeafList>> getUsesResolvedListOfLeafList() { | 534 | public List<List<YangLeafList>> getUsesResolvedListOfLeafList() { |
504 | return resolvedGroupingLeafLists; | 535 | return resolvedGroupingLeafLists; |
505 | } | 536 | } |
537 | + | ||
538 | + @Override | ||
539 | + public List<YangIfFeature> getIfFeatureList() { | ||
540 | + return ifFeatureList; | ||
541 | + } | ||
542 | + | ||
543 | + @Override | ||
544 | + public void addIfFeatureList(YangIfFeature ifFeature) { | ||
545 | + if (getIfFeatureList() == null) { | ||
546 | + setIfFeatureList(new LinkedList<>()); | ||
547 | + } | ||
548 | + getIfFeatureList().add(ifFeature); | ||
549 | + } | ||
550 | + | ||
551 | + @Override | ||
552 | + public void setIfFeatureList(List<YangIfFeature> ifFeatureList) { | ||
553 | + this.ifFeatureList = ifFeatureList; | ||
554 | + } | ||
506 | } | 555 | } | ... | ... |
utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangWhen.java
0 → 100644
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 | +package org.onosproject.yangutils.datamodel; | ||
17 | + | ||
18 | +import java.io.Serializable; | ||
19 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
20 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
21 | +import org.onosproject.yangutils.datamodel.utils.YangConstructType; | ||
22 | + | ||
23 | +/* | ||
24 | + * Reference RFC 6020. | ||
25 | + * | ||
26 | + * The "when" statement makes its parent data definition statement | ||
27 | + * conditional. The node defined by the parent data definition | ||
28 | + * statement is only valid when the condition specified by the "when" | ||
29 | + * statement is satisfied. | ||
30 | + * | ||
31 | + * The statement's argument is an XPath expression, which is used to formally | ||
32 | + * specify this condition. If the XPath expression conceptually evaluates to | ||
33 | + * "true" for a particular instance, then the node defined by the parent data | ||
34 | + * definition statement is valid; otherwise, it is not. | ||
35 | + * | ||
36 | + * The when's sub-statements | ||
37 | + * | ||
38 | + * +---------------+---------+-------------+------------------+ | ||
39 | + * | substatement | section | cardinality |data model mapping| | ||
40 | + * +---------------+---------+-------------+------------------+ | ||
41 | + * | description | 7.19.3 | 0..1 | -string | | ||
42 | + * | reference | 7.19.4 | 0..1 | -string | | ||
43 | + * +---------------+---------+-------------+------------------+ | ||
44 | + */ | ||
45 | + | ||
46 | +/** | ||
47 | + * Represents information defined in YANG when. | ||
48 | + */ | ||
49 | +public class YangWhen implements YangDesc, YangReference, Parsable, Serializable { | ||
50 | + | ||
51 | + private static final long serialVersionUID = 806201646L; | ||
52 | + | ||
53 | + /** | ||
54 | + * When condition info. | ||
55 | + */ | ||
56 | + private String condition; | ||
57 | + | ||
58 | + /** | ||
59 | + * Description string. | ||
60 | + */ | ||
61 | + private String description; | ||
62 | + | ||
63 | + /** | ||
64 | + * Reference string. | ||
65 | + */ | ||
66 | + private String reference; | ||
67 | + | ||
68 | + /** | ||
69 | + * Creates a YANG when restriction. | ||
70 | + */ | ||
71 | + public YangWhen() { | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * Returns the condition. | ||
76 | + * | ||
77 | + * @return the condition | ||
78 | + */ | ||
79 | + public String getCondition() { | ||
80 | + return condition; | ||
81 | + } | ||
82 | + | ||
83 | + /** | ||
84 | + * Sets the condition. | ||
85 | + * | ||
86 | + * @param condition the condition to set | ||
87 | + */ | ||
88 | + public void setCondition(String condition) { | ||
89 | + this.condition = condition; | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Returns the description. | ||
94 | + * | ||
95 | + * @return the description | ||
96 | + */ | ||
97 | + @Override | ||
98 | + public String getDescription() { | ||
99 | + return description; | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * Sets the description. | ||
104 | + * | ||
105 | + * @param description set the description | ||
106 | + */ | ||
107 | + @Override | ||
108 | + public void setDescription(String description) { | ||
109 | + this.description = description; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * Returns the textual reference. | ||
114 | + * | ||
115 | + * @return the reference | ||
116 | + */ | ||
117 | + @Override | ||
118 | + public String getReference() { | ||
119 | + return reference; | ||
120 | + } | ||
121 | + | ||
122 | + /** | ||
123 | + * Sets the textual reference. | ||
124 | + * | ||
125 | + * @param reference the reference to set | ||
126 | + */ | ||
127 | + @Override | ||
128 | + public void setReference(String reference) { | ||
129 | + this.reference = reference; | ||
130 | + } | ||
131 | + | ||
132 | + /** | ||
133 | + * Returns the type of the parsed data. | ||
134 | + * | ||
135 | + * @return returns WHEN_DATA | ||
136 | + */ | ||
137 | + @Override | ||
138 | + public YangConstructType getYangConstructType() { | ||
139 | + return YangConstructType.WHEN_DATA; | ||
140 | + } | ||
141 | + | ||
142 | + /** | ||
143 | + * Validates the data on entering the corresponding parse tree node. | ||
144 | + * | ||
145 | + * @throws DataModelException a violation of data model rules | ||
146 | + */ | ||
147 | + @Override | ||
148 | + public void validateDataOnEntry() throws DataModelException { | ||
149 | + // TODO auto-generated method stub, to be implemented by parser | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * Validates the data on exiting the corresponding parse tree node. | ||
154 | + * | ||
155 | + * @throws DataModelException a violation of data model rules | ||
156 | + */ | ||
157 | + @Override | ||
158 | + public void validateDataOnExit() throws DataModelException { | ||
159 | + // TODO auto-generated method stub, to be implemented by parser | ||
160 | + } | ||
161 | +} |
utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangWhenHolder.java
0 → 100644
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.datamodel; | ||
18 | + | ||
19 | +/** | ||
20 | + * Abstraction of when entity. It is used to abstract the data holders of when. | ||
21 | + */ | ||
22 | +public interface YangWhenHolder { | ||
23 | + | ||
24 | + /** | ||
25 | + * Returns the when. | ||
26 | + * | ||
27 | + * @return the when | ||
28 | + */ | ||
29 | + YangWhen getWhen(); | ||
30 | + | ||
31 | + /** | ||
32 | + * Sets the when. | ||
33 | + * | ||
34 | + * @param when the when to set | ||
35 | + */ | ||
36 | + void setWhen(YangWhen when); | ||
37 | +} |
... | @@ -21,6 +21,7 @@ import java.util.Set; | ... | @@ -21,6 +21,7 @@ import java.util.Set; |
21 | 21 | ||
22 | import org.onosproject.yangutils.datamodel.CollisionDetector; | 22 | import org.onosproject.yangutils.datamodel.CollisionDetector; |
23 | import org.onosproject.yangutils.datamodel.ResolvableType; | 23 | import org.onosproject.yangutils.datamodel.ResolvableType; |
24 | +import org.onosproject.yangutils.datamodel.YangIfFeature; | ||
24 | import org.onosproject.yangutils.datamodel.YangLeaf; | 25 | import org.onosproject.yangutils.datamodel.YangLeaf; |
25 | import org.onosproject.yangutils.datamodel.YangLeafList; | 26 | import org.onosproject.yangutils.datamodel.YangLeafList; |
26 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; | 27 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
... | @@ -29,13 +30,14 @@ import org.onosproject.yangutils.datamodel.YangReferenceResolver; | ... | @@ -29,13 +30,14 @@ import org.onosproject.yangutils.datamodel.YangReferenceResolver; |
29 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; | 30 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; |
30 | import org.onosproject.yangutils.datamodel.YangRpc; | 31 | import org.onosproject.yangutils.datamodel.YangRpc; |
31 | import org.onosproject.yangutils.datamodel.YangType; | 32 | import org.onosproject.yangutils.datamodel.YangType; |
33 | +import org.onosproject.yangutils.datamodel.YangUses; | ||
32 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 34 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
33 | 35 | ||
34 | - | ||
35 | /** | 36 | /** |
36 | * Represents utilities for data model tree. | 37 | * Represents utilities for data model tree. |
37 | */ | 38 | */ |
38 | public final class DataModelUtils { | 39 | public final class DataModelUtils { |
40 | + | ||
39 | /** | 41 | /** |
40 | * Creates a new data model tree utility. | 42 | * Creates a new data model tree utility. |
41 | */ | 43 | */ |
... | @@ -161,11 +163,15 @@ public final class DataModelUtils { | ... | @@ -161,11 +163,15 @@ public final class DataModelUtils { |
161 | .getEntityToResolve() instanceof YangType) { | 163 | .getEntityToResolve() instanceof YangType) { |
162 | resolutionNode.addToResolutionList(resolutionInfo, | 164 | resolutionNode.addToResolutionList(resolutionInfo, |
163 | ResolvableType.YANG_DERIVED_DATA_TYPE); | 165 | ResolvableType.YANG_DERIVED_DATA_TYPE); |
164 | - } else { | 166 | + } else if (resolutionInfo.getEntityToResolveInfo() |
167 | + .getEntityToResolve() instanceof YangUses) { | ||
165 | resolutionNode.addToResolutionList(resolutionInfo, | 168 | resolutionNode.addToResolutionList(resolutionInfo, |
166 | ResolvableType.YANG_USES); | 169 | ResolvableType.YANG_USES); |
170 | + } else if (resolutionInfo.getEntityToResolveInfo() | ||
171 | + .getEntityToResolve() instanceof YangIfFeature) { | ||
172 | + resolutionNode.addToResolutionList(resolutionInfo, | ||
173 | + ResolvableType.YANG_IF_FEATURE); | ||
167 | } | 174 | } |
168 | - | ||
169 | } | 175 | } |
170 | 176 | ||
171 | /** | 177 | /** | ... | ... |
... | @@ -46,6 +46,11 @@ public enum ResolvableStatus { | ... | @@ -46,6 +46,11 @@ public enum ResolvableStatus { |
46 | * Identifies that resolvable entity is inter file linked (i.e. complete | 46 | * Identifies that resolvable entity is inter file linked (i.e. complete |
47 | * linking with external files). | 47 | * linking with external files). |
48 | */ | 48 | */ |
49 | - INTER_FILE_LINKED | 49 | + INTER_FILE_LINKED, |
50 | + | ||
51 | + /** | ||
52 | + * Identifies that resolvable entity is referred node is not defined. | ||
53 | + */ | ||
54 | + UNDEFINED | ||
50 | 55 | ||
51 | } | 56 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.linker.impl; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.linker.impl; |
18 | import java.io.Serializable; | 18 | import java.io.Serializable; |
19 | 19 | ||
20 | import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo; | 20 | import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo; |
21 | +import org.onosproject.yangutils.datamodel.YangIfFeature; | ||
21 | import org.onosproject.yangutils.datamodel.YangNode; | 22 | import org.onosproject.yangutils.datamodel.YangNode; |
22 | import org.onosproject.yangutils.datamodel.YangType; | 23 | import org.onosproject.yangutils.datamodel.YangType; |
23 | import org.onosproject.yangutils.datamodel.YangUses; | 24 | import org.onosproject.yangutils.datamodel.YangUses; |
... | @@ -76,6 +77,8 @@ public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T | ... | @@ -76,6 +77,8 @@ public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T |
76 | prefix = ((YangType<?>) entityToBeResolved).getPrefix(); | 77 | prefix = ((YangType<?>) entityToBeResolved).getPrefix(); |
77 | } else if (entityToBeResolved instanceof YangUses) { | 78 | } else if (entityToBeResolved instanceof YangUses) { |
78 | prefix = ((YangUses) entityToBeResolved).getPrefix(); | 79 | prefix = ((YangUses) entityToBeResolved).getPrefix(); |
80 | + } else if (entityToBeResolved instanceof YangIfFeature) { | ||
81 | + prefix = ((YangIfFeature) entityToBeResolved).getPrefix(); | ||
79 | } else { | 82 | } else { |
80 | throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses"); | 83 | throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses"); |
81 | } | 84 | } | ... | ... |
... | @@ -156,6 +156,8 @@ public class YangLinkerManager | ... | @@ -156,6 +156,8 @@ public class YangLinkerManager |
156 | throws LinkerException { | 156 | throws LinkerException { |
157 | for (YangNode yangNode : yangNodeSet) { | 157 | for (YangNode yangNode : yangNodeSet) { |
158 | try { | 158 | try { |
159 | + ((YangReferenceResolver) yangNode) | ||
160 | + .resolveInterFileLinking(ResolvableType.YANG_IF_FEATURE); | ||
159 | ((YangReferenceResolver) yangNode).resolveInterFileLinking(ResolvableType.YANG_USES); | 161 | ((YangReferenceResolver) yangNode).resolveInterFileLinking(ResolvableType.YANG_USES); |
160 | ((YangReferenceResolver) yangNode) | 162 | ((YangReferenceResolver) yangNode) |
161 | .resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); | 163 | .resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -40,7 +40,9 @@ import org.onosproject.yangutils.parser.impl.listeners.DefaultListener; | ... | @@ -40,7 +40,9 @@ import org.onosproject.yangutils.parser.impl.listeners.DefaultListener; |
40 | import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener; | 40 | import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener; |
41 | import org.onosproject.yangutils.parser.impl.listeners.EnumListener; | 41 | import org.onosproject.yangutils.parser.impl.listeners.EnumListener; |
42 | import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener; | 42 | import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener; |
43 | +import org.onosproject.yangutils.parser.impl.listeners.FeatureListener; | ||
43 | import org.onosproject.yangutils.parser.impl.listeners.GroupingListener; | 44 | import org.onosproject.yangutils.parser.impl.listeners.GroupingListener; |
45 | +import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener; | ||
44 | import org.onosproject.yangutils.parser.impl.listeners.ImportListener; | 46 | import org.onosproject.yangutils.parser.impl.listeners.ImportListener; |
45 | import org.onosproject.yangutils.parser.impl.listeners.IncludeListener; | 47 | import org.onosproject.yangutils.parser.impl.listeners.IncludeListener; |
46 | import org.onosproject.yangutils.parser.impl.listeners.InputListener; | 48 | import org.onosproject.yangutils.parser.impl.listeners.InputListener; |
... | @@ -53,6 +55,7 @@ import org.onosproject.yangutils.parser.impl.listeners.MandatoryListener; | ... | @@ -53,6 +55,7 @@ import org.onosproject.yangutils.parser.impl.listeners.MandatoryListener; |
53 | import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener; | 55 | import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener; |
54 | import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener; | 56 | import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener; |
55 | import org.onosproject.yangutils.parser.impl.listeners.ModuleListener; | 57 | import org.onosproject.yangutils.parser.impl.listeners.ModuleListener; |
58 | +import org.onosproject.yangutils.parser.impl.listeners.MustListener; | ||
56 | import org.onosproject.yangutils.parser.impl.listeners.NotificationListener; | 59 | import org.onosproject.yangutils.parser.impl.listeners.NotificationListener; |
57 | import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener; | 60 | import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener; |
58 | import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener; | 61 | import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener; |
... | @@ -76,6 +79,7 @@ import org.onosproject.yangutils.parser.impl.listeners.UnitsListener; | ... | @@ -76,6 +79,7 @@ import org.onosproject.yangutils.parser.impl.listeners.UnitsListener; |
76 | import org.onosproject.yangutils.parser.impl.listeners.UsesListener; | 79 | import org.onosproject.yangutils.parser.impl.listeners.UsesListener; |
77 | import org.onosproject.yangutils.parser.impl.listeners.ValueListener; | 80 | import org.onosproject.yangutils.parser.impl.listeners.ValueListener; |
78 | import org.onosproject.yangutils.parser.impl.listeners.VersionListener; | 81 | import org.onosproject.yangutils.parser.impl.listeners.VersionListener; |
82 | +import org.onosproject.yangutils.parser.impl.listeners.WhenListener; | ||
79 | 83 | ||
80 | import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT; | 84 | import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT; |
81 | import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED; | 85 | import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED; |
... | @@ -473,22 +477,22 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -473,22 +477,22 @@ public class TreeWalkListener implements GeneratedYangListener { |
473 | 477 | ||
474 | @Override | 478 | @Override |
475 | public void enterFeatureStatement(GeneratedYangParser.FeatureStatementContext ctx) { | 479 | public void enterFeatureStatement(GeneratedYangParser.FeatureStatementContext ctx) { |
476 | - handleUnsupportedYangConstruct(YangConstructType.FEATURE_DATA, ctx, CURRENTLY_UNSUPPORTED); | 480 | + FeatureListener.processFeatureEntry(this, ctx); |
477 | } | 481 | } |
478 | 482 | ||
479 | @Override | 483 | @Override |
480 | public void exitFeatureStatement(GeneratedYangParser.FeatureStatementContext ctx) { | 484 | public void exitFeatureStatement(GeneratedYangParser.FeatureStatementContext ctx) { |
481 | - //TODO: to be implemented | 485 | + FeatureListener.processFeatureExit(this, ctx); |
482 | } | 486 | } |
483 | 487 | ||
484 | @Override | 488 | @Override |
485 | public void enterFeatureBody(GeneratedYangParser.FeatureBodyContext ctx) { | 489 | public void enterFeatureBody(GeneratedYangParser.FeatureBodyContext ctx) { |
486 | - //TODO : to be implemented | 490 | + // do nothing |
487 | } | 491 | } |
488 | 492 | ||
489 | @Override | 493 | @Override |
490 | public void exitFeatureBody(GeneratedYangParser.FeatureBodyContext ctx) { | 494 | public void exitFeatureBody(GeneratedYangParser.FeatureBodyContext ctx) { |
491 | - //TODO : to be implemented | 495 | + // do nothing. |
492 | } | 496 | } |
493 | 497 | ||
494 | @Override | 498 | @Override |
... | @@ -503,12 +507,12 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -503,12 +507,12 @@ public class TreeWalkListener implements GeneratedYangListener { |
503 | 507 | ||
504 | @Override | 508 | @Override |
505 | public void enterIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext ctx) { | 509 | public void enterIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext ctx) { |
506 | - // TODO: to be implemented | 510 | + IfFeatureListener.processIfFeatureEntry(this, ctx); |
507 | } | 511 | } |
508 | 512 | ||
509 | @Override | 513 | @Override |
510 | public void exitIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext ctx) { | 514 | public void exitIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext ctx) { |
511 | - // TODO: to be implemented | 515 | + // do nothing. |
512 | } | 516 | } |
513 | 517 | ||
514 | @Override | 518 | @Override |
... | @@ -813,12 +817,12 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -813,12 +817,12 @@ public class TreeWalkListener implements GeneratedYangListener { |
813 | 817 | ||
814 | @Override | 818 | @Override |
815 | public void enterMustStatement(GeneratedYangParser.MustStatementContext ctx) { | 819 | public void enterMustStatement(GeneratedYangParser.MustStatementContext ctx) { |
816 | - // TODO: to be implemented | 820 | + MustListener.processMustEntry(this, ctx); |
817 | } | 821 | } |
818 | 822 | ||
819 | @Override | 823 | @Override |
820 | public void exitMustStatement(GeneratedYangParser.MustStatementContext ctx) { | 824 | public void exitMustStatement(GeneratedYangParser.MustStatementContext ctx) { |
821 | - // TODO: to be implemented | 825 | + MustListener.processMustExit(this, ctx); |
822 | } | 826 | } |
823 | 827 | ||
824 | @Override | 828 | @Override |
... | @@ -1083,12 +1087,12 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -1083,12 +1087,12 @@ public class TreeWalkListener implements GeneratedYangListener { |
1083 | 1087 | ||
1084 | @Override | 1088 | @Override |
1085 | public void enterWhenStatement(GeneratedYangParser.WhenStatementContext ctx) { | 1089 | public void enterWhenStatement(GeneratedYangParser.WhenStatementContext ctx) { |
1086 | - // TODO: to be implemented | 1090 | + WhenListener.processWhenEntry(this, ctx); |
1087 | } | 1091 | } |
1088 | 1092 | ||
1089 | @Override | 1093 | @Override |
1090 | public void exitWhenStatement(GeneratedYangParser.WhenStatementContext ctx) { | 1094 | public void exitWhenStatement(GeneratedYangParser.WhenStatementContext ctx) { |
1091 | - // TODO: to be implemented | 1095 | + WhenListener.processWhenExit(this, ctx); |
1092 | } | 1096 | } |
1093 | 1097 | ||
1094 | @Override | 1098 | @Override | ... | ... |
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 | +/* | ||
20 | + * Reference: RFC6020 and YANG ANTLR Grammar | ||
21 | + * | ||
22 | + * ABNF grammar as per RFC6020 | ||
23 | + * feature-stmt = feature-keyword sep identifier-arg-str optsep | ||
24 | + * (";" / | ||
25 | + * "{" stmtsep | ||
26 | + * ;; these stmts can appear in any order | ||
27 | + * *(if-feature-stmt stmtsep) | ||
28 | + * [status-stmt stmtsep] | ||
29 | + * [description-stmt stmtsep] | ||
30 | + * [reference-stmt stmtsep] | ||
31 | + * "}") | ||
32 | + * | ||
33 | + * | ||
34 | + * | ||
35 | + * ANTLR grammar rule | ||
36 | + * featureStatement : FEATURE_KEYWORD string (STMTEND | LEFT_CURLY_BRACE featureBody RIGHT_CURLY_BRACE); | ||
37 | + */ | ||
38 | + | ||
39 | +import org.onosproject.yangutils.datamodel.YangFeature; | ||
40 | +import org.onosproject.yangutils.datamodel.YangFeatureHolder; | ||
41 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
42 | +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ||
43 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
44 | +import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ||
45 | + | ||
46 | +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.FEATURE_DATA; | ||
47 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | ||
48 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | ||
49 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | ||
50 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | ||
51 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | ||
52 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | ||
53 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
54 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | ||
55 | + | ||
56 | +/** | ||
57 | + * Represents listener based call back function corresponding to the "feature" | ||
58 | + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020. | ||
59 | + */ | ||
60 | +public final class FeatureListener { | ||
61 | + | ||
62 | + /** | ||
63 | + * Creates a new feature listener. | ||
64 | + */ | ||
65 | + private FeatureListener() { | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * Performs validation and updates the data model tree.It is called when parser receives | ||
70 | + * an input matching the grammar rule (feature). | ||
71 | + * | ||
72 | + * @param listener listener's object | ||
73 | + * @param ctx context object of the grammar rule | ||
74 | + */ | ||
75 | + public static void processFeatureEntry(TreeWalkListener listener, | ||
76 | + GeneratedYangParser.FeatureStatementContext ctx) { | ||
77 | + | ||
78 | + // Check for stack to be non empty. | ||
79 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, FEATURE_DATA, ctx.string().getText(), ENTRY); | ||
80 | + | ||
81 | + String identifier = getValidIdentifier(ctx.string().getText(), FEATURE_DATA, ctx); | ||
82 | + | ||
83 | + // Obtain the node of the stack. | ||
84 | + Parsable tmpNode = listener.getParsedDataStack().peek(); | ||
85 | + if (tmpNode instanceof YangFeatureHolder) { | ||
86 | + YangFeatureHolder featureHolder = (YangFeatureHolder) tmpNode; | ||
87 | + | ||
88 | + YangFeature feature = new YangFeature(); | ||
89 | + feature.setName(identifier); | ||
90 | + | ||
91 | + featureHolder.addFeatureList(feature); | ||
92 | + listener.getParsedDataStack().push(feature); | ||
93 | + } else { | ||
94 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, FEATURE_DATA, | ||
95 | + ctx.string().getText(), ENTRY)); | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Perform validations and updates the data model tree.It is called when parser exits from | ||
101 | + * grammar rule(feature). | ||
102 | + * | ||
103 | + * @param listener listener's object | ||
104 | + * @param ctx context object of the grammar rule | ||
105 | + */ | ||
106 | + public static void processFeatureExit(TreeWalkListener listener, | ||
107 | + GeneratedYangParser.FeatureStatementContext ctx) { | ||
108 | + | ||
109 | + // Check for stack to be non empty. | ||
110 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, FEATURE_DATA, ctx.string().getText(), EXIT); | ||
111 | + | ||
112 | + if (listener.getParsedDataStack().peek() instanceof YangFeature) { | ||
113 | + listener.getParsedDataStack().pop(); | ||
114 | + } else { | ||
115 | + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, FEATURE_DATA, | ||
116 | + ctx.string().getText(), EXIT)); | ||
117 | + } | ||
118 | + } | ||
119 | +} |
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 | +/* | ||
20 | + * Reference: RFC6020 and YANG ANTLR Grammar | ||
21 | + * | ||
22 | + * ABNF grammar as per RFC6020 | ||
23 | + * | ||
24 | + * if-feature-stmt = if-feature-keyword sep identifier-ref-arg-str | ||
25 | + * optsep stmtend | ||
26 | + * | ||
27 | + * ANTLR grammar rule | ||
28 | + * ifFeatureStatement : IF_FEATURE_KEYWORD string STMTEND; | ||
29 | + */ | ||
30 | + | ||
31 | +import org.onosproject.yangutils.datamodel.YangFeature; | ||
32 | +import org.onosproject.yangutils.datamodel.YangIfFeature; | ||
33 | +import org.onosproject.yangutils.datamodel.YangIfFeatureHolder; | ||
34 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
35 | +import org.onosproject.yangutils.datamodel.YangLeafList; | ||
36 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
37 | +import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | ||
38 | +import org.onosproject.yangutils.datamodel.YangResolutionInfo; | ||
39 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
40 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
41 | +import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl; | ||
42 | +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ||
43 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
44 | +import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ||
45 | + | ||
46 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo; | ||
47 | +import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED; | ||
48 | +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IF_FEATURE_DATA; | ||
49 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | ||
50 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | ||
51 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | ||
52 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | ||
53 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | ||
54 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | ||
55 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | ||
56 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier; | ||
57 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | ||
58 | + | ||
59 | +/** | ||
60 | + * Represents listener based call back function corresponding to the "if-feature" | ||
61 | + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020. | ||
62 | + */ | ||
63 | +public final class IfFeatureListener { | ||
64 | + | ||
65 | + /** | ||
66 | + * Creates a new IfFeature listener. | ||
67 | + */ | ||
68 | + private IfFeatureListener() { | ||
69 | + } | ||
70 | + | ||
71 | + /** | ||
72 | + * Performs validation and updates the data model tree.It is called when parser receives | ||
73 | + * an input matching the grammar rule (if-feature). | ||
74 | + * | ||
75 | + * @param listener listener's object | ||
76 | + * @param ctx context object of the grammar rule | ||
77 | + */ | ||
78 | + public static void processIfFeatureEntry(TreeWalkListener listener, | ||
79 | + GeneratedYangParser.IfFeatureStatementContext ctx) { | ||
80 | + // Check for stack to be non empty. | ||
81 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, IF_FEATURE_DATA, ctx.string().getText(), ENTRY); | ||
82 | + | ||
83 | + // Validate if-feature argument string | ||
84 | + YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), | ||
85 | + IF_FEATURE_DATA, ctx); | ||
86 | + | ||
87 | + YangIfFeature ifFeature = new YangIfFeature(); | ||
88 | + ifFeature.setName(nodeIdentifier); | ||
89 | + ifFeature.setResolvableStatus(UNRESOLVED); | ||
90 | + YangIfFeatureHolder ifFeatureHolder; | ||
91 | + | ||
92 | + // Obtain the node of the stack. | ||
93 | + Parsable tmpNode = listener.getParsedDataStack().peek(); | ||
94 | + if (tmpNode instanceof YangIfFeatureHolder) { | ||
95 | + ifFeatureHolder = (YangIfFeatureHolder) tmpNode; | ||
96 | + ifFeatureHolder.addIfFeatureList(ifFeature); | ||
97 | + } else { | ||
98 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IF_FEATURE_DATA, | ||
99 | + ctx.string().getText(), ENTRY)); | ||
100 | + } | ||
101 | + | ||
102 | + // Add resolution information to the list | ||
103 | + Parsable parentNode; | ||
104 | + if (tmpNode instanceof YangLeafList || tmpNode instanceof YangLeaf | ||
105 | + || tmpNode instanceof YangFeature) { | ||
106 | + Parsable leafData = listener.getParsedDataStack().pop(); | ||
107 | + parentNode = listener.getParsedDataStack().peek(); | ||
108 | + listener.getParsedDataStack().push(leafData); | ||
109 | + } else { | ||
110 | + parentNode = tmpNode; | ||
111 | + } | ||
112 | + | ||
113 | + // Verify parent node of leaf | ||
114 | + if (!(parentNode instanceof YangNode)) { | ||
115 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IF_FEATURE_DATA, | ||
116 | + ctx.string().getText(), EXIT)); | ||
117 | + } | ||
118 | + | ||
119 | + int errorLine = ctx.getStart().getLine(); | ||
120 | + int errorPosition = ctx.getStart().getCharPositionInLine(); | ||
121 | + YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangIfFeature>(ifFeature, | ||
122 | + (YangNode) parentNode, errorLine, | ||
123 | + errorPosition); | ||
124 | + addToResolutionList(resolutionInfo, ctx); | ||
125 | + } | ||
126 | + | ||
127 | + /** | ||
128 | + * Add to resolution list. | ||
129 | + * | ||
130 | + * @param resolutionInfo resolution information. | ||
131 | + * @param ctx context object of the grammar rule | ||
132 | + */ | ||
133 | + private static void addToResolutionList(YangResolutionInfo<YangIfFeature> resolutionInfo, | ||
134 | + GeneratedYangParser.IfFeatureStatementContext ctx) { | ||
135 | + | ||
136 | + try { | ||
137 | + addResolutionInfo(resolutionInfo); | ||
138 | + } catch (DataModelException e) { | ||
139 | + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | ||
140 | + IF_FEATURE_DATA, ctx.string().getText(), EXIT, e.getMessage())); | ||
141 | + } | ||
142 | + } | ||
143 | +} |
... | @@ -16,11 +16,13 @@ | ... | @@ -16,11 +16,13 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import java.util.Date; | ||
19 | import org.onosproject.yangutils.datamodel.ResolvableType; | 20 | import org.onosproject.yangutils.datamodel.ResolvableType; |
20 | import org.onosproject.yangutils.datamodel.YangModule; | 21 | import org.onosproject.yangutils.datamodel.YangModule; |
21 | import org.onosproject.yangutils.datamodel.YangReferenceResolver; | 22 | import org.onosproject.yangutils.datamodel.YangReferenceResolver; |
22 | import org.onosproject.yangutils.datamodel.YangRevision; | 23 | import org.onosproject.yangutils.datamodel.YangRevision; |
23 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 24 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
25 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
24 | import org.onosproject.yangutils.linker.exceptions.LinkerException; | 26 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
25 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 27 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
26 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 28 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
... | @@ -34,8 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMes | ... | @@ -34,8 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMes |
34 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | 36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; |
35 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | 37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; |
36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
39 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getCurrentDateForRevision; | ||
37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
38 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.setCurrentDateForRevision; | ||
39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty; | 41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty; |
40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
41 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangModuleNode; | 43 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangModuleNode; |
... | @@ -91,13 +93,6 @@ public final class ModuleListener { | ... | @@ -91,13 +93,6 @@ public final class ModuleListener { |
91 | yangModule.setVersion((byte) 1); | 93 | yangModule.setVersion((byte) 1); |
92 | } | 94 | } |
93 | 95 | ||
94 | - if (ctx.moduleBody().revisionStatements().revisionStatement().isEmpty()) { | ||
95 | - String currentDate = setCurrentDateForRevision(); | ||
96 | - YangRevision currentRevision = new YangRevision(); | ||
97 | - currentRevision.setRevDate(currentDate); | ||
98 | - yangModule.setRevision(currentRevision); | ||
99 | - } | ||
100 | - | ||
101 | listener.getParsedDataStack().push(yangModule); | 96 | listener.getParsedDataStack().push(yangModule); |
102 | } | 97 | } |
103 | 98 | ||
... | @@ -113,12 +108,23 @@ public final class ModuleListener { | ... | @@ -113,12 +108,23 @@ public final class ModuleListener { |
113 | // Check for stack to be non empty. | 108 | // Check for stack to be non empty. |
114 | checkStackIsNotEmpty(listener, MISSING_HOLDER, MODULE_DATA, ctx.identifier().getText(), EXIT); | 109 | checkStackIsNotEmpty(listener, MISSING_HOLDER, MODULE_DATA, ctx.identifier().getText(), EXIT); |
115 | 110 | ||
116 | - if (!(listener.getParsedDataStack().peek() instanceof YangModule)) { | 111 | + Parsable tmpNode = listener.getParsedDataStack().peek(); |
112 | + if (!(tmpNode instanceof YangModule)) { | ||
117 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA, | 113 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA, |
118 | ctx.identifier().getText(), EXIT)); | 114 | ctx.identifier().getText(), EXIT)); |
119 | } | 115 | } |
116 | + | ||
117 | + if (((YangModule) tmpNode).getRevision() == null) { | ||
118 | + Date currentDate = getCurrentDateForRevision(); | ||
119 | + YangRevision currentRevision = new YangRevision(); | ||
120 | + currentRevision.setRevDate(currentDate); | ||
121 | + ((YangModule) tmpNode).setRevision(currentRevision); | ||
122 | + } | ||
123 | + | ||
120 | try { | 124 | try { |
121 | ((YangReferenceResolver) listener.getParsedDataStack() | 125 | ((YangReferenceResolver) listener.getParsedDataStack() |
126 | + .peek()).resolveSelfFileLinking(ResolvableType.YANG_IF_FEATURE); | ||
127 | + ((YangReferenceResolver) listener.getParsedDataStack() | ||
122 | .peek()).resolveSelfFileLinking(ResolvableType.YANG_USES); | 128 | .peek()).resolveSelfFileLinking(ResolvableType.YANG_USES); |
123 | ((YangReferenceResolver) listener.getParsedDataStack() | 129 | ((YangReferenceResolver) listener.getParsedDataStack() |
124 | .peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); | 130 | .peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); | ... | ... |
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 org.onosproject.yangutils.datamodel.YangMust; | ||
20 | +import org.onosproject.yangutils.datamodel.YangMustHolder; | ||
21 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
22 | +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ||
23 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
24 | +import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ||
25 | + | ||
26 | +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MUST_DATA; | ||
27 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | ||
28 | +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.ListenerErrorType.INVALID_HOLDER; | ||
31 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | ||
32 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | ||
33 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat; | ||
34 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | ||
35 | + | ||
36 | +/* | ||
37 | + * Reference: RFC6020 and YANG ANTLR Grammar | ||
38 | + * | ||
39 | + * ABNF grammar as per RFC6020 | ||
40 | + * | ||
41 | + * must-stmt = must-keyword sep string optsep | ||
42 | + * (";" / | ||
43 | + * "{" stmtsep | ||
44 | + * ;; these stmts can appear in any order | ||
45 | + * [error-message-stmt stmtsep] | ||
46 | + * [error-app-tag-stmt stmtsep] | ||
47 | + * [description-stmt stmtsep] | ||
48 | + * [reference-stmt stmtsep] | ||
49 | + * "}") | ||
50 | + * | ||
51 | + * ANTLR grammar rule | ||
52 | + * mustStatement : MUST_KEYWORD string (STMTEND | LEFT_CURLY_BRACE commonStatements RIGHT_CURLY_BRACE); | ||
53 | + */ | ||
54 | + | ||
55 | +/** | ||
56 | + * Represents listener based call back function corresponding to the | ||
57 | + * "must" rule defined in ANTLR grammar file for corresponding ABNF rule | ||
58 | + * in RFC 6020. | ||
59 | + */ | ||
60 | +public final class MustListener { | ||
61 | + | ||
62 | + /** | ||
63 | + * Creates a new must listener. | ||
64 | + */ | ||
65 | + private MustListener() { | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * Perform validations and updates the data model tree.It is called when parser | ||
70 | + * receives an input matching the grammar rule (must). | ||
71 | + * | ||
72 | + * @param listener listener's object | ||
73 | + * @param ctx context object of the grammar rule | ||
74 | + */ | ||
75 | + public static void processMustEntry(TreeWalkListener listener, | ||
76 | + GeneratedYangParser.MustStatementContext ctx) { | ||
77 | + | ||
78 | + // Check for stack to be non empty. | ||
79 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, MUST_DATA, ctx.string().getText(), ENTRY); | ||
80 | + String constraint = removeQuotesAndHandleConcat(ctx.string().getText()); | ||
81 | + | ||
82 | + // Obtain the node of the stack. | ||
83 | + Parsable tmpNode = listener.getParsedDataStack().peek(); | ||
84 | + if (tmpNode instanceof YangMustHolder) { | ||
85 | + | ||
86 | + YangMust must = new YangMust(); | ||
87 | + must.setConstraint(constraint); | ||
88 | + | ||
89 | + YangMustHolder mustHolder = (YangMustHolder) tmpNode; | ||
90 | + mustHolder.addMust(must); | ||
91 | + | ||
92 | + listener.getParsedDataStack().push(must); | ||
93 | + } else { | ||
94 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MUST_DATA, | ||
95 | + ctx.string().getText(), ENTRY)); | ||
96 | + } | ||
97 | + | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * Performs validation and updates the data model tree.It is called when parser | ||
102 | + * exits from grammar rule (must). | ||
103 | + * | ||
104 | + * @param listener listener's object | ||
105 | + * @param ctx context object of the grammar rule | ||
106 | + */ | ||
107 | + public static void processMustExit(TreeWalkListener listener, | ||
108 | + GeneratedYangParser.MustStatementContext ctx) { | ||
109 | + | ||
110 | + // Check for stack to be non empty. | ||
111 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, MUST_DATA, ctx.string().getText(), EXIT); | ||
112 | + | ||
113 | + if (listener.getParsedDataStack().peek() instanceof YangMust) { | ||
114 | + listener.getParsedDataStack().pop(); | ||
115 | + } else { | ||
116 | + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MUST_DATA, | ||
117 | + ctx.string().getText(), EXIT)); | ||
118 | + } | ||
119 | + } | ||
120 | +} |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import java.util.Date; | ||
19 | import org.onosproject.yangutils.datamodel.YangImport; | 20 | import org.onosproject.yangutils.datamodel.YangImport; |
20 | import org.onosproject.yangutils.datamodel.YangInclude; | 21 | import org.onosproject.yangutils.datamodel.YangInclude; |
21 | import org.onosproject.yangutils.datamodel.utils.Parsable; | 22 | import org.onosproject.yangutils.datamodel.utils.Parsable; |
... | @@ -28,8 +29,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc | ... | @@ -28,8 +29,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc |
28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | 30 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; |
30 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 31 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
31 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.isDateValid; | 32 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidDateFromString; |
32 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat; | ||
33 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 33 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
34 | 34 | ||
35 | /* | 35 | /* |
... | @@ -87,13 +87,7 @@ public final class RevisionDateListener { | ... | @@ -87,13 +87,7 @@ public final class RevisionDateListener { |
87 | checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATE_DATA, ctx.dateArgumentString().getText(), | 87 | checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATE_DATA, ctx.dateArgumentString().getText(), |
88 | ENTRY); | 88 | ENTRY); |
89 | 89 | ||
90 | - String date = removeQuotesAndHandleConcat(ctx.dateArgumentString().getText()); | 90 | + Date date = getValidDateFromString(ctx.dateArgumentString().getText(), ctx); |
91 | - if (!isDateValid(date)) { | ||
92 | - ParserException parserException = new ParserException("YANG file error: Input date is not correct"); | ||
93 | - parserException.setLine(ctx.getStart().getLine()); | ||
94 | - parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
95 | - throw parserException; | ||
96 | - } | ||
97 | 91 | ||
98 | // Obtain the node of the stack. | 92 | // Obtain the node of the stack. |
99 | Parsable tmpNode = listener.getParsedDataStack().peek(); | 93 | Parsable tmpNode = listener.getParsedDataStack().peek(); | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import java.util.Date; | ||
19 | import org.onosproject.yangutils.datamodel.YangModule; | 20 | import org.onosproject.yangutils.datamodel.YangModule; |
20 | import org.onosproject.yangutils.datamodel.YangRevision; | 21 | import org.onosproject.yangutils.datamodel.YangRevision; |
21 | import org.onosproject.yangutils.datamodel.YangSubModule; | 22 | import org.onosproject.yangutils.datamodel.YangSubModule; |
... | @@ -31,8 +32,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMes | ... | @@ -31,8 +32,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMes |
31 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | 32 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; |
32 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | 33 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; |
33 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 34 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
34 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.isDateValid; | 35 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidDateFromString; |
35 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat; | ||
36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
37 | 37 | ||
38 | /* | 38 | /* |
... | @@ -88,20 +88,7 @@ public final class RevisionListener { | ... | @@ -88,20 +88,7 @@ public final class RevisionListener { |
88 | // Check for stack to be non empty. | 88 | // Check for stack to be non empty. |
89 | checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.dateArgumentString().getText(), ENTRY); | 89 | checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.dateArgumentString().getText(), ENTRY); |
90 | 90 | ||
91 | - // Validate for reverse chronological order of revision & for revision | 91 | + Date date = getValidDateFromString(ctx.dateArgumentString().getText(), ctx); |
92 | - // value. | ||
93 | - if (!validateRevision(listener, ctx)) { | ||
94 | - return; | ||
95 | - // TODO to be implemented. | ||
96 | - } | ||
97 | - | ||
98 | - String date = removeQuotesAndHandleConcat(ctx.dateArgumentString().getText()); | ||
99 | - if (!isDateValid(date)) { | ||
100 | - ParserException parserException = new ParserException("YANG file error: Input date is not correct"); | ||
101 | - parserException.setLine(ctx.getStart().getLine()); | ||
102 | - parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
103 | - throw parserException; | ||
104 | - } | ||
105 | 92 | ||
106 | YangRevision revisionNode = new YangRevision(); | 93 | YangRevision revisionNode = new YangRevision(); |
107 | revisionNode.setRevDate(date); | 94 | revisionNode.setRevDate(date); |
... | @@ -134,12 +121,26 @@ public final class RevisionListener { | ... | @@ -134,12 +121,26 @@ public final class RevisionListener { |
134 | switch (tmpNode.getYangConstructType()) { | 121 | switch (tmpNode.getYangConstructType()) { |
135 | case MODULE_DATA: { | 122 | case MODULE_DATA: { |
136 | YangModule module = (YangModule) tmpNode; | 123 | YangModule module = (YangModule) tmpNode; |
124 | + if (module.getRevision() != null) { | ||
125 | + Date curRevisionDate = module.getRevision().getRevDate(); | ||
126 | + if (curRevisionDate.before(((YangRevision) tmpRevisionNode).getRevDate())) { | ||
127 | + module.setRevision((YangRevision) tmpRevisionNode); | ||
128 | + } | ||
129 | + } else { | ||
137 | module.setRevision((YangRevision) tmpRevisionNode); | 130 | module.setRevision((YangRevision) tmpRevisionNode); |
131 | + } | ||
138 | break; | 132 | break; |
139 | } | 133 | } |
140 | case SUB_MODULE_DATA: { | 134 | case SUB_MODULE_DATA: { |
141 | YangSubModule subModule = (YangSubModule) tmpNode; | 135 | YangSubModule subModule = (YangSubModule) tmpNode; |
136 | + if (subModule.getRevision() != null) { | ||
137 | + Date curRevisionDate = subModule.getRevision().getRevDate(); | ||
138 | + if (curRevisionDate.before(((YangRevision) tmpRevisionNode).getRevDate())) { | ||
142 | subModule.setRevision((YangRevision) tmpRevisionNode); | 139 | subModule.setRevision((YangRevision) tmpRevisionNode); |
140 | + } | ||
141 | + } else { | ||
142 | + subModule.setRevision((YangRevision) tmpRevisionNode); | ||
143 | + } | ||
143 | break; | 144 | break; |
144 | } | 145 | } |
145 | default: | 146 | default: | ... | ... |
... | @@ -16,11 +16,13 @@ | ... | @@ -16,11 +16,13 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import java.util.Date; | ||
19 | import org.onosproject.yangutils.datamodel.ResolvableType; | 20 | import org.onosproject.yangutils.datamodel.ResolvableType; |
20 | import org.onosproject.yangutils.datamodel.YangReferenceResolver; | 21 | import org.onosproject.yangutils.datamodel.YangReferenceResolver; |
21 | import org.onosproject.yangutils.datamodel.YangRevision; | 22 | import org.onosproject.yangutils.datamodel.YangRevision; |
22 | import org.onosproject.yangutils.datamodel.YangSubModule; | 23 | import org.onosproject.yangutils.datamodel.YangSubModule; |
23 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 24 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
25 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
24 | import org.onosproject.yangutils.linker.exceptions.LinkerException; | 26 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
25 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 27 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
26 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 28 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
... | @@ -34,8 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMes | ... | @@ -34,8 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMes |
34 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | 36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; |
35 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | 37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; |
36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
39 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getCurrentDateForRevision; | ||
37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
38 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.setCurrentDateForRevision; | ||
39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty; | 41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty; |
40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
41 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangSubModuleNode; | 43 | import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangSubModuleNode; |
... | @@ -94,13 +96,6 @@ public final class SubModuleListener { | ... | @@ -94,13 +96,6 @@ public final class SubModuleListener { |
94 | yangSubModule.setVersion((byte) 1); | 96 | yangSubModule.setVersion((byte) 1); |
95 | } | 97 | } |
96 | 98 | ||
97 | - if (ctx.submoduleBody().revisionStatements().revisionStatement().isEmpty()) { | ||
98 | - String currentDate = setCurrentDateForRevision(); | ||
99 | - YangRevision currentRevision = new YangRevision(); | ||
100 | - currentRevision.setRevDate(currentDate); | ||
101 | - yangSubModule.setRevision(currentRevision); | ||
102 | - } | ||
103 | - | ||
104 | listener.getParsedDataStack().push(yangSubModule); | 99 | listener.getParsedDataStack().push(yangSubModule); |
105 | } | 100 | } |
106 | 101 | ||
... | @@ -118,12 +113,23 @@ public final class SubModuleListener { | ... | @@ -118,12 +113,23 @@ public final class SubModuleListener { |
118 | checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(), | 113 | checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(), |
119 | EXIT); | 114 | EXIT); |
120 | 115 | ||
121 | - if (!(listener.getParsedDataStack().peek() instanceof YangSubModule)) { | 116 | + Parsable tmpNode = listener.getParsedDataStack().peek(); |
117 | + if (!(tmpNode instanceof YangSubModule)) { | ||
122 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA, | 118 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA, |
123 | ctx.identifier().getText(), EXIT)); | 119 | ctx.identifier().getText(), EXIT)); |
124 | } | 120 | } |
121 | + | ||
122 | + if (((YangSubModule) tmpNode).getRevision() == null) { | ||
123 | + Date currentDate = getCurrentDateForRevision(); | ||
124 | + YangRevision currentRevision = new YangRevision(); | ||
125 | + currentRevision.setRevDate(currentDate); | ||
126 | + ((YangSubModule) tmpNode).setRevision(currentRevision); | ||
127 | + } | ||
128 | + | ||
125 | try { | 129 | try { |
126 | ((YangReferenceResolver) listener.getParsedDataStack().peek()) | 130 | ((YangReferenceResolver) listener.getParsedDataStack().peek()) |
131 | + .resolveSelfFileLinking(ResolvableType.YANG_IF_FEATURE); | ||
132 | + ((YangReferenceResolver) listener.getParsedDataStack().peek()) | ||
127 | .resolveSelfFileLinking(ResolvableType.YANG_USES); | 133 | .resolveSelfFileLinking(ResolvableType.YANG_USES); |
128 | ((YangReferenceResolver) listener.getParsedDataStack().peek()) | 134 | ((YangReferenceResolver) listener.getParsedDataStack().peek()) |
129 | .resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); | 135 | .resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE); | ... | ... |
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 org.onosproject.yangutils.datamodel.YangWhen; | ||
20 | +import org.onosproject.yangutils.datamodel.YangWhenHolder; | ||
21 | +import org.onosproject.yangutils.datamodel.utils.Parsable; | ||
22 | +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ||
23 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
24 | +import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ||
25 | + | ||
26 | +import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_DATA; | ||
27 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | ||
28 | +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.ListenerErrorType.INVALID_HOLDER; | ||
31 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | ||
32 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | ||
33 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat; | ||
34 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | ||
35 | + | ||
36 | +/* | ||
37 | + * Reference: RFC6020 and YANG ANTLR Grammar | ||
38 | + * | ||
39 | + * ABNF grammar as per RFC6020 | ||
40 | + * | ||
41 | + * when-stmt = when-keyword sep string optsep | ||
42 | + * (";" / | ||
43 | + * "{" stmtsep | ||
44 | + * ;; these stmts can appear in any order | ||
45 | + * [description-stmt stmtsep] | ||
46 | + * [reference-stmt stmtsep] | ||
47 | + * "}") | ||
48 | + * | ||
49 | + * ANTLR grammar rule | ||
50 | + * whenStatement : WHEN_KEYWORD string (STMTEND | LEFT_CURLY_BRACE ((descriptionStatement? referenceStatement?) | ||
51 | + * | (referenceStatement? descriptionStatement?)) RIGHT_CURLY_BRACE); | ||
52 | + */ | ||
53 | + | ||
54 | +/** | ||
55 | + * Represents listener based call back function corresponding to the | ||
56 | + * "when" rule defined in ANTLR grammar file for corresponding ABNF rule | ||
57 | + * in RFC 6020. | ||
58 | + */ | ||
59 | +public final class WhenListener { | ||
60 | + | ||
61 | + /** | ||
62 | + * Creates a new when listener. | ||
63 | + */ | ||
64 | + private WhenListener() { | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * Perform validations and updates the data model tree.It is called when parser | ||
69 | + * receives an input matching the grammar rule (when). | ||
70 | + * | ||
71 | + * @param listener listener's object | ||
72 | + * @param ctx context object of the grammar rule | ||
73 | + */ | ||
74 | + public static void processWhenEntry(TreeWalkListener listener, | ||
75 | + GeneratedYangParser.WhenStatementContext ctx) { | ||
76 | + | ||
77 | + // Check for stack to be non empty. | ||
78 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, WHEN_DATA, ctx.string().getText(), ENTRY); | ||
79 | + String condition = removeQuotesAndHandleConcat(ctx.string().getText()); | ||
80 | + | ||
81 | + YangWhenHolder whenHolder; | ||
82 | + | ||
83 | + // Obtain the node of the stack. | ||
84 | + Parsable tmpNode = listener.getParsedDataStack().peek(); | ||
85 | + if (tmpNode instanceof YangWhenHolder) { | ||
86 | + whenHolder = (YangWhenHolder) tmpNode; | ||
87 | + | ||
88 | + YangWhen when = new YangWhen(); | ||
89 | + when.setCondition(condition); | ||
90 | + | ||
91 | + whenHolder.setWhen(when); | ||
92 | + listener.getParsedDataStack().push(when); | ||
93 | + } else { | ||
94 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, | ||
95 | + WHEN_DATA, ctx.string().getText(), ENTRY)); | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Performs validation and updates the data model tree.It is called when parser | ||
101 | + * exits from grammar rule (when). | ||
102 | + * | ||
103 | + * @param listener listener's object | ||
104 | + * @param ctx context object of the grammar rule | ||
105 | + */ | ||
106 | + public static void processWhenExit(TreeWalkListener listener, | ||
107 | + GeneratedYangParser.WhenStatementContext ctx) { | ||
108 | + | ||
109 | + // Check for stack to be non empty. | ||
110 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, WHEN_DATA, ctx.string().getText(), EXIT); | ||
111 | + | ||
112 | + if (listener.getParsedDataStack().peek() instanceof YangWhen) { | ||
113 | + listener.getParsedDataStack().pop(); | ||
114 | + } else { | ||
115 | + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, WHEN_DATA, | ||
116 | + ctx.string().getText(), EXIT)); | ||
117 | + } | ||
118 | + } | ||
119 | +} |
... | @@ -18,7 +18,7 @@ package org.onosproject.yangutils.parser.impl.parserutils; | ... | @@ -18,7 +18,7 @@ package org.onosproject.yangutils.parser.impl.parserutils; |
18 | 18 | ||
19 | import java.text.ParseException; | 19 | import java.text.ParseException; |
20 | import java.text.SimpleDateFormat; | 20 | import java.text.SimpleDateFormat; |
21 | -import java.util.Calendar; | 21 | +import java.util.Date; |
22 | import java.util.LinkedList; | 22 | import java.util.LinkedList; |
23 | import java.util.List; | 23 | import java.util.List; |
24 | import java.util.regex.Pattern; | 24 | import java.util.regex.Pattern; |
... | @@ -30,20 +30,18 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ... | @@ -30,20 +30,18 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
30 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 30 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
31 | 31 | ||
32 | import static org.onosproject.yangutils.utils.UtilConstants.ADD; | 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; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.CARET; |
34 | +import static org.onosproject.yangutils.utils.UtilConstants.COLON; | ||
37 | import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED; | 35 | import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED; |
38 | -import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; | ||
39 | -import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN; | ||
40 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
41 | -import static org.onosproject.yangutils.utils.UtilConstants.TRUE; | ||
42 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; |
43 | -import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR; | ||
44 | import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF; |
45 | -import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF; | ||
46 | import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_IDENTIFIER; | 39 | import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_IDENTIFIER; |
40 | +import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF; | ||
41 | +import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; | ||
42 | +import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | ||
43 | +import static org.onosproject.yangutils.utils.UtilConstants.TRUE; | ||
44 | +import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR; | ||
47 | 45 | ||
48 | /** | 46 | /** |
49 | * Represents an utility for listener. | 47 | * Represents an utility for listener. |
... | @@ -256,17 +254,24 @@ public final class ListenerUtil { | ... | @@ -256,17 +254,24 @@ public final class ListenerUtil { |
256 | } | 254 | } |
257 | 255 | ||
258 | /** | 256 | /** |
259 | - * Sets current date and makes it in usable format for revision. | 257 | + * Returns current date and makes it in usable format for revision. |
260 | * | 258 | * |
261 | * @return usable current date format for revision | 259 | * @return usable current date format for revision |
262 | */ | 260 | */ |
263 | - public static String setCurrentDateForRevision() { | 261 | + public static Date getCurrentDateForRevision() { |
264 | 262 | ||
265 | - Calendar date = Calendar.getInstance(); | ||
266 | SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); | 263 | SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); |
267 | - String dateForRevision = dateFormat.format(date.getTime()).replaceAll(SLASH, HYPHEN).replaceAll(SPACE, | 264 | + |
268 | - EMPTY_STRING); | 265 | + Date date = new Date(); |
269 | - return dateForRevision; | 266 | + String dateInString = dateFormat.format(date); |
267 | + try { | ||
268 | + //if not valid, it will throw ParseException | ||
269 | + Date now = dateFormat.parse(dateInString); | ||
270 | + return date; | ||
271 | + } catch (ParseException e) { | ||
272 | + ParserException parserException = new ParserException("YANG file error: Input date is not correct"); | ||
273 | + throw parserException; | ||
274 | + } | ||
270 | } | 275 | } |
271 | 276 | ||
272 | /** | 277 | /** |
... | @@ -373,4 +378,35 @@ public final class ListenerUtil { | ... | @@ -373,4 +378,35 @@ public final class ListenerUtil { |
373 | parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | 378 | parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); |
374 | throw parserException; | 379 | throw parserException; |
375 | } | 380 | } |
381 | + | ||
382 | + /** | ||
383 | + * Returns date and makes it in usable format for revision. | ||
384 | + * | ||
385 | + * @param dateInString date argument string from yang file | ||
386 | + * @param ctx yang construct's context to get the line number and character position | ||
387 | + * @return date format for revision | ||
388 | + */ | ||
389 | + public static Date getValidDateFromString(String dateInString, ParserRuleContext ctx) { | ||
390 | + String dateArgument = removeQuotesAndHandleConcat(dateInString); | ||
391 | + if (dateArgument == null || !dateArgument.matches(DATE_PATTERN)) { | ||
392 | + ParserException parserException = new ParserException("YANG file error: Input date is not correct"); | ||
393 | + parserException.setLine(ctx.getStart().getLine()); | ||
394 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
395 | + throw parserException; | ||
396 | + } | ||
397 | + | ||
398 | + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); | ||
399 | + sdf.setLenient(false); | ||
400 | + | ||
401 | + try { | ||
402 | + //if not valid, it will throw ParseException | ||
403 | + Date date = sdf.parse(dateArgument); | ||
404 | + return date; | ||
405 | + } catch (ParseException e) { | ||
406 | + ParserException parserException = new ParserException("YANG file error: Input date is not correct"); | ||
407 | + parserException.setLine(ctx.getStart().getLine()); | ||
408 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
409 | + throw parserException; | ||
410 | + } | ||
411 | + } | ||
376 | } | 412 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -18,7 +18,9 @@ package org.onosproject.yangutils.translator.tojava.utils; | ... | @@ -18,7 +18,9 @@ package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | import java.io.File; | 19 | import java.io.File; |
20 | import java.io.IOException; | 20 | import java.io.IOException; |
21 | +import java.text.SimpleDateFormat; | ||
21 | import java.util.ArrayList; | 22 | import java.util.ArrayList; |
23 | +import java.util.Date; | ||
22 | import java.util.List; | 24 | import java.util.List; |
23 | import org.onosproject.yangutils.datamodel.YangNode; | 25 | import org.onosproject.yangutils.datamodel.YangNode; |
24 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 26 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
... | @@ -59,6 +61,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -59,6 +61,7 @@ public final class JavaIdentifierSyntax { |
59 | private static final int INDEX_TWO = 2; | 61 | private static final int INDEX_TWO = 2; |
60 | private static final int VALUE_CHECK = 10; | 62 | private static final int VALUE_CHECK = 10; |
61 | private static final String ZERO = "0"; | 63 | private static final String ZERO = "0"; |
64 | + private static final String DATE_FORMAT = "yyyy-MM-dd"; | ||
62 | 65 | ||
63 | /** | 66 | /** |
64 | * Create instance of java identifier syntax. | 67 | * Create instance of java identifier syntax. |
... | @@ -75,7 +78,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -75,7 +78,7 @@ public final class JavaIdentifierSyntax { |
75 | * @param conflictResolver object of YANG to java naming conflict util | 78 | * @param conflictResolver object of YANG to java naming conflict util |
76 | * @return the root package string | 79 | * @return the root package string |
77 | */ | 80 | */ |
78 | - public static String getRootPackage(byte version, String nameSpace, String revision, | 81 | + public static String getRootPackage(byte version, String nameSpace, Date revision, |
79 | YangToJavaNamingConflictUtil conflictResolver) { | 82 | YangToJavaNamingConflictUtil conflictResolver) { |
80 | 83 | ||
81 | String pkg; | 84 | String pkg; |
... | @@ -125,30 +128,23 @@ public final class JavaIdentifierSyntax { | ... | @@ -125,30 +128,23 @@ public final class JavaIdentifierSyntax { |
125 | * | 128 | * |
126 | * @param date YANG module revision | 129 | * @param date YANG module revision |
127 | * @return revision string | 130 | * @return revision string |
128 | - * @throws TranslatorException when date is invalid. | ||
129 | */ | 131 | */ |
130 | - private static String getYangRevisionStr(String date) throws TranslatorException { | 132 | + private static String getYangRevisionStr(Date date) { |
131 | - | 133 | + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); |
132 | - String[] revisionArr = date.split(HYPHEN); | 134 | + String dateInString = sdf.format(date); |
135 | + String[] revisionArr = dateInString.split(HYPHEN); | ||
133 | 136 | ||
134 | String rev = REVISION_PREFIX; | 137 | String rev = REVISION_PREFIX; |
135 | rev = rev + revisionArr[INDEX_ZERO]; | 138 | rev = rev + revisionArr[INDEX_ZERO]; |
136 | 139 | ||
137 | - if (Integer.parseInt(revisionArr[INDEX_ONE]) <= MAX_MONTHS | ||
138 | - && Integer.parseInt(revisionArr[INDEX_TWO]) <= MAX_DAYS) { | ||
139 | for (int i = INDEX_ONE; i < revisionArr.length; i++) { | 140 | for (int i = INDEX_ONE; i < revisionArr.length; i++) { |
140 | - | ||
141 | Integer val = Integer.parseInt(revisionArr[i]); | 141 | Integer val = Integer.parseInt(revisionArr[i]); |
142 | if (val < VALUE_CHECK) { | 142 | if (val < VALUE_CHECK) { |
143 | rev = rev + ZERO; | 143 | rev = rev + ZERO; |
144 | } | 144 | } |
145 | rev = rev + val; | 145 | rev = rev + val; |
146 | } | 146 | } |
147 | - | ||
148 | return rev; | 147 | return rev; |
149 | - } else { | ||
150 | - throw new TranslatorException("Date in revision is not proper: " + date); | ||
151 | - } | ||
152 | } | 148 | } |
153 | 149 | ||
154 | /** | 150 | /** | ... | ... |
... | @@ -1140,6 +1140,12 @@ public final class UtilConstants { | ... | @@ -1140,6 +1140,12 @@ public final class UtilConstants { |
1140 | + "grouping for given uses"; | 1140 | + "grouping for given uses"; |
1141 | 1141 | ||
1142 | /** | 1142 | /** |
1143 | + * Static attribute for grouping linker error information. | ||
1144 | + */ | ||
1145 | + public static final String FEATURE_LINKER_ERROR = "YANG file error: Unable to find feature " | ||
1146 | + + "for given if-feature"; | ||
1147 | + | ||
1148 | + /** | ||
1143 | * Static attribute for reference. | 1149 | * Static attribute for reference. |
1144 | */ | 1150 | */ |
1145 | public static final String REFERENCE = "Reference"; | 1151 | public static final String REFERENCE = "Reference"; | ... | ... |
... | @@ -16,14 +16,15 @@ | ... | @@ -16,14 +16,15 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import java.io.IOException; | ||
20 | +import java.text.ParseException; | ||
21 | +import java.text.SimpleDateFormat; | ||
19 | import org.junit.Test; | 22 | import org.junit.Test; |
20 | import org.onosproject.yangutils.datamodel.YangModule; | 23 | import org.onosproject.yangutils.datamodel.YangModule; |
21 | import org.onosproject.yangutils.datamodel.YangNode; | 24 | import org.onosproject.yangutils.datamodel.YangNode; |
22 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 25 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
23 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 26 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
24 | 27 | ||
25 | -import java.io.IOException; | ||
26 | - | ||
27 | import static org.hamcrest.core.Is.is; | 28 | import static org.hamcrest.core.Is.is; |
28 | import static org.junit.Assert.assertThat; | 29 | import static org.junit.Assert.assertThat; |
29 | 30 | ||
... | @@ -33,6 +34,8 @@ import static org.junit.Assert.assertThat; | ... | @@ -33,6 +34,8 @@ import static org.junit.Assert.assertThat; |
33 | public class ImportListenerTest { | 34 | public class ImportListenerTest { |
34 | 35 | ||
35 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); | 36 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
37 | + private static final String DATE_FORMAT = "yyyy-MM-dd"; | ||
38 | + private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); | ||
36 | 39 | ||
37 | /** | 40 | /** |
38 | * Checks if mandatory parameter prefix is present in import. | 41 | * Checks if mandatory parameter prefix is present in import. |
... | @@ -65,12 +68,12 @@ public class ImportListenerTest { | ... | @@ -65,12 +68,12 @@ public class ImportListenerTest { |
65 | * Checks if import listener updates the data model tree. | 68 | * Checks if import listener updates the data model tree. |
66 | */ | 69 | */ |
67 | @Test | 70 | @Test |
68 | - public void processImportValidEntry() throws IOException, ParserException { | 71 | + public void processImportValidEntry() throws IOException, ParserException, ParseException { |
69 | 72 | ||
70 | YangNode node = manager.getDataModel("src/test/resources/ImportValidEntry.yang"); | 73 | YangNode node = manager.getDataModel("src/test/resources/ImportValidEntry.yang"); |
71 | 74 | ||
72 | // Checks for the revision value in data model tree. | 75 | // Checks for the revision value in data model tree. |
73 | - assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03")); | 76 | + assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03"))); |
74 | // Checks for the prefix id in data model tree. | 77 | // Checks for the prefix id in data model tree. |
75 | assertThat(((YangModule) node).getImportList().get(0).getPrefixId(), is("On2")); | 78 | assertThat(((YangModule) node).getImportList().get(0).getPrefixId(), is("On2")); |
76 | // Checks for the module name in data model tree. | 79 | // Checks for the module name in data model tree. | ... | ... |
... | @@ -16,14 +16,15 @@ | ... | @@ -16,14 +16,15 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import java.io.IOException; | ||
20 | +import java.text.ParseException; | ||
21 | +import java.text.SimpleDateFormat; | ||
19 | import org.junit.Test; | 22 | import org.junit.Test; |
20 | import org.onosproject.yangutils.datamodel.YangModule; | 23 | import org.onosproject.yangutils.datamodel.YangModule; |
21 | import org.onosproject.yangutils.datamodel.YangNode; | 24 | import org.onosproject.yangutils.datamodel.YangNode; |
22 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 25 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
23 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 26 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
24 | 27 | ||
25 | -import java.io.IOException; | ||
26 | - | ||
27 | import static org.hamcrest.core.Is.is; | 28 | import static org.hamcrest.core.Is.is; |
28 | import static org.junit.Assert.assertThat; | 29 | import static org.junit.Assert.assertThat; |
29 | 30 | ||
... | @@ -33,6 +34,8 @@ import static org.junit.Assert.assertThat; | ... | @@ -33,6 +34,8 @@ import static org.junit.Assert.assertThat; |
33 | public class IncludeListenerTest { | 34 | public class IncludeListenerTest { |
34 | 35 | ||
35 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); | 36 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
37 | + private static final String DATE_FORMAT = "yyyy-MM-dd"; | ||
38 | + private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); | ||
36 | 39 | ||
37 | /** | 40 | /** |
38 | * Checks if include listener with ; is valid and updates the data | 41 | * Checks if include listener with ; is valid and updates the data |
... | @@ -65,43 +68,43 @@ public class IncludeListenerTest { | ... | @@ -65,43 +68,43 @@ public class IncludeListenerTest { |
65 | * and updates the data model tree. | 68 | * and updates the data model tree. |
66 | */ | 69 | */ |
67 | @Test | 70 | @Test |
68 | - public void processIncludeWithDate() throws IOException, ParserException { | 71 | + public void processIncludeWithDate() throws IOException, ParserException, ParseException { |
69 | 72 | ||
70 | YangNode node = manager.getDataModel("src/test/resources/IncludeWithDate.yang"); | 73 | YangNode node = manager.getDataModel("src/test/resources/IncludeWithDate.yang"); |
71 | 74 | ||
72 | // Checks for the sub module name in data model tree. | 75 | // Checks for the sub module name in data model tree. |
73 | assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut")); | 76 | assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut")); |
74 | - assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03")); | 77 | + assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03"))); |
75 | } | 78 | } |
76 | 79 | ||
77 | /** | 80 | /** |
78 | * Checks if include has more than one occurrence. | 81 | * Checks if include has more than one occurrence. |
79 | */ | 82 | */ |
80 | @Test | 83 | @Test |
81 | - public void processIncludeMultiInstance() throws IOException, ParserException { | 84 | + public void processIncludeMultiInstance() throws IOException, ParserException, ParseException { |
82 | 85 | ||
83 | YangNode node = manager.getDataModel("src/test/resources/IncludeMultiInstance.yang"); | 86 | YangNode node = manager.getDataModel("src/test/resources/IncludeMultiInstance.yang"); |
84 | 87 | ||
85 | // Checks for the sub module name in data model tree. | 88 | // Checks for the sub module name in data model tree. |
86 | assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut")); | 89 | assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut")); |
87 | - assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03")); | 90 | + assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03"))); |
88 | assertThat(((YangModule) node).getIncludeList().get(1).getSubModuleName(), is("sdn")); | 91 | assertThat(((YangModule) node).getIncludeList().get(1).getSubModuleName(), is("sdn")); |
89 | - assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03")); | 92 | + assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03"))); |
90 | } | 93 | } |
91 | 94 | ||
92 | /** | 95 | /** |
93 | * Checks if include and import can come in any order. | 96 | * Checks if include and import can come in any order. |
94 | */ | 97 | */ |
95 | @Test | 98 | @Test |
96 | - public void processIncludeImportAnyOrder() throws IOException, ParserException { | 99 | + public void processIncludeImportAnyOrder() throws IOException, ParserException, ParseException { |
97 | 100 | ||
98 | YangNode node = manager.getDataModel("src/test/resources/IncludeImportAnyOrder.yang"); | 101 | YangNode node = manager.getDataModel("src/test/resources/IncludeImportAnyOrder.yang"); |
99 | 102 | ||
100 | // Checks for the sub module name in data model tree. | 103 | // Checks for the sub module name in data model tree. |
101 | assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut")); | 104 | assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut")); |
102 | - assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03")); | 105 | + assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03"))); |
103 | assertThat(((YangModule) node).getIncludeList().get(1).getSubModuleName(), is("sdn")); | 106 | assertThat(((YangModule) node).getIncludeList().get(1).getSubModuleName(), is("sdn")); |
104 | - assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03")); | 107 | + assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03"))); |
105 | } | 108 | } |
106 | 109 | ||
107 | /** | 110 | /** | ... | ... |
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 org.junit.Test; | ||
20 | +import org.onosproject.yangutils.datamodel.YangMust; | ||
21 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
22 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
23 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
24 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
25 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
26 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
27 | + | ||
28 | +import java.io.IOException; | ||
29 | +import java.util.List; | ||
30 | +import java.util.ListIterator; | ||
31 | + | ||
32 | +import static org.hamcrest.core.Is.is; | ||
33 | +import static org.junit.Assert.assertThat; | ||
34 | + | ||
35 | +/** | ||
36 | + * Test cases for testing must listener functionality. | ||
37 | + */ | ||
38 | +public class MustListenerTest { | ||
39 | + | ||
40 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
41 | + | ||
42 | + /** | ||
43 | + * Checks if must listener updates the data model. | ||
44 | + */ | ||
45 | + @Test | ||
46 | + public void processContainerSubStatementMust() throws IOException, ParserException { | ||
47 | + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementMust.yang"); | ||
48 | + | ||
49 | + YangModule yangNode = (YangModule) node; | ||
50 | + assertThat(yangNode.getName(), is("Test")); | ||
51 | + | ||
52 | + YangContainer yangContainer = (YangContainer) yangNode.getChild(); | ||
53 | + assertThat(yangContainer.getName(), is("interface")); | ||
54 | + | ||
55 | + String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)"; | ||
56 | + List<YangMust> mustConstraintList = yangContainer.getListOfMust(); | ||
57 | + assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint)); | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * Checks if must listener updates the data model. | ||
62 | + */ | ||
63 | + @Test | ||
64 | + public void processLeafSubStatementMust() throws IOException, ParserException { | ||
65 | + YangNode node = manager.getDataModel("src/test/resources/LeafSubStatementMust.yang"); | ||
66 | + | ||
67 | + YangModule yangNode = (YangModule) node; | ||
68 | + assertThat(yangNode.getName(), is("Test")); | ||
69 | + | ||
70 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
71 | + YangLeaf leafInfo = leafIterator.next(); | ||
72 | + | ||
73 | + assertThat(leafInfo.getListOfMust().iterator().next().getConstraint(), is("ifType != 'ethernet'")); | ||
74 | + } | ||
75 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -16,14 +16,15 @@ | ... | @@ -16,14 +16,15 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import java.io.IOException; | ||
20 | +import java.text.ParseException; | ||
21 | +import java.text.SimpleDateFormat; | ||
19 | import org.junit.Test; | 22 | import org.junit.Test; |
20 | import org.onosproject.yangutils.datamodel.YangModule; | 23 | import org.onosproject.yangutils.datamodel.YangModule; |
21 | import org.onosproject.yangutils.datamodel.YangNode; | 24 | import org.onosproject.yangutils.datamodel.YangNode; |
22 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 25 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
23 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 26 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
24 | 27 | ||
25 | -import java.io.IOException; | ||
26 | - | ||
27 | import static org.hamcrest.core.Is.is; | 28 | import static org.hamcrest.core.Is.is; |
28 | import static org.junit.Assert.assertThat; | 29 | import static org.junit.Assert.assertThat; |
29 | 30 | ||
... | @@ -33,6 +34,8 @@ import static org.junit.Assert.assertThat; | ... | @@ -33,6 +34,8 @@ import static org.junit.Assert.assertThat; |
33 | public class RevisionDateListenerTest { | 34 | public class RevisionDateListenerTest { |
34 | 35 | ||
35 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); | 36 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
37 | + private static final String DATE_FORMAT = "yyyy-MM-dd"; | ||
38 | + private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); | ||
36 | 39 | ||
37 | /** | 40 | /** |
38 | * Checks if revision date syntax is correct in include. | 41 | * Checks if revision date syntax is correct in include. |
... | @@ -56,26 +59,26 @@ public class RevisionDateListenerTest { | ... | @@ -56,26 +59,26 @@ public class RevisionDateListenerTest { |
56 | * Checks revision date in quotes inside include. | 59 | * Checks revision date in quotes inside include. |
57 | */ | 60 | */ |
58 | @Test | 61 | @Test |
59 | - public void processRevisionDateInQuotesAtInclude() throws IOException, ParserException { | 62 | + public void processRevisionDateInQuotesAtInclude() throws IOException, ParserException, ParseException { |
60 | 63 | ||
61 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtInclude.yang"); | 64 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtInclude.yang"); |
62 | // Checks for the version value in data model tree. | 65 | // Checks for the version value in data model tree. |
63 | - assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03")); | 66 | + assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03"))); |
64 | - assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03")); | 67 | + assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03"))); |
65 | - assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03")); | 68 | + assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03"))); |
66 | } | 69 | } |
67 | 70 | ||
68 | /** | 71 | /** |
69 | * Checks revision date in quotes inside import. | 72 | * Checks revision date in quotes inside import. |
70 | */ | 73 | */ |
71 | @Test | 74 | @Test |
72 | - public void processRevisionDateInQuotesAtImport() throws IOException, ParserException { | 75 | + public void processRevisionDateInQuotesAtImport() throws IOException, ParserException, ParseException { |
73 | 76 | ||
74 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtImport.yang"); | 77 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtImport.yang"); |
75 | // Checks for the version value in data model tree. | 78 | // Checks for the version value in data model tree. |
76 | - assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03")); | 79 | + assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03"))); |
77 | - assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03")); | 80 | + assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03"))); |
78 | - assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03")); | 81 | + assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03"))); |
79 | } | 82 | } |
80 | 83 | ||
81 | /** | 84 | /** |
... | @@ -100,13 +103,13 @@ public class RevisionDateListenerTest { | ... | @@ -100,13 +103,13 @@ public class RevisionDateListenerTest { |
100 | * Checks if revision date listener updates the data model tree. | 103 | * Checks if revision date listener updates the data model tree. |
101 | */ | 104 | */ |
102 | @Test | 105 | @Test |
103 | - public void processRevisionDateValidEntry() throws IOException, ParserException { | 106 | + public void processRevisionDateValidEntry() throws IOException, ParserException, ParseException { |
104 | 107 | ||
105 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateValidEntry.yang"); | 108 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateValidEntry.yang"); |
106 | 109 | ||
107 | // Checks for the version value in data model tree. | 110 | // Checks for the version value in data model tree. |
108 | - assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03")); | 111 | + assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03"))); |
109 | - assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03")); | 112 | + assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03"))); |
110 | - assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03")); | 113 | + assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03"))); |
111 | } | 114 | } |
112 | } | 115 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,14 +16,15 @@ | ... | @@ -16,14 +16,15 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import java.io.IOException; | ||
20 | +import java.text.ParseException; | ||
21 | +import java.text.SimpleDateFormat; | ||
19 | import org.junit.Test; | 22 | import org.junit.Test; |
20 | import org.onosproject.yangutils.datamodel.YangModule; | 23 | import org.onosproject.yangutils.datamodel.YangModule; |
21 | import org.onosproject.yangutils.datamodel.YangNode; | 24 | import org.onosproject.yangutils.datamodel.YangNode; |
22 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 25 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
23 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 26 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
24 | 27 | ||
25 | -import java.io.IOException; | ||
26 | - | ||
27 | import static org.hamcrest.core.Is.is; | 28 | import static org.hamcrest.core.Is.is; |
28 | import static org.hamcrest.core.IsNull.notNullValue; | 29 | import static org.hamcrest.core.IsNull.notNullValue; |
29 | import static org.junit.Assert.assertThat; | 30 | import static org.junit.Assert.assertThat; |
... | @@ -34,18 +35,19 @@ import static org.junit.Assert.assertThat; | ... | @@ -34,18 +35,19 @@ import static org.junit.Assert.assertThat; |
34 | public class RevisionListenerTest { | 35 | public class RevisionListenerTest { |
35 | 36 | ||
36 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); | 37 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
38 | + private static final String DATE_FORMAT = "yyyy-MM-dd"; | ||
39 | + private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); | ||
37 | 40 | ||
38 | /** | 41 | /** |
39 | * Checks if revision doesn't have optional parameters "revision and | 42 | * Checks if revision doesn't have optional parameters "revision and |
40 | * description". | 43 | * description". |
41 | */ | 44 | */ |
42 | @Test | 45 | @Test |
43 | - public void processRevisionNoOptionalParameter() throws IOException, ParserException { | 46 | + public void processRevisionNoOptionalParameter() throws IOException, ParserException, ParseException { |
44 | 47 | ||
45 | YangNode node = manager.getDataModel("src/test/resources/RevisionNoOptionalParameter.yang"); | 48 | YangNode node = manager.getDataModel("src/test/resources/RevisionNoOptionalParameter.yang"); |
46 | - | ||
47 | // Checks for the version value in data model tree. | 49 | // Checks for the version value in data model tree. |
48 | - assertThat(((YangModule) node).getRevision().getRevDate(), is("2016-02-03")); | 50 | + assertThat(((YangModule) node).getRevision().getRevDate(), is(simpleDateFormat.parse("2016-02-03"))); |
49 | } | 51 | } |
50 | 52 | ||
51 | /** | 53 | /** |
... | @@ -75,4 +77,14 @@ public class RevisionListenerTest { | ... | @@ -75,4 +77,14 @@ public class RevisionListenerTest { |
75 | YangNode node = manager.getDataModel("src/test/resources/RevisionAbsence.yang"); | 77 | YangNode node = manager.getDataModel("src/test/resources/RevisionAbsence.yang"); |
76 | assertThat(((YangModule) node).getRevision().getRevDate(), notNullValue()); | 78 | assertThat(((YangModule) node).getRevision().getRevDate(), notNullValue()); |
77 | } | 79 | } |
80 | + | ||
81 | + /** | ||
82 | + * Checks latest date is stored when there are multiple revisions. | ||
83 | + */ | ||
84 | + @Test | ||
85 | + public void processWithMultipleRevision() throws IOException, ParserException, ParseException { | ||
86 | + | ||
87 | + YangNode node = manager.getDataModel("src/test/resources/MultipleRevision.yang"); | ||
88 | + assertThat(((YangModule) node).getRevision().getRevDate(), is(simpleDateFormat.parse("2013-07-15"))); | ||
89 | + } | ||
78 | } | 90 | } |
... | \ 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.parser.impl.listeners; | ||
18 | + | ||
19 | +import org.junit.Test; | ||
20 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
21 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
22 | +import org.onosproject.yangutils.datamodel.YangList; | ||
23 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
24 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
25 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
26 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
27 | + | ||
28 | +import java.io.IOException; | ||
29 | +import java.util.ListIterator; | ||
30 | + | ||
31 | +import static org.hamcrest.core.Is.is; | ||
32 | +import static org.junit.Assert.assertThat; | ||
33 | + | ||
34 | +/** | ||
35 | + * Test cases for testing when listener functionality. | ||
36 | + */ | ||
37 | +public class WhenListenerTest { | ||
38 | + | ||
39 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
40 | + | ||
41 | + /** | ||
42 | + * Checks if when listener updates the data model. | ||
43 | + */ | ||
44 | + @Test | ||
45 | + public void processContainerSubStatementWhen() throws IOException, ParserException { | ||
46 | + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementWhen.yang"); | ||
47 | + | ||
48 | + YangModule yangNode = (YangModule) node; | ||
49 | + assertThat(yangNode.getName(), is("Test")); | ||
50 | + | ||
51 | + YangList yangList = (YangList) yangNode.getChild(); | ||
52 | + assertThat(yangList.getName(), is("interface-switching-capability")); | ||
53 | + | ||
54 | + YangContainer container = (YangContainer) yangList.getNextSibling(); | ||
55 | + assertThat(container.getName(), is("time-division-multiplex-capable")); | ||
56 | + | ||
57 | + String expectedConstraint = "../switching-capability = 'TDM'"; | ||
58 | + assertThat(container.getWhen().getCondition(), is(expectedConstraint)); | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * Checks if when listener updates the data model. | ||
63 | + */ | ||
64 | + @Test | ||
65 | + public void processLeafSubStatementWhen() throws IOException, ParserException { | ||
66 | + YangNode node = manager.getDataModel("src/test/resources/LeafSubStatementWhen.yang"); | ||
67 | + | ||
68 | + YangModule yangNode = (YangModule) node; | ||
69 | + assertThat(yangNode.getName(), is("Test")); | ||
70 | + | ||
71 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
72 | + YangLeaf leafInfo = leafIterator.next(); | ||
73 | + | ||
74 | + assertThat(leafInfo.getWhen().getCondition(), is("ifType != 'ethernet'")); | ||
75 | + } | ||
76 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed. Click to expand it.
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 java.io.IOException; | ||
20 | +import java.util.List; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
23 | +import org.onosproject.yangutils.datamodel.YangFeature; | ||
24 | +import org.onosproject.yangutils.datamodel.YangIfFeature; | ||
25 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
26 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
27 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
28 | +import org.onosproject.yangutils.datamodel.YangNodeType; | ||
29 | +import org.onosproject.yangutils.datamodel.YangSubModule; | ||
30 | +import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; | ||
31 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
32 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
33 | + | ||
34 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
35 | +import static org.hamcrest.core.Is.is; | ||
36 | + | ||
37 | +/** | ||
38 | + * Test cases for testing if-feature intra file linking. | ||
39 | + */ | ||
40 | +public class IntraFileIfFeatureLinkingTest { | ||
41 | + | ||
42 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
43 | + | ||
44 | + /** | ||
45 | + * Checks self resolution when feature defined in same file. | ||
46 | + */ | ||
47 | + @Test | ||
48 | + public void processSelfFileLinkingWithFeature() | ||
49 | + throws IOException, ParserException { | ||
50 | + | ||
51 | + YangNode node = manager | ||
52 | + .getDataModel("src/test/resources/SelfFileLinkingWithFeature.yang"); | ||
53 | + | ||
54 | + // Check whether the data model tree returned is of type module. | ||
55 | + assertThat((node instanceof YangModule), is(true)); | ||
56 | + | ||
57 | + // Check whether the node type is set properly to module. | ||
58 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
59 | + | ||
60 | + // Check whether the module name is set correctly. | ||
61 | + YangModule yangNode = (YangModule) node; | ||
62 | + assertThat(yangNode.getName(), is("syslog")); | ||
63 | + | ||
64 | + List<YangFeature> featureList = yangNode.getFeatureList(); | ||
65 | + YangFeature feature = featureList.iterator().next(); | ||
66 | + assertThat(feature.getName(), is("local-storage")); | ||
67 | + | ||
68 | + YangContainer container = (YangContainer) yangNode.getChild(); | ||
69 | + assertThat(container.getName(), is("speed")); | ||
70 | + | ||
71 | + List<YangLeaf> listOfLeaf = container.getListOfLeaf(); | ||
72 | + YangLeaf leaf = listOfLeaf.iterator().next(); | ||
73 | + assertThat(leaf.getName(), is("local-storage-limit")); | ||
74 | + | ||
75 | + List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList(); | ||
76 | + YangIfFeature ifFeature = ifFeatureList.iterator().next(); | ||
77 | + assertThat(ifFeature.getName().getName(), is("local-storage")); | ||
78 | + assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * Checks self resolution when feature is undefined. | ||
83 | + */ | ||
84 | + @Test | ||
85 | + public void processSelfFileLinkingWithFeatureUndefined() | ||
86 | + throws IOException, ParserException { | ||
87 | + | ||
88 | + YangNode node = manager | ||
89 | + .getDataModel("src/test/resources/SelfFileLinkingWithFeatureUndefined.yang"); | ||
90 | + | ||
91 | + // Check whether the data model tree returned is of type module. | ||
92 | + assertThat((node instanceof YangModule), is(true)); | ||
93 | + | ||
94 | + // Check whether the node type is set properly to module. | ||
95 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
96 | + | ||
97 | + // Check whether the module name is set correctly. | ||
98 | + YangModule yangNode = (YangModule) node; | ||
99 | + assertThat(yangNode.getName(), is("syslog")); | ||
100 | + | ||
101 | + YangContainer container = (YangContainer) yangNode.getChild(); | ||
102 | + assertThat(container.getName(), is("speed")); | ||
103 | + | ||
104 | + List<YangLeaf> listOfLeaf = container.getListOfLeaf(); | ||
105 | + YangLeaf leaf = listOfLeaf.iterator().next(); | ||
106 | + assertThat(leaf.getName(), is("local-storage-limit")); | ||
107 | + | ||
108 | + List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList(); | ||
109 | + YangIfFeature ifFeature = ifFeatureList.iterator().next(); | ||
110 | + assertThat(ifFeature.getName().getName(), is("local-storage")); | ||
111 | + assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.INTRA_FILE_RESOLVED)); | ||
112 | + } | ||
113 | + | ||
114 | + /** | ||
115 | + * Checks self resolution of feature with multiple dependency. | ||
116 | + */ | ||
117 | + @Test | ||
118 | + public void processSelfFileLinkingWithMultipleDependency() throws IOException, ParserException { | ||
119 | + YangNode node = manager | ||
120 | + .getDataModel("src/test/resources/SelfFileLinkingWithMultipleDependency.yang"); | ||
121 | + | ||
122 | + // Check whether the data model tree returned is of type module. | ||
123 | + assertThat((node instanceof YangModule), is(true)); | ||
124 | + | ||
125 | + // Check whether the node type is set properly to module. | ||
126 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
127 | + | ||
128 | + // Check whether the module name is set correctly. | ||
129 | + YangModule yangNode = (YangModule) node; | ||
130 | + assertThat(yangNode.getName(), is("syslog")); | ||
131 | + | ||
132 | + List<YangFeature> featureList = yangNode.getFeatureList(); | ||
133 | + YangFeature feature = featureList.iterator().next(); | ||
134 | + assertThat(feature.getName(), is("p2mp-te")); | ||
135 | + | ||
136 | + YangContainer container = (YangContainer) yangNode.getChild(); | ||
137 | + assertThat(container.getName(), is("speed")); | ||
138 | + | ||
139 | + List<YangLeaf> listOfLeaf = container.getListOfLeaf(); | ||
140 | + YangLeaf leaf = listOfLeaf.iterator().next(); | ||
141 | + assertThat(leaf.getName(), is("local-storage-limit")); | ||
142 | + | ||
143 | + List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList(); | ||
144 | + YangIfFeature ifFeature = ifFeatureList.iterator().next(); | ||
145 | + assertThat(ifFeature.getName().getName(), is("frr-te")); | ||
146 | + assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); | ||
147 | + } | ||
148 | + | ||
149 | + /** | ||
150 | + * Checks self resolution of feature with multiple dependency undefined. | ||
151 | + */ | ||
152 | + @Test | ||
153 | + public void processSelfFileLinkingWithMultipleDependencyUnresolved() throws IOException, ParserException { | ||
154 | + YangNode node = manager | ||
155 | + .getDataModel("src/test/resources/SelfFileLinkingWithMultipleDependencyUnresolved.yang"); | ||
156 | + | ||
157 | + // Check whether the data model tree returned is of type module. | ||
158 | + assertThat((node instanceof YangModule), is(true)); | ||
159 | + | ||
160 | + // Check whether the node type is set properly to module. | ||
161 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
162 | + | ||
163 | + // Check whether the module name is set correctly. | ||
164 | + YangModule yangNode = (YangModule) node; | ||
165 | + assertThat(yangNode.getName(), is("syslog")); | ||
166 | + | ||
167 | + List<YangFeature> featureList = yangNode.getFeatureList(); | ||
168 | + YangFeature feature = featureList.iterator().next(); | ||
169 | + assertThat(feature.getName(), is("frr-te")); | ||
170 | + | ||
171 | + YangContainer container = (YangContainer) yangNode.getChild(); | ||
172 | + assertThat(container.getName(), is("speed")); | ||
173 | + | ||
174 | + List<YangLeaf> listOfLeaf = container.getListOfLeaf(); | ||
175 | + YangLeaf leaf = listOfLeaf.iterator().next(); | ||
176 | + assertThat(leaf.getName(), is("local-storage-limit")); | ||
177 | + | ||
178 | + List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList(); | ||
179 | + YangIfFeature ifFeature = ifFeatureList.iterator().next(); | ||
180 | + assertThat(ifFeature.getName().getName(), is("frr-te")); | ||
181 | + assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.INTRA_FILE_RESOLVED)); | ||
182 | + } | ||
183 | + | ||
184 | + /** | ||
185 | + * Checks self resolution when feature is defined in same file in submodule. | ||
186 | + */ | ||
187 | + @Test | ||
188 | + public void processSelfFileLinkingWithFeatureInSubModule() | ||
189 | + throws IOException, ParserException { | ||
190 | + | ||
191 | + YangNode node = manager | ||
192 | + .getDataModel("src/test/resources/SelfFileLinkingWithFeatureInSubModule.yang"); | ||
193 | + | ||
194 | + // Check whether the data model tree returned is of type module. | ||
195 | + assertThat((node instanceof YangSubModule), is(true)); | ||
196 | + | ||
197 | + // Check whether the node type is set properly to module. | ||
198 | + assertThat(node.getNodeType(), is(YangNodeType.SUB_MODULE_NODE)); | ||
199 | + | ||
200 | + // Check whether the module name is set correctly. | ||
201 | + YangSubModule yangNode = (YangSubModule) node; | ||
202 | + assertThat(yangNode.getName(), is("syslog")); | ||
203 | + | ||
204 | + List<YangFeature> featureList = yangNode.getFeatureList(); | ||
205 | + YangFeature feature = featureList.iterator().next(); | ||
206 | + assertThat(feature.getName(), is("local-storage")); | ||
207 | + | ||
208 | + YangContainer container = (YangContainer) yangNode.getChild(); | ||
209 | + assertThat(container.getName(), is("speed")); | ||
210 | + | ||
211 | + List<YangLeaf> listOfLeaf = container.getListOfLeaf(); | ||
212 | + YangLeaf leaf = listOfLeaf.iterator().next(); | ||
213 | + assertThat(leaf.getName(), is("local-storage-limit")); | ||
214 | + | ||
215 | + List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList(); | ||
216 | + YangIfFeature ifFeature = ifFeatureList.iterator().next(); | ||
217 | + assertThat(ifFeature.getName().getName(), is("local-storage")); | ||
218 | + assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); | ||
219 | + } | ||
220 | +} |
... | @@ -20,6 +20,9 @@ import java.io.File; | ... | @@ -20,6 +20,9 @@ import java.io.File; |
20 | import java.io.IOException; | 20 | import java.io.IOException; |
21 | import java.lang.reflect.Constructor; | 21 | import java.lang.reflect.Constructor; |
22 | import java.lang.reflect.InvocationTargetException; | 22 | import java.lang.reflect.InvocationTargetException; |
23 | +import java.text.ParseException; | ||
24 | +import java.text.SimpleDateFormat; | ||
25 | +import java.util.Date; | ||
23 | import org.junit.Rule; | 26 | import org.junit.Rule; |
24 | import org.junit.Test; | 27 | import org.junit.Test; |
25 | import org.junit.rules.ExpectedException; | 28 | import org.junit.rules.ExpectedException; |
... | @@ -104,6 +107,8 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -104,6 +107,8 @@ public final class JavaIdentifierSyntaxTest { |
104 | private static final String WITH_SMALL = "test_this"; | 107 | private static final String WITH_SMALL = "test_this"; |
105 | private static final String WITH_CAMEL_CASE_WITH_PREFIX = "123addPrefixTry"; | 108 | private static final String WITH_CAMEL_CASE_WITH_PREFIX = "123addPrefixTry"; |
106 | private static final String WITH_CAMEL_CASE_WITH_PREFIX1 = "abc1234567890Ss1123G123Gaa"; | 109 | private static final String WITH_CAMEL_CASE_WITH_PREFIX1 = "abc1234567890Ss1123G123Gaa"; |
110 | + private static final String DATE_FORMAT = "yyyy-MM-dd"; | ||
111 | + private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); | ||
107 | private static YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil(); | 112 | private static YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil(); |
108 | private static final String BASE_DIR_PKG = "target.UnitTestCase."; | 113 | private static final String BASE_DIR_PKG = "target.UnitTestCase."; |
109 | private static final String DIR_PATH = "exist1.exist2.exist3"; | 114 | private static final String DIR_PATH = "exist1.exist2.exist3"; |
... | @@ -140,9 +145,10 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -140,9 +145,10 @@ public final class JavaIdentifierSyntaxTest { |
140 | * Unit test for root package generation with revision complexity. | 145 | * Unit test for root package generation with revision complexity. |
141 | */ | 146 | */ |
142 | @Test | 147 | @Test |
143 | - public void getRootPackageTest() { | 148 | + public void getRootPackageTest() throws ParseException { |
144 | conflictResolver.setPrefixForIdentifier(null); | 149 | conflictResolver.setPrefixForIdentifier(null); |
145 | - String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1, conflictResolver); | 150 | + Date date = simpleDateFormat.parse(DATE1); |
151 | + String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, date, conflictResolver); | ||
146 | assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER | 152 | assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
147 | + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true)); | 153 | + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true)); |
148 | } | 154 | } |
... | @@ -151,31 +157,34 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -151,31 +157,34 @@ public final class JavaIdentifierSyntaxTest { |
151 | * Unit test for root package generation with invalid prefix. | 157 | * Unit test for root package generation with invalid prefix. |
152 | */ | 158 | */ |
153 | @Test | 159 | @Test |
154 | - public void getRootPackageWithInvalidPrefix() throws TranslatorException { | 160 | + public void getRootPackageWithInvalidPrefix() throws TranslatorException, ParseException { |
155 | thrown.expect(TranslatorException.class); | 161 | thrown.expect(TranslatorException.class); |
156 | thrown.expectMessage("The given prefix in pom.xml is invalid."); | 162 | thrown.expectMessage("The given prefix in pom.xml is invalid."); |
157 | conflictResolver.setPrefixForIdentifier(INVALID_PREFIX); | 163 | conflictResolver.setPrefixForIdentifier(INVALID_PREFIX); |
158 | - String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE_FOR_INVALID_PREFIX, DATE1, conflictResolver); | 164 | + Date date = simpleDateFormat.parse(DATE1); |
165 | + String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE_FOR_INVALID_PREFIX, date, | ||
166 | + conflictResolver); | ||
159 | } | 167 | } |
160 | 168 | ||
161 | /** | 169 | /** |
162 | * Unit test for root package generation with special characters presence. | 170 | * Unit test for root package generation with special characters presence. |
163 | */ | 171 | */ |
164 | @Test | 172 | @Test |
165 | - public void getRootPackageWithSpecialCharactersTest() { | 173 | + public void getRootPackageWithSpecialCharactersTest() throws ParseException { |
166 | conflictResolver.setPrefixForIdentifier(VALID_PREFIX); | 174 | conflictResolver.setPrefixForIdentifier(VALID_PREFIX); |
167 | - String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1, conflictResolver); | 175 | + Date date = simpleDateFormat.parse(DATE1); |
176 | + String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, date, conflictResolver); | ||
168 | assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER | 177 | assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
169 | + PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true)); | 178 | + PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true)); |
170 | conflictResolver.setPrefixForIdentifier(null); | 179 | conflictResolver.setPrefixForIdentifier(null); |
171 | - String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1, conflictResolver); | 180 | + String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, date, conflictResolver); |
172 | assertThat(rootPackage1.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER | 181 | assertThat(rootPackage1.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
173 | + PERIOD + VALID_NAME_SPACE2 + PERIOD + DATE_WITH_REV1), is(true)); | 182 | + PERIOD + VALID_NAME_SPACE2 + PERIOD + DATE_WITH_REV1), is(true)); |
174 | - String rootPackage2 = getRootPackage((byte) 1, INVALID_NAME_SPACE3, DATE1, conflictResolver); | 183 | + String rootPackage2 = getRootPackage((byte) 1, INVALID_NAME_SPACE3, date, conflictResolver); |
175 | assertThat(rootPackage2.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER | 184 | assertThat(rootPackage2.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
176 | + PERIOD + VALID_NAME_SPACE4 + PERIOD + DATE_WITH_REV1), is(true)); | 185 | + PERIOD + VALID_NAME_SPACE4 + PERIOD + DATE_WITH_REV1), is(true)); |
177 | conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1); | 186 | conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1); |
178 | - String rootPackage3 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1, conflictResolver); | 187 | + String rootPackage3 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, date, conflictResolver); |
179 | assertThat(rootPackage3.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER | 188 | assertThat(rootPackage3.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
180 | + PERIOD + VALID_NAME_SPACE3 + PERIOD + DATE_WITH_REV1), is(true)); | 189 | + PERIOD + VALID_NAME_SPACE3 + PERIOD + DATE_WITH_REV1), is(true)); |
181 | 190 | ||
... | @@ -185,8 +194,9 @@ public final class JavaIdentifierSyntaxTest { | ... | @@ -185,8 +194,9 @@ public final class JavaIdentifierSyntaxTest { |
185 | * Unit test for root package generation without complexity in revision. | 194 | * Unit test for root package generation without complexity in revision. |
186 | */ | 195 | */ |
187 | @Test | 196 | @Test |
188 | - public void getRootPackageWithRevTest() { | 197 | + public void getRootPackageWithRevTest() throws ParseException { |
189 | - String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2, null); | 198 | + Date date = simpleDateFormat.parse(DATE2); |
199 | + String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, date, null); | ||
190 | assertThat(rootPkgWithRev.equals( | 200 | assertThat(rootPkgWithRev.equals( |
191 | DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2), | 201 | DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2), |
192 | is(true)); | 202 | is(true)); | ... | ... |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + container interface { | ||
6 | + leaf ifType { | ||
7 | + type enumeration { | ||
8 | + enum ethernet; | ||
9 | + enum atm; | ||
10 | + } | ||
11 | + } | ||
12 | + leaf ifMTU { | ||
13 | + type uint32; | ||
14 | + } | ||
15 | + must "ifType != 'ethernet' or " + | ||
16 | + "(ifType = 'ethernet' and ifMTU = 1500)" { | ||
17 | + description "An ethernet MTU must be 1500"; | ||
18 | + } | ||
19 | + must "ifType != 'atm' or " + | ||
20 | + "(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" { | ||
21 | + description "An atm MTU must be 64 .. 17966"; | ||
22 | + } | ||
23 | + } | ||
24 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + list interface-switching-capability { | ||
6 | + key "switching-capability"; | ||
7 | + description | ||
8 | + "List of Interface Switching Capabilities Descriptors (ISCD) | ||
9 | + for this link."; | ||
10 | + reference | ||
11 | + "RFC3471: Generalized Multi-Protocol Label Switching (GMPLS) | ||
12 | + Signaling Functional Description. | ||
13 | + RFC4203: OSPF Extensions in Support of Generalized | ||
14 | + Multi-Protocol Label Switching (GMPLS)."; | ||
15 | + leaf switching-capability { | ||
16 | + type string; | ||
17 | + description | ||
18 | + "Switching Capability for this interface."; | ||
19 | + } | ||
20 | + } | ||
21 | + container time-division-multiplex-capable { | ||
22 | + when "../switching-capability = 'TDM'" { | ||
23 | + description "Valid only for TDM"; | ||
24 | + } | ||
25 | + description | ||
26 | + "Interface has time-division multiplex capabilities."; | ||
27 | + | ||
28 | + leaf minimum-lsp-bandwidth { | ||
29 | + type decimal64; | ||
30 | + } | ||
31 | + } | ||
32 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace urn:ietf:params:xml:ns:yang:ietf-ospf; | ||
4 | + prefix test; | ||
5 | + | ||
6 | + revision 2013-07-15 { | ||
7 | + description | ||
8 | + "This revision adds the following new data types: | ||
9 | + - yang-identifier | ||
10 | + - hex-string | ||
11 | + - uuid | ||
12 | + - dotted-quad"; | ||
13 | + reference | ||
14 | + "RFC 6991: Common YANG Data Types"; | ||
15 | + } | ||
16 | + revision 2013-07-14 { | ||
17 | + description | ||
18 | + "This revision adds the following new data types: | ||
19 | + - yang-identifier | ||
20 | + - hex-string | ||
21 | + - uuid | ||
22 | + - dotted-quad"; | ||
23 | + reference | ||
24 | + "RFC 6991: Common YANG Data Types"; | ||
25 | + } | ||
26 | +} |
1 | +module syslog { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix "sys"; | ||
5 | + feature local-storage { | ||
6 | + description | ||
7 | + "This feature means the device supports local | ||
8 | + storage (memory, flash or disk) that can be used to | ||
9 | + store syslog messages."; | ||
10 | + } | ||
11 | + | ||
12 | + container speed { | ||
13 | + leaf local-storage-limit { | ||
14 | + if-feature local-storage; | ||
15 | + type uint64; | ||
16 | + units "kilobyte"; | ||
17 | + config false; | ||
18 | + description | ||
19 | + "The amount of local storage that can be | ||
20 | + used to hold syslog messages."; | ||
21 | + } | ||
22 | + } | ||
23 | +} |
1 | +submodule syslog { | ||
2 | + yang-version 1; | ||
3 | + belongs-to "syslog1" { | ||
4 | + prefix "sys"; | ||
5 | + } | ||
6 | + feature local-storage { | ||
7 | + description | ||
8 | + "This feature means the device supports local | ||
9 | + storage (memory, flash or disk) that can be used to | ||
10 | + store syslog messages."; | ||
11 | + } | ||
12 | + | ||
13 | + container speed { | ||
14 | + leaf local-storage-limit { | ||
15 | + if-feature local-storage; | ||
16 | + type uint64; | ||
17 | + units "kilobyte"; | ||
18 | + config false; | ||
19 | + description | ||
20 | + "The amount of local storage that can be | ||
21 | + used to hold syslog messages."; | ||
22 | + } | ||
23 | + } | ||
24 | +} |
1 | +module syslog { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix "sys"; | ||
5 | + | ||
6 | + container speed { | ||
7 | + leaf local-storage-limit { | ||
8 | + if-feature local-storage; | ||
9 | + type uint64; | ||
10 | + units "kilobyte"; | ||
11 | + config false; | ||
12 | + description | ||
13 | + "The amount of local storage that can be | ||
14 | + used to hold syslog messages."; | ||
15 | + } | ||
16 | + } | ||
17 | +} |
1 | +module syslog { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix "sys"; | ||
5 | + | ||
6 | + feature p2mp-te { | ||
7 | + description "Indicates support for P2MP-TE"; | ||
8 | + } | ||
9 | + | ||
10 | + feature frr-te { | ||
11 | + description "Indicates support for TE FastReroute (FRR)"; | ||
12 | + if-feature p2mp-te; | ||
13 | + } | ||
14 | + | ||
15 | + container speed { | ||
16 | + leaf local-storage-limit { | ||
17 | + if-feature frr-te; | ||
18 | + type uint64; | ||
19 | + units "kilobyte"; | ||
20 | + config false; | ||
21 | + description | ||
22 | + "The amount of local storage that can be | ||
23 | + used to hold syslog messages."; | ||
24 | + } | ||
25 | + } | ||
26 | +} |
utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithMultipleDependencyUnresolved.yang
0 → 100644
1 | +module syslog { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix "sys"; | ||
5 | + | ||
6 | + feature frr-te { | ||
7 | + description "Indicates support for TE FastReroute (FRR)"; | ||
8 | + if-feature p2mp-te; | ||
9 | + } | ||
10 | + | ||
11 | + container speed { | ||
12 | + leaf local-storage-limit { | ||
13 | + if-feature frr-te; | ||
14 | + type uint64; | ||
15 | + units "kilobyte"; | ||
16 | + config false; | ||
17 | + description | ||
18 | + "The amount of local storage that can be | ||
19 | + used to hold syslog messages."; | ||
20 | + } | ||
21 | + } | ||
22 | +} |
1 | +module syslog { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix "sys"; | ||
5 | + | ||
6 | + feature p2mp-te { | ||
7 | + description "Indicates support for P2MP-TE"; | ||
8 | + } | ||
9 | + | ||
10 | + feature frr-te { | ||
11 | + description "Indicates support for TE FastReroute (FRR)"; | ||
12 | + if-feature p2mp-te; | ||
13 | + } | ||
14 | + | ||
15 | + container speed { | ||
16 | + leaf local-storage-limit { | ||
17 | + if-feature local-storage; | ||
18 | + type uint64; | ||
19 | + units "kilobyte"; | ||
20 | + config false; | ||
21 | + description | ||
22 | + "The amount of local storage that can be | ||
23 | + used to hold syslog messages."; | ||
24 | + } | ||
25 | + } | ||
26 | +} |
1 | +module syslog1 { | ||
2 | + yang-version 1; | ||
3 | + namespace "http://huawei1.com"; | ||
4 | + prefix "sys1"; | ||
5 | + | ||
6 | + import "syslog2" { | ||
7 | + prefix "sys2"; | ||
8 | + } | ||
9 | + | ||
10 | + feature frr-te { | ||
11 | + description "Indicates support for TE FastReroute (FRR)"; | ||
12 | + if-feature "sys2:p2mp-te"; | ||
13 | + } | ||
14 | + | ||
15 | + container speed { | ||
16 | + leaf local-storage-limit { | ||
17 | + if-feature frr-te; | ||
18 | + type uint64; | ||
19 | + units "kilobyte"; | ||
20 | + config false; | ||
21 | + description | ||
22 | + "The amount of local storage that can be | ||
23 | + used to hold syslog messages."; | ||
24 | + } | ||
25 | + } | ||
26 | +} |
utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependency/featurefile1.yang
0 → 100644
1 | +module syslog1 { | ||
2 | + yang-version 1; | ||
3 | + namespace "http://huawei1.com"; | ||
4 | + prefix "sys1"; | ||
5 | + | ||
6 | + import "syslog2" { | ||
7 | + prefix "sys2"; | ||
8 | + } | ||
9 | + | ||
10 | + feature frr-te { | ||
11 | + description "Indicates support for TE FastReroute (FRR)"; | ||
12 | + if-feature "sys2:p2mp-te"; | ||
13 | + } | ||
14 | + | ||
15 | + container speed { | ||
16 | + leaf local-storage-limit { | ||
17 | + if-feature frr-te; | ||
18 | + type uint64; | ||
19 | + units "kilobyte"; | ||
20 | + config false; | ||
21 | + description | ||
22 | + "The amount of local storage that can be | ||
23 | + used to hold syslog messages."; | ||
24 | + } | ||
25 | + } | ||
26 | +} |
1 | +module syslog1 { | ||
2 | + yang-version 1; | ||
3 | + namespace "http://huawei1.com"; | ||
4 | + prefix "sys1"; | ||
5 | + | ||
6 | + import "syslog2" { | ||
7 | + prefix "sys2"; | ||
8 | + } | ||
9 | + | ||
10 | + feature frr-te { | ||
11 | + description "Indicates support for TE FastReroute (FRR)"; | ||
12 | + if-feature "sys2:p2mp-te"; | ||
13 | + } | ||
14 | + | ||
15 | + container speed { | ||
16 | + leaf local-storage-limit { | ||
17 | + if-feature frr-te; | ||
18 | + type uint64; | ||
19 | + units "kilobyte"; | ||
20 | + config false; | ||
21 | + description | ||
22 | + "The amount of local storage that can be | ||
23 | + used to hold syslog messages."; | ||
24 | + } | ||
25 | + } | ||
26 | +} |
1 | +module syslog3 { | ||
2 | + yang-version 1; | ||
3 | + namespace "http://huawei3.com"; | ||
4 | + prefix "sys3"; | ||
5 | + | ||
6 | + include "syslog4"; | ||
7 | + | ||
8 | + feature frr-te { | ||
9 | + description "Indicates support for TE FastReroute (FRR)"; | ||
10 | + if-feature "p2mp-te"; | ||
11 | + } | ||
12 | + | ||
13 | + container speed { | ||
14 | + leaf local-storage-limit { | ||
15 | + if-feature frr-te; | ||
16 | + type uint64; | ||
17 | + units "kilobyte"; | ||
18 | + config false; | ||
19 | + description | ||
20 | + "The amount of local storage that can be | ||
21 | + used to hold syslog messages."; | ||
22 | + } | ||
23 | + } | ||
24 | +} |
utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependency/featurefile1.yang
0 → 100644
1 | +module syslog1 { | ||
2 | + yang-version 1; | ||
3 | + namespace "http://huawei3.com"; | ||
4 | + prefix "sys1"; | ||
5 | + | ||
6 | + include "syslog2"; | ||
7 | + | ||
8 | + feature frr-te { | ||
9 | + description "Indicates support for TE FastReroute (FRR)"; | ||
10 | + if-feature "p2mp-te"; | ||
11 | + } | ||
12 | + | ||
13 | + container speed { | ||
14 | + leaf local-storage-limit { | ||
15 | + if-feature frr-te; | ||
16 | + type uint64; | ||
17 | + units "kilobyte"; | ||
18 | + config false; | ||
19 | + description | ||
20 | + "The amount of local storage that can be | ||
21 | + used to hold syslog messages."; | ||
22 | + } | ||
23 | + } | ||
24 | +} |
1 | +module syslog1 { | ||
2 | + yang-version 1; | ||
3 | + namespace "http://huawei3.com"; | ||
4 | + prefix "sys1"; | ||
5 | + | ||
6 | + include "syslog2"; | ||
7 | + | ||
8 | + feature frr-te { | ||
9 | + description "Indicates support for TE FastReroute (FRR)"; | ||
10 | + if-feature "p2mp-te"; | ||
11 | + } | ||
12 | + | ||
13 | + container speed { | ||
14 | + leaf local-storage-limit { | ||
15 | + if-feature frr-te; | ||
16 | + type uint64; | ||
17 | + units "kilobyte"; | ||
18 | + config false; | ||
19 | + description | ||
20 | + "The amount of local storage that can be | ||
21 | + used to hold syslog messages."; | ||
22 | + } | ||
23 | + } | ||
24 | +} |
... | @@ -68,7 +68,7 @@ | ... | @@ -68,7 +68,7 @@ |
68 | * Features | 68 | * Features |
69 | */ | 69 | */ |
70 | 70 | ||
71 | - /*feature configuration-schedule { | 71 | + feature configuration-schedule { |
72 | description | 72 | description |
73 | "This feature indicates that the system supports | 73 | "This feature indicates that the system supports |
74 | configuration scheduling."; | 74 | configuration scheduling."; |
... | @@ -91,7 +91,7 @@ | ... | @@ -91,7 +91,7 @@ |
91 | description | 91 | description |
92 | "This feature indicates that the system supports | 92 | "This feature indicates that the system supports |
93 | template configuration."; | 93 | template configuration."; |
94 | - }*/ | 94 | + } |
95 | 95 | ||
96 | /* | 96 | /* |
97 | * Typedefs | 97 | * Typedefs | ... | ... |
... | @@ -257,7 +257,7 @@ | ... | @@ -257,7 +257,7 @@ |
257 | }*/ | 257 | }*/ |
258 | 258 | ||
259 | /* TE basic features */ | 259 | /* TE basic features */ |
260 | - /*feature p2mp-te { | 260 | + feature p2mp-te { |
261 | description | 261 | description |
262 | "Indicates support for P2MP-TE"; | 262 | "Indicates support for P2MP-TE"; |
263 | } | 263 | } |
... | @@ -291,7 +291,7 @@ | ... | @@ -291,7 +291,7 @@ |
291 | feature named-path-constraints { | 291 | feature named-path-constraints { |
292 | description | 292 | description |
293 | "Indicates support for named path constraints"; | 293 | "Indicates support for named path constraints"; |
294 | - }*/ | 294 | + } |
295 | 295 | ||
296 | grouping explicit-route-subobject { | 296 | grouping explicit-route-subobject { |
297 | description | 297 | description | ... | ... |
-
Please register or login to post a comment