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 1548 additions and 273 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
262 - setResolvableStatus(derivedInfo.resolve()); 265 + try {
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()) {
279 - ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(), 282 + try {
280 - YangConstructType.LEAF_DATA); 283 + ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(),
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()) {
286 - ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(), 293 + try {
287 - YangConstructType.LEAF_LIST_DATA); 294 + ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(),
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
292 - YangNode.cloneSubTree(getRefGroup(), usesParentNode); 303 + try {
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;
...@@ -48,14 +46,13 @@ public final class DataModelUtils { ...@@ -48,14 +46,13 @@ public final class DataModelUtils {
48 * Detects the colliding identifier name in a given YANG node and its child. 46 * Detects the colliding identifier name in a given YANG node and its child.
49 * 47 *
50 * @param identifierName name for which collision detection is to be 48 * @param identifierName name for which collision detection is to be
51 - * checked 49 + * checked
52 - * @param dataType type of YANG node asking for detecting collision 50 + * @param dataType type of YANG node asking for detecting collision
53 - * @param node instance of calling node 51 + * @param node instance of calling node
54 * @throws DataModelException a violation of data model rules 52 * @throws DataModelException a violation of data model rules
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 {
...@@ -81,9 +78,9 @@ public final class DataModelUtils { ...@@ -81,9 +78,9 @@ public final class DataModelUtils {
81 * Detects colliding of uses and grouping only with uses and grouping respectively. 78 * Detects colliding of uses and grouping only with uses and grouping respectively.
82 * 79 *
83 * @param identifierName name for which collision detection is to be 80 * @param identifierName name for which collision detection is to be
84 - * checked 81 + * checked
85 - * @param dataType type of YANG node asking for detecting collision 82 + * @param dataType type of YANG node asking for detecting collision
86 - * @param node node instance of calling node 83 + * @param node node instance of calling node
87 * @throws DataModelException a violation of data model rules 84 * @throws DataModelException a violation of data model rules
88 */ 85 */
89 public static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node) 86 public static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node)
...@@ -103,9 +100,9 @@ public final class DataModelUtils { ...@@ -103,9 +100,9 @@ public final class DataModelUtils {
103 /** 100 /**
104 * Detects the colliding identifier name in a given leaf node. 101 * Detects the colliding identifier name in a given leaf node.
105 * 102 *
106 - * @param listOfLeaf List of leaves to detect collision 103 + * @param listOfLeaf List of leaves to detect collision
107 * @param identifierName name for which collision detection is to be 104 * @param identifierName name for which collision detection is to be
108 - * checked 105 + * checked
109 * @throws DataModelException a violation of data model rules 106 * @throws DataModelException a violation of data model rules
110 */ 107 */
111 private static void detectCollidingLeaf(List<YangLeaf> listOfLeaf, String identifierName) 108 private static void detectCollidingLeaf(List<YangLeaf> listOfLeaf, String identifierName)
...@@ -127,7 +124,7 @@ public final class DataModelUtils { ...@@ -127,7 +124,7 @@ public final class DataModelUtils {
127 * 124 *
128 * @param listOfLeafList list of leaf-lists to detect collision 125 * @param listOfLeafList list of leaf-lists to detect collision
129 * @param identifierName name for which collision detection is to be 126 * @param identifierName name for which collision detection is to be
130 - * checked 127 + * checked
131 * @throws DataModelException a violation of data model rules 128 * @throws DataModelException a violation of data model rules
132 */ 129 */
133 private static void detectCollidingLeafList(List<YangLeafList> listOfLeafList, String identifierName) 130 private static void detectCollidingLeafList(List<YangLeafList> listOfLeafList, String identifierName)
...@@ -148,7 +145,7 @@ public final class DataModelUtils { ...@@ -148,7 +145,7 @@ public final class DataModelUtils {
148 * Add a resolution information. 145 * Add a resolution information.
149 * 146 *
150 * @param resolutionInfo information about the YANG construct which has to 147 * @param resolutionInfo information about the YANG construct which has to
151 - * be resolved 148 + * be resolved
152 * @throws DataModelException a violation of data model rules 149 * @throws DataModelException a violation of data model rules
153 */ 150 */
154 public static void addResolutionInfo(YangResolutionInfo resolutionInfo) 151 public static void addResolutionInfo(YangResolutionInfo resolutionInfo)
...@@ -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
253 */ 226 */
254 - public static YangNode findBelongsToModuleNode(List<YangFileInfo> yangFileInfo, 227 + public static YangNode findReferredNode(Set<YangFileInfo> yangFileInfoSet, String refNodeName) {
255 - String belongsToModuleName) throws DataModelException { 228 + /*
256 - Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator(); 229 + * Run through the YANG files to see which YANG file matches the
257 - while (yangFileIterator.hasNext()) { 230 + * referred node name.
258 - YangFileInfo yangFile = yangFileIterator.next(); 231 + */
259 - YangNode yangNode = yangFile.getRootNode(); 232 + for (YangFileInfo yangFileInfo : yangFileInfoSet) {
260 - if (yangNode.getName().equals(belongsToModuleName)) { 233 + YangNode yangNode = yangFileInfo.getRootNode();
261 - return yangNode; 234 + if (yangNode.getName().equals(refNodeName)) {
235 + return yangFileInfo.getRootNode();
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.
...@@ -61,7 +64,7 @@ public class YangEntityToResolveInfo<T> { ...@@ -61,7 +64,7 @@ public class YangEntityToResolveInfo<T> {
61 * Sets parent node which contains the entity to be resolved. 64 * Sets parent node which contains the entity to be resolved.
62 * 65 *
63 * @param holderOfEntityToResolve parent node which contains the entity to 66 * @param holderOfEntityToResolve parent node which contains the entity to
64 - * be resolved 67 + * be resolved
65 */ 68 */
66 public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) { 69 public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
67 this.holderOfEntityToResolve = holderOfEntityToResolve; 70 this.holderOfEntityToResolve = holderOfEntityToResolve;
...@@ -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 }
......
...@@ -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;
...\ No newline at end of file ...\ No newline at end of file
20 +package org.onosproject.yangutils.linker.impl;
......
...@@ -74,20 +74,26 @@ public final class BelongsToListener { ...@@ -74,20 +74,26 @@ public final class BelongsToListener {
74 * (belongsto), perform validations and update the data model tree. 74 * (belongsto), perform validations and update the data model tree.
75 * 75 *
76 * @param listener Listener's object 76 * @param listener Listener's object
77 - * @param ctx context object of the grammar rule 77 + * @param ctx context object of the grammar rule
78 */ 78 */
79 public static void processBelongsToEntry(TreeWalkListener listener, 79 public static void processBelongsToEntry(TreeWalkListener listener,
80 GeneratedYangParser.BelongstoStatementContext ctx) { 80 GeneratedYangParser.BelongstoStatementContext ctx) {
81 81
82 // Check for stack to be non empty. 82 // Check for stack to be non empty.
83 checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.identifier().getText(), 83 checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.identifier().getText(),
84 - ENTRY); 84 + ENTRY);
85 85
86 String identifier = getValidIdentifier(ctx.identifier().getText(), BELONGS_TO_DATA, ctx); 86 String identifier = getValidIdentifier(ctx.identifier().getText(), BELONGS_TO_DATA, ctx);
87 87
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 }
...@@ -97,14 +103,14 @@ public final class BelongsToListener { ...@@ -97,14 +103,14 @@ public final class BelongsToListener {
97 * validations and update the data model tree. 103 * validations and update the data model tree.
98 * 104 *
99 * @param listener Listener's object 105 * @param listener Listener's object
100 - * @param ctx context object of the grammar rule 106 + * @param ctx context object of the grammar rule
101 */ 107 */
102 public static void processBelongsToExit(TreeWalkListener listener, 108 public static void processBelongsToExit(TreeWalkListener listener,
103 GeneratedYangParser.BelongstoStatementContext ctx) { 109 GeneratedYangParser.BelongstoStatementContext ctx) {
104 110
105 // Check for stack to be non empty. 111 // Check for stack to be non empty.
106 checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.identifier().getText(), 112 checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.identifier().getText(),
107 - EXIT); 113 + EXIT);
108 114
109 Parsable tmpBelongstoNode = listener.getParsedDataStack().peek(); 115 Parsable tmpBelongstoNode = listener.getParsedDataStack().peek();
110 if (tmpBelongstoNode instanceof YangBelongsTo) { 116 if (tmpBelongstoNode instanceof YangBelongsTo) {
...@@ -112,7 +118,7 @@ public final class BelongsToListener { ...@@ -112,7 +118,7 @@ public final class BelongsToListener {
112 118
113 // Check for stack to be empty. 119 // Check for stack to be empty.
114 checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, 120 checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA,
115 - ctx.identifier().getText(), EXIT); 121 + ctx.identifier().getText(), EXIT);
116 122
117 Parsable tmpNode = listener.getParsedDataStack().peek(); 123 Parsable tmpNode = listener.getParsedDataStack().peek();
118 switch (tmpNode.getYangConstructType()) { 124 switch (tmpNode.getYangConstructType()) {
...@@ -129,7 +135,7 @@ public final class BelongsToListener { ...@@ -129,7 +135,7 @@ public final class BelongsToListener {
129 } 135 }
130 } else { 136 } else {
131 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BELONGS_TO_DATA, 137 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BELONGS_TO_DATA,
132 - ctx.identifier().getText(), EXIT)); 138 + ctx.identifier().getText(), EXIT));
133 } 139 }
134 } 140 }
135 } 141 }
......
...@@ -73,7 +73,7 @@ public final class ImportListener { ...@@ -73,7 +73,7 @@ public final class ImportListener {
73 * (import), perform validations and update the data model tree. 73 * (import), perform validations and update the data model tree.
74 * 74 *
75 * @param listener Listener's object 75 * @param listener Listener's object
76 - * @param ctx context object of the grammar rule 76 + * @param ctx context object of the grammar rule
77 */ 77 */
78 public static void processImportEntry(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) { 78 public static void processImportEntry(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
79 79
...@@ -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 }
...@@ -94,7 +100,7 @@ public final class ImportListener { ...@@ -94,7 +100,7 @@ public final class ImportListener {
94 * validations and update the data model tree. 100 * validations and update the data model tree.
95 * 101 *
96 * @param listener Listener's object 102 * @param listener Listener's object
97 - * @param ctx context object of the grammar rule 103 + * @param ctx context object of the grammar rule
98 */ 104 */
99 public static void processImportExit(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) { 105 public static void processImportExit(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
100 106
...@@ -107,7 +113,7 @@ public final class ImportListener { ...@@ -107,7 +113,7 @@ public final class ImportListener {
107 113
108 // Check for stack to be non empty. 114 // Check for stack to be non empty.
109 checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.identifier().getText(), 115 checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.identifier().getText(),
110 - EXIT); 116 + EXIT);
111 117
112 Parsable tmpNode = listener.getParsedDataStack().peek(); 118 Parsable tmpNode = listener.getParsedDataStack().peek();
113 switch (tmpNode.getYangConstructType()) { 119 switch (tmpNode.getYangConstructType()) {
...@@ -128,7 +134,7 @@ public final class ImportListener { ...@@ -128,7 +134,7 @@ public final class ImportListener {
128 } 134 }
129 } else { 135 } else {
130 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, IMPORT_DATA, 136 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, IMPORT_DATA,
131 - ctx.identifier().getText(), EXIT)); 137 + ctx.identifier().getText(), EXIT));
132 } 138 }
133 } 139 }
134 } 140 }
......
...@@ -72,19 +72,25 @@ public final class IncludeListener { ...@@ -72,19 +72,25 @@ public final class IncludeListener {
72 * (include), perform validations and update the data model tree. 72 * (include), perform validations and update the data model tree.
73 * 73 *
74 * @param listener Listener's object 74 * @param listener Listener's object
75 - * @param ctx context object of the grammar rule 75 + * @param ctx context object of the grammar rule
76 */ 76 */
77 public static void processIncludeEntry(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) { 77 public static void processIncludeEntry(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
78 78
79 // Check for stack to be non empty. 79 // Check for stack to be non empty.
80 checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(), 80 checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(),
81 - ENTRY); 81 + ENTRY);
82 82
83 String identifier = getValidIdentifier(ctx.identifier().getText(), INCLUDE_DATA, ctx); 83 String identifier = getValidIdentifier(ctx.identifier().getText(), INCLUDE_DATA, ctx);
84 84
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
...@@ -93,7 +99,7 @@ public final class IncludeListener { ...@@ -93,7 +99,7 @@ public final class IncludeListener {
93 * validations and update the data model tree. 99 * validations and update the data model tree.
94 * 100 *
95 * @param listener Listener's object 101 * @param listener Listener's object
96 - * @param ctx context object of the grammar rule 102 + * @param ctx context object of the grammar rule
97 */ 103 */
98 public static void processIncludeExit(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) { 104 public static void processIncludeExit(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
99 105
...@@ -106,7 +112,7 @@ public final class IncludeListener { ...@@ -106,7 +112,7 @@ public final class IncludeListener {
106 112
107 // Check for stack to be non empty. 113 // Check for stack to be non empty.
108 checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(), 114 checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(),
109 - EXIT); 115 + EXIT);
110 116
111 Parsable tmpNode = listener.getParsedDataStack().peek(); 117 Parsable tmpNode = listener.getParsedDataStack().peek();
112 switch (tmpNode.getYangConstructType()) { 118 switch (tmpNode.getYangConstructType()) {
...@@ -127,7 +133,7 @@ public final class IncludeListener { ...@@ -127,7 +133,7 @@ public final class IncludeListener {
127 } 133 }
128 } else { 134 } else {
129 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INCLUDE_DATA, 135 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INCLUDE_DATA,
130 - ctx.identifier().getText(), EXIT)); 136 + ctx.identifier().getText(), EXIT));
131 } 137 }
132 } 138 }
133 } 139 }
......
...@@ -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;
...@@ -99,8 +100,8 @@ public final class LengthRestrictionListener { ...@@ -99,8 +100,8 @@ public final class LengthRestrictionListener {
99 * Sets the length restriction to type. 100 * Sets the length restriction to type.
100 * 101 *
101 * @param listener listener's object 102 * @param listener listener's object
102 - * @param type Yang type for which length restriction to be set 103 + * @param type Yang type for which length restriction to be set
103 - * @param ctx context object of the grammar rule 104 + * @param ctx context object of the grammar rule
104 */ 105 */
105 private static void setLengthRestriction(TreeWalkListener listener, YangType type, 106 private static void setLengthRestriction(TreeWalkListener listener, YangType type,
106 GeneratedYangParser.LengthStatementContext ctx) { 107 GeneratedYangParser.LengthStatementContext ctx) {
...@@ -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
130 - YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo(); 131 + if (type.getDataType() == STRING) {
132 + YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
133 + if (stringRestriction == null) {
134 + stringRestriction = new YangStringRestriction();
135 + type.setDataTypeExtendedInfo(stringRestriction);
136 + }
131 137
132 - if (stringRestriction == null) { 138 + stringRestriction.setLengthRestriction(lengthRestriction);
133 - stringRestriction = new YangStringRestriction(); 139 + } else {
134 - type.setDataTypeExtendedInfo(stringRestriction); 140 + type.setDataTypeExtendedInfo(lengthRestriction);
135 } 141 }
136 142
137 - stringRestriction.setLengthRestriction(lengthRestriction);
138 listener.getParsedDataStack().push(lengthRestriction); 143 listener.getParsedDataStack().push(lengthRestriction);
139 } 144 }
140 145
...@@ -143,7 +148,7 @@ public final class LengthRestrictionListener { ...@@ -143,7 +148,7 @@ public final class LengthRestrictionListener {
143 * It is called when parser exits from grammar rule (length). 148 * It is called when parser exits from grammar rule (length).
144 * 149 *
145 * @param listener listener's object 150 * @param listener listener's object
146 - * @param ctx context object of the grammar rule 151 + * @param ctx context object of the grammar rule
147 */ 152 */
148 public static void processLengthRestrictionExit(TreeWalkListener listener, 153 public static void processLengthRestrictionExit(TreeWalkListener listener,
149 GeneratedYangParser.LengthStatementContext ctx) { 154 GeneratedYangParser.LengthStatementContext ctx) {
......
...@@ -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;
...@@ -81,10 +79,10 @@ public final class TypeListener { ...@@ -81,10 +79,10 @@ public final class TypeListener {
81 * (type), performs validation and updates the data model tree. 79 * (type), performs validation and updates the data model tree.
82 * 80 *
83 * @param listener listener's object 81 * @param listener listener's object
84 - * @param ctx context object of the grammar rule 82 + * @param ctx context object of the grammar rule
85 */ 83 */
86 public static void processTypeEntry(TreeWalkListener listener, 84 public static void processTypeEntry(TreeWalkListener listener,
87 - GeneratedYangParser.TypeStatementContext ctx) { 85 + GeneratedYangParser.TypeStatementContext ctx) {
88 86
89 // Check for stack to be non empty. 87 // Check for stack to be non empty.
90 checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), ENTRY); 88 checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), ENTRY);
...@@ -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,
...@@ -233,10 +235,10 @@ public final class TypeListener { ...@@ -233,10 +235,10 @@ public final class TypeListener {
233 * validations and update the data model tree. 235 * validations and update the data model tree.
234 * 236 *
235 * @param listener Listener's object 237 * @param listener Listener's object
236 - * @param ctx context object of the grammar rule 238 + * @param ctx context object of the grammar rule
237 */ 239 */
238 public static void processTypeExit(TreeWalkListener listener, 240 public static void processTypeExit(TreeWalkListener listener,
239 - GeneratedYangParser.TypeStatementContext ctx) { 241 + GeneratedYangParser.TypeStatementContext ctx) {
240 242
241 // Check for stack to be non empty. 243 // Check for stack to be non empty.
242 checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, TYPE_DATA, ctx.string().getText(), EXIT); 244 checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, TYPE_DATA, ctx.string().getText(), EXIT);
...@@ -252,15 +254,15 @@ public final class TypeListener { ...@@ -252,15 +254,15 @@ public final class TypeListener {
252 * Adds to resolution list. 254 * Adds to resolution list.
253 * 255 *
254 * @param resolutionInfo resolution information 256 * @param resolutionInfo resolution information
255 - * @param ctx context object of the grammar rule 257 + * @param ctx context object of the grammar rule
256 */ 258 */
257 private static void addToResolutionList(YangResolutionInfo<YangType> resolutionInfo, 259 private static void addToResolutionList(YangResolutionInfo<YangType> resolutionInfo,
258 - GeneratedYangParser.TypeStatementContext ctx) { 260 + GeneratedYangParser.TypeStatementContext ctx) {
259 try { 261 try {
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 }
......
...@@ -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;
...@@ -105,10 +104,10 @@ public class YangJavaSubModule ...@@ -105,10 +104,10 @@ public class YangJavaSubModule
105 * Returns the name space of the module to which the sub module belongs to. 104 * Returns the name space of the module to which the sub module belongs to.
106 * 105 *
107 * @param belongsToInfo Information of the module to which the sub module 106 * @param belongsToInfo Information of the module to which the sub module
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;
...@@ -109,7 +112,7 @@ public final class AttributesJavaDataType { ...@@ -109,7 +112,7 @@ public final class AttributesJavaDataType {
109 * Returns from string method parsed string. 112 * Returns from string method parsed string.
110 * 113 *
111 * @param targetDataType target data type 114 * @param targetDataType target data type
112 - * @param yangType YANG type 115 + * @param yangType YANG type
113 * @return parsed string 116 * @return parsed string
114 */ 117 */
115 public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) { 118 public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
...@@ -155,7 +158,7 @@ public final class AttributesJavaDataType { ...@@ -155,7 +158,7 @@ public final class AttributesJavaDataType {
155 /** 158 /**
156 * Returns java import class. 159 * Returns java import class.
157 * 160 *
158 - * @param yangType YANG type 161 + * @param yangType YANG type
159 * @param isListAttr if the attribute need to be a list 162 * @param isListAttr if the attribute need to be a list
160 * @return java import class 163 * @return java import class
161 */ 164 */
...@@ -260,9 +263,9 @@ public final class AttributesJavaDataType { ...@@ -260,9 +263,9 @@ public final class AttributesJavaDataType {
260 /** 263 /**
261 * Returns java import package. 264 * Returns java import package.
262 * 265 *
263 - * @param yangType YANG type 266 + * @param yangType YANG type
264 * @param isListAttr if the attribute is of list type 267 * @param isListAttr if the attribute is of list type
265 - * @param classInfo java import class info 268 + * @param classInfo java import class info
266 * @return java import package 269 * @return java import package
267 */ 270 */
268 public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) { 271 public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) {
...@@ -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.
...@@ -43,8 +42,8 @@ public final class YangFileScanner { ...@@ -43,8 +42,8 @@ public final class YangFileScanner {
43 * @param root specified directory 42 * @param root specified directory
44 * @return list of java files 43 * @return list of java files
45 * @throws NullPointerException when no files are there. 44 * @throws NullPointerException when no files are there.
46 - * @throws IOException when files get deleted while performing the 45 + * @throws IOException when files get deleted while performing the
47 - * operations 46 + * operations
48 */ 47 */
49 public static List<String> getJavaFiles(String root) throws IOException { 48 public static List<String> getJavaFiles(String root) throws IOException {
50 49
...@@ -52,33 +51,27 @@ public final class YangFileScanner { ...@@ -52,33 +51,27 @@ 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
59 * @throws NullPointerException when no files are there 58 * @throws NullPointerException when no files are there
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 /**
75 * Returns the list of required files. 68 * Returns the list of required files.
76 * 69 *
77 - * @param root specified directory 70 + * @param root specified directory
78 * @param extension file extension 71 * @param extension file extension
79 * @return list of required files 72 * @return list of required files
80 * @throws NullPointerException when no file is there 73 * @throws NullPointerException when no file is there
81 - * @throws IOException when files get deleted while performing the operations 74 + * @throws IOException when files get deleted while performing the operations
82 */ 75 */
83 public static List<String> getFiles(String root, String extension) throws IOException { 76 public static List<String> getFiles(String root, String extension) throws IOException {
84 77
......
...@@ -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;
...@@ -81,9 +83,9 @@ public final class YangIoUtils { ...@@ -81,9 +83,9 @@ public final class YangIoUtils {
81 /** 83 /**
82 * Adds package info file for the created directory. 84 * Adds package info file for the created directory.
83 * 85 *
84 - * @param path directory path 86 + * @param path directory path
85 - * @param classInfo class info for the package 87 + * @param classInfo class info for the package
86 - * @param pack package of the directory 88 + * @param pack package of the directory
87 * @param isChildNode is it a child node 89 * @param isChildNode is it a child node
88 * @throws IOException when fails to create package info file 90 * @throws IOException when fails to create package info file
89 */ 91 */
...@@ -167,7 +169,7 @@ public final class YangIoUtils { ...@@ -167,7 +169,7 @@ public final class YangIoUtils {
167 /** 169 /**
168 * Adds generated source directory to the compilation root. 170 * Adds generated source directory to the compilation root.
169 * 171 *
170 - * @param source directory 172 + * @param source directory
171 * @param project current maven project 173 * @param project current maven project
172 * @param context current build context 174 * @param context current build context
173 */ 175 */
...@@ -180,7 +182,7 @@ public final class YangIoUtils { ...@@ -180,7 +182,7 @@ public final class YangIoUtils {
180 /** 182 /**
181 * Removes extra char from the string. 183 * Removes extra char from the string.
182 * 184 *
183 - * @param valueString string to be trimmed 185 + * @param valueString string to be trimmed
184 * @param removealStirng extra chars 186 * @param removealStirng extra chars
185 * @return new string 187 * @return new string
186 */ 188 */
...@@ -215,8 +217,8 @@ public final class YangIoUtils { ...@@ -215,8 +217,8 @@ public final class YangIoUtils {
215 * Returns the directory path of the package in canonical form. 217 * Returns the directory path of the package in canonical form.
216 * 218 *
217 * @param baseCodeGenPath base path where the generated files needs to be 219 * @param baseCodeGenPath base path where the generated files needs to be
218 - * put 220 + * put
219 - * @param pathOfJavaPkg java package of the file being generated 221 + * @param pathOfJavaPkg java package of the file being generated
220 * @return absolute path of the package in canonical form 222 * @return absolute path of the package in canonical form
221 */ 223 */
222 public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) { 224 public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) {
...@@ -236,8 +238,8 @@ public final class YangIoUtils { ...@@ -236,8 +238,8 @@ public final class YangIoUtils {
236 * Returns the absolute path of the package in canonical form. 238 * Returns the absolute path of the package in canonical form.
237 * 239 *
238 * @param baseCodeGenPath base path where the generated files needs to be 240 * @param baseCodeGenPath base path where the generated files needs to be
239 - * put 241 + * put
240 - * @param pathOfJavaPkg java package of the file being generated 242 + * @param pathOfJavaPkg java package of the file being generated
241 * @return absolute path of the package in canonical form 243 * @return absolute path of the package in canonical form
242 */ 244 */
243 public static String getAbsolutePackagePath(String baseCodeGenPath, String pathOfJavaPkg) { 245 public static String getAbsolutePackagePath(String baseCodeGenPath, String pathOfJavaPkg) {
...@@ -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()) {
...@@ -291,7 +293,7 @@ public final class YangIoUtils { ...@@ -291,7 +293,7 @@ public final class YangIoUtils {
291 * Merges the temp java files to main java files. 293 * Merges the temp java files to main java files.
292 * 294 *
293 * @param appendFile temp file 295 * @param appendFile temp file
294 - * @param srcFile main file 296 + * @param srcFile main file
295 * @throws IOException when fails to append contents 297 * @throws IOException when fails to append contents
296 */ 298 */
297 public static void mergeJavaFiles(File appendFile, File srcFile) throws IOException { 299 public static void mergeJavaFiles(File appendFile, File srcFile) throws IOException {
......
...@@ -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;
...@@ -49,11 +48,11 @@ public final class YangFileScannerTest { ...@@ -49,11 +48,11 @@ public final class YangFileScannerTest {
49 /** 48 /**
50 * A private constructor is tested. 49 * A private constructor is tested.
51 * 50 *
52 - * @throws SecurityException if any security violation is observed 51 + * @throws SecurityException if any security violation is observed
53 - * @throws NoSuchMethodException if when the method is not found 52 + * @throws NoSuchMethodException if when the method is not found
54 - * @throws IllegalArgumentException if there is illegal argument found 53 + * @throws IllegalArgumentException if there is illegal argument found
55 - * @throws InstantiationException if instantiation is provoked for the private constructor 54 + * @throws InstantiationException if instantiation is provoked for the private constructor
56 - * @throws IllegalAccessException if instance is provoked or a method is provoked 55 + * @throws IllegalAccessException if instance is provoked or a method is provoked
57 * @throws InvocationTargetException when an exception occurs by the method or constructor 56 * @throws InvocationTargetException when an exception occurs by the method or constructor
58 */ 57 */
59 @Test 58 @Test
...@@ -101,7 +100,7 @@ public final class YangFileScannerTest { ...@@ -101,7 +100,7 @@ public final class YangFileScannerTest {
101 /** 100 /**
102 * Method used for creating file inside the specified directory. 101 * Method used for creating file inside the specified directory.
103 * 102 *
104 - * @param myDir the path where file has to be created inside 103 + * @param myDir the path where file has to be created inside
105 * @param fileName the name of the file to be created 104 * @param fileName the name of the file to be created
106 */ 105 */
107 private void createFile(File myDir, String fileName) throws IOException { 106 private void createFile(File myDir, String fileName) throws IOException {
...@@ -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 +}