Gaurav Agrawal
Committed by Gerrit Code Review

[ONOS-4063 to 68] Intra YANG file Linking Implementation and Intra YANG file Linking Framework

Change-Id: I06e602c351ab54178bf90b8676af71a70e42371f
Showing 58 changed files with 2321 additions and 445 deletions
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.datamodel;
18 +
19 +import java.util.List;
20 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
21 +
22 +/**
23 + * Abstraction of YANG dependency resolution information. Abstracted to obtain the
24 + * resolution information.
25 + */
26 +public interface HasResolutionInfo {
27 +
28 + /**
29 + * Returns unresolved resolution list.
30 + *
31 + * @return unresolved resolution list
32 + */
33 + List<YangResolutionInfo> getUnresolvedResolutionList();
34 +
35 + /**
36 + * Add to the resolution list.
37 + *
38 + * @param resolutionInfo resolution information
39 + */
40 + void addToResolutionList(YangResolutionInfo resolutionInfo);
41 +
42 + /**
43 + * Creates resolution list.
44 + *
45 + * @param resolutionList resolution list
46 + */
47 + void setResolutionList(List<YangResolutionInfo> resolutionList);
48 +
49 + /**
50 + * Returns unresolved imported list.
51 + *
52 + * @return unresolved imported list
53 + */
54 + List<YangImport> getImportList();
55 +
56 + /**
57 + * Add to the import list.
58 + *
59 + * @param yangImport import to be added
60 + */
61 + void addToImportList(YangImport yangImport);
62 +
63 + /**
64 + * Create import list.
65 + *
66 + * @param importList import list
67 + */
68 + void setImportList(List<YangImport> importList);
69 +
70 + /**
71 + * Returns unresolved include list.
72 + *
73 + * @return unresolved include list
74 + */
75 + List<YangInclude> getIncludeList();
76 +
77 + /**
78 + * Add to the include list.
79 + *
80 + * @param yangInclude include to be added
81 + */
82 + void addToIncludeList(YangInclude yangInclude);
83 +
84 + /**
85 + * Create include list.
86 + *
87 + * @param includeList include list
88 + */
89 + void setIncludeList(List<YangInclude> includeList);
90 +
91 + /**
92 + * Returns prefix of resolution root node.
93 + *
94 + * @return prefix resolution root node prefix
95 + */
96 + String getPrefix();
97 +
98 + /**
99 + * Set prefix of resolution list root node.
100 + *
101 + * @param prefix resolution root node prefix
102 + */
103 + void setPrefix(String prefix);
104 +
105 + /**
106 + * Resolve self file linking.
107 + *
108 + * @throws DataModelException a violation in data model rule
109 + */
110 + void resolveSelfFileLinking() throws DataModelException;
111 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.datamodel;
18 +
19 +/**
20 + * ENUM to identify the YANG resolution type.
21 + */
22 +public enum ResolutionType {
23 + /**
24 + * Identifies that resolution is for typedef.
25 + */
26 + TYPEDEF_RESOLUTION,
27 +
28 + /**
29 + * Identifies that resolution is for grouping.
30 + */
31 + GROUPING_RESOLUTION;
32 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.datamodel;
18 +
19 +/**
20 + * Abstraction of YANG resolvable information. Abstracted to obtain the
21 + * information required for linking resolution.
22 + */
23 +public interface Resolvable {
24 +
25 + /**
26 + * Returns the status of resolution. If completely resolved returns enum
27 + * value "RESOLVED", if not returns "UNRESOLVED", in case reference of
28 + * grouping/typedef is added to uses/type but it's not resolved
29 + * "PARTIALLY_RESOLVED" is returned.
30 + *
31 + * @return status of resolution
32 + */
33 + ResolvableStatus getResolvableStatus();
34 +
35 + /**
36 + * Set the status of type/uses resolution. If completely resolved set enum
37 + * value "RESOLVED", if not set it to "UNRESOLVED", in case reference of
38 + * grouping/typedef is added to uses/type but it's not resolved
39 + * "PARTIALLY_RESOLVED" should be set.
40 + *
41 + * @param resolvableStatus status of resolution
42 + */
43 + void setResolvableStatus(ResolvableStatus resolvableStatus);
44 +
45 + /**
46 + * Resolves the linking.
47 + */
48 + void resolve();
49 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.datamodel;
18 +
19 +/**
20 + * Represents the status of resolvable entity.
21 + */
22 +public enum ResolvableStatus {
23 +
24 + /**
25 + * Identifies that resolvable entity is resolved.
26 + */
27 + RESOLVED,
28 +
29 + /**
30 + * Identifies that resolvable entity is unresolved.
31 + */
32 + UNRESOLVED,
33 +
34 + /**
35 + * Identifies that resolvable entity is partially resolved.
36 + */
37 + PARTIALLY_RESOLVED;
38 +}
...@@ -16,112 +16,83 @@ ...@@ -16,112 +16,83 @@
16 16
17 package org.onosproject.yangutils.datamodel; 17 package org.onosproject.yangutils.datamodel;
18 18
19 -import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20 -import org.onosproject.yangutils.parser.Parsable;
21 -import org.onosproject.yangutils.utils.YangConstructType;
22 -
23 -/*-
24 - * Reference RFC 6020.
25 - *
26 - * The typedef Statement
27 - *
28 - * The "typedef" statement defines a new type that may be used locally
29 - * in the module, in modules or submodules which include it, and by
30 - * other modules that import from it. The new type is called the
31 - * "derived type", and the type from which it was derived is called
32 - * the "base type". All derived types can be traced back to a YANG
33 - * built-in type.
34 - *
35 - * The "typedef" statement's argument is an identifier that is the name
36 - * of the type to be defined, and MUST be followed by a block of
37 - * sub-statements that holds detailed typedef information.
38 - *
39 - * The name of the type MUST NOT be one of the YANG built-in types. If
40 - * the typedef is defined at the top level of a YANG module or
41 - * submodule, the name of the type to be defined MUST be unique within
42 - * the module.
43 - */
44 /** 19 /**
45 - * Derived type information. 20 + * Maintains the derived information.
21 + *
22 + * @param <T> extended information.
46 */ 23 */
47 -public class YangDerivedType implements Parsable { 24 +public class YangDerivedInfo<T> {
48 25
49 /** 26 /**
50 - * All derived types can be traced back to a YANG built-in type. 27 + * YANG typedef reference.
51 */ 28 */
52 - private YangDataTypes effectiveYangBuiltInType; 29 + private YangTypeDef referredTypeDef;
53 30
54 /** 31 /**
55 - * Base type from which the current type is derived. 32 + * Resolved additional information about data type after linking, example
33 + * restriction info, named values, etc. The extra information is based
34 + * on the data type. Based on the data type, the extended info can vary.
56 */ 35 */
57 - private YangType<?> baseType; 36 + private T resolvedExtendedInfo;
58 37
59 /** 38 /**
60 - * Default constructor. 39 + * Additional information about data type, example restriction info, named
40 + * values, etc. The extra information is based on the data type. Based on
41 + * the data type, the extended info can vary.
61 */ 42 */
62 - public YangDerivedType() { 43 + private T extendedInfo;
63 - }
64 44
65 /** 45 /**
66 - * Get the effective YANG built-in type of the derived data type. 46 + * Returns the referred typedef reference.
67 * 47 *
68 - * @return effective YANG built-in type of the derived data type 48 + * @return referred typedef reference
69 */ 49 */
70 - public YangDataTypes getEffectiveYangBuiltInType() { 50 + public YangTypeDef getReferredTypeDef() {
71 - return effectiveYangBuiltInType; 51 + return referredTypeDef;
72 } 52 }
73 53
74 /** 54 /**
75 - * Set the effective YANG built-in type of the derived data type. 55 + * Set the referred typedef reference.
76 * 56 *
77 - * @param builtInType effective YANG built-in type of the derived data type 57 + * @param referredTypeDef referred typedef reference
78 */ 58 */
79 - public void setEffectiveYangBuiltInType(YangDataTypes builtInType) { 59 + public void setReferredTypeDef(YangTypeDef referredTypeDef) {
80 - effectiveYangBuiltInType = builtInType; 60 + this.referredTypeDef = referredTypeDef;
81 } 61 }
82 62
83 /** 63 /**
84 - * Get the base type information. 64 + * Returns resolved extended information after successful linking.
85 * 65 *
86 - * @return base type information 66 + * @return resolved extended information
87 */ 67 */
88 - public YangType<?> getBaseType() { 68 + public T getResolvedExtendedInfo() {
89 - return baseType; 69 + return resolvedExtendedInfo;
90 } 70 }
91 71
92 /** 72 /**
93 - * Get the base type information. 73 + * Set resolved extended information after successful linking.
94 * 74 *
95 - * @param baseType base type information 75 + * @param resolvedExtendedInfo resolved extended information
96 */ 76 */
97 - public void setBaseType(YangType<?> baseType) { 77 + public void setResolvedExtendedInfo(T resolvedExtendedInfo) {
98 - this.baseType = baseType; 78 + this.resolvedExtendedInfo = resolvedExtendedInfo;
99 } 79 }
100 80
101 /** 81 /**
102 - * Get the parsable type. 82 + * Returns extended information.
103 - */ 83 + *
104 - @Override 84 + * @return extended information
105 - public YangConstructType getYangConstructType() {
106 - return YangConstructType.DERIVED;
107 - }
108 -
109 - /**
110 - * TODO.
111 */ 85 */
112 - @Override 86 + public T getExtendedInfo() {
113 - public void validateDataOnEntry() throws DataModelException { 87 + return extendedInfo;
114 - // TODO Auto-generated method stub
115 -
116 } 88 }
117 89
118 /** 90 /**
119 - * TODO. 91 + * Set extended information.
92 + *
93 + * @param extendedInfo extended information
120 */ 94 */
121 - @Override 95 + public void setExtendedInfo(T extendedInfo) {
122 - public void validateDataOnExit() throws DataModelException { 96 + this.extendedInfo = extendedInfo;
123 - // TODO Auto-generated method stub
124 -
125 } 97 }
126 -
127 } 98 }
......
...@@ -75,6 +75,11 @@ public class YangImport implements Parsable { ...@@ -75,6 +75,11 @@ public class YangImport implements Parsable {
75 private String prefixId; 75 private String prefixId;
76 76
77 /** 77 /**
78 + * Resolution information root node which is also the data model root node.
79 + */
80 + private HasResolutionInfo resolutionInfoNode;
81 +
82 + /**
78 * Reference:RFC 6020. 83 * Reference:RFC 6020.
79 * 84 *
80 * The import's "revision-date" statement is used to specify the exact 85 * The import's "revision-date" statement is used to specify the exact
...@@ -177,4 +182,22 @@ public class YangImport implements Parsable { ...@@ -177,4 +182,22 @@ public class YangImport implements Parsable {
177 // TODO auto-generated method stub, to be implemented by parser 182 // TODO auto-generated method stub, to be implemented by parser
178 183
179 } 184 }
185 +
186 + /**
187 + * Returns the resolution information node.
188 + *
189 + * @return the resolution information node
190 + */
191 + public HasResolutionInfo getResolutionInfoNode() {
192 + return resolutionInfoNode;
193 + }
194 +
195 + /**
196 + * Set the dresolution information node.
197 + *
198 + * @param resolutionInfoNode the resolution information node
199 + */
200 + public void setResolutionInfoNode(HasResolutionInfo resolutionInfoNode) {
201 + this.resolutionInfoNode = resolutionInfoNode;
202 + }
180 } 203 }
......
...@@ -51,6 +51,11 @@ public class YangInclude implements Parsable { ...@@ -51,6 +51,11 @@ public class YangInclude implements Parsable {
51 private String revision; 51 private String revision;
52 52
53 /** 53 /**
54 + * Resolution information root node which is also the data model root node.
55 + */
56 + private HasResolutionInfo resolutionInfoNode;
57 +
58 + /**
54 * Default constructor. 59 * Default constructor.
55 */ 60 */
56 public YangInclude() { 61 public YangInclude() {
...@@ -124,4 +129,21 @@ public class YangInclude implements Parsable { ...@@ -124,4 +129,21 @@ public class YangInclude implements Parsable {
124 129
125 } 130 }
126 131
132 + /**
133 + * Returns the resolution information node.
134 + *
135 + * @return the resolution information node
136 + */
137 + public HasResolutionInfo getResolutionInfoNode() {
138 + return resolutionInfoNode;
139 + }
140 +
141 + /**
142 + * Set the dresolution information node.
143 + *
144 + * @param resolutionInfoNode the resolution information node
145 + */
146 + public void setResolutionInfoNode(HasResolutionInfo resolutionInfoNode) {
147 + this.resolutionInfoNode = resolutionInfoNode;
148 + }
127 } 149 }
......
...@@ -17,12 +17,12 @@ package org.onosproject.yangutils.datamodel; ...@@ -17,12 +17,12 @@ package org.onosproject.yangutils.datamodel;
17 17
18 import java.util.LinkedList; 18 import java.util.LinkedList;
19 import java.util.List; 19 import java.util.List;
20 -
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 20 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22 import org.onosproject.yangutils.parser.Parsable; 21 import org.onosproject.yangutils.parser.Parsable;
23 import org.onosproject.yangutils.utils.YangConstructType; 22 import org.onosproject.yangutils.utils.YangConstructType;
24 23
25 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; 24 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
25 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
26 26
27 /*- 27 /*-
28 * Reference:RFC 6020. 28 * Reference:RFC 6020.
...@@ -68,7 +68,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol ...@@ -68,7 +68,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
68 * Data model node to maintain information defined in YANG module. 68 * Data model node to maintain information defined in YANG module.
69 */ 69 */
70 public class YangModule extends YangNode 70 public class YangModule extends YangNode
71 - implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector { 71 + implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, HasResolutionInfo {
72 72
73 /** 73 /**
74 * Name of the module. 74 * Name of the module.
...@@ -185,16 +185,19 @@ public class YangModule extends YangNode ...@@ -185,16 +185,19 @@ public class YangModule extends YangNode
185 * matching "typedef" or "grouping" statement among the immediate 185 * matching "typedef" or "grouping" statement among the immediate
186 * sub-statements of each ancestor statement. 186 * sub-statements of each ancestor statement.
187 */ 187 */
188 - /** 188 + private List<YangResolutionInfo> unresolvedResolutionList;
189 - * List of nodes which require nested reference resolution.
190 - */
191 - private List<YangNode> nestedReferenceResoulutionList;
192 189
193 /** 190 /**
194 * Create a YANG node of module type. 191 * Create a YANG node of module type.
195 */ 192 */
196 public YangModule() { 193 public YangModule() {
194 +
197 super(YangNodeType.MODULE_NODE); 195 super(YangNodeType.MODULE_NODE);
196 + unresolvedResolutionList = new LinkedList<YangResolutionInfo>();
197 + importList = new LinkedList<YangImport>();
198 + includeList = new LinkedList<YangInclude>();
199 + listOfLeaf = new LinkedList<YangLeaf>();
200 + listOfLeafList = new LinkedList<YangLeafList>();
198 } 201 }
199 202
200 /** 203 /**
...@@ -265,28 +268,17 @@ public class YangModule extends YangNode ...@@ -265,28 +268,17 @@ public class YangModule extends YangNode
265 } 268 }
266 269
267 /** 270 /**
268 - * prevent setting the import list from outside.
269 - *
270 - * @param importList the import list to set
271 - */
272 - private void setImportList(List<YangImport> importList) {
273 - this.importList = importList;
274 - }
275 -
276 - /**
277 * Add the imported module information to the import list. 271 * Add the imported module information to the import list.
278 * 272 *
279 * @param importedModule module being imported 273 * @param importedModule module being imported
280 */ 274 */
281 - public void addImportedInfo(YangImport importedModule) { 275 + public void addToImportList(YangImport importedModule) {
282 -
283 - if (getImportList() == null) {
284 - setImportList(new LinkedList<YangImport>());
285 - }
286 -
287 getImportList().add(importedModule); 276 getImportList().add(importedModule);
277 + }
288 278
289 - return; 279 + @Override
280 + public void setImportList(List<YangImport> importList) {
281 + this.importList = importList;
290 } 282 }
291 283
292 /** 284 /**
...@@ -299,27 +291,17 @@ public class YangModule extends YangNode ...@@ -299,27 +291,17 @@ public class YangModule extends YangNode
299 } 291 }
300 292
301 /** 293 /**
302 - * Set the list of included sub modules.
303 - *
304 - * @param includeList the included list to set
305 - */
306 - private void setIncludeList(List<YangInclude> includeList) {
307 - this.includeList = includeList;
308 - }
309 -
310 - /**
311 * Add the included sub module information to the include list. 294 * Add the included sub module information to the include list.
312 * 295 *
313 * @param includeModule submodule being included 296 * @param includeModule submodule being included
314 */ 297 */
315 - public void addIncludedInfo(YangInclude includeModule) { 298 + public void addToIncludeList(YangInclude includeModule) {
316 -
317 - if (getIncludeList() == null) {
318 - setIncludeList(new LinkedList<YangInclude>());
319 - }
320 -
321 getIncludeList().add(includeModule); 299 getIncludeList().add(includeModule);
322 - return; 300 + }
301 +
302 + @Override
303 + public void setIncludeList(List<YangInclude> includeList) {
304 + this.includeList = includeList;
323 } 305 }
324 306
325 /** 307 /**
...@@ -333,25 +315,12 @@ public class YangModule extends YangNode ...@@ -333,25 +315,12 @@ public class YangModule extends YangNode
333 } 315 }
334 316
335 /** 317 /**
336 - * Set the list of leaf in module.
337 - *
338 - * @param leafsList the list of leaf to set
339 - */
340 - private void setListOfLeaf(List<YangLeaf> leafsList) {
341 - listOfLeaf = leafsList;
342 - }
343 -
344 - /**
345 * Add a leaf in module. 318 * Add a leaf in module.
346 * 319 *
347 * @param leaf the leaf to be added 320 * @param leaf the leaf to be added
348 */ 321 */
349 @Override 322 @Override
350 public void addLeaf(YangLeaf leaf) { 323 public void addLeaf(YangLeaf leaf) {
351 - if (getListOfLeaf() == null) {
352 - setListOfLeaf(new LinkedList<YangLeaf>());
353 - }
354 -
355 getListOfLeaf().add(leaf); 324 getListOfLeaf().add(leaf);
356 } 325 }
357 326
...@@ -366,25 +335,12 @@ public class YangModule extends YangNode ...@@ -366,25 +335,12 @@ public class YangModule extends YangNode
366 } 335 }
367 336
368 /** 337 /**
369 - * Set the list of leaf-list in module.
370 - *
371 - * @param listOfLeafList the list of leaf-list to set
372 - */
373 - private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
374 - this.listOfLeafList = listOfLeafList;
375 - }
376 -
377 - /**
378 * Add a leaf-list in module. 338 * Add a leaf-list in module.
379 * 339 *
380 * @param leafList the leaf-list to be added 340 * @param leafList the leaf-list to be added
381 */ 341 */
382 @Override 342 @Override
383 public void addLeafList(YangLeafList leafList) { 343 public void addLeafList(YangLeafList leafList) {
384 - if (getListOfLeafList() == null) {
385 - setListOfLeafList(new LinkedList<YangLeafList>());
386 - }
387 -
388 getListOfLeafList().add(leafList); 344 getListOfLeafList().add(leafList);
389 } 345 }
390 346
...@@ -442,6 +398,14 @@ public class YangModule extends YangNode ...@@ -442,6 +398,14 @@ public class YangModule extends YangNode
442 this.prefix = prefix; 398 this.prefix = prefix;
443 } 399 }
444 400
401 + @Override
402 + public void resolveSelfFileLinking() throws DataModelException {
403 + // Get the list to be resolved.
404 + List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
405 + // Resolve linking for a resolution list.
406 + resolveLinkingForResolutionList(resolutionList, this);
407 + }
408 +
445 /** 409 /**
446 * Get the textual reference. 410 * Get the textual reference.
447 * 411 *
...@@ -499,37 +463,6 @@ public class YangModule extends YangNode ...@@ -499,37 +463,6 @@ public class YangModule extends YangNode
499 } 463 }
500 464
501 /** 465 /**
502 - * Get the list of nested reference's which required resolution.
503 - *
504 - * @return list of nested reference's which required resolution
505 - */
506 - public List<YangNode> getNestedReferenceResoulutionList() {
507 - return nestedReferenceResoulutionList;
508 - }
509 -
510 - /**
511 - * Set list of nested reference's which requires resolution.
512 - *
513 - * @param nestedReferenceResoulutionList list of nested reference's which
514 - * requires resolution
515 - */
516 - private void setNestedReferenceResoulutionList(List<YangNode> nestedReferenceResoulutionList) {
517 - this.nestedReferenceResoulutionList = nestedReferenceResoulutionList;
518 - }
519 -
520 - /**
521 - * Set list of nested reference's which requires resolution.
522 - *
523 - * @param nestedReference nested reference which requires resolution
524 - */
525 - public void addToNestedReferenceResoulutionList(YangNode nestedReference) {
526 - if (getNestedReferenceResoulutionList() == null) {
527 - setNestedReferenceResoulutionList(new LinkedList<YangNode>());
528 - }
529 - getNestedReferenceResoulutionList().add(nestedReference);
530 - }
531 -
532 - /**
533 * Returns the type of the parsed data. 466 * Returns the type of the parsed data.
534 * 467 *
535 * @return returns MODULE_DATA 468 * @return returns MODULE_DATA
...@@ -565,31 +498,6 @@ public class YangModule extends YangNode ...@@ -565,31 +498,6 @@ public class YangModule extends YangNode
565 */ 498 */
566 } 499 }
567 500
568 - /**
569 - * Add a type to resolve the nested references.
570 - *
571 - * @param node grouping or typedef node which needs to be resolved
572 - * @throws DataModelException data model exception
573 - */
574 - public static void addToResolveList(YangNode node) throws DataModelException {
575 - /* get the module node to add maintain the list of nested reference */
576 - YangModule module;
577 - YangNode curNode = node;
578 - while (curNode.getNodeType() != YangNodeType.MODULE_NODE) {
579 - curNode = curNode.getParent();
580 - if (curNode == null) {
581 - break;
582 - }
583 - }
584 - if (curNode == null) {
585 - throw new DataModelException("Datamodel tree is not correct");
586 - }
587 -
588 - module = (YangModule) curNode;
589 - module.addToNestedReferenceResoulutionList(node);
590 - return;
591 - }
592 -
593 @Override 501 @Override
594 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { 502 public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
595 // Asks helper to detect colliding child. 503 // Asks helper to detect colliding child.
...@@ -601,4 +509,18 @@ public class YangModule extends YangNode ...@@ -601,4 +509,18 @@ public class YangModule extends YangNode
601 // Not required as module doesn't have any parent. 509 // Not required as module doesn't have any parent.
602 } 510 }
603 511
512 + @Override
513 + public List<YangResolutionInfo> getUnresolvedResolutionList() {
514 + return unresolvedResolutionList;
515 + }
516 +
517 + @Override
518 + public void addToResolutionList(YangResolutionInfo resolutionInfo) {
519 + unresolvedResolutionList.add(resolutionInfo);
520 + }
521 +
522 + @Override
523 + public void setResolutionList(List<YangResolutionInfo> resolutionList) {
524 + unresolvedResolutionList = resolutionList;
525 + }
604 } 526 }
......
...@@ -45,7 +45,7 @@ public class YangNodeIdentifier { ...@@ -45,7 +45,7 @@ public class YangNodeIdentifier {
45 /** 45 /**
46 * Set name of the node identifier. 46 * Set name of the node identifier.
47 * 47 *
48 - * @param name node identifier name 48 + * @param name name of the node identifier
49 */ 49 */
50 public void setName(String name) { 50 public void setName(String name) {
51 this.name = name; 51 this.name = name;
...@@ -54,7 +54,7 @@ public class YangNodeIdentifier { ...@@ -54,7 +54,7 @@ public class YangNodeIdentifier {
54 /** 54 /**
55 * Returns prefix of the node identifier. 55 * Returns prefix of the node identifier.
56 * 56 *
57 - * @return prefix of the node identifier 57 + * @return name of the node identifier
58 */ 58 */
59 public String getPrefix() { 59 public String getPrefix() {
60 return prefix; 60 return prefix;
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.datamodel;
18 +
19 +import java.util.Stack;
20 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
21 +
22 +/**
23 + * Resolution object which will be resolved by linker.
24 + */
25 +public class YangResolutionInfo<T> {
26 +
27 + // Prefix associated with the linking.
28 + private String prefix;
29 +
30 + // Parsable node for which resolution is to be performed.
31 + private T entityToResolve;
32 +
33 + // Holder of the YANG construct for which resolution has to be carried out.
34 + private YangNode holderOfEntityToResolve;
35 +
36 + // Error Line number.
37 + private int lineNumber;
38 +
39 + // Error character position.
40 + private int charPosition;
41 +
42 + // Status of resolution.
43 + private boolean isResolved;
44 +
45 + /*
46 + * Stack for type/uses is maintained for hierarchical references, this
47 + * is used during resolution.
48 + */
49 + private Stack<T> partialResolvedStack;
50 +
51 + // Flag to indicate whether more references are detected.
52 + private boolean isMoreReferenceDetected;
53 +
54 + // Module/Sub-module prefix.
55 + private String resolutionInfoRootNodePrefix;
56 +
57 + /**
58 + * Create a resolution information object.
59 + */
60 + private YangResolutionInfo() {
61 +
62 + }
63 +
64 + /**
65 + * Creates a resolution information object with all the inputs.
66 + *
67 + * @param dataNode current parsable data node
68 + * @param resolutionType type of resolution whether grouping/typedef
69 + * @param holderNode parent YANG node
70 + * @param prefix imported module prefix
71 + * @param lineNumber error line number
72 + * @param charPositionInLine error character position in line
73 + */
74 + public YangResolutionInfo(T dataNode, ResolutionType resolutionType,
75 + YangNode holderNode, String prefix, int lineNumber,
76 + int charPositionInLine) {
77 + this.setHolderOfEntityToResolve(holderNode);
78 + this.setEntityToResolve(dataNode);
79 + this.setPrefix(prefix);
80 + this.setLineNumber(lineNumber);
81 + this.setCharPosition(charPositionInLine);
82 + setPartialResolvedStack(new Stack<T>());
83 + }
84 +
85 + /**
86 + * Creates a resolution information object with all the inputs except prefix.
87 + *
88 + * @param dataNode current parsable data node
89 + * @param resolutionType type of resolution whether grouping/typedef
90 + * @param holderNode parent YANG node
91 + * @param lineNumber error line number
92 + * @param charPositionInLine error character position in line
93 + */
94 + public YangResolutionInfo(T dataNode, ResolutionType resolutionType,
95 + YangNode holderNode, int lineNumber,
96 + int charPositionInLine) {
97 + this.setHolderOfEntityToResolve(holderNode);
98 + this.setEntityToResolve(dataNode);
99 + this.setLineNumber(lineNumber);
100 + this.setCharPosition(charPositionInLine);
101 + }
102 +
103 + /**
104 + * Resolve linking with all the ancestors node for a resolution info.
105 + *
106 + * @param resolutionInfoNodePrefix module/sub-module prefix
107 + * @throws DataModelException DataModelException a violation of data model rules
108 + */
109 + public void resolveLinkingForResolutionInfo(String resolutionInfoNodePrefix) throws DataModelException {
110 +
111 + this.resolutionInfoRootNodePrefix = resolutionInfoNodePrefix;
112 +
113 + // Current node to resolve, it can be a YANG type or YANG uses.
114 + T entityToResolve = getEntityToResolve();
115 +
116 + // Check if linking is already done
117 + if (entityToResolve instanceof Resolvable) {
118 + Resolvable resolvable = (Resolvable) entityToResolve;
119 + if (resolvable.getResolvableStatus() == ResolvableStatus.RESOLVED ||
120 + resolvable.getResolvableStatus() == ResolvableStatus.PARTIALLY_RESOLVED) {
121 + return;
122 + }
123 + } else {
124 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
125 + }
126 +
127 + // Push the initial YANG type to the stack.
128 + getPartialResolvedStack().push(entityToResolve);
129 +
130 + // Get holder of entity to resolve
131 + YangNode curNode = getHolderOfEntityToResolve();
132 +
133 + resolveLinkingWithAncestors(curNode);
134 + }
135 +
136 + /**
137 + * Resolves linking with ancestors.
138 + *
139 + * @param curNode current node for which ancestors to be checked
140 + * @throws DataModelException a violation of data model rules
141 + */
142 + private void resolveLinkingWithAncestors(YangNode curNode) throws DataModelException {
143 +
144 + while (curNode != null) {
145 + YangNode node = curNode.getChild();
146 + if (resolveLinkingForNodesChildAndSibling(node, curNode)) {
147 + return;
148 + }
149 + curNode = curNode.getParent();
150 + }
151 +
152 + // If curNode is null, it indicates an error condition in YANG file.
153 + DataModelException dataModelException = new DataModelException("YANG file error: Unable to find base " +
154 + "typedef/grouping for given type/uses");
155 + dataModelException.setLine(getLineNumber());
156 + dataModelException.setCharPosition(getCharPosition());
157 + throw dataModelException;
158 + }
159 +
160 + /**
161 + * Resolves linking for a node child and siblings.
162 + *
163 + * @param node current node
164 + * @param parentNode parent node of current node
165 + * @return flag to indicate whether resolution is done
166 + * @throws DataModelException
167 + */
168 + private boolean resolveLinkingForNodesChildAndSibling(YangNode node, YangNode parentNode)
169 + throws DataModelException {
170 + while ((node != null)) {
171 + isMoreReferenceDetected = false;
172 + // Check if node is of type, typedef or grouping
173 + if (isNodeOfResolveType(node)) {
174 + if (resolveLinkingForNode(node, parentNode)) {
175 + return true;
176 + }
177 + }
178 + if (isMoreReferenceDetected) {
179 + /*
180 + * If more reference are present, tree traversal must start
181 + * from first child again, to check the availability of
182 + * typedef/grouping.
183 + */
184 + node = parentNode.getChild();
185 + } else {
186 + node = node.getNextSibling();
187 + }
188 + }
189 + return false;
190 + }
191 +
192 + /**
193 + * Resolves linking for a node.
194 + *
195 + * @param node current node
196 + * @param parentNode parent node of current node
197 + * @return flag to indicate whether resolution is done
198 + * @throws DataModelException a violation of data model rules
199 + */
200 + private boolean resolveLinkingForNode(YangNode node, YangNode parentNode) throws
201 + DataModelException {
202 + /*
203 + * Check if name of node name matches with the entity name
204 + * under resolution.
205 + */
206 + if (isNodeNameSameAsResolutionInfoName(node)) {
207 + // Add reference of entity to the node under resolution.
208 + addReferredEntityLink(node);
209 + // Check if referred entity has further reference to uses/type.
210 + if (!(isMoreReferencePresent(node))) {
211 + // Resolve all the entities in stack.
212 + resolveStackAndAddToStack(node);
213 + return true;
214 + } else {
215 + // Add referred type/uses to the stack.
216 + addToPartialResolvedStack(node);
217 + /*
218 + * Check whether referred type is resolved, partially resolved
219 + * or unresolved.
220 + */
221 + if (isReferenceFullyResolved()) {
222 + // Resolve the stack which is complete.
223 + resolveCompleteStack();
224 + return true;
225 + } else if (isReferencePartiallyResolved()) {
226 + /*
227 + * Update the resolution type to partially resolved for all
228 + * type/uses in stack
229 + */
230 + updateResolutionTypeToPartial();
231 + return true;
232 + } else {
233 + /*
234 + * Check if prefix is present to find that the derived
235 + * reference is for intra file or inter file, if it's
236 + * inter-file return and stop further processing.
237 + */
238 + if (isExternalPrefixPresent(node)) {
239 + /*
240 + * Update the resolution type to partially resolved for all
241 + * type/uses in stack
242 + */
243 + updateResolutionTypeToPartial();
244 + return true;
245 + } else {
246 + /*
247 + * If prefix is not present it indicates intra-file
248 + * dependency in this case set the node back to first
249 + * child, as referred entity may appear in any order
250 + * and continue with the resolution.
251 + */
252 + isMoreReferenceDetected = true;
253 + return false;
254 + }
255 + }
256 + }
257 + }
258 + return false;
259 + }
260 +
261 + /**
262 + * Update resolution type to partial for all type/uses in stack.
263 + *
264 + * @throws DataModelException a violation of data model rules
265 + */
266 + private void updateResolutionTypeToPartial() throws DataModelException {
267 + // For all entries in stack calls for the resolution in type/uses.
268 + for (T entity:getPartialResolvedStack()) {
269 + if (!(entity instanceof Resolvable)) {
270 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
271 + }
272 + if (((Resolvable) entity).getResolvableStatus() == ResolvableStatus.UNRESOLVED) {
273 + // Set the resolution status in inside the type/uses.
274 + ((Resolvable) entity).setResolvableStatus(ResolvableStatus.PARTIALLY_RESOLVED);
275 + }
276 + }
277 + }
278 +
279 + /**
280 + * Add referred type/uses to the stack and resolve the stack.
281 + *
282 + * @param node typedef/grouping node
283 + * @throws DataModelException a violation of data model rules
284 + */
285 + private void resolveStackAndAddToStack(YangNode node) throws DataModelException {
286 + if (getEntityToResolve() instanceof YangType) {
287 + // Add to the stack only for YANG typedef.
288 + getPartialResolvedStack().push((T) ((YangTypeDef) node).getDataType());
289 + }
290 + // Don't add to stack in case of YANG grouping.
291 +
292 + // Resolve the complete stack.
293 + resolveCompleteStack();
294 + }
295 +
296 + /**
297 + * Check if the referred type/uses is partially resolved.
298 + *
299 + * @return true if reference is partially resolved, otherwise false
300 + */
301 + private boolean isReferencePartiallyResolved() {
302 + if (getPartialResolvedStack().peek() instanceof YangType) {
303 + /*
304 + * Checks if type is partially resolved.
305 + */
306 + if (((YangType) getPartialResolvedStack().peek()).getResolvableStatus() ==
307 + ResolvableStatus.PARTIALLY_RESOLVED) {
308 + return true;
309 + }
310 + } else if (getPartialResolvedStack().peek() instanceof YangUses) {
311 + if (((YangUses) getPartialResolvedStack().peek()).getResolvableStatus() ==
312 + ResolvableStatus.PARTIALLY_RESOLVED) {
313 + return true;
314 + }
315 + }
316 + return false;
317 + }
318 +
319 + /**
320 + * Check if the referred type/uses is resolved.
321 + *
322 + * @return true if reference is resolved, otherwise false
323 + */
324 + private boolean isReferenceFullyResolved() {
325 + if (getPartialResolvedStack().peek() instanceof YangType) {
326 + /*
327 + * Checks if type is partially resolved.
328 + */
329 + if (((YangType) getPartialResolvedStack().peek()).getResolvableStatus() ==
330 + ResolvableStatus.RESOLVED) {
331 + return true;
332 + }
333 + } else if (getPartialResolvedStack().peek() instanceof YangUses) {
334 + if (((YangUses) getPartialResolvedStack().peek()).getResolvableStatus() ==
335 + ResolvableStatus.RESOLVED) {
336 + return true;
337 + }
338 + }
339 + return false;
340 + }
341 +
342 + /**
343 + * Check if node is of resolve type i.e. of type typedef or grouping.
344 + *
345 + * @param node typedef/grouping node
346 + * @return true if node is of resolve type otherwise false
347 + * @throws DataModelException a violation of data model rules
348 + */
349 + private boolean isNodeOfResolveType(YangNode node) throws DataModelException {
350 + if (getPartialResolvedStack().peek() instanceof YangType && entityToResolve instanceof YangType) {
351 + if (node instanceof YangTypeDef) {
352 + return true;
353 + }
354 + } else if (getPartialResolvedStack().peek() instanceof YangUses && entityToResolve instanceof YangUses) {
355 + if (node instanceof YangGrouping) {
356 + return true;
357 + }
358 + } else {
359 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
360 + }
361 + return false;
362 + }
363 +
364 +
365 + /**
366 + * Check if node name is same as name in resolution info, i.e. name of
367 + * typedef/grouping is same as name of type/uses.
368 + *
369 + * @param node typedef/grouping node
370 + * @return true if node name is same as name in resolution info, otherwise
371 + * false
372 + * @throws DataModelException a violation of data model rules
373 + */
374 + private boolean isNodeNameSameAsResolutionInfoName(YangNode node) throws DataModelException {
375 + if (getPartialResolvedStack().peek() instanceof YangType) {
376 + if (node.getName().equals(((YangType<?>) getPartialResolvedStack().peek()).getDataTypeName())) {
377 + return true;
378 + }
379 + } else if (getPartialResolvedStack().peek() instanceof YangUses) {
380 + if (node.getName().equals(((YangUses) getPartialResolvedStack().peek()).getName())) {
381 + return true;
382 + }
383 + } else {
384 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
385 + }
386 + return false;
387 + }
388 +
389 + /**
390 + * Add reference of grouping/typedef in uses/type.
391 + *
392 + * @param node grouping/typedef node
393 + * @throws DataModelException a violation of data model rules
394 + */
395 + private void addReferredEntityLink(YangNode node) throws DataModelException {
396 + if (getPartialResolvedStack().peek() instanceof YangType) {
397 + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) ((YangType<?>) getPartialResolvedStack().peek())
398 + .getDataTypeExtendedInfo();
399 + derivedInfo.setReferredTypeDef((YangTypeDef) node);
400 + } else if (getPartialResolvedStack().peek() instanceof YangUses) {
401 + ((YangUses) getPartialResolvedStack().peek()).setRefGroup((YangGrouping) node);
402 + } else {
403 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
404 + }
405 + }
406 +
407 + /**
408 + * Checks if typedef/grouping has further reference to type/typedef.
409 + *
410 + * @param node grouping/typedef node
411 + * @return true if referred entity is resolved, otherwise false
412 + * @throws DataModelException a violation of data model rules
413 + */
414 + private boolean isMoreReferencePresent(YangNode node) throws DataModelException {
415 + if (getEntityToResolve() instanceof YangType) {
416 + /*
417 + * Checks if typedef type is built-in type
418 + */
419 + if ((((YangTypeDef) node).getDataType().getDataType() != YangDataTypes.DERIVED)) {
420 + return false;
421 + }
422 + } else if (getEntityToResolve() instanceof YangUses) {
423 + /*
424 + * Search if the grouping has any uses child, if so return false,
425 + * else return true.
426 + */
427 + if (getUsesInGrouping(node) == null) {
428 + return false;
429 + }
430 + } else {
431 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
432 + }
433 + return true;
434 + }
435 +
436 + /**
437 + * Return if there is any uses in grouping.
438 + *
439 + * @param node grouping/typedef node
440 + * @return if there is any uses in grouping, otherwise return null
441 + */
442 + private YangUses getUsesInGrouping(YangNode node) {
443 + YangNode curNode = ((YangGrouping) node).getChild();
444 + while (curNode != null) {
445 + if (curNode instanceof YangUses) {
446 + break;
447 + }
448 + curNode = curNode.getNextSibling();
449 + }
450 + return (YangUses) curNode;
451 + }
452 +
453 + /**
454 + * Resolve the complete stack.
455 + *
456 + * @throws DataModelException a violation of data model rules
457 + */
458 + private void resolveCompleteStack() throws DataModelException {
459 + // For all entries in stack calls for the resolution in type/uses.
460 + for (T entity:getPartialResolvedStack()) {
461 + if (!(entity instanceof Resolvable)) {
462 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
463 + }
464 + ((Resolvable) entity).resolve();
465 + // Set the resolution status in inside the type/uses.
466 + ((Resolvable) entity).setResolvableStatus(ResolvableStatus.RESOLVED);
467 + }
468 + /*
469 + * Set the resolution status in resolution info present in resolution
470 + * list.
471 + */
472 + setIsResolved(true);
473 + }
474 +
475 + /**
476 + * Add to partial resolved stack.
477 + *
478 + * @param node grouping/typedef node
479 + * @throws DataModelException a violation of data model rules
480 + */
481 + private void addToPartialResolvedStack(YangNode node) throws DataModelException {
482 + if (getPartialResolvedStack().peek() instanceof YangType) {
483 + // Add to the stack only for YANG typedef.
484 + getPartialResolvedStack().push((T) ((YangTypeDef) node).getDataType());
485 + } else if (getPartialResolvedStack().peek() instanceof YangUses) {
486 + getPartialResolvedStack().push((T) getUsesInGrouping(node));
487 + } else {
488 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
489 + }
490 + }
491 +
492 + /**
493 + * Check if prefix is associated with type/uses.
494 + *
495 + * @param node typedef/grouping node
496 + * @return true if prefix is present, otherwise false
497 + * @throws DataModelException a violation of data model rules
498 + */
499 + private boolean isExternalPrefixPresent(YangNode node) throws DataModelException {
500 + if (getEntityToResolve() instanceof YangType) {
501 + if (((YangTypeDef) node).getDataType().getPrefix() != null &&
502 + (!((YangTypeDef) node).getDataType().getPrefix().equals(resolutionInfoRootNodePrefix))) {
503 + return true;
504 + }
505 + } else if (getEntityToResolve() instanceof YangUses) {
506 + if (getUsesInGrouping(node).getPrefix() != null) {
507 + return true;
508 + }
509 + } else {
510 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
511 + }
512 + return false;
513 + }
514 +
515 + /**
516 + * Returns prefix of imported module.
517 + *
518 + * @return prefix of imported module
519 + */
520 + public String getPrefix() {
521 + return prefix;
522 + }
523 +
524 + /**
525 + * Set prefix of imported module.
526 + *
527 + * @param prefix of imported module
528 + */
529 + public void setPrefix(String prefix) {
530 + this.prefix = prefix;
531 + }
532 +
533 + /**
534 + * Returns parsable entity which is to be resolved.
535 + *
536 + * @return parsable entity which is to be resolved
537 + */
538 + public T getEntityToResolve() {
539 + return entityToResolve;
540 + }
541 +
542 + /**
543 + * Set parsable entity to be resolved.
544 + *
545 + * @param entityToResolve YANG entity to be resolved
546 + */
547 + public void setEntityToResolve(T entityToResolve) {
548 + this.entityToResolve = entityToResolve;
549 + }
550 +
551 + /**
552 + * Returns parent YANG node holder for the entity to be resolved.
553 + *
554 + * @return parent YANG node holder
555 + */
556 + public YangNode getHolderOfEntityToResolve() {
557 + return holderOfEntityToResolve;
558 + }
559 +
560 + /**
561 + * Set parent YANG node holder for the entity to be resolved.
562 + *
563 + * @param holderOfEntityToResolve parent YANG node holder
564 + */
565 + public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
566 + this.holderOfEntityToResolve = holderOfEntityToResolve;
567 + }
568 +
569 + /**
570 + * Returns error position.
571 + *
572 + * @return error position
573 + */
574 + public int getCharPosition() {
575 + return charPosition;
576 + }
577 +
578 + /**
579 + * Set error position.
580 + *
581 + * @param charPosition position of error
582 + */
583 + public void setCharPosition(int charPosition) {
584 + this.charPosition = charPosition;
585 + }
586 +
587 + /**
588 + * Returns error character position in line.
589 + *
590 + * @return error character position in line
591 + */
592 + public int getLineNumber() {
593 + return lineNumber;
594 + }
595 +
596 + /**
597 + * Set error character position in line.
598 + *
599 + * @param lineNumber error character position in line
600 + */
601 + public void setLineNumber(int lineNumber) {
602 + this.lineNumber = lineNumber;
603 + }
604 +
605 + /**
606 + * Returns status of resolution.
607 + *
608 + * @return resolution status
609 + */
610 + public boolean isResolved() {
611 + return isResolved;
612 + }
613 +
614 + /**
615 + * Set status of resolution.
616 + *
617 + * @param isResolved resolution status
618 + */
619 + public void setIsResolved(boolean isResolved) {
620 + this.isResolved = isResolved;
621 + }
622 +
623 + /**
624 + * Returns stack of YANG type with partially resolved YANG construct hierarchy.
625 + *
626 + * @return partial resolved YANG construct stack
627 + */
628 + public Stack<T> getPartialResolvedStack() {
629 + return partialResolvedStack;
630 + }
631 +
632 + /**
633 + * Set stack of YANG type with partially resolved YANG construct hierarchy.
634 + *
635 + * @param partialResolvedStack partial resolved YANG construct stack
636 + */
637 + public void setPartialResolvedStack(Stack<T> partialResolvedStack) {
638 + this.partialResolvedStack = partialResolvedStack;
639 + }
640 +}
...@@ -17,12 +17,12 @@ package org.onosproject.yangutils.datamodel; ...@@ -17,12 +17,12 @@ package org.onosproject.yangutils.datamodel;
17 17
18 import java.util.LinkedList; 18 import java.util.LinkedList;
19 import java.util.List; 19 import java.util.List;
20 -
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 20 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22 import org.onosproject.yangutils.parser.Parsable; 21 import org.onosproject.yangutils.parser.Parsable;
23 import org.onosproject.yangutils.utils.YangConstructType; 22 import org.onosproject.yangutils.utils.YangConstructType;
24 23
25 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; 24 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
25 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
26 26
27 /* 27 /*
28 * Reference RFC 6020. 28 * Reference RFC 6020.
...@@ -75,7 +75,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol ...@@ -75,7 +75,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
75 * Data model node to maintain information defined in YANG sub-module. 75 * Data model node to maintain information defined in YANG sub-module.
76 */ 76 */
77 public class YangSubModule extends YangNode 77 public class YangSubModule extends YangNode
78 - implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector { 78 + implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, HasResolutionInfo {
79 79
80 /** 80 /**
81 * Name of sub module. 81 * Name of sub module.
...@@ -124,17 +124,17 @@ public class YangSubModule extends YangNode ...@@ -124,17 +124,17 @@ public class YangSubModule extends YangNode
124 private List<YangLeafList> listOfLeafList; 124 private List<YangLeafList> listOfLeafList;
125 125
126 /** 126 /**
127 - * organization owner of the sub-module. 127 + * Organization owner of the sub-module.
128 */ 128 */
129 private String organization; 129 private String organization;
130 130
131 /** 131 /**
132 - * reference of the sub-module. 132 + * Reference of the sub-module.
133 */ 133 */
134 private String reference; 134 private String reference;
135 135
136 /** 136 /**
137 - * revision info of the sub-module. 137 + * Revision info of the sub-module.
138 */ 138 */
139 private YangRevision revision; 139 private YangRevision revision;
140 140
...@@ -144,10 +144,54 @@ public class YangSubModule extends YangNode ...@@ -144,10 +144,54 @@ public class YangSubModule extends YangNode
144 private byte version; 144 private byte version;
145 145
146 /** 146 /**
147 + * Prefix of parent module.
148 + */
149 + private String prefix;
150 + /*-
151 + * Reference RFC 6020.
152 + *
153 + * Nested typedefs and groupings.
154 + * Typedefs and groupings may appear nested under many YANG statements,
155 + * allowing these to be lexically scoped by the hierarchy under which
156 + * they appear. This allows types and groupings to be defined near
157 + * where they are used, rather than placing them at the top level of the
158 + * hierarchy. The close proximity increases readability.
159 + *
160 + * Scoping also allows types to be defined without concern for naming
161 + * conflicts between types in different submodules. Type names can be
162 + * specified without adding leading strings designed to prevent name
163 + * collisions within large modules.
164 + *
165 + * Finally, scoping allows the module author to keep types and groupings
166 + * private to their module or submodule, preventing their reuse. Since
167 + * only top-level types and groupings (i.e., those appearing as
168 + * sub-statements to a module or submodule statement) can be used outside
169 + * the module or submodule, the developer has more control over what
170 + * pieces of their module are presented to the outside world, supporting
171 + * the need to hide internal information and maintaining a boundary
172 + * between what is shared with the outside world and what is kept
173 + * private.
174 + *
175 + * Scoped definitions MUST NOT shadow definitions at a higher scope. A
176 + * type or grouping cannot be defined if a higher level in the schema
177 + * hierarchy has a definition with a matching identifier.
178 + *
179 + * A reference to an unprefixed type or grouping, or one which uses the
180 + * prefix of the current module, is resolved by locating the closest
181 + * matching "typedef" or "grouping" statement among the immediate
182 + * sub-statements of each ancestor statement.
183 + */
184 + private List<YangResolutionInfo> unresolvedResolutionList;
185 + /**
147 * Create a sub module node. 186 * Create a sub module node.
148 */ 187 */
149 public YangSubModule() { 188 public YangSubModule() {
150 super(YangNodeType.SUB_MODULE_NODE); 189 super(YangNodeType.SUB_MODULE_NODE);
190 + unresolvedResolutionList = new LinkedList<YangResolutionInfo>();
191 + importList = new LinkedList<YangImport>();
192 + includeList = new LinkedList<YangInclude>();
193 + listOfLeaf = new LinkedList<YangLeaf>();
194 + listOfLeafList = new LinkedList<YangLeafList>();
151 } 195 }
152 196
153 /** 197 /**
...@@ -236,28 +280,17 @@ public class YangSubModule extends YangNode ...@@ -236,28 +280,17 @@ public class YangSubModule extends YangNode
236 } 280 }
237 281
238 /** 282 /**
239 - * prevent setting the import list from outside.
240 - *
241 - * @param importList the import list to set
242 - */
243 - private void setImportList(List<YangImport> importList) {
244 - this.importList = importList;
245 - }
246 -
247 - /**
248 * Add the imported module information to the import list. 283 * Add the imported module information to the import list.
249 * 284 *
250 * @param importedModule module being imported 285 * @param importedModule module being imported
251 */ 286 */
252 - public void addImportedInfo(YangImport importedModule) { 287 + public void addToImportList(YangImport importedModule) {
253 -
254 - if (getImportList() == null) {
255 - setImportList(new LinkedList<YangImport>());
256 - }
257 -
258 getImportList().add(importedModule); 288 getImportList().add(importedModule);
289 + }
259 290
260 - return; 291 + @Override
292 + public void setImportList(List<YangImport> importList) {
293 + this.importList = importList;
261 } 294 }
262 295
263 /** 296 /**
...@@ -270,27 +303,35 @@ public class YangSubModule extends YangNode ...@@ -270,27 +303,35 @@ public class YangSubModule extends YangNode
270 } 303 }
271 304
272 /** 305 /**
273 - * Set the list of included sub modules. 306 + * Add the included sub module information to the include list.
274 * 307 *
275 - * @param includeList the included list to set 308 + * @param includeModule submodule being included
276 */ 309 */
277 - private void setIncludeList(List<YangInclude> includeList) { 310 + public void addToIncludeList(YangInclude includeModule) {
311 + getIncludeList().add(includeModule);
312 + }
313 +
314 + @Override
315 + public void setIncludeList(List<YangInclude> includeList) {
278 this.includeList = includeList; 316 this.includeList = includeList;
279 } 317 }
280 318
281 - /** 319 + @Override
282 - * Add the included sub module information to the include list. 320 + public String getPrefix() {
283 - * 321 + return prefix;
284 - * @param includeModule submodule being included 322 + }
285 - */
286 - public void addIncludedInfo(YangInclude includeModule) {
287 323
288 - if (getIncludeList() == null) { 324 + @Override
289 - setIncludeList(new LinkedList<YangInclude>()); 325 + public void setPrefix(String prefix) {
290 - } 326 + this.prefix = prefix;
327 + }
291 328
292 - getIncludeList().add(includeModule); 329 + @Override
293 - return; 330 + public void resolveSelfFileLinking() throws DataModelException {
331 + // Get the list to be resolved.
332 + List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
333 + // Resolve linking for a resolution list.
334 + resolveLinkingForResolutionList(resolutionList, this);
294 } 335 }
295 336
296 /** 337 /**
...@@ -304,25 +345,12 @@ public class YangSubModule extends YangNode ...@@ -304,25 +345,12 @@ public class YangSubModule extends YangNode
304 } 345 }
305 346
306 /** 347 /**
307 - * Set the list of leaves.
308 - *
309 - * @param leafsList the list of leaf to set
310 - */
311 - private void setListOfLeaf(List<YangLeaf> leafsList) {
312 - listOfLeaf = leafsList;
313 - }
314 -
315 - /**
316 * Add a leaf. 348 * Add a leaf.
317 * 349 *
318 * @param leaf the leaf to be added 350 * @param leaf the leaf to be added
319 */ 351 */
320 @Override 352 @Override
321 public void addLeaf(YangLeaf leaf) { 353 public void addLeaf(YangLeaf leaf) {
322 - if (getListOfLeaf() == null) {
323 - setListOfLeaf(new LinkedList<YangLeaf>());
324 - }
325 -
326 getListOfLeaf().add(leaf); 354 getListOfLeaf().add(leaf);
327 } 355 }
328 356
...@@ -337,25 +365,12 @@ public class YangSubModule extends YangNode ...@@ -337,25 +365,12 @@ public class YangSubModule extends YangNode
337 } 365 }
338 366
339 /** 367 /**
340 - * Set the list of leaf-list.
341 - *
342 - * @param listOfLeafList the list of leaf-list to set
343 - */
344 - private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
345 - this.listOfLeafList = listOfLeafList;
346 - }
347 -
348 - /**
349 * Add a leaf-list. 368 * Add a leaf-list.
350 * 369 *
351 * @param leafList the leaf-list to be added 370 * @param leafList the leaf-list to be added
352 */ 371 */
353 @Override 372 @Override
354 public void addLeafList(YangLeafList leafList) { 373 public void addLeafList(YangLeafList leafList) {
355 - if (getListOfLeafList() == null) {
356 - setListOfLeafList(new LinkedList<YangLeafList>());
357 - }
358 -
359 getListOfLeafList().add(leafList); 374 getListOfLeafList().add(leafList);
360 } 375 }
361 376
...@@ -473,4 +488,19 @@ public class YangSubModule extends YangNode ...@@ -473,4 +488,19 @@ public class YangSubModule extends YangNode
473 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { 488 public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
474 // Not required as module doesn't have any parent. 489 // Not required as module doesn't have any parent.
475 } 490 }
491 +
492 + @Override
493 + public List<YangResolutionInfo> getUnresolvedResolutionList() {
494 + return unresolvedResolutionList;
495 + }
496 +
497 + @Override
498 + public void addToResolutionList(YangResolutionInfo resolutionInfo) {
499 + this.unresolvedResolutionList.add(resolutionInfo);
500 + }
501 +
502 + @Override
503 + public void setResolutionList(List<YangResolutionInfo> resolutionList) {
504 + this.unresolvedResolutionList = resolutionList;
505 + }
476 } 506 }
......
...@@ -49,12 +49,12 @@ import org.onosproject.yangutils.utils.YangConstructType; ...@@ -49,12 +49,12 @@ import org.onosproject.yangutils.utils.YangConstructType;
49 * 49 *
50 * @param <T> YANG data type info 50 * @param <T> YANG data type info
51 */ 51 */
52 -public class YangType<T> implements Parsable { 52 +public class YangType<T> implements Parsable, Resolvable {
53 53
54 /** 54 /**
55 - * YANG data type name. 55 + * YANG node identifier.
56 */ 56 */
57 - private String dataTypeName; 57 + private YangNodeIdentifier nodeIdentifier;
58 58
59 /** 59 /**
60 * Java package in which the Java type is defined. 60 * Java package in which the Java type is defined.
...@@ -74,9 +74,50 @@ public class YangType<T> implements Parsable { ...@@ -74,9 +74,50 @@ public class YangType<T> implements Parsable {
74 private T dataTypeExtendedInfo; 74 private T dataTypeExtendedInfo;
75 75
76 /** 76 /**
77 + * Effective built-in type, requried in case type of typedef is again a
78 + * derived type. This information is to be added during linking.
79 + */
80 + private YangDataTypes effectiveBuiltInType;
81 +
82 + /**
83 + * Effective pattern restriction, requried in case type of typedef is again
84 + * a derived type. This information is to be added during linking.
85 + */
86 + private YangPatternRestriction effectivePatternRestriction;
87 +
88 + /**
89 + * Status of resolution. If completely resolved enum value is "RESOLVED",
90 + * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
91 + * is added to uses/type but it's not resolved value of enum should be
92 + * "PARTIALLY_RESOLVED".
93 + */
94 + private ResolvableStatus resolvableStatus;
95 +
96 + /**
77 * Default constructor. 97 * Default constructor.
78 */ 98 */
79 public YangType() { 99 public YangType() {
100 +
101 + nodeIdentifier = new YangNodeIdentifier();
102 + resolvableStatus = ResolvableStatus.UNRESOLVED;
103 + }
104 +
105 + /**
106 + * Returns prefix associated with data type name.
107 + *
108 + * @return prefix associated with data type name
109 + */
110 + public String getPrefix() {
111 + return nodeIdentifier.getPrefix();
112 + }
113 +
114 + /**
115 + * Set prefix associated with data type name.
116 + *
117 + * @param prefix prefix associated with data type name
118 + */
119 + public void setPrefix(String prefix) {
120 + nodeIdentifier.setPrefix(prefix);
80 } 121 }
81 122
82 /** 123 /**
...@@ -85,7 +126,7 @@ public class YangType<T> implements Parsable { ...@@ -85,7 +126,7 @@ public class YangType<T> implements Parsable {
85 * @return the name of data type 126 * @return the name of data type
86 */ 127 */
87 public String getDataTypeName() { 128 public String getDataTypeName() {
88 - return dataTypeName; 129 + return nodeIdentifier.getName();
89 } 130 }
90 131
91 /** 132 /**
...@@ -94,7 +135,7 @@ public class YangType<T> implements Parsable { ...@@ -94,7 +135,7 @@ public class YangType<T> implements Parsable {
94 * @param typeName the name to set 135 * @param typeName the name to set
95 */ 136 */
96 public void setDataTypeName(String typeName) { 137 public void setDataTypeName(String typeName) {
97 - dataTypeName = typeName; 138 + nodeIdentifier.setName(typeName);
98 } 139 }
99 140
100 /** 141 /**
...@@ -152,6 +193,60 @@ public class YangType<T> implements Parsable { ...@@ -152,6 +193,60 @@ public class YangType<T> implements Parsable {
152 } 193 }
153 194
154 /** 195 /**
196 + * Returns node identifier.
197 + *
198 + * @return node identifier
199 + */
200 + public YangNodeIdentifier getNodeIdentifier() {
201 + return nodeIdentifier;
202 + }
203 +
204 + /**
205 + * Set node identifier.
206 + *
207 + * @param nodeIdentifier the node identifier
208 + */
209 + public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
210 + this.nodeIdentifier = nodeIdentifier;
211 + }
212 +
213 + /**
214 + * Return effective built-in type.
215 + *
216 + * @return effective built-in type
217 + */
218 + public YangDataTypes getEffectiveBuiltInType() {
219 + return effectiveBuiltInType;
220 + }
221 +
222 + /**
223 + * Set effective built-in type.
224 + *
225 + * @param effectiveBuiltInType effective built-in type
226 + */
227 + public void setEffectiveBuiltInType(YangDataTypes effectiveBuiltInType) {
228 + this.effectiveBuiltInType = effectiveBuiltInType;
229 + }
230 +
231 + /**
232 + * Returns effective pattern restriction.
233 + *
234 + * @return effective pattern restriction
235 + */
236 + public YangPatternRestriction getEffectivePatternRestriction() {
237 + return effectivePatternRestriction;
238 + }
239 +
240 + /**
241 + * Set effective pattern restriction.
242 + *
243 + * @param effectivePatternRestriction effective pattern restriction
244 + */
245 + public void setEffectivePatternRestriction(YangPatternRestriction effectivePatternRestriction) {
246 + this.effectivePatternRestriction = effectivePatternRestriction;
247 + }
248 +
249 + /**
155 * Returns the type of the parsed data. 250 * Returns the type of the parsed data.
156 * 251 *
157 * @return returns TYPE_DATA 252 * @return returns TYPE_DATA
...@@ -182,4 +277,19 @@ public class YangType<T> implements Parsable { ...@@ -182,4 +277,19 @@ public class YangType<T> implements Parsable {
182 // TODO auto-generated method stub, to be implemented by parser 277 // TODO auto-generated method stub, to be implemented by parser
183 278
184 } 279 }
280 +
281 + @Override
282 + public ResolvableStatus getResolvableStatus() {
283 + return resolvableStatus;
284 + }
285 +
286 + @Override
287 + public void setResolvableStatus(ResolvableStatus resolvableStatus) {
288 + this.resolvableStatus = resolvableStatus;
289 + }
290 +
291 + @Override
292 + public void resolve() {
293 + //TODO: implement the method.
294 + }
185 } 295 }
......
...@@ -75,9 +75,14 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -75,9 +75,14 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
75 private YangStatusType status; 75 private YangStatusType status;
76 76
77 /** 77 /**
78 - * Maintain the derived type information. 78 + * Name of the typedef.
79 */ 79 */
80 - private YangType<YangDerivedType> derivedType; 80 + private String name;
81 +
82 + /**
83 + * Maintain the data type information.
84 + */
85 + private YangType<?> dataType;
81 86
82 /** 87 /**
83 * Units of the data type. 88 * Units of the data type.
...@@ -92,7 +97,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -92,7 +97,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
92 } 97 }
93 98
94 /** 99 /**
95 - * Get the default value. 100 + * Returns the default value.
96 * 101 *
97 * @return the default value 102 * @return the default value
98 */ 103 */
...@@ -110,7 +115,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -110,7 +115,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
110 } 115 }
111 116
112 /** 117 /**
113 - * Get the description. 118 + * Returns the description.
114 * 119 *
115 * @return the description 120 * @return the description
116 */ 121 */
...@@ -130,7 +135,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -130,7 +135,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
130 } 135 }
131 136
132 /** 137 /**
133 - * Get the textual reference. 138 + * Returns the textual reference.
134 * 139 *
135 * @return the reference 140 * @return the reference
136 */ 141 */
...@@ -150,7 +155,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -150,7 +155,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
150 } 155 }
151 156
152 /** 157 /**
153 - * Get the status. 158 + * Returns the status.
154 * 159 *
155 * @return the status 160 * @return the status
156 */ 161 */
...@@ -170,25 +175,25 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -170,25 +175,25 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
170 } 175 }
171 176
172 /** 177 /**
173 - * Get the derived type. 178 + * Returns the data type.
174 * 179 *
175 - * @return the derived type 180 + * @return the data type
176 */ 181 */
177 - public YangType<YangDerivedType> getDerivedType() { 182 + public YangType<?> getDataType() {
178 - return derivedType; 183 + return dataType;
179 } 184 }
180 185
181 /** 186 /**
182 - * Set the derived type. 187 + * Set the data type.
183 * 188 *
184 - * @param derivedType the derived type 189 + * @param dataType the data type
185 */ 190 */
186 - public void setDerivedType(YangType<YangDerivedType> derivedType) { 191 + public void setDataType(YangType<?> dataType) {
187 - this.derivedType = derivedType; 192 + this.dataType = dataType;
188 } 193 }
189 194
190 /** 195 /**
191 - * Get the unit. 196 + * Returns the unit.
192 * 197 *
193 * @return the units 198 * @return the units
194 */ 199 */
...@@ -232,47 +237,17 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -232,47 +237,17 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
232 */ 237 */
233 @Override 238 @Override
234 public void validateDataOnExit() throws DataModelException { 239 public void validateDataOnExit() throws DataModelException {
235 - YangType<YangDerivedType> type = getDerivedType(); 240 + // TODO auto-generated method stub, to be implemented by parser
236 - if (type == null) {
237 - throw new DataModelException("Typedef does not have type info.");
238 - }
239 - if (type.getDataType() != YangDataTypes.DERIVED
240 - || type.getDataTypeName() == null) {
241 - throw new DataModelException("Typedef type is not derived.");
242 - }
243 -
244 - YangDerivedType derivedTypeInfo = type.getDataTypeExtendedInfo();
245 - if (derivedTypeInfo == null) {
246 - throw new DataModelException("derrived type does not have derived info.");
247 - }
248 -
249 - YangType<?> baseType = derivedTypeInfo.getBaseType();
250 - if (baseType == null) {
251 - throw new DataModelException("Base type of a derived type is missing.");
252 - }
253 -
254 - if (derivedTypeInfo.getEffectiveYangBuiltInType() == null) {
255 - /* resolve the effective type from the data tree. */
256 - /*
257 - * TODO: try to resolve the nested reference, if possible in the
258 - * partial tree, otherwise we need to resolve finally when the
259 - * complete module is created.
260 - */
261 - YangModule.addToResolveList(this);
262 - }
263 } 241 }
264 242
265 /** 243 /**
266 - * Get the YANG name of the typedef. 244 + * Returns the YANG name of the typedef.
267 * 245 *
268 * @return YANG name of the typedef 246 * @return YANG name of the typedef
269 */ 247 */
270 @Override 248 @Override
271 public String getName() { 249 public String getName() {
272 - if (getDerivedType() != null) { 250 + return name;
273 - return getDerivedType().getDataTypeName();
274 - }
275 - return null;
276 } 251 }
277 252
278 /** 253 /**
...@@ -282,12 +257,6 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -282,12 +257,6 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
282 */ 257 */
283 @Override 258 @Override
284 public void setName(String name) { 259 public void setName(String name) {
285 - if (getDerivedType() == null) { 260 + this.name = name;
286 - throw new RuntimeException(
287 - "Derrived Type info needs to be set in parser when the typedef listner is processed");
288 - }
289 - getDerivedType().setDataTypeName(name);
290 - getDerivedType().setDataType(YangDataTypes.DERIVED);
291 } 261 }
292 -
293 } 262 }
......
...@@ -52,12 +52,12 @@ import org.onosproject.yangutils.utils.YangConstructType; ...@@ -52,12 +52,12 @@ import org.onosproject.yangutils.utils.YangConstructType;
52 * Data model node to maintain information defined in YANG uses. 52 * Data model node to maintain information defined in YANG uses.
53 * 53 *
54 */ 54 */
55 -public class YangUses extends YangNode implements YangCommonInfo, Parsable { 55 +public class YangUses extends YangNode implements YangCommonInfo, Parsable, Resolvable {
56 56
57 /** 57 /**
58 - * Name of YANG uses. 58 + * YANG node identifier.
59 */ 59 */
60 - private String name; 60 + private YangNodeIdentifier nodeIdentifier;
61 61
62 /** 62 /**
63 * Referred group. 63 * Referred group.
...@@ -80,28 +80,20 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -80,28 +80,20 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
80 private YangStatusType status; 80 private YangStatusType status;
81 81
82 /** 82 /**
83 - * Create an YANG uses node. 83 + * Status of resolution. If completely resolved enum value is "RESOLVED",
84 + * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
85 + * is added to uses/type but it's not resolved value of enum should be
86 + * "PARTIALLY_RESOLVED".
84 */ 87 */
85 - public YangUses() { 88 + private ResolvableStatus resolvableStatus;
86 - super(YangNodeType.USES_NODE);
87 - }
88 89
89 /** 90 /**
90 - * Returns the name. 91 + * Create an YANG uses node.
91 - *
92 - * @return the name
93 - */
94 - public String getRefGroupingName() {
95 - return name;
96 - }
97 -
98 - /**
99 - * Set the name.
100 - *
101 - * @param refGroupingName the referred grouping name to set
102 */ 92 */
103 - public void setRefGroupingName(String refGroupingName) { 93 + public YangUses() {
104 - name = refGroupingName; 94 + super(YangNodeType.USES_NODE);
95 + nodeIdentifier = new YangNodeIdentifier();
96 + resolvableStatus = ResolvableStatus.UNRESOLVED;
105 } 97 }
106 98
107 /** 99 /**
...@@ -214,12 +206,62 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable { ...@@ -214,12 +206,62 @@ public class YangUses extends YangNode implements YangCommonInfo, Parsable {
214 206
215 @Override 207 @Override
216 public String getName() { 208 public String getName() {
217 - return name; 209 + return nodeIdentifier.getName();
218 } 210 }
219 211
220 @Override 212 @Override
221 public void setName(String name) { 213 public void setName(String name) {
222 - this.name = name; 214 + nodeIdentifier.setName(name);
215 + }
216 +
217 + /**
218 + * Returns node identifier.
219 + *
220 + * @return node identifier
221 + */
222 + public YangNodeIdentifier getNodeIdentifier() {
223 + return nodeIdentifier;
223 } 224 }
224 225
226 + /**
227 + * Set node identifier.
228 + *
229 + * @param nodeIdentifier the node identifier
230 + */
231 + public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
232 + this.nodeIdentifier = nodeIdentifier;
233 + }
234 +
235 + /**
236 + * Returns prefix associated with uses.
237 + *
238 + * @return prefix associated with uses
239 + */
240 + public String getPrefix() {
241 + return nodeIdentifier.getPrefix();
242 + }
243 +
244 + /**
245 + * Get prefix associated with uses.
246 + *
247 + * @param prefix prefix associated with uses
248 + */
249 + public void setPrefix(String prefix) {
250 + nodeIdentifier.setPrefix(prefix);
251 + }
252 +
253 + @Override
254 + public void resolve() {
255 + //TODO: implement the method.
256 + }
257 +
258 + @Override
259 + public ResolvableStatus getResolvableStatus() {
260 + return resolvableStatus;
261 + }
262 +
263 + @Override
264 + public void setResolvableStatus(ResolvableStatus resolvableStatus) {
265 + this.resolvableStatus = resolvableStatus;
266 + }
225 } 267 }
......
...@@ -21,6 +21,8 @@ package org.onosproject.yangutils.datamodel.exceptions; ...@@ -21,6 +21,8 @@ package org.onosproject.yangutils.datamodel.exceptions;
21 public class DataModelException extends Exception { 21 public class DataModelException extends Exception {
22 22
23 private static final long serialVersionUID = 201601270658L; 23 private static final long serialVersionUID = 201601270658L;
24 + private int lineNumber;
25 + private int charPositionInLine;
24 26
25 /** 27 /**
26 * Constructor to create a data model exception with message. 28 * Constructor to create a data model exception with message.
...@@ -49,4 +51,40 @@ public class DataModelException extends Exception { ...@@ -49,4 +51,40 @@ public class DataModelException extends Exception {
49 public DataModelException(final Throwable cause) { 51 public DataModelException(final Throwable cause) {
50 super(cause); 52 super(cause);
51 } 53 }
54 +
55 + /**
56 + * Returns line number of the exception.
57 + *
58 + * @return line number of the exception
59 + */
60 + public int getLineNumber() {
61 + return this.lineNumber;
62 + }
63 +
64 + /**
65 + * Returns position of the exception.
66 + *
67 + * @return position of the exception
68 + */
69 + public int getCharPositionInLine() {
70 + return this.charPositionInLine;
71 + }
72 +
73 + /**
74 + * Sets line number of YANG file.
75 + *
76 + * @param line line number of YANG file
77 + */
78 + public void setLine(int line) {
79 + this.lineNumber = line;
80 + }
81 +
82 + /**
83 + * Sets position of exception.
84 + *
85 + * @param charPosition position of exception
86 + */
87 + public void setCharPosition(int charPosition) {
88 + this.charPositionInLine = charPosition;
89 + }
52 } 90 }
......
...@@ -16,11 +16,14 @@ ...@@ -16,11 +16,14 @@
16 16
17 package org.onosproject.yangutils.datamodel.utils; 17 package org.onosproject.yangutils.datamodel.utils;
18 18
19 +import java.util.List;
19 import org.onosproject.yangutils.datamodel.CollisionDetector; 20 import org.onosproject.yangutils.datamodel.CollisionDetector;
21 +import org.onosproject.yangutils.datamodel.HasResolutionInfo;
20 import org.onosproject.yangutils.datamodel.YangLeaf; 22 import org.onosproject.yangutils.datamodel.YangLeaf;
21 import org.onosproject.yangutils.datamodel.YangLeafList; 23 import org.onosproject.yangutils.datamodel.YangLeafList;
22 import org.onosproject.yangutils.datamodel.YangLeavesHolder; 24 import org.onosproject.yangutils.datamodel.YangLeavesHolder;
23 import org.onosproject.yangutils.datamodel.YangNode; 25 import org.onosproject.yangutils.datamodel.YangNode;
26 +import org.onosproject.yangutils.datamodel.YangResolutionInfo;
24 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 27 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
25 import org.onosproject.yangutils.utils.YangConstructType; 28 import org.onosproject.yangutils.utils.YangConstructType;
26 29
...@@ -39,27 +42,23 @@ public final class DataModelUtils { ...@@ -39,27 +42,23 @@ public final class DataModelUtils {
39 * Detects the colliding identifier name in a given YANG node and its child. 42 * Detects the colliding identifier name in a given YANG node and its child.
40 * 43 *
41 * @param identifierName name for which collision detection is to be 44 * @param identifierName name for which collision detection is to be
42 - * checked. 45 + * checked
43 - * @param dataType type of YANG node asking for detecting collision. 46 + * @param dataType type of YANG node asking for detecting collision
44 - * @param node instance of calling node. 47 + * @param node instance of calling node
45 - * @throws DataModelException a violation of data model rules. 48 + * @throws DataModelException a violation of data model rules
46 */ 49 */
47 public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node) 50 public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node)
48 throws DataModelException { 51 throws DataModelException {
49 - if (((YangLeavesHolder) node).getListOfLeaf() != null) { 52 + if (dataType == YangConstructType.LEAF_DATA) {
50 - for (YangLeaf leaf : ((YangLeavesHolder) node).getListOfLeaf()) { 53 + YangLeavesHolder leavesHolder = (YangLeavesHolder) node;
51 - if (leaf.getLeafName().equals(identifierName)) { 54 + if (leavesHolder.getListOfLeaf() != null) {
52 - throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \"" 55 + detectCollidingLeaf(leavesHolder, identifierName);
53 - + leaf.getLeafName() + "\"");
54 - }
55 } 56 }
56 } 57 }
57 - if (((YangLeavesHolder) node).getListOfLeafList() != null) { 58 + if (dataType == YangConstructType.LEAF_LIST_DATA) {
58 - for (YangLeafList leafList : ((YangLeavesHolder) node).getListOfLeafList()) { 59 + if (((YangLeavesHolder) node).getListOfLeafList() != null) {
59 - if (leafList.getLeafName().equals(identifierName)) { 60 + YangLeavesHolder leavesHolder = (YangLeavesHolder) node;
60 - throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " + 61 + detectCollidingLeafList(leavesHolder, identifierName);
61 - "list \"" + leafList.getLeafName() + "\"");
62 - }
63 } 62 }
64 } 63 }
65 node = node.getChild(); 64 node = node.getChild();
...@@ -70,4 +69,78 @@ public final class DataModelUtils { ...@@ -70,4 +69,78 @@ public final class DataModelUtils {
70 node = node.getNextSibling(); 69 node = node.getNextSibling();
71 } 70 }
72 } 71 }
72 +
73 + /**
74 + * Detects the colliding identifier name in a given leaf node.
75 + *
76 + * @param leavesHolder leaves node against which collision to be checked
77 + * @param identifierName name for which collision detection is to be
78 + * checked
79 + * @throws DataModelException a violation of data model rules
80 + */
81 + private static void detectCollidingLeaf(YangLeavesHolder leavesHolder, String identifierName) throws
82 + DataModelException {
83 + for (YangLeaf leaf : leavesHolder.getListOfLeaf()) {
84 + if (leaf.getLeafName().equals(identifierName)) {
85 + throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \""
86 + + leaf.getLeafName() + "\"");
87 + }
88 + }
89 + }
90 +
91 + /**
92 + * Detects the colliding identifier name in a given leaf-list node.
93 + *
94 + * @param leavesHolder leaves node against which collision to be checked
95 + * @param identifierName name for which collision detection is to be
96 + * checked
97 + * @throws DataModelException a violation of data model rules
98 + */
99 + private static void detectCollidingLeafList(YangLeavesHolder leavesHolder, String identifierName) throws
100 + DataModelException {
101 + for (YangLeafList leafList : leavesHolder.getListOfLeafList()) {
102 + if (leafList.getLeafName().equals(identifierName)) {
103 + throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " +
104 + "list \"" + leafList.getLeafName() + "\"");
105 + }
106 + }
107 + }
108 +
109 + /**
110 + * Add a resolution information.
111 + *
112 + * @param resolutionInfo information about the YANG construct which has to
113 + * be resolved
114 + * @throws DataModelException a violation of data model rules
115 + */
116 + public static void addResolutionInfo(YangResolutionInfo resolutionInfo) throws DataModelException {
117 + /* get the module node to add maintain the list of nested reference */
118 + YangNode curNode = resolutionInfo.getHolderOfEntityToResolve();
119 + while (!(curNode instanceof HasResolutionInfo)) {
120 + curNode = curNode.getParent();
121 + if (curNode == null) {
122 + throw new DataModelException("Internal datamodel error: Datamodel tree is not correct");
123 + }
124 + }
125 + HasResolutionInfo resolutionNode = (HasResolutionInfo) curNode;
126 + resolutionNode.addToResolutionList(resolutionInfo);
127 + }
128 +
129 + /**
130 + * Resolve linking for a resolution list.
131 + *
132 + * @param resolutionList resolution list for which linking to be done
133 + * @param resolutionInfoNode module/sub-module node
134 + * @throws DataModelException a violation of data model rules
135 + */
136 + public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList,
137 + HasResolutionInfo resolutionInfoNode)
138 + throws DataModelException {
139 + for (YangResolutionInfo resolutionInfo : resolutionList) {
140 + if (resolutionInfo.getPrefix() == null ||
141 + resolutionInfo.getPrefix().equals(resolutionInfoNode.getPrefix())) {
142 + resolutionInfo.resolveLinkingForResolutionInfo(resolutionInfoNode.getPrefix());
143 + }
144 + }
145 + }
73 } 146 }
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 + * use this file except in compliance with the License. You may obtain a copy of
6 + * 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, WITHOUT
12 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 + * License for the specific language governing permissions and limitations under
14 + * the License.
15 + */
16 +
17 +package org.onosproject.yangutils.linker;
18 +
19 +import java.util.Map;
20 +import org.onosproject.yangutils.datamodel.HasResolutionInfo;
21 +
22 +/**
23 + * Abstraction of entity which provides linking service of YANG files.
24 + */
25 +public interface YangLinker {
26 +
27 + /**
28 + * Resolve the import and include dependencies for a given resolution
29 + * information.
30 + *
31 + * @param fileMapEntry map entry for which resolution is to be done
32 + * @param yangFilesMap map of dependent file and resolution information*/
33 + void resolveDependencies(Map.Entry<String, HasResolutionInfo> fileMapEntry, Map<String,
34 + HasResolutionInfo> yangFilesMap);
35 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Provide inter file and inter jar linking implementation.
19 + */
20 +package org.onosproject.yangutils.linker.impl;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Provide inter jar and inter file linking abstract interface.
19 + */
20 +package org.onosproject.yangutils.linker;
...\ No newline at end of file ...\ No newline at end of file
...@@ -23,13 +23,13 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; ...@@ -23,13 +23,13 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
23 import org.onosproject.yangutils.parser.exceptions.ParserException; 23 import org.onosproject.yangutils.parser.exceptions.ParserException;
24 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 24 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
25 25
26 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
27 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 26 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 27 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
29 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 29 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; 30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
34 import static org.onosproject.yangutils.utils.YangConstructType.BELONGS_TO_DATA; 34 import static org.onosproject.yangutils.utils.YangConstructType.BELONGS_TO_DATA;
35 35
...@@ -119,6 +119,7 @@ public final class BelongsToListener { ...@@ -119,6 +119,7 @@ public final class BelongsToListener {
119 case SUB_MODULE_DATA: { 119 case SUB_MODULE_DATA: {
120 YangSubModule subModule = (YangSubModule) tmpNode; 120 YangSubModule subModule = (YangSubModule) tmpNode;
121 subModule.setBelongsTo((YangBelongsTo) tmpBelongstoNode); 121 subModule.setBelongsTo((YangBelongsTo) tmpBelongstoNode);
122 + subModule.setPrefix(subModule.getBelongsTo().getPrefix());
122 break; 123 break;
123 } 124 }
124 default: 125 default:
......
...@@ -113,12 +113,12 @@ public final class ImportListener { ...@@ -113,12 +113,12 @@ public final class ImportListener {
113 switch (tmpNode.getYangConstructType()) { 113 switch (tmpNode.getYangConstructType()) {
114 case MODULE_DATA: { 114 case MODULE_DATA: {
115 YangModule module = (YangModule) tmpNode; 115 YangModule module = (YangModule) tmpNode;
116 - module.addImportedInfo((YangImport) tmpImportNode); 116 + module.addToImportList((YangImport) tmpImportNode);
117 break; 117 break;
118 } 118 }
119 case SUB_MODULE_DATA: { 119 case SUB_MODULE_DATA: {
120 YangSubModule subModule = (YangSubModule) tmpNode; 120 YangSubModule subModule = (YangSubModule) tmpNode;
121 - subModule.addImportedInfo((YangImport) tmpImportNode); 121 + subModule.addToImportList((YangImport) tmpImportNode);
122 break; 122 break;
123 } 123 }
124 default: 124 default:
......
...@@ -24,13 +24,13 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; ...@@ -24,13 +24,13 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
24 import org.onosproject.yangutils.parser.exceptions.ParserException; 24 import org.onosproject.yangutils.parser.exceptions.ParserException;
25 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 25 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
26 26
27 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 27 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
29 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 29 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
33 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
35 import static org.onosproject.yangutils.utils.YangConstructType.INCLUDE_DATA; 35 import static org.onosproject.yangutils.utils.YangConstructType.INCLUDE_DATA;
36 36
...@@ -112,12 +112,12 @@ public final class IncludeListener { ...@@ -112,12 +112,12 @@ public final class IncludeListener {
112 switch (tmpNode.getYangConstructType()) { 112 switch (tmpNode.getYangConstructType()) {
113 case MODULE_DATA: { 113 case MODULE_DATA: {
114 YangModule module = (YangModule) tmpNode; 114 YangModule module = (YangModule) tmpNode;
115 - module.addIncludedInfo((YangInclude) tmpIncludeNode); 115 + module.addToIncludeList((YangInclude) tmpIncludeNode);
116 break; 116 break;
117 } 117 }
118 case SUB_MODULE_DATA: { 118 case SUB_MODULE_DATA: {
119 YangSubModule subModule = (YangSubModule) tmpNode; 119 YangSubModule subModule = (YangSubModule) tmpNode;
120 - subModule.addIncludedInfo((YangInclude) tmpIncludeNode); 120 + subModule.addToIncludeList((YangInclude) tmpIncludeNode);
121 break; 121 break;
122 } 122 }
123 default: 123 default:
......
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
16 16
17 package org.onosproject.yangutils.parser.impl.listeners; 17 package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 +import org.onosproject.yangutils.datamodel.HasResolutionInfo;
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;
22 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
21 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 23 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
22 import org.onosproject.yangutils.parser.exceptions.ParserException; 24 import org.onosproject.yangutils.parser.exceptions.ParserException;
23 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 25 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
...@@ -113,5 +115,13 @@ public final class ModuleListener { ...@@ -113,5 +115,13 @@ public final class ModuleListener {
113 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA, 115 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA,
114 ctx.identifier().getText(), EXIT)); 116 ctx.identifier().getText(), EXIT));
115 } 117 }
118 + try {
119 + ((HasResolutionInfo) listener.getParsedDataStack().peek()).resolveSelfFileLinking();
120 + } catch (DataModelException e) {
121 + ParserException parserException = new ParserException(e.getMessage());
122 + parserException.setLine(e.getLineNumber());
123 + parserException.setCharPosition(e.getCharPositionInLine());
124 + throw parserException;
125 + }
116 } 126 }
117 } 127 }
......
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
16 16
17 package org.onosproject.yangutils.parser.impl.listeners; 17 package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 +import org.onosproject.yangutils.datamodel.HasResolutionInfo;
19 import org.onosproject.yangutils.datamodel.YangRevision; 20 import org.onosproject.yangutils.datamodel.YangRevision;
20 import org.onosproject.yangutils.datamodel.YangSubModule; 21 import org.onosproject.yangutils.datamodel.YangSubModule;
22 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
21 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 23 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
22 import org.onosproject.yangutils.parser.exceptions.ParserException; 24 import org.onosproject.yangutils.parser.exceptions.ParserException;
23 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 25 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
...@@ -118,5 +120,13 @@ public final class SubModuleListener { ...@@ -118,5 +120,13 @@ public final class SubModuleListener {
118 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA, 120 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA,
119 ctx.identifier().getText(), EXIT)); 121 ctx.identifier().getText(), EXIT));
120 } 122 }
123 + try {
124 + ((HasResolutionInfo) listener.getParsedDataStack().peek()).resolveSelfFileLinking();
125 + } catch (DataModelException e) {
126 + ParserException parserException = new ParserException(e.getMessage());
127 + parserException.setLine(e.getLineNumber());
128 + parserException.setCharPosition(e.getCharPositionInLine());
129 + throw parserException;
130 + }
121 } 131 }
122 } 132 }
......
...@@ -17,18 +17,15 @@ ...@@ -17,18 +17,15 @@
17 package org.onosproject.yangutils.parser.impl.listeners; 17 package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 import org.onosproject.yangutils.datamodel.YangContainer; 19 import org.onosproject.yangutils.datamodel.YangContainer;
20 -import org.onosproject.yangutils.datamodel.YangDataTypes; 20 +import org.onosproject.yangutils.datamodel.YangInput;
21 -import org.onosproject.yangutils.datamodel.YangDerivedType;
22 import org.onosproject.yangutils.datamodel.YangList; 21 import org.onosproject.yangutils.datamodel.YangList;
23 import org.onosproject.yangutils.datamodel.YangModule; 22 import org.onosproject.yangutils.datamodel.YangModule;
24 import org.onosproject.yangutils.datamodel.YangNode; 23 import org.onosproject.yangutils.datamodel.YangNode;
25 -import org.onosproject.yangutils.datamodel.YangSubModule;
26 -import org.onosproject.yangutils.datamodel.YangType;
27 -import org.onosproject.yangutils.datamodel.YangTypeDef;
28 -import org.onosproject.yangutils.datamodel.YangInput;
29 -import org.onosproject.yangutils.datamodel.YangOutput;
30 import org.onosproject.yangutils.datamodel.YangNotification; 24 import org.onosproject.yangutils.datamodel.YangNotification;
25 +import org.onosproject.yangutils.datamodel.YangOutput;
31 import org.onosproject.yangutils.datamodel.YangRpc; 26 import org.onosproject.yangutils.datamodel.YangRpc;
27 +import org.onosproject.yangutils.datamodel.YangSubModule;
28 +import org.onosproject.yangutils.datamodel.YangTypeDef;
32 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 29 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
33 import org.onosproject.yangutils.parser.Parsable; 30 import org.onosproject.yangutils.parser.Parsable;
34 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 31 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
...@@ -123,12 +120,8 @@ public final class TypeDefListener { ...@@ -123,12 +120,8 @@ public final class TypeDefListener {
123 * Create a derived type information, the base type must be set in type 120 * Create a derived type information, the base type must be set in type
124 * listener. 121 * listener.
125 */ 122 */
126 - YangType<YangDerivedType> derivedType = new YangType<YangDerivedType>();
127 - derivedType.setDataType(YangDataTypes.DERIVED);
128 - derivedType.setDataTypeName(identifier);
129 -
130 YangTypeDef typeDefNode = getYangTypeDefNode(JAVA_GENERATION); 123 YangTypeDef typeDefNode = getYangTypeDefNode(JAVA_GENERATION);
131 - typeDefNode.setDerivedType(derivedType); 124 + typeDefNode.setName(identifier);
132 125
133 Parsable curData = listener.getParsedDataStack().peek(); 126 Parsable curData = listener.getParsedDataStack().peek();
134 127
......
...@@ -16,10 +16,14 @@ ...@@ -16,10 +16,14 @@
16 16
17 package org.onosproject.yangutils.parser.impl.listeners; 17 package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 +import org.onosproject.yangutils.datamodel.ResolutionType;
19 import org.onosproject.yangutils.datamodel.YangDataTypes; 20 import org.onosproject.yangutils.datamodel.YangDataTypes;
20 -import org.onosproject.yangutils.datamodel.YangDerivedType; 21 +import org.onosproject.yangutils.datamodel.YangDerivedInfo;
21 import org.onosproject.yangutils.datamodel.YangLeaf; 22 import org.onosproject.yangutils.datamodel.YangLeaf;
22 import org.onosproject.yangutils.datamodel.YangLeafList; 23 import org.onosproject.yangutils.datamodel.YangLeafList;
24 +import org.onosproject.yangutils.datamodel.YangNode;
25 +import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
26 +import org.onosproject.yangutils.datamodel.YangResolutionInfo;
23 import org.onosproject.yangutils.datamodel.YangType; 27 import org.onosproject.yangutils.datamodel.YangType;
24 import org.onosproject.yangutils.datamodel.YangTypeDef; 28 import org.onosproject.yangutils.datamodel.YangTypeDef;
25 import org.onosproject.yangutils.datamodel.YangUnion; 29 import org.onosproject.yangutils.datamodel.YangUnion;
...@@ -28,13 +32,18 @@ import org.onosproject.yangutils.parser.Parsable; ...@@ -28,13 +32,18 @@ import org.onosproject.yangutils.parser.Parsable;
28 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 32 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
29 import org.onosproject.yangutils.parser.exceptions.ParserException; 33 import org.onosproject.yangutils.parser.exceptions.ParserException;
30 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 34 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
35 +import org.onosproject.yangutils.utils.YangConstructType;
31 36
37 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
40 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 41 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
35 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 42 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
36 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; 43 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
37 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 44 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
45 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
46 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 47 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
39 import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA; 48 import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
40 49
...@@ -77,12 +86,19 @@ public final class TypeListener { ...@@ -77,12 +86,19 @@ public final class TypeListener {
77 // Check for stack to be non empty. 86 // Check for stack to be non empty.
78 checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), ENTRY); 87 checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), ENTRY);
79 88
89 + // Validate node identifier.
90 + YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), YangConstructType.TYPE_DATA,
91 + ctx);
92 +
93 + // Obtain the YANG data type.
80 YangDataTypes yangDataTypes = YangDataTypes.getType(ctx.string().getText()); 94 YangDataTypes yangDataTypes = YangDataTypes.getType(ctx.string().getText());
81 - YangType<?> type = new YangType();
82 95
83 - type.setDataTypeName(ctx.string().getText()); 96 + // Create YANG type object and fill the values.
97 + YangType<?> type = new YangType();
98 + type.setNodeIdentifier(nodeIdentifier);
84 type.setDataType(yangDataTypes); 99 type.setDataType(yangDataTypes);
85 100
101 + // Push the type to the stack.
86 listener.getParsedDataStack().push(type); 102 listener.getParsedDataStack().push(type);
87 } 103 }
88 104
...@@ -99,24 +115,91 @@ public final class TypeListener { ...@@ -99,24 +115,91 @@ public final class TypeListener {
99 // Check for stack to be non empty. 115 // Check for stack to be non empty.
100 checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, TYPE_DATA, ctx.string().getText(), EXIT); 116 checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, TYPE_DATA, ctx.string().getText(), EXIT);
101 117
102 - Parsable type = listener.getParsedDataStack().pop(); 118 + Parsable parsableType = listener.getParsedDataStack().pop();
103 - if (!(type instanceof YangType)) { 119 + if (!(parsableType instanceof YangType)) {
104 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA, 120 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
105 ctx.string().getText(), EXIT)); 121 ctx.string().getText(), EXIT));
106 } 122 }
107 123
124 + YangType<?> type = (YangType<?>) parsableType;
125 +
108 // Check for stack to be non empty. 126 // Check for stack to be non empty.
109 checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), EXIT); 127 checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), EXIT);
110 128
129 + YangDataTypes yangDataTypes = YangDataTypes.getType(ctx.string().getText());
130 +
131 + int errorLine = ctx.getStart().getLine();
132 + int errorPosition = ctx.getStart().getCharPositionInLine();
133 +
111 Parsable tmpData = listener.getParsedDataStack().peek(); 134 Parsable tmpData = listener.getParsedDataStack().peek();
112 switch (tmpData.getYangConstructType()) { 135 switch (tmpData.getYangConstructType()) {
113 case LEAF_DATA: 136 case LEAF_DATA:
114 YangLeaf leaf = (YangLeaf) tmpData; 137 YangLeaf leaf = (YangLeaf) tmpData;
115 leaf.setDataType((YangType<?>) type); 138 leaf.setDataType((YangType<?>) type);
139 +
140 + /*
141 + * If data type is derived, resolution information to be added
142 + * in resolution list.
143 + */
144 + if (yangDataTypes == YangDataTypes.DERIVED) {
145 + // Parent YANG node of leaf to be added in resolution information.
146 + Parsable leafData = listener.getParsedDataStack().pop();
147 + Parsable parentNodeOfLeaf = listener.getParsedDataStack().peek();
148 + listener.getParsedDataStack().push(leafData);
149 +
150 + // Verify parent node of leaf
151 + if (!(parentNodeOfLeaf instanceof YangNode)) {
152 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
153 + ctx.string().getText(), EXIT));
154 + }
155 +
156 + // Get the prefix information
157 + String prefix = ((YangType<?>) type).getPrefix();
158 +
159 + // Create empty derived info and attach it to type extended info.
160 + YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
161 + ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
162 +
163 + // Add resolution information to the list
164 + YangResolutionInfo resolutionInfo = new YangResolutionInfo<YangType>(type,
165 + ResolutionType.TYPEDEF_RESOLUTION, (YangNode) parentNodeOfLeaf, prefix, errorLine,
166 + errorPosition);
167 + addToResolutionList(resolutionInfo, ctx);
168 + }
116 break; 169 break;
117 case LEAF_LIST_DATA: 170 case LEAF_LIST_DATA:
118 YangLeafList leafList = (YangLeafList) tmpData; 171 YangLeafList leafList = (YangLeafList) tmpData;
119 leafList.setDataType((YangType<?>) type); 172 leafList.setDataType((YangType<?>) type);
173 +
174 + /*
175 + * If data type is derived, resolution information to be added
176 + * in resolution list.
177 + */
178 + if (yangDataTypes == YangDataTypes.DERIVED) {
179 + // Parent YANG node of leaf to be added in resolution information.
180 + Parsable leafListData = listener.getParsedDataStack().pop();
181 + Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek();
182 + listener.getParsedDataStack().push(leafListData);
183 +
184 + // Verify parent node of leaf
185 + if (!(parentNodeOfLeafList instanceof YangNode)) {
186 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
187 + ctx.string().getText(), EXIT));
188 + }
189 +
190 + // Get the prefix information
191 + String prefix = ((YangType<?>) type).getPrefix();
192 +
193 + // Create empty derived info and attach it to type extended info.
194 + YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
195 + ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
196 +
197 + // Add resolution information to the list
198 + YangResolutionInfo resolutionInfo = new YangResolutionInfo<YangType>(type,
199 + ResolutionType.TYPEDEF_RESOLUTION, (YangNode) parentNodeOfLeafList, prefix, errorLine,
200 + errorPosition);
201 + addToResolutionList(resolutionInfo, ctx);
202 + }
120 break; 203 break;
121 case UNION_DATA: 204 case UNION_DATA:
122 YangUnion unionNode = (YangUnion) tmpData; 205 YangUnion unionNode = (YangUnion) tmpData;
...@@ -130,34 +213,50 @@ public final class TypeListener { ...@@ -130,34 +213,50 @@ public final class TypeListener {
130 } 213 }
131 break; 214 break;
132 case TYPEDEF_DATA: 215 case TYPEDEF_DATA:
133 -
134 /* Prepare the base type info and set in derived type */ 216 /* Prepare the base type info and set in derived type */
135 YangTypeDef typeDef = (YangTypeDef) tmpData; 217 YangTypeDef typeDef = (YangTypeDef) tmpData;
136 - YangType<YangDerivedType> derivedType = typeDef.getDerivedType(); 218 + typeDef.setDataType((YangType<?>) type);
137 - if (derivedType == null) {
138 - //TODO: set the error info correctly, to depict missing info
139 - throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
140 - ctx.string().getText(), ENTRY));
141 - }
142 219
143 - YangDerivedType derivedTypeInfo = new YangDerivedType(); 220 + /*
144 - if (((YangType<?>) type).getDataType() != YangDataTypes.DERIVED) { 221 + * If data type is derived, resolution information to be added
145 - derivedTypeInfo.setEffectiveYangBuiltInType(((YangType<?>) type).getDataType()); 222 + * in resolution list.
146 - } else { 223 + */
147 - /* 224 + if (yangDataTypes == YangDataTypes.DERIVED) {
148 - * It will be resolved in the validate data model at exit. 225 +
149 - * Nothing needs to be done. 226 + // Get the prefix information
150 - */ 227 + String prefix = ((YangType<?>) type).getPrefix();
151 - } 228 +
152 - derivedTypeInfo.setBaseType((YangType<?>) type); 229 + // Create empty derived info and attach it to type extended info.
153 - derivedType.setDataTypeExtendedInfo(derivedTypeInfo); 230 + YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
231 + ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
154 232
233 + // Add resolution information to the list
234 + YangResolutionInfo resolutionInfo = new YangResolutionInfo<YangType>(type,
235 + ResolutionType.TYPEDEF_RESOLUTION, (YangNode) typeDef, prefix, errorLine, errorPosition);
236 + addToResolutionList(resolutionInfo, ctx);
237 + }
155 break; 238 break;
156 - //TODO: union, deviate replacement statement.case TYPEDEF_DATA: //TODO 239 + //TODO: deviate replacement statement.case TYPEDEF_DATA: //TODO
157 240
158 default: 241 default:
159 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA, 242 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
160 ctx.string().getText(), EXIT)); 243 ctx.string().getText(), EXIT));
161 } 244 }
162 } 245 }
246 +
247 + /**
248 + * Add to resolution list.
249 + *
250 + * @param resolutionInfo resolution information.
251 + * @param ctx context object of the grammar rule
252 + */
253 + private static void addToResolutionList(YangResolutionInfo<YangType> resolutionInfo,
254 + GeneratedYangParser.TypeStatementContext ctx) {
255 + try {
256 + addResolutionInfo(resolutionInfo);
257 + } catch (DataModelException e) {
258 + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
259 + TYPE_DATA, ctx.string().getText(), EXIT, e.getMessage()));
260 + }
261 + }
163 } 262 }
......
...@@ -1102,7 +1102,7 @@ public class TempJavaCodeFragmentFiles { ...@@ -1102,7 +1102,7 @@ public class TempJavaCodeFragmentFiles {
1102 public void addTypeDefAttributeToTempFiles(YangNode curNode) throws IOException { 1102 public void addTypeDefAttributeToTempFiles(YangNode curNode) throws IOException {
1103 1103
1104 JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfTypeDef(curNode, 1104 JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfTypeDef(curNode,
1105 - ((YangTypeDef) curNode).getDerivedType().getDataTypeExtendedInfo().getBaseType(), 1105 + ((YangTypeDef) curNode).getDataType(),
1106 ((YangTypeDef) curNode).getName(), false); 1106 ((YangTypeDef) curNode).getName(), false);
1107 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); 1107 addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
1108 } 1108 }
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.linker;
18 +
19 +import java.io.IOException;
20 +import java.util.ListIterator;
21 +import org.junit.Test;
22 +import org.onosproject.yangutils.datamodel.ResolvableStatus;
23 +import org.onosproject.yangutils.datamodel.YangContainer;
24 +import org.onosproject.yangutils.datamodel.YangDataTypes;
25 +import org.onosproject.yangutils.datamodel.YangDerivedInfo;
26 +import org.onosproject.yangutils.datamodel.YangLeaf;
27 +import org.onosproject.yangutils.datamodel.YangList;
28 +import org.onosproject.yangutils.datamodel.YangModule;
29 +import org.onosproject.yangutils.datamodel.YangNode;
30 +import org.onosproject.yangutils.datamodel.YangNodeType;
31 +import org.onosproject.yangutils.datamodel.YangTypeDef;
32 +import org.onosproject.yangutils.parser.exceptions.ParserException;
33 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
34 +
35 +import static org.hamcrest.MatcherAssert.assertThat;
36 +import static org.hamcrest.core.Is.is;
37 +
38 +/**
39 + * Test cases for testing "type" intra file linking.
40 + */
41 +public class IntraFileTypeLinkingTest {
42 +
43 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
44 +
45 + /**
46 + * Checks self resolution when typedef and leaf using type are siblings.
47 + */
48 + @Test
49 + public void processSelfResolutionWhenTypeAndTypedefAtRootLevel() throws IOException, ParserException {
50 +
51 + YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang");
52 +
53 + // Check whether the data model tree returned is of type module.
54 + assertThat((node instanceof YangModule), is(true));
55 +
56 + // Check whether the node type is set properly to module.
57 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
58 +
59 + // Check whether the module name is set correctly.
60 + YangModule yangNode = (YangModule) node;
61 + assertThat(yangNode.getName(), is("Test"));
62 +
63 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
64 + YangLeaf leafInfo = leafIterator.next();
65 +
66 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
67 + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
68 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
69 +
70 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
71 + is((YangTypeDef) node.getChild()));
72 +
73 + assertThat((leafInfo.getDataType().getResolvableStatus()),
74 + is(ResolvableStatus.RESOLVED));
75 + }
76 +
77 + /**
78 + * Checks self resolution when typedef and leaf using type are at different
79 + * level where typedef is at the root.
80 + */
81 + @Test
82 + public void processSelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy() throws IOException, ParserException {
83 +
84 + YangNode node =
85 + manager.getDataModel("src/test/resources/SelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy.yang");
86 +
87 + // Check whether the data model tree returned is of type module.
88 + assertThat((node instanceof YangModule), is(true));
89 +
90 + // Check whether the node type is set properly to module.
91 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
92 +
93 + // Check whether the module name is set correctly.
94 + YangModule yangNode = (YangModule) node;
95 + assertThat(yangNode.getName(), is("Test"));
96 +
97 + YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling();
98 +
99 + YangList yangList = (YangList) yangContainer.getChild();
100 +
101 + ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
102 + YangLeaf leafInfo = leafIterator.next();
103 +
104 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
105 + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
106 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
107 +
108 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
109 + is((YangTypeDef) node.getChild()));
110 +
111 + assertThat((leafInfo.getDataType().getResolvableStatus()),
112 + is(ResolvableStatus.RESOLVED));
113 + }
114 +
115 + /**
116 + * Checks self resolution when typedef and leaf using type are at different
117 + * level where typedef is at the root and defined after parent holder
118 + * of type.
119 + */
120 + @Test
121 + public void processSelfFileLinkingTypedefAtRootIsAfterContainerHavingType() throws IOException, ParserException {
122 +
123 + YangNode node =
124 + manager.getDataModel("src/test/resources/SelfFileLinkingTypedefAtRootIsAfterContainerHavingType.yang");
125 +
126 + // Check whether the data model tree returned is of type module.
127 + assertThat((node instanceof YangModule), is(true));
128 +
129 + // Check whether the node type is set properly to module.
130 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
131 +
132 + // Check whether the module name is set correctly.
133 + YangModule yangNode = (YangModule) node;
134 + assertThat(yangNode.getName(), is("Test"));
135 +
136 + YangContainer yangContainer = (YangContainer) node.getChild();
137 +
138 + YangList yangList = (YangList) yangContainer.getChild();
139 +
140 + ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
141 + YangLeaf leafInfo = leafIterator.next();
142 +
143 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
144 + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
145 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
146 +
147 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
148 + is((YangTypeDef) node.getChild().getNextSibling()));
149 +
150 + assertThat((leafInfo.getDataType().getResolvableStatus()),
151 + is(ResolvableStatus.RESOLVED));
152 + }
153 +
154 + /**
155 + * Checks self resolution when typedef and leaf using type are at different
156 + * level where typedef is at the level of root+1 and defined after parent
157 + * holder of type.
158 + */
159 + @Test
160 + public void processSelfFileLinkingTypedefAtMiddleLevelAfterParentHolder() throws IOException, ParserException {
161 +
162 + YangNode node =
163 + manager.getDataModel("src/test/resources/SelfFileLinkingTypedefAtMiddleLevelAfterParentHolder.yang");
164 +
165 + // Check whether the data model tree returned is of type module.
166 + assertThat((node instanceof YangModule), is(true));
167 +
168 + // Check whether the node type is set properly to module.
169 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
170 +
171 + // Check whether the module name is set correctly.
172 + YangModule yangNode = (YangModule) node;
173 + assertThat(yangNode.getName(), is("Test"));
174 +
175 + YangContainer yangContainer = (YangContainer) node.getChild();
176 +
177 + YangList yangList = (YangList) yangContainer.getChild();
178 +
179 + ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
180 + YangLeaf leafInfo = leafIterator.next();
181 +
182 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
183 + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
184 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
185 +
186 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
187 + is((YangTypeDef) yangContainer.getChild().getNextSibling()));
188 +
189 + assertThat((leafInfo.getDataType().getResolvableStatus()),
190 + is(ResolvableStatus.RESOLVED));
191 + }
192 +
193 + /**
194 + * Checks self resolution when typedef hierarchical references are present.
195 + */
196 + @Test
197 + public void processSelfFileLinkingWithTypdefHierarchicalReference() throws IOException, ParserException {
198 +
199 + YangNode node =
200 + manager.getDataModel("src/test/resources/SelfFileLinkingWithTypdefHierarchicalReference.yang");
201 +
202 + // Check whether the data model tree returned is of type module.
203 + assertThat((node instanceof YangModule), is(true));
204 +
205 + // Check whether the node type is set properly to module.
206 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
207 +
208 + // Check whether the module name is set correctly.
209 + YangModule yangNode = (YangModule) node;
210 + assertThat(yangNode.getName(), is("Test"));
211 +
212 + YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling();
213 +
214 + YangList yangList = (YangList) yangContainer.getChild();
215 +
216 + ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
217 + YangLeaf leafInfo = leafIterator.next();
218 +
219 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
220 + assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
221 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
222 +
223 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
224 + is((YangTypeDef) yangList.getChild()));
225 + assertThat((leafInfo.getDataType().getResolvableStatus()),
226 + is(ResolvableStatus.RESOLVED));
227 +
228 + YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
229 +
230 + assertThat(((YangDerivedInfo<?>) typeDef1.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
231 + is((YangTypeDef) yangContainer.getChild().getNextSibling()));
232 + assertThat((typeDef1.getDataType().getResolvableStatus()),
233 + is(ResolvableStatus.RESOLVED));
234 +
235 + YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
236 +
237 + assertThat(((YangDerivedInfo<?>) typeDef2.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
238 + is((YangTypeDef) node.getChild()));
239 + assertThat((typeDef2.getDataType().getResolvableStatus()),
240 + is(ResolvableStatus.RESOLVED));
241 + }
242 +
243 + /**
244 + * Checks self resolution when typedef hierarchical references are present
245 + * with last type is unresolved.
246 + */
247 + @Test
248 + public void processSelfFileLinkingWithTypdefHierarchicalRefUnresolved() throws IOException, ParserException {
249 +
250 + YangNode node =
251 + manager.getDataModel("src/test/resources/SelfFileLinkingWithTypdefHierarchicalRefUnresolved.yang");
252 +
253 + // Check whether the data model tree returned is of type module.
254 + assertThat((node instanceof YangModule), is(true));
255 +
256 + // Check whether the node type is set properly to module.
257 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
258 +
259 + // Check whether the module name is set correctly.
260 + YangModule yangNode = (YangModule) node;
261 + assertThat(yangNode.getName(), is("Test"));
262 +
263 + YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling();
264 +
265 + YangList yangList = (YangList) yangContainer.getChild();
266 +
267 + ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
268 + YangLeaf leafInfo = leafIterator.next();
269 +
270 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
271 + assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
272 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
273 +
274 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
275 + is((YangTypeDef) yangList.getChild()));
276 + assertThat((leafInfo.getDataType().getResolvableStatus()),
277 + is(ResolvableStatus.PARTIALLY_RESOLVED));
278 +
279 + YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
280 +
281 + assertThat(((YangDerivedInfo<?>) typeDef1.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
282 + is((YangTypeDef) yangContainer.getChild().getNextSibling()));
283 + assertThat((typeDef1.getDataType().getResolvableStatus()),
284 + is(ResolvableStatus.PARTIALLY_RESOLVED));
285 +
286 + YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
287 +
288 + assertThat(((YangDerivedInfo<?>) typeDef2.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
289 + is((YangTypeDef) node.getChild()));
290 + assertThat((typeDef2.getDataType().getResolvableStatus()),
291 + is(ResolvableStatus.PARTIALLY_RESOLVED));
292 + }
293 +
294 + /**
295 + * Checks self resolution when type uses prefix of self module.
296 + */
297 + @Test
298 + public void processSelfFileLinkingWithTypeWithSelfModulePrefix() throws IOException, ParserException {
299 +
300 + YangNode node =
301 + manager.getDataModel("src/test/resources/SelfFileLinkingWithTypeWithSelfModulePrefix.yang");
302 +
303 + // Check whether the data model tree returned is of type module.
304 + assertThat((node instanceof YangModule), is(true));
305 +
306 + // Check whether the node type is set properly to module.
307 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
308 +
309 + // Check whether the module name is set correctly.
310 + YangModule yangNode = (YangModule) node;
311 + assertThat(yangNode.getName(), is("Test"));
312 +
313 + YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling();
314 +
315 + YangList yangList = (YangList) yangContainer.getChild();
316 +
317 + ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
318 + YangLeaf leafInfo = leafIterator.next();
319 +
320 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
321 + assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
322 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
323 +
324 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
325 + is((YangTypeDef) yangList.getChild()));
326 + assertThat((leafInfo.getDataType().getResolvableStatus()),
327 + is(ResolvableStatus.RESOLVED));
328 +
329 + YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
330 +
331 + assertThat(((YangDerivedInfo<?>) typeDef1.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
332 + is((YangTypeDef) yangContainer.getChild().getNextSibling()));
333 + assertThat((typeDef1.getDataType().getResolvableStatus()),
334 + is(ResolvableStatus.RESOLVED));
335 +
336 + YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
337 +
338 + assertThat(((YangDerivedInfo<?>) typeDef2.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
339 + is((YangTypeDef) node.getChild()));
340 + assertThat((typeDef2.getDataType().getResolvableStatus()),
341 + is(ResolvableStatus.RESOLVED));
342 + }
343 +
344 + /**
345 + * Checks self resolution when some type uses prefix of self module
346 + * some uses external prefix.
347 + */
348 + @Test
349 + public void processSelfFileLinkingWithTypeWithSelfAndExternalPrefixMix() throws IOException, ParserException {
350 +
351 + YangNode node =
352 + manager.getDataModel("src/test/resources/SelfFileLinkingWithTypeWithSelfAndExternalPrefixMix.yang");
353 +
354 + // Check whether the data model tree returned is of type module.
355 + assertThat((node instanceof YangModule), is(true));
356 +
357 + // Check whether the node type is set properly to module.
358 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
359 +
360 + // Check whether the module name is set correctly.
361 + YangModule yangNode = (YangModule) node;
362 + assertThat(yangNode.getName(), is("Test"));
363 +
364 + YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling();
365 +
366 + YangList yangList = (YangList) yangContainer.getChild();
367 +
368 + ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
369 + YangLeaf leafInfo = leafIterator.next();
370 +
371 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
372 + assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
373 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
374 +
375 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
376 + is((YangTypeDef) yangList.getChild()));
377 + assertThat((leafInfo.getDataType().getResolvableStatus()),
378 + is(ResolvableStatus.PARTIALLY_RESOLVED));
379 +
380 + YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
381 +
382 + YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
383 +
384 + assertThat(((YangDerivedInfo<?>) typeDef2.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
385 + is((YangTypeDef) node.getChild()));
386 + assertThat((typeDef2.getDataType().getResolvableStatus()),
387 + is(ResolvableStatus.RESOLVED));
388 + }
389 +
390 + /**
391 + * Check self resolution when type referred typedef is not available in
392 + * file.
393 + */
394 + @Test(expected = ParserException.class)
395 + public void processSelfResolutionWhenTypeReferredTypedefNotDefined() throws IOException, ParserException {
396 +
397 + YangNode node =
398 + manager.getDataModel("src/test/resources/SelfResolutionWhenTypeReferredTypedefNotDefined.yang");
399 + }
400 +
401 + /**
402 + * Checks self resolution when typedef and leaf using type are at different
403 + * level where typedef is is not an ancestor of type.
404 + */
405 + @Test(expected = ParserException.class)
406 + public void processSelfFileLinkingTypedefNotFound() throws IOException, ParserException {
407 +
408 + YangNode node = manager.getDataModel("src/test/resources/SelfFileLinkingTypedefNotFound.yang");
409 + }
410 +
411 + /**
412 + * Checks hierarchical self resolution with self resolution failure scenario.
413 + */
414 + @Test(expected = ParserException.class)
415 + public void processSelfFileLinkingWithHierarchicalTypeFailureScenario() throws IOException, ParserException {
416 +
417 + YangNode node =
418 + manager.getDataModel("src/test/resources/SelfFileLinkingWithHierarchicalTypeFailureScenario.yang");
419 + }
420 +}
...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.util.ListIterator; 20 import java.util.ListIterator;
21 -
22 import org.junit.Rule; 21 import org.junit.Rule;
23 import org.junit.Test; 22 import org.junit.Test;
24 import org.junit.rules.ExpectedException; 23 import org.junit.rules.ExpectedException;
...@@ -170,7 +169,7 @@ public class ConfigListenerTest { ...@@ -170,7 +169,7 @@ public class ConfigListenerTest {
170 YangLeaf leafInfo = leafIterator.next(); 169 YangLeaf leafInfo = leafIterator.next();
171 170
172 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 171 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
173 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 172 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
174 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 173 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
175 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 174 assertThat(leafInfo.getUnits(), is("\"seconds\""));
176 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 175 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
...@@ -206,7 +205,7 @@ public class ConfigListenerTest { ...@@ -206,7 +205,7 @@ public class ConfigListenerTest {
206 YangLeaf leafInfo = leafIterator.next(); 205 YangLeaf leafInfo = leafIterator.next();
207 206
208 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 207 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
209 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 208 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
210 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 209 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
211 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 210 assertThat(leafInfo.getUnits(), is("\"seconds\""));
212 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 211 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......
...@@ -193,7 +193,7 @@ public class ContainerListenerTest { ...@@ -193,7 +193,7 @@ public class ContainerListenerTest {
193 YangLeaf leafInfo = leafIterator.next(); 193 YangLeaf leafInfo = leafIterator.next();
194 194
195 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 195 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
196 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 196 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
197 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 197 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
198 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 198 assertThat(leafInfo.getUnits(), is("\"seconds\""));
199 assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT)); 199 assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
......
...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.util.ListIterator; 20 import java.util.ListIterator;
21 -
22 import org.junit.Rule; 21 import org.junit.Rule;
23 import org.junit.Test; 22 import org.junit.Test;
24 import org.junit.rules.ExpectedException; 23 import org.junit.rules.ExpectedException;
...@@ -178,7 +177,7 @@ public class DescriptionListenerTest { ...@@ -178,7 +177,7 @@ public class DescriptionListenerTest {
178 YangLeaf leafInfo = leafIterator.next(); 177 YangLeaf leafInfo = leafIterator.next();
179 178
180 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 179 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
181 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 180 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
182 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 181 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
183 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 182 assertThat(leafInfo.getUnits(), is("\"seconds\""));
184 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 183 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
...@@ -215,7 +214,7 @@ public class DescriptionListenerTest { ...@@ -215,7 +214,7 @@ public class DescriptionListenerTest {
215 YangLeaf leafInfo = leafIterator.next(); 214 YangLeaf leafInfo = leafIterator.next();
216 215
217 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 216 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
218 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 217 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
219 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 218 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
220 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 219 assertThat(leafInfo.getUnits(), is("\"seconds\""));
221 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 220 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......
...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.util.ListIterator; 20 import java.util.ListIterator;
21 -
22 import org.junit.Rule; 21 import org.junit.Rule;
23 import org.junit.Test; 22 import org.junit.Test;
24 import org.junit.rules.ExpectedException; 23 import org.junit.rules.ExpectedException;
...@@ -68,7 +67,7 @@ public class LeafListListenerTest { ...@@ -68,7 +67,7 @@ public class LeafListListenerTest {
68 YangLeafList leafListInfo = leafListIterator.next(); 67 YangLeafList leafListInfo = leafListIterator.next();
69 68
70 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 69 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
71 - assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 70 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16"));
72 assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 71 assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
73 assertThat(leafListInfo.getUnits(), is("\"seconds\"")); 72 assertThat(leafListInfo.getUnits(), is("\"seconds\""));
74 assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 73 assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
...@@ -163,7 +162,7 @@ public class LeafListListenerTest { ...@@ -163,7 +162,7 @@ public class LeafListListenerTest {
163 YangLeafList leafListInfo = leafListIterator.next(); 162 YangLeafList leafListInfo = leafListIterator.next();
164 163
165 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 164 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
166 - assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 165 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16"));
167 assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 166 assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
168 assertThat(leafListInfo.getUnits(), is("\"seconds\"")); 167 assertThat(leafListInfo.getUnits(), is("\"seconds\""));
169 assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 168 assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
...@@ -200,7 +199,7 @@ public class LeafListListenerTest { ...@@ -200,7 +199,7 @@ public class LeafListListenerTest {
200 YangLeafList leafListInfo = leafListIterator.next(); 199 YangLeafList leafListInfo = leafListIterator.next();
201 200
202 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 201 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
203 - assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 202 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16"));
204 assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 203 assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
205 assertThat(leafListInfo.getUnits(), is("\"seconds\"")); 204 assertThat(leafListInfo.getUnits(), is("\"seconds\""));
206 assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 205 assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......
...@@ -68,7 +68,7 @@ public class LeafListenerTest { ...@@ -68,7 +68,7 @@ public class LeafListenerTest {
68 YangLeaf leafInfo = leafIterator.next(); 68 YangLeaf leafInfo = leafIterator.next();
69 69
70 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 70 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
71 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 71 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
72 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 72 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
73 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 73 assertThat(leafInfo.getUnits(), is("\"seconds\""));
74 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 74 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
...@@ -162,7 +162,7 @@ public class LeafListenerTest { ...@@ -162,7 +162,7 @@ public class LeafListenerTest {
162 YangLeaf leafInfo = leafIterator.next(); 162 YangLeaf leafInfo = leafIterator.next();
163 163
164 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 164 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
165 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 165 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
166 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 166 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
167 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 167 assertThat(leafInfo.getUnits(), is("\"seconds\""));
168 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 168 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
...@@ -225,7 +225,7 @@ public class LeafListenerTest { ...@@ -225,7 +225,7 @@ public class LeafListenerTest {
225 YangLeaf leafInfo = leafIterator.next(); 225 YangLeaf leafInfo = leafIterator.next();
226 226
227 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 227 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
228 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 228 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
229 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 229 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
230 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 230 assertThat(leafInfo.getUnits(), is("\"seconds\""));
231 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 231 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......
...@@ -162,7 +162,7 @@ public class ListListenerTest { ...@@ -162,7 +162,7 @@ public class ListListenerTest {
162 YangLeaf leafInfo = leafIterator.next(); 162 YangLeaf leafInfo = leafIterator.next();
163 163
164 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 164 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
165 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 165 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
166 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 166 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
167 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 167 assertThat(leafInfo.getUnits(), is("\"seconds\""));
168 assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT)); 168 assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
......
...@@ -16,21 +16,19 @@ ...@@ -16,21 +16,19 @@
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.util.ListIterator;
19 import org.junit.Test; 21 import org.junit.Test;
20 -import org.onosproject.yangutils.datamodel.YangNode; 22 +import org.onosproject.yangutils.datamodel.YangLeaf;
21 import org.onosproject.yangutils.datamodel.YangModule; 23 import org.onosproject.yangutils.datamodel.YangModule;
24 +import org.onosproject.yangutils.datamodel.YangNode;
25 +import org.onosproject.yangutils.datamodel.YangNodeType;
22 import org.onosproject.yangutils.datamodel.YangNotification; 26 import org.onosproject.yangutils.datamodel.YangNotification;
23 import org.onosproject.yangutils.datamodel.YangStatusType; 27 import org.onosproject.yangutils.datamodel.YangStatusType;
24 -import org.onosproject.yangutils.datamodel.YangNodeType;
25 import org.onosproject.yangutils.datamodel.YangTypeDef; 28 import org.onosproject.yangutils.datamodel.YangTypeDef;
26 -import org.onosproject.yangutils.datamodel.YangLeaf;
27 -import org.onosproject.yangutils.datamodel.YangDataTypes;
28 import org.onosproject.yangutils.parser.exceptions.ParserException; 29 import org.onosproject.yangutils.parser.exceptions.ParserException;
29 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 30 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
30 31
31 -import java.io.IOException;
32 -import java.util.ListIterator;
33 -
34 import static org.hamcrest.core.Is.is; 32 import static org.hamcrest.core.Is.is;
35 import static org.junit.Assert.assertThat; 33 import static org.junit.Assert.assertThat;
36 34
...@@ -63,8 +61,6 @@ public class NotificationListenerTest { ...@@ -63,8 +61,6 @@ public class NotificationListenerTest {
63 YangTypeDef typeDef = (YangTypeDef) yangNotification.getChild(); 61 YangTypeDef typeDef = (YangTypeDef) yangNotification.getChild();
64 assertThat(typeDef.getName(), is("my-type")); 62 assertThat(typeDef.getName(), is("my-type"));
65 assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED)); 63 assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
66 - assertThat(typeDef.getDerivedType().getDataTypeExtendedInfo()
67 - .getBaseType().getDataType(), is(YangDataTypes.INT32));
68 64
69 ListIterator<YangLeaf> leafIterator = yangNotification.getListOfLeaf().listIterator(); 65 ListIterator<YangLeaf> leafIterator = yangNotification.getListOfLeaf().listIterator();
70 YangLeaf leafInfo = leafIterator.next(); 66 YangLeaf leafInfo = leafIterator.next();
......
...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.util.ListIterator; 20 import java.util.ListIterator;
21 -
22 import org.junit.Rule; 21 import org.junit.Rule;
23 import org.junit.Test; 22 import org.junit.Test;
24 import org.junit.rules.ExpectedException; 23 import org.junit.rules.ExpectedException;
...@@ -177,7 +176,7 @@ public class ReferenceListenerTest { ...@@ -177,7 +176,7 @@ public class ReferenceListenerTest {
177 YangLeaf leafInfo = leafIterator.next(); 176 YangLeaf leafInfo = leafIterator.next();
178 177
179 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 178 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
180 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 179 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
181 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 180 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
182 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 181 assertThat(leafInfo.getUnits(), is("\"seconds\""));
183 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 182 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
...@@ -214,7 +213,7 @@ public class ReferenceListenerTest { ...@@ -214,7 +213,7 @@ public class ReferenceListenerTest {
214 YangLeaf leafInfo = leafIterator.next(); 213 YangLeaf leafInfo = leafIterator.next();
215 214
216 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 215 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
217 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 216 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
218 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 217 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
219 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 218 assertThat(leafInfo.getUnits(), is("\"seconds\""));
220 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 219 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......
...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.util.ListIterator; 20 import java.util.ListIterator;
21 -
22 import org.junit.Rule; 21 import org.junit.Rule;
23 import org.junit.Test; 22 import org.junit.Test;
24 import org.junit.rules.ExpectedException; 23 import org.junit.rules.ExpectedException;
...@@ -187,7 +186,7 @@ public class StatusListenerTest { ...@@ -187,7 +186,7 @@ public class StatusListenerTest {
187 YangLeaf leafInfo = leafIterator.next(); 186 YangLeaf leafInfo = leafIterator.next();
188 187
189 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 188 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
190 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 189 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
191 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 190 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
192 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 191 assertThat(leafInfo.getUnits(), is("\"seconds\""));
193 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 192 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
...@@ -224,7 +223,7 @@ public class StatusListenerTest { ...@@ -224,7 +223,7 @@ public class StatusListenerTest {
224 YangLeaf leafInfo = leafIterator.next(); 223 YangLeaf leafInfo = leafIterator.next();
225 224
226 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 225 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
227 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 226 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
228 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 227 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
229 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 228 assertThat(leafInfo.getUnits(), is("\"seconds\""));
230 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 229 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
......
...@@ -2,7 +2,6 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -2,7 +2,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 import java.util.ListIterator; 4 import java.util.ListIterator;
5 -
6 import org.junit.Test; 5 import org.junit.Test;
7 import org.onosproject.yangutils.datamodel.YangDataTypes; 6 import org.onosproject.yangutils.datamodel.YangDataTypes;
8 import org.onosproject.yangutils.datamodel.YangLeaf; 7 import org.onosproject.yangutils.datamodel.YangLeaf;
...@@ -45,7 +44,7 @@ public class TypeListenerTest { ...@@ -45,7 +44,7 @@ public class TypeListenerTest {
45 YangLeaf leafInfo = leafIterator.next(); 44 YangLeaf leafInfo = leafIterator.next();
46 45
47 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 46 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
48 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"hello\"")); 47 + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
49 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED)); 48 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
50 } 49 }
51 50
...@@ -71,7 +70,7 @@ public class TypeListenerTest { ...@@ -71,7 +70,7 @@ public class TypeListenerTest {
71 YangLeaf leafInfo = leafIterator.next(); 70 YangLeaf leafInfo = leafIterator.next();
72 71
73 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 72 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
74 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 73 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
75 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 74 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
76 } 75 }
77 76
...@@ -97,7 +96,7 @@ public class TypeListenerTest { ...@@ -97,7 +96,7 @@ public class TypeListenerTest {
97 YangLeafList leafListInfo = leafListIterator.next(); 96 YangLeafList leafListInfo = leafListIterator.next();
98 97
99 assertThat(leafListInfo.getLeafName(), is("invalid-interval")); 98 assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
100 - assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 99 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16"));
101 assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); 100 assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
102 } 101 }
103 } 102 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.util.ListIterator; 20 import java.util.ListIterator;
21 -
22 import org.junit.Rule; 21 import org.junit.Rule;
23 import org.junit.Test; 22 import org.junit.Test;
24 import org.junit.rules.ExpectedException; 23 import org.junit.rules.ExpectedException;
...@@ -117,7 +116,7 @@ public class UnitsListenerTest { ...@@ -117,7 +116,7 @@ public class UnitsListenerTest {
117 116
118 // Check whether leaf properties is set correctly. 117 // Check whether leaf properties is set correctly.
119 assertThat(leafInfo.getLeafName(), is("invalid-interval")); 118 assertThat(leafInfo.getLeafName(), is("invalid-interval"));
120 - assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); 119 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
121 assertThat(leafInfo.getUnits(), is("\"seconds\"")); 120 assertThat(leafInfo.getUnits(), is("\"seconds\""));
122 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); 121 assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
123 assertThat(leafInfo.isConfig(), is(true)); 122 assertThat(leafInfo.isConfig(), is(true));
......
...@@ -3,6 +3,6 @@ module Test { ...@@ -3,6 +3,6 @@ module Test {
3 namespace http://huawei.com; 3 namespace http://huawei.com;
4 prefix Ant; 4 prefix Ant;
5 leaf invalid-interval { 5 leaf invalid-interval {
6 - type "hello"; 6 + type P:hello;
7 } 7 }
8 -}
...\ No newline at end of file ...\ No newline at end of file
8 +}
......
...@@ -5,17 +5,17 @@ module Test { ...@@ -5,17 +5,17 @@ module Test {
5 list valid { 5 list valid {
6 key address; 6 key address;
7 leaf address { 7 leaf address {
8 - type ip; 8 + type P:ip;
9 } 9 }
10 grouping endpoint { 10 grouping endpoint {
11 description "grouping under test"; 11 description "grouping under test";
12 status current; 12 status current;
13 reference "RFC 6020"; 13 reference "RFC 6020";
14 leaf address { 14 leaf address {
15 - type ip-address; 15 + type P:ip-address;
16 } 16 }
17 leaf port { 17 leaf port {
18 - type port-number; 18 + type P:port-number;
19 } 19 }
20 } 20 }
21 } 21 }
......
...@@ -5,10 +5,10 @@ module Test { ...@@ -5,10 +5,10 @@ module Test {
5 container valid { 5 container valid {
6 grouping endpoint { 6 grouping endpoint {
7 leaf address { 7 leaf address {
8 - type ip-address; 8 + type P:ip-address;
9 } 9 }
10 leaf port { 10 leaf port {
11 - type port-number; 11 + type P:port-number;
12 } 12 }
13 } 13 }
14 } 14 }
......
...@@ -5,14 +5,14 @@ module Test { ...@@ -5,14 +5,14 @@ module Test {
5 list valid { 5 list valid {
6 key address; 6 key address;
7 leaf address { 7 leaf address {
8 - type ip; 8 + type P:ip;
9 } 9 }
10 grouping endpoint { 10 grouping endpoint {
11 leaf address { 11 leaf address {
12 - type ip-address; 12 + type P:ip-address;
13 } 13 }
14 leaf port { 14 leaf port {
15 - type port-number; 15 + type P:port-number;
16 } 16 }
17 } 17 }
18 } 18 }
......
...@@ -4,10 +4,10 @@ module Test { ...@@ -4,10 +4,10 @@ module Test {
4 prefix Ant; 4 prefix Ant;
5 grouping endpoint { 5 grouping endpoint {
6 leaf address { 6 leaf address {
7 - type ip-address; 7 + type P:ip-address;
8 } 8 }
9 leaf port { 9 leaf port {
10 - type port-number; 10 + type P:port-number;
11 } 11 }
12 } 12 }
13 } 13 }
......
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container ospf {
6 + list valid {
7 + key "invalid-interval";
8 + leaf invalid-interval {
9 + type hello;
10 + }
11 + }
12 + typedef hello {
13 + type String;
14 + }
15 + }
16 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container ospf {
6 + list valid {
7 + key "invalid-interval";
8 + leaf invalid-interval {
9 + type hello;
10 + }
11 + }
12 + }
13 + typedef hello {
14 + type String;
15 + }
16 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + typedef hello {
6 + type String;
7 + }
8 + container ospf {
9 + list valid {
10 + key "invalid-interval";
11 + leaf invalid-interval {
12 + type hello;
13 + }
14 + }
15 + }
16 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container ospf {
6 + list valid {
7 + key "invalid-interval";
8 + leaf invalid-interval {
9 + type hello;
10 + }
11 + }
12 + }
13 + container isis {
14 + typedef hello {
15 + type String;
16 + }
17 + }
18 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + typedef Percentage {
6 + type INT;
7 + }
8 + container ospf {
9 + list valid {
10 + key "invalid-interval";
11 + leaf invalid-interval {
12 + type Ant:FirstClass;
13 + }
14 + typedef FirstClass {
15 + type Ant:PassingClass;
16 + }
17 + }
18 + typedef PassingClass {
19 + type Percentage;
20 + }
21 + }
22 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + typedef Percentage {
6 + type P:Per;
7 + }
8 + container ospf {
9 + list valid {
10 + key "invalid-interval";
11 + leaf invalid-interval {
12 + type FirstClass;
13 + }
14 + typedef FirstClass {
15 + type PassingClass;
16 + }
17 + }
18 + typedef PassingClass {
19 + type Percentage;
20 + }
21 + }
22 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + typedef Percentage {
6 + type int32;
7 + }
8 + container ospf {
9 + list valid {
10 + key "invalid-interval";
11 + leaf invalid-interval {
12 + type FirstClass;
13 + }
14 + typedef FirstClass {
15 + type PassingClass;
16 + }
17 + }
18 + typedef PassingClass {
19 + type Percentage;
20 + }
21 + }
22 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + typedef Percentage {
6 + type int32;
7 + }
8 + container ospf {
9 + list valid {
10 + key "invalid-interval";
11 + leaf invalid-interval {
12 + type Ant:FirstClass;
13 + }
14 + typedef FirstClass {
15 + type P:PassingClass;
16 + }
17 + }
18 + typedef PassingClass {
19 + type Ant:Percentage;
20 + }
21 + }
22 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + typedef Percentage {
6 + type int32;
7 + }
8 + container ospf {
9 + list valid {
10 + key "invalid-interval";
11 + leaf invalid-interval {
12 + type Ant:FirstClass;
13 + }
14 + typedef FirstClass {
15 + type PassingClass;
16 + }
17 + }
18 + typedef PassingClass {
19 + type Ant:Percentage;
20 + }
21 + }
22 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type hello;
7 + }
8 + typedef hello {
9 + type String;
10 + }
11 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type hello;
7 + }
8 + typedef hi {
9 + type String;
10 + }
11 +}
...@@ -5,7 +5,7 @@ module Test { ...@@ -5,7 +5,7 @@ module Test {
5 list valid { 5 list valid {
6 key address; 6 key address;
7 leaf address { 7 leaf address {
8 - type ip; 8 + type P:ip;
9 } 9 }
10 uses endpoint { 10 uses endpoint {
11 description "grouping under test"; 11 description "grouping under test";
......
...@@ -16,10 +16,10 @@ module rock { ...@@ -16,10 +16,10 @@ module rock {
16 } 16 }
17 } 17 }
18 leaf if-admin-status { 18 leaf if-admin-status {
19 - type admin-status; 19 + type P:admin-status;
20 } 20 }
21 leaf if-oper-status { 21 leaf if-oper-status {
22 - type oper-status; 22 + type P:oper-status;
23 } 23 }
24 } 24 }
25 } 25 }
......
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + typedef hello {
6 + type String;
7 + }
8 + leaf invalid-interval {
9 + type hello;
10 + }
11 +}