Gaurav Agrawal
Committed by Gerrit Code Review

[ONOS-4350] Inter file linking implementation and inter-jar linking framework

Change-Id: I71a26ba3e0b9d17261e78a9313fe7f047195932e
Showing 63 changed files with 2555 additions and 322 deletions
1 -/*
2 - * Copyright 2016-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -package org.onosproject.yangutils.datamodel;
18 -
19 -/**
20 - * Represents 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 -}
...@@ -15,10 +15,14 @@ ...@@ -15,10 +15,14 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 +import java.util.Set;
18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 19 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 import org.onosproject.yangutils.parser.Parsable; 20 import org.onosproject.yangutils.parser.Parsable;
21 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
20 import org.onosproject.yangutils.utils.YangConstructType; 22 import org.onosproject.yangutils.utils.YangConstructType;
21 23
24 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
25 +
22 /*- 26 /*-
23 * Reference 6020. 27 * Reference 6020.
24 * 28 *
...@@ -46,7 +50,7 @@ import org.onosproject.yangutils.utils.YangConstructType; ...@@ -46,7 +50,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
46 /** 50 /**
47 * Represents the belongs-to data type information. 51 * Represents the belongs-to data type information.
48 */ 52 */
49 -public class YangBelongsTo implements Parsable { 53 +public class YangBelongsTo implements Parsable, LocationInfo {
50 54
51 /** 55 /**
52 * Reference RFC 6020. 56 * Reference RFC 6020.
...@@ -70,6 +74,12 @@ public class YangBelongsTo implements Parsable { ...@@ -70,6 +74,12 @@ public class YangBelongsTo implements Parsable {
70 */ 74 */
71 private String prefix; 75 private String prefix;
72 76
77 + // Error Line number.
78 + private int lineNumber;
79 +
80 + // Error character position.
81 + private int charPosition;
82 +
73 /** 83 /**
74 * Create a belongs to object. 84 * Create a belongs to object.
75 */ 85 */
...@@ -90,7 +100,6 @@ public class YangBelongsTo implements Parsable { ...@@ -90,7 +100,6 @@ public class YangBelongsTo implements Parsable {
90 * Sets the belongs to module name. 100 * Sets the belongs to module name.
91 * 101 *
92 * @param belongsToModuleName the belongs to module name to set 102 * @param belongsToModuleName the belongs to module name to set
93 - *
94 */ 103 */
95 public void setBelongsToModuleName(String belongsToModuleName) { 104 public void setBelongsToModuleName(String belongsToModuleName) {
96 this.belongsToModuleName = belongsToModuleName; 105 this.belongsToModuleName = belongsToModuleName;
...@@ -161,4 +170,47 @@ public class YangBelongsTo implements Parsable { ...@@ -161,4 +170,47 @@ public class YangBelongsTo implements Parsable {
161 public void validateDataOnExit() throws DataModelException { 170 public void validateDataOnExit() throws DataModelException {
162 // TODO auto-generated method stub, to be implemented by parser 171 // TODO auto-generated method stub, to be implemented by parser
163 } 172 }
173 +
174 + @Override
175 + public int getLineNumber() {
176 + return lineNumber;
177 + }
178 +
179 + @Override
180 + public int getCharPosition() {
181 + return charPosition;
182 + }
183 +
184 + @Override
185 + public void setLineNumber(int lineNumber) {
186 + this.lineNumber = lineNumber;
187 + }
188 +
189 + @Override
190 + public void setCharPosition(int charPositionInLine) {
191 + this.charPosition = charPositionInLine;
192 + }
193 +
194 + /**
195 + * Links the belongs to with a module.
196 + *
197 + * @param yangFileInfoSet YANG file information set
198 + * @throws DataModelException a violation in data model rule
199 + */
200 + public void linkWithModule(Set<YangFileInfo> yangFileInfoSet)
201 + throws DataModelException {
202 + String belongsToModuleName = getBelongsToModuleName();
203 + YangNode moduleNode = findReferredNode(yangFileInfoSet, belongsToModuleName);
204 + if (moduleNode != null) {
205 + if (moduleNode instanceof YangModule) {
206 + setModuleNode(moduleNode);
207 + return;
208 + }
209 + }
210 + DataModelException exception = new DataModelException("YANG file error : Module " + belongsToModuleName +
211 + "to which sub-module belongs to is not found.");
212 + exception.setLine(getLineNumber());
213 + exception.setCharPosition(getCharPosition());
214 + throw exception;
215 + }
164 } 216 }
......
...@@ -17,10 +17,10 @@ ...@@ -17,10 +17,10 @@
17 package org.onosproject.yangutils.datamodel; 17 package org.onosproject.yangutils.datamodel;
18 18
19 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 19 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20 +import org.onosproject.yangutils.linker.impl.ResolvableStatus;
20 import com.google.common.base.Strings; 21 import com.google.common.base.Strings;
21 22
22 -import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED; 23 +import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
23 -import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED;
24 import static org.onosproject.yangutils.datamodel.YangDataTypes.BITS; 24 import static org.onosproject.yangutils.datamodel.YangDataTypes.BITS;
25 import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN; 25 import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN;
26 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; 26 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
...@@ -30,6 +30,8 @@ import static org.onosproject.yangutils.datamodel.YangDataTypes.IDENTITYREF; ...@@ -30,6 +30,8 @@ import static org.onosproject.yangutils.datamodel.YangDataTypes.IDENTITYREF;
30 import static org.onosproject.yangutils.datamodel.YangDataTypes.LEAFREF; 30 import static org.onosproject.yangutils.datamodel.YangDataTypes.LEAFREF;
31 import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; 31 import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
32 import static org.onosproject.yangutils.datamodel.YangDataTypes.UNION; 32 import static org.onosproject.yangutils.datamodel.YangDataTypes.UNION;
33 +import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_RESOLVED;
34 +import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
33 import static org.onosproject.yangutils.utils.RestrictionResolver.isOfRangeRestrictedType; 35 import static org.onosproject.yangutils.utils.RestrictionResolver.isOfRangeRestrictedType;
34 import static org.onosproject.yangutils.utils.RestrictionResolver.processLengthRestriction; 36 import static org.onosproject.yangutils.utils.RestrictionResolver.processLengthRestriction;
35 import static org.onosproject.yangutils.utils.RestrictionResolver.processRangeRestriction; 37 import static org.onosproject.yangutils.utils.RestrictionResolver.processRangeRestriction;
...@@ -236,7 +238,7 @@ public class YangDerivedInfo<T> implements LocationInfo { ...@@ -236,7 +238,7 @@ public class YangDerivedInfo<T> implements LocationInfo {
236 * Check whether the referred typedef is resolved. 238 * Check whether the referred typedef is resolved.
237 */ 239 */
238 if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) { 240 if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) {
239 - throw new DataModelException("Linker Error: Referred typedef is not resolved."); 241 + throw new DataModelException("Linker Error: Referred typedef is not resolved for type.");
240 } 242 }
241 243
242 /* 244 /*
...@@ -301,6 +303,28 @@ public class YangDerivedInfo<T> implements LocationInfo { ...@@ -301,6 +303,28 @@ public class YangDerivedInfo<T> implements LocationInfo {
301 */ 303 */
302 return RESOLVED; 304 return RESOLVED;
303 } 305 }
306 + } else if (getEffectiveBuiltInType() == BINARY) {
307 + if (refDerivedInfo.getResolvedExtendedInfo() == null) {
308 + resolveLengthRestriction(null);
309 + /*
310 + * Return the resolution status as resolved, if it's not
311 + * resolve length restriction will throw exception
312 + * in previous function.
313 + */
314 + return RESOLVED;
315 + } else {
316 + if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
317 + throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
318 + "type.");
319 + }
320 + resolveLengthRestriction((YangRangeRestriction) refDerivedInfo.getResolvedExtendedInfo());
321 + /*
322 + * Return the resolution status as resolved, if it's not
323 + * resolve length restriction will throw exception
324 + * in previous function.
325 + */
326 + return RESOLVED;
327 + }
304 } 328 }
305 } else { 329 } else {
306 setEffectiveBuiltInType((baseType.getDataType())); 330 setEffectiveBuiltInType((baseType.getDataType()));
...@@ -356,6 +380,28 @@ public class YangDerivedInfo<T> implements LocationInfo { ...@@ -356,6 +380,28 @@ public class YangDerivedInfo<T> implements LocationInfo {
356 */ 380 */
357 return RESOLVED; 381 return RESOLVED;
358 } 382 }
383 + } else if (getEffectiveBuiltInType() == BINARY) {
384 + if (baseType.getDataTypeExtendedInfo() == null) {
385 + resolveLengthRestriction(null);
386 + /*
387 + * Return the resolution status as resolved, if it's not
388 + * resolve length restriction will throw exception
389 + * in previous function.
390 + */
391 + return RESOLVED;
392 + } else {
393 + if (!(baseType.getDataTypeExtendedInfo() instanceof YangRangeRestriction)) {
394 + throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
395 + "type.");
396 + }
397 + resolveLengthRestriction((YangRangeRestriction) baseType.getDataTypeExtendedInfo());
398 + /*
399 + * Return the resolution status as resolved, if it's not
400 + * resolve length restriction will throw exception
401 + * in previous function.
402 + */
403 + return RESOLVED;
404 + }
359 } 405 }
360 } 406 }
361 407
......
...@@ -15,10 +15,14 @@ ...@@ -15,10 +15,14 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 +import java.util.Set;
18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 19 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 import org.onosproject.yangutils.parser.Parsable; 20 import org.onosproject.yangutils.parser.Parsable;
21 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
20 import org.onosproject.yangutils.utils.YangConstructType; 22 import org.onosproject.yangutils.utils.YangConstructType;
21 23
24 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
25 +
22 /* 26 /*
23 * Reference:RFC 6020. 27 * Reference:RFC 6020.
24 * The "import" statement makes definitions from one module available 28 * The "import" statement makes definitions from one module available
...@@ -64,7 +68,7 @@ import org.onosproject.yangutils.utils.YangConstructType; ...@@ -64,7 +68,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
64 * Represents the information about the imported modules. 68 * Represents the information about the imported modules.
65 */ 69 */
66 public class YangImport 70 public class YangImport
67 - implements Parsable { 71 + implements Parsable, LocationInfo {
68 72
69 /** 73 /**
70 * Name of the module that is being imported. 74 * Name of the module that is being imported.
...@@ -78,7 +82,7 @@ public class YangImport ...@@ -78,7 +82,7 @@ public class YangImport
78 82
79 /** 83 /**
80 * Reference:RFC 6020. 84 * Reference:RFC 6020.
81 - * 85 + * <p>
82 * The import's "revision-date" statement is used to specify the exact 86 * The import's "revision-date" statement is used to specify the exact
83 * version of the module to import. The "revision-date" statement MUST match 87 * version of the module to import. The "revision-date" statement MUST match
84 * the most recent "revision" statement in the imported module. organization 88 * the most recent "revision" statement in the imported module. organization
...@@ -87,10 +91,20 @@ public class YangImport ...@@ -87,10 +91,20 @@ public class YangImport
87 private String revision; 91 private String revision;
88 92
89 /** 93 /**
94 + * Reference to node which is imported.
95 + */
96 + private YangNode importedNode;
97 +
98 + // Error Line number.
99 + private int lineNumber;
100 +
101 + // Error character position.
102 + private int charPosition;
103 +
104 + /**
90 * Creates a YANG import. 105 * Creates a YANG import.
91 */ 106 */
92 public YangImport() { 107 public YangImport() {
93 -
94 } 108 }
95 109
96 /** 110 /**
...@@ -181,4 +195,91 @@ public class YangImport ...@@ -181,4 +195,91 @@ public class YangImport
181 // TODO auto-generated method stub, to be implemented by parser 195 // TODO auto-generated method stub, to be implemented by parser
182 196
183 } 197 }
198 +
199 + /**
200 + * Returns imported node.
201 + *
202 + * @return imported node
203 + */
204 + public YangNode getImportedNode() {
205 + return importedNode;
206 + }
207 +
208 + /**
209 + * Sets imported node.
210 + *
211 + * @param importedNode imported node
212 + */
213 + public void setImportedNode(YangNode importedNode) {
214 + this.importedNode = importedNode;
215 + }
216 +
217 + @Override
218 + public int getLineNumber() {
219 + return lineNumber;
220 + }
221 +
222 + @Override
223 + public int getCharPosition() {
224 + return charPosition;
225 + }
226 +
227 + @Override
228 + public void setLineNumber(int lineNumber) {
229 + this.lineNumber = lineNumber;
230 + }
231 +
232 + @Override
233 + public void setCharPosition(int charPositionInLine) {
234 + this.charPosition = charPositionInLine;
235 + }
236 +
237 + /**
238 + * Adds reference to an import.
239 + *
240 + * @param yangFileInfoSet YANG file info set
241 + * @throws DataModelException a violation of data model rules
242 + */
243 + public void addReferenceToImport(Set<YangFileInfo> yangFileInfoSet) throws DataModelException {
244 + String importedModuleName = getModuleName();
245 + String importedModuleRevision = getRevision();
246 + YangNode moduleNode = null;
247 + /*
248 + * Find the imported module node for a given module name
249 + * with a specified revision if revision is not null.
250 + */
251 + if (importedModuleRevision != null) {
252 + String importedModuleNameWithRevision = importedModuleName + "@" + importedModuleRevision;
253 + moduleNode = findReferredNode(yangFileInfoSet, importedModuleNameWithRevision);
254 + }
255 +
256 + /*
257 + * Find the imported module node for a given module name
258 + * without revision if can't find with revision.
259 + */
260 + if (moduleNode == null) {
261 + moduleNode = findReferredNode(yangFileInfoSet, importedModuleName);
262 + }
263 +
264 + if (moduleNode != null) {
265 + if (moduleNode instanceof YangModule) {
266 + if (getRevision() == null || getRevision().isEmpty()) {
267 + setImportedNode(moduleNode);
268 + return;
269 + }
270 + // Match revision if import is with revision.
271 + if (((YangModule) moduleNode).getRevision().getRevDate().equals(importedModuleRevision)) {
272 + setImportedNode(moduleNode);
273 + return;
274 + }
275 + }
276 + }
277 +
278 + // Exception if there is no match.
279 + DataModelException exception = new DataModelException("YANG file error : Imported module "
280 + + importedModuleName + " with revision " + importedModuleRevision + " is not found.");
281 + exception.setLine(getLineNumber());
282 + exception.setCharPosition(getCharPosition());
283 + throw exception;
284 + }
184 } 285 }
......
...@@ -15,10 +15,14 @@ ...@@ -15,10 +15,14 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 +import java.util.Set;
18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 19 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 import org.onosproject.yangutils.parser.Parsable; 20 import org.onosproject.yangutils.parser.Parsable;
21 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
20 import org.onosproject.yangutils.utils.YangConstructType; 22 import org.onosproject.yangutils.utils.YangConstructType;
21 23
24 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
25 +
22 /* 26 /*
23 * Reference:RFC 6020. 27 * Reference:RFC 6020.
24 * The "include" statement is used to make content from a submodule 28 * The "include" statement is used to make content from a submodule
...@@ -38,7 +42,7 @@ import org.onosproject.yangutils.utils.YangConstructType; ...@@ -38,7 +42,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
38 * Represents the information about the included sub-modules. 42 * Represents the information about the included sub-modules.
39 */ 43 */
40 public class YangInclude 44 public class YangInclude
41 - implements Parsable { 45 + implements Parsable, LocationInfo {
42 46
43 /** 47 /**
44 * Name of the sub-module that is being included. 48 * Name of the sub-module that is being included.
...@@ -52,6 +56,17 @@ public class YangInclude ...@@ -52,6 +56,17 @@ public class YangInclude
52 private String revision; 56 private String revision;
53 57
54 /** 58 /**
59 + * Reference to node which is included.
60 + */
61 + private YangNode includedNode;
62 +
63 + // Error Line number.
64 + private int lineNumber;
65 +
66 + // Error character position.
67 + private int charPosition;
68 +
69 + /**
55 * Creates a YANG include. 70 * Creates a YANG include.
56 */ 71 */
57 public YangInclude() { 72 public YangInclude() {
...@@ -127,4 +142,98 @@ public class YangInclude ...@@ -127,4 +142,98 @@ public class YangInclude
127 142
128 } 143 }
129 144
145 + public YangNode getIncludedNode() {
146 + return includedNode;
147 + }
148 +
149 + public void setIncludedNode(YangNode includedNode) {
150 + this.includedNode = includedNode;
151 + }
152 +
153 + @Override
154 + public int getLineNumber() {
155 + return lineNumber;
156 + }
157 +
158 + @Override
159 + public int getCharPosition() {
160 + return charPosition;
161 + }
162 +
163 + @Override
164 + public void setLineNumber(int lineNumber) {
165 + this.lineNumber = lineNumber;
166 + }
167 +
168 + @Override
169 + public void setCharPosition(int charPositionInLine) {
170 + this.charPosition = charPositionInLine;
171 + }
172 +
173 + /**
174 + * Adds reference to an include.
175 + *
176 + * @param yangFileInfoSet YANG file info set
177 + * @return YANG sub module node
178 + * @throws DataModelException a violation of data model rules
179 + */
180 + public YangSubModule addReferenceToInclude(Set<YangFileInfo> yangFileInfoSet) throws DataModelException {
181 + String includedSubModuleName = getSubModuleName();
182 + String includedSubModuleRevision = getRevision();
183 + YangNode subModuleNode = null;
184 +
185 + /*
186 + * Find the included sub-module node for a given module name
187 + * with a specified revision if revision is not null.
188 + */
189 + if (includedSubModuleRevision != null) {
190 + String includedSubModuleNameWithRevision = includedSubModuleName + "@" + includedSubModuleRevision;
191 + subModuleNode = findReferredNode(yangFileInfoSet, includedSubModuleNameWithRevision);
192 + }
193 +
194 + /*
195 + * Find the imported sub module node for a given module name
196 + * without revision if can't find with revision.
197 + */
198 + if (subModuleNode == null) {
199 + subModuleNode = findReferredNode(yangFileInfoSet, includedSubModuleName);
200 + }
201 +
202 + if (subModuleNode != null) {
203 + if (subModuleNode instanceof YangSubModule) {
204 + if (getRevision() == null || getRevision().isEmpty()) {
205 + setIncludedNode(subModuleNode);
206 + return (YangSubModule) subModuleNode;
207 + }
208 + // Match revision if inclusion is with revision.
209 + if (((YangSubModule) subModuleNode).getRevision().getRevDate().equals(includedSubModuleRevision)) {
210 + setIncludedNode(subModuleNode);
211 + return (YangSubModule) subModuleNode;
212 + }
213 + }
214 + }
215 + // Exception if there is no match.
216 + DataModelException exception = new DataModelException("YANG file error : Included sub module " +
217 + includedSubModuleName + "with a given revision is not found.");
218 + exception.setLine(getLineNumber());
219 + exception.setCharPosition(getCharPosition());
220 + throw exception;
221 + }
222 +
223 + /**
224 + * Reports an error when included sub-module doesn't meet condition that
225 + * "included sub-modules should belong module, as defined by the
226 + * "belongs-to" statement or sub-modules are only allowed to include other
227 + * sub-modules belonging to the same module.
228 + *
229 + * @throws DataModelException a violation in data model rule
230 + */
231 + public void reportIncludeError() throws DataModelException {
232 + DataModelException exception = new DataModelException("YANG file error : Included sub-module " +
233 + getSubModuleName() + "doesn't belongs to parent module also it doesn't belongs" +
234 + "to sub-module belonging to the same parent module.");
235 + exception.setLine(getLineNumber());
236 + exception.setCharPosition(getCharPosition());
237 + throw exception;
238 + }
130 } 239 }
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.datamodel;
18 +
19 +/*-
20 + * Reference RFC 6020.
21 + *
22 + * Binary can be restricted with "length" statements alone.
23 + *
24 + */
25 +
26 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
27 +import org.onosproject.yangutils.parser.Parsable;
28 +import org.onosproject.yangutils.utils.YangConstructType;
29 +import org.onosproject.yangutils.utils.builtindatatype.YangUint64;
30 +
31 +/**
32 + * Represents the restriction for length data type.
33 + */
34 +public class YangLengthRestriction implements YangDesc, YangReference, YangAppErrorInfo, Parsable {
35 +
36 + /*-
37 + * Reference RFC 6020.
38 + * The length Statement
39 + *
40 + * The "length" statement, which is an optional sub-statement to the
41 + * "type" statement, takes as an argument a length expression string.
42 + * It is used to restrict the built-in type "string", or types derived
43 + * from "string".
44 + * A "length" statement restricts the number of unicode characters in
45 + * the string.
46 + * A length range consists of an explicit value, or a lower bound, two
47 + * consecutive dots "..", and an upper bound. Multiple values or ranges
48 + * can be given, separated by "|". Length-restricting values MUST NOT
49 + * be negative. If multiple values or ranges are given, they all MUST
50 + * be disjoint and MUST be in ascending order. If a length restriction
51 + * is applied to an already length-restricted type, the new restriction
52 + * MUST be equal or more limiting, that is, raising the lower bounds,
53 + * reducing the upper bounds, removing explicit length values or ranges,
54 + * or splitting ranges into multiple ranges with intermediate gaps. A
55 + * length value is a non-negative integer, or one of the special values
56 + * "min" or "max". "min" and "max" mean the minimum and maximum length
57 + * accepted for the type being restricted, respectively. An
58 + * implementation is not required to support a length value larger than
59 + * 18446744073709551615.
60 + * The length's sub-statements
61 + *
62 + * +---------------+---------+-------------+-----------------+
63 + * | substatement | section | cardinality | mapped data type|
64 + * +---------------+---------+-------------+-----------------+
65 + * | description | 7.19.3 | 0..1 | string |
66 + * | error-app-tag | 7.5.4.2 | 0..1 | string |
67 + * | error-message | 7.5.4.1 | 0..1 | string |
68 + * | reference | 7.19.4 | 0..1 | string |
69 + * +---------------+---------+-------------+-----------------+
70 + */
71 +
72 + /**
73 + * Length restriction information.
74 + */
75 + private YangRangeRestriction<YangUint64> lengthRestriction;
76 +
77 + /**
78 + * Textual reference.
79 + */
80 + private String reference;
81 +
82 + /**
83 + * Application's error message, to be used for data error.
84 + */
85 + private String errorMessage;
86 +
87 + /**
88 + * Application's error tag, to be filled in data validation error response.
89 + */
90 + private String errorAppTag;
91 +
92 + /**
93 + * Textual description.
94 + */
95 + private String description;
96 +
97 + /**
98 + * Creates a YANG length restriction object.
99 + */
100 + public YangLengthRestriction() {
101 + }
102 +
103 + /**
104 + * Returns the length restriction on the string data.
105 + *
106 + * @return length restriction on the string data
107 + */
108 + public YangRangeRestriction<YangUint64> getLengthRestriction() {
109 + return lengthRestriction;
110 + }
111 +
112 + /**
113 + * Sets the length restriction on the string data.
114 + *
115 + * @param lengthRestriction length restriction on the string data
116 + */
117 + public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) {
118 + this.lengthRestriction = lengthRestriction;
119 + }
120 +
121 + /**
122 + * Returns the textual reference of the length restriction.
123 + *
124 + * @return textual reference of the length restriction
125 + */
126 + @Override
127 + public String getReference() {
128 + return reference;
129 + }
130 +
131 + /**
132 + * Sets the textual reference of the length restriction.
133 + *
134 + * @param ref textual reference of the length restriction
135 + */
136 + @Override
137 + public void setReference(String ref) {
138 + reference = ref;
139 + }
140 +
141 + /**
142 + * Returns the description of the length restriction.
143 + *
144 + * @return description of the length restriction
145 + */
146 + @Override
147 + public String getDescription() {
148 + return description;
149 + }
150 +
151 + /**
152 + * Sets the description of the length restriction.
153 + *
154 + * @param desc description of the length restriction
155 + */
156 + @Override
157 + public void setDescription(String desc) {
158 + description = desc;
159 +
160 + }
161 +
162 + /**
163 + * Returns application's error message, to be used for data error.
164 + *
165 + * @return Application's error message, to be used for data error
166 + */
167 + @Override
168 + public String getGetErrorMessage() {
169 + return errorMessage;
170 + }
171 +
172 + /**
173 + * Sets Application's error message, to be used for data error.
174 + *
175 + * @param errMsg Application's error message, to be used for data error
176 + */
177 + @Override
178 + public void setErrorMessage(String errMsg) {
179 + errorMessage = errMsg;
180 +
181 + }
182 +
183 + /**
184 + * Returns application's error tag, to be used for data error.
185 + *
186 + * @return application's error tag, to be used for data error
187 + */
188 + @Override
189 + public String getGetErrorAppTag() {
190 + return errorAppTag;
191 + }
192 +
193 + /**
194 + * Sets application's error tag, to be used for data error.
195 + *
196 + * @param errTag application's error tag, to be used for data error.
197 + */
198 + @Override
199 + public void setErrorAppTag(String errTag) {
200 + errorAppTag = errTag;
201 + }
202 +
203 + @Override
204 + public YangConstructType getYangConstructType() {
205 + return YangConstructType.PATTERN_DATA;
206 + }
207 +
208 + @Override
209 + public void validateDataOnEntry() throws DataModelException {
210 + //TODO: implement the method.
211 + }
212 +
213 + @Override
214 + public void validateDataOnExit() throws DataModelException {
215 + //TODO: implement the method.
216 + }
217 +}
...@@ -15,14 +15,20 @@ ...@@ -15,14 +15,20 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 +import java.util.Iterator;
18 import java.util.LinkedList; 19 import java.util.LinkedList;
19 import java.util.List; 20 import java.util.List;
20 - 21 +import java.util.Set;
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 +import org.onosproject.yangutils.linker.exceptions.LinkerException;
24 +import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
25 +import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
22 import org.onosproject.yangutils.parser.Parsable; 26 import org.onosproject.yangutils.parser.Parsable;
27 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
23 import org.onosproject.yangutils.utils.YangConstructType; 28 import org.onosproject.yangutils.utils.YangConstructType;
24 29
25 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; 30 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
31 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.linkInterFileReferences;
26 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList; 32 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
27 33
28 /*- 34 /*-
...@@ -79,7 +85,7 @@ public class YangModule extends YangNode ...@@ -79,7 +85,7 @@ public class YangModule extends YangNode
79 85
80 /** 86 /**
81 * Reference:RFC 6020. 87 * Reference:RFC 6020.
82 - * 88 + * <p>
83 * The "contact" statement provides contact information for the module. The 89 * The "contact" statement provides contact information for the module. The
84 * argument is a string that is used to specify contact information for the 90 * argument is a string that is used to specify contact information for the
85 * person or persons to whom technical queries concerning this module should 91 * person or persons to whom technical queries concerning this module should
...@@ -90,7 +96,7 @@ public class YangModule extends YangNode ...@@ -90,7 +96,7 @@ public class YangModule extends YangNode
90 96
91 /** 97 /**
92 * Reference:RFC 6020. 98 * Reference:RFC 6020.
93 - * 99 + * <p>
94 * The "description" statement takes as an argument a string that contains a 100 * The "description" statement takes as an argument a string that contains a
95 * human-readable textual description of this definition. The text is 101 * human-readable textual description of this definition. The text is
96 * provided in a language (or languages) chosen by the module developer; for 102 * provided in a language (or languages) chosen by the module developer; for
...@@ -125,7 +131,7 @@ public class YangModule extends YangNode ...@@ -125,7 +131,7 @@ public class YangModule extends YangNode
125 131
126 /** 132 /**
127 * Reference:RFC 6020. 133 * Reference:RFC 6020.
128 - * 134 + * <p>
129 * The "organization" statement defines the party responsible for this 135 * The "organization" statement defines the party responsible for this
130 * module. The argument is a string that is used to specify a textual 136 * module. The argument is a string that is used to specify a textual
131 * description of the organization(s) under whose auspices this module was 137 * description of the organization(s) under whose auspices this module was
...@@ -408,6 +414,14 @@ public class YangModule extends YangNode ...@@ -408,6 +414,14 @@ public class YangModule extends YangNode
408 resolveLinkingForResolutionList(resolutionList, this); 414 resolveLinkingForResolutionList(resolutionList, this);
409 } 415 }
410 416
417 + @Override
418 + public void resolveInterFileLinking() throws DataModelException {
419 + // Get the list to be resolved.
420 + List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
421 + // Resolve linking for a resolution list.
422 + linkInterFileReferences(resolutionList, this);
423 + }
424 +
411 /** 425 /**
412 * Returns the textual reference. 426 * Returns the textual reference.
413 * 427 *
...@@ -525,4 +539,43 @@ public class YangModule extends YangNode ...@@ -525,4 +539,43 @@ public class YangModule extends YangNode
525 public void setResolutionList(List<YangResolutionInfo> resolutionList) { 539 public void setResolutionList(List<YangResolutionInfo> resolutionList) {
526 unresolvedResolutionList = resolutionList; 540 unresolvedResolutionList = resolutionList;
527 } 541 }
542 +
543 + @Override
544 + public void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet)
545 + throws LinkerException {
546 + Iterator<YangImport> importInfoIterator = getImportList().iterator();
547 + // Run through the imported list to add references.
548 + while (importInfoIterator.hasNext()) {
549 + YangImport yangImport = importInfoIterator.next();
550 + try {
551 + yangImport.addReferenceToImport(yangFileInfoSet);
552 + } catch (DataModelException e) {
553 + throw new LinkerException(e.getMessage());
554 + }
555 + }
556 + }
557 +
558 + @Override
559 + public void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet)
560 + throws LinkerException {
561 + Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator();
562 + // Run through the included list to add references.
563 + while (includeInfoIterator.hasNext()) {
564 + YangInclude yangInclude = includeInfoIterator.next();
565 + YangSubModule subModule = null;
566 + try {
567 + subModule = yangInclude.addReferenceToInclude(yangFileInfoSet);
568 + } catch (DataModelException e) {
569 + throw new LinkerException(e.getMessage());
570 + }
571 + // Check if the referred sub-modules parent is self
572 + if (!(subModule.getBelongsTo().getModuleNode() == this)) {
573 + try {
574 + yangInclude.reportIncludeError();
575 + } catch (DataModelException e) {
576 + throw new LinkerException(e.getMessage());
577 + }
578 + }
579 + }
580 + }
528 } 581 }
......
...@@ -15,14 +15,20 @@ ...@@ -15,14 +15,20 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 +import java.util.Iterator;
18 import java.util.LinkedList; 19 import java.util.LinkedList;
19 import java.util.List; 20 import java.util.List;
20 - 21 +import java.util.Set;
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 +import org.onosproject.yangutils.linker.exceptions.LinkerException;
24 +import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
25 +import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
22 import org.onosproject.yangutils.parser.Parsable; 26 import org.onosproject.yangutils.parser.Parsable;
27 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
23 import org.onosproject.yangutils.utils.YangConstructType; 28 import org.onosproject.yangutils.utils.YangConstructType;
24 29
25 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; 30 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
31 +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.linkInterFileReferences;
26 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList; 32 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
27 33
28 /* 34 /*
...@@ -92,7 +98,7 @@ public class YangSubModule extends YangNode ...@@ -92,7 +98,7 @@ public class YangSubModule extends YangNode
92 98
93 /** 99 /**
94 * Reference RFC 6020. 100 * Reference RFC 6020.
95 - * 101 + * <p>
96 * The "contact" statement provides contact information for the module. The 102 * The "contact" statement provides contact information for the module. The
97 * argument is a string that is used to specify contact information for the 103 * argument is a string that is used to specify contact information for the
98 * person or persons to whom technical queries concerning this module should 104 * person or persons to whom technical queries concerning this module should
...@@ -338,6 +344,14 @@ public class YangSubModule extends YangNode ...@@ -338,6 +344,14 @@ public class YangSubModule extends YangNode
338 resolveLinkingForResolutionList(resolutionList, this); 344 resolveLinkingForResolutionList(resolutionList, this);
339 } 345 }
340 346
347 + @Override
348 + public void resolveInterFileLinking() throws DataModelException {
349 + // Get the list to be resolved.
350 + List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
351 + // Resolve linking for a resolution list.
352 + linkInterFileReferences(resolutionList, this);
353 + }
354 +
341 /** 355 /**
342 * Returns the list of leaves. 356 * Returns the list of leaves.
343 * 357 *
...@@ -507,4 +521,54 @@ public class YangSubModule extends YangNode ...@@ -507,4 +521,54 @@ public class YangSubModule extends YangNode
507 public void setResolutionList(List<YangResolutionInfo> resolutionList) { 521 public void setResolutionList(List<YangResolutionInfo> resolutionList) {
508 this.unresolvedResolutionList = resolutionList; 522 this.unresolvedResolutionList = resolutionList;
509 } 523 }
524 +
525 + /**
526 + * Links the sub-module with module.
527 + *
528 + * @param yangFileInfoSet YANG file information set
529 + * @throws DataModelException a violation in data model rule
530 + */
531 + public void linkWithModule(Set<YangFileInfo> yangFileInfoSet)
532 + throws DataModelException {
533 + getBelongsTo().linkWithModule(yangFileInfoSet);
534 + }
535 +
536 + @Override
537 + public void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet)
538 + throws LinkerException {
539 + Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator();
540 + // Run through the included list to add references.
541 + while (includeInfoIterator.hasNext()) {
542 + YangInclude yangInclude = includeInfoIterator.next();
543 + YangSubModule subModule = null;
544 + try {
545 + subModule = yangInclude.addReferenceToInclude(yangFileInfoSet);
546 + } catch (DataModelException e) {
547 + throw new LinkerException(e.getMessage());
548 + }
549 + // Check if the referred sub-modules parent is self
550 + if (!(subModule.getBelongsTo().getModuleNode() == getBelongsTo().getModuleNode())) {
551 + try {
552 + yangInclude.reportIncludeError();
553 + } catch (DataModelException e) {
554 + throw new LinkerException(e.getMessage());
555 + }
556 + }
557 + }
558 + }
559 +
560 + @Override
561 + public void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet)
562 + throws LinkerException {
563 + Iterator<YangImport> importInfoIterator = getImportList().iterator();
564 + // Run through the imported list to add references.
565 + while (importInfoIterator.hasNext()) {
566 + YangImport yangImport = importInfoIterator.next();
567 + try {
568 + yangImport.addReferenceToImport(yangFileInfoSet);
569 + } catch (DataModelException e) {
570 + throw new LinkerException(e.getMessage());
571 + }
572 + }
573 + }
510 } 574 }
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
17 package org.onosproject.yangutils.datamodel; 17 package org.onosproject.yangutils.datamodel;
18 18
19 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 19 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20 +import org.onosproject.yangutils.linker.exceptions.LinkerException;
21 +import org.onosproject.yangutils.linker.impl.Resolvable;
22 +import org.onosproject.yangutils.linker.impl.ResolvableStatus;
20 import org.onosproject.yangutils.parser.Parsable; 23 import org.onosproject.yangutils.parser.Parsable;
21 import org.onosproject.yangutils.utils.YangConstructType; 24 import org.onosproject.yangutils.utils.YangConstructType;
22 25
...@@ -244,21 +247,25 @@ public class YangType<T> ...@@ -244,21 +247,25 @@ public class YangType<T>
244 } 247 }
245 248
246 @Override 249 @Override
247 - public void resolve() throws DataModelException { 250 + public void resolve() throws LinkerException {
248 /* 251 /*
249 * Check whether the data type is derived. 252 * Check whether the data type is derived.
250 */ 253 */
251 if (getDataType() != DERIVED) { 254 if (getDataType() != DERIVED) {
252 - throw new DataModelException("Linker Error: Resolve should only be called for derived data types."); 255 + throw new LinkerException("Linker Error: Resolve should only be called for derived data types.");
253 } 256 }
254 257
255 // Check if the derived info is present. 258 // Check if the derived info is present.
256 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo(); 259 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo();
257 if (derivedInfo == null) { 260 if (derivedInfo == null) {
258 - throw new DataModelException("Linker Error: Derived information is missing."); 261 + throw new LinkerException("Linker Error: Derived information is missing.");
259 } 262 }
260 263
261 // Initiate the resolution 264 // Initiate the resolution
265 + try {
262 setResolvableStatus(derivedInfo.resolve()); 266 setResolvableStatus(derivedInfo.resolve());
267 + } catch (DataModelException e) {
268 + throw new LinkerException(e.getMessage());
269 + }
263 } 270 }
264 } 271 }
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 +import org.onosproject.yangutils.linker.exceptions.LinkerException;
20 +import org.onosproject.yangutils.linker.impl.Resolvable;
21 +import org.onosproject.yangutils.linker.impl.ResolvableStatus;
19 import org.onosproject.yangutils.parser.Parsable; 22 import org.onosproject.yangutils.parser.Parsable;
20 import org.onosproject.yangutils.utils.YangConstructType; 23 import org.onosproject.yangutils.utils.YangConstructType;
21 24
...@@ -259,37 +262,49 @@ public class YangUses ...@@ -259,37 +262,49 @@ public class YangUses
259 262
260 @Override 263 @Override
261 public void resolve() 264 public void resolve()
262 - throws DataModelException { 265 + throws LinkerException {
263 266
264 YangGrouping referredGrouping = getRefGroup(); 267 YangGrouping referredGrouping = getRefGroup();
265 268
266 if (referredGrouping == null) { 269 if (referredGrouping == null) {
267 - throw new DataModelException("YANG uses linker error, cannot resolve uses"); 270 + throw new LinkerException("Linker Exception: YANG uses linker error, cannot resolve uses");
268 } 271 }
269 272
270 YangNode usesParentNode = getParentNodeInGenCode(this); 273 YangNode usesParentNode = getParentNodeInGenCode(this);
271 if ((!(usesParentNode instanceof YangLeavesHolder)) 274 if ((!(usesParentNode instanceof YangLeavesHolder))
272 || (!(usesParentNode instanceof CollisionDetector))) { 275 || (!(usesParentNode instanceof CollisionDetector))) {
273 - throw new DataModelException("YANG uses holder construct is wrong"); 276 + throw new LinkerException("Linker Exception: YANG uses holder construct is wrong");
274 } 277 }
275 278
276 YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode; 279 YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode;
277 if (referredGrouping.getListOfLeaf() != null) { 280 if (referredGrouping.getListOfLeaf() != null) {
278 for (YangLeaf leaf : referredGrouping.getListOfLeaf()) { 281 for (YangLeaf leaf : referredGrouping.getListOfLeaf()) {
282 + try {
279 ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(), 283 ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(),
280 YangConstructType.LEAF_DATA); 284 YangConstructType.LEAF_DATA);
285 + } catch (DataModelException e) {
286 + throw new LinkerException(e.getMessage());
287 + }
281 usesParentLeavesHolder.addLeaf(leaf); 288 usesParentLeavesHolder.addLeaf(leaf);
282 } 289 }
283 } 290 }
284 if (referredGrouping.getListOfLeafList() != null) { 291 if (referredGrouping.getListOfLeafList() != null) {
285 for (YangLeafList leafList : referredGrouping.getListOfLeafList()) { 292 for (YangLeafList leafList : referredGrouping.getListOfLeafList()) {
293 + try {
286 ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(), 294 ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(),
287 YangConstructType.LEAF_LIST_DATA); 295 YangConstructType.LEAF_LIST_DATA);
296 + } catch (DataModelException e) {
297 + throw new LinkerException(e.getMessage());
298 + }
288 usesParentLeavesHolder.addLeafList(leafList); 299 usesParentLeavesHolder.addLeafList(leafList);
289 } 300 }
290 } 301 }
291 302
303 + try {
292 YangNode.cloneSubTree(getRefGroup(), usesParentNode); 304 YangNode.cloneSubTree(getRefGroup(), usesParentNode);
305 + } catch (DataModelException e) {
306 + throw new LinkerException(e.getMessage());
307 + }
293 } 308 }
294 309
295 @Override 310 @Override
......
...@@ -16,17 +16,15 @@ ...@@ -16,17 +16,15 @@
16 16
17 package org.onosproject.yangutils.datamodel.utils; 17 package org.onosproject.yangutils.datamodel.utils;
18 18
19 -import java.util.Iterator;
20 import java.util.List; 19 import java.util.List;
21 - 20 +import java.util.Set;
22 import org.onosproject.yangutils.datamodel.CollisionDetector; 21 import org.onosproject.yangutils.datamodel.CollisionDetector;
23 -import org.onosproject.yangutils.datamodel.YangImport;
24 import org.onosproject.yangutils.datamodel.YangLeaf; 22 import org.onosproject.yangutils.datamodel.YangLeaf;
25 import org.onosproject.yangutils.datamodel.YangLeafList; 23 import org.onosproject.yangutils.datamodel.YangLeafList;
26 import org.onosproject.yangutils.datamodel.YangLeavesHolder; 24 import org.onosproject.yangutils.datamodel.YangLeavesHolder;
27 import org.onosproject.yangutils.datamodel.YangNode; 25 import org.onosproject.yangutils.datamodel.YangNode;
28 -import org.onosproject.yangutils.datamodel.YangReferenceResolver; 26 +import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
29 -import org.onosproject.yangutils.datamodel.YangResolutionInfo; 27 +import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
30 import org.onosproject.yangutils.datamodel.YangRpc; 28 import org.onosproject.yangutils.datamodel.YangRpc;
31 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 29 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
32 import org.onosproject.yangutils.parser.Parsable; 30 import org.onosproject.yangutils.parser.Parsable;
...@@ -55,7 +53,6 @@ public final class DataModelUtils { ...@@ -55,7 +53,6 @@ public final class DataModelUtils {
55 */ 53 */
56 public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node) 54 public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node)
57 throws DataModelException { 55 throws DataModelException {
58 -
59 if (dataType == YangConstructType.USES_DATA || dataType == YangConstructType.GROUPING_DATA) { 56 if (dataType == YangConstructType.USES_DATA || dataType == YangConstructType.GROUPING_DATA) {
60 detectCollidingForUsesGrouping(identifierName, dataType, node); 57 detectCollidingForUsesGrouping(identifierName, dataType, node);
61 } else { 58 } else {
...@@ -165,64 +162,41 @@ public final class DataModelUtils { ...@@ -165,64 +162,41 @@ public final class DataModelUtils {
165 } 162 }
166 YangReferenceResolver resolutionNode = (YangReferenceResolver) curNode; 163 YangReferenceResolver resolutionNode = (YangReferenceResolver) curNode;
167 164
168 - if (!isPrefixValid(resolutionInfo.getEntityToResolveInfo().getEntityPrefix(),
169 - resolutionNode)) {
170 - throw new DataModelException("The prefix used is not valid");
171 - }
172 resolutionNode.addToResolutionList(resolutionInfo); 165 resolutionNode.addToResolutionList(resolutionInfo);
173 } 166 }
174 167
175 /** 168 /**
176 - * Evaluates whether the prefix in uses/type is valid. 169 + * Resolve linking for a resolution list.
177 * 170 *
178 - * @param entityPrefix prefix in the current module/sub-module 171 + * @param resolutionList resolution list for which linking to be done
179 - * @param resolutionNode uses/type node which has the prefix with it 172 + * @param dataModelRootNode module/sub-module node
180 - * @return whether prefix is valid or not 173 + * @throws DataModelException a violation of data model rules
181 */ 174 */
182 - private static boolean isPrefixValid(String entityPrefix, YangReferenceResolver resolutionNode) { 175 + public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList,
183 - if (entityPrefix == null) { 176 + YangReferenceResolver dataModelRootNode)
184 - return true; 177 + throws DataModelException {
185 - }
186 -
187 - if (resolutionNode.getPrefix().contentEquals(entityPrefix)) {
188 - return true;
189 - }
190 -
191 - if (resolutionNode.getImportList() != null) {
192 - for (YangImport importedInfo : resolutionNode.getImportList()) {
193 - if (importedInfo.getPrefixId().contentEquals(entityPrefix)) {
194 - return true;
195 - }
196 - }
197 - }
198 -
199 - if (resolutionNode.getIncludeList() != null) {
200 - /**
201 - * TODO: check if the prefix matches with the imported data
202 178
203 - for (YangInclude includedInfo : resolutionNode.getIncludeList()) { 179 + for (YangResolutionInfo resolutionInfo : resolutionList) {
204 - if (includedInfo.contentEquals(prefix)) { 180 + resolutionInfo.resolveLinkingForResolutionInfo(dataModelRootNode);
205 - return true;
206 - }
207 - }*/
208 } 181 }
209 -
210 - return false;
211 } 182 }
212 183
213 /** 184 /**
214 - * Resolve linking for a resolution list. 185 + * Links type/uses referring to typedef/uses of inter YANG file.
215 * 186 *
216 * @param resolutionList resolution list for which linking to be done 187 * @param resolutionList resolution list for which linking to be done
217 * @param dataModelRootNode module/sub-module node 188 * @param dataModelRootNode module/sub-module node
218 * @throws DataModelException a violation of data model rules 189 * @throws DataModelException a violation of data model rules
219 */ 190 */
220 - public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList, 191 + public static void linkInterFileReferences(List<YangResolutionInfo> resolutionList,
221 YangReferenceResolver dataModelRootNode) 192 YangReferenceResolver dataModelRootNode)
222 throws DataModelException { 193 throws DataModelException {
223 - 194 + /*
195 + * Run through the resolution list, find type/uses referring to
196 + * inter file typedef/grouping, ask for linking.
197 + */
224 for (YangResolutionInfo resolutionInfo : resolutionList) { 198 for (YangResolutionInfo resolutionInfo : resolutionList) {
225 - resolutionInfo.resolveLinkingForResolutionInfo(dataModelRootNode.getPrefix()); 199 + resolutionInfo.linkInterFile(dataModelRootNode);
226 } 200 }
227 } 201 }
228 202
...@@ -244,24 +218,23 @@ public final class DataModelUtils { ...@@ -244,24 +218,23 @@ public final class DataModelUtils {
244 } 218 }
245 219
246 /** 220 /**
247 - * Returns module's data model node to which sub-module belongs to. 221 + * Returns referred node in a given set.
248 * 222 *
249 - * @param yangFileInfo YANG file information 223 + * @param yangFileInfoSet YANG file info set
250 - * @param belongsToModuleName name of the module to which sub-module belongs to 224 + * @param refNodeName name of the node which is referred
251 - * @return module node to which sub-module belongs to 225 + * @return referred node's reference
252 - * @throws DataModelException when belongs to module node is not found 226 + */
227 + public static YangNode findReferredNode(Set<YangFileInfo> yangFileInfoSet, String refNodeName) {
228 + /*
229 + * Run through the YANG files to see which YANG file matches the
230 + * referred node name.
253 */ 231 */
254 - public static YangNode findBelongsToModuleNode(List<YangFileInfo> yangFileInfo, 232 + for (YangFileInfo yangFileInfo : yangFileInfoSet) {
255 - String belongsToModuleName) throws DataModelException { 233 + YangNode yangNode = yangFileInfo.getRootNode();
256 - Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator(); 234 + if (yangNode.getName().equals(refNodeName)) {
257 - while (yangFileIterator.hasNext()) { 235 + return yangFileInfo.getRootNode();
258 - YangFileInfo yangFile = yangFileIterator.next();
259 - YangNode yangNode = yangFile.getRootNode();
260 - if (yangNode.getName().equals(belongsToModuleName)) {
261 - return yangNode;
262 } 236 }
263 } 237 }
264 - throw new DataModelException("YANG file error : Module " + belongsToModuleName + " to which sub-module " + 238 + return null;
265 - "belongs to is not found.");
266 } 239 }
267 } 240 }
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
16 16
17 package org.onosproject.yangutils.linker; 17 package org.onosproject.yangutils.linker;
18 18
19 -import java.util.Map; 19 +import java.util.Set;
20 -import org.onosproject.yangutils.datamodel.YangReferenceResolver; 20 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
21 21
22 /** 22 /**
23 * Abstraction of entity which provides linking service of YANG files. 23 * Abstraction of entity which provides linking service of YANG files.
...@@ -28,8 +28,7 @@ public interface YangLinker { ...@@ -28,8 +28,7 @@ public interface YangLinker {
28 * Resolve the import and include dependencies for a given resolution 28 * Resolve the import and include dependencies for a given resolution
29 * information. 29 * information.
30 * 30 *
31 - * @param fileMapEntry map entry for which resolution is to be done 31 + * @param yangFileInfoSet set of all dependent YANG files
32 - * @param yangFilesMap map of dependent file and resolution information*/ 32 + */
33 - void resolveDependencies(Map.Entry<String, YangReferenceResolver> fileMapEntry, Map<String, 33 + void resolveDependencies(Set<YangFileInfo> yangFileInfoSet);
34 - YangReferenceResolver> yangFilesMap);
35 } 34 }
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.linker.exceptions;
18 +
19 +/**
20 + * Represents base class for exceptions in linker operations.
21 + */
22 +public class LinkerException extends RuntimeException {
23 +
24 + private static final long serialVersionUID = 20160211L;
25 + private int lineNumber;
26 + private int charPositionInLine;
27 + private String fileName;
28 +
29 + /**
30 + * Creates a new linker exception.
31 + */
32 + public LinkerException() {
33 + super();
34 + }
35 +
36 + /**
37 + * Creates a new linker exception with given message.
38 + *
39 + * @param message the detail of exception in string
40 + */
41 + public LinkerException(String message) {
42 + super(message);
43 + }
44 +
45 + /**
46 + * Creates a new linker exception from given message and cause.
47 + *
48 + * @param message the detail of exception in string
49 + * @param cause underlying cause of the error
50 + */
51 + public LinkerException(final String message, final Throwable cause) {
52 + super(message, cause);
53 + }
54 +
55 + /**
56 + * Creates a new linker exception from cause.
57 + *
58 + * @param cause underlying cause of the error
59 + */
60 + public LinkerException(final Throwable cause) {
61 + super(cause);
62 + }
63 +
64 + /**
65 + * Returns line number of the exception.
66 + *
67 + * @return line number of the exception
68 + */
69 + public int getLineNumber() {
70 + return this.lineNumber;
71 + }
72 +
73 + /**
74 + * Returns YANG file name of the exception.
75 + *
76 + * @return YANG file name of the exception
77 + */
78 + public String getFileName() {
79 + return this.fileName;
80 + }
81 +
82 + /**
83 + * Returns position of the exception.
84 + *
85 + * @return position of the exception
86 + */
87 + public int getCharPositionInLine() {
88 + return this.charPositionInLine;
89 + }
90 +
91 + /**
92 + * Sets line number of YANG file.
93 + *
94 + * @param line line number of YANG file
95 + */
96 + public void setLine(int line) {
97 + this.lineNumber = line;
98 + }
99 +
100 + /**
101 + * Sets position of exception.
102 + *
103 + * @param charPosition position of exception
104 + */
105 + public void setCharPosition(int charPosition) {
106 + this.charPositionInLine = charPosition;
107 + }
108 +
109 + /**
110 + * Sets file name in parser exception.
111 + *
112 + * @param fileName YANG file name
113 + */
114 + public void setFileName(String fileName) {
115 + this.fileName = fileName;
116 + }
117 +}
1 +/*
2 + * Copyright 2016-present 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 +/**
18 + * Custom linker exceptions.
19 + */
20 +package org.onosproject.yangutils.linker.exceptions;
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.yangutils.datamodel; 17 +package org.onosproject.yangutils.linker.impl;
18 18
19 -import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 19 +import org.onosproject.yangutils.linker.exceptions.LinkerException;
20 20
21 /** 21 /**
22 * Abstraction of YANG resolvable information. Abstracted to obtain the 22 * Abstraction of YANG resolvable information. Abstracted to obtain the
...@@ -47,8 +47,8 @@ public interface Resolvable { ...@@ -47,8 +47,8 @@ public interface Resolvable {
47 /** 47 /**
48 * Resolves the linking. 48 * Resolves the linking.
49 * 49 *
50 - * @throws DataModelException data model error 50 + * @throws LinkerException linker error
51 */ 51 */
52 void resolve() 52 void resolve()
53 - throws DataModelException; 53 + throws LinkerException;
54 } 54 }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.yangutils.datamodel; 17 +package org.onosproject.yangutils.linker.impl;
18 18
19 /** 19 /**
20 * Represents the status of resolvable entity. 20 * Represents the status of resolvable entity.
...@@ -40,6 +40,12 @@ public enum ResolvableStatus { ...@@ -40,6 +40,12 @@ public enum ResolvableStatus {
40 /** 40 /**
41 * Identifies that resolvable entity is resolved. 41 * Identifies that resolvable entity is resolved.
42 */ 42 */
43 - RESOLVED 43 + RESOLVED,
44 +
45 + /**
46 + * Identifies that resolvable entity is inter file linked (i.e. complete
47 + * linking with external files).
48 + */
49 + INTER_FILE_LINKED
44 50
45 } 51 }
......
...@@ -13,9 +13,12 @@ ...@@ -13,9 +13,12 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.yangutils.datamodel; 16 +package org.onosproject.yangutils.linker.impl;
17 17
18 -import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 18 +import org.onosproject.yangutils.datamodel.YangNode;
19 +import org.onosproject.yangutils.datamodel.YangType;
20 +import org.onosproject.yangutils.datamodel.YangUses;
21 +import org.onosproject.yangutils.linker.exceptions.LinkerException;
19 22
20 /** 23 /**
21 * Represents information about entity being resolved. 24 * Represents information about entity being resolved.
...@@ -71,10 +74,10 @@ public class YangEntityToResolveInfo<T> { ...@@ -71,10 +74,10 @@ public class YangEntityToResolveInfo<T> {
71 * Retrieves the prefix of the entity. 74 * Retrieves the prefix of the entity.
72 * 75 *
73 * @return entities prefix 76 * @return entities prefix
74 - * @throws DataModelException data model error 77 + * @throws LinkerException linker error
75 */ 78 */
76 public String getEntityPrefix() 79 public String getEntityPrefix()
77 - throws DataModelException { 80 + throws LinkerException {
78 if (getEntityToResolve() == null) { 81 if (getEntityToResolve() == null) {
79 return null; 82 return null;
80 } 83 }
...@@ -86,7 +89,7 @@ public class YangEntityToResolveInfo<T> { ...@@ -86,7 +89,7 @@ public class YangEntityToResolveInfo<T> {
86 } else if (entityToBeResolved instanceof YangUses) { 89 } else if (entityToBeResolved instanceof YangUses) {
87 prefix = ((YangUses) entityToBeResolved).getPrefix(); 90 prefix = ((YangUses) entityToBeResolved).getPrefix();
88 } else { 91 } else {
89 - throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses"); 92 + throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses");
90 } 93 }
91 return prefix; 94 return prefix;
92 } 95 }
......
1 +/*
2 + * Copyright 2016-present 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.impl;
18 +
19 +import java.util.Set;
20 +import org.onosproject.yangutils.datamodel.YangNode;
21 +import org.onosproject.yangutils.datamodel.YangSubModule;
22 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 +import org.onosproject.yangutils.linker.YangLinker;
24 +import org.onosproject.yangutils.linker.exceptions.LinkerException;
25 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
26 +
27 +import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
28 +
29 +/**
30 + * Representation of entity which provides linking service of YANG files.
31 + */
32 +public class YangLinkerManager implements YangLinker {
33 + @Override
34 + public void resolveDependencies(Set<YangFileInfo> yangFileInfoSet) {
35 +
36 + // Carry out linking of sub module with module.
37 + linkSubModulesToParentModule(yangFileInfoSet);
38 +
39 + // Add references to import list.
40 + addRefToYangFilesImportList(yangFileInfoSet);
41 +
42 + // Add reference to include list.
43 + addRefToYangFilesIncludeList(yangFileInfoSet);
44 +
45 + // TODO check for circular import/include.
46 +
47 + // Carry out inter-file linking.
48 + processInterFileLinking(yangFileInfoSet);
49 + }
50 +
51 + /**
52 + * Resolves sub-module linking by linking sub module with parent module.
53 + *
54 + * @param yangFileInfoSet set of YANG files info
55 + * @throws LinkerException fails to link sub-module to parent module
56 + */
57 + public void linkSubModulesToParentModule(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
58 + for (YangFileInfo yangFileInfo : yangFileInfoSet) {
59 + YangNode yangNode = yangFileInfo.getRootNode();
60 + if (yangNode instanceof YangSubModule) {
61 + try {
62 + ((YangSubModule) yangNode).linkWithModule(yangFileInfoSet);
63 + } catch (DataModelException e) {
64 + String errorInfo = "YANG file error: " + yangFileInfo.getYangFileName() + " at line: "
65 + + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
66 + + e.getMessage();
67 + throw new LinkerException(errorInfo);
68 + }
69 + }
70 + }
71 + }
72 +
73 + /**
74 + * Adds imported node information to the import list.
75 + *
76 + * @param yangFileInfoSet set of YANG files info
77 + * @throws LinkerException fails to find imported module
78 + */
79 + public void addRefToYangFilesImportList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
80 + for (YangFileInfo yangFileInfo : yangFileInfoSet) {
81 + YangNode yangNode = yangFileInfo.getRootNode();
82 + if (yangNode instanceof YangReferenceResolver) {
83 + ((YangReferenceResolver) yangNode).addReferencesToImportList(yangFileInfoSet);
84 + }
85 + }
86 + }
87 +
88 + /**
89 + * Adds included node information to the include list.
90 + *
91 + * @param yangFileInfoSet set of YANG files info
92 + * @throws LinkerException fails to find included sub-module
93 + */
94 + public void addRefToYangFilesIncludeList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
95 + for (YangFileInfo yangFileInfo : yangFileInfoSet) {
96 + YangNode yangNode = yangFileInfo.getRootNode();
97 + if (yangNode instanceof YangReferenceResolver) {
98 + ((YangReferenceResolver) yangNode).addReferencesToIncludeList(yangFileInfoSet);
99 + }
100 + }
101 + }
102 +
103 + /**
104 + * Processes inter file linking for type and uses.
105 + *
106 + * @param yangFileInfoSet set of YANG files info
107 + * @throws LinkerException a violation in linker execution
108 + */
109 + public void processInterFileLinking(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
110 + for (YangFileInfo yangFileInfo : yangFileInfoSet) {
111 + try {
112 + ((YangReferenceResolver) yangFileInfo.getRootNode()).resolveInterFileLinking();
113 + } catch (DataModelException e) {
114 + String errorInfo = "Error in file: " + yangFileInfo.getYangFileName() + " at line: "
115 + + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
116 + throw new LinkerException(errorInfo);
117 + }
118 + }
119 + }
120 +}
...@@ -14,10 +14,15 @@ ...@@ -14,10 +14,15 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.yangutils.datamodel; 17 +package org.onosproject.yangutils.linker.impl;
18 18
19 import java.util.List; 19 import java.util.List;
20 +import java.util.Set;
21 +import org.onosproject.yangutils.datamodel.YangImport;
22 +import org.onosproject.yangutils.datamodel.YangInclude;
20 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 23 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
24 +import org.onosproject.yangutils.linker.exceptions.LinkerException;
25 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
21 26
22 /** 27 /**
23 * Abstraction of YANG dependency resolution information. Abstracted to obtain the 28 * Abstraction of YANG dependency resolution information. Abstracted to obtain the
...@@ -33,7 +38,7 @@ public interface YangReferenceResolver { ...@@ -33,7 +38,7 @@ public interface YangReferenceResolver {
33 List<YangResolutionInfo> getUnresolvedResolutionList(); 38 List<YangResolutionInfo> getUnresolvedResolutionList();
34 39
35 /** 40 /**
36 - * Add to the resolution list. 41 + * Adds to the resolution list.
37 * 42 *
38 * @param resolutionInfo resolution information 43 * @param resolutionInfo resolution information
39 */ 44 */
...@@ -54,7 +59,7 @@ public interface YangReferenceResolver { ...@@ -54,7 +59,7 @@ public interface YangReferenceResolver {
54 List<YangImport> getImportList(); 59 List<YangImport> getImportList();
55 60
56 /** 61 /**
57 - * Add to the import list. 62 + * Adds to the import list.
58 * 63 *
59 * @param yangImport import to be added 64 * @param yangImport import to be added
60 */ 65 */
...@@ -75,14 +80,14 @@ public interface YangReferenceResolver { ...@@ -75,14 +80,14 @@ public interface YangReferenceResolver {
75 List<YangInclude> getIncludeList(); 80 List<YangInclude> getIncludeList();
76 81
77 /** 82 /**
78 - * Add to the include list. 83 + * Adds to the include list.
79 * 84 *
80 * @param yangInclude include to be added 85 * @param yangInclude include to be added
81 */ 86 */
82 void addToIncludeList(YangInclude yangInclude); 87 void addToIncludeList(YangInclude yangInclude);
83 88
84 /** 89 /**
85 - * Create include list. 90 + * Creates include list.
86 * 91 *
87 * @param includeList include list 92 * @param includeList include list
88 */ 93 */
...@@ -96,16 +101,39 @@ public interface YangReferenceResolver { ...@@ -96,16 +101,39 @@ public interface YangReferenceResolver {
96 String getPrefix(); 101 String getPrefix();
97 102
98 /** 103 /**
99 - * Set prefix of resolution list root node. 104 + * Sets prefix of resolution list root node.
100 * 105 *
101 * @param prefix resolution root node prefix 106 * @param prefix resolution root node prefix
102 */ 107 */
103 void setPrefix(String prefix); 108 void setPrefix(String prefix);
104 109
105 /** 110 /**
106 - * Resolve self file linking. 111 + * Resolves self file linking.
107 * 112 *
108 * @throws DataModelException a violation in data model rule 113 * @throws DataModelException a violation in data model rule
109 */ 114 */
110 void resolveSelfFileLinking() throws DataModelException; 115 void resolveSelfFileLinking() throws DataModelException;
116 +
117 + /**
118 + * Resolves inter file linking.
119 + *
120 + * @throws DataModelException a violation in data model rule
121 + */
122 + void resolveInterFileLinking() throws DataModelException;
123 +
124 + /**
125 + * Adds references to include.
126 + *
127 + * @param yangFileInfoSet YANG file info set
128 + * @throws LinkerException a violation of linker rules
129 + */
130 + void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException;
131 +
132 + /**
133 + * Adds references to import.
134 + *
135 + * @param yangFileInfoSet YANG file info set
136 + * @throws LinkerException a violation of linker rules
137 + */
138 + void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException;
111 } 139 }
......
...@@ -14,15 +14,26 @@ ...@@ -14,15 +14,26 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.yangutils.datamodel; 17 +package org.onosproject.yangutils.linker.impl;
18 18
19 import java.util.Stack; 19 import java.util.Stack;
20 +import org.onosproject.yangutils.datamodel.LocationInfo;
21 +import org.onosproject.yangutils.datamodel.YangDataTypes;
22 +import org.onosproject.yangutils.datamodel.YangDerivedInfo;
23 +import org.onosproject.yangutils.datamodel.YangGrouping;
24 +import org.onosproject.yangutils.datamodel.YangImport;
25 +import org.onosproject.yangutils.datamodel.YangInclude;
26 +import org.onosproject.yangutils.datamodel.YangNode;
27 +import org.onosproject.yangutils.datamodel.YangType;
28 +import org.onosproject.yangutils.datamodel.YangTypeDef;
29 +import org.onosproject.yangutils.datamodel.YangUses;
20 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 30 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
21 31
22 -import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED; 32 +import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTER_FILE_LINKED;
23 -import static org.onosproject.yangutils.datamodel.ResolvableStatus.LINKED; 33 +import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_RESOLVED;
24 -import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED; 34 +import static org.onosproject.yangutils.linker.impl.ResolvableStatus.LINKED;
25 -import static org.onosproject.yangutils.datamodel.ResolvableStatus.UNRESOLVED; 35 +import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
36 +import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED;
26 37
27 /** 38 /**
28 * Represents resolution object which will be resolved by linker. 39 * Represents resolution object which will be resolved by linker.
...@@ -36,21 +47,28 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -36,21 +47,28 @@ public class YangResolutionInfo<T> implements LocationInfo {
36 */ 47 */
37 private YangEntityToResolveInfo<T> entityToResolveInfo; 48 private YangEntityToResolveInfo<T> entityToResolveInfo;
38 49
39 - // Error Line number. 50 + /**
51 + * Error line number.
52 + */
40 private int lineNumber; 53 private int lineNumber;
41 54
42 - // Error character position. 55 + /**
56 + * Error character position in number.
57 + */
43 private int charPosition; 58 private int charPosition;
44 59
45 - /* 60 + /**
61 + * Current module/sub-module reference, will be used in inter-file/
62 + * inter-jar scenario to get the import/include list.
63 + */
64 + private YangReferenceResolver curReferenceResolver;
65 +
66 + /**
46 * Stack for type/uses is maintained for hierarchical references, this is 67 * Stack for type/uses is maintained for hierarchical references, this is
47 * used during resolution. 68 * used during resolution.
48 */ 69 */
49 private Stack<YangEntityToResolveInfo<T>> partialResolvedStack; 70 private Stack<YangEntityToResolveInfo<T>> partialResolvedStack;
50 71
51 - // Module/Sub-module prefix.
52 - private String resolutionInfoRootNodePrefix;
53 -
54 /** 72 /**
55 * It is private to ensure the overloaded method be invoked to create an 73 * It is private to ensure the overloaded method be invoked to create an
56 * object. 74 * object.
...@@ -69,25 +87,25 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -69,25 +87,25 @@ public class YangResolutionInfo<T> implements LocationInfo {
69 * @param charPositionInLine error character position in line 87 * @param charPositionInLine error character position in line
70 */ 88 */
71 public YangResolutionInfo(T dataNode, YangNode holderNode, int lineNumber, int charPositionInLine) { 89 public YangResolutionInfo(T dataNode, YangNode holderNode, int lineNumber, int charPositionInLine) {
72 - setEntityToResolveInfo(new YangEntityToResolveInfo<T>()); 90 + setEntityToResolveInfo(new YangEntityToResolveInfo<>());
73 getEntityToResolveInfo().setEntityToResolve(dataNode); 91 getEntityToResolveInfo().setEntityToResolve(dataNode);
74 getEntityToResolveInfo().setHolderOfEntityToResolve(holderNode); 92 getEntityToResolveInfo().setHolderOfEntityToResolve(holderNode);
75 this.setLineNumber(lineNumber); 93 this.setLineNumber(lineNumber);
76 this.setCharPosition(charPositionInLine); 94 this.setCharPosition(charPositionInLine);
77 - setPartialResolvedStack(new Stack<YangEntityToResolveInfo<T>>()); 95 + setPartialResolvedStack(new Stack<>());
78 } 96 }
79 97
80 /** 98 /**
81 - * Resolve linking with all the ancestors node for a resolution info. 99 + * Resolves linking with all the ancestors node for a resolution info.
82 * 100 *
83 - * @param resolutionInfoNodePrefix module/sub-module prefix 101 + * @param dataModelRootNode module/sub-module node
84 * @throws DataModelException DataModelException a violation of data model 102 * @throws DataModelException DataModelException a violation of data model
85 * rules 103 * rules
86 */ 104 */
87 - public void resolveLinkingForResolutionInfo(String resolutionInfoNodePrefix) 105 + public void resolveLinkingForResolutionInfo(YangReferenceResolver dataModelRootNode)
88 throws DataModelException { 106 throws DataModelException {
89 107
90 - this.resolutionInfoRootNodePrefix = resolutionInfoNodePrefix; 108 + setCurReferenceResolver(dataModelRootNode);
91 109
92 // Current node to resolve, it can be a YANG type or YANG uses. 110 // Current node to resolve, it can be a YANG type or YANG uses.
93 T entityToResolve = getEntityToResolveInfo().getEntityToResolve(); 111 T entityToResolve = getEntityToResolveInfo().getEntityToResolve();
...@@ -142,7 +160,7 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -142,7 +160,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
142 /* 160 /*
143 * If the top of the stack is already linked then 161 * If the top of the stack is already linked then
144 * resolve the references and pop the entity and 162 * resolve the references and pop the entity and
145 - * continue with remaining stack elements to resolve 163 + * continue with remaining stack elements to resolve.
146 */ 164 */
147 resolveTopOfStack(); 165 resolveTopOfStack();
148 getPartialResolvedStack().pop(); 166 getPartialResolvedStack().pop();
...@@ -151,8 +169,7 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -151,8 +169,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
151 169
152 case INTRA_FILE_RESOLVED: { 170 case INTRA_FILE_RESOLVED: {
153 /* 171 /*
154 - * TODO: this needs to be deleted, when inter-file 172 + * Pop the top of the stack.
155 - * resolution is implmeneted
156 */ 173 */
157 getPartialResolvedStack().pop(); 174 getPartialResolvedStack().pop();
158 break; 175 break;
...@@ -187,7 +204,7 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -187,7 +204,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
187 } 204 }
188 205
189 /** 206 /**
190 - * Resolve the current entity in the stack. 207 + * Resolves the current entity in the stack.
191 */ 208 */
192 private void resolveTopOfStack() 209 private void resolveTopOfStack()
193 throws DataModelException { 210 throws DataModelException {
...@@ -207,12 +224,12 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -207,12 +224,12 @@ public class YangResolutionInfo<T> implements LocationInfo {
207 private void linkTopOfStackReferenceUpdateStack() 224 private void linkTopOfStackReferenceUpdateStack()
208 throws DataModelException { 225 throws DataModelException {
209 226
210 - if (!isSelfFileReference()) {
211 /* 227 /*
212 - * TODO: use mojo utilities to load the referred module/sub-module 228 + * Check if self file reference is there, this will not check for the
213 - * and get the reference to the corresponding referred entity 229 + * scenario when prefix is not present and type/uses is present in
230 + * sub-module from include list.
214 */ 231 */
215 - 232 + if (!isCandidateForSelfFileReference()) {
216 ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED); 233 ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
217 return; 234 return;
218 } 235 }
...@@ -240,34 +257,29 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -240,34 +257,29 @@ public class YangResolutionInfo<T> implements LocationInfo {
240 257
241 potentialAncestorWithReferredNode = potentialAncestorWithReferredNode.getParent(); 258 potentialAncestorWithReferredNode = potentialAncestorWithReferredNode.getParent();
242 } 259 }
260 +
261 + /*
262 + * In case prefix is not present it's a candidate for inter-file
263 + * resolution via include list.
264 + */
265 + if (getRefPrefix() == null) {
266 + ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
267 + }
243 } 268 }
244 269
245 /** 270 /**
246 - * Check if the reference in self file or in external file. 271 + * Checks if the reference in self file or in external file.
247 * 272 *
248 * @return true if self file reference, false otherwise 273 * @return true if self file reference, false otherwise
249 * @throws DataModelException a violation of data model rules 274 * @throws DataModelException a violation of data model rules
250 */ 275 */
251 - private boolean isSelfFileReference() 276 + private boolean isCandidateForSelfFileReference() throws DataModelException {
252 - throws DataModelException { 277 + String prefix = getRefPrefix();
253 - String prefix; 278 + return prefix == null || prefix.contentEquals(getCurReferenceResolver().getPrefix());
254 - if (getCurrentEntityToResolveFromStack() instanceof YangType) {
255 - prefix = ((YangType<?>) getCurrentEntityToResolveFromStack()).getPrefix();
256 - } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
257 - prefix = ((YangUses) getCurrentEntityToResolveFromStack()).getPrefix();
258 - } else {
259 - throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
260 - }
261 -
262 - if (prefix == null) {
263 - return true;
264 - }
265 - return prefix.contentEquals(resolutionInfoRootNodePrefix);
266 -
267 } 279 }
268 280
269 /** 281 /**
270 - * Check for the referred node defined in a ancestor scope. 282 + * Checks for the referred node defined in a ancestor scope.
271 * 283 *
272 * @param potentialReferredNode potential referred node 284 * @param potentialReferredNode potential referred node
273 * @return status of resolution and updating the partial resolved stack with 285 * @return status of resolution and updating the partial resolved stack with
...@@ -282,7 +294,7 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -282,7 +294,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
282 if (isReferredNode(potentialReferredNode)) { 294 if (isReferredNode(potentialReferredNode)) {
283 295
284 // Adds reference link of entity to the node under resolution. 296 // Adds reference link of entity to the node under resolution.
285 - addReferredEntityLink(potentialReferredNode); 297 + addReferredEntityLink(potentialReferredNode, LINKED);
286 298
287 /** 299 /**
288 * resolve the reference and update the partial resolution stack 300 * resolve the reference and update the partial resolution stack
...@@ -303,7 +315,7 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -303,7 +315,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
303 } 315 }
304 316
305 /** 317 /**
306 - * Check if the potential referred node is the actual referred node. 318 + * Checks if the potential referred node is the actual referred node.
307 * 319 *
308 * @param potentialReferredNode typedef/grouping node 320 * @param potentialReferredNode typedef/grouping node
309 * @return true if node is of resolve type otherwise false 321 * @return true if node is of resolve type otherwise false
...@@ -334,7 +346,7 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -334,7 +346,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
334 } 346 }
335 347
336 /** 348 /**
337 - * Check if node name is same as name in resolution info, i.e. name of 349 + * Checks if node name is same as name in resolution info, i.e. name of
338 * typedef/grouping is same as name of type/uses. 350 * typedef/grouping is same as name of type/uses.
339 * 351 *
340 * @param node typedef/grouping node 352 * @param node typedef/grouping node
...@@ -366,9 +378,10 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -366,9 +378,10 @@ public class YangResolutionInfo<T> implements LocationInfo {
366 * Adds reference of grouping/typedef in uses/type. 378 * Adds reference of grouping/typedef in uses/type.
367 * 379 *
368 * @param referredNode grouping/typedef node being referred 380 * @param referredNode grouping/typedef node being referred
381 + * @param linkedStatus linked status if success.
369 * @throws DataModelException a violation of data model rules 382 * @throws DataModelException a violation of data model rules
370 */ 383 */
371 - private void addReferredEntityLink(YangNode referredNode) 384 + private void addReferredEntityLink(YangNode referredNode, ResolvableStatus linkedStatus)
372 throws DataModelException { 385 throws DataModelException {
373 if (getCurrentEntityToResolveFromStack() instanceof YangType) { 386 if (getCurrentEntityToResolveFromStack() instanceof YangType) {
374 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) 387 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>)
...@@ -382,7 +395,7 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -382,7 +395,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
382 } 395 }
383 396
384 // Sets the resolution status in inside the type/uses. 397 // Sets the resolution status in inside the type/uses.
385 - ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(LINKED); 398 + ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(linkedStatus);
386 } 399 }
387 400
388 /** 401 /**
...@@ -402,7 +415,7 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -402,7 +415,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
402 if (((YangTypeDef) referredNode).getTypeDefBaseType().getDataType() 415 if (((YangTypeDef) referredNode).getTypeDefBaseType().getDataType()
403 == YangDataTypes.DERIVED) { 416 == YangDataTypes.DERIVED) {
404 417
405 - YangEntityToResolveInfo<YangType<?>> unResolvedEntityInfo = new YangEntityToResolveInfo<YangType<?>>(); 418 + YangEntityToResolveInfo<YangType<?>> unResolvedEntityInfo = new YangEntityToResolveInfo<>();
406 unResolvedEntityInfo.setEntityToResolve(((YangTypeDef) referredNode) 419 unResolvedEntityInfo.setEntityToResolve(((YangTypeDef) referredNode)
407 .getTypeDefBaseType()); 420 .getTypeDefBaseType());
408 unResolvedEntityInfo.setHolderOfEntityToResolve(referredNode); 421 unResolvedEntityInfo.setHolderOfEntityToResolve(referredNode);
...@@ -421,7 +434,7 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -421,7 +434,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
421 } 434 }
422 435
423 /** 436 /**
424 - * Return if there is any unresolved uses in grouping. 437 + * Returns if there is any unresolved uses in grouping.
425 * 438 *
426 * @param node grouping/typedef node 439 * @param node grouping/typedef node
427 */ 440 */
...@@ -433,19 +446,12 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -433,19 +446,12 @@ public class YangResolutionInfo<T> implements LocationInfo {
433 YangNode curNode = node.getChild(); 446 YangNode curNode = node.getChild();
434 while (curNode != null) { 447 while (curNode != null) {
435 if (curNode instanceof YangUses) { 448 if (curNode instanceof YangUses) {
436 - ResolvableStatus curResolveStatus = ((Resolvable) curNode).getResolvableStatus(); 449 + YangEntityToResolveInfo<YangUses> unResolvedEntityInfo = new YangEntityToResolveInfo<>();
437 - if (curResolveStatus == UNRESOLVED) {
438 - /**
439 - * The current uses is not resolved, add it to partial
440 - * resolved stack
441 - */
442 - YangEntityToResolveInfo<YangUses> unResolvedEntityInfo = new YangEntityToResolveInfo<YangUses>();
443 unResolvedEntityInfo.setEntityToResolve((YangUses) curNode); 450 unResolvedEntityInfo.setEntityToResolve((YangUses) curNode);
444 unResolvedEntityInfo.setHolderOfEntityToResolve(node); 451 unResolvedEntityInfo.setHolderOfEntityToResolve(node);
445 addInPartialResolvedStack((YangEntityToResolveInfo<T>) unResolvedEntityInfo); 452 addInPartialResolvedStack((YangEntityToResolveInfo<T>) unResolvedEntityInfo);
446 453
447 } 454 }
448 - }
449 curNode = curNode.getNextSibling(); 455 curNode = curNode.getNextSibling();
450 } 456 }
451 } 457 }
...@@ -503,7 +509,7 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -503,7 +509,7 @@ public class YangResolutionInfo<T> implements LocationInfo {
503 * @param entityToResolveInfo information about the entity that needs to be 509 * @param entityToResolveInfo information about the entity that needs to be
504 * resolved 510 * resolved
505 */ 511 */
506 - public void setEntityToResolveInfo(YangEntityToResolveInfo<T> entityToResolveInfo) { 512 + private void setEntityToResolveInfo(YangEntityToResolveInfo<T> entityToResolveInfo) {
507 this.entityToResolveInfo = entityToResolveInfo; 513 this.entityToResolveInfo = entityToResolveInfo;
508 } 514 }
509 515
...@@ -526,4 +532,324 @@ public class YangResolutionInfo<T> implements LocationInfo { ...@@ -526,4 +532,324 @@ public class YangResolutionInfo<T> implements LocationInfo {
526 public void setCharPosition(int charPositionInLine) { 532 public void setCharPosition(int charPositionInLine) {
527 this.charPosition = charPositionInLine; 533 this.charPosition = charPositionInLine;
528 } 534 }
535 +
536 + /**
537 + * Returns current module/sub-module reference, will be used in inter-file/
538 + * inter-jar scenario to get the import/include list.
539 + *
540 + * @return current module/sub-module reference
541 + */
542 + private YangReferenceResolver getCurReferenceResolver() {
543 + return curReferenceResolver;
544 + }
545 +
546 + /**
547 + * Sets current module/sub-module reference, will be used in inter-file/
548 + * inter-jar scenario to get the import/include list.
549 + *
550 + * @param curReferenceResolver current module/sub-module reference
551 + */
552 + private void setCurReferenceResolver(YangReferenceResolver curReferenceResolver) {
553 + this.curReferenceResolver = curReferenceResolver;
554 + }
555 +
556 + /**
557 + * Performs inter file linking of uses/type referring to typedef/grouping
558 + * of other YANG file.
559 + *
560 + * @param dataModelRootNode module/sub-module node
561 + * @throws DataModelException a violation in data model rule
562 + */
563 + public void linkInterFile(YangReferenceResolver dataModelRootNode)
564 + throws DataModelException {
565 +
566 + setCurReferenceResolver(dataModelRootNode);
567 +
568 + // Current node to resolve, it can be a YANG type or YANG uses.
569 + T entityToResolve = getEntityToResolveInfo().getEntityToResolve();
570 +
571 + // Check if linking is already done
572 + if (entityToResolve instanceof Resolvable) {
573 + Resolvable resolvable = (Resolvable) entityToResolve;
574 + if (resolvable.getResolvableStatus() == RESOLVED) {
575 + return;
576 + }
577 + } else {
578 + throw new DataModelException("Data Model Exception: Entity to resolved is not Resolvable");
579 + }
580 +
581 + // Push the initial entity to resolve in stack.
582 + addInPartialResolvedStack(getEntityToResolveInfo());
583 +
584 + // Inter file linking and resolution.
585 + linkInterFileAndResolve();
586 + }
587 +
588 + /**
589 + * Returns the referenced prefix of entity under resolution.
590 + *
591 + * @return referenced prefix of entity under resolution
592 + * @throws DataModelException a violation in data model rule
593 + */
594 + private String getRefPrefix() throws DataModelException {
595 + String refPrefix;
596 + if (getCurrentEntityToResolveFromStack() instanceof YangType) {
597 + refPrefix = ((YangType<?>) getCurrentEntityToResolveFromStack()).getPrefix();
598 + } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
599 + refPrefix = ((YangUses) getCurrentEntityToResolveFromStack()).getPrefix();
600 + } else {
601 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
602 + }
603 + return refPrefix;
604 + }
605 +
606 + /**
607 + * Performs inter file linking and resolution.
608 + *
609 + * @throws DataModelException a violation in data model rule
610 + */
611 + private void linkInterFileAndResolve()
612 + throws DataModelException {
613 +
614 + while (getPartialResolvedStack().size() != 0) {
615 +
616 + // Current node to resolve, it can be a YANG type or YANG uses.
617 + T entityToResolve = getCurrentEntityToResolveFromStack();
618 + // Check if linking is already done
619 + if (entityToResolve instanceof Resolvable) {
620 +
621 + Resolvable resolvable = (Resolvable) entityToResolve;
622 + switch (resolvable.getResolvableStatus()) {
623 + case RESOLVED: {
624 + /*
625 + * If the entity is already resolved in the stack, then
626 + * pop it and continue with the remaining stack elements
627 + * to resolve
628 + */
629 + getPartialResolvedStack().pop();
630 + break;
631 + }
632 +
633 + case INTER_FILE_LINKED: {
634 + /*
635 + * If the top of the stack is already linked then
636 + * resolve the references and pop the entity and
637 + * continue with remaining stack elements to resolve
638 + */
639 + resolveTopOfStack();
640 + getPartialResolvedStack().pop();
641 + break;
642 + }
643 +
644 + case INTRA_FILE_RESOLVED: {
645 + /*
646 + * If the top of the stack is intra file resolved
647 + * then check if top of stack is linked, if not
648 + * link it using import/include list and push the
649 + * linked referred entity to the stack, otherwise
650 + * only push it to the stack.
651 + */
652 + linkInterFileTopOfStackRefUpdateStack();
653 + break;
654 + }
655 +
656 + default: {
657 + throw new DataModelException("Data Model Exception: Unsupported, linker state");
658 + }
659 +
660 + }
661 +
662 + } else {
663 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
664 + }
665 +
666 + }
667 +
668 + }
669 +
670 + /**
671 + * Links the top of the stack if it's inter-file and update stack.
672 + *
673 + * @throws DataModelException data model error
674 + */
675 + private void linkInterFileTopOfStackRefUpdateStack() throws DataModelException {
676 +
677 + /*
678 + * Obtain the referred node of top of stack entity under resolution
679 + */
680 + T referredNode = getRefNode();
681 +
682 + /*
683 + * Check for null for scenario when it's not linked and inter-file
684 + * linking is required.
685 + */
686 + if (referredNode == null) {
687 +
688 + /*
689 + * Check if prefix is null or not, to identify whether to search
690 + * in import list or include list.
691 + */
692 + if (getRefPrefix() != null && !(getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix()))) {
693 + if (resolveWithImport()) {
694 + return;
695 + }
696 + } else {
697 + if (resolveWithInclude()) {
698 + return;
699 + }
700 + }
701 + // Exception when referred typedef/grouping is not found.
702 + DataModelException dataModelException = new DataModelException("YANG file error: Referred " +
703 + "typedef/grouping for a given type/uses can't be found.");
704 + dataModelException.setLine(getLineNumber());
705 + dataModelException.setCharPosition(getCharPosition());
706 + throw dataModelException;
707 + } else {
708 + /*
709 + * If referred node is already linked, then just change the status
710 + * and push to the stack.
711 + */
712 + ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTER_FILE_LINKED);
713 + addUnresolvedRecursiveReferenceToStack((YangNode) referredNode);
714 + }
715 + }
716 +
717 + /**
718 + * Finds and resolves with include list.
719 + *
720 + * @return true if resolved, false otherwise
721 + * @throws DataModelException a violation in data model rule
722 + */
723 + private boolean resolveWithInclude() throws DataModelException {
724 + /*
725 + * Run through all the nodes in include list and search for referred
726 + * typedef/grouping at the root level.
727 + */
728 + for (YangInclude yangInclude : getCurReferenceResolver().getIncludeList()) {
729 + YangNode linkedNode = null;
730 + if (getCurrentEntityToResolveFromStack() instanceof YangType) {
731 + linkedNode = findRefTypedef(yangInclude.getIncludedNode());
732 + } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
733 + linkedNode = findRefGrouping(yangInclude.getIncludedNode());
734 + }
735 + if (linkedNode != null) {
736 + // Add the link to external entity.
737 + addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
738 + /*
739 + * Update the current reference resolver to external
740 + * module/sub-module containing the referred typedef/grouping.
741 + */
742 + setCurReferenceResolver((YangReferenceResolver) yangInclude.getIncludedNode());
743 + // Add the type/uses of referred typedef/grouping to the stack.
744 + addUnresolvedRecursiveReferenceToStack(linkedNode);
745 + return true;
746 + }
747 + }
748 + // If referred node can't be found return false.
749 + return false;
750 + }
751 +
752 + /**
753 + * Finds and resolves with import list.
754 + *
755 + * @return true if resolved, false otherwise
756 + * @throws DataModelException a violation in data model rule
757 + */
758 + private boolean resolveWithImport() throws DataModelException {
759 + /*
760 + * Run through import list to find the referred typedef/grouping.
761 + */
762 + for (YangImport yangImport : getCurReferenceResolver().getImportList()) {
763 + /*
764 + * Match the prefix attached to entity under resolution with the
765 + * imported/included module/sub-module's prefix. If found, search
766 + * for the referred typedef/grouping at the root level.
767 + */
768 + if (yangImport.getPrefixId().contentEquals(getRefPrefix())) {
769 + YangNode linkedNode = null;
770 + if (getCurrentEntityToResolveFromStack() instanceof YangType) {
771 + linkedNode = findRefTypedef(yangImport.getImportedNode());
772 + } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
773 + linkedNode = findRefGrouping(yangImport.getImportedNode());
774 + }
775 + if (linkedNode != null) {
776 + // Add the link to external entity.
777 + addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
778 + /*
779 + * Update the current reference resolver to external
780 + * module/sub-module containing the referred typedef/grouping.
781 + */
782 + setCurReferenceResolver((YangReferenceResolver) yangImport.getImportedNode());
783 + // Add the type/uses of referred typedef/grouping to the stack.
784 + addUnresolvedRecursiveReferenceToStack(linkedNode);
785 + return true;
786 + }
787 + /*
788 + * If referred node can't be found at root level break for loop,
789 + * and return false.
790 + */
791 + break;
792 + }
793 + }
794 + // If referred node can't be found return false.
795 + return false;
796 + }
797 +
798 + /**
799 + * Returns referred typedef/grouping node.
800 + *
801 + * @return referred typedef/grouping node
802 + * @throws DataModelException a violation in data model rule
803 + */
804 + private T getRefNode() throws DataModelException {
805 + if (getCurrentEntityToResolveFromStack() instanceof YangType) {
806 + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>)
807 + ((YangType<?>) getCurrentEntityToResolveFromStack()).getDataTypeExtendedInfo();
808 + return (T) derivedInfo.getReferredTypeDef();
809 + } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
810 + return (T) ((YangUses) getCurrentEntityToResolveFromStack()).getRefGroup();
811 + } else {
812 + throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
813 + }
814 + }
815 +
816 + /**
817 + * Finds the referred grouping node at the root level of imported/included node.
818 + *
819 + * @param refNode module/sub-module node
820 + * @return referred grouping
821 + */
822 + private YangNode findRefGrouping(YangNode refNode) {
823 + YangNode tmpNode = refNode.getChild();
824 + while (tmpNode != null) {
825 + if (tmpNode instanceof YangGrouping) {
826 + if (tmpNode.getName()
827 + .equals(((YangUses) getCurrentEntityToResolveFromStack()).getName())) {
828 + return tmpNode;
829 + }
830 + }
831 + tmpNode = tmpNode.getNextSibling();
832 + }
833 + return null;
834 + }
835 +
836 + /**
837 + * Finds the referred typedef node at the root level of imported/included node.
838 + *
839 + * @param refNode module/sub-module node
840 + * @return referred typedef
841 + */
842 + private YangNode findRefTypedef(YangNode refNode) {
843 + YangNode tmpNode = refNode.getChild();
844 + while (tmpNode != null) {
845 + if (tmpNode instanceof YangTypeDef) {
846 + if (tmpNode.getName()
847 + .equals(((YangType) getCurrentEntityToResolveFromStack()).getDataTypeName())) {
848 + return tmpNode;
849 + }
850 + }
851 + tmpNode = tmpNode.getNextSibling();
852 + }
853 + return null;
854 + }
529 } 855 }
......
...@@ -15,6 +15,6 @@ ...@@ -15,6 +15,6 @@
15 */ 15 */
16 16
17 /** 17 /**
18 - * Provide inter file and inter jar linking implementation. 18 + * Provide intra/inter file and inter jar linking implementation.
19 */ 19 */
20 package org.onosproject.yangutils.linker.impl; 20 package org.onosproject.yangutils.linker.impl;
......
...@@ -88,6 +88,12 @@ public final class BelongsToListener { ...@@ -88,6 +88,12 @@ public final class BelongsToListener {
88 YangBelongsTo belongstoNode = new YangBelongsTo(); 88 YangBelongsTo belongstoNode = new YangBelongsTo();
89 belongstoNode.setBelongsToModuleName(identifier); 89 belongstoNode.setBelongsToModuleName(identifier);
90 90
91 + // Set the line number and character position in line for the belongs to.
92 + int errorLine = ctx.getStart().getLine();
93 + int errorPosition = ctx.getStart().getCharPositionInLine();
94 + belongstoNode.setLineNumber(errorLine);
95 + belongstoNode.setCharPosition(errorPosition);
96 +
91 // Push belongsto into the stack. 97 // Push belongsto into the stack.
92 listener.getParsedDataStack().push(belongstoNode); 98 listener.getParsedDataStack().push(belongstoNode);
93 } 99 }
......
...@@ -85,6 +85,12 @@ public final class ImportListener { ...@@ -85,6 +85,12 @@ public final class ImportListener {
85 YangImport importNode = new YangImport(); 85 YangImport importNode = new YangImport();
86 importNode.setModuleName(identifier); 86 importNode.setModuleName(identifier);
87 87
88 + // Set the line number and character position in line for the belongs to.
89 + int errorLine = ctx.getStart().getLine();
90 + int errorPosition = ctx.getStart().getCharPositionInLine();
91 + importNode.setLineNumber(errorLine);
92 + importNode.setCharPosition(errorPosition);
93 +
88 // Push import node to the stack. 94 // Push import node to the stack.
89 listener.getParsedDataStack().push(importNode); 95 listener.getParsedDataStack().push(importNode);
90 } 96 }
......
...@@ -85,6 +85,12 @@ public final class IncludeListener { ...@@ -85,6 +85,12 @@ public final class IncludeListener {
85 YangInclude includeNode = new YangInclude(); 85 YangInclude includeNode = new YangInclude();
86 includeNode.setSubModuleName(identifier); 86 includeNode.setSubModuleName(identifier);
87 87
88 + // Set the line number and character position in line for the belongs to.
89 + int errorLine = ctx.getStart().getLine();
90 + int errorPosition = ctx.getStart().getCharPositionInLine();
91 + includeNode.setLineNumber(errorLine);
92 + includeNode.setCharPosition(errorPosition);
93 +
88 listener.getParsedDataStack().push(includeNode); 94 listener.getParsedDataStack().push(includeNode);
89 } 95 }
90 96
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
16 16
17 package org.onosproject.yangutils.parser.impl.listeners; 17 package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 -import org.onosproject.yangutils.datamodel.YangDataTypes;
20 import org.onosproject.yangutils.datamodel.YangDerivedInfo; 19 import org.onosproject.yangutils.datamodel.YangDerivedInfo;
21 import org.onosproject.yangutils.datamodel.YangRangeRestriction; 20 import org.onosproject.yangutils.datamodel.YangRangeRestriction;
22 import org.onosproject.yangutils.datamodel.YangStringRestriction; 21 import org.onosproject.yangutils.datamodel.YangStringRestriction;
...@@ -27,7 +26,9 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; ...@@ -27,7 +26,9 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
27 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 26 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
28 import org.onosproject.yangutils.utils.YangConstructType; 27 import org.onosproject.yangutils.utils.YangConstructType;
29 28
29 +import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
30 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; 30 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
31 +import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
...@@ -115,10 +116,10 @@ public final class LengthRestrictionListener { ...@@ -115,10 +116,10 @@ public final class LengthRestrictionListener {
115 return; 116 return;
116 } 117 }
117 118
118 - if (type.getDataType() != YangDataTypes.STRING) { 119 + if (type.getDataType() != STRING && type.getDataType() != BINARY) {
119 ParserException parserException = new ParserException("YANG file error : " + 120 ParserException parserException = new ParserException("YANG file error : " +
120 YangConstructType.getYangConstructType(LENGTH_DATA) + " name " + ctx.length().getText() + 121 YangConstructType.getYangConstructType(LENGTH_DATA) + " name " + ctx.length().getText() +
121 - " can be used to restrict the built-in type string or types derived from string."); 122 + " can be used to restrict the built-in type string/binary or types derived from string/binary.");
122 parserException.setLine(ctx.getStart().getLine()); 123 parserException.setLine(ctx.getStart().getLine());
123 parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); 124 parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
124 throw parserException; 125 throw parserException;
...@@ -127,14 +128,18 @@ public final class LengthRestrictionListener { ...@@ -127,14 +128,18 @@ public final class LengthRestrictionListener {
127 YangRangeRestriction lengthRestriction = processLengthRestriction(null, ctx.getStart().getLine(), 128 YangRangeRestriction lengthRestriction = processLengthRestriction(null, ctx.getStart().getLine(),
128 ctx.getStart().getCharPositionInLine(), false, ctx.length().getText()); 129 ctx.getStart().getCharPositionInLine(), false, ctx.length().getText());
129 130
131 + if (type.getDataType() == STRING) {
130 YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo(); 132 YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
131 -
132 if (stringRestriction == null) { 133 if (stringRestriction == null) {
133 stringRestriction = new YangStringRestriction(); 134 stringRestriction = new YangStringRestriction();
134 type.setDataTypeExtendedInfo(stringRestriction); 135 type.setDataTypeExtendedInfo(stringRestriction);
135 } 136 }
136 137
137 stringRestriction.setLengthRestriction(lengthRestriction); 138 stringRestriction.setLengthRestriction(lengthRestriction);
139 + } else {
140 + type.setDataTypeExtendedInfo(lengthRestriction);
141 + }
142 +
138 listener.getParsedDataStack().push(lengthRestriction); 143 listener.getParsedDataStack().push(lengthRestriction);
139 } 144 }
140 145
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
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.YangReferenceResolver; 19 +import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
20 import org.onosproject.yangutils.datamodel.YangModule; 20 import org.onosproject.yangutils.datamodel.YangModule;
21 import org.onosproject.yangutils.datamodel.YangRevision; 21 import org.onosproject.yangutils.datamodel.YangRevision;
22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
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.YangReferenceResolver; 19 +import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
20 import org.onosproject.yangutils.datamodel.YangRevision; 20 import org.onosproject.yangutils.datamodel.YangRevision;
21 import org.onosproject.yangutils.datamodel.YangSubModule; 21 import org.onosproject.yangutils.datamodel.YangSubModule;
22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
......
...@@ -22,26 +22,24 @@ import org.onosproject.yangutils.datamodel.YangLeaf; ...@@ -22,26 +22,24 @@ import org.onosproject.yangutils.datamodel.YangLeaf;
22 import org.onosproject.yangutils.datamodel.YangLeafList; 22 import org.onosproject.yangutils.datamodel.YangLeafList;
23 import org.onosproject.yangutils.datamodel.YangNode; 23 import org.onosproject.yangutils.datamodel.YangNode;
24 import org.onosproject.yangutils.datamodel.YangNodeIdentifier; 24 import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
25 -import org.onosproject.yangutils.datamodel.YangResolutionInfo;
26 import org.onosproject.yangutils.datamodel.YangType; 25 import org.onosproject.yangutils.datamodel.YangType;
27 import org.onosproject.yangutils.datamodel.YangTypeDef; 26 import org.onosproject.yangutils.datamodel.YangTypeDef;
28 import org.onosproject.yangutils.datamodel.YangUnion; 27 import org.onosproject.yangutils.datamodel.YangUnion;
29 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 28 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
29 +import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
30 import org.onosproject.yangutils.parser.Parsable; 30 import org.onosproject.yangutils.parser.Parsable;
31 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 31 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
32 import org.onosproject.yangutils.parser.exceptions.ParserException; 32 import org.onosproject.yangutils.parser.exceptions.ParserException;
33 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 33 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
34 34
35 -import static org.onosproject.yangutils.datamodel.ResolvableStatus.UNRESOLVED;
36 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo; 35 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
37 import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; 36 import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
38 import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangType; 37 import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangType;
38 +import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED;
39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
40 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 40 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
41 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction 41 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
42 - .constructExtendedListenerErrorMessage; 42 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
43 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
44 - .constructListenerErrorMessage;
45 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 43 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
46 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; 44 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
47 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 45 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
...@@ -190,6 +188,8 @@ public final class TypeListener { ...@@ -190,6 +188,8 @@ public final class TypeListener {
190 YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>(); 188 YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
191 ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo); 189 ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
192 190
191 + type.setResolvableStatus(UNRESOLVED);
192 +
193 // Add resolution information to the list 193 // Add resolution information to the list
194 YangResolutionInfo resolutionInfo = 194 YangResolutionInfo resolutionInfo =
195 new YangResolutionInfo<YangType>(type, unionNode, errorLine, errorPosition); 195 new YangResolutionInfo<YangType>(type, unionNode, errorLine, errorPosition);
...@@ -211,13 +211,15 @@ public final class TypeListener { ...@@ -211,13 +211,15 @@ public final class TypeListener {
211 YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>(); 211 YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
212 ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo); 212 ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
213 213
214 + type.setResolvableStatus(UNRESOLVED);
215 +
214 // Add resolution information to the list 216 // Add resolution information to the list
215 YangResolutionInfo resolutionInfo = 217 YangResolutionInfo resolutionInfo =
216 new YangResolutionInfo<YangType>(type, typeDef, errorLine, errorPosition); 218 new YangResolutionInfo<YangType>(type, typeDef, errorLine, errorPosition);
217 addToResolutionList(resolutionInfo, ctx); 219 addToResolutionList(resolutionInfo, ctx);
218 } 220 }
219 break; 221 break;
220 - //TODO: deviate replacement statement.case TYPEDEF_DATA: //TODO 222 + //TODO: deviate replacement statement.
221 223
222 default: 224 default:
223 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA, 225 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
...@@ -260,7 +262,7 @@ public final class TypeListener { ...@@ -260,7 +262,7 @@ public final class TypeListener {
260 addResolutionInfo(resolutionInfo); 262 addResolutionInfo(resolutionInfo);
261 } catch (DataModelException e) { 263 } catch (DataModelException e) {
262 throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, 264 throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
263 - TYPE_DATA, ctx.string().getText(), EXIT, e.getMessage())); 265 + TYPE_DATA, ctx.string().getText(), ENTRY, e.getMessage()));
264 } 266 }
265 } 267 }
266 } 268 }
......
...@@ -26,7 +26,7 @@ import org.onosproject.yangutils.datamodel.YangNode; ...@@ -26,7 +26,7 @@ import org.onosproject.yangutils.datamodel.YangNode;
26 import org.onosproject.yangutils.datamodel.YangNodeIdentifier; 26 import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
27 import org.onosproject.yangutils.datamodel.YangNotification; 27 import org.onosproject.yangutils.datamodel.YangNotification;
28 import org.onosproject.yangutils.datamodel.YangOutput; 28 import org.onosproject.yangutils.datamodel.YangOutput;
29 -import org.onosproject.yangutils.datamodel.YangResolutionInfo; 29 +import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
30 import org.onosproject.yangutils.datamodel.YangSubModule; 30 import org.onosproject.yangutils.datamodel.YangSubModule;
31 import org.onosproject.yangutils.datamodel.YangUses; 31 import org.onosproject.yangutils.datamodel.YangUses;
32 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 32 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
16 16
17 package org.onosproject.yangutils.plugin.manager; 17 package org.onosproject.yangutils.plugin.manager;
18 18
19 +import java.util.Objects;
20 +import org.onosproject.yangutils.linker.impl.ResolvableStatus;
19 import org.onosproject.yangutils.datamodel.YangNode; 21 import org.onosproject.yangutils.datamodel.YangNode;
20 22
21 /** 23 /**
...@@ -29,11 +31,21 @@ public class YangFileInfo { ...@@ -29,11 +31,21 @@ public class YangFileInfo {
29 private String yangFileName; 31 private String yangFileName;
30 32
31 /** 33 /**
34 + * YANG file revision.
35 + */
36 + private String revision;
37 +
38 + /**
32 * Data model node after parsing YANG file. 39 * Data model node after parsing YANG file.
33 */ 40 */
34 private YangNode rootNode; 41 private YangNode rootNode;
35 42
36 /** 43 /**
44 + * Resolution status of YANG file.
45 + */
46 + private ResolvableStatus resolvableStatus;
47 +
48 + /**
37 * Returns data model node for YANG file. 49 * Returns data model node for YANG file.
38 * 50 *
39 * @return data model node for YANG file 51 * @return data model node for YANG file
...@@ -68,4 +80,58 @@ public class YangFileInfo { ...@@ -68,4 +80,58 @@ public class YangFileInfo {
68 public void setYangFileName(String yangFileName) { 80 public void setYangFileName(String yangFileName) {
69 this.yangFileName = yangFileName; 81 this.yangFileName = yangFileName;
70 } 82 }
83 +
84 + /**
85 + * Returns the revision of YANG file.
86 + *
87 + * @return revision of YANG file
88 + */
89 + public String getRevision() {
90 + return revision;
91 + }
92 +
93 + /**
94 + * Sets the revision of YANG file.
95 + *
96 + * @param revision revision of YANG file
97 + */
98 + public void setRevision(String revision) {
99 + this.revision = revision;
100 + }
101 +
102 + /**
103 + * Returns the resolution status of YANG file.
104 + *
105 + * @return resolution status of YANG file
106 + */
107 + public ResolvableStatus getResolvableStatus() {
108 + return resolvableStatus;
109 + }
110 +
111 + /**
112 + * Sets the resolution status of YANG file.
113 + *
114 + * @param resolvableStatus resolution status of YANG file
115 + */
116 + public void setResolvableStatus(ResolvableStatus resolvableStatus) {
117 + this.resolvableStatus = resolvableStatus;
118 + }
119 +
120 + @Override
121 + public boolean equals(Object obj) {
122 +
123 + if (this == obj) {
124 + return true;
125 + }
126 + if (obj instanceof YangFileInfo) {
127 + final YangFileInfo other = (YangFileInfo) obj;
128 + return Objects.equals(this.yangFileName, other.yangFileName);
129 + }
130 + return false;
131 + }
132 +
133 + @Override
134 + public int hashCode() {
135 + return Objects.hashCode(this.yangFileName);
136 + }
71 } 137 }
......
...@@ -17,9 +17,10 @@ ...@@ -17,9 +17,10 @@
17 package org.onosproject.yangutils.plugin.manager; 17 package org.onosproject.yangutils.plugin.manager;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 +import java.util.HashSet;
20 import java.util.Iterator; 21 import java.util.Iterator;
21 import java.util.List; 22 import java.util.List;
22 - 23 +import java.util.Set;
23 import org.apache.maven.plugin.AbstractMojo; 24 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoExecutionException; 25 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugin.MojoFailureException; 26 import org.apache.maven.plugin.MojoFailureException;
...@@ -28,8 +29,9 @@ import org.apache.maven.plugins.annotations.Mojo; ...@@ -28,8 +29,9 @@ import org.apache.maven.plugins.annotations.Mojo;
28 import org.apache.maven.plugins.annotations.Parameter; 29 import org.apache.maven.plugins.annotations.Parameter;
29 import org.apache.maven.project.MavenProject; 30 import org.apache.maven.project.MavenProject;
30 import org.onosproject.yangutils.datamodel.YangNode; 31 import org.onosproject.yangutils.datamodel.YangNode;
31 -import org.onosproject.yangutils.datamodel.YangSubModule; 32 +import org.onosproject.yangutils.linker.YangLinker;
32 -import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 33 +import org.onosproject.yangutils.linker.exceptions.LinkerException;
34 +import org.onosproject.yangutils.linker.impl.YangLinkerManager;
33 import org.onosproject.yangutils.parser.YangUtilsParser; 35 import org.onosproject.yangutils.parser.YangUtilsParser;
34 import org.onosproject.yangutils.parser.exceptions.ParserException; 36 import org.onosproject.yangutils.parser.exceptions.ParserException;
35 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 37 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
...@@ -48,10 +50,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; ...@@ -48,10 +50,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
48 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 50 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
49 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 51 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
50 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource; 52 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource;
51 -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
52 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget; 53 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget;
54 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
53 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory; 55 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory;
54 -import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findBelongsToModuleNode;
55 56
56 /** 57 /**
57 * Represents ONOS YANG utility maven plugin. 58 * Represents ONOS YANG utility maven plugin.
...@@ -63,6 +64,14 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findBelon ...@@ -63,6 +64,14 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findBelon
63 requiresProject = true) 64 requiresProject = true)
64 public class YangUtilManager extends AbstractMojo { 65 public class YangUtilManager extends AbstractMojo {
65 66
67 + private YangNode rootNode;
68 + // YANG file information set.
69 + private Set<YangFileInfo> yangFileInfoSet = new HashSet<>();
70 + private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
71 + private YangLinker yangLinker = new YangLinkerManager();
72 +
73 + private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
74 +
66 /** 75 /**
67 * Source directory for YANG files. 76 * Source directory for YANG files.
68 */ 77 */
...@@ -117,12 +126,6 @@ public class YangUtilManager extends AbstractMojo { ...@@ -117,12 +126,6 @@ public class YangUtilManager extends AbstractMojo {
117 @Component 126 @Component
118 private BuildContext context; 127 private BuildContext context;
119 128
120 - private static final String DEFAULT_PKG = SLASH
121 - + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
122 -
123 - private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
124 - private YangNode rootNode;
125 -
126 @Override 129 @Override
127 public void execute() throws MojoExecutionException, MojoFailureException { 130 public void execute() throws MojoExecutionException, MojoFailureException {
128 131
...@@ -136,47 +139,40 @@ public class YangUtilManager extends AbstractMojo { ...@@ -136,47 +139,40 @@ public class YangUtilManager extends AbstractMojo {
136 139
137 String searchDir = getDirectory(baseDir, yangFilesDir); 140 String searchDir = getDirectory(baseDir, yangFilesDir);
138 String codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH; 141 String codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH;
142 +
143 + // Creates conflict resolver and set values to it.
139 YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil(); 144 YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
140 conflictResolver.setReplacementForPeriod(replacementForPeriod); 145 conflictResolver.setReplacementForPeriod(replacementForPeriod);
141 conflictResolver.setReplacementForHyphen(replacementForHyphen); 146 conflictResolver.setReplacementForHyphen(replacementForHyphen);
142 conflictResolver.setReplacementForUnderscore(replacementForUnderscore); 147 conflictResolver.setReplacementForUnderscore(replacementForUnderscore);
143 - List<YangFileInfo> yangFileInfo = YangFileScanner.getYangFiles(searchDir);
144 - if (yangFileInfo == null || yangFileInfo.isEmpty()) {
145 - // no files to translate
146 - return;
147 - }
148 YangPluginConfig yangPlugin = new YangPluginConfig(); 148 YangPluginConfig yangPlugin = new YangPluginConfig();
149 yangPlugin.setCodeGenDir(codeGenDir); 149 yangPlugin.setCodeGenDir(codeGenDir);
150 yangPlugin.setConflictResolver(conflictResolver); 150 yangPlugin.setConflictResolver(conflictResolver);
151 151
152 - Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator(); 152 + /*
153 - while (yangFileIterator.hasNext()) { 153 + * Obtain the YANG files at a path mentioned in plugin and creates
154 - YangFileInfo yangFile = yangFileIterator.next(); 154 + * YANG file information set.
155 - try { 155 + */
156 - YangNode yangNode = yangUtilsParser.getDataModel(yangFile.getYangFileName()); 156 + createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
157 - yangFile.setRootNode(yangNode);
158 - setRootNode(yangNode);
159 - } catch (ParserException e) {
160 - String logInfo = "Error in file: " + e.getFileName();
161 - if (e.getLineNumber() != 0) {
162 - logInfo = logInfo + " at line: " + e.getLineNumber() + " at position: "
163 - + e.getCharPositionInLine();
164 157
165 - } 158 + // Check if there are any file to translate, if not return.
166 - if (e.getMessage() != null) { 159 + if (getYangFileInfoSet() == null || getYangFileInfoSet().isEmpty()) {
167 - logInfo = logInfo + NEW_LINE + e.getMessage(); 160 + // No files to translate
168 - } 161 + return;
169 - getLog().info(logInfo);
170 - throw e;
171 - }
172 } 162 }
173 163
174 - resolveLinkingForSubModule(yangFileInfo); 164 + //Carry out the parsing for all the YANG files.
165 + parseYangFileInfoSet();
175 166
176 - translateToJava(yangFileInfo, yangPlugin); 167 + // Resolve dependencies using linker.
168 + resolveDependenciesUsingLinker();
169 +
170 + // Perform translation to JAVA.
171 + translateToJava(getYangFileInfoSet(), yangPlugin);
177 172
178 addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context); 173 addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context);
179 - copyYangFilesToTarget(yangFileInfo, getDirectory(baseDir, outputDirectory), project); 174 +
175 + copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project);
180 } catch (Exception e) { 176 } catch (Exception e) {
181 String fileName = ""; 177 String fileName = "";
182 if (e instanceof TranslatorException) { 178 if (e instanceof TranslatorException) {
...@@ -196,22 +192,45 @@ public class YangUtilManager extends AbstractMojo { ...@@ -196,22 +192,45 @@ public class YangUtilManager extends AbstractMojo {
196 } 192 }
197 193
198 /** 194 /**
199 - * Set current project. 195 + * Links all the provided with the YANG file info set.
200 * 196 *
201 - * @param curProject maven project 197 + * @throws MojoExecutionException a violation in mojo excecution
202 */ 198 */
203 - public void setCurrentProject(MavenProject curProject) { 199 + public void resolveDependenciesUsingLinker() throws MojoExecutionException {
204 - project = curProject; 200 + for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
205 - 201 + try {
202 + yangLinker.resolveDependencies(getYangFileInfoSet());
203 + } catch (LinkerException e) {
204 + throw new MojoExecutionException(e.getMessage());
205 + }
206 + }
206 } 207 }
207 208
208 /** 209 /**
209 - * Returns current project. 210 + * Parses all the provided YANG files and generates YANG data model tree.
210 * 211 *
211 - * @return current project 212 + * @throws IOException a violation in IO
212 */ 213 */
213 - public MavenProject getCurrentProject() { 214 + public void parseYangFileInfoSet() throws IOException {
214 - return project; 215 + for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
216 + try {
217 + YangNode yangNode = yangUtilsParser.getDataModel(yangFileInfo.getYangFileName());
218 + yangFileInfo.setRootNode(yangNode);
219 + setRootNode(yangNode);
220 + } catch (ParserException e) {
221 + String logInfo = "Error in file: " + e.getFileName();
222 + if (e.getLineNumber() != 0) {
223 + logInfo = logInfo + " at line: " + e.getLineNumber() + " at position: "
224 + + e.getCharPositionInLine();
225 +
226 + }
227 + if (e.getMessage() != null) {
228 + logInfo = logInfo + NEW_LINE + e.getMessage();
229 + }
230 + getLog().info(logInfo);
231 + throw e;
232 + }
233 + }
215 } 234 }
216 235
217 /** 236 /**
...@@ -219,7 +238,7 @@ public class YangUtilManager extends AbstractMojo { ...@@ -219,7 +238,7 @@ public class YangUtilManager extends AbstractMojo {
219 * 238 *
220 * @return current root YANG node of data-model tree 239 * @return current root YANG node of data-model tree
221 */ 240 */
222 - public YangNode getRootNode() { 241 + private YangNode getRootNode() {
223 return rootNode; 242 return rootNode;
224 } 243 }
225 244
...@@ -228,44 +247,55 @@ public class YangUtilManager extends AbstractMojo { ...@@ -228,44 +247,55 @@ public class YangUtilManager extends AbstractMojo {
228 * 247 *
229 * @param rootNode current root YANG node of data-model tree 248 * @param rootNode current root YANG node of data-model tree
230 */ 249 */
231 - public void setRootNode(YangNode rootNode) { 250 + private void setRootNode(YangNode rootNode) {
232 this.rootNode = rootNode; 251 this.rootNode = rootNode;
233 } 252 }
234 253
235 /** 254 /**
236 * Translates to java code corresponding to the YANG schema. 255 * Translates to java code corresponding to the YANG schema.
237 * 256 *
238 - * @param yangFileInfo YANG file information 257 + * @param yangFileInfoSet YANG file information
239 * @param yangPlugin YANG plugin config 258 * @param yangPlugin YANG plugin config
240 * @throws IOException when fails to generate java code file the current 259 * @throws IOException when fails to generate java code file the current
241 * node 260 * node
242 */ 261 */
243 - public static void translateToJava(List<YangFileInfo> yangFileInfo, YangPluginConfig yangPlugin) 262 + public void translateToJava(Set<YangFileInfo> yangFileInfoSet, YangPluginConfig yangPlugin)
244 throws IOException { 263 throws IOException {
245 - Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator(); 264 + Iterator<YangFileInfo> yangFileIterator = yangFileInfoSet.iterator();
246 while (yangFileIterator.hasNext()) { 265 while (yangFileIterator.hasNext()) {
247 - YangFileInfo yangFile = yangFileIterator.next(); 266 + YangFileInfo yangFileInfo = yangFileIterator.next();
248 - generateJavaCode(yangFile.getRootNode(), yangPlugin, yangFile.getYangFileName()); 267 + generateJavaCode(yangFileInfo.getRootNode(), yangPlugin, yangFileInfo.getYangFileName());
249 } 268 }
250 } 269 }
251 270
252 /** 271 /**
253 - * Resolves sub-module linking. 272 + * Creates a YANG file info set.
254 * 273 *
255 - * @param yangFileInfo YANG file information 274 + * @param yangFileList YANG files list
256 - * @throws DataModelException when belongs-to module node is not found
257 */ 275 */
258 - public static void resolveLinkingForSubModule(List<YangFileInfo> yangFileInfo) throws DataModelException { 276 + public void createYangFileInfoSet(List<String> yangFileList) {
259 - Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator(); 277 + for (String yangFile : yangFileList) {
260 - while (yangFileIterator.hasNext()) { 278 + YangFileInfo yangFileInfo = new YangFileInfo();
261 - YangFileInfo yangFile = yangFileIterator.next(); 279 + yangFileInfo.setYangFileName(yangFile);
262 - YangNode yangNode = yangFile.getRootNode(); 280 + getYangFileInfoSet().add(yangFileInfo);
263 - if (yangNode instanceof YangSubModule) { 281 + }
264 - String belongsToModuleName = ((YangSubModule) yangNode).getBelongsTo()
265 - .getBelongsToModuleName();
266 - YangNode moduleNode = findBelongsToModuleNode(yangFileInfo, belongsToModuleName);
267 - ((YangSubModule) yangNode).getBelongsTo().setModuleNode(moduleNode);
268 } 282 }
283 +
284 + /**
285 + * Returns the YANG file info set.
286 + *
287 + * @return the YANG file info set
288 + */
289 + public Set<YangFileInfo> getYangFileInfoSet() {
290 + return yangFileInfoSet;
269 } 291 }
292 +
293 + /**
294 + * Sets the YANG file info set.
295 + *
296 + * @param yangFileInfoSet the YANG file info set
297 + */
298 + public void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) {
299 + this.yangFileInfoSet = yangFileInfoSet;
270 } 300 }
271 } 301 }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
16 package org.onosproject.yangutils.translator.tojava.javamodel; 16 package org.onosproject.yangutils.translator.tojava.javamodel;
17 17
18 import java.io.IOException; 18 import java.io.IOException;
19 -
20 import org.onosproject.yangutils.datamodel.YangBelongsTo; 19 import org.onosproject.yangutils.datamodel.YangBelongsTo;
21 import org.onosproject.yangutils.datamodel.YangModule; 20 import org.onosproject.yangutils.datamodel.YangModule;
22 import org.onosproject.yangutils.datamodel.YangSubModule; 21 import org.onosproject.yangutils.datamodel.YangSubModule;
...@@ -108,7 +107,7 @@ public class YangJavaSubModule ...@@ -108,7 +107,7 @@ public class YangJavaSubModule
108 * belongs 107 * belongs
109 * @return the name space string of the module. 108 * @return the name space string of the module.
110 */ 109 */
111 - private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) { 110 + public String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
112 return ((YangModule) belongsToInfo.getModuleNode()).getNameSpace().getUri(); 111 return ((YangModule) belongsToInfo.getModuleNode()).getNameSpace().getUri();
113 } 112 }
114 113
......
...@@ -24,14 +24,17 @@ import org.onosproject.yangutils.datamodel.YangType; ...@@ -24,14 +24,17 @@ import org.onosproject.yangutils.datamodel.YangType;
24 import org.onosproject.yangutils.datamodel.YangTypeDef; 24 import org.onosproject.yangutils.datamodel.YangTypeDef;
25 import org.onosproject.yangutils.datamodel.YangUnion; 25 import org.onosproject.yangutils.datamodel.YangUnion;
26 import org.onosproject.yangutils.translator.exception.TranslatorException; 26 import org.onosproject.yangutils.translator.exception.TranslatorException;
27 -import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
28 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 27 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
28 +import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
29 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration; 29 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
30 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
31 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
30 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef; 32 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
31 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion; 33 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
32 34
33 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 35 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
34 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; 36 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
37 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
35 import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; 38 import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
36 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; 39 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
37 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; 40 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
...@@ -424,6 +427,20 @@ public final class AttributesJavaDataType { ...@@ -424,6 +427,20 @@ public final class AttributesJavaDataType {
424 throw new TranslatorException("invalid child node is being processed."); 427 throw new TranslatorException("invalid child node is being processed.");
425 } 428 }
426 JavaFileInfo parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo(); 429 JavaFileInfo parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
430 + if (parentInfo.getPackage() == null) {
431 + if (parent instanceof YangJavaModule) {
432 + YangJavaModule module = (YangJavaModule) parent;
433 + String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module
434 + .getRevision().getRevDate());
435 + return modulePkg + PERIOD + getCamelCase(module.getName(), null).toLowerCase();
436 + } else if (parent instanceof YangJavaSubModule) {
437 + YangJavaSubModule submodule = (YangJavaSubModule) parent;
438 + String subModulePkg = getRootPackage(submodule.getVersion(),
439 + submodule.getNameSpaceFromModule(submodule.getBelongsTo()),
440 + submodule.getRevision().getRevDate());
441 + return subModulePkg + PERIOD + getCamelCase(submodule.getName(), null).toLowerCase();
442 + }
443 + }
427 return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase(); 444 return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase();
428 } 445 }
429 } 446 }
......
...@@ -21,7 +21,6 @@ import java.io.IOException; ...@@ -21,7 +21,6 @@ import java.io.IOException;
21 import java.util.LinkedList; 21 import java.util.LinkedList;
22 import java.util.List; 22 import java.util.List;
23 import java.util.Stack; 23 import java.util.Stack;
24 -import org.onosproject.yangutils.plugin.manager.YangFileInfo;
25 24
26 /** 25 /**
27 * Represents utility for searching the files in a directory. 26 * Represents utility for searching the files in a directory.
...@@ -52,7 +51,7 @@ public final class YangFileScanner { ...@@ -52,7 +51,7 @@ public final class YangFileScanner {
52 } 51 }
53 52
54 /** 53 /**
55 - * Returns the list of YANG file information. 54 + * Returns the list of YANG file.
56 * 55 *
57 * @param root specified directory 56 * @param root specified directory
58 * @return list of YANG file information 57 * @return list of YANG file information
...@@ -60,15 +59,9 @@ public final class YangFileScanner { ...@@ -60,15 +59,9 @@ public final class YangFileScanner {
60 * @throws IOException when files get deleted while performing the 59 * @throws IOException when files get deleted while performing the
61 * operations 60 * operations
62 */ 61 */
63 - public static List<YangFileInfo> getYangFiles(String root) throws IOException { 62 + public static List<String> getYangFiles(String root) throws IOException {
64 List<String> yangFiles = getFiles(root, YANG_FILE_EXTENTION); 63 List<String> yangFiles = getFiles(root, YANG_FILE_EXTENTION);
65 - List<YangFileInfo> fileInfo = new LinkedList<>(); 64 + return yangFiles;
66 - for (String yangFile : yangFiles) {
67 - YangFileInfo yangFileInfo = new YangFileInfo();
68 - yangFileInfo.setYangFileName(yangFile);
69 - fileInfo.add(yangFileInfo);
70 - }
71 - return fileInfo;
72 } 65 }
73 66
74 /** 67 /**
......
...@@ -23,18 +23,20 @@ import java.io.IOException; ...@@ -23,18 +23,20 @@ import java.io.IOException;
23 import java.nio.file.Files; 23 import java.nio.file.Files;
24 import java.nio.file.StandardCopyOption; 24 import java.nio.file.StandardCopyOption;
25 import java.util.ArrayList; 25 import java.util.ArrayList;
26 -import java.util.LinkedList;
27 import java.util.Iterator; 26 import java.util.Iterator;
28 import java.util.List; 27 import java.util.List;
28 +import java.util.LinkedList;
29 import java.util.Stack; 29 import java.util.Stack;
30 +import java.util.Set;
30 31
31 import org.apache.commons.io.FileUtils; 32 import org.apache.commons.io.FileUtils;
32 import org.apache.maven.model.Resource; 33 import org.apache.maven.model.Resource;
33 import org.apache.maven.project.MavenProject; 34 import org.apache.maven.project.MavenProject;
35 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
36 +
34 import org.slf4j.Logger; 37 import org.slf4j.Logger;
35 import org.sonatype.plexus.build.incremental.BuildContext; 38 import org.sonatype.plexus.build.incremental.BuildContext;
36 39
37 -import org.onosproject.yangutils.plugin.manager.YangFileInfo;
38 import static org.onosproject.yangutils.utils.UtilConstants.COMMA; 40 import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
39 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; 41 import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
40 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 42 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
...@@ -247,12 +249,12 @@ public final class YangIoUtils { ...@@ -247,12 +249,12 @@ public final class YangIoUtils {
247 /** 249 /**
248 * Copies YANG files to the current project's output directory. 250 * Copies YANG files to the current project's output directory.
249 * 251 *
250 - * @param yangFileInfo list of YANG files 252 + * @param yangFileInfo set of YANG files
251 * @param outputDir project's output directory 253 * @param outputDir project's output directory
252 * @param project maven project 254 * @param project maven project
253 * @throws IOException when fails to copy files to destination resource directory 255 * @throws IOException when fails to copy files to destination resource directory
254 */ 256 */
255 - public static void copyYangFilesToTarget(List<YangFileInfo> yangFileInfo, String outputDir, MavenProject project) 257 + public static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
256 throws IOException { 258 throws IOException {
257 259
258 List<File> files = getListOfFile(yangFileInfo); 260 List<File> files = getListOfFile(yangFileInfo);
...@@ -274,10 +276,10 @@ public final class YangIoUtils { ...@@ -274,10 +276,10 @@ public final class YangIoUtils {
274 /** 276 /**
275 * Provides a list of files from list of strings. 277 * Provides a list of files from list of strings.
276 * 278 *
277 - * @param yangFileInfo list of yang file information 279 + * @param yangFileInfo set of yang file information
278 * @return list of files 280 * @return list of files
279 */ 281 */
280 - private static List<File> getListOfFile(List<YangFileInfo> yangFileInfo) { 282 + private static List<File> getListOfFile(Set<YangFileInfo> yangFileInfo) {
281 List<File> files = new ArrayList<>(); 283 List<File> files = new ArrayList<>();
282 Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator(); 284 Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
283 while (yangFileIterator.hasNext()) { 285 while (yangFileIterator.hasNext()) {
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.linker;
18 +
19 +import java.io.IOException;
20 +import java.util.Iterator;
21 +import java.util.ListIterator;
22 +import org.apache.maven.plugin.MojoExecutionException;
23 +import org.junit.Test;
24 +import org.onosproject.yangutils.datamodel.YangDataTypes;
25 +import org.onosproject.yangutils.datamodel.YangDerivedInfo;
26 +import org.onosproject.yangutils.datamodel.YangGrouping;
27 +import org.onosproject.yangutils.datamodel.YangLeaf;
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.datamodel.YangUses;
33 +import org.onosproject.yangutils.linker.impl.ResolvableStatus;
34 +import org.onosproject.yangutils.linker.impl.YangLinkerManager;
35 +import org.onosproject.yangutils.parser.exceptions.ParserException;
36 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
37 +import org.onosproject.yangutils.plugin.manager.YangFileInfo;
38 +import org.onosproject.yangutils.plugin.manager.YangUtilManager;
39 +import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
40 +
41 +import static org.hamcrest.CoreMatchers.nullValue;
42 +import static org.hamcrest.MatcherAssert.assertThat;
43 +import static org.hamcrest.core.Is.is;
44 +import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
45 +import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
46 +import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
47 +import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
48 +
49 +/**
50 + * Test cases for testing inter file linking.
51 + */
52 +public class InterFileLinkingTest {
53 +
54 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
55 + private final YangUtilManager utilManager = new YangUtilManager();
56 + private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
57 +
58 + /**
59 + * Checks inter file type linking.
60 + */
61 + @Test
62 + public void processInterFileTypeLinking()
63 + throws IOException, ParserException, MojoExecutionException {
64 +
65 + String searchDir = "src/test/resources/interfiletype";
66 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
67 + utilManager.parseYangFileInfoSet();
68 +
69 + YangNode refNode = null;
70 + YangNode selfNode = null;
71 +
72 + // Add references to import list.
73 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
74 +
75 + // Carry out inter-file linking.
76 + yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
77 +
78 + Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
79 +
80 + YangFileInfo yangFileInfo = yangFileInfoIterator.next();
81 +
82 + if (yangFileInfo.getRootNode().getName().equals("module1")) {
83 + selfNode = yangFileInfo.getRootNode();
84 + refNode = yangFileInfoIterator.next().getRootNode();
85 + } else {
86 + refNode = yangFileInfo.getRootNode();
87 + selfNode = yangFileInfoIterator.next().getRootNode();
88 + }
89 +
90 + // Check whether the data model tree returned is of type module.
91 + assertThat(selfNode instanceof YangModule, is(true));
92 +
93 + // Check whether the node type is set properly to module.
94 + assertThat(selfNode.getNodeType(), is(MODULE_NODE));
95 +
96 + // Check whether the module name is set correctly.
97 + YangModule yangNode = (YangModule) selfNode;
98 + assertThat(yangNode.getName(), is("module1"));
99 +
100 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
101 + YangLeaf leafInfo = leafIterator.next();
102 +
103 + assertThat(leafInfo.getName(), is("invalid-interval"));
104 + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
105 + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
106 +
107 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
108 + is((YangTypeDef) refNode.getChild()));
109 +
110 + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
111 +
112 + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
113 +
114 + // Check for the effective built-in type.
115 + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
116 +
117 + // Check for the restriction.
118 + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
119 + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
120 + assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
121 + assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
122 + }
123 +
124 + /**
125 + * Checks inter file uses linking.
126 + */
127 + @Test
128 + public void processInterFileUsesLinking()
129 + throws IOException, ParserException, MojoExecutionException {
130 +
131 + String searchDir = "src/test/resources/interfileuses";
132 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
133 + utilManager.parseYangFileInfoSet();
134 +
135 + YangNode refNode = null;
136 + YangNode selfNode = null;
137 +
138 + // Add references to import list.
139 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
140 +
141 + // Carry out inter-file linking.
142 + yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
143 +
144 + Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
145 +
146 + YangFileInfo yangFileInfo = yangFileInfoIterator.next();
147 +
148 + if (yangFileInfo.getRootNode().getName().equals("module1")) {
149 + selfNode = yangFileInfo.getRootNode();
150 + refNode = yangFileInfoIterator.next().getRootNode();
151 + } else {
152 + refNode = yangFileInfo.getRootNode();
153 + selfNode = yangFileInfoIterator.next().getRootNode();
154 + }
155 +
156 + // Check whether the data model tree returned is of type module.
157 + assertThat((selfNode instanceof YangModule), is(true));
158 +
159 + // Check whether the node type is set properly to module.
160 + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE));
161 +
162 + // Check whether the module name is set correctly.
163 + YangModule yangNode = (YangModule) selfNode;
164 + assertThat(yangNode.getName(), is("module1"));
165 +
166 + ListIterator<YangLeaf> leafIterator;
167 + YangLeaf leafInfo;
168 +
169 + // Check whether grouping is the sibling of module's child.
170 + assertThat((refNode.getChild() instanceof YangGrouping), is(true));
171 +
172 + YangGrouping grouping = (YangGrouping) refNode.getChild();
173 + leafIterator = grouping.getListOfLeaf().listIterator();
174 + leafInfo = leafIterator.next();
175 +
176 + // Check whether the information in the leaf is correct under grouping.
177 + assertThat(leafInfo.getName(), is("hello"));
178 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
179 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
180 +
181 + // Check whether uses is module's child.
182 + assertThat((yangNode.getChild() instanceof YangUses), is(true));
183 + YangUses uses = (YangUses) yangNode.getChild();
184 +
185 + // Check whether uses get resolved.
186 + assertThat(uses.getResolvableStatus(),
187 + is(ResolvableStatus.RESOLVED));
188 +
189 + leafIterator = yangNode.getListOfLeaf().listIterator();
190 + leafInfo = leafIterator.next();
191 +
192 + // Check whether the information in the leaf is correct under module.
193 + assertThat(leafInfo.getName(), is("hello"));
194 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
195 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
196 + }
197 +
198 + /**
199 + * Checks inter file type linking with include list.
200 + */
201 + @Test
202 + public void processInterFileTypeLinkingWithIncludeList()
203 + throws IOException, ParserException, MojoExecutionException {
204 +
205 + String searchDir = "src/test/resources/interfiletypewithinclude";
206 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
207 + utilManager.parseYangFileInfoSet();
208 +
209 + YangNode refNode = null;
210 + YangNode selfNode = null;
211 +
212 + // Carry out linking of sub module with module.
213 + yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangFileInfoSet());
214 +
215 + // Add reference to include list.
216 + yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangFileInfoSet());
217 +
218 + // Carry out inter-file linking.
219 + yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
220 +
221 + Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
222 +
223 + YangFileInfo yangFileInfo = yangFileInfoIterator.next();
224 +
225 + if (yangFileInfo.getRootNode().getName().equals("module1")) {
226 + selfNode = yangFileInfo.getRootNode();
227 + refNode = yangFileInfoIterator.next().getRootNode();
228 + } else {
229 + refNode = yangFileInfo.getRootNode();
230 + selfNode = yangFileInfoIterator.next().getRootNode();
231 + }
232 +
233 + // Check whether the data model tree returned is of type module.
234 + assertThat(selfNode instanceof YangModule, is(true));
235 +
236 + // Check whether the node type is set properly to module.
237 + assertThat(selfNode.getNodeType(), is(MODULE_NODE));
238 +
239 + // Check whether the module name is set correctly.
240 + YangModule yangNode = (YangModule) selfNode;
241 + assertThat(yangNode.getName(), is("module1"));
242 +
243 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
244 + YangLeaf leafInfo = leafIterator.next();
245 +
246 + assertThat(leafInfo.getName(), is("invalid-interval"));
247 + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
248 + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
249 +
250 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
251 + is((YangTypeDef) refNode.getChild()));
252 +
253 + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
254 +
255 + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
256 +
257 + // Check for the effective built-in type.
258 + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
259 +
260 + // Check for the restriction.
261 + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
262 + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
263 + assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
264 + assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
265 + }
266 +
267 + /**
268 + * Checks inter file uses linking with include list.
269 + */
270 + @Test
271 + public void processInterFileUsesLinkingWithInclude()
272 + throws IOException, ParserException, MojoExecutionException {
273 +
274 + String searchDir = "src/test/resources/interfileuseswithinclude";
275 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
276 + utilManager.parseYangFileInfoSet();
277 +
278 + YangNode refNode = null;
279 + YangNode selfNode = null;
280 +
281 + // Carry out linking of sub module with module.
282 + yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangFileInfoSet());
283 +
284 + // Add reference to include list.
285 + yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangFileInfoSet());
286 +
287 + // Carry out inter-file linking.
288 + yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
289 +
290 + Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
291 +
292 + YangFileInfo yangFileInfo = yangFileInfoIterator.next();
293 +
294 + if (yangFileInfo.getRootNode().getName().equals("module1")) {
295 + selfNode = yangFileInfo.getRootNode();
296 + refNode = yangFileInfoIterator.next().getRootNode();
297 + } else {
298 + refNode = yangFileInfo.getRootNode();
299 + selfNode = yangFileInfoIterator.next().getRootNode();
300 + }
301 +
302 + // Check whether the data model tree returned is of type module.
303 + assertThat((selfNode instanceof YangModule), is(true));
304 +
305 + // Check whether the node type is set properly to module.
306 + assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE));
307 +
308 + // Check whether the module name is set correctly.
309 + YangModule yangNode = (YangModule) selfNode;
310 + assertThat(yangNode.getName(), is("module1"));
311 +
312 + ListIterator<YangLeaf> leafIterator;
313 + YangLeaf leafInfo;
314 +
315 + // Check whether grouping is the sibling of module's child.
316 + assertThat((refNode.getChild() instanceof YangGrouping), is(true));
317 +
318 + YangGrouping grouping = (YangGrouping) refNode.getChild();
319 + leafIterator = grouping.getListOfLeaf().listIterator();
320 + leafInfo = leafIterator.next();
321 +
322 + // Check whether the information in the leaf is correct under grouping.
323 + assertThat(leafInfo.getName(), is("hello"));
324 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
325 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
326 +
327 + // Check whether uses is module's child.
328 + assertThat((yangNode.getChild() instanceof YangUses), is(true));
329 + YangUses uses = (YangUses) yangNode.getChild();
330 +
331 + // Check whether uses get resolved.
332 + assertThat(uses.getResolvableStatus(),
333 + is(ResolvableStatus.RESOLVED));
334 +
335 + leafIterator = yangNode.getListOfLeaf().listIterator();
336 + leafInfo = leafIterator.next();
337 +
338 + // Check whether the information in the leaf is correct under module.
339 + assertThat(leafInfo.getName(), is("hello"));
340 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
341 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
342 + }
343 +
344 + /**
345 + * Checks inter file type linking with revision.
346 + */
347 + @Test
348 + public void processInterFileTypeLinkingWithRevision()
349 + throws IOException, ParserException, MojoExecutionException {
350 +
351 + String searchDir = "src/test/resources/interfiletypewithrevision";
352 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
353 + utilManager.parseYangFileInfoSet();
354 +
355 + YangNode refNode = null;
356 + YangNode selfNode = null;
357 +
358 + // Add references to import list.
359 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
360 +
361 + // Carry out inter-file linking.
362 + yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
363 +
364 + Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
365 +
366 + YangFileInfo yangFileInfo = yangFileInfoIterator.next();
367 +
368 + if (yangFileInfo.getRootNode().getName().equals("module1")) {
369 + selfNode = yangFileInfo.getRootNode();
370 + refNode = yangFileInfoIterator.next().getRootNode();
371 + } else {
372 + refNode = yangFileInfo.getRootNode();
373 + selfNode = yangFileInfoIterator.next().getRootNode();
374 + }
375 +
376 + // Check whether the data model tree returned is of type module.
377 + assertThat(selfNode instanceof YangModule, is(true));
378 +
379 + // Check whether the node type is set properly to module.
380 + assertThat(selfNode.getNodeType(), is(MODULE_NODE));
381 +
382 + // Check whether the module name is set correctly.
383 + YangModule yangNode = (YangModule) selfNode;
384 + assertThat(yangNode.getName(), is("module1"));
385 +
386 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
387 + YangLeaf leafInfo = leafIterator.next();
388 +
389 + assertThat(leafInfo.getName(), is("invalid-interval"));
390 + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
391 + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
392 +
393 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
394 + is((YangTypeDef) refNode.getChild()));
395 +
396 + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
397 +
398 + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
399 +
400 + // Check for the effective built-in type.
401 + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
402 +
403 + // Check for the restriction.
404 + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
405 + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
406 + assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
407 + assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
408 + }
409 +
410 + /**
411 + * Checks inter file type linking with revision in name.
412 + */
413 + @Test
414 + public void processInterFileTypeLinkingWithRevisionInName()
415 + throws IOException, ParserException, MojoExecutionException {
416 +
417 + String searchDir = "src/test/resources/interfiletypewithrevisioninname";
418 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
419 + utilManager.parseYangFileInfoSet();
420 +
421 + YangNode refNode = null;
422 + YangNode selfNode = null;
423 +
424 + // Add references to import list.
425 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
426 +
427 + // Carry out inter-file linking.
428 + yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
429 +
430 + Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
431 +
432 + YangFileInfo yangFileInfo = yangFileInfoIterator.next();
433 +
434 + if (yangFileInfo.getRootNode().getName().equals("module1")) {
435 + selfNode = yangFileInfo.getRootNode();
436 + refNode = yangFileInfoIterator.next().getRootNode();
437 + } else {
438 + refNode = yangFileInfo.getRootNode();
439 + selfNode = yangFileInfoIterator.next().getRootNode();
440 + }
441 +
442 + // Check whether the data model tree returned is of type module.
443 + assertThat(selfNode instanceof YangModule, is(true));
444 +
445 + // Check whether the node type is set properly to module.
446 + assertThat(selfNode.getNodeType(), is(MODULE_NODE));
447 +
448 + // Check whether the module name is set correctly.
449 + YangModule yangNode = (YangModule) selfNode;
450 + assertThat(yangNode.getName(), is("module1"));
451 +
452 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
453 + YangLeaf leafInfo = leafIterator.next();
454 +
455 + assertThat(leafInfo.getName(), is("invalid-interval"));
456 + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
457 + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
458 +
459 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
460 + is((YangTypeDef) refNode.getChild()));
461 +
462 + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
463 +
464 + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
465 +
466 + // Check for the effective built-in type.
467 + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
468 +
469 + // Check for the restriction.
470 + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
471 + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
472 + assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
473 + assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
474 + }
475 +
476 + /**
477 + * Checks hierarchical inter file type linking.
478 + */
479 + @Test
480 + public void processHierarchicalInterFileTypeLinking()
481 + throws IOException, ParserException, MojoExecutionException {
482 +
483 + String searchDir = "src/test/resources/hierarchicalinterfiletype";
484 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
485 + utilManager.parseYangFileInfoSet();
486 +
487 + YangNode refNode1 = null;
488 + YangNode refNode2 = null;
489 + YangNode selfNode = null;
490 +
491 + // Add references to import list.
492 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
493 +
494 + // Carry out inter-file linking.
495 + yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
496 +
497 + for (YangFileInfo yangFile : utilManager.getYangFileInfoSet()) {
498 + if (yangFile.getRootNode().getName().equals("ietf-network-topology")) {
499 + selfNode = yangFile.getRootNode();
500 + } else if (yangFile.getRootNode().getName().equals("ietf-network")) {
501 + refNode1 = yangFile.getRootNode();
502 + } else {
503 + refNode2 = yangFile.getRootNode();
504 + }
505 + }
506 +
507 + // Check whether the data model tree returned is of type module.
508 + assertThat(selfNode instanceof YangModule, is(true));
509 +
510 + // Check whether the node type is set properly to module.
511 + assertThat(selfNode.getNodeType(), is(MODULE_NODE));
512 +
513 + // Check whether the module name is set correctly.
514 + YangModule yangNode = (YangModule) selfNode;
515 + assertThat(yangNode.getName(), is("ietf-network-topology"));
516 +
517 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
518 + YangLeaf leafInfo = leafIterator.next();
519 +
520 + assertThat(leafInfo.getName(), is("source-node"));
521 + assertThat(leafInfo.getDataType().getDataTypeName(), is("node-id"));
522 + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
523 +
524 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
525 + is((YangTypeDef) refNode1.getChild()));
526 +
527 + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
528 +
529 + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
530 +
531 + // Check for the effective built-in type.
532 + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
533 +
534 + // Check for the restriction.
535 + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
536 + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
537 + assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
538 + assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
539 + }
540 +
541 + /**
542 + * Checks hierarchical intra with inter file type linking.
543 + */
544 + @Test
545 + public void processHierarchicalIntraWithInterFileTypeLinking()
546 + throws IOException, ParserException, MojoExecutionException {
547 +
548 + String searchDir = "src/test/resources/hierarchicalintrawithinterfiletype";
549 + utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
550 + utilManager.parseYangFileInfoSet();
551 +
552 + YangNode refNode1 = null;
553 + YangNode selfNode = null;
554 +
555 + // Add references to import list.
556 + yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
557 +
558 + // Carry out inter-file linking.
559 + yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
560 +
561 + for (YangFileInfo yangFile : utilManager.getYangFileInfoSet()) {
562 + if (yangFile.getRootNode().getName().equals("ietf-network")) {
563 + selfNode = yangFile.getRootNode();
564 + } else if (yangFile.getRootNode().getName().equals("ietf-inet-types")) {
565 + refNode1 = yangFile.getRootNode();
566 + }
567 + }
568 +
569 + // Check whether the data model tree returned is of type module.
570 + assertThat(selfNode instanceof YangModule, is(true));
571 +
572 + // Check whether the node type is set properly to module.
573 + assertThat(selfNode.getNodeType(), is(MODULE_NODE));
574 +
575 + // Check whether the module name is set correctly.
576 + YangModule yangNode = (YangModule) selfNode;
577 + assertThat(yangNode.getName(), is("ietf-network"));
578 +
579 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
580 + YangLeaf leafInfo = leafIterator.next();
581 +
582 + assertThat(leafInfo.getName(), is("node-ref"));
583 + assertThat(leafInfo.getDataType().getDataTypeName(), is("node-id"));
584 + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
585 +
586 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
587 + is((YangTypeDef) selfNode.getChild()));
588 +
589 + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
590 +
591 + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
592 +
593 + // Check for the effective built-in type.
594 + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
595 +
596 + // Check for the restriction.
597 + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
598 + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
599 + assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
600 + assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
601 + }
602 +}
...@@ -32,12 +32,13 @@ import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; ...@@ -32,12 +32,13 @@ import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
32 import static org.hamcrest.CoreMatchers.nullValue; 32 import static org.hamcrest.CoreMatchers.nullValue;
33 import static org.hamcrest.MatcherAssert.assertThat; 33 import static org.hamcrest.MatcherAssert.assertThat;
34 import static org.hamcrest.core.Is.is; 34 import static org.hamcrest.core.Is.is;
35 -import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED; 35 +import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
36 -import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED;
37 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; 36 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
38 import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32; 37 import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
39 import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; 38 import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
40 import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; 39 import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
40 +import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_RESOLVED;
41 +import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
41 42
42 /** 43 /**
43 * Test cases for testing "type" intra file linking. 44 * Test cases for testing "type" intra file linking.
...@@ -516,4 +517,48 @@ public class IntraFileTypeLinkingTest { ...@@ -516,4 +517,48 @@ public class IntraFileTypeLinkingTest {
516 YangNode node = 517 YangNode node =
517 manager.getDataModel("src/test/resources/SelfFileLinkingWithHierarchicalTypeFailureScenario.yang"); 518 manager.getDataModel("src/test/resources/SelfFileLinkingWithHierarchicalTypeFailureScenario.yang");
518 } 519 }
520 +
521 + /**
522 + * Checks self resolution when typedef and leaf using type are siblings for binary type.
523 + */
524 + @Test
525 + public void processSelfResolutionWhenTypeAndTypedefAtRootLevelForBinary()
526 + throws IOException, ParserException {
527 +
528 + YangNode node
529 + = manager.getDataModel("src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevelForBinary.yang");
530 +
531 + // Check whether the data model tree returned is of type module.
532 + assertThat(node instanceof YangModule, is(true));
533 +
534 + // Check whether the node type is set properly to module.
535 + assertThat(node.getNodeType(), is(MODULE_NODE));
536 +
537 + // Check whether the module name is set correctly.
538 + YangModule yangNode = (YangModule) node;
539 + assertThat(yangNode.getName(), is("ospf"));
540 +
541 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
542 + YangLeaf leafInfo = leafIterator.next();
543 +
544 + assertThat(leafInfo.getName(), is("typedef14"));
545 + assertThat(leafInfo.getDataType().getDataTypeName(), is("type14"));
546 + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
547 +
548 + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
549 + is((YangTypeDef) node.getChild()));
550 +
551 + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
552 +
553 + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
554 +
555 + // Check for the effective built-in type.
556 + assertThat(derivedInfo.getEffectiveBuiltInType(), is(BINARY));
557 +
558 + // Check for the restriction.
559 + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
560 + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
561 + assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
562 + assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
563 + }
519 } 564 }
......
...@@ -21,7 +21,6 @@ import java.util.ListIterator; ...@@ -21,7 +21,6 @@ import java.util.ListIterator;
21 import org.junit.Rule; 21 import org.junit.Rule;
22 import org.junit.Test; 22 import org.junit.Test;
23 import org.junit.rules.ExpectedException; 23 import org.junit.rules.ExpectedException;
24 -import org.onosproject.yangutils.datamodel.ResolvableStatus;
25 import org.onosproject.yangutils.datamodel.YangContainer; 24 import org.onosproject.yangutils.datamodel.YangContainer;
26 import org.onosproject.yangutils.datamodel.YangDataTypes; 25 import org.onosproject.yangutils.datamodel.YangDataTypes;
27 import org.onosproject.yangutils.datamodel.YangGrouping; 26 import org.onosproject.yangutils.datamodel.YangGrouping;
...@@ -32,6 +31,8 @@ import org.onosproject.yangutils.datamodel.YangNode; ...@@ -32,6 +31,8 @@ import org.onosproject.yangutils.datamodel.YangNode;
32 import org.onosproject.yangutils.datamodel.YangNodeType; 31 import org.onosproject.yangutils.datamodel.YangNodeType;
33 import org.onosproject.yangutils.datamodel.YangTypeDef; 32 import org.onosproject.yangutils.datamodel.YangTypeDef;
34 import org.onosproject.yangutils.datamodel.YangUses; 33 import org.onosproject.yangutils.datamodel.YangUses;
34 +import org.onosproject.yangutils.linker.exceptions.LinkerException;
35 +import org.onosproject.yangutils.linker.impl.ResolvableStatus;
35 import org.onosproject.yangutils.parser.exceptions.ParserException; 36 import org.onosproject.yangutils.parser.exceptions.ParserException;
36 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 37 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
37 38
...@@ -293,9 +294,9 @@ public class IntraFileUsesLinkingTest { ...@@ -293,9 +294,9 @@ public class IntraFileUsesLinkingTest {
293 */ 294 */
294 @Test 295 @Test
295 public void processSelfResolutionGroupingReferencingItselfFailureScenerio() 296 public void processSelfResolutionGroupingReferencingItselfFailureScenerio()
296 - throws IOException, ParserException { 297 + throws IOException {
297 298
298 - thrown.expect(ParserException.class); 299 + thrown.expect(LinkerException.class);
299 thrown.expectMessage( 300 thrown.expectMessage(
300 "YANG file error: Duplicate input identifier detected, same as leaf \"zip-code\""); 301 "YANG file error: Duplicate input identifier detected, same as leaf \"zip-code\"");
301 YangNode node = manager 302 YangNode node = manager
......
...@@ -30,6 +30,7 @@ import org.onosproject.yangutils.datamodel.YangRangeRestriction; ...@@ -30,6 +30,7 @@ import org.onosproject.yangutils.datamodel.YangRangeRestriction;
30 import org.onosproject.yangutils.datamodel.YangStringRestriction; 30 import org.onosproject.yangutils.datamodel.YangStringRestriction;
31 import org.onosproject.yangutils.datamodel.YangTypeDef; 31 import org.onosproject.yangutils.datamodel.YangTypeDef;
32 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 32 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
33 +import org.onosproject.yangutils.linker.exceptions.LinkerException;
33 import org.onosproject.yangutils.parser.exceptions.ParserException; 34 import org.onosproject.yangutils.parser.exceptions.ParserException;
34 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 35 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
35 import org.onosproject.yangutils.utils.builtindatatype.YangInt32; 36 import org.onosproject.yangutils.utils.builtindatatype.YangInt32;
...@@ -39,11 +40,11 @@ import static org.hamcrest.CoreMatchers.nullValue; ...@@ -39,11 +40,11 @@ import static org.hamcrest.CoreMatchers.nullValue;
39 import static org.hamcrest.MatcherAssert.assertThat; 40 import static org.hamcrest.MatcherAssert.assertThat;
40 import static org.hamcrest.core.Is.is; 41 import static org.hamcrest.core.Is.is;
41 import static org.hamcrest.core.IsNull.notNullValue; 42 import static org.hamcrest.core.IsNull.notNullValue;
42 -import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED;
43 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; 43 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
44 import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32; 44 import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
45 import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; 45 import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
46 import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; 46 import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
47 +import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
47 48
48 /** 49 /**
49 * Test cases for testing restriction resolution. 50 * Test cases for testing restriction resolution.
...@@ -225,9 +226,9 @@ public final class RestrictionResolutionTest { ...@@ -225,9 +226,9 @@ public final class RestrictionResolutionTest {
225 /** 226 /**
226 * Checks length restriction in typedef and in type with not stricter value. 227 * Checks length restriction in typedef and in type with not stricter value.
227 */ 228 */
228 - @Test(expected = ParserException.class) 229 + @Test(expected = LinkerException.class)
229 public void processLengthRestrictionInTypedefAndTypeInValid() 230 public void processLengthRestrictionInTypedefAndTypeInValid()
230 - throws IOException, ParserException, DataModelException { 231 + throws IOException, DataModelException {
231 YangNode node = manager.getDataModel("src/test/resources/LengthRestrictionInTypedefAndTypeInValid.yang"); 232 YangNode node = manager.getDataModel("src/test/resources/LengthRestrictionInTypedefAndTypeInValid.yang");
232 } 233 }
233 234
...@@ -429,9 +430,9 @@ public final class RestrictionResolutionTest { ...@@ -429,9 +430,9 @@ public final class RestrictionResolutionTest {
429 /** 430 /**
430 * Checks range restriction for string in referred type. 431 * Checks range restriction for string in referred type.
431 */ 432 */
432 - @Test(expected = ParserException.class) 433 + @Test(expected = LinkerException.class)
433 public void processRangeRestrictionInStringInRefType() 434 public void processRangeRestrictionInStringInRefType()
434 - throws IOException, ParserException, DataModelException { 435 + throws IOException, DataModelException {
435 YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInStringInRefType.yang"); 436 YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInStringInRefType.yang");
436 } 437 }
437 438
...@@ -826,9 +827,9 @@ public final class RestrictionResolutionTest { ...@@ -826,9 +827,9 @@ public final class RestrictionResolutionTest {
826 * Checks multiple pattern and length restriction in referred type and 827 * Checks multiple pattern and length restriction in referred type and
827 * typedef invalid scenario. 828 * typedef invalid scenario.
828 */ 829 */
829 - @Test(expected = ParserException.class) 830 + @Test(expected = LinkerException.class)
830 public void processMultiplePatternAndLengthRestrictionInValid() 831 public void processMultiplePatternAndLengthRestrictionInValid()
831 - throws IOException, ParserException, DataModelException { 832 + throws IOException, DataModelException {
832 YangNode node = manager.getDataModel("src/test/resources/MultiplePatternAndLengthRestrictionInValid.yang"); 833 YangNode node = manager.getDataModel("src/test/resources/MultiplePatternAndLengthRestrictionInValid.yang");
833 } 834 }
834 } 835 }
......
...@@ -144,7 +144,7 @@ public class LengthRestrictionListenerTest { ...@@ -144,7 +144,7 @@ public class LengthRestrictionListenerTest {
144 public void processLengthWithInvalidType() throws IOException, ParserException { 144 public void processLengthWithInvalidType() throws IOException, ParserException {
145 thrown.expect(ParserException.class); 145 thrown.expect(ParserException.class);
146 thrown.expectMessage("YANG file error : length name \"1..100\" can be used to restrict the built-in type" + 146 thrown.expectMessage("YANG file error : length name \"1..100\" can be used to restrict the built-in type" +
147 - " string or types derived from string."); 147 + " string/binary or types derived from string/binary.");
148 YangNode node = manager.getDataModel("src/test/resources/LengthWithInvalidType.yang"); 148 YangNode node = manager.getDataModel("src/test/resources/LengthWithInvalidType.yang");
149 } 149 }
150 150
......
...@@ -26,7 +26,6 @@ import java.util.List; ...@@ -26,7 +26,6 @@ import java.util.List;
26 import org.junit.Rule; 26 import org.junit.Rule;
27 import org.junit.Test; 27 import org.junit.Test;
28 import org.junit.rules.ExpectedException; 28 import org.junit.rules.ExpectedException;
29 -import org.onosproject.yangutils.plugin.manager.YangFileInfo;
30 29
31 import static org.hamcrest.core.Is.is; 30 import static org.hamcrest.core.Is.is;
32 import static org.hamcrest.core.IsNot.not; 31 import static org.hamcrest.core.IsNot.not;
...@@ -136,7 +135,7 @@ public final class YangFileScannerTest { ...@@ -136,7 +135,7 @@ public final class YangFileScannerTest {
136 135
137 String emptyYangDir = baseDir + separator + "scanner1"; 136 String emptyYangDir = baseDir + separator + "scanner1";
138 File path = createDirectory(emptyYangDir); 137 File path = createDirectory(emptyYangDir);
139 - List<YangFileInfo> emptyDirContents = getYangFiles(path.toString()); 138 + List<String> emptyDirContents = getYangFiles(path.toString());
140 List<String> expectedContents = new LinkedList<>(); 139 List<String> expectedContents = new LinkedList<>();
141 assertThat(true, is(emptyDirContents.equals(expectedContents))); 140 assertThat(true, is(emptyDirContents.equals(expectedContents)));
142 } 141 }
......
...@@ -6,13 +6,13 @@ module Test { ...@@ -6,13 +6,13 @@ module Test {
6 list valid { 6 list valid {
7 key "invalid-interval"; 7 key "invalid-interval";
8 leaf invalid-interval { 8 leaf invalid-interval {
9 - type hello; 9 + type Ant:hello;
10 } 10 }
11 } 11 }
12 } 12 }
13 container isis { 13 container isis {
14 typedef hello { 14 typedef hello {
15 - type String; 15 + type string;
16 } 16 }
17 } 17 }
18 } 18 }
......
...@@ -3,7 +3,7 @@ module Test { ...@@ -3,7 +3,7 @@ module Test {
3 namespace http://huawei.com; 3 namespace http://huawei.com;
4 prefix Ant; 4 prefix Ant;
5 typedef Percentage { 5 typedef Percentage {
6 - type INT; 6 + type Ant:INT;
7 } 7 }
8 container ospf { 8 container ospf {
9 list valid { 9 list valid {
......
...@@ -2,9 +2,9 @@ module Test { ...@@ -2,9 +2,9 @@ module Test {
2 yang-version 1; 2 yang-version 1;
3 namespace http://huawei.com; 3 namespace http://huawei.com;
4 prefix Ant; 4 prefix Ant;
5 - container test{ 5 + container test {
6 - leaf leaf2{ 6 + leaf leaf2 {
7 - type String; 7 + type string;
8 } 8 }
9 grouping treat { 9 grouping treat {
10 grouping create { 10 grouping create {
...@@ -13,5 +13,5 @@ module Test { ...@@ -13,5 +13,5 @@ module Test {
13 } 13 }
14 } 14 }
15 } 15 }
16 - uses treat; 16 + uses Ant:treat;
17 } 17 }
......
1 +module ospf {
2 + namespace "urn:cisco:params:xml:ns:yang:ospf";
3 + // replace with IANA namespace when assigned
4 + prefix ospf;
5 + revision 2020-10-20 {
6 + description
7 + "Initial revision.";
8 + }
9 +
10 + typedef type14 {
11 + type binary;
12 + }
13 +
14 + leaf typedef14 {
15 + type type14;
16 + }
17 +}
...@@ -3,9 +3,9 @@ module Test { ...@@ -3,9 +3,9 @@ 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 Ant:hello;
7 } 7 }
8 typedef hi { 8 typedef hi {
9 - type String; 9 + type string;
10 } 10 }
11 } 11 }
......
1 + module ietf-inet-types {
2 +
3 + yang-version 1;
4 +
5 + namespace
6 + "urn:ietf:params:xml:ns:yang:ietf-inet-types";
7 +
8 + prefix inet;
9 +
10 +
11 +
12 + typedef uri {
13 + type string;
14 + }
15 + }
1 + module ietf-network-topology {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network-topology";
4 + prefix nt;
5 +
6 + import ietf-inet-types {
7 + prefix inet;
8 + }
9 + import ietf-network {
10 + prefix nd;
11 + }
12 + leaf source-node {
13 + type nd:node-id;
14 + description
15 + "Source node identifier, must be in same topology.";
16 + }
17 + }
1 + module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 +
6 + import ietf-inet-types {
7 + prefix inet;
8 + }
9 +
10 + typedef node-id {
11 + type inet:uri;
12 + description
13 + "Identifier for a node.";
14 + }
15 +
16 + }
1 + module ietf-inet-types {
2 +
3 + yang-version 1;
4 +
5 + namespace
6 + "urn:ietf:params:xml:ns:yang:ietf-inet-types";
7 +
8 + prefix inet;
9 +
10 + typedef uri {
11 + type string;
12 + }
13 + }
1 + module ietf-network {
2 + yang-version 1;
3 + namespace "urn:ietf:params:xml:ns:yang:ietf-network";
4 + prefix nd;
5 +
6 + import ietf-inet-types {
7 + prefix inet;
8 + }
9 + leaf node-ref {
10 + type node-id;
11 + description
12 + "Used to reference a node.
13 + Nodes are identified relative to the network they are
14 + contained in.";
15 + }
16 +
17 + typedef node-id {
18 + type inet:uri;
19 + description
20 + "Identifier for a node.";
21 + }
22 + }
1 +module module1 {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + import module2 {
6 + prefix p;
7 + }
8 + leaf invalid-interval {
9 + type p:hello;
10 + }
11 + typedef hello {
12 + type string;
13 + }
14 +}
1 +module module2 {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant2;
5 + typedef hello {
6 + type string;
7 + }
8 +}
1 +module module1 {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + include module2;
6 + leaf invalid-interval {
7 + type hello;
8 + }
9 +}
1 +submodule module2 {
2 + yang-version 1;
3 + belongs-to module1 {
4 + prefix "module1";
5 + }
6 + typedef hello {
7 + type string;
8 + }
9 +}
1 +module module1 {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + import module2 {
6 + prefix p;
7 + revision-date 2007-06-09;
8 + }
9 + leaf invalid-interval {
10 + type p:hello;
11 + }
12 + typedef hello {
13 + type string;
14 + }
15 +}
1 +module module2 {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant2;
5 + revision 2007-06-09 {
6 + description "Initial revision.";
7 + }
8 + typedef hello {
9 + type string;
10 + }
11 +}
1 +module module1 {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + import module2 {
6 + prefix p;
7 + revision-date 2007-06-09;
8 + }
9 + leaf invalid-interval {
10 + type p:hello;
11 + }
12 + typedef hello {
13 + type string;
14 + }
15 +}
1 +module module2 {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant2;
5 + revision 2007-06-09 {
6 + description "Initial revision.";
7 + }
8 + typedef hello {
9 + type string;
10 + }
11 +}
1 +module module1 {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + import module2 {
6 + prefix p;
7 + }
8 + uses p:hello;
9 +}
1 +module module2 {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + grouping hello {
6 + leaf hello {
7 + type string;
8 + }
9 + }
10 +}
1 +module module1 {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + include module2;
6 + uses hello;
7 +}
1 +submodule module2 {
2 + yang-version 1;
3 + belongs-to module1 {
4 + prefix "module1";
5 + }
6 + grouping hello {
7 + leaf hello {
8 + type string;
9 + }
10 + }
11 +}