rama-huawei
Committed by Patrick Liu

[ONOS-4798] Error Message implementation for YANG utils

Change-Id: Idb13e851258754773f8f447ace69a9393c7c1b3d
Showing 30 changed files with 1002 additions and 226 deletions
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 + * Represents data model node to maintain YANG app error message information.
21 + */
22 +public interface YangAppErrorHolder {
23 +
24 + /**
25 + * Sets the application's error information.
26 + *
27 + * @param yangAppErrorInfo the application's error information
28 + */
29 + void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo);
30 +
31 + /**
32 + * Returns application's error information.
33 + *
34 + * @return application's error information
35 + */
36 + YangAppErrorInfo getAppErrorInfo();
37 +
38 +}
1 -/*Copyright 2016.year Open Networking Laboratory 1 +/*
2 - 2 + * Copyright 2016-present Open Networking Laboratory
3 -Licensed under the Apache License, Version 2.0 (the "License"); 3 + *
4 -you may not use this file except in compliance with the License. 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 -You may obtain a copy of the License at 5 + * you may not use this file except in compliance with the License.
6 - 6 + * You may obtain a copy of the License at
7 - http://www.apache.org/licenses/LICENSE-2.0 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 + */
8 16
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 package org.onosproject.yangutils.datamodel; 17 package org.onosproject.yangutils.datamodel;
15 18
19 +import java.io.Serializable;
20 +
16 /** 21 /**
17 - * Abstraction of error message and application info processing. 22 + * Represents data model to maintain yang app error information.
23 + */
24 +public class YangAppErrorInfo implements Serializable {
25 +
26 + private static final long serialVersionUID = 807201693L;
27 +
28 + /**
29 + * Application's error message, to be used for data error.
30 + */
31 + private String errorMessage;
32 +
33 + /**
34 + * Error tag, to be filled in data validation error response.
35 + */
36 + private String errorTag;
37 +
38 + /**
39 + * Application's error tag, to be filled in data validation error response.
40 + */
41 + private String errorAppTag;
42 +
43 + /**
44 + * Application's error path, to be filled in data validation error response.
45 + */
46 + private String errorAppPath;
47 +
48 + /**
49 + * Application's error info, to be filled in data validation error response.
50 + */
51 + private String errorAppInfo;
52 +
53 + /**
54 + * Creates a YANG app error info object.
55 + */
56 + @SuppressWarnings("unused")
57 + public YangAppErrorInfo() {
58 + }
59 +
60 + /**
61 + * Returns application's error message, to be used for data error.
62 + *
63 + * @return Application's error message, to be used for data error
64 + */
65 + public String getGetErrorMessage() {
66 + return errorMessage;
67 + }
68 +
69 + /**
70 + * Sets Application's error message, to be used for data error.
71 + *
72 + * @param errMsg Application's error message, to be used for data error
73 + */
74 + public void setErrorMessage(String errMsg) {
75 + errorMessage = errMsg;
76 + }
77 +
78 + /**
79 + * Returns error tag, to be used for data error.
80 + *
81 + * @return error tag, to be used for data error
82 + */
83 + public String getGetErrorTag() {
84 + return errorTag;
85 + }
86 +
87 + /**
88 + * Sets error tag, to be used for data error.
89 + *
90 + * @param errTag error tag, to be used for data error
91 + */
92 + public void setErrorTag(String errTag) {
93 + errorTag = errTag;
94 + }
95 +
96 + /**
97 + * Returns application's error tag, to be used for data error.
98 + *
99 + * @return application's error tag, to be used for data error
100 + */
101 + public String getGetErrorAppTag() {
102 + return errorAppTag;
103 + }
104 +
105 + /**
106 + * Sets application's error tag, to be used for data error.
107 + *
108 + * @param errTag application's error tag, to be used for data error
18 */ 109 */
19 -public interface YangAppErrorInfo { 110 + public void setErrorAppTag(String errTag) {
111 + errorAppTag = errTag;
112 + }
20 113
21 /** 114 /**
22 - * Returns the application's error message for data error. 115 + * Returns application's error path, to be used for data error.
23 * 116 *
24 - * @return application's error message for data error. 117 + * @return application's error path, to be used for data error
25 */ 118 */
26 - String getGetErrorMessage(); 119 + public String getGetErrorAppPath() {
120 + return errorAppPath;
121 + }
27 122
28 /** 123 /**
29 - * Sets the application's error message for data error. 124 + * Sets application's error path, to be used for data error.
30 * 125 *
31 - * @param errorMessage application's error message for data error. 126 + * @param errPath application's error path, to be used for data error
32 */ 127 */
33 - void setErrorMessage(String errorMessage); 128 + public void setErrorAppPath(String errPath) {
129 + errorAppPath = errPath;
130 + }
34 131
35 /** 132 /**
36 - * Returns the application's error tag for data error. 133 + * Returns application's error info, to be used for data error.
37 * 134 *
38 - * @return application's error tag for data error. 135 + * @return application's error info, to be used for data error
39 */ 136 */
40 - String getGetErrorAppTag(); 137 + public String getGetErrorAppInfo() {
138 + return errorAppInfo;
139 + }
41 140
42 /** 141 /**
43 - * Sets the application's error tag for data error. 142 + * Sets application's error info, to be used for data error.
44 * 143 *
45 - * @param errorMessage application's error tag for data error. 144 + * @param errInfo application's error info, to be used for data error
46 */ 145 */
47 - void setErrorAppTag(String errorMessage); 146 + public void setErrorAppInfo(String errInfo) {
147 + errorAppInfo = errInfo;
148 + }
48 } 149 }
......
...@@ -23,6 +23,9 @@ import org.onosproject.yangutils.datamodel.utils.Parsable; ...@@ -23,6 +23,9 @@ import org.onosproject.yangutils.datamodel.utils.Parsable;
23 import org.onosproject.yangutils.datamodel.utils.YangConstructType; 23 import org.onosproject.yangutils.datamodel.utils.YangConstructType;
24 24
25 import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE_DATA; 25 import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE_DATA;
26 +import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.DATA_MISSING_ERROR_TAG;
27 +import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.ERROR_PATH_MISSING_CHOICE;
28 +import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.MISSING_CHOICE_ERROR_APP_TAG;
26 29
27 /*- 30 /*-
28 * Reference RFC 6020. 31 * Reference RFC 6020.
...@@ -65,7 +68,7 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE ...@@ -65,7 +68,7 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE
65 */ 68 */
66 public class YangChoice extends YangNode 69 public class YangChoice extends YangNode
67 implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentableNode, 70 implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentableNode,
68 - YangWhenHolder, YangIfFeatureHolder { 71 + YangWhenHolder, YangIfFeatureHolder, YangAppErrorHolder {
69 72
70 private static final long serialVersionUID = 806201604L; 73 private static final long serialVersionUID = 806201604L;
71 74
...@@ -160,10 +163,19 @@ public class YangChoice extends YangNode ...@@ -160,10 +163,19 @@ public class YangChoice extends YangNode
160 private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>(); 163 private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
161 164
162 /** 165 /**
166 + * YANG application error information.
167 + */
168 + private YangAppErrorInfo yangAppErrorInfo;
169 +
170 + /**
163 * Create a choice node. 171 * Create a choice node.
164 */ 172 */
165 public YangChoice() { 173 public YangChoice() {
166 super(YangNodeType.CHOICE_NODE); 174 super(YangNodeType.CHOICE_NODE);
175 + yangAppErrorInfo = new YangAppErrorInfo();
176 + yangAppErrorInfo.setErrorTag(DATA_MISSING_ERROR_TAG);
177 + yangAppErrorInfo.setErrorAppTag(MISSING_CHOICE_ERROR_APP_TAG);
178 + yangAppErrorInfo.setErrorAppPath(ERROR_PATH_MISSING_CHOICE);
167 } 179 }
168 180
169 /** 181 /**
...@@ -435,4 +447,15 @@ public class YangChoice extends YangNode ...@@ -435,4 +447,15 @@ public class YangChoice extends YangNode
435 public List<YangAugmentedInfo> getAugmentedInfoList() { 447 public List<YangAugmentedInfo> getAugmentedInfoList() {
436 return yangAugmentedInfo; 448 return yangAugmentedInfo;
437 } 449 }
450 +
451 + @Override
452 + public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
453 + this.yangAppErrorInfo = yangAppErrorInfo;
454 + }
455 +
456 + @Override
457 + public YangAppErrorInfo getAppErrorInfo() {
458 + return yangAppErrorInfo;
459 + }
460 +
438 } 461 }
......
...@@ -87,7 +87,7 @@ public class YangLeafList ...@@ -87,7 +87,7 @@ public class YangLeafList
87 * 87 *
88 * If no "max-elements" statement is present, it defaults to "unbounded". 88 * If no "max-elements" statement is present, it defaults to "unbounded".
89 */ 89 */
90 - private int maxElelements = Integer.MAX_VALUE; 90 + private YangMaxElement maxElement;
91 91
92 /** 92 /**
93 * Reference:RFC 6020. 93 * Reference:RFC 6020.
...@@ -107,7 +107,7 @@ public class YangLeafList ...@@ -107,7 +107,7 @@ public class YangLeafList
107 * 107 *
108 * o Otherwise, it is enforced if the ancestor node exists. 108 * o Otherwise, it is enforced if the ancestor node exists.
109 */ 109 */
110 - private int minElements = 0; 110 + private YangMinElement minElements;
111 111
112 /** 112 /**
113 * The textual reference to this leaf-list. 113 * The textual reference to this leaf-list.
...@@ -153,6 +153,8 @@ public class YangLeafList ...@@ -153,6 +153,8 @@ public class YangLeafList
153 * Creates a YANG leaf-list. 153 * Creates a YANG leaf-list.
154 */ 154 */
155 public YangLeafList() { 155 public YangLeafList() {
156 + setMinElements(new YangMinElement());
157 + setMaxElements(new YangMaxElement());
156 } 158 }
157 159
158 /** 160 /**
...@@ -232,38 +234,38 @@ public class YangLeafList ...@@ -232,38 +234,38 @@ public class YangLeafList
232 } 234 }
233 235
234 /** 236 /**
235 - * Returns the max elements no. 237 + * Returns the maximum elements number.
236 * 238 *
237 - * @return the max elements no 239 + * @return the maximum elements number
238 */ 240 */
239 - public int getMaxElelements() { 241 + public YangMaxElement getMaxElements() {
240 - return maxElelements; 242 + return maxElement;
241 } 243 }
242 244
243 /** 245 /**
244 - * Sets the max elements no. 246 + * Sets the maximum elements number.
245 * 247 *
246 - * @param maxElelements max elements no 248 + * @param maxElement maximum elements number
247 */ 249 */
248 - public void setMaxElelements(int maxElelements) { 250 + public void setMaxElements(YangMaxElement maxElement) {
249 - this.maxElelements = maxElelements; 251 + this.maxElement = maxElement;
250 } 252 }
251 253
252 /** 254 /**
253 - * Returns the min elements no. 255 + * Returns the minimum elements number.
254 * 256 *
255 - * @return the min elements no 257 + * @return the minimum elements number
256 */ 258 */
257 - public int getMinElements() { 259 + public YangMinElement getMinElements() {
258 return minElements; 260 return minElements;
259 } 261 }
260 262
261 /** 263 /**
262 - * Sets the min elements no. 264 + * Sets the minimum elements number.
263 * 265 *
264 - * @param minElements the min elements no 266 + * @param minElements the minimum elements number
265 */ 267 */
266 - public void setMinElements(int minElements) { 268 + public void setMinElements(YangMinElement minElements) {
267 this.minElements = minElements; 269 this.minElements = minElements;
268 } 270 }
269 271
......
...@@ -29,6 +29,9 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; ...@@ -29,6 +29,9 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
29 29
30 import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED; 30 import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
31 import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED; 31 import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
32 +import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.DATA_MISSING_ERROR_TAG;
33 +import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.ERROR_PATH_LEAFREF_LEAF;
34 +import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.INSTANCE_REQUIRED_ERROR_APP_TAG;
32 35
33 /* 36 /*
34 * Reference:RFC 6020. 37 * Reference:RFC 6020.
...@@ -44,7 +47,7 @@ import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVE ...@@ -44,7 +47,7 @@ import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVE
44 * @param <T> YANG leafref info 47 * @param <T> YANG leafref info
45 */ 48 */
46 public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangIfFeatureHolder, 49 public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangIfFeatureHolder,
47 - YangXPathResolver { 50 + YangXPathResolver, YangAppErrorHolder {
48 51
49 private static final long serialVersionUID = 286201644L; 52 private static final long serialVersionUID = 286201644L;
50 53
...@@ -97,6 +100,21 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI ...@@ -97,6 +100,21 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI
97 private List<YangIfFeature> ifFeatureList; 100 private List<YangIfFeature> ifFeatureList;
98 101
99 /** 102 /**
103 + * YANG application error information.
104 + */
105 + private YangAppErrorInfo yangAppErrorInfo;
106 +
107 + /**
108 + * Creates a YANG leaf ref.
109 + */
110 + public YangLeafRef() {
111 + yangAppErrorInfo = new YangAppErrorInfo();
112 + yangAppErrorInfo.setErrorTag(DATA_MISSING_ERROR_TAG);
113 + yangAppErrorInfo.setErrorAppTag(INSTANCE_REQUIRED_ERROR_APP_TAG);
114 + yangAppErrorInfo.setErrorAppPath(ERROR_PATH_LEAFREF_LEAF);
115 + }
116 +
117 + /**
100 * Returns the status of the require instance in leafref. 118 * Returns the status of the require instance in leafref.
101 * 119 *
102 * @return status of the require instance 120 * @return status of the require instance
...@@ -266,6 +284,16 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI ...@@ -266,6 +284,16 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI
266 } 284 }
267 285
268 @Override 286 @Override
287 + public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
288 + this.yangAppErrorInfo = yangAppErrorInfo;
289 + }
290 +
291 + @Override
292 + public YangAppErrorInfo getAppErrorInfo() {
293 + return yangAppErrorInfo;
294 + }
295 +
296 + @Override
269 public void resolve() throws DataModelException { 297 public void resolve() throws DataModelException {
270 298
271 if (getReferredLeafOrLeafList() == null) { 299 if (getReferredLeafOrLeafList() == null) {
......
...@@ -33,7 +33,7 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64; ...@@ -33,7 +33,7 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
33 /** 33 /**
34 * Represents the restriction for length data type. 34 * Represents the restriction for length data type.
35 */ 35 */
36 -public class YangLengthRestriction implements YangDesc, YangReference, YangAppErrorInfo, Parsable, Serializable { 36 +public class YangLengthRestriction implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder {
37 37
38 /*- 38 /*-
39 * Reference RFC 6020. 39 * Reference RFC 6020.
...@@ -84,19 +84,14 @@ public class YangLengthRestriction implements YangDesc, YangReference, YangAppEr ...@@ -84,19 +84,14 @@ public class YangLengthRestriction implements YangDesc, YangReference, YangAppEr
84 private String reference; 84 private String reference;
85 85
86 /** 86 /**
87 - * Application's error message, to be used for data error. 87 + * Textual description.
88 */ 88 */
89 - private String errorMessage; 89 + private String description;
90 90
91 /** 91 /**
92 - * Application's error tag, to be filled in data validation error response. 92 + * YANG application error information.
93 */ 93 */
94 - private String errorAppTag; 94 + private YangAppErrorInfo yangAppErrorInfo;
95 -
96 - /**
97 - * Textual description.
98 - */
99 - private String description;
100 95
101 /** 96 /**
102 * Creates a YANG length restriction object. 97 * Creates a YANG length restriction object.
...@@ -164,59 +159,38 @@ public class YangLengthRestriction implements YangDesc, YangReference, YangAppEr ...@@ -164,59 +159,38 @@ public class YangLengthRestriction implements YangDesc, YangReference, YangAppEr
164 159
165 } 160 }
166 161
167 - /**
168 - * Returns application's error message, to be used for data error.
169 - *
170 - * @return Application's error message, to be used for data error
171 - */
172 @Override 162 @Override
173 - public String getGetErrorMessage() { 163 + public YangConstructType getYangConstructType() {
174 - return errorMessage; 164 + return YangConstructType.PATTERN_DATA;
175 } 165 }
176 166
177 - /**
178 - * Sets Application's error message, to be used for data error.
179 - *
180 - * @param errMsg Application's error message, to be used for data error
181 - */
182 @Override 167 @Override
183 - public void setErrorMessage(String errMsg) { 168 + public void validateDataOnEntry() throws DataModelException {
184 - errorMessage = errMsg; 169 + // TODO: implement the method.
170 + }
185 171
172 + @Override
173 + public void validateDataOnExit() throws DataModelException {
174 + // TODO: implement the method.
186 } 175 }
187 176
188 /** 177 /**
189 - * Returns application's error tag, to be used for data error. 178 + * Sets the application's error information.
190 * 179 *
191 - * @return application's error tag, to be used for data error 180 + * @param yangAppErrorInfo the application's error information
192 */ 181 */
193 @Override 182 @Override
194 - public String getGetErrorAppTag() { 183 + public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
195 - return errorAppTag; 184 + this.yangAppErrorInfo = yangAppErrorInfo;
196 } 185 }
197 186
198 /** 187 /**
199 - * Sets application's error tag, to be used for data error. 188 + * Returns application's error information.
200 * 189 *
201 - * @param errTag application's error tag, to be used for data error. 190 + * @return application's error information
202 */ 191 */
203 @Override 192 @Override
204 - public void setErrorAppTag(String errTag) { 193 + public YangAppErrorInfo getAppErrorInfo() {
205 - errorAppTag = errTag; 194 + return yangAppErrorInfo;
206 - }
207 -
208 - @Override
209 - public YangConstructType getYangConstructType() {
210 - return YangConstructType.PATTERN_DATA;
211 - }
212 -
213 - @Override
214 - public void validateDataOnEntry() throws DataModelException {
215 - // TODO: implement the method.
216 - }
217 -
218 - @Override
219 - public void validateDataOnExit() throws DataModelException {
220 - // TODO: implement the method.
221 } 195 }
222 } 196 }
......
...@@ -140,7 +140,7 @@ public class YangList ...@@ -140,7 +140,7 @@ public class YangList
140 * 140 *
141 * If no "max-elements" statement is present, it defaults to "unbounded". 141 * If no "max-elements" statement is present, it defaults to "unbounded".
142 */ 142 */
143 - private int maxElements = Integer.MAX_VALUE; 143 + private YangMaxElement maxElements;
144 144
145 /** 145 /**
146 * Reference RFC 6020. 146 * Reference RFC 6020.
...@@ -160,7 +160,7 @@ public class YangList ...@@ -160,7 +160,7 @@ public class YangList
160 * 160 *
161 * o Otherwise, it is enforced if the ancestor node exists. 161 * o Otherwise, it is enforced if the ancestor node exists.
162 */ 162 */
163 - private int minElements = 0; 163 + private YangMinElement minElements;
164 164
165 /** 165 /**
166 * reference. 166 * reference.
...@@ -381,7 +381,7 @@ public class YangList ...@@ -381,7 +381,7 @@ public class YangList
381 * 381 *
382 * @return the max elements 382 * @return the max elements
383 */ 383 */
384 - public int getMaxElements() { 384 + public YangMaxElement getMaxElements() {
385 return maxElements; 385 return maxElements;
386 } 386 }
387 387
...@@ -390,8 +390,8 @@ public class YangList ...@@ -390,8 +390,8 @@ public class YangList
390 * 390 *
391 * @param max the max elements 391 * @param max the max elements
392 */ 392 */
393 - public void setMaxElements(int max) { 393 + public void setMaxElements(YangMaxElement max) {
394 - maxElements = max; 394 + this.maxElements = max;
395 } 395 }
396 396
397 /** 397 /**
...@@ -399,7 +399,7 @@ public class YangList ...@@ -399,7 +399,7 @@ public class YangList
399 * 399 *
400 * @return the minimum elements 400 * @return the minimum elements
401 */ 401 */
402 - public int getMinElements() { 402 + public YangMinElement getMinElements() {
403 return minElements; 403 return minElements;
404 } 404 }
405 405
...@@ -408,7 +408,7 @@ public class YangList ...@@ -408,7 +408,7 @@ public class YangList
408 * 408 *
409 * @param minElements the minimum elements 409 * @param minElements the minimum elements
410 */ 410 */
411 - public void setMinElements(int minElements) { 411 + public void setMinElements(YangMinElement minElements) {
412 this.minElements = minElements; 412 this.minElements = minElements;
413 } 413 }
414 414
......
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 static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
20 +import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.TOO_MANY_ELEMENTS_ERROR_APP_TAG;
21 +
22 +import java.io.Serializable;
23 +
24 +/**
25 + * Represents max element data represented in YANG.
26 + */
27 +public class YangMaxElement implements YangAppErrorHolder, Serializable {
28 +
29 + private static final long serialVersionUID = 807201694L;
30 +
31 + /**
32 + * YANG application error information.
33 + */
34 + private YangAppErrorInfo yangAppErrorInfo;
35 +
36 + /**
37 + * Reference:RFC 6020.
38 + *
39 + * The "max-elements" statement, which is optional, takes as an argument a
40 + * positive integer or the string "unbounded", which puts a constraint on
41 + * valid list entries. A valid leaf-list or list always has at most
42 + * max-elements entries.
43 + *
44 + * If no "max-elements" statement is present, it defaults to "unbounded".
45 + */
46 + private int maxElement = Integer.MAX_VALUE;
47 +
48 + /**
49 + * Creates a YANG maximum element.
50 + */
51 + public YangMaxElement() {
52 + YangAppErrorInfo yangAppErrorInfo = new YangAppErrorInfo();
53 + yangAppErrorInfo.setErrorTag(OPERATION_FAILED_ERROR_TAG);
54 + yangAppErrorInfo.setErrorAppTag(TOO_MANY_ELEMENTS_ERROR_APP_TAG);
55 + }
56 +
57 + /**
58 + * Returns the maximum element value.
59 + *
60 + * @return the maximum element value
61 + */
62 + public int getMaxElement() {
63 + return maxElement;
64 + }
65 +
66 + /**
67 + * Sets the maximum element value.
68 + *
69 + * @param maxElement the maximum element value
70 + */
71 + public void setMaxElement(int maxElement) {
72 + this.maxElement = maxElement;
73 + }
74 +
75 + @Override
76 + public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
77 + this.yangAppErrorInfo = yangAppErrorInfo;
78 + }
79 +
80 + @Override
81 + public YangAppErrorInfo getAppErrorInfo() {
82 + return yangAppErrorInfo;
83 + }
84 +}
...\ 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.datamodel;
18 +
19 +import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
20 +import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.TOO_FEW_ELEMENTS_ERROR_APP_TAG;
21 +
22 +import java.io.Serializable;
23 +
24 +/**
25 + * Represents minimum element data represented in YANG.
26 + */
27 +public class YangMinElement implements YangAppErrorHolder, Serializable {
28 +
29 + private static final long serialVersionUID = 807201695L;
30 +
31 + /**
32 + * YANG application error information.
33 + */
34 + private YangAppErrorInfo yangAppErrorInfo;
35 +
36 + /**
37 + * Reference:RFC 6020.
38 + *
39 + * The "min-elements" statement, which is optional, takes as an argument a
40 + * non-negative integer that puts a constraint on valid list entries. A
41 + * valid leaf-list or list MUST have at least min-elements entries.
42 + *
43 + * If no "min-elements" statement is present, it defaults to zero.
44 + *
45 + * The behavior of the constraint depends on the type of the leaf-list's or
46 + * list's closest ancestor node in the schema tree that is not a non-
47 + * presence container:
48 + *
49 + * If this ancestor is a case node, the constraint is enforced if any
50 + * other node from the case exists.
51 + *
52 + * Otherwise, it is enforced if the ancestor node exists.
53 + */
54 + private int minElement = 0;
55 +
56 + /**
57 + * Creates a YANG minimum element.
58 + */
59 + public YangMinElement() {
60 + YangAppErrorInfo yangAppErrorInfo = new YangAppErrorInfo();
61 + yangAppErrorInfo.setErrorTag(OPERATION_FAILED_ERROR_TAG);
62 + yangAppErrorInfo.setErrorAppTag(TOO_FEW_ELEMENTS_ERROR_APP_TAG);
63 + }
64 +
65 + /**
66 + * Returns the minimum element value.
67 + *
68 + * @return the minimum element value
69 + */
70 + public int getMinElement() {
71 + return minElement;
72 + }
73 +
74 + /**
75 + * Sets the minimum element value.
76 + *
77 + * @param minElement the minimum element value
78 + */
79 + public void setMinElement(int minElement) {
80 + this.minElement = minElement;
81 + }
82 +
83 + @Override
84 + public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
85 + this.yangAppErrorInfo = yangAppErrorInfo;
86 + }
87 +
88 + @Override
89 + public YangAppErrorInfo getAppErrorInfo() {
90 + return yangAppErrorInfo;
91 + }
92 +}
...@@ -20,6 +20,8 @@ import java.io.Serializable; ...@@ -20,6 +20,8 @@ import java.io.Serializable;
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;
23 +import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
24 +import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.MUST_VIOLATION_ERROR_APP_TAG;
23 25
24 /*- 26 /*-
25 * The "must" statement, which is optional, takes as an argument a string that 27 * The "must" statement, which is optional, takes as an argument a string that
...@@ -48,7 +50,7 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType; ...@@ -48,7 +50,7 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType;
48 /** 50 /**
49 * Represents information defined in YANG must. 51 * Represents information defined in YANG must.
50 */ 52 */
51 -public class YangMust implements YangDesc, YangReference, Parsable, Serializable { 53 +public class YangMust implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder {
52 54
53 private static final long serialVersionUID = 806201646L; 55 private static final long serialVersionUID = 806201646L;
54 56
...@@ -68,9 +70,17 @@ public class YangMust implements YangDesc, YangReference, Parsable, Serializable ...@@ -68,9 +70,17 @@ public class YangMust implements YangDesc, YangReference, Parsable, Serializable
68 private String reference; 70 private String reference;
69 71
70 /** 72 /**
73 + * YANG application error information.
74 + */
75 + private YangAppErrorInfo yangAppErrorInfo;
76 +
77 + /**
71 * Creates a YANG must restriction. 78 * Creates a YANG must restriction.
72 */ 79 */
73 public YangMust() { 80 public YangMust() {
81 + yangAppErrorInfo = new YangAppErrorInfo();
82 + yangAppErrorInfo.setErrorTag(OPERATION_FAILED_ERROR_TAG);
83 + yangAppErrorInfo.setErrorAppTag(MUST_VIOLATION_ERROR_APP_TAG);
74 } 84 }
75 85
76 /** 86 /**
...@@ -160,4 +170,14 @@ public class YangMust implements YangDesc, YangReference, Parsable, Serializable ...@@ -160,4 +170,14 @@ public class YangMust implements YangDesc, YangReference, Parsable, Serializable
160 public void validateDataOnExit() throws DataModelException { 170 public void validateDataOnExit() throws DataModelException {
161 // TODO auto-generated method stub, to be implemented by parser 171 // TODO auto-generated method stub, to be implemented by parser
162 } 172 }
173 +
174 + @Override
175 + public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
176 + this.yangAppErrorInfo = yangAppErrorInfo;
177 + }
178 +
179 + @Override
180 + public YangAppErrorInfo getAppErrorInfo() {
181 + return yangAppErrorInfo;
182 + }
163 } 183 }
......
...@@ -52,7 +52,7 @@ import java.util.List; ...@@ -52,7 +52,7 @@ import java.util.List;
52 * Represents pattern restriction information. The regular expression restriction on string 52 * Represents pattern restriction information. The regular expression restriction on string
53 * data type. 53 * data type.
54 */ 54 */
55 -public class YangPatternRestriction implements Serializable { 55 +public class YangPatternRestriction implements Serializable, YangAppErrorHolder {
56 56
57 private static final long serialVersionUID = 806201649L; 57 private static final long serialVersionUID = 806201649L;
58 58
...@@ -62,6 +62,11 @@ public class YangPatternRestriction implements Serializable { ...@@ -62,6 +62,11 @@ public class YangPatternRestriction implements Serializable {
62 private List<String> patternList; 62 private List<String> patternList;
63 63
64 /** 64 /**
65 + * YANG application error information.
66 + */
67 + private YangAppErrorInfo yangAppErrorInfo;
68 +
69 + /**
65 * Creates a YANG pattern restriction object. 70 * Creates a YANG pattern restriction object.
66 */ 71 */
67 public YangPatternRestriction() { 72 public YangPatternRestriction() {
...@@ -94,4 +99,14 @@ public class YangPatternRestriction implements Serializable { ...@@ -94,4 +99,14 @@ public class YangPatternRestriction implements Serializable {
94 public void addPattern(String newPattern) { 99 public void addPattern(String newPattern) {
95 getPatternList().add(newPattern); 100 getPatternList().add(newPattern);
96 } 101 }
102 +
103 + @Override
104 + public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
105 + this.yangAppErrorInfo = yangAppErrorInfo;
106 + }
107 +
108 + @Override
109 + public YangAppErrorInfo getAppErrorInfo() {
110 + return yangAppErrorInfo;
111 + }
97 } 112 }
......
...@@ -59,7 +59,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -59,7 +59,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
59 * @param <T> range type (data type) 59 * @param <T> range type (data type)
60 */ 60 */
61 public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> 61 public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
62 - implements YangDesc, YangReference, YangAppErrorInfo, Parsable, Serializable { 62 + implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder {
63 63
64 private static final long serialVersionUID = 8062016051L; 64 private static final long serialVersionUID = 8062016051L;
65 65
...@@ -75,19 +75,14 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> ...@@ -75,19 +75,14 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
75 private String reference; 75 private String reference;
76 76
77 /** 77 /**
78 - * Application's error message, to be used for data error. 78 + * Textual description.
79 - */
80 - private String errorMessage;
81 -
82 - /**
83 - * Application's error tag, to be filled in data validation error response.
84 */ 79 */
85 - private String errorAppTag; 80 + private String description;
86 81
87 /** 82 /**
88 - * Textual description. 83 + * YANG application error information.
89 */ 84 */
90 - private String description; 85 + private YangAppErrorInfo yangAppErrorInfo;
91 86
92 /** 87 /**
93 * Creates YANG range restriction object. 88 * Creates YANG range restriction object.
...@@ -278,47 +273,6 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> ...@@ -278,47 +273,6 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
278 273
279 } 274 }
280 275
281 - /**
282 - * Returns application's error message, to be used for data error.
283 - *
284 - * @return Application's error message, to be used for data error
285 - */
286 - @Override
287 - public String getGetErrorMessage() {
288 - return errorMessage;
289 - }
290 -
291 - /**
292 - * Sets Application's error message, to be used for data error.
293 - *
294 - * @param errMsg Application's error message, to be used for data error
295 - */
296 - @Override
297 - public void setErrorMessage(String errMsg) {
298 - errorMessage = errMsg;
299 -
300 - }
301 -
302 - /**
303 - * Returns application's error tag, to be used for data error.
304 - *
305 - * @return application's error tag, to be used for data error
306 - */
307 - @Override
308 - public String getGetErrorAppTag() {
309 - return errorAppTag;
310 - }
311 -
312 - /**
313 - * Sets application's error tag, to be used for data error.
314 - *
315 - * @param errTag application's error tag, to be used for data error.
316 - */
317 - @Override
318 - public void setErrorAppTag(String errTag) {
319 - errorAppTag = errTag;
320 - }
321 -
322 @Override 276 @Override
323 public YangConstructType getYangConstructType() { 277 public YangConstructType getYangConstructType() {
324 return YangConstructType.RANGE_DATA; 278 return YangConstructType.RANGE_DATA;
...@@ -333,4 +287,14 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> ...@@ -333,4 +287,14 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
333 public void validateDataOnExit() throws DataModelException { 287 public void validateDataOnExit() throws DataModelException {
334 // TODO: implement the method. 288 // TODO: implement the method.
335 } 289 }
290 +
291 + @Override
292 + public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
293 + this.yangAppErrorInfo = yangAppErrorInfo;
294 + }
295 +
296 + @Override
297 + public YangAppErrorInfo getAppErrorInfo() {
298 + return yangAppErrorInfo;
299 + }
336 } 300 }
......
...@@ -33,7 +33,7 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64; ...@@ -33,7 +33,7 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
33 /** 33 /**
34 * Represents the restriction for string data type. 34 * Represents the restriction for string data type.
35 */ 35 */
36 -public class YangStringRestriction implements YangDesc, YangReference, YangAppErrorInfo, Parsable, Serializable { 36 +public class YangStringRestriction implements YangDesc, YangReference, Parsable, Serializable {
37 37
38 /*- 38 /*-
39 * Reference RFC 6020. 39 * Reference RFC 6020.
...@@ -89,16 +89,6 @@ public class YangStringRestriction implements YangDesc, YangReference, YangAppEr ...@@ -89,16 +89,6 @@ public class YangStringRestriction implements YangDesc, YangReference, YangAppEr
89 private String reference; 89 private String reference;
90 90
91 /** 91 /**
92 - * Application's error message, to be used for data error.
93 - */
94 - private String errorMessage;
95 -
96 - /**
97 - * Application's error tag, to be filled in data validation error response.
98 - */
99 - private String errorAppTag;
100 -
101 - /**
102 * Textual description. 92 * Textual description.
103 */ 93 */
104 private String description; 94 private String description;
...@@ -198,47 +188,6 @@ public class YangStringRestriction implements YangDesc, YangReference, YangAppEr ...@@ -198,47 +188,6 @@ public class YangStringRestriction implements YangDesc, YangReference, YangAppEr
198 188
199 } 189 }
200 190
201 - /**
202 - * Returns application's error message, to be used for data error.
203 - *
204 - * @return Application's error message, to be used for data error
205 - */
206 - @Override
207 - public String getGetErrorMessage() {
208 - return errorMessage;
209 - }
210 -
211 - /**
212 - * Sets Application's error message, to be used for data error.
213 - *
214 - * @param errMsg Application's error message, to be used for data error
215 - */
216 - @Override
217 - public void setErrorMessage(String errMsg) {
218 - errorMessage = errMsg;
219 -
220 - }
221 -
222 - /**
223 - * Returns application's error tag, to be used for data error.
224 - *
225 - * @return application's error tag, to be used for data error
226 - */
227 - @Override
228 - public String getGetErrorAppTag() {
229 - return errorAppTag;
230 - }
231 -
232 - /**
233 - * Sets application's error tag, to be used for data error.
234 - *
235 - * @param errTag application's error tag, to be used for data error.
236 - */
237 - @Override
238 - public void setErrorAppTag(String errTag) {
239 - errorAppTag = errTag;
240 - }
241 -
242 @Override 191 @Override
243 public YangConstructType getYangConstructType() { 192 public YangConstructType getYangConstructType() {
244 return YangConstructType.PATTERN_DATA; 193 return YangConstructType.PATTERN_DATA;
......
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.utils;
18 +
19 +/**
20 + * Represents default YANG error message types.
21 + */
22 +public final class YangErrMsgConstants {
23 +
24 + /**
25 + * Static attribute for operation failed error tag.
26 + */
27 + public static final String OPERATION_FAILED_ERROR_TAG = "operation-failed";
28 +
29 + /**
30 + * Static attribute for data missing error tag.
31 + */
32 + public static final String DATA_MISSING_ERROR_TAG = "data-missing";
33 +
34 + /**
35 + * Static attribute for bad attribute error tag.
36 + */
37 + public static final String BAD_ATTRIBUTE_ERROR_TAG = "bad-attribute";
38 +
39 + /**
40 + * Static attribute for data not unique error app tag.
41 + */
42 + public static final String DATA_NOT_UNIQUE_ERROR_APP_TAG = "data-not-unique";
43 +
44 + /**
45 + * Static attribute for too many elements error app tag.
46 + */
47 + public static final String TOO_MANY_ELEMENTS_ERROR_APP_TAG = "too-many-elements";
48 +
49 + /**
50 + * Static attribute for too few elements error app tag.
51 + */
52 + public static final String TOO_FEW_ELEMENTS_ERROR_APP_TAG = "too-few-elements";
53 +
54 + /**
55 + * Static attribute for must violation error app tag.
56 + */
57 + public static final String MUST_VIOLATION_ERROR_APP_TAG = "must-violation";
58 +
59 + /**
60 + * Static attribute for instance required error app tag.
61 + */
62 + public static final String INSTANCE_REQUIRED_ERROR_APP_TAG = "instance-required";
63 +
64 + /**
65 + * Static attribute for missing choice error app tag.
66 + */
67 + public static final String MISSING_CHOICE_ERROR_APP_TAG = "missing-choice";
68 +
69 + /**
70 + * Static attribute for missing instance error app tag.
71 + */
72 + public static final String MISSING_INSTANCE_ERROR_APP_TAG = "missing-instance";
73 +
74 + /**
75 + * TODO: Static attribute for error path to the instance-identifier leaf.
76 + */
77 + public static final String ERROR_PATH_INSTANCE_IDENTIFIER_LEAF = "Path to the instance-identifier leaf.";
78 +
79 + /**
80 + * Static attribute for error path to the missing choice.
81 + */
82 + public static final String ERROR_PATH_MISSING_CHOICE = "Path to the element with the missing choice.";
83 +
84 + /**
85 + * Static attribute for error path to the leafref leaf.
86 + */
87 + public static final String ERROR_PATH_LEAFREF_LEAF = "Path to the leafref leaf.";
88 +
89 + /**
90 + * Creates an instance of yang error message constants.
91 + */
92 + private YangErrMsgConstants() {
93 + }
94 +}
...@@ -88,7 +88,8 @@ import org.onosproject.yangutils.parser.impl.listeners.UsesListener; ...@@ -88,7 +88,8 @@ import org.onosproject.yangutils.parser.impl.listeners.UsesListener;
88 import org.onosproject.yangutils.parser.impl.listeners.ValueListener; 88 import org.onosproject.yangutils.parser.impl.listeners.ValueListener;
89 import org.onosproject.yangutils.parser.impl.listeners.VersionListener; 89 import org.onosproject.yangutils.parser.impl.listeners.VersionListener;
90 import org.onosproject.yangutils.parser.impl.listeners.WhenListener; 90 import org.onosproject.yangutils.parser.impl.listeners.WhenListener;
91 - 91 +import org.onosproject.yangutils.parser.impl.listeners.ErrorMessageListener;
92 +import org.onosproject.yangutils.parser.impl.listeners.ErrorAppTagListener;
92 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.handleUnsupportedYangConstruct; 93 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.handleUnsupportedYangConstruct;
93 import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED; 94 import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
94 import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT; 95 import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT;
...@@ -845,7 +846,7 @@ public class TreeWalkListener implements GeneratedYangListener { ...@@ -845,7 +846,7 @@ public class TreeWalkListener implements GeneratedYangListener {
845 846
846 @Override 847 @Override
847 public void enterErrorMessageStatement(GeneratedYangParser.ErrorMessageStatementContext ctx) { 848 public void enterErrorMessageStatement(GeneratedYangParser.ErrorMessageStatementContext ctx) {
848 - handleUnsupportedYangConstruct(YangConstructType.ERROR_MESSAGE_DATA, ctx, CURRENTLY_UNSUPPORTED); 849 + ErrorMessageListener.processErrorMessageEntry(this, ctx);
849 } 850 }
850 851
851 @Override 852 @Override
...@@ -855,7 +856,7 @@ public class TreeWalkListener implements GeneratedYangListener { ...@@ -855,7 +856,7 @@ public class TreeWalkListener implements GeneratedYangListener {
855 856
856 @Override 857 @Override
857 public void enterErrorAppTagStatement(GeneratedYangParser.ErrorAppTagStatementContext ctx) { 858 public void enterErrorAppTagStatement(GeneratedYangParser.ErrorAppTagStatementContext ctx) {
858 - handleUnsupportedYangConstruct(YangConstructType.ERROR_APP_TAG_DATA, ctx, CURRENTLY_UNSUPPORTED); 859 + ErrorAppTagListener.processErrorAppTagMessageEntry(this, ctx);
859 } 860 }
860 861
861 @Override 862 @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 +import org.onosproject.yangutils.datamodel.YangAppErrorHolder;
20 +import org.onosproject.yangutils.datamodel.YangAppErrorInfo;
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.ERROR_APP_TAG_DATA;
27 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
28 +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.MISSING_HOLDER;
31 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
33 +
34 +/*
35 + * Reference: RFC 6020 and YANG ANTLR Grammar
36 + *
37 + * ABNF grammar as per RFC 6020
38 + *
39 + * error-app-tag-stmt = error-app-tag-keyword sep string stmtend
40 + *
41 + * ANTLR grammar rule
42 + * errorAppTagStatement : ERROR_APP_TAG_KEYWORD string STMTEND;
43 + */
44 +
45 +/**
46 + * Represents listener based call back function corresponding to the
47 + * error app tag defined in ANTLR grammar file for corresponding ABNF rule
48 + * in RFC 6020.
49 + */
50 +public final class ErrorAppTagListener {
51 +
52 + /**
53 + * Creates a new error app tag listener.
54 + */
55 + private ErrorAppTagListener() {
56 + }
57 +
58 + /**
59 + * Performs validations and updates the data model tree. It is called when parser
60 + * receives an input matching the grammar rule error app tag.
61 + *
62 + * @param listener listener's object
63 + * @param ctx context object of the grammar rule
64 + */
65 + public static void processErrorAppTagMessageEntry(TreeWalkListener listener,
66 + GeneratedYangParser.ErrorAppTagStatementContext ctx) {
67 +
68 + // Check for stack to be non empty.
69 + checkStackIsNotEmpty(listener, MISSING_HOLDER, ERROR_APP_TAG_DATA, ctx.string().getText(), ENTRY);
70 + String errorMessage = removeQuotesAndHandleConcat(ctx.string().getText());
71 + // Obtain the node of the stack.
72 + Parsable tmpNode = listener.getParsedDataStack().peek();
73 + if (tmpNode instanceof YangAppErrorHolder) {
74 + YangAppErrorInfo yangAppErrorInfo = ((YangAppErrorHolder) tmpNode).getAppErrorInfo();
75 + yangAppErrorInfo.setErrorAppTag(errorMessage);
76 + } else {
77 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ERROR_APP_TAG_DATA,
78 + ctx.string().getText(), ENTRY));
79 + }
80 + }
81 +}
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.YangAppErrorHolder;
20 +import org.onosproject.yangutils.datamodel.YangAppErrorInfo;
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.ERROR_MESSAGE_DATA;
27 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
28 +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.MISSING_HOLDER;
31 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
33 +
34 +/*
35 + * Reference: RFC6020 and YANG ANTLR Grammar
36 + *
37 + * ABNF grammar as per RFC6020
38 + *
39 + * error-message-stmt = error-message-keyword sep string stmtend
40 + *
41 + * ANTLR grammar rule
42 + * errorMessageStatement : ERROR_MESSAGE_KEYWORD string STMTEND;
43 + */
44 +
45 +/**
46 + * Represents listener based call back function corresponding to the
47 + * app error message defined in ANTLR grammar file for corresponding ABNF rule
48 + * in RFC 6020.
49 + */
50 +public final class ErrorMessageListener {
51 +
52 + /**
53 + * Creates a new must listener.
54 + */
55 + private ErrorMessageListener() {
56 + }
57 +
58 + /**
59 + * Performs validations and updates the data model tree. It is called when parser
60 + * receives an input matching the grammar rule (app error message).
61 + *
62 + * @param listener listener's object
63 + * @param ctx context object of the grammar rule
64 + */
65 + public static void processErrorMessageEntry(TreeWalkListener listener,
66 + GeneratedYangParser.ErrorMessageStatementContext ctx) {
67 +
68 + // Check for stack to be non empty.
69 + checkStackIsNotEmpty(listener, MISSING_HOLDER, ERROR_MESSAGE_DATA, ctx.string().getText(), ENTRY);
70 + String errorMessage = removeQuotesAndHandleConcat(ctx.string().getText());
71 +
72 + // Obtain the node of the stack.
73 + Parsable tmpNode = listener.getParsedDataStack().peek();
74 + if (tmpNode instanceof YangAppErrorHolder) {
75 + YangAppErrorInfo yangAppErrorInfo = ((YangAppErrorHolder) tmpNode).getAppErrorInfo();
76 + yangAppErrorInfo.setErrorMessage(errorMessage);
77 + } else {
78 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ERROR_MESSAGE_DATA,
79 + ctx.string().getText(), ENTRY));
80 + }
81 + }
82 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 import org.onosproject.yangutils.datamodel.YangLeafList; 19 import org.onosproject.yangutils.datamodel.YangLeafList;
20 import org.onosproject.yangutils.datamodel.YangList; 20 import org.onosproject.yangutils.datamodel.YangList;
21 +import org.onosproject.yangutils.datamodel.YangMaxElement;
21 import org.onosproject.yangutils.datamodel.utils.Parsable; 22 import org.onosproject.yangutils.datamodel.utils.Parsable;
22 import org.onosproject.yangutils.datamodel.utils.YangConstructType; 23 import org.onosproject.yangutils.datamodel.utils.YangConstructType;
23 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 24 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
...@@ -81,11 +82,15 @@ public final class MaxElementsListener { ...@@ -81,11 +82,15 @@ public final class MaxElementsListener {
81 switch (tmpData.getYangConstructType()) { 82 switch (tmpData.getYangConstructType()) {
82 case LEAF_LIST_DATA: 83 case LEAF_LIST_DATA:
83 YangLeafList leafList = (YangLeafList) tmpData; 84 YangLeafList leafList = (YangLeafList) tmpData;
84 - leafList.setMaxElelements(maxElementsValue); 85 + YangMaxElement maxLeafListElement = new YangMaxElement();
86 + maxLeafListElement.setMaxElement(maxElementsValue);
87 + leafList.setMaxElements(maxLeafListElement);
85 break; 88 break;
86 case LIST_DATA: 89 case LIST_DATA:
87 YangList yangList = (YangList) tmpData; 90 YangList yangList = (YangList) tmpData;
88 - yangList.setMaxElements(maxElementsValue); 91 + YangMaxElement maxListElement = new YangMaxElement();
92 + maxListElement.setMaxElement(maxElementsValue);
93 + yangList.setMaxElements(maxListElement);
89 break; 94 break;
90 default: 95 default:
91 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MAX_ELEMENT_DATA, "", ENTRY)); 96 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MAX_ELEMENT_DATA, "", ENTRY));
......
...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 import org.onosproject.yangutils.datamodel.YangLeafList; 19 import org.onosproject.yangutils.datamodel.YangLeafList;
20 import org.onosproject.yangutils.datamodel.YangList; 20 import org.onosproject.yangutils.datamodel.YangList;
21 +import org.onosproject.yangutils.datamodel.YangMinElement;
21 import org.onosproject.yangutils.datamodel.utils.Parsable; 22 import org.onosproject.yangutils.datamodel.utils.Parsable;
22 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 23 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
23 import org.onosproject.yangutils.parser.exceptions.ParserException; 24 import org.onosproject.yangutils.parser.exceptions.ParserException;
...@@ -78,11 +79,15 @@ public final class MinElementsListener { ...@@ -78,11 +79,15 @@ public final class MinElementsListener {
78 switch (tmpData.getYangConstructType()) { 79 switch (tmpData.getYangConstructType()) {
79 case LEAF_LIST_DATA: 80 case LEAF_LIST_DATA:
80 YangLeafList leafList = (YangLeafList) tmpData; 81 YangLeafList leafList = (YangLeafList) tmpData;
81 - leafList.setMinElements(minElementValue); 82 + YangMinElement minLeafListElement = new YangMinElement();
83 + minLeafListElement.setMinElement(minElementValue);
84 + leafList.setMinElements(minLeafListElement);
82 break; 85 break;
83 case LIST_DATA: 86 case LIST_DATA:
84 YangList yangList = (YangList) tmpData; 87 YangList yangList = (YangList) tmpData;
85 - yangList.setMinElements(minElementValue); 88 + YangMinElement minElement = new YangMinElement();
89 + minElement.setMinElement(minElementValue);
90 + yangList.setMinElements(minElement);
86 break; 91 break;
87 default: 92 default:
88 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MIN_ELEMENT_DATA, 93 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MIN_ELEMENT_DATA,
......
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.YangAppErrorInfo;
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 +
31 +import static org.hamcrest.core.Is.is;
32 +import static org.junit.Assert.assertThat;
33 +
34 +/**
35 + * Test-cases for testing error app tag message listener functionality.
36 + */
37 +public class ErrorAppTagListenerTest {
38 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
39 +
40 + /**
41 + * Checks if error app tag message is default updated in the data model.
42 + */
43 + @Test
44 + public void processContainerSubStatementErrorDefaultAppTag() throws IOException, ParserException {
45 + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementErrorDefaultAppTag.yang");
46 +
47 + YangModule yangNode = (YangModule) node;
48 + assertThat(yangNode.getName(), is("ErrorAppTag"));
49 +
50 + YangContainer yangContainer = (YangContainer) yangNode.getChild();
51 + assertThat(yangContainer.getName(), is("interface"));
52 +
53 + String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
54 + List<YangMust> mustConstraintList = yangContainer.getListOfMust();
55 + assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint));
56 +
57 + YangAppErrorInfo yangAppErrorInfo = mustConstraintList.iterator().next().getAppErrorInfo();
58 + assertThat(yangAppErrorInfo.getGetErrorAppTag(), is("must-violation"));
59 + assertThat(yangAppErrorInfo.getGetErrorTag(), is("operation-failed"));
60 + }
61 +
62 + /**
63 + * Checks if error app tag message listener updates the data model.
64 + */
65 + @Test
66 + public void processContainerSubStatementErrorAppTag() throws IOException, ParserException {
67 + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementErrorAppTag.yang");
68 +
69 + YangModule yangNode = (YangModule) node;
70 + assertThat(yangNode.getName(), is("ErrorAppTag"));
71 +
72 + YangContainer yangContainer = (YangContainer) yangNode.getChild();
73 + assertThat(yangContainer.getName(), is("interface"));
74 +
75 + String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
76 + List<YangMust> mustConstraintList = yangContainer.getListOfMust();
77 + assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint));
78 +
79 + YangAppErrorInfo yangAppErrorInfo = mustConstraintList.iterator().next().getAppErrorInfo();
80 + assertThat(yangAppErrorInfo.getGetErrorAppTag(), is("An ethernet MTU must be 1500"));
81 + assertThat(yangAppErrorInfo.getGetErrorTag(), is("operation-failed"));
82 + }
83 +}
...\ 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.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.YangAppErrorInfo;
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 +
31 +import static org.hamcrest.core.Is.is;
32 +import static org.junit.Assert.assertThat;
33 +
34 +/**
35 + * Test-cases for testing error message listener functionality.
36 + */
37 +public class ErrorMessageListnerTest {
38 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
39 +
40 + /**
41 + * Checks if error message listener updates the data model.
42 + */
43 + @Test
44 + public void processContainerSubStatementErrorMessage() throws IOException, ParserException {
45 + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementErrorMessage.yang");
46 +
47 + YangModule yangNode = (YangModule) node;
48 + assertThat(yangNode.getName(), is("ErrorMessage"));
49 +
50 + YangContainer yangContainer = (YangContainer) yangNode.getChild();
51 + assertThat(yangContainer.getName(), is("interface"));
52 +
53 + String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
54 + List<YangMust> mustConstraintList = yangContainer.getListOfMust();
55 + assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint));
56 +
57 + YangAppErrorInfo yangAppErrorInfo = mustConstraintList.iterator().next().getAppErrorInfo();
58 + assertThat(yangAppErrorInfo.getGetErrorMessage(), is("An ethernet MTU must be 1500"));
59 + assertThat(yangAppErrorInfo.getGetErrorTag(), is("operation-failed"));
60 + }
61 +}
...@@ -72,8 +72,8 @@ public class InputListenerTest { ...@@ -72,8 +72,8 @@ public class InputListenerTest {
72 assertThat(yangList.getName(), is("ospf")); 72 assertThat(yangList.getName(), is("ospf"));
73 assertThat(yangList.getKeyList().contains("invalid-interval"), is(true)); 73 assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
74 assertThat(yangList.isConfig(), is(true)); 74 assertThat(yangList.isConfig(), is(true));
75 - assertThat(yangList.getMaxElements(), is(10)); 75 + assertThat(yangList.getMaxElements().getMaxElement(), is(10));
76 - assertThat(yangList.getMinElements(), is(3)); 76 + assertThat(yangList.getMinElements().getMinElement(), is(3));
77 leafIterator = yangList.getListOfLeaf().listIterator(); 77 leafIterator = yangList.getListOfLeaf().listIterator();
78 leafInfo = leafIterator.next(); 78 leafInfo = leafIterator.next();
79 assertThat(leafInfo.getName(), is("invalid-interval")); 79 assertThat(leafInfo.getName(), is("invalid-interval"));
......
...@@ -72,7 +72,7 @@ public class LeafListListenerTest { ...@@ -72,7 +72,7 @@ public class LeafListListenerTest {
72 assertThat(leafListInfo.getUnits(), is("\"seconds\"")); 72 assertThat(leafListInfo.getUnits(), is("\"seconds\""));
73 assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 73 assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
74 assertThat(leafListInfo.isConfig(), is(true)); 74 assertThat(leafListInfo.isConfig(), is(true));
75 - assertThat(leafListInfo.getMaxElelements(), is(3)); 75 + assertThat(leafListInfo.getMaxElements().getMaxElement(), is(3));
76 assertThat(leafListInfo.getStatus(), is(YangStatusType.CURRENT)); 76 assertThat(leafListInfo.getStatus(), is(YangStatusType.CURRENT));
77 assertThat(leafListInfo.getReference(), is("\"RFC 6020\"")); 77 assertThat(leafListInfo.getReference(), is("\"RFC 6020\""));
78 } 78 }
...@@ -162,8 +162,8 @@ public class LeafListListenerTest { ...@@ -162,8 +162,8 @@ public class LeafListListenerTest {
162 assertThat(leafListInfo.getUnits(), is("\"seconds\"")); 162 assertThat(leafListInfo.getUnits(), is("\"seconds\""));
163 assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 163 assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
164 assertThat(leafListInfo.isConfig(), is(true)); 164 assertThat(leafListInfo.isConfig(), is(true));
165 - assertThat(leafListInfo.getMinElements(), is(1)); 165 + assertThat(leafListInfo.getMinElements().getMinElement(), is(1));
166 - assertThat(leafListInfo.getMaxElelements(), is(2147483647)); 166 + assertThat(leafListInfo.getMaxElements().getMaxElement(), is(2147483647));
167 assertThat(leafListInfo.getStatus(), is(YangStatusType.CURRENT)); 167 assertThat(leafListInfo.getStatus(), is(YangStatusType.CURRENT));
168 assertThat(leafListInfo.getReference(), is("\"RFC 6020\"")); 168 assertThat(leafListInfo.getReference(), is("\"RFC 6020\""));
169 } 169 }
......
...@@ -151,8 +151,8 @@ public class ListListenerTest { ...@@ -151,8 +151,8 @@ public class ListListenerTest {
151 assertThat(yangList.getKeyList().contains("invalid-interval"), is(true)); 151 assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
152 152
153 assertThat(yangList.isConfig(), is(true)); 153 assertThat(yangList.isConfig(), is(true));
154 - assertThat(yangList.getMaxElements(), is(10)); 154 + assertThat(yangList.getMaxElements().getMaxElement(), is(10));
155 - assertThat(yangList.getMinElements(), is(3)); 155 + assertThat(yangList.getMinElements().getMinElement(), is(3));
156 assertThat(yangList.getDescription(), is("\"list description\"")); 156 assertThat(yangList.getDescription(), is("\"list description\""));
157 assertThat(yangList.getStatus(), is(YangStatusType.CURRENT)); 157 assertThat(yangList.getStatus(), is(YangStatusType.CURRENT));
158 assertThat(yangList.getReference(), is("\"list reference\"")); 158 assertThat(yangList.getReference(), is("\"list reference\""));
......
...@@ -65,7 +65,7 @@ public class MaxElementsListenerTest { ...@@ -65,7 +65,7 @@ public class MaxElementsListenerTest {
65 YangLeafList leafListInfo = leafListIterator.next(); 65 YangLeafList leafListInfo = leafListIterator.next();
66 66
67 assertThat(leafListInfo.getName(), is("invalid-interval")); 67 assertThat(leafListInfo.getName(), is("invalid-interval"));
68 - assertThat(leafListInfo.getMaxElelements(), is(3)); 68 + assertThat(leafListInfo.getMaxElements().getMaxElement(), is(3));
69 } 69 }
70 70
71 /** 71 /**
...@@ -88,7 +88,7 @@ public class MaxElementsListenerTest { ...@@ -88,7 +88,7 @@ public class MaxElementsListenerTest {
88 // Check whether the list is child of module 88 // Check whether the list is child of module
89 YangList yangList = (YangList) yangNode.getChild(); 89 YangList yangList = (YangList) yangNode.getChild();
90 assertThat(yangList.getName(), is("valid")); 90 assertThat(yangList.getName(), is("valid"));
91 - assertThat(yangList.getMaxElements(), is(3)); 91 + assertThat(yangList.getMaxElements().getMaxElement(), is(3));
92 } 92 }
93 93
94 /** 94 /**
...@@ -136,7 +136,7 @@ public class MaxElementsListenerTest { ...@@ -136,7 +136,7 @@ public class MaxElementsListenerTest {
136 YangLeafList leafListInfo = leafListIterator.next(); 136 YangLeafList leafListInfo = leafListIterator.next();
137 137
138 assertThat(leafListInfo.getName(), is("invalid-interval")); 138 assertThat(leafListInfo.getName(), is("invalid-interval"));
139 - assertThat(leafListInfo.getMaxElelements(), is(2147483647)); 139 + assertThat(leafListInfo.getMaxElements().getMaxElement(), is(2147483647));
140 } 140 }
141 141
142 /** 142 /**
...@@ -161,7 +161,7 @@ public class MaxElementsListenerTest { ...@@ -161,7 +161,7 @@ public class MaxElementsListenerTest {
161 YangLeafList leafListInfo = leafListIterator.next(); 161 YangLeafList leafListInfo = leafListIterator.next();
162 162
163 assertThat(leafListInfo.getName(), is("invalid-interval")); 163 assertThat(leafListInfo.getName(), is("invalid-interval"));
164 - assertThat(leafListInfo.getMaxElelements(), is(2147483647)); 164 + assertThat(leafListInfo.getMaxElements().getMaxElement(), is(2147483647));
165 } 165 }
166 166
167 /** 167 /**
......
...@@ -65,7 +65,7 @@ public class MinElementsListenerTest { ...@@ -65,7 +65,7 @@ public class MinElementsListenerTest {
65 YangLeafList leafListInfo = leafListIterator.next(); 65 YangLeafList leafListInfo = leafListIterator.next();
66 66
67 assertThat(leafListInfo.getName(), is("invalid-interval")); 67 assertThat(leafListInfo.getName(), is("invalid-interval"));
68 - assertThat(leafListInfo.getMinElements(), is(3)); 68 + assertThat(leafListInfo.getMinElements().getMinElement(), is(3));
69 } 69 }
70 70
71 /** 71 /**
...@@ -88,7 +88,7 @@ public class MinElementsListenerTest { ...@@ -88,7 +88,7 @@ public class MinElementsListenerTest {
88 // Check whether the list is child of module 88 // Check whether the list is child of module
89 YangList yangList = (YangList) yangNode.getChild(); 89 YangList yangList = (YangList) yangNode.getChild();
90 assertThat(yangList.getName(), is("valid")); 90 assertThat(yangList.getName(), is("valid"));
91 - assertThat(yangList.getMinElements(), is(3)); 91 + assertThat(yangList.getMinElements().getMinElement(), is(3));
92 } 92 }
93 93
94 /** 94 /**
...@@ -158,6 +158,6 @@ public class MinElementsListenerTest { ...@@ -158,6 +158,6 @@ public class MinElementsListenerTest {
158 YangLeafList leafListInfo = leafListIterator.next(); 158 YangLeafList leafListInfo = leafListIterator.next();
159 159
160 assertThat(leafListInfo.getName(), is("invalid-interval")); 160 assertThat(leafListInfo.getName(), is("invalid-interval"));
161 - assertThat(leafListInfo.getMinElements(), is(0)); 161 + assertThat(leafListInfo.getMinElements().getMinElement(), is(0));
162 } 162 }
163 } 163 }
......
...@@ -71,8 +71,8 @@ public class OutputListenerTest { ...@@ -71,8 +71,8 @@ public class OutputListenerTest {
71 assertThat(yangList.getName(), is("ospf")); 71 assertThat(yangList.getName(), is("ospf"));
72 assertThat(yangList.getKeyList().contains("invalid-interval"), is(true)); 72 assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
73 assertThat(yangList.isConfig(), is(true)); 73 assertThat(yangList.isConfig(), is(true));
74 - assertThat(yangList.getMaxElements(), is(10)); 74 + assertThat(yangList.getMaxElements().getMaxElement(), is(10));
75 - assertThat(yangList.getMinElements(), is(3)); 75 + assertThat(yangList.getMinElements().getMinElement(), is(3));
76 leafIterator = yangList.getListOfLeaf().listIterator(); 76 leafIterator = yangList.getListOfLeaf().listIterator();
77 leafInfo = leafIterator.next(); 77 leafInfo = leafIterator.next();
78 assertThat(leafInfo.getName(), is("invalid-interval")); 78 assertThat(leafInfo.getName(), is("invalid-interval"));
......
1 +module ErrorAppTag {
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 + error-app-tag "An ethernet MTU must be 1500";
19 + }
20 + must "ifType != 'atm' or " +
21 + "(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
22 + description "An atm MTU must be 64 .. 17966";
23 + }
24 + }
25 +}
1 +module ErrorAppTag {
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 ErrorMessage {
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 + error-message "An ethernet MTU must be 1500";
19 + }
20 + must "ifType != 'atm' or " +
21 + "(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
22 + description "An atm MTU must be 64 .. 17966";
23 + }
24 + }
25 +}