[ONOS-4350] Inter file linking implementation and inter-jar linking framework
Change-Id: I71a26ba3e0b9d17261e78a9313fe7f047195932e
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolutionType.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolutionType.java
deleted file mode 100644
index e69492a..0000000
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolutionType.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.datamodel;
-
-/**
- * Represents ENUM to identify the YANG resolution type.
- */
-public enum ResolutionType {
- /**
- * Identifies that resolution is for typedef.
- */
- TYPEDEF_RESOLUTION,
-
- /**
- * Identifies that resolution is for grouping.
- */
- GROUPING_RESOLUTION
-}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangBelongsTo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangBelongsTo.java
index 417e07e..694df32 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangBelongsTo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangBelongsTo.java
@@ -15,10 +15,14 @@
*/
package org.onosproject.yangutils.datamodel;
+import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
+
/*-
* Reference 6020.
*
@@ -46,7 +50,7 @@
/**
* Represents the belongs-to data type information.
*/
-public class YangBelongsTo implements Parsable {
+public class YangBelongsTo implements Parsable, LocationInfo {
/**
* Reference RFC 6020.
@@ -70,6 +74,12 @@
*/
private String prefix;
+ // Error Line number.
+ private int lineNumber;
+
+ // Error character position.
+ private int charPosition;
+
/**
* Create a belongs to object.
*/
@@ -90,7 +100,6 @@
* Sets the belongs to module name.
*
* @param belongsToModuleName the belongs to module name to set
- *
*/
public void setBelongsToModuleName(String belongsToModuleName) {
this.belongsToModuleName = belongsToModuleName;
@@ -161,4 +170,47 @@
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
+
+ @Override
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ @Override
+ public int getCharPosition() {
+ return charPosition;
+ }
+
+ @Override
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ @Override
+ public void setCharPosition(int charPositionInLine) {
+ this.charPosition = charPositionInLine;
+ }
+
+ /**
+ * Links the belongs to with a module.
+ *
+ * @param yangFileInfoSet YANG file information set
+ * @throws DataModelException a violation in data model rule
+ */
+ public void linkWithModule(Set<YangFileInfo> yangFileInfoSet)
+ throws DataModelException {
+ String belongsToModuleName = getBelongsToModuleName();
+ YangNode moduleNode = findReferredNode(yangFileInfoSet, belongsToModuleName);
+ if (moduleNode != null) {
+ if (moduleNode instanceof YangModule) {
+ setModuleNode(moduleNode);
+ return;
+ }
+ }
+ DataModelException exception = new DataModelException("YANG file error : Module " + belongsToModuleName +
+ "to which sub-module belongs to is not found.");
+ exception.setLine(getLineNumber());
+ exception.setCharPosition(getCharPosition());
+ throw exception;
+ }
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
index 8c94d7d..e1d0e68 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
@@ -17,10 +17,10 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.impl.ResolvableStatus;
import com.google.common.base.Strings;
-import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED;
-import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.YangDataTypes.BITS;
import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN;
import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
@@ -30,6 +30,8 @@
import static org.onosproject.yangutils.datamodel.YangDataTypes.LEAFREF;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.YangDataTypes.UNION;
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.utils.RestrictionResolver.isOfRangeRestrictedType;
import static org.onosproject.yangutils.utils.RestrictionResolver.processLengthRestriction;
import static org.onosproject.yangutils.utils.RestrictionResolver.processRangeRestriction;
@@ -236,7 +238,7 @@
* Check whether the referred typedef is resolved.
*/
if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) {
- throw new DataModelException("Linker Error: Referred typedef is not resolved.");
+ throw new DataModelException("Linker Error: Referred typedef is not resolved for type.");
}
/*
@@ -301,6 +303,28 @@
*/
return RESOLVED;
}
+ } else if (getEffectiveBuiltInType() == BINARY) {
+ if (refDerivedInfo.getResolvedExtendedInfo() == null) {
+ resolveLengthRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve length restriction will throw exception
+ * in previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
+ throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
+ "type.");
+ }
+ resolveLengthRestriction((YangRangeRestriction) refDerivedInfo.getResolvedExtendedInfo());
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve length restriction will throw exception
+ * in previous function.
+ */
+ return RESOLVED;
+ }
}
} else {
setEffectiveBuiltInType((baseType.getDataType()));
@@ -356,6 +380,28 @@
*/
return RESOLVED;
}
+ } else if (getEffectiveBuiltInType() == BINARY) {
+ if (baseType.getDataTypeExtendedInfo() == null) {
+ resolveLengthRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve length restriction will throw exception
+ * in previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(baseType.getDataTypeExtendedInfo() instanceof YangRangeRestriction)) {
+ throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
+ "type.");
+ }
+ resolveLengthRestriction((YangRangeRestriction) baseType.getDataTypeExtendedInfo());
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve length restriction will throw exception
+ * in previous function.
+ */
+ return RESOLVED;
+ }
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java
index 4ab3f2a..ef5d25a 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java
@@ -15,10 +15,14 @@
*/
package org.onosproject.yangutils.datamodel;
+import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
+
/*
* Reference:RFC 6020.
* The "import" statement makes definitions from one module available
@@ -64,7 +68,7 @@
* Represents the information about the imported modules.
*/
public class YangImport
- implements Parsable {
+ implements Parsable, LocationInfo {
/**
* Name of the module that is being imported.
@@ -78,7 +82,7 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The import's "revision-date" statement is used to specify the exact
* version of the module to import. The "revision-date" statement MUST match
* the most recent "revision" statement in the imported module. organization
@@ -87,10 +91,20 @@
private String revision;
/**
+ * Reference to node which is imported.
+ */
+ private YangNode importedNode;
+
+ // Error Line number.
+ private int lineNumber;
+
+ // Error character position.
+ private int charPosition;
+
+ /**
* Creates a YANG import.
*/
public YangImport() {
-
}
/**
@@ -181,4 +195,91 @@
// TODO auto-generated method stub, to be implemented by parser
}
+
+ /**
+ * Returns imported node.
+ *
+ * @return imported node
+ */
+ public YangNode getImportedNode() {
+ return importedNode;
+ }
+
+ /**
+ * Sets imported node.
+ *
+ * @param importedNode imported node
+ */
+ public void setImportedNode(YangNode importedNode) {
+ this.importedNode = importedNode;
+ }
+
+ @Override
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ @Override
+ public int getCharPosition() {
+ return charPosition;
+ }
+
+ @Override
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ @Override
+ public void setCharPosition(int charPositionInLine) {
+ this.charPosition = charPositionInLine;
+ }
+
+ /**
+ * Adds reference to an import.
+ *
+ * @param yangFileInfoSet YANG file info set
+ * @throws DataModelException a violation of data model rules
+ */
+ public void addReferenceToImport(Set<YangFileInfo> yangFileInfoSet) throws DataModelException {
+ String importedModuleName = getModuleName();
+ String importedModuleRevision = getRevision();
+ YangNode moduleNode = null;
+ /*
+ * Find the imported module node for a given module name
+ * with a specified revision if revision is not null.
+ */
+ if (importedModuleRevision != null) {
+ String importedModuleNameWithRevision = importedModuleName + "@" + importedModuleRevision;
+ moduleNode = findReferredNode(yangFileInfoSet, importedModuleNameWithRevision);
+ }
+
+ /*
+ * Find the imported module node for a given module name
+ * without revision if can't find with revision.
+ */
+ if (moduleNode == null) {
+ moduleNode = findReferredNode(yangFileInfoSet, importedModuleName);
+ }
+
+ if (moduleNode != null) {
+ if (moduleNode instanceof YangModule) {
+ if (getRevision() == null || getRevision().isEmpty()) {
+ setImportedNode(moduleNode);
+ return;
+ }
+ // Match revision if import is with revision.
+ if (((YangModule) moduleNode).getRevision().getRevDate().equals(importedModuleRevision)) {
+ setImportedNode(moduleNode);
+ return;
+ }
+ }
+ }
+
+ // Exception if there is no match.
+ DataModelException exception = new DataModelException("YANG file error : Imported module "
+ + importedModuleName + " with revision " + importedModuleRevision + " is not found.");
+ exception.setLine(getLineNumber());
+ exception.setCharPosition(getCharPosition());
+ throw exception;
+ }
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java
index 4892613..d331a72 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java
@@ -15,10 +15,14 @@
*/
package org.onosproject.yangutils.datamodel;
+import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
+
/*
* Reference:RFC 6020.
* The "include" statement is used to make content from a submodule
@@ -38,7 +42,7 @@
* Represents the information about the included sub-modules.
*/
public class YangInclude
- implements Parsable {
+ implements Parsable, LocationInfo {
/**
* Name of the sub-module that is being included.
@@ -52,6 +56,17 @@
private String revision;
/**
+ * Reference to node which is included.
+ */
+ private YangNode includedNode;
+
+ // Error Line number.
+ private int lineNumber;
+
+ // Error character position.
+ private int charPosition;
+
+ /**
* Creates a YANG include.
*/
public YangInclude() {
@@ -127,4 +142,98 @@
}
+ public YangNode getIncludedNode() {
+ return includedNode;
+ }
+
+ public void setIncludedNode(YangNode includedNode) {
+ this.includedNode = includedNode;
+ }
+
+ @Override
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ @Override
+ public int getCharPosition() {
+ return charPosition;
+ }
+
+ @Override
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ @Override
+ public void setCharPosition(int charPositionInLine) {
+ this.charPosition = charPositionInLine;
+ }
+
+ /**
+ * Adds reference to an include.
+ *
+ * @param yangFileInfoSet YANG file info set
+ * @return YANG sub module node
+ * @throws DataModelException a violation of data model rules
+ */
+ public YangSubModule addReferenceToInclude(Set<YangFileInfo> yangFileInfoSet) throws DataModelException {
+ String includedSubModuleName = getSubModuleName();
+ String includedSubModuleRevision = getRevision();
+ YangNode subModuleNode = null;
+
+ /*
+ * Find the included sub-module node for a given module name
+ * with a specified revision if revision is not null.
+ */
+ if (includedSubModuleRevision != null) {
+ String includedSubModuleNameWithRevision = includedSubModuleName + "@" + includedSubModuleRevision;
+ subModuleNode = findReferredNode(yangFileInfoSet, includedSubModuleNameWithRevision);
+ }
+
+ /*
+ * Find the imported sub module node for a given module name
+ * without revision if can't find with revision.
+ */
+ if (subModuleNode == null) {
+ subModuleNode = findReferredNode(yangFileInfoSet, includedSubModuleName);
+ }
+
+ if (subModuleNode != null) {
+ if (subModuleNode instanceof YangSubModule) {
+ if (getRevision() == null || getRevision().isEmpty()) {
+ setIncludedNode(subModuleNode);
+ return (YangSubModule) subModuleNode;
+ }
+ // Match revision if inclusion is with revision.
+ if (((YangSubModule) subModuleNode).getRevision().getRevDate().equals(includedSubModuleRevision)) {
+ setIncludedNode(subModuleNode);
+ return (YangSubModule) subModuleNode;
+ }
+ }
+ }
+ // Exception if there is no match.
+ DataModelException exception = new DataModelException("YANG file error : Included sub module " +
+ includedSubModuleName + "with a given revision is not found.");
+ exception.setLine(getLineNumber());
+ exception.setCharPosition(getCharPosition());
+ throw exception;
+ }
+
+ /**
+ * Reports an error when included sub-module doesn't meet condition that
+ * "included sub-modules should belong module, as defined by the
+ * "belongs-to" statement or sub-modules are only allowed to include other
+ * sub-modules belonging to the same module.
+ *
+ * @throws DataModelException a violation in data model rule
+ */
+ public void reportIncludeError() throws DataModelException {
+ DataModelException exception = new DataModelException("YANG file error : Included sub-module " +
+ getSubModuleName() + "doesn't belongs to parent module also it doesn't belongs" +
+ "to sub-module belonging to the same parent module.");
+ exception.setLine(getLineNumber());
+ exception.setCharPosition(getCharPosition());
+ throw exception;
+ }
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
new file mode 100644
index 0000000..8556445
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * Binary can be restricted with "length" statements alone.
+ *
+ */
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.utils.YangConstructType;
+import org.onosproject.yangutils.utils.builtindatatype.YangUint64;
+
+/**
+ * Represents the restriction for length data type.
+ */
+public class YangLengthRestriction implements YangDesc, YangReference, YangAppErrorInfo, Parsable {
+
+ /*-
+ * Reference RFC 6020.
+ * The length Statement
+ *
+ * The "length" statement, which is an optional sub-statement to the
+ * "type" statement, takes as an argument a length expression string.
+ * It is used to restrict the built-in type "string", or types derived
+ * from "string".
+ * A "length" statement restricts the number of unicode characters in
+ * the string.
+ * A length range consists of an explicit value, or a lower bound, two
+ * consecutive dots "..", and an upper bound. Multiple values or ranges
+ * can be given, separated by "|". Length-restricting values MUST NOT
+ * be negative. If multiple values or ranges are given, they all MUST
+ * be disjoint and MUST be in ascending order. If a length restriction
+ * is applied to an already length-restricted type, the new restriction
+ * MUST be equal or more limiting, that is, raising the lower bounds,
+ * reducing the upper bounds, removing explicit length values or ranges,
+ * or splitting ranges into multiple ranges with intermediate gaps. A
+ * length value is a non-negative integer, or one of the special values
+ * "min" or "max". "min" and "max" mean the minimum and maximum length
+ * accepted for the type being restricted, respectively. An
+ * implementation is not required to support a length value larger than
+ * 18446744073709551615.
+ * The length's sub-statements
+ *
+ * +---------------+---------+-------------+-----------------+
+ * | substatement | section | cardinality | mapped data type|
+ * +---------------+---------+-------------+-----------------+
+ * | description | 7.19.3 | 0..1 | string |
+ * | error-app-tag | 7.5.4.2 | 0..1 | string |
+ * | error-message | 7.5.4.1 | 0..1 | string |
+ * | reference | 7.19.4 | 0..1 | string |
+ * +---------------+---------+-------------+-----------------+
+ */
+
+ /**
+ * Length restriction information.
+ */
+ private YangRangeRestriction<YangUint64> lengthRestriction;
+
+ /**
+ * Textual reference.
+ */
+ private String reference;
+
+ /**
+ * Application's error message, to be used for data error.
+ */
+ private String errorMessage;
+
+ /**
+ * Application's error tag, to be filled in data validation error response.
+ */
+ private String errorAppTag;
+
+ /**
+ * Textual description.
+ */
+ private String description;
+
+ /**
+ * Creates a YANG length restriction object.
+ */
+ public YangLengthRestriction() {
+ }
+
+ /**
+ * Returns the length restriction on the string data.
+ *
+ * @return length restriction on the string data
+ */
+ public YangRangeRestriction<YangUint64> getLengthRestriction() {
+ return lengthRestriction;
+ }
+
+ /**
+ * Sets the length restriction on the string data.
+ *
+ * @param lengthRestriction length restriction on the string data
+ */
+ public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) {
+ this.lengthRestriction = lengthRestriction;
+ }
+
+ /**
+ * Returns the textual reference of the length restriction.
+ *
+ * @return textual reference of the length restriction
+ */
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ /**
+ * Sets the textual reference of the length restriction.
+ *
+ * @param ref textual reference of the length restriction
+ */
+ @Override
+ public void setReference(String ref) {
+ reference = ref;
+ }
+
+ /**
+ * Returns the description of the length restriction.
+ *
+ * @return description of the length restriction
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description of the length restriction.
+ *
+ * @param desc description of the length restriction
+ */
+ @Override
+ public void setDescription(String desc) {
+ description = desc;
+
+ }
+
+ /**
+ * Returns application's error message, to be used for data error.
+ *
+ * @return Application's error message, to be used for data error
+ */
+ @Override
+ public String getGetErrorMessage() {
+ return errorMessage;
+ }
+
+ /**
+ * Sets Application's error message, to be used for data error.
+ *
+ * @param errMsg Application's error message, to be used for data error
+ */
+ @Override
+ public void setErrorMessage(String errMsg) {
+ errorMessage = errMsg;
+
+ }
+
+ /**
+ * Returns application's error tag, to be used for data error.
+ *
+ * @return application's error tag, to be used for data error
+ */
+ @Override
+ public String getGetErrorAppTag() {
+ return errorAppTag;
+ }
+
+ /**
+ * Sets application's error tag, to be used for data error.
+ *
+ * @param errTag application's error tag, to be used for data error.
+ */
+ @Override
+ public void setErrorAppTag(String errTag) {
+ errorAppTag = errTag;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.PATTERN_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ //TODO: implement the method.
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ //TODO: implement the method.
+ }
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
index f737e32..2fc88c0 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
@@ -15,14 +15,20 @@
*/
package org.onosproject.yangutils.datamodel;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-
+import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.linkInterFileReferences;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
/*-
@@ -79,7 +85,7 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The "contact" statement provides contact information for the module. The
* argument is a string that is used to specify contact information for the
* person or persons to whom technical queries concerning this module should
@@ -90,7 +96,7 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The "description" statement takes as an argument a string that contains a
* human-readable textual description of this definition. The text is
* provided in a language (or languages) chosen by the module developer; for
@@ -125,7 +131,7 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The "organization" statement defines the party responsible for this
* module. The argument is a string that is used to specify a textual
* description of the organization(s) under whose auspices this module was
@@ -408,6 +414,14 @@
resolveLinkingForResolutionList(resolutionList, this);
}
+ @Override
+ public void resolveInterFileLinking() throws DataModelException {
+ // Get the list to be resolved.
+ List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
+ // Resolve linking for a resolution list.
+ linkInterFileReferences(resolutionList, this);
+ }
+
/**
* Returns the textual reference.
*
@@ -525,4 +539,43 @@
public void setResolutionList(List<YangResolutionInfo> resolutionList) {
unresolvedResolutionList = resolutionList;
}
+
+ @Override
+ public void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet)
+ throws LinkerException {
+ Iterator<YangImport> importInfoIterator = getImportList().iterator();
+ // Run through the imported list to add references.
+ while (importInfoIterator.hasNext()) {
+ YangImport yangImport = importInfoIterator.next();
+ try {
+ yangImport.addReferenceToImport(yangFileInfoSet);
+ } catch (DataModelException e) {
+ throw new LinkerException(e.getMessage());
+ }
+ }
+ }
+
+ @Override
+ public void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet)
+ throws LinkerException {
+ Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator();
+ // Run through the included list to add references.
+ while (includeInfoIterator.hasNext()) {
+ YangInclude yangInclude = includeInfoIterator.next();
+ YangSubModule subModule = null;
+ try {
+ subModule = yangInclude.addReferenceToInclude(yangFileInfoSet);
+ } catch (DataModelException e) {
+ throw new LinkerException(e.getMessage());
+ }
+ // Check if the referred sub-modules parent is self
+ if (!(subModule.getBelongsTo().getModuleNode() == this)) {
+ try {
+ yangInclude.reportIncludeError();
+ } catch (DataModelException e) {
+ throw new LinkerException(e.getMessage());
+ }
+ }
+ }
+ }
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
deleted file mode 100644
index ac2d6b3..0000000
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
+++ /dev/null
@@ -1,529 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.datamodel;
-
-import java.util.Stack;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-
-import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED;
-import static org.onosproject.yangutils.datamodel.ResolvableStatus.LINKED;
-import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED;
-import static org.onosproject.yangutils.datamodel.ResolvableStatus.UNRESOLVED;
-
-/**
- * Represents resolution object which will be resolved by linker.
- *
- * @param <T> type of resolution entity uses / type
- */
-public class YangResolutionInfo<T> implements LocationInfo {
-
- /**
- * Information about the entity that needs to be resolved.
- */
- private YangEntityToResolveInfo<T> entityToResolveInfo;
-
- // Error Line number.
- private int lineNumber;
-
- // Error character position.
- private int charPosition;
-
- /*
- * Stack for type/uses is maintained for hierarchical references, this is
- * used during resolution.
- */
- private Stack<YangEntityToResolveInfo<T>> partialResolvedStack;
-
- // Module/Sub-module prefix.
- private String resolutionInfoRootNodePrefix;
-
- /**
- * It is private to ensure the overloaded method be invoked to create an
- * object.
- */
- @SuppressWarnings("unused")
- private YangResolutionInfo() {
-
- }
-
- /**
- * Creates a resolution information object with all the inputs.
- *
- * @param dataNode current parsable data node
- * @param holderNode parent YANG node
- * @param lineNumber error line number
- * @param charPositionInLine error character position in line
- */
- public YangResolutionInfo(T dataNode, YangNode holderNode, int lineNumber, int charPositionInLine) {
- setEntityToResolveInfo(new YangEntityToResolveInfo<T>());
- getEntityToResolveInfo().setEntityToResolve(dataNode);
- getEntityToResolveInfo().setHolderOfEntityToResolve(holderNode);
- this.setLineNumber(lineNumber);
- this.setCharPosition(charPositionInLine);
- setPartialResolvedStack(new Stack<YangEntityToResolveInfo<T>>());
- }
-
- /**
- * Resolve linking with all the ancestors node for a resolution info.
- *
- * @param resolutionInfoNodePrefix module/sub-module prefix
- * @throws DataModelException DataModelException a violation of data model
- * rules
- */
- public void resolveLinkingForResolutionInfo(String resolutionInfoNodePrefix)
- throws DataModelException {
-
- this.resolutionInfoRootNodePrefix = resolutionInfoNodePrefix;
-
- // Current node to resolve, it can be a YANG type or YANG uses.
- T entityToResolve = getEntityToResolveInfo().getEntityToResolve();
-
- // Check if linking is already done
- if (entityToResolve instanceof Resolvable) {
- Resolvable resolvable = (Resolvable) entityToResolve;
- if (resolvable.getResolvableStatus() == RESOLVED) {
- /**
- * entity is already resolved, so nothing to do
- */
- return;
- }
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
- }
-
- // Push the initial entity to resolve in stack.
- addInPartialResolvedStack(getEntityToResolveInfo());
-
- linkAndResolvePartialResolvedStack();
- }
-
- /**
- * Resolves linking with ancestors.
- *
- * @throws DataModelException a violation of data model rules
- */
- private void linkAndResolvePartialResolvedStack()
- throws DataModelException {
-
- while (getPartialResolvedStack().size() != 0) {
-
- // Current node to resolve, it can be a YANG type or YANG uses.
- T entityToResolve = getCurrentEntityToResolveFromStack();
- // Check if linking is already done
- if (entityToResolve instanceof Resolvable) {
-
- Resolvable resolvable = (Resolvable) entityToResolve;
- switch (resolvable.getResolvableStatus()) {
- case RESOLVED: {
- /*
- * If the entity is already resolved in the stack, then
- * pop it and continue with the remaining stack elements
- * to resolve
- */
- getPartialResolvedStack().pop();
- break;
- }
-
- case LINKED: {
- /*
- * If the top of the stack is already linked then
- * resolve the references and pop the entity and
- * continue with remaining stack elements to resolve
- */
- resolveTopOfStack();
- getPartialResolvedStack().pop();
- break;
- }
-
- case INTRA_FILE_RESOLVED: {
- /*
- * TODO: this needs to be deleted, when inter-file
- * resolution is implmeneted
- */
- getPartialResolvedStack().pop();
- break;
- }
-
- case UNRESOLVED: {
- linkTopOfStackReferenceUpdateStack();
-
- if (resolvable.getResolvableStatus() == UNRESOLVED) {
- // If current entity is still not resolved, then linking/resolution has failed.
- DataModelException dataModelException =
- new DataModelException("YANG file error: Unable to find base "
- + "typedef/grouping for given type/uses");
- dataModelException.setLine(getLineNumber());
- dataModelException.setCharPosition(getCharPosition());
- throw dataModelException;
- }
- break;
- }
- default: {
- throw new DataModelException("Data Model Exception: Unsupported, linker state");
- }
-
- }
-
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
- }
-
- }
-
- }
-
- /**
- * Resolve the current entity in the stack.
- */
- private void resolveTopOfStack()
- throws DataModelException {
- ((Resolvable) getCurrentEntityToResolveFromStack()).resolve();
- if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus()
- != INTRA_FILE_RESOLVED) {
- // Sets the resolution status in inside the type/uses.
- ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(RESOLVED);
- }
- }
-
- /**
- * Resolves linking for a node child and siblings.
- *
- * @throws DataModelException data model error
- */
- private void linkTopOfStackReferenceUpdateStack()
- throws DataModelException {
-
- if (!isSelfFileReference()) {
- /*
- * TODO: use mojo utilities to load the referred module/sub-module
- * and get the reference to the corresponding referred entity
- */
-
- ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
- return;
- }
-
- /**
- * Try to resolve the top of the stack and update partial resolved stack
- * if there is recursive references
- */
- YangNode potentialAncestorWithReferredNode = getPartialResolvedStack().peek()
- .getHolderOfEntityToResolve();
-
- /**
- * Traverse up in the ancestor tree to check if the referred node is
- * defined
- */
- while (potentialAncestorWithReferredNode != null) {
-
- /**
- * Check for the referred node defined in a ancestor scope
- */
- YangNode potentialReferredNode = potentialAncestorWithReferredNode.getChild();
- if (isReferredNodeInSiblingListProcessed(potentialReferredNode)) {
- return;
- }
-
- potentialAncestorWithReferredNode = potentialAncestorWithReferredNode.getParent();
- }
- }
-
- /**
- * Check if the reference in self file or in external file.
- *
- * @return true if self file reference, false otherwise
- * @throws DataModelException a violation of data model rules
- */
- private boolean isSelfFileReference()
- throws DataModelException {
- String prefix;
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- prefix = ((YangType<?>) getCurrentEntityToResolveFromStack()).getPrefix();
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- prefix = ((YangUses) getCurrentEntityToResolveFromStack()).getPrefix();
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
- }
-
- if (prefix == null) {
- return true;
- }
- return prefix.contentEquals(resolutionInfoRootNodePrefix);
-
- }
-
- /**
- * Check for the referred node defined in a ancestor scope.
- *
- * @param potentialReferredNode potential referred node
- * @return status of resolution and updating the partial resolved stack with
- * the any recursive references
- * @throws DataModelException data model errors
- */
- private boolean isReferredNodeInSiblingListProcessed(YangNode potentialReferredNode)
- throws DataModelException {
- while (potentialReferredNode != null) {
-
- // Check if the potential referred node is the actual referred node
- if (isReferredNode(potentialReferredNode)) {
-
- // Adds reference link of entity to the node under resolution.
- addReferredEntityLink(potentialReferredNode);
-
- /**
- * resolve the reference and update the partial resolution stack
- * with any further recursive references
- */
- addUnresolvedRecursiveReferenceToStack(potentialReferredNode);
-
- /*
- * return true, since the reference is linked and any recursive
- * unresolved references is added to the stack
- */
- return true;
- }
-
- potentialReferredNode = potentialReferredNode.getNextSibling();
- }
- return false;
- }
-
- /**
- * Check if the potential referred node is the actual referred node.
- *
- * @param potentialReferredNode typedef/grouping node
- * @return true if node is of resolve type otherwise false
- * @throws DataModelException a violation of data model rules
- */
- private boolean isReferredNode(YangNode potentialReferredNode)
- throws DataModelException {
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- if (potentialReferredNode instanceof YangTypeDef) {
- /*
- * Check if name of node name matches with the entity being
- * resolved
- */
- return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
- }
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- if (potentialReferredNode instanceof YangGrouping) {
- /*
- * Check if name of node name matches with the entity being
- * resolved
- */
- return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
- }
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
- }
- return false;
- }
-
- /**
- * Check if node name is same as name in resolution info, i.e. name of
- * typedef/grouping is same as name of type/uses.
- *
- * @param node typedef/grouping node
- * @return true if node name is same as name in resolution info, otherwise
- * false
- * @throws DataModelException a violation of data model rules
- */
-
- private boolean isNodeNameSameAsResolutionInfoName(YangNode node)
- throws DataModelException {
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- if (node.getName().contentEquals(
- ((YangType<?>) getCurrentEntityToResolveFromStack())
- .getDataTypeName())) {
- return true;
- }
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- if (node.getName().contentEquals(
- ((YangUses) getCurrentEntityToResolveFromStack()).getName())) {
- return true;
- }
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
- }
- return false;
- }
-
- /**
- * Adds reference of grouping/typedef in uses/type.
- *
- * @param referredNode grouping/typedef node being referred
- * @throws DataModelException a violation of data model rules
- */
- private void addReferredEntityLink(YangNode referredNode)
- throws DataModelException {
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>)
- ((YangType<?>) getCurrentEntityToResolveFromStack()).getDataTypeExtendedInfo();
- derivedInfo.setReferredTypeDef((YangTypeDef) referredNode);
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- ((YangUses) getCurrentEntityToResolveFromStack())
- .setRefGroup((YangGrouping) referredNode);
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
- }
-
- // Sets the resolution status in inside the type/uses.
- ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(LINKED);
- }
-
- /**
- * Checks if type/grouping has further reference to typedef/ unresolved
- * uses. Add it to the partial resolve stack and return the status of
- * addition to stack.
- *
- * @param referredNode grouping/typedef node
- * @throws DataModelException a violation of data model rules
- */
- private void addUnresolvedRecursiveReferenceToStack(YangNode referredNode)
- throws DataModelException {
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- /*
- * Checks if typedef type is derived
- */
- if (((YangTypeDef) referredNode).getTypeDefBaseType().getDataType()
- == YangDataTypes.DERIVED) {
-
- YangEntityToResolveInfo<YangType<?>> unResolvedEntityInfo = new YangEntityToResolveInfo<YangType<?>>();
- unResolvedEntityInfo.setEntityToResolve(((YangTypeDef) referredNode)
- .getTypeDefBaseType());
- unResolvedEntityInfo.setHolderOfEntityToResolve(referredNode);
- addInPartialResolvedStack((YangEntityToResolveInfo<T>) unResolvedEntityInfo);
- }
-
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- /*
- * Search if the grouping has any un resolved uses child, if so
- * return true, else return false.
- */
- addUnResolvedUsesToStack(referredNode);
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
- }
- }
-
- /**
- * Return if there is any unresolved uses in grouping.
- *
- * @param node grouping/typedef node
- */
- private void addUnResolvedUsesToStack(YangNode node) {
-
- /**
- * Search the grouping node's children for presence of uses node.
- */
- YangNode curNode = node.getChild();
- while (curNode != null) {
- if (curNode instanceof YangUses) {
- ResolvableStatus curResolveStatus = ((Resolvable) curNode).getResolvableStatus();
- if (curResolveStatus == UNRESOLVED) {
- /**
- * The current uses is not resolved, add it to partial
- * resolved stack
- */
- YangEntityToResolveInfo<YangUses> unResolvedEntityInfo = new YangEntityToResolveInfo<YangUses>();
- unResolvedEntityInfo.setEntityToResolve((YangUses) curNode);
- unResolvedEntityInfo.setHolderOfEntityToResolve(node);
- addInPartialResolvedStack((YangEntityToResolveInfo<T>) unResolvedEntityInfo);
-
- }
- }
- curNode = curNode.getNextSibling();
- }
- }
-
- /**
- * Returns stack of YANG type with partially resolved YANG construct
- * hierarchy.
- *
- * @return partial resolved YANG construct stack
- */
- private Stack<YangEntityToResolveInfo<T>> getPartialResolvedStack() {
- return partialResolvedStack;
- }
-
- /**
- * Sets stack of YANG type with partially resolved YANG construct hierarchy.
- *
- * @param partialResolvedStack partial resolved YANG construct stack
- */
- private void setPartialResolvedStack(Stack<YangEntityToResolveInfo<T>> partialResolvedStack) {
- this.partialResolvedStack = partialResolvedStack;
- }
-
- /**
- * Sets stack of YANG type with partially resolved YANG construct hierarchy.
- *
- * @param partialResolvedInfo partial resolved YANG construct stack
- */
- private void addInPartialResolvedStack(YangEntityToResolveInfo<T> partialResolvedInfo) {
- getPartialResolvedStack().push(partialResolvedInfo);
- }
-
- /**
- * Retrieves the next entity in the stack that needs to be resolved. It is
- * assumed that the caller ensures that the stack is not empty.
- *
- * @return next entity in the stack that needs to be resolved
- */
- private T getCurrentEntityToResolveFromStack() {
- return getPartialResolvedStack().peek().getEntityToResolve();
- }
-
- /**
- * Retrieves information about the entity that needs to be resolved.
- *
- * @return information about the entity that needs to be resolved
- */
- public YangEntityToResolveInfo<T> getEntityToResolveInfo() {
- return entityToResolveInfo;
- }
-
- /**
- * Sets information about the entity that needs to be resolved.
- *
- * @param entityToResolveInfo information about the entity that needs to be
- * resolved
- */
- public void setEntityToResolveInfo(YangEntityToResolveInfo<T> entityToResolveInfo) {
- this.entityToResolveInfo = entityToResolveInfo;
- }
-
- @Override
- public int getLineNumber() {
- return lineNumber;
- }
-
- @Override
- public int getCharPosition() {
- return charPosition;
- }
-
- @Override
- public void setLineNumber(int lineNumber) {
- this.lineNumber = lineNumber;
- }
-
- @Override
- public void setCharPosition(int charPositionInLine) {
- this.charPosition = charPositionInLine;
- }
-}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
index d762151..bf442a1 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
@@ -15,14 +15,20 @@
*/
package org.onosproject.yangutils.datamodel;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-
+import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.linkInterFileReferences;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
/*
@@ -92,7 +98,7 @@
/**
* Reference RFC 6020.
- *
+ * <p>
* The "contact" statement provides contact information for the module. The
* argument is a string that is used to specify contact information for the
* person or persons to whom technical queries concerning this module should
@@ -338,6 +344,14 @@
resolveLinkingForResolutionList(resolutionList, this);
}
+ @Override
+ public void resolveInterFileLinking() throws DataModelException {
+ // Get the list to be resolved.
+ List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
+ // Resolve linking for a resolution list.
+ linkInterFileReferences(resolutionList, this);
+ }
+
/**
* Returns the list of leaves.
*
@@ -507,4 +521,54 @@
public void setResolutionList(List<YangResolutionInfo> resolutionList) {
this.unresolvedResolutionList = resolutionList;
}
+
+ /**
+ * Links the sub-module with module.
+ *
+ * @param yangFileInfoSet YANG file information set
+ * @throws DataModelException a violation in data model rule
+ */
+ public void linkWithModule(Set<YangFileInfo> yangFileInfoSet)
+ throws DataModelException {
+ getBelongsTo().linkWithModule(yangFileInfoSet);
+ }
+
+ @Override
+ public void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet)
+ throws LinkerException {
+ Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator();
+ // Run through the included list to add references.
+ while (includeInfoIterator.hasNext()) {
+ YangInclude yangInclude = includeInfoIterator.next();
+ YangSubModule subModule = null;
+ try {
+ subModule = yangInclude.addReferenceToInclude(yangFileInfoSet);
+ } catch (DataModelException e) {
+ throw new LinkerException(e.getMessage());
+ }
+ // Check if the referred sub-modules parent is self
+ if (!(subModule.getBelongsTo().getModuleNode() == getBelongsTo().getModuleNode())) {
+ try {
+ yangInclude.reportIncludeError();
+ } catch (DataModelException e) {
+ throw new LinkerException(e.getMessage());
+ }
+ }
+ }
+ }
+
+ @Override
+ public void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet)
+ throws LinkerException {
+ Iterator<YangImport> importInfoIterator = getImportList().iterator();
+ // Run through the imported list to add references.
+ while (importInfoIterator.hasNext()) {
+ YangImport yangImport = importInfoIterator.next();
+ try {
+ yangImport.addReferenceToImport(yangFileInfoSet);
+ } catch (DataModelException e) {
+ throw new LinkerException(e.getMessage());
+ }
+ }
+ }
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangType.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
index d37a8c7..4421619 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
@@ -17,6 +17,9 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import org.onosproject.yangutils.linker.impl.Resolvable;
+import org.onosproject.yangutils.linker.impl.ResolvableStatus;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
@@ -244,21 +247,25 @@
}
@Override
- public void resolve() throws DataModelException {
+ public void resolve() throws LinkerException {
/*
* Check whether the data type is derived.
*/
if (getDataType() != DERIVED) {
- throw new DataModelException("Linker Error: Resolve should only be called for derived data types.");
+ throw new LinkerException("Linker Error: Resolve should only be called for derived data types.");
}
// Check if the derived info is present.
YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo();
if (derivedInfo == null) {
- throw new DataModelException("Linker Error: Derived information is missing.");
+ throw new LinkerException("Linker Error: Derived information is missing.");
}
// Initiate the resolution
- setResolvableStatus(derivedInfo.resolve());
+ try {
+ setResolvableStatus(derivedInfo.resolve());
+ } catch (DataModelException e) {
+ throw new LinkerException(e.getMessage());
+ }
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
index 55fbaf4..f6a5e6b 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
@@ -16,6 +16,9 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import org.onosproject.yangutils.linker.impl.Resolvable;
+import org.onosproject.yangutils.linker.impl.ResolvableStatus;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
@@ -259,37 +262,49 @@
@Override
public void resolve()
- throws DataModelException {
+ throws LinkerException {
YangGrouping referredGrouping = getRefGroup();
if (referredGrouping == null) {
- throw new DataModelException("YANG uses linker error, cannot resolve uses");
+ throw new LinkerException("Linker Exception: YANG uses linker error, cannot resolve uses");
}
YangNode usesParentNode = getParentNodeInGenCode(this);
if ((!(usesParentNode instanceof YangLeavesHolder))
|| (!(usesParentNode instanceof CollisionDetector))) {
- throw new DataModelException("YANG uses holder construct is wrong");
+ throw new LinkerException("Linker Exception: YANG uses holder construct is wrong");
}
YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode;
if (referredGrouping.getListOfLeaf() != null) {
for (YangLeaf leaf : referredGrouping.getListOfLeaf()) {
- ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(),
- YangConstructType.LEAF_DATA);
+ try {
+ ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(),
+ YangConstructType.LEAF_DATA);
+ } catch (DataModelException e) {
+ throw new LinkerException(e.getMessage());
+ }
usesParentLeavesHolder.addLeaf(leaf);
}
}
if (referredGrouping.getListOfLeafList() != null) {
for (YangLeafList leafList : referredGrouping.getListOfLeafList()) {
- ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(),
- YangConstructType.LEAF_LIST_DATA);
+ try {
+ ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(),
+ YangConstructType.LEAF_LIST_DATA);
+ } catch (DataModelException e) {
+ throw new LinkerException(e.getMessage());
+ }
usesParentLeavesHolder.addLeafList(leafList);
}
}
- YangNode.cloneSubTree(getRefGroup(), usesParentNode);
+ try {
+ YangNode.cloneSubTree(getRefGroup(), usesParentNode);
+ } catch (DataModelException e) {
+ throw new LinkerException(e.getMessage());
+ }
}
@Override
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
index e243d5e..93eb417 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -16,17 +16,15 @@
package org.onosproject.yangutils.datamodel.utils;
-import java.util.Iterator;
import java.util.List;
-
+import java.util.Set;
import org.onosproject.yangutils.datamodel.CollisionDetector;
-import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangReferenceResolver;
-import org.onosproject.yangutils.datamodel.YangResolutionInfo;
+import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
@@ -48,14 +46,13 @@
* Detects the colliding identifier name in a given YANG node and its child.
*
* @param identifierName name for which collision detection is to be
- * checked
- * @param dataType type of YANG node asking for detecting collision
- * @param node instance of calling node
+ * checked
+ * @param dataType type of YANG node asking for detecting collision
+ * @param node instance of calling node
* @throws DataModelException a violation of data model rules
*/
public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node)
throws DataModelException {
-
if (dataType == YangConstructType.USES_DATA || dataType == YangConstructType.GROUPING_DATA) {
detectCollidingForUsesGrouping(identifierName, dataType, node);
} else {
@@ -81,9 +78,9 @@
* Detects colliding of uses and grouping only with uses and grouping respectively.
*
* @param identifierName name for which collision detection is to be
- * checked
- * @param dataType type of YANG node asking for detecting collision
- * @param node node instance of calling node
+ * checked
+ * @param dataType type of YANG node asking for detecting collision
+ * @param node node instance of calling node
* @throws DataModelException a violation of data model rules
*/
public static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node)
@@ -103,9 +100,9 @@
/**
* Detects the colliding identifier name in a given leaf node.
*
- * @param listOfLeaf List of leaves to detect collision
+ * @param listOfLeaf List of leaves to detect collision
* @param identifierName name for which collision detection is to be
- * checked
+ * checked
* @throws DataModelException a violation of data model rules
*/
private static void detectCollidingLeaf(List<YangLeaf> listOfLeaf, String identifierName)
@@ -127,7 +124,7 @@
*
* @param listOfLeafList list of leaf-lists to detect collision
* @param identifierName name for which collision detection is to be
- * checked
+ * checked
* @throws DataModelException a violation of data model rules
*/
private static void detectCollidingLeafList(List<YangLeafList> listOfLeafList, String identifierName)
@@ -148,7 +145,7 @@
* Add a resolution information.
*
* @param resolutionInfo information about the YANG construct which has to
- * be resolved
+ * be resolved
* @throws DataModelException a violation of data model rules
*/
public static void addResolutionInfo(YangResolutionInfo resolutionInfo)
@@ -165,64 +162,41 @@
}
YangReferenceResolver resolutionNode = (YangReferenceResolver) curNode;
- if (!isPrefixValid(resolutionInfo.getEntityToResolveInfo().getEntityPrefix(),
- resolutionNode)) {
- throw new DataModelException("The prefix used is not valid");
- }
resolutionNode.addToResolutionList(resolutionInfo);
}
/**
- * Evaluates whether the prefix in uses/type is valid.
- *
- * @param entityPrefix prefix in the current module/sub-module
- * @param resolutionNode uses/type node which has the prefix with it
- * @return whether prefix is valid or not
- */
- private static boolean isPrefixValid(String entityPrefix, YangReferenceResolver resolutionNode) {
- if (entityPrefix == null) {
- return true;
- }
-
- if (resolutionNode.getPrefix().contentEquals(entityPrefix)) {
- return true;
- }
-
- if (resolutionNode.getImportList() != null) {
- for (YangImport importedInfo : resolutionNode.getImportList()) {
- if (importedInfo.getPrefixId().contentEquals(entityPrefix)) {
- return true;
- }
- }
- }
-
- if (resolutionNode.getIncludeList() != null) {
- /**
- * TODO: check if the prefix matches with the imported data
-
- for (YangInclude includedInfo : resolutionNode.getIncludeList()) {
- if (includedInfo.contentEquals(prefix)) {
- return true;
- }
- }*/
- }
-
- return false;
- }
-
- /**
* Resolve linking for a resolution list.
*
- * @param resolutionList resolution list for which linking to be done
+ * @param resolutionList resolution list for which linking to be done
* @param dataModelRootNode module/sub-module node
* @throws DataModelException a violation of data model rules
*/
public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList,
- YangReferenceResolver dataModelRootNode)
+ YangReferenceResolver dataModelRootNode)
throws DataModelException {
for (YangResolutionInfo resolutionInfo : resolutionList) {
- resolutionInfo.resolveLinkingForResolutionInfo(dataModelRootNode.getPrefix());
+ resolutionInfo.resolveLinkingForResolutionInfo(dataModelRootNode);
+ }
+ }
+
+ /**
+ * Links type/uses referring to typedef/uses of inter YANG file.
+ *
+ * @param resolutionList resolution list for which linking to be done
+ * @param dataModelRootNode module/sub-module node
+ * @throws DataModelException a violation of data model rules
+ */
+ public static void linkInterFileReferences(List<YangResolutionInfo> resolutionList,
+ YangReferenceResolver dataModelRootNode)
+ throws DataModelException {
+ /*
+ * Run through the resolution list, find type/uses referring to
+ * inter file typedef/grouping, ask for linking.
+ */
+ for (YangResolutionInfo resolutionInfo : resolutionList) {
+ resolutionInfo.linkInterFile(dataModelRootNode);
}
}
@@ -244,24 +218,23 @@
}
/**
- * Returns module's data model node to which sub-module belongs to.
+ * Returns referred node in a given set.
*
- * @param yangFileInfo YANG file information
- * @param belongsToModuleName name of the module to which sub-module belongs to
- * @return module node to which sub-module belongs to
- * @throws DataModelException when belongs to module node is not found
+ * @param yangFileInfoSet YANG file info set
+ * @param refNodeName name of the node which is referred
+ * @return referred node's reference
*/
- public static YangNode findBelongsToModuleNode(List<YangFileInfo> yangFileInfo,
- String belongsToModuleName) throws DataModelException {
- Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
- while (yangFileIterator.hasNext()) {
- YangFileInfo yangFile = yangFileIterator.next();
- YangNode yangNode = yangFile.getRootNode();
- if (yangNode.getName().equals(belongsToModuleName)) {
- return yangNode;
+ public static YangNode findReferredNode(Set<YangFileInfo> yangFileInfoSet, String refNodeName) {
+ /*
+ * Run through the YANG files to see which YANG file matches the
+ * referred node name.
+ */
+ for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+ YangNode yangNode = yangFileInfo.getRootNode();
+ if (yangNode.getName().equals(refNodeName)) {
+ return yangFileInfo.getRootNode();
}
}
- throw new DataModelException("YANG file error : Module " + belongsToModuleName + " to which sub-module " +
- "belongs to is not found.");
+ return null;
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/YangLinker.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/YangLinker.java
index f659fa9..bbb673a 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/YangLinker.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/YangLinker.java
@@ -16,8 +16,8 @@
package org.onosproject.yangutils.linker;
-import java.util.Map;
-import org.onosproject.yangutils.datamodel.YangReferenceResolver;
+import java.util.Set;
+import org.onosproject.yangutils.plugin.manager.YangFileInfo;
/**
* Abstraction of entity which provides linking service of YANG files.
@@ -28,8 +28,7 @@
* Resolve the import and include dependencies for a given resolution
* information.
*
- * @param fileMapEntry map entry for which resolution is to be done
- * @param yangFilesMap map of dependent file and resolution information*/
- void resolveDependencies(Map.Entry<String, YangReferenceResolver> fileMapEntry, Map<String,
- YangReferenceResolver> yangFilesMap);
+ * @param yangFileInfoSet set of all dependent YANG files
+ */
+ void resolveDependencies(Set<YangFileInfo> yangFileInfoSet);
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/exceptions/LinkerException.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/exceptions/LinkerException.java
new file mode 100644
index 0000000..755b5b4
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/exceptions/LinkerException.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.linker.exceptions;
+
+/**
+ * Represents base class for exceptions in linker operations.
+ */
+public class LinkerException extends RuntimeException {
+
+ private static final long serialVersionUID = 20160211L;
+ private int lineNumber;
+ private int charPositionInLine;
+ private String fileName;
+
+ /**
+ * Creates a new linker exception.
+ */
+ public LinkerException() {
+ super();
+ }
+
+ /**
+ * Creates a new linker exception with given message.
+ *
+ * @param message the detail of exception in string
+ */
+ public LinkerException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new linker exception from given message and cause.
+ *
+ * @param message the detail of exception in string
+ * @param cause underlying cause of the error
+ */
+ public LinkerException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new linker exception from cause.
+ *
+ * @param cause underlying cause of the error
+ */
+ public LinkerException(final Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Returns line number of the exception.
+ *
+ * @return line number of the exception
+ */
+ public int getLineNumber() {
+ return this.lineNumber;
+ }
+
+ /**
+ * Returns YANG file name of the exception.
+ *
+ * @return YANG file name of the exception
+ */
+ public String getFileName() {
+ return this.fileName;
+ }
+
+ /**
+ * Returns position of the exception.
+ *
+ * @return position of the exception
+ */
+ public int getCharPositionInLine() {
+ return this.charPositionInLine;
+ }
+
+ /**
+ * Sets line number of YANG file.
+ *
+ * @param line line number of YANG file
+ */
+ public void setLine(int line) {
+ this.lineNumber = line;
+ }
+
+ /**
+ * Sets position of exception.
+ *
+ * @param charPosition position of exception
+ */
+ public void setCharPosition(int charPosition) {
+ this.charPositionInLine = charPosition;
+ }
+
+ /**
+ * Sets file name in parser exception.
+ *
+ * @param fileName YANG file name
+ */
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/exceptions/package-info.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/exceptions/package-info.java
new file mode 100644
index 0000000..42cf3a2
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/exceptions/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+/**
+ * Custom linker exceptions.
+ */
+package org.onosproject.yangutils.linker.exceptions;
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/Resolvable.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/Resolvable.java
similarity index 88%
rename from utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/Resolvable.java
rename to utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/Resolvable.java
index e05f4a9..f384dc5 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/Resolvable.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/Resolvable.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package org.onosproject.yangutils.datamodel;
+package org.onosproject.yangutils.linker.impl;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
/**
* Abstraction of YANG resolvable information. Abstracted to obtain the
@@ -47,8 +47,8 @@
/**
* Resolves the linking.
*
- * @throws DataModelException data model error
+ * @throws LinkerException linker error
*/
void resolve()
- throws DataModelException;
+ throws LinkerException;
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolvableStatus.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/ResolvableStatus.java
similarity index 83%
rename from utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolvableStatus.java
rename to utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/ResolvableStatus.java
index d1cacb4..cd43c18 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolvableStatus.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/ResolvableStatus.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yangutils.datamodel;
+package org.onosproject.yangutils.linker.impl;
/**
* Represents the status of resolvable entity.
@@ -40,6 +40,12 @@
/**
* Identifies that resolvable entity is resolved.
*/
- RESOLVED
+ RESOLVED,
+
+ /**
+ * Identifies that resolvable entity is inter file linked (i.e. complete
+ * linking with external files).
+ */
+ INTER_FILE_LINKED
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfo.java
similarity index 83%
rename from utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java
rename to utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfo.java
index 229625c..f239692 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfo.java
@@ -13,9 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.yangutils.datamodel;
+package org.onosproject.yangutils.linker.impl;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangUses;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
/**
* Represents information about entity being resolved.
@@ -61,7 +64,7 @@
* Sets parent node which contains the entity to be resolved.
*
* @param holderOfEntityToResolve parent node which contains the entity to
- * be resolved
+ * be resolved
*/
public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
this.holderOfEntityToResolve = holderOfEntityToResolve;
@@ -71,10 +74,10 @@
* Retrieves the prefix of the entity.
*
* @return entities prefix
- * @throws DataModelException data model error
+ * @throws LinkerException linker error
*/
public String getEntityPrefix()
- throws DataModelException {
+ throws LinkerException {
if (getEntityToResolve() == null) {
return null;
}
@@ -86,7 +89,7 @@
} else if (entityToBeResolved instanceof YangUses) {
prefix = ((YangUses) entityToBeResolved).getPrefix();
} else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses");
}
return prefix;
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
new file mode 100644
index 0000000..0fc3d99
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.onosproject.yangutils.linker.impl;
+
+import java.util.Set;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.YangLinker;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import org.onosproject.yangutils.plugin.manager.YangFileInfo;
+
+import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+
+/**
+ * Representation of entity which provides linking service of YANG files.
+ */
+public class YangLinkerManager implements YangLinker {
+ @Override
+ public void resolveDependencies(Set<YangFileInfo> yangFileInfoSet) {
+
+ // Carry out linking of sub module with module.
+ linkSubModulesToParentModule(yangFileInfoSet);
+
+ // Add references to import list.
+ addRefToYangFilesImportList(yangFileInfoSet);
+
+ // Add reference to include list.
+ addRefToYangFilesIncludeList(yangFileInfoSet);
+
+ // TODO check for circular import/include.
+
+ // Carry out inter-file linking.
+ processInterFileLinking(yangFileInfoSet);
+ }
+
+ /**
+ * Resolves sub-module linking by linking sub module with parent module.
+ *
+ * @param yangFileInfoSet set of YANG files info
+ * @throws LinkerException fails to link sub-module to parent module
+ */
+ public void linkSubModulesToParentModule(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
+ for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+ YangNode yangNode = yangFileInfo.getRootNode();
+ if (yangNode instanceof YangSubModule) {
+ try {
+ ((YangSubModule) yangNode).linkWithModule(yangFileInfoSet);
+ } catch (DataModelException e) {
+ String errorInfo = "YANG file error: " + yangFileInfo.getYangFileName() + " at line: "
+ + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
+ + e.getMessage();
+ throw new LinkerException(errorInfo);
+ }
+ }
+ }
+ }
+
+ /**
+ * Adds imported node information to the import list.
+ *
+ * @param yangFileInfoSet set of YANG files info
+ * @throws LinkerException fails to find imported module
+ */
+ public void addRefToYangFilesImportList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
+ for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+ YangNode yangNode = yangFileInfo.getRootNode();
+ if (yangNode instanceof YangReferenceResolver) {
+ ((YangReferenceResolver) yangNode).addReferencesToImportList(yangFileInfoSet);
+ }
+ }
+ }
+
+ /**
+ * Adds included node information to the include list.
+ *
+ * @param yangFileInfoSet set of YANG files info
+ * @throws LinkerException fails to find included sub-module
+ */
+ public void addRefToYangFilesIncludeList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
+ for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+ YangNode yangNode = yangFileInfo.getRootNode();
+ if (yangNode instanceof YangReferenceResolver) {
+ ((YangReferenceResolver) yangNode).addReferencesToIncludeList(yangFileInfoSet);
+ }
+ }
+ }
+
+ /**
+ * Processes inter file linking for type and uses.
+ *
+ * @param yangFileInfoSet set of YANG files info
+ * @throws LinkerException a violation in linker execution
+ */
+ public void processInterFileLinking(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
+ for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+ try {
+ ((YangReferenceResolver) yangFileInfo.getRootNode()).resolveInterFileLinking();
+ } catch (DataModelException e) {
+ String errorInfo = "Error in file: " + yangFileInfo.getYangFileName() + " at line: "
+ + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
+ throw new LinkerException(errorInfo);
+ }
+ }
+ }
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangReferenceResolver.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangReferenceResolver.java
similarity index 67%
rename from utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangReferenceResolver.java
rename to utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangReferenceResolver.java
index e9ae54d..4681985 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangReferenceResolver.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangReferenceResolver.java
@@ -14,10 +14,15 @@
* limitations under the License.
*/
-package org.onosproject.yangutils.datamodel;
+package org.onosproject.yangutils.linker.impl;
import java.util.List;
+import java.util.Set;
+import org.onosproject.yangutils.datamodel.YangImport;
+import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import org.onosproject.yangutils.plugin.manager.YangFileInfo;
/**
* Abstraction of YANG dependency resolution information. Abstracted to obtain the
@@ -33,7 +38,7 @@
List<YangResolutionInfo> getUnresolvedResolutionList();
/**
- * Add to the resolution list.
+ * Adds to the resolution list.
*
* @param resolutionInfo resolution information
*/
@@ -54,7 +59,7 @@
List<YangImport> getImportList();
/**
- * Add to the import list.
+ * Adds to the import list.
*
* @param yangImport import to be added
*/
@@ -75,14 +80,14 @@
List<YangInclude> getIncludeList();
/**
- * Add to the include list.
+ * Adds to the include list.
*
* @param yangInclude include to be added
*/
void addToIncludeList(YangInclude yangInclude);
/**
- * Create include list.
+ * Creates include list.
*
* @param includeList include list
*/
@@ -96,16 +101,39 @@
String getPrefix();
/**
- * Set prefix of resolution list root node.
+ * Sets prefix of resolution list root node.
*
* @param prefix resolution root node prefix
*/
void setPrefix(String prefix);
/**
- * Resolve self file linking.
+ * Resolves self file linking.
*
* @throws DataModelException a violation in data model rule
*/
void resolveSelfFileLinking() throws DataModelException;
+
+ /**
+ * Resolves inter file linking.
+ *
+ * @throws DataModelException a violation in data model rule
+ */
+ void resolveInterFileLinking() throws DataModelException;
+
+ /**
+ * Adds references to include.
+ *
+ * @param yangFileInfoSet YANG file info set
+ * @throws LinkerException a violation of linker rules
+ */
+ void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException;
+
+ /**
+ * Adds references to import.
+ *
+ * @param yangFileInfoSet YANG file info set
+ * @throws LinkerException a violation of linker rules
+ */
+ void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException;
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java
new file mode 100644
index 0000000..d838440
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java
@@ -0,0 +1,855 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.linker.impl;
+
+import java.util.Stack;
+import org.onosproject.yangutils.datamodel.LocationInfo;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangDerivedInfo;
+import org.onosproject.yangutils.datamodel.YangGrouping;
+import org.onosproject.yangutils.datamodel.YangImport;
+import org.onosproject.yangutils.datamodel.YangInclude;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.YangUses;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTER_FILE_LINKED;
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.LINKED;
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED;
+
+/**
+ * Represents resolution object which will be resolved by linker.
+ *
+ * @param <T> type of resolution entity uses / type
+ */
+public class YangResolutionInfo<T> implements LocationInfo {
+
+ /**
+ * Information about the entity that needs to be resolved.
+ */
+ private YangEntityToResolveInfo<T> entityToResolveInfo;
+
+ /**
+ * Error line number.
+ */
+ private int lineNumber;
+
+ /**
+ * Error character position in number.
+ */
+ private int charPosition;
+
+ /**
+ * Current module/sub-module reference, will be used in inter-file/
+ * inter-jar scenario to get the import/include list.
+ */
+ private YangReferenceResolver curReferenceResolver;
+
+ /**
+ * Stack for type/uses is maintained for hierarchical references, this is
+ * used during resolution.
+ */
+ private Stack<YangEntityToResolveInfo<T>> partialResolvedStack;
+
+ /**
+ * It is private to ensure the overloaded method be invoked to create an
+ * object.
+ */
+ @SuppressWarnings("unused")
+ private YangResolutionInfo() {
+
+ }
+
+ /**
+ * Creates a resolution information object with all the inputs.
+ *
+ * @param dataNode current parsable data node
+ * @param holderNode parent YANG node
+ * @param lineNumber error line number
+ * @param charPositionInLine error character position in line
+ */
+ public YangResolutionInfo(T dataNode, YangNode holderNode, int lineNumber, int charPositionInLine) {
+ setEntityToResolveInfo(new YangEntityToResolveInfo<>());
+ getEntityToResolveInfo().setEntityToResolve(dataNode);
+ getEntityToResolveInfo().setHolderOfEntityToResolve(holderNode);
+ this.setLineNumber(lineNumber);
+ this.setCharPosition(charPositionInLine);
+ setPartialResolvedStack(new Stack<>());
+ }
+
+ /**
+ * Resolves linking with all the ancestors node for a resolution info.
+ *
+ * @param dataModelRootNode module/sub-module node
+ * @throws DataModelException DataModelException a violation of data model
+ * rules
+ */
+ public void resolveLinkingForResolutionInfo(YangReferenceResolver dataModelRootNode)
+ throws DataModelException {
+
+ setCurReferenceResolver(dataModelRootNode);
+
+ // Current node to resolve, it can be a YANG type or YANG uses.
+ T entityToResolve = getEntityToResolveInfo().getEntityToResolve();
+
+ // Check if linking is already done
+ if (entityToResolve instanceof Resolvable) {
+ Resolvable resolvable = (Resolvable) entityToResolve;
+ if (resolvable.getResolvableStatus() == RESOLVED) {
+ /**
+ * entity is already resolved, so nothing to do
+ */
+ return;
+ }
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ }
+
+ // Push the initial entity to resolve in stack.
+ addInPartialResolvedStack(getEntityToResolveInfo());
+
+ linkAndResolvePartialResolvedStack();
+ }
+
+ /**
+ * Resolves linking with ancestors.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ private void linkAndResolvePartialResolvedStack()
+ throws DataModelException {
+
+ while (getPartialResolvedStack().size() != 0) {
+
+ // Current node to resolve, it can be a YANG type or YANG uses.
+ T entityToResolve = getCurrentEntityToResolveFromStack();
+ // Check if linking is already done
+ if (entityToResolve instanceof Resolvable) {
+
+ Resolvable resolvable = (Resolvable) entityToResolve;
+ switch (resolvable.getResolvableStatus()) {
+ case RESOLVED: {
+ /*
+ * If the entity is already resolved in the stack, then
+ * pop it and continue with the remaining stack elements
+ * to resolve
+ */
+ getPartialResolvedStack().pop();
+ break;
+ }
+
+ case LINKED: {
+ /*
+ * If the top of the stack is already linked then
+ * resolve the references and pop the entity and
+ * continue with remaining stack elements to resolve.
+ */
+ resolveTopOfStack();
+ getPartialResolvedStack().pop();
+ break;
+ }
+
+ case INTRA_FILE_RESOLVED: {
+ /*
+ * Pop the top of the stack.
+ */
+ getPartialResolvedStack().pop();
+ break;
+ }
+
+ case UNRESOLVED: {
+ linkTopOfStackReferenceUpdateStack();
+
+ if (resolvable.getResolvableStatus() == UNRESOLVED) {
+ // If current entity is still not resolved, then linking/resolution has failed.
+ DataModelException dataModelException =
+ new DataModelException("YANG file error: Unable to find base "
+ + "typedef/grouping for given type/uses");
+ dataModelException.setLine(getLineNumber());
+ dataModelException.setCharPosition(getCharPosition());
+ throw dataModelException;
+ }
+ break;
+ }
+ default: {
+ throw new DataModelException("Data Model Exception: Unsupported, linker state");
+ }
+
+ }
+
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ }
+
+ }
+
+ }
+
+ /**
+ * Resolves the current entity in the stack.
+ */
+ private void resolveTopOfStack()
+ throws DataModelException {
+ ((Resolvable) getCurrentEntityToResolveFromStack()).resolve();
+ if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus()
+ != INTRA_FILE_RESOLVED) {
+ // Sets the resolution status in inside the type/uses.
+ ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(RESOLVED);
+ }
+ }
+
+ /**
+ * Resolves linking for a node child and siblings.
+ *
+ * @throws DataModelException data model error
+ */
+ private void linkTopOfStackReferenceUpdateStack()
+ throws DataModelException {
+
+ /*
+ * Check if self file reference is there, this will not check for the
+ * scenario when prefix is not present and type/uses is present in
+ * sub-module from include list.
+ */
+ if (!isCandidateForSelfFileReference()) {
+ ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
+ return;
+ }
+
+ /**
+ * Try to resolve the top of the stack and update partial resolved stack
+ * if there is recursive references
+ */
+ YangNode potentialAncestorWithReferredNode = getPartialResolvedStack().peek()
+ .getHolderOfEntityToResolve();
+
+ /**
+ * Traverse up in the ancestor tree to check if the referred node is
+ * defined
+ */
+ while (potentialAncestorWithReferredNode != null) {
+
+ /**
+ * Check for the referred node defined in a ancestor scope
+ */
+ YangNode potentialReferredNode = potentialAncestorWithReferredNode.getChild();
+ if (isReferredNodeInSiblingListProcessed(potentialReferredNode)) {
+ return;
+ }
+
+ potentialAncestorWithReferredNode = potentialAncestorWithReferredNode.getParent();
+ }
+
+ /*
+ * In case prefix is not present it's a candidate for inter-file
+ * resolution via include list.
+ */
+ if (getRefPrefix() == null) {
+ ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
+ }
+ }
+
+ /**
+ * Checks if the reference in self file or in external file.
+ *
+ * @return true if self file reference, false otherwise
+ * @throws DataModelException a violation of data model rules
+ */
+ private boolean isCandidateForSelfFileReference() throws DataModelException {
+ String prefix = getRefPrefix();
+ return prefix == null || prefix.contentEquals(getCurReferenceResolver().getPrefix());
+ }
+
+ /**
+ * Checks for the referred node defined in a ancestor scope.
+ *
+ * @param potentialReferredNode potential referred node
+ * @return status of resolution and updating the partial resolved stack with
+ * the any recursive references
+ * @throws DataModelException data model errors
+ */
+ private boolean isReferredNodeInSiblingListProcessed(YangNode potentialReferredNode)
+ throws DataModelException {
+ while (potentialReferredNode != null) {
+
+ // Check if the potential referred node is the actual referred node
+ if (isReferredNode(potentialReferredNode)) {
+
+ // Adds reference link of entity to the node under resolution.
+ addReferredEntityLink(potentialReferredNode, LINKED);
+
+ /**
+ * resolve the reference and update the partial resolution stack
+ * with any further recursive references
+ */
+ addUnresolvedRecursiveReferenceToStack(potentialReferredNode);
+
+ /*
+ * return true, since the reference is linked and any recursive
+ * unresolved references is added to the stack
+ */
+ return true;
+ }
+
+ potentialReferredNode = potentialReferredNode.getNextSibling();
+ }
+ return false;
+ }
+
+ /**
+ * Checks if the potential referred node is the actual referred node.
+ *
+ * @param potentialReferredNode typedef/grouping node
+ * @return true if node is of resolve type otherwise false
+ * @throws DataModelException a violation of data model rules
+ */
+ private boolean isReferredNode(YangNode potentialReferredNode)
+ throws DataModelException {
+ if (getCurrentEntityToResolveFromStack() instanceof YangType) {
+ if (potentialReferredNode instanceof YangTypeDef) {
+ /*
+ * Check if name of node name matches with the entity being
+ * resolved
+ */
+ return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
+ }
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
+ if (potentialReferredNode instanceof YangGrouping) {
+ /*
+ * Check if name of node name matches with the entity being
+ * resolved
+ */
+ return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
+ }
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ }
+ return false;
+ }
+
+ /**
+ * Checks if node name is same as name in resolution info, i.e. name of
+ * typedef/grouping is same as name of type/uses.
+ *
+ * @param node typedef/grouping node
+ * @return true if node name is same as name in resolution info, otherwise
+ * false
+ * @throws DataModelException a violation of data model rules
+ */
+
+ private boolean isNodeNameSameAsResolutionInfoName(YangNode node)
+ throws DataModelException {
+ if (getCurrentEntityToResolveFromStack() instanceof YangType) {
+ if (node.getName().contentEquals(
+ ((YangType<?>) getCurrentEntityToResolveFromStack())
+ .getDataTypeName())) {
+ return true;
+ }
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
+ if (node.getName().contentEquals(
+ ((YangUses) getCurrentEntityToResolveFromStack()).getName())) {
+ return true;
+ }
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ }
+ return false;
+ }
+
+ /**
+ * Adds reference of grouping/typedef in uses/type.
+ *
+ * @param referredNode grouping/typedef node being referred
+ * @param linkedStatus linked status if success.
+ * @throws DataModelException a violation of data model rules
+ */
+ private void addReferredEntityLink(YangNode referredNode, ResolvableStatus linkedStatus)
+ throws DataModelException {
+ if (getCurrentEntityToResolveFromStack() instanceof YangType) {
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>)
+ ((YangType<?>) getCurrentEntityToResolveFromStack()).getDataTypeExtendedInfo();
+ derivedInfo.setReferredTypeDef((YangTypeDef) referredNode);
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
+ ((YangUses) getCurrentEntityToResolveFromStack())
+ .setRefGroup((YangGrouping) referredNode);
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ }
+
+ // Sets the resolution status in inside the type/uses.
+ ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(linkedStatus);
+ }
+
+ /**
+ * Checks if type/grouping has further reference to typedef/ unresolved
+ * uses. Add it to the partial resolve stack and return the status of
+ * addition to stack.
+ *
+ * @param referredNode grouping/typedef node
+ * @throws DataModelException a violation of data model rules
+ */
+ private void addUnresolvedRecursiveReferenceToStack(YangNode referredNode)
+ throws DataModelException {
+ if (getCurrentEntityToResolveFromStack() instanceof YangType) {
+ /*
+ * Checks if typedef type is derived
+ */
+ if (((YangTypeDef) referredNode).getTypeDefBaseType().getDataType()
+ == YangDataTypes.DERIVED) {
+
+ YangEntityToResolveInfo<YangType<?>> unResolvedEntityInfo = new YangEntityToResolveInfo<>();
+ unResolvedEntityInfo.setEntityToResolve(((YangTypeDef) referredNode)
+ .getTypeDefBaseType());
+ unResolvedEntityInfo.setHolderOfEntityToResolve(referredNode);
+ addInPartialResolvedStack((YangEntityToResolveInfo<T>) unResolvedEntityInfo);
+ }
+
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
+ /*
+ * Search if the grouping has any un resolved uses child, if so
+ * return true, else return false.
+ */
+ addUnResolvedUsesToStack(referredNode);
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ }
+ }
+
+ /**
+ * Returns if there is any unresolved uses in grouping.
+ *
+ * @param node grouping/typedef node
+ */
+ private void addUnResolvedUsesToStack(YangNode node) {
+
+ /**
+ * Search the grouping node's children for presence of uses node.
+ */
+ YangNode curNode = node.getChild();
+ while (curNode != null) {
+ if (curNode instanceof YangUses) {
+ YangEntityToResolveInfo<YangUses> unResolvedEntityInfo = new YangEntityToResolveInfo<>();
+ unResolvedEntityInfo.setEntityToResolve((YangUses) curNode);
+ unResolvedEntityInfo.setHolderOfEntityToResolve(node);
+ addInPartialResolvedStack((YangEntityToResolveInfo<T>) unResolvedEntityInfo);
+
+ }
+ curNode = curNode.getNextSibling();
+ }
+ }
+
+ /**
+ * Returns stack of YANG type with partially resolved YANG construct
+ * hierarchy.
+ *
+ * @return partial resolved YANG construct stack
+ */
+ private Stack<YangEntityToResolveInfo<T>> getPartialResolvedStack() {
+ return partialResolvedStack;
+ }
+
+ /**
+ * Sets stack of YANG type with partially resolved YANG construct hierarchy.
+ *
+ * @param partialResolvedStack partial resolved YANG construct stack
+ */
+ private void setPartialResolvedStack(Stack<YangEntityToResolveInfo<T>> partialResolvedStack) {
+ this.partialResolvedStack = partialResolvedStack;
+ }
+
+ /**
+ * Sets stack of YANG type with partially resolved YANG construct hierarchy.
+ *
+ * @param partialResolvedInfo partial resolved YANG construct stack
+ */
+ private void addInPartialResolvedStack(YangEntityToResolveInfo<T> partialResolvedInfo) {
+ getPartialResolvedStack().push(partialResolvedInfo);
+ }
+
+ /**
+ * Retrieves the next entity in the stack that needs to be resolved. It is
+ * assumed that the caller ensures that the stack is not empty.
+ *
+ * @return next entity in the stack that needs to be resolved
+ */
+ private T getCurrentEntityToResolveFromStack() {
+ return getPartialResolvedStack().peek().getEntityToResolve();
+ }
+
+ /**
+ * Retrieves information about the entity that needs to be resolved.
+ *
+ * @return information about the entity that needs to be resolved
+ */
+ public YangEntityToResolveInfo<T> getEntityToResolveInfo() {
+ return entityToResolveInfo;
+ }
+
+ /**
+ * Sets information about the entity that needs to be resolved.
+ *
+ * @param entityToResolveInfo information about the entity that needs to be
+ * resolved
+ */
+ private void setEntityToResolveInfo(YangEntityToResolveInfo<T> entityToResolveInfo) {
+ this.entityToResolveInfo = entityToResolveInfo;
+ }
+
+ @Override
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ @Override
+ public int getCharPosition() {
+ return charPosition;
+ }
+
+ @Override
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ @Override
+ public void setCharPosition(int charPositionInLine) {
+ this.charPosition = charPositionInLine;
+ }
+
+ /**
+ * Returns current module/sub-module reference, will be used in inter-file/
+ * inter-jar scenario to get the import/include list.
+ *
+ * @return current module/sub-module reference
+ */
+ private YangReferenceResolver getCurReferenceResolver() {
+ return curReferenceResolver;
+ }
+
+ /**
+ * Sets current module/sub-module reference, will be used in inter-file/
+ * inter-jar scenario to get the import/include list.
+ *
+ * @param curReferenceResolver current module/sub-module reference
+ */
+ private void setCurReferenceResolver(YangReferenceResolver curReferenceResolver) {
+ this.curReferenceResolver = curReferenceResolver;
+ }
+
+ /**
+ * Performs inter file linking of uses/type referring to typedef/grouping
+ * of other YANG file.
+ *
+ * @param dataModelRootNode module/sub-module node
+ * @throws DataModelException a violation in data model rule
+ */
+ public void linkInterFile(YangReferenceResolver dataModelRootNode)
+ throws DataModelException {
+
+ setCurReferenceResolver(dataModelRootNode);
+
+ // Current node to resolve, it can be a YANG type or YANG uses.
+ T entityToResolve = getEntityToResolveInfo().getEntityToResolve();
+
+ // Check if linking is already done
+ if (entityToResolve instanceof Resolvable) {
+ Resolvable resolvable = (Resolvable) entityToResolve;
+ if (resolvable.getResolvableStatus() == RESOLVED) {
+ return;
+ }
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is not Resolvable");
+ }
+
+ // Push the initial entity to resolve in stack.
+ addInPartialResolvedStack(getEntityToResolveInfo());
+
+ // Inter file linking and resolution.
+ linkInterFileAndResolve();
+ }
+
+ /**
+ * Returns the referenced prefix of entity under resolution.
+ *
+ * @return referenced prefix of entity under resolution
+ * @throws DataModelException a violation in data model rule
+ */
+ private String getRefPrefix() throws DataModelException {
+ String refPrefix;
+ if (getCurrentEntityToResolveFromStack() instanceof YangType) {
+ refPrefix = ((YangType<?>) getCurrentEntityToResolveFromStack()).getPrefix();
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
+ refPrefix = ((YangUses) getCurrentEntityToResolveFromStack()).getPrefix();
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ }
+ return refPrefix;
+ }
+
+ /**
+ * Performs inter file linking and resolution.
+ *
+ * @throws DataModelException a violation in data model rule
+ */
+ private void linkInterFileAndResolve()
+ throws DataModelException {
+
+ while (getPartialResolvedStack().size() != 0) {
+
+ // Current node to resolve, it can be a YANG type or YANG uses.
+ T entityToResolve = getCurrentEntityToResolveFromStack();
+ // Check if linking is already done
+ if (entityToResolve instanceof Resolvable) {
+
+ Resolvable resolvable = (Resolvable) entityToResolve;
+ switch (resolvable.getResolvableStatus()) {
+ case RESOLVED: {
+ /*
+ * If the entity is already resolved in the stack, then
+ * pop it and continue with the remaining stack elements
+ * to resolve
+ */
+ getPartialResolvedStack().pop();
+ break;
+ }
+
+ case INTER_FILE_LINKED: {
+ /*
+ * If the top of the stack is already linked then
+ * resolve the references and pop the entity and
+ * continue with remaining stack elements to resolve
+ */
+ resolveTopOfStack();
+ getPartialResolvedStack().pop();
+ break;
+ }
+
+ case INTRA_FILE_RESOLVED: {
+ /*
+ * If the top of the stack is intra file resolved
+ * then check if top of stack is linked, if not
+ * link it using import/include list and push the
+ * linked referred entity to the stack, otherwise
+ * only push it to the stack.
+ */
+ linkInterFileTopOfStackRefUpdateStack();
+ break;
+ }
+
+ default: {
+ throw new DataModelException("Data Model Exception: Unsupported, linker state");
+ }
+
+ }
+
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ }
+
+ }
+
+ }
+
+ /**
+ * Links the top of the stack if it's inter-file and update stack.
+ *
+ * @throws DataModelException data model error
+ */
+ private void linkInterFileTopOfStackRefUpdateStack() throws DataModelException {
+
+ /*
+ * Obtain the referred node of top of stack entity under resolution
+ */
+ T referredNode = getRefNode();
+
+ /*
+ * Check for null for scenario when it's not linked and inter-file
+ * linking is required.
+ */
+ if (referredNode == null) {
+
+ /*
+ * Check if prefix is null or not, to identify whether to search
+ * in import list or include list.
+ */
+ if (getRefPrefix() != null && !(getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix()))) {
+ if (resolveWithImport()) {
+ return;
+ }
+ } else {
+ if (resolveWithInclude()) {
+ return;
+ }
+ }
+ // Exception when referred typedef/grouping is not found.
+ DataModelException dataModelException = new DataModelException("YANG file error: Referred " +
+ "typedef/grouping for a given type/uses can't be found.");
+ dataModelException.setLine(getLineNumber());
+ dataModelException.setCharPosition(getCharPosition());
+ throw dataModelException;
+ } else {
+ /*
+ * If referred node is already linked, then just change the status
+ * and push to the stack.
+ */
+ ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTER_FILE_LINKED);
+ addUnresolvedRecursiveReferenceToStack((YangNode) referredNode);
+ }
+ }
+
+ /**
+ * Finds and resolves with include list.
+ *
+ * @return true if resolved, false otherwise
+ * @throws DataModelException a violation in data model rule
+ */
+ private boolean resolveWithInclude() throws DataModelException {
+ /*
+ * Run through all the nodes in include list and search for referred
+ * typedef/grouping at the root level.
+ */
+ for (YangInclude yangInclude : getCurReferenceResolver().getIncludeList()) {
+ YangNode linkedNode = null;
+ if (getCurrentEntityToResolveFromStack() instanceof YangType) {
+ linkedNode = findRefTypedef(yangInclude.getIncludedNode());
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
+ linkedNode = findRefGrouping(yangInclude.getIncludedNode());
+ }
+ if (linkedNode != null) {
+ // Add the link to external entity.
+ addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
+ /*
+ * Update the current reference resolver to external
+ * module/sub-module containing the referred typedef/grouping.
+ */
+ setCurReferenceResolver((YangReferenceResolver) yangInclude.getIncludedNode());
+ // Add the type/uses of referred typedef/grouping to the stack.
+ addUnresolvedRecursiveReferenceToStack(linkedNode);
+ return true;
+ }
+ }
+ // If referred node can't be found return false.
+ return false;
+ }
+
+ /**
+ * Finds and resolves with import list.
+ *
+ * @return true if resolved, false otherwise
+ * @throws DataModelException a violation in data model rule
+ */
+ private boolean resolveWithImport() throws DataModelException {
+ /*
+ * Run through import list to find the referred typedef/grouping.
+ */
+ for (YangImport yangImport : getCurReferenceResolver().getImportList()) {
+ /*
+ * Match the prefix attached to entity under resolution with the
+ * imported/included module/sub-module's prefix. If found, search
+ * for the referred typedef/grouping at the root level.
+ */
+ if (yangImport.getPrefixId().contentEquals(getRefPrefix())) {
+ YangNode linkedNode = null;
+ if (getCurrentEntityToResolveFromStack() instanceof YangType) {
+ linkedNode = findRefTypedef(yangImport.getImportedNode());
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
+ linkedNode = findRefGrouping(yangImport.getImportedNode());
+ }
+ if (linkedNode != null) {
+ // Add the link to external entity.
+ addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
+ /*
+ * Update the current reference resolver to external
+ * module/sub-module containing the referred typedef/grouping.
+ */
+ setCurReferenceResolver((YangReferenceResolver) yangImport.getImportedNode());
+ // Add the type/uses of referred typedef/grouping to the stack.
+ addUnresolvedRecursiveReferenceToStack(linkedNode);
+ return true;
+ }
+ /*
+ * If referred node can't be found at root level break for loop,
+ * and return false.
+ */
+ break;
+ }
+ }
+ // If referred node can't be found return false.
+ return false;
+ }
+
+ /**
+ * Returns referred typedef/grouping node.
+ *
+ * @return referred typedef/grouping node
+ * @throws DataModelException a violation in data model rule
+ */
+ private T getRefNode() throws DataModelException {
+ if (getCurrentEntityToResolveFromStack() instanceof YangType) {
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>)
+ ((YangType<?>) getCurrentEntityToResolveFromStack()).getDataTypeExtendedInfo();
+ return (T) derivedInfo.getReferredTypeDef();
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
+ return (T) ((YangUses) getCurrentEntityToResolveFromStack()).getRefGroup();
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ }
+ }
+
+ /**
+ * Finds the referred grouping node at the root level of imported/included node.
+ *
+ * @param refNode module/sub-module node
+ * @return referred grouping
+ */
+ private YangNode findRefGrouping(YangNode refNode) {
+ YangNode tmpNode = refNode.getChild();
+ while (tmpNode != null) {
+ if (tmpNode instanceof YangGrouping) {
+ if (tmpNode.getName()
+ .equals(((YangUses) getCurrentEntityToResolveFromStack()).getName())) {
+ return tmpNode;
+ }
+ }
+ tmpNode = tmpNode.getNextSibling();
+ }
+ return null;
+ }
+
+ /**
+ * Finds the referred typedef node at the root level of imported/included node.
+ *
+ * @param refNode module/sub-module node
+ * @return referred typedef
+ */
+ private YangNode findRefTypedef(YangNode refNode) {
+ YangNode tmpNode = refNode.getChild();
+ while (tmpNode != null) {
+ if (tmpNode instanceof YangTypeDef) {
+ if (tmpNode.getName()
+ .equals(((YangType) getCurrentEntityToResolveFromStack()).getDataTypeName())) {
+ return tmpNode;
+ }
+ }
+ tmpNode = tmpNode.getNextSibling();
+ }
+ return null;
+ }
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/package-info.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/package-info.java
index be8bb13..1d38e5a 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/package-info.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/linker/impl/package-info.java
@@ -15,6 +15,6 @@
*/
/**
- * Provide inter file and inter jar linking implementation.
+ * Provide intra/inter file and inter jar linking implementation.
*/
-package org.onosproject.yangutils.linker.impl;
\ No newline at end of file
+package org.onosproject.yangutils.linker.impl;
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java
index ff25f00..08de56b 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java
@@ -74,20 +74,26 @@
* (belongsto), perform validations and update the data model tree.
*
* @param listener Listener's object
- * @param ctx context object of the grammar rule
+ * @param ctx context object of the grammar rule
*/
public static void processBelongsToEntry(TreeWalkListener listener,
GeneratedYangParser.BelongstoStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.identifier().getText(),
- ENTRY);
+ ENTRY);
String identifier = getValidIdentifier(ctx.identifier().getText(), BELONGS_TO_DATA, ctx);
YangBelongsTo belongstoNode = new YangBelongsTo();
belongstoNode.setBelongsToModuleName(identifier);
+ // Set the line number and character position in line for the belongs to.
+ int errorLine = ctx.getStart().getLine();
+ int errorPosition = ctx.getStart().getCharPositionInLine();
+ belongstoNode.setLineNumber(errorLine);
+ belongstoNode.setCharPosition(errorPosition);
+
// Push belongsto into the stack.
listener.getParsedDataStack().push(belongstoNode);
}
@@ -97,14 +103,14 @@
* validations and update the data model tree.
*
* @param listener Listener's object
- * @param ctx context object of the grammar rule
+ * @param ctx context object of the grammar rule
*/
public static void processBelongsToExit(TreeWalkListener listener,
GeneratedYangParser.BelongstoStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.identifier().getText(),
- EXIT);
+ EXIT);
Parsable tmpBelongstoNode = listener.getParsedDataStack().peek();
if (tmpBelongstoNode instanceof YangBelongsTo) {
@@ -112,7 +118,7 @@
// Check for stack to be empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA,
- ctx.identifier().getText(), EXIT);
+ ctx.identifier().getText(), EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getYangConstructType()) {
@@ -129,7 +135,7 @@
}
} else {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BELONGS_TO_DATA,
- ctx.identifier().getText(), EXIT));
+ ctx.identifier().getText(), EXIT));
}
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java
index 03938b1..061c4dd 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java
@@ -73,7 +73,7 @@
* (import), perform validations and update the data model tree.
*
* @param listener Listener's object
- * @param ctx context object of the grammar rule
+ * @param ctx context object of the grammar rule
*/
public static void processImportEntry(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
@@ -85,6 +85,12 @@
YangImport importNode = new YangImport();
importNode.setModuleName(identifier);
+ // Set the line number and character position in line for the belongs to.
+ int errorLine = ctx.getStart().getLine();
+ int errorPosition = ctx.getStart().getCharPositionInLine();
+ importNode.setLineNumber(errorLine);
+ importNode.setCharPosition(errorPosition);
+
// Push import node to the stack.
listener.getParsedDataStack().push(importNode);
}
@@ -94,7 +100,7 @@
* validations and update the data model tree.
*
* @param listener Listener's object
- * @param ctx context object of the grammar rule
+ * @param ctx context object of the grammar rule
*/
public static void processImportExit(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
@@ -107,7 +113,7 @@
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.identifier().getText(),
- EXIT);
+ EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getYangConstructType()) {
@@ -128,7 +134,7 @@
}
} else {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, IMPORT_DATA,
- ctx.identifier().getText(), EXIT));
+ ctx.identifier().getText(), EXIT));
}
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java
index 721b9fe..8cac71d 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java
@@ -72,19 +72,25 @@
* (include), perform validations and update the data model tree.
*
* @param listener Listener's object
- * @param ctx context object of the grammar rule
+ * @param ctx context object of the grammar rule
*/
public static void processIncludeEntry(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(),
- ENTRY);
+ ENTRY);
String identifier = getValidIdentifier(ctx.identifier().getText(), INCLUDE_DATA, ctx);
YangInclude includeNode = new YangInclude();
includeNode.setSubModuleName(identifier);
+ // Set the line number and character position in line for the belongs to.
+ int errorLine = ctx.getStart().getLine();
+ int errorPosition = ctx.getStart().getCharPositionInLine();
+ includeNode.setLineNumber(errorLine);
+ includeNode.setCharPosition(errorPosition);
+
listener.getParsedDataStack().push(includeNode);
}
@@ -93,7 +99,7 @@
* validations and update the data model tree.
*
* @param listener Listener's object
- * @param ctx context object of the grammar rule
+ * @param ctx context object of the grammar rule
*/
public static void processIncludeExit(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
@@ -106,7 +112,7 @@
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(),
- EXIT);
+ EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getYangConstructType()) {
@@ -127,7 +133,7 @@
}
} else {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INCLUDE_DATA,
- ctx.identifier().getText(), EXIT));
+ ctx.identifier().getText(), EXIT));
}
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
index 2f1d7fe..c78aa1e 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
@@ -16,7 +16,6 @@
package org.onosproject.yangutils.parser.impl.listeners;
-import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangRangeRestriction;
import org.onosproject.yangutils.datamodel.YangStringRestriction;
@@ -27,7 +26,9 @@
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.utils.YangConstructType;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
@@ -99,8 +100,8 @@
* Sets the length restriction to type.
*
* @param listener listener's object
- * @param type Yang type for which length restriction to be set
- * @param ctx context object of the grammar rule
+ * @param type Yang type for which length restriction to be set
+ * @param ctx context object of the grammar rule
*/
private static void setLengthRestriction(TreeWalkListener listener, YangType type,
GeneratedYangParser.LengthStatementContext ctx) {
@@ -115,10 +116,10 @@
return;
}
- if (type.getDataType() != YangDataTypes.STRING) {
+ if (type.getDataType() != STRING && type.getDataType() != BINARY) {
ParserException parserException = new ParserException("YANG file error : " +
YangConstructType.getYangConstructType(LENGTH_DATA) + " name " + ctx.length().getText() +
- " can be used to restrict the built-in type string or types derived from string.");
+ " can be used to restrict the built-in type string/binary or types derived from string/binary.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -127,14 +128,18 @@
YangRangeRestriction lengthRestriction = processLengthRestriction(null, ctx.getStart().getLine(),
ctx.getStart().getCharPositionInLine(), false, ctx.length().getText());
- YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
+ if (type.getDataType() == STRING) {
+ YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
+ if (stringRestriction == null) {
+ stringRestriction = new YangStringRestriction();
+ type.setDataTypeExtendedInfo(stringRestriction);
+ }
- if (stringRestriction == null) {
- stringRestriction = new YangStringRestriction();
- type.setDataTypeExtendedInfo(stringRestriction);
+ stringRestriction.setLengthRestriction(lengthRestriction);
+ } else {
+ type.setDataTypeExtendedInfo(lengthRestriction);
}
- stringRestriction.setLengthRestriction(lengthRestriction);
listener.getParsedDataStack().push(lengthRestriction);
}
@@ -143,7 +148,7 @@
* It is called when parser exits from grammar rule (length).
*
* @param listener listener's object
- * @param ctx context object of the grammar rule
+ * @param ctx context object of the grammar rule
*/
public static void processLengthRestrictionExit(TreeWalkListener listener,
GeneratedYangParser.LengthStatementContext ctx) {
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
index fd1bd84..a0005ba 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
@@ -16,7 +16,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
-import org.onosproject.yangutils.datamodel.YangReferenceResolver;
+import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
index cfaa15f..2c97f30 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
@@ -16,7 +16,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
-import org.onosproject.yangutils.datamodel.YangReferenceResolver;
+import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
index e5b098b..6e25f1b 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
@@ -22,26 +22,24 @@
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-import static org.onosproject.yangutils.datamodel.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangType;
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
- .constructExtendedListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
- .constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
@@ -81,10 +79,10 @@
* (type), performs validation and updates the data model tree.
*
* @param listener listener's object
- * @param ctx context object of the grammar rule
+ * @param ctx context object of the grammar rule
*/
public static void processTypeEntry(TreeWalkListener listener,
- GeneratedYangParser.TypeStatementContext ctx) {
+ GeneratedYangParser.TypeStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), ENTRY);
@@ -190,6 +188,8 @@
YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
+ type.setResolvableStatus(UNRESOLVED);
+
// Add resolution information to the list
YangResolutionInfo resolutionInfo =
new YangResolutionInfo<YangType>(type, unionNode, errorLine, errorPosition);
@@ -211,13 +211,15 @@
YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
+ type.setResolvableStatus(UNRESOLVED);
+
// Add resolution information to the list
YangResolutionInfo resolutionInfo =
new YangResolutionInfo<YangType>(type, typeDef, errorLine, errorPosition);
addToResolutionList(resolutionInfo, ctx);
}
break;
- //TODO: deviate replacement statement.case TYPEDEF_DATA: //TODO
+ //TODO: deviate replacement statement.
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
@@ -233,10 +235,10 @@
* validations and update the data model tree.
*
* @param listener Listener's object
- * @param ctx context object of the grammar rule
+ * @param ctx context object of the grammar rule
*/
public static void processTypeExit(TreeWalkListener listener,
- GeneratedYangParser.TypeStatementContext ctx) {
+ GeneratedYangParser.TypeStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, TYPE_DATA, ctx.string().getText(), EXIT);
@@ -252,15 +254,15 @@
* Adds to resolution list.
*
* @param resolutionInfo resolution information
- * @param ctx context object of the grammar rule
+ * @param ctx context object of the grammar rule
*/
private static void addToResolutionList(YangResolutionInfo<YangType> resolutionInfo,
- GeneratedYangParser.TypeStatementContext ctx) {
+ GeneratedYangParser.TypeStatementContext ctx) {
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- TYPE_DATA, ctx.string().getText(), EXIT, e.getMessage()));
+ TYPE_DATA, ctx.string().getText(), ENTRY, e.getMessage()));
}
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java
index 1658eee..fd6523f 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java
@@ -26,7 +26,7 @@
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangResolutionInfo;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangFileInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangFileInfo.java
index 7cb870c..a92ca68 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangFileInfo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangFileInfo.java
@@ -16,6 +16,8 @@
package org.onosproject.yangutils.plugin.manager;
+import java.util.Objects;
+import org.onosproject.yangutils.linker.impl.ResolvableStatus;
import org.onosproject.yangutils.datamodel.YangNode;
/**
@@ -29,11 +31,21 @@
private String yangFileName;
/**
+ * YANG file revision.
+ */
+ private String revision;
+
+ /**
* Data model node after parsing YANG file.
*/
private YangNode rootNode;
/**
+ * Resolution status of YANG file.
+ */
+ private ResolvableStatus resolvableStatus;
+
+ /**
* Returns data model node for YANG file.
*
* @return data model node for YANG file
@@ -68,4 +80,58 @@
public void setYangFileName(String yangFileName) {
this.yangFileName = yangFileName;
}
+
+ /**
+ * Returns the revision of YANG file.
+ *
+ * @return revision of YANG file
+ */
+ public String getRevision() {
+ return revision;
+ }
+
+ /**
+ * Sets the revision of YANG file.
+ *
+ * @param revision revision of YANG file
+ */
+ public void setRevision(String revision) {
+ this.revision = revision;
+ }
+
+ /**
+ * Returns the resolution status of YANG file.
+ *
+ * @return resolution status of YANG file
+ */
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ /**
+ * Sets the resolution status of YANG file.
+ *
+ * @param resolvableStatus resolution status of YANG file
+ */
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangFileInfo) {
+ final YangFileInfo other = (YangFileInfo) obj;
+ return Objects.equals(this.yangFileName, other.yangFileName);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(this.yangFileName);
+ }
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index f602b29..bcbe5af 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -17,9 +17,10 @@
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-
+import java.util.Set;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -28,8 +29,9 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.YangLinker;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.parser.YangUtilsParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
@@ -48,10 +50,9 @@
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory;
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findBelongsToModuleNode;
/**
* Represents ONOS YANG utility maven plugin.
@@ -63,6 +64,14 @@
requiresProject = true)
public class YangUtilManager extends AbstractMojo {
+ private YangNode rootNode;
+ // YANG file information set.
+ private Set<YangFileInfo> yangFileInfoSet = new HashSet<>();
+ private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
+ private YangLinker yangLinker = new YangLinkerManager();
+
+ private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
+
/**
* Source directory for YANG files.
*/
@@ -117,12 +126,6 @@
@Component
private BuildContext context;
- private static final String DEFAULT_PKG = SLASH
- + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
-
- private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
- private YangNode rootNode;
-
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
@@ -136,47 +139,40 @@
String searchDir = getDirectory(baseDir, yangFilesDir);
String codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH;
+
+ // Creates conflict resolver and set values to it.
YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
conflictResolver.setReplacementForPeriod(replacementForPeriod);
conflictResolver.setReplacementForHyphen(replacementForHyphen);
conflictResolver.setReplacementForUnderscore(replacementForUnderscore);
- List<YangFileInfo> yangFileInfo = YangFileScanner.getYangFiles(searchDir);
- if (yangFileInfo == null || yangFileInfo.isEmpty()) {
- // no files to translate
- return;
- }
YangPluginConfig yangPlugin = new YangPluginConfig();
yangPlugin.setCodeGenDir(codeGenDir);
yangPlugin.setConflictResolver(conflictResolver);
- Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
- while (yangFileIterator.hasNext()) {
- YangFileInfo yangFile = yangFileIterator.next();
- try {
- YangNode yangNode = yangUtilsParser.getDataModel(yangFile.getYangFileName());
- yangFile.setRootNode(yangNode);
- setRootNode(yangNode);
- } catch (ParserException e) {
- String logInfo = "Error in file: " + e.getFileName();
- if (e.getLineNumber() != 0) {
- logInfo = logInfo + " at line: " + e.getLineNumber() + " at position: "
- + e.getCharPositionInLine();
+ /*
+ * Obtain the YANG files at a path mentioned in plugin and creates
+ * YANG file information set.
+ */
+ createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
- }
- if (e.getMessage() != null) {
- logInfo = logInfo + NEW_LINE + e.getMessage();
- }
- getLog().info(logInfo);
- throw e;
- }
+ // Check if there are any file to translate, if not return.
+ if (getYangFileInfoSet() == null || getYangFileInfoSet().isEmpty()) {
+ // No files to translate
+ return;
}
- resolveLinkingForSubModule(yangFileInfo);
+ //Carry out the parsing for all the YANG files.
+ parseYangFileInfoSet();
- translateToJava(yangFileInfo, yangPlugin);
+ // Resolve dependencies using linker.
+ resolveDependenciesUsingLinker();
+
+ // Perform translation to JAVA.
+ translateToJava(getYangFileInfoSet(), yangPlugin);
addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context);
- copyYangFilesToTarget(yangFileInfo, getDirectory(baseDir, outputDirectory), project);
+
+ copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project);
} catch (Exception e) {
String fileName = "";
if (e instanceof TranslatorException) {
@@ -196,22 +192,45 @@
}
/**
- * Set current project.
+ * Links all the provided with the YANG file info set.
*
- * @param curProject maven project
+ * @throws MojoExecutionException a violation in mojo excecution
*/
- public void setCurrentProject(MavenProject curProject) {
- project = curProject;
-
+ public void resolveDependenciesUsingLinker() throws MojoExecutionException {
+ for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
+ try {
+ yangLinker.resolveDependencies(getYangFileInfoSet());
+ } catch (LinkerException e) {
+ throw new MojoExecutionException(e.getMessage());
+ }
+ }
}
/**
- * Returns current project.
+ * Parses all the provided YANG files and generates YANG data model tree.
*
- * @return current project
+ * @throws IOException a violation in IO
*/
- public MavenProject getCurrentProject() {
- return project;
+ public void parseYangFileInfoSet() throws IOException {
+ for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
+ try {
+ YangNode yangNode = yangUtilsParser.getDataModel(yangFileInfo.getYangFileName());
+ yangFileInfo.setRootNode(yangNode);
+ setRootNode(yangNode);
+ } catch (ParserException e) {
+ String logInfo = "Error in file: " + e.getFileName();
+ if (e.getLineNumber() != 0) {
+ logInfo = logInfo + " at line: " + e.getLineNumber() + " at position: "
+ + e.getCharPositionInLine();
+
+ }
+ if (e.getMessage() != null) {
+ logInfo = logInfo + NEW_LINE + e.getMessage();
+ }
+ getLog().info(logInfo);
+ throw e;
+ }
+ }
}
/**
@@ -219,7 +238,7 @@
*
* @return current root YANG node of data-model tree
*/
- public YangNode getRootNode() {
+ private YangNode getRootNode() {
return rootNode;
}
@@ -228,44 +247,55 @@
*
* @param rootNode current root YANG node of data-model tree
*/
- public void setRootNode(YangNode rootNode) {
+ private void setRootNode(YangNode rootNode) {
this.rootNode = rootNode;
}
/**
* Translates to java code corresponding to the YANG schema.
*
- * @param yangFileInfo YANG file information
- * @param yangPlugin YANG plugin config
+ * @param yangFileInfoSet YANG file information
+ * @param yangPlugin YANG plugin config
* @throws IOException when fails to generate java code file the current
- * node
+ * node
*/
- public static void translateToJava(List<YangFileInfo> yangFileInfo, YangPluginConfig yangPlugin)
+ public void translateToJava(Set<YangFileInfo> yangFileInfoSet, YangPluginConfig yangPlugin)
throws IOException {
- Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
+ Iterator<YangFileInfo> yangFileIterator = yangFileInfoSet.iterator();
while (yangFileIterator.hasNext()) {
- YangFileInfo yangFile = yangFileIterator.next();
- generateJavaCode(yangFile.getRootNode(), yangPlugin, yangFile.getYangFileName());
+ YangFileInfo yangFileInfo = yangFileIterator.next();
+ generateJavaCode(yangFileInfo.getRootNode(), yangPlugin, yangFileInfo.getYangFileName());
}
}
/**
- * Resolves sub-module linking.
+ * Creates a YANG file info set.
*
- * @param yangFileInfo YANG file information
- * @throws DataModelException when belongs-to module node is not found
+ * @param yangFileList YANG files list
*/
- public static void resolveLinkingForSubModule(List<YangFileInfo> yangFileInfo) throws DataModelException {
- Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
- while (yangFileIterator.hasNext()) {
- YangFileInfo yangFile = yangFileIterator.next();
- YangNode yangNode = yangFile.getRootNode();
- if (yangNode instanceof YangSubModule) {
- String belongsToModuleName = ((YangSubModule) yangNode).getBelongsTo()
- .getBelongsToModuleName();
- YangNode moduleNode = findBelongsToModuleNode(yangFileInfo, belongsToModuleName);
- ((YangSubModule) yangNode).getBelongsTo().setModuleNode(moduleNode);
- }
+ public void createYangFileInfoSet(List<String> yangFileList) {
+ for (String yangFile : yangFileList) {
+ YangFileInfo yangFileInfo = new YangFileInfo();
+ yangFileInfo.setYangFileName(yangFile);
+ getYangFileInfoSet().add(yangFileInfo);
}
}
+
+ /**
+ * Returns the YANG file info set.
+ *
+ * @return the YANG file info set
+ */
+ public Set<YangFileInfo> getYangFileInfoSet() {
+ return yangFileInfoSet;
+ }
+
+ /**
+ * Sets the YANG file info set.
+ *
+ * @param yangFileInfoSet the YANG file info set
+ */
+ public void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) {
+ this.yangFileInfoSet = yangFileInfoSet;
+ }
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
index a0834f0..59d4912 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
@@ -16,7 +16,6 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
-
import org.onosproject.yangutils.datamodel.YangBelongsTo;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangSubModule;
@@ -105,10 +104,10 @@
* Returns the name space of the module to which the sub module belongs to.
*
* @param belongsToInfo Information of the module to which the sub module
- * belongs
+ * belongs
* @return the name space string of the module.
*/
- private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
+ public String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
return ((YangModule) belongsToInfo.getModuleNode()).getNameSpace().getUri();
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
index f5c6bdc..cc5cc6c 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
@@ -24,14 +24,17 @@
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
@@ -109,7 +112,7 @@
* Returns from string method parsed string.
*
* @param targetDataType target data type
- * @param yangType YANG type
+ * @param yangType YANG type
* @return parsed string
*/
public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
@@ -155,7 +158,7 @@
/**
* Returns java import class.
*
- * @param yangType YANG type
+ * @param yangType YANG type
* @param isListAttr if the attribute need to be a list
* @return java import class
*/
@@ -260,9 +263,9 @@
/**
* Returns java import package.
*
- * @param yangType YANG type
+ * @param yangType YANG type
* @param isListAttr if the attribute is of list type
- * @param classInfo java import class info
+ * @param classInfo java import class info
* @return java import package
*/
public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) {
@@ -424,6 +427,20 @@
throw new TranslatorException("invalid child node is being processed.");
}
JavaFileInfo parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
+ if (parentInfo.getPackage() == null) {
+ if (parent instanceof YangJavaModule) {
+ YangJavaModule module = (YangJavaModule) parent;
+ String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module
+ .getRevision().getRevDate());
+ return modulePkg + PERIOD + getCamelCase(module.getName(), null).toLowerCase();
+ } else if (parent instanceof YangJavaSubModule) {
+ YangJavaSubModule submodule = (YangJavaSubModule) parent;
+ String subModulePkg = getRootPackage(submodule.getVersion(),
+ submodule.getNameSpaceFromModule(submodule.getBelongsTo()),
+ submodule.getRevision().getRevDate());
+ return subModulePkg + PERIOD + getCamelCase(submodule.getName(), null).toLowerCase();
+ }
+ }
return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase();
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
index 7fa99b7..4a3f847 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
@@ -21,7 +21,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
-import org.onosproject.yangutils.plugin.manager.YangFileInfo;
/**
* Represents utility for searching the files in a directory.
@@ -43,8 +42,8 @@
* @param root specified directory
* @return list of java files
* @throws NullPointerException when no files are there.
- * @throws IOException when files get deleted while performing the
- * operations
+ * @throws IOException when files get deleted while performing the
+ * operations
*/
public static List<String> getJavaFiles(String root) throws IOException {
@@ -52,33 +51,27 @@
}
/**
- * Returns the list of YANG file information.
+ * Returns the list of YANG file.
*
* @param root specified directory
* @return list of YANG file information
* @throws NullPointerException when no files are there
- * @throws IOException when files get deleted while performing the
- * operations
+ * @throws IOException when files get deleted while performing the
+ * operations
*/
- public static List<YangFileInfo> getYangFiles(String root) throws IOException {
+ public static List<String> getYangFiles(String root) throws IOException {
List<String> yangFiles = getFiles(root, YANG_FILE_EXTENTION);
- List<YangFileInfo> fileInfo = new LinkedList<>();
- for (String yangFile : yangFiles) {
- YangFileInfo yangFileInfo = new YangFileInfo();
- yangFileInfo.setYangFileName(yangFile);
- fileInfo.add(yangFileInfo);
- }
- return fileInfo;
+ return yangFiles;
}
/**
* Returns the list of required files.
*
- * @param root specified directory
+ * @param root specified directory
* @param extension file extension
* @return list of required files
* @throws NullPointerException when no file is there
- * @throws IOException when files get deleted while performing the operations
+ * @throws IOException when files get deleted while performing the operations
*/
public static List<String> getFiles(String root, String extension) throws IOException {
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
index d8f7e53..835b675 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
@@ -23,18 +23,20 @@
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
-import java.util.LinkedList;
import java.util.Iterator;
import java.util.List;
+import java.util.LinkedList;
import java.util.Stack;
+import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
+import org.onosproject.yangutils.plugin.manager.YangFileInfo;
+
import org.slf4j.Logger;
import org.sonatype.plexus.build.incremental.BuildContext;
-import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
@@ -81,9 +83,9 @@
/**
* Adds package info file for the created directory.
*
- * @param path directory path
- * @param classInfo class info for the package
- * @param pack package of the directory
+ * @param path directory path
+ * @param classInfo class info for the package
+ * @param pack package of the directory
* @param isChildNode is it a child node
* @throws IOException when fails to create package info file
*/
@@ -167,7 +169,7 @@
/**
* Adds generated source directory to the compilation root.
*
- * @param source directory
+ * @param source directory
* @param project current maven project
* @param context current build context
*/
@@ -180,7 +182,7 @@
/**
* Removes extra char from the string.
*
- * @param valueString string to be trimmed
+ * @param valueString string to be trimmed
* @param removealStirng extra chars
* @return new string
*/
@@ -215,8 +217,8 @@
* Returns the directory path of the package in canonical form.
*
* @param baseCodeGenPath base path where the generated files needs to be
- * put
- * @param pathOfJavaPkg java package of the file being generated
+ * put
+ * @param pathOfJavaPkg java package of the file being generated
* @return absolute path of the package in canonical form
*/
public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) {
@@ -236,8 +238,8 @@
* Returns the absolute path of the package in canonical form.
*
* @param baseCodeGenPath base path where the generated files needs to be
- * put
- * @param pathOfJavaPkg java package of the file being generated
+ * put
+ * @param pathOfJavaPkg java package of the file being generated
* @return absolute path of the package in canonical form
*/
public static String getAbsolutePackagePath(String baseCodeGenPath, String pathOfJavaPkg) {
@@ -247,12 +249,12 @@
/**
* Copies YANG files to the current project's output directory.
*
- * @param yangFileInfo list of YANG files
- * @param outputDir project's output directory
- * @param project maven project
+ * @param yangFileInfo set of YANG files
+ * @param outputDir project's output directory
+ * @param project maven project
* @throws IOException when fails to copy files to destination resource directory
*/
- public static void copyYangFilesToTarget(List<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
+ public static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
throws IOException {
List<File> files = getListOfFile(yangFileInfo);
@@ -274,10 +276,10 @@
/**
* Provides a list of files from list of strings.
*
- * @param yangFileInfo list of yang file information
+ * @param yangFileInfo set of yang file information
* @return list of files
*/
- private static List<File> getListOfFile(List<YangFileInfo> yangFileInfo) {
+ private static List<File> getListOfFile(Set<YangFileInfo> yangFileInfo) {
List<File> files = new ArrayList<>();
Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
while (yangFileIterator.hasNext()) {
@@ -291,7 +293,7 @@
* Merges the temp java files to main java files.
*
* @param appendFile temp file
- * @param srcFile main file
+ * @param srcFile main file
* @throws IOException when fails to append contents
*/
public static void mergeJavaFiles(File appendFile, File srcFile) throws IOException {
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/InterFileLinkingTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/InterFileLinkingTest.java
new file mode 100644
index 0000000..3ca5315
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/InterFileLinkingTest.java
@@ -0,0 +1,602 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.linker;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangDerivedInfo;
+import org.onosproject.yangutils.datamodel.YangGrouping;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.YangUses;
+import org.onosproject.yangutils.linker.impl.ResolvableStatus;
+import org.onosproject.yangutils.linker.impl.YangLinkerManager;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+import org.onosproject.yangutils.plugin.manager.YangFileInfo;
+import org.onosproject.yangutils.plugin.manager.YangUtilManager;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
+import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
+
+/**
+ * Test cases for testing inter file linking.
+ */
+public class InterFileLinkingTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+ private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
+
+ /**
+ * Checks inter file type linking.
+ */
+ @Test
+ public void processInterFileTypeLinking()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfiletype";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+
+ YangNode refNode = null;
+ YangNode selfNode = null;
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
+
+ Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
+
+ YangFileInfo yangFileInfo = yangFileInfoIterator.next();
+
+ if (yangFileInfo.getRootNode().getName().equals("module1")) {
+ selfNode = yangFileInfo.getRootNode();
+ refNode = yangFileInfoIterator.next().getRootNode();
+ } else {
+ refNode = yangFileInfo.getRootNode();
+ selfNode = yangFileInfoIterator.next().getRootNode();
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("module1"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("invalid-interval"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+ assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ is((YangTypeDef) refNode.getChild()));
+
+ assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+ // Check for the effective built-in type.
+ assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+ // Check for the restriction.
+ assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+ assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
+ }
+
+ /**
+ * Checks inter file uses linking.
+ */
+ @Test
+ public void processInterFileUsesLinking()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfileuses";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+
+ YangNode refNode = null;
+ YangNode selfNode = null;
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
+
+ Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
+
+ YangFileInfo yangFileInfo = yangFileInfoIterator.next();
+
+ if (yangFileInfo.getRootNode().getName().equals("module1")) {
+ selfNode = yangFileInfo.getRootNode();
+ refNode = yangFileInfoIterator.next().getRootNode();
+ } else {
+ refNode = yangFileInfo.getRootNode();
+ selfNode = yangFileInfoIterator.next().getRootNode();
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((selfNode instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("module1"));
+
+ ListIterator<YangLeaf> leafIterator;
+ YangLeaf leafInfo;
+
+ // Check whether grouping is the sibling of module's child.
+ assertThat((refNode.getChild() instanceof YangGrouping), is(true));
+
+ YangGrouping grouping = (YangGrouping) refNode.getChild();
+ leafIterator = grouping.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under grouping.
+ assertThat(leafInfo.getName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ // Check whether uses is module's child.
+ assertThat((yangNode.getChild() instanceof YangUses), is(true));
+ YangUses uses = (YangUses) yangNode.getChild();
+
+ // Check whether uses get resolved.
+ assertThat(uses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ leafIterator = yangNode.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under module.
+ assertThat(leafInfo.getName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+ }
+
+ /**
+ * Checks inter file type linking with include list.
+ */
+ @Test
+ public void processInterFileTypeLinkingWithIncludeList()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfiletypewithinclude";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+
+ YangNode refNode = null;
+ YangNode selfNode = null;
+
+ // Carry out linking of sub module with module.
+ yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangFileInfoSet());
+
+ // Add reference to include list.
+ yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangFileInfoSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
+
+ Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
+
+ YangFileInfo yangFileInfo = yangFileInfoIterator.next();
+
+ if (yangFileInfo.getRootNode().getName().equals("module1")) {
+ selfNode = yangFileInfo.getRootNode();
+ refNode = yangFileInfoIterator.next().getRootNode();
+ } else {
+ refNode = yangFileInfo.getRootNode();
+ selfNode = yangFileInfoIterator.next().getRootNode();
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("module1"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("invalid-interval"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+ assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ is((YangTypeDef) refNode.getChild()));
+
+ assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+ // Check for the effective built-in type.
+ assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+ // Check for the restriction.
+ assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+ assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
+ }
+
+ /**
+ * Checks inter file uses linking with include list.
+ */
+ @Test
+ public void processInterFileUsesLinkingWithInclude()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfileuseswithinclude";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+
+ YangNode refNode = null;
+ YangNode selfNode = null;
+
+ // Carry out linking of sub module with module.
+ yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangFileInfoSet());
+
+ // Add reference to include list.
+ yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangFileInfoSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
+
+ Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
+
+ YangFileInfo yangFileInfo = yangFileInfoIterator.next();
+
+ if (yangFileInfo.getRootNode().getName().equals("module1")) {
+ selfNode = yangFileInfo.getRootNode();
+ refNode = yangFileInfoIterator.next().getRootNode();
+ } else {
+ refNode = yangFileInfo.getRootNode();
+ selfNode = yangFileInfoIterator.next().getRootNode();
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((selfNode instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("module1"));
+
+ ListIterator<YangLeaf> leafIterator;
+ YangLeaf leafInfo;
+
+ // Check whether grouping is the sibling of module's child.
+ assertThat((refNode.getChild() instanceof YangGrouping), is(true));
+
+ YangGrouping grouping = (YangGrouping) refNode.getChild();
+ leafIterator = grouping.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under grouping.
+ assertThat(leafInfo.getName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+
+ // Check whether uses is module's child.
+ assertThat((yangNode.getChild() instanceof YangUses), is(true));
+ YangUses uses = (YangUses) yangNode.getChild();
+
+ // Check whether uses get resolved.
+ assertThat(uses.getResolvableStatus(),
+ is(ResolvableStatus.RESOLVED));
+
+ leafIterator = yangNode.getListOfLeaf().listIterator();
+ leafInfo = leafIterator.next();
+
+ // Check whether the information in the leaf is correct under module.
+ assertThat(leafInfo.getName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+ }
+
+ /**
+ * Checks inter file type linking with revision.
+ */
+ @Test
+ public void processInterFileTypeLinkingWithRevision()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfiletypewithrevision";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+
+ YangNode refNode = null;
+ YangNode selfNode = null;
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
+
+ Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
+
+ YangFileInfo yangFileInfo = yangFileInfoIterator.next();
+
+ if (yangFileInfo.getRootNode().getName().equals("module1")) {
+ selfNode = yangFileInfo.getRootNode();
+ refNode = yangFileInfoIterator.next().getRootNode();
+ } else {
+ refNode = yangFileInfo.getRootNode();
+ selfNode = yangFileInfoIterator.next().getRootNode();
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("module1"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("invalid-interval"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+ assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ is((YangTypeDef) refNode.getChild()));
+
+ assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+ // Check for the effective built-in type.
+ assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+ // Check for the restriction.
+ assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+ assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
+ }
+
+ /**
+ * Checks inter file type linking with revision in name.
+ */
+ @Test
+ public void processInterFileTypeLinkingWithRevisionInName()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfiletypewithrevisioninname";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+
+ YangNode refNode = null;
+ YangNode selfNode = null;
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
+
+ Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
+
+ YangFileInfo yangFileInfo = yangFileInfoIterator.next();
+
+ if (yangFileInfo.getRootNode().getName().equals("module1")) {
+ selfNode = yangFileInfo.getRootNode();
+ refNode = yangFileInfoIterator.next().getRootNode();
+ } else {
+ refNode = yangFileInfo.getRootNode();
+ selfNode = yangFileInfoIterator.next().getRootNode();
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("module1"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("invalid-interval"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+ assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+ assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ is((YangTypeDef) refNode.getChild()));
+
+ assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+ // Check for the effective built-in type.
+ assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+ // Check for the restriction.
+ assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+ assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
+ }
+
+ /**
+ * Checks hierarchical inter file type linking.
+ */
+ @Test
+ public void processHierarchicalInterFileTypeLinking()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/hierarchicalinterfiletype";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+ YangNode selfNode = null;
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
+
+ for (YangFileInfo yangFile : utilManager.getYangFileInfoSet()) {
+ if (yangFile.getRootNode().getName().equals("ietf-network-topology")) {
+ selfNode = yangFile.getRootNode();
+ } else if (yangFile.getRootNode().getName().equals("ietf-network")) {
+ refNode1 = yangFile.getRootNode();
+ } else {
+ refNode2 = yangFile.getRootNode();
+ }
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("ietf-network-topology"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("source-node"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("node-id"));
+ assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+ assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ is((YangTypeDef) refNode1.getChild()));
+
+ assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+ // Check for the effective built-in type.
+ assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+ // Check for the restriction.
+ assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+ assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
+ }
+
+ /**
+ * Checks hierarchical intra with inter file type linking.
+ */
+ @Test
+ public void processHierarchicalIntraWithInterFileTypeLinking()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/hierarchicalintrawithinterfiletype";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+
+ YangNode refNode1 = null;
+ YangNode selfNode = null;
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
+
+ for (YangFileInfo yangFile : utilManager.getYangFileInfoSet()) {
+ if (yangFile.getRootNode().getName().equals("ietf-network")) {
+ selfNode = yangFile.getRootNode();
+ } else if (yangFile.getRootNode().getName().equals("ietf-inet-types")) {
+ refNode1 = yangFile.getRootNode();
+ }
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("ietf-network"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("node-ref"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("node-id"));
+ assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+ assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ is((YangTypeDef) selfNode.getChild()));
+
+ assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+ // Check for the effective built-in type.
+ assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+ // Check for the restriction.
+ assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+ assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
+ }
+}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java
index a4cb0a5..ab4f45f 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java
@@ -32,12 +32,13 @@
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
-import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED;
-import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
/**
* Test cases for testing "type" intra file linking.
@@ -516,4 +517,48 @@
YangNode node =
manager.getDataModel("src/test/resources/SelfFileLinkingWithHierarchicalTypeFailureScenario.yang");
}
+
+ /**
+ * Checks self resolution when typedef and leaf using type are siblings for binary type.
+ */
+ @Test
+ public void processSelfResolutionWhenTypeAndTypedefAtRootLevelForBinary()
+ throws IOException, ParserException {
+
+ YangNode node
+ = manager.getDataModel("src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevelForBinary.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(node instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("ospf"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("typedef14"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("type14"));
+ assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+ assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ is((YangTypeDef) node.getChild()));
+
+ assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+ // Check for the effective built-in type.
+ assertThat(derivedInfo.getEffectiveBuiltInType(), is(BINARY));
+
+ // Check for the restriction.
+ assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+ assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+ assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
+ }
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
index 85c3840..e906afd 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
@@ -21,7 +21,6 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.onosproject.yangutils.datamodel.ResolvableStatus;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangGrouping;
@@ -32,6 +31,8 @@
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUses;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import org.onosproject.yangutils.linker.impl.ResolvableStatus;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
@@ -293,9 +294,9 @@
*/
@Test
public void processSelfResolutionGroupingReferencingItselfFailureScenerio()
- throws IOException, ParserException {
+ throws IOException {
- thrown.expect(ParserException.class);
+ thrown.expect(LinkerException.class);
thrown.expectMessage(
"YANG file error: Duplicate input identifier detected, same as leaf \"zip-code\"");
YangNode node = manager
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/RestrictionResolutionTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/RestrictionResolutionTest.java
index 4b473f4..7b1eeaf 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/RestrictionResolutionTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/RestrictionResolutionTest.java
@@ -30,6 +30,7 @@
import org.onosproject.yangutils.datamodel.YangStringRestriction;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.builtindatatype.YangInt32;
@@ -39,11 +40,11 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
-import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
/**
* Test cases for testing restriction resolution.
@@ -225,9 +226,9 @@
/**
* Checks length restriction in typedef and in type with not stricter value.
*/
- @Test(expected = ParserException.class)
+ @Test(expected = LinkerException.class)
public void processLengthRestrictionInTypedefAndTypeInValid()
- throws IOException, ParserException, DataModelException {
+ throws IOException, DataModelException {
YangNode node = manager.getDataModel("src/test/resources/LengthRestrictionInTypedefAndTypeInValid.yang");
}
@@ -429,9 +430,9 @@
/**
* Checks range restriction for string in referred type.
*/
- @Test(expected = ParserException.class)
+ @Test(expected = LinkerException.class)
public void processRangeRestrictionInStringInRefType()
- throws IOException, ParserException, DataModelException {
+ throws IOException, DataModelException {
YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInStringInRefType.yang");
}
@@ -826,9 +827,9 @@
* Checks multiple pattern and length restriction in referred type and
* typedef invalid scenario.
*/
- @Test(expected = ParserException.class)
+ @Test(expected = LinkerException.class)
public void processMultiplePatternAndLengthRestrictionInValid()
- throws IOException, ParserException, DataModelException {
+ throws IOException, DataModelException {
YangNode node = manager.getDataModel("src/test/resources/MultiplePatternAndLengthRestrictionInValid.yang");
}
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
index 40036f5..ae15d0c 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
@@ -144,7 +144,7 @@
public void processLengthWithInvalidType() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("YANG file error : length name \"1..100\" can be used to restrict the built-in type" +
- " string or types derived from string.");
+ " string/binary or types derived from string/binary.");
YangNode node = manager.getDataModel("src/test/resources/LengthWithInvalidType.yang");
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
index 7d199b9..1d17976 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
@@ -26,7 +26,6 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
@@ -49,11 +48,11 @@
/**
* A private constructor is tested.
*
- * @throws SecurityException if any security violation is observed
- * @throws NoSuchMethodException if when the method is not found
- * @throws IllegalArgumentException if there is illegal argument found
- * @throws InstantiationException if instantiation is provoked for the private constructor
- * @throws IllegalAccessException if instance is provoked or a method is provoked
+ * @throws SecurityException if any security violation is observed
+ * @throws NoSuchMethodException if when the method is not found
+ * @throws IllegalArgumentException if there is illegal argument found
+ * @throws InstantiationException if instantiation is provoked for the private constructor
+ * @throws IllegalAccessException if instance is provoked or a method is provoked
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
@@ -101,7 +100,7 @@
/**
* Method used for creating file inside the specified directory.
*
- * @param myDir the path where file has to be created inside
+ * @param myDir the path where file has to be created inside
* @param fileName the name of the file to be created
*/
private void createFile(File myDir, String fileName) throws IOException {
@@ -136,7 +135,7 @@
String emptyYangDir = baseDir + separator + "scanner1";
File path = createDirectory(emptyYangDir);
- List<YangFileInfo> emptyDirContents = getYangFiles(path.toString());
+ List<String> emptyDirContents = getYangFiles(path.toString());
List<String> expectedContents = new LinkedList<>();
assertThat(true, is(emptyDirContents.equals(expectedContents)));
}
diff --git a/utils/yangutils/src/test/resources/SelfFileLinkingTypedefNotFound.yang b/utils/yangutils/src/test/resources/SelfFileLinkingTypedefNotFound.yang
index 9248598..523f0b4 100644
--- a/utils/yangutils/src/test/resources/SelfFileLinkingTypedefNotFound.yang
+++ b/utils/yangutils/src/test/resources/SelfFileLinkingTypedefNotFound.yang
@@ -6,13 +6,13 @@
list valid {
key "invalid-interval";
leaf invalid-interval {
- type hello;
+ type Ant:hello;
}
}
}
container isis {
typedef hello {
- type String;
+ type string;
}
}
}
diff --git a/utils/yangutils/src/test/resources/SelfFileLinkingWithHierarchicalTypeFailureScenario.yang b/utils/yangutils/src/test/resources/SelfFileLinkingWithHierarchicalTypeFailureScenario.yang
index 71d1947..d622196 100644
--- a/utils/yangutils/src/test/resources/SelfFileLinkingWithHierarchicalTypeFailureScenario.yang
+++ b/utils/yangutils/src/test/resources/SelfFileLinkingWithHierarchicalTypeFailureScenario.yang
@@ -3,7 +3,7 @@
namespace http://huawei.com;
prefix Ant;
typedef Percentage {
- type INT;
+ type Ant:INT;
}
container ospf {
list valid {
diff --git a/utils/yangutils/src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang b/utils/yangutils/src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang
index 4dbc1a2..b2ab735 100644
--- a/utils/yangutils/src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang
+++ b/utils/yangutils/src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang
@@ -2,9 +2,9 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
- container test{
- leaf leaf2{
- type String;
+ container test {
+ leaf leaf2 {
+ type string;
}
grouping treat {
grouping create {
@@ -13,5 +13,5 @@
}
}
}
- uses treat;
+ uses Ant:treat;
}
diff --git a/utils/yangutils/src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevelForBinary.yang b/utils/yangutils/src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevelForBinary.yang
new file mode 100644
index 0000000..d6ff30e
--- /dev/null
+++ b/utils/yangutils/src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevelForBinary.yang
@@ -0,0 +1,17 @@
+module ospf {
+ namespace "urn:cisco:params:xml:ns:yang:ospf";
+ // replace with IANA namespace when assigned
+ prefix ospf;
+ revision 2020-10-20 {
+ description
+ "Initial revision.";
+ }
+
+ typedef type14 {
+ type binary;
+ }
+
+ leaf typedef14 {
+ type type14;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/SelfResolutionWhenTypeReferredTypedefNotDefined.yang b/utils/yangutils/src/test/resources/SelfResolutionWhenTypeReferredTypedefNotDefined.yang
index 499e10d..33f90c9 100644
--- a/utils/yangutils/src/test/resources/SelfResolutionWhenTypeReferredTypedefNotDefined.yang
+++ b/utils/yangutils/src/test/resources/SelfResolutionWhenTypeReferredTypedefNotDefined.yang
@@ -3,9 +3,9 @@
namespace http://huawei.com;
prefix Ant;
leaf invalid-interval {
- type hello;
+ type Ant:hello;
}
typedef hi {
- type String;
+ type string;
}
}
diff --git a/utils/yangutils/src/test/resources/hierarchicalinterfiletype/ietf-inet-types.yang b/utils/yangutils/src/test/resources/hierarchicalinterfiletype/ietf-inet-types.yang
new file mode 100644
index 0000000..38f209f
--- /dev/null
+++ b/utils/yangutils/src/test/resources/hierarchicalinterfiletype/ietf-inet-types.yang
@@ -0,0 +1,15 @@
+ module ietf-inet-types {
+
+ yang-version 1;
+
+ namespace
+ "urn:ietf:params:xml:ns:yang:ietf-inet-types";
+
+ prefix inet;
+
+
+
+ typedef uri {
+ type string;
+ }
+ }
diff --git a/utils/yangutils/src/test/resources/hierarchicalinterfiletype/ietf-network-topology.yang b/utils/yangutils/src/test/resources/hierarchicalinterfiletype/ietf-network-topology.yang
new file mode 100644
index 0000000..6e9dfb7
--- /dev/null
+++ b/utils/yangutils/src/test/resources/hierarchicalinterfiletype/ietf-network-topology.yang
@@ -0,0 +1,17 @@
+ module ietf-network-topology {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:ietf-network-topology";
+ prefix nt;
+
+ import ietf-inet-types {
+ prefix inet;
+ }
+ import ietf-network {
+ prefix nd;
+ }
+ leaf source-node {
+ type nd:node-id;
+ description
+ "Source node identifier, must be in same topology.";
+ }
+ }
diff --git a/utils/yangutils/src/test/resources/hierarchicalinterfiletype/ietf-network.yang b/utils/yangutils/src/test/resources/hierarchicalinterfiletype/ietf-network.yang
new file mode 100644
index 0000000..1f15b40
--- /dev/null
+++ b/utils/yangutils/src/test/resources/hierarchicalinterfiletype/ietf-network.yang
@@ -0,0 +1,16 @@
+ module ietf-network {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+ prefix nd;
+
+ import ietf-inet-types {
+ prefix inet;
+ }
+
+ typedef node-id {
+ type inet:uri;
+ description
+ "Identifier for a node.";
+ }
+
+ }
diff --git a/utils/yangutils/src/test/resources/hierarchicalintrawithinterfiletype/ietf-inet-types.yang b/utils/yangutils/src/test/resources/hierarchicalintrawithinterfiletype/ietf-inet-types.yang
new file mode 100644
index 0000000..48d13c6
--- /dev/null
+++ b/utils/yangutils/src/test/resources/hierarchicalintrawithinterfiletype/ietf-inet-types.yang
@@ -0,0 +1,13 @@
+ module ietf-inet-types {
+
+ yang-version 1;
+
+ namespace
+ "urn:ietf:params:xml:ns:yang:ietf-inet-types";
+
+ prefix inet;
+
+ typedef uri {
+ type string;
+ }
+ }
diff --git a/utils/yangutils/src/test/resources/hierarchicalintrawithinterfiletype/ietf-network.yang b/utils/yangutils/src/test/resources/hierarchicalintrawithinterfiletype/ietf-network.yang
new file mode 100644
index 0000000..e35d0f5
--- /dev/null
+++ b/utils/yangutils/src/test/resources/hierarchicalintrawithinterfiletype/ietf-network.yang
@@ -0,0 +1,22 @@
+ module ietf-network {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+ prefix nd;
+
+ import ietf-inet-types {
+ prefix inet;
+ }
+ leaf node-ref {
+ type node-id;
+ description
+ "Used to reference a node.
+ Nodes are identified relative to the network they are
+ contained in.";
+ }
+
+ typedef node-id {
+ type inet:uri;
+ description
+ "Identifier for a node.";
+ }
+ }
diff --git a/utils/yangutils/src/test/resources/interfiletype/module1.yang b/utils/yangutils/src/test/resources/interfiletype/module1.yang
new file mode 100644
index 0000000..3c60bd6
--- /dev/null
+++ b/utils/yangutils/src/test/resources/interfiletype/module1.yang
@@ -0,0 +1,14 @@
+module module1 {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ import module2 {
+ prefix p;
+ }
+ leaf invalid-interval {
+ type p:hello;
+ }
+ typedef hello {
+ type string;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/interfiletype/module2.yang b/utils/yangutils/src/test/resources/interfiletype/module2.yang
new file mode 100644
index 0000000..6784c45
--- /dev/null
+++ b/utils/yangutils/src/test/resources/interfiletype/module2.yang
@@ -0,0 +1,8 @@
+module module2 {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant2;
+ typedef hello {
+ type string;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/interfiletypewithinclude/module1.yang b/utils/yangutils/src/test/resources/interfiletypewithinclude/module1.yang
new file mode 100644
index 0000000..d1d4db3
--- /dev/null
+++ b/utils/yangutils/src/test/resources/interfiletypewithinclude/module1.yang
@@ -0,0 +1,9 @@
+module module1 {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ include module2;
+ leaf invalid-interval {
+ type hello;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/interfiletypewithinclude/module2.yang b/utils/yangutils/src/test/resources/interfiletypewithinclude/module2.yang
new file mode 100644
index 0000000..8e47100
--- /dev/null
+++ b/utils/yangutils/src/test/resources/interfiletypewithinclude/module2.yang
@@ -0,0 +1,9 @@
+submodule module2 {
+ yang-version 1;
+ belongs-to module1 {
+ prefix "module1";
+ }
+ typedef hello {
+ type string;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/interfiletypewithrevision/module1.yang b/utils/yangutils/src/test/resources/interfiletypewithrevision/module1.yang
new file mode 100644
index 0000000..180511d
--- /dev/null
+++ b/utils/yangutils/src/test/resources/interfiletypewithrevision/module1.yang
@@ -0,0 +1,15 @@
+module module1 {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ import module2 {
+ prefix p;
+ revision-date 2007-06-09;
+ }
+ leaf invalid-interval {
+ type p:hello;
+ }
+ typedef hello {
+ type string;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/interfiletypewithrevision/module2.yang b/utils/yangutils/src/test/resources/interfiletypewithrevision/module2.yang
new file mode 100644
index 0000000..fd99872
--- /dev/null
+++ b/utils/yangutils/src/test/resources/interfiletypewithrevision/module2.yang
@@ -0,0 +1,11 @@
+module module2 {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant2;
+ revision 2007-06-09 {
+ description "Initial revision.";
+ }
+ typedef hello {
+ type string;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/interfiletypewithrevisioninname/module1.yang b/utils/yangutils/src/test/resources/interfiletypewithrevisioninname/module1.yang
new file mode 100644
index 0000000..180511d
--- /dev/null
+++ b/utils/yangutils/src/test/resources/interfiletypewithrevisioninname/module1.yang
@@ -0,0 +1,15 @@
+module module1 {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ import module2 {
+ prefix p;
+ revision-date 2007-06-09;
+ }
+ leaf invalid-interval {
+ type p:hello;
+ }
+ typedef hello {
+ type string;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/interfiletypewithrevisioninname/module2@2007-06-09.yang b/utils/yangutils/src/test/resources/interfiletypewithrevisioninname/module2@2007-06-09.yang
new file mode 100644
index 0000000..fd99872
--- /dev/null
+++ b/utils/yangutils/src/test/resources/interfiletypewithrevisioninname/module2@2007-06-09.yang
@@ -0,0 +1,11 @@
+module module2 {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant2;
+ revision 2007-06-09 {
+ description "Initial revision.";
+ }
+ typedef hello {
+ type string;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/interfileuses/module1.yang b/utils/yangutils/src/test/resources/interfileuses/module1.yang
new file mode 100644
index 0000000..69df326
--- /dev/null
+++ b/utils/yangutils/src/test/resources/interfileuses/module1.yang
@@ -0,0 +1,9 @@
+module module1 {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ import module2 {
+ prefix p;
+ }
+ uses p:hello;
+}
diff --git a/utils/yangutils/src/test/resources/interfileuses/module2.yang b/utils/yangutils/src/test/resources/interfileuses/module2.yang
new file mode 100644
index 0000000..5bb3616
--- /dev/null
+++ b/utils/yangutils/src/test/resources/interfileuses/module2.yang
@@ -0,0 +1,10 @@
+module module2 {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ grouping hello {
+ leaf hello {
+ type string;
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/interfileuseswithinclude/module1.yang b/utils/yangutils/src/test/resources/interfileuseswithinclude/module1.yang
new file mode 100644
index 0000000..41899d9
--- /dev/null
+++ b/utils/yangutils/src/test/resources/interfileuseswithinclude/module1.yang
@@ -0,0 +1,7 @@
+module module1 {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ include module2;
+ uses hello;
+}
diff --git a/utils/yangutils/src/test/resources/interfileuseswithinclude/module2.yang b/utils/yangutils/src/test/resources/interfileuseswithinclude/module2.yang
new file mode 100644
index 0000000..1b423d9
--- /dev/null
+++ b/utils/yangutils/src/test/resources/interfileuseswithinclude/module2.yang
@@ -0,0 +1,11 @@
+submodule module2 {
+ yang-version 1;
+ belongs-to module1 {
+ prefix "module1";
+ }
+ grouping hello {
+ leaf hello {
+ type string;
+ }
+ }
+}