[ONOS-4670] Removal of Data Model dependencies on Linker
Change-Id: I3f9c5af30198ea31d743e06cea1764dcb306ec32
diff --git a/src/main/java/org/onosproject/yangutils/linker/Resolvable.java b/src/main/java/org/onosproject/yangutils/linker/Resolvable.java
index 975c3f4..8fb10ad 100644
--- a/src/main/java/org/onosproject/yangutils/linker/Resolvable.java
+++ b/src/main/java/org/onosproject/yangutils/linker/Resolvable.java
@@ -16,7 +16,7 @@
package org.onosproject.yangutils.linker;
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
/**
* Abstraction of YANG resolvable information. Abstracted to obtain the
@@ -47,8 +47,8 @@
/**
* Resolves the linking.
*
- * @throws LinkerException linker error
+ * @throws DataModelException data model exception
*/
void resolve()
- throws LinkerException;
+ throws DataModelException;
}
diff --git a/src/main/java/org/onosproject/yangutils/linker/ResolvableType.java b/src/main/java/org/onosproject/yangutils/linker/ResolvableType.java
deleted file mode 100644
index ff0778f..0000000
--- a/src/main/java/org/onosproject/yangutils/linker/ResolvableType.java
+++ /dev/null
@@ -1,33 +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.linker;
-
-/**
- * Type of the resolvable info.
- */
-public enum ResolvableType {
-
- /**
- * Identifies the derived data type.
- */
- YANG_DERIVED_DATA_TYPE,
-
- /**
- * Identifies the uses.
- */
- YANG_USES
-}
diff --git a/src/main/java/org/onosproject/yangutils/linker/YangReferenceResolver.java b/src/main/java/org/onosproject/yangutils/linker/YangReferenceResolver.java
deleted file mode 100644
index 307675d..0000000
--- a/src/main/java/org/onosproject/yangutils/linker/YangReferenceResolver.java
+++ /dev/null
@@ -1,150 +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.linker;
-
-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.linker.impl.YangResolutionInfo;
-import org.onosproject.yangutils.plugin.manager.YangFileInfo;
-
-/**
- * Abstraction of YANG dependency resolution information. Abstracted to obtain the
- * resolution information.
- */
-public interface YangReferenceResolver {
-
- /**
- * Returns unresolved resolution list.
- *
- * @param type resolvable type
- * @return list of resolution information objects
- */
- List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type);
-
- /**
- * Adds to the resolution list.
- *
- * @param resolutionInfo resolution information
- * @param type resolvable type
- */
- void addToResolutionList(YangResolutionInfo resolutionInfo, ResolvableType type);
-
- /**
- * Creates resolution list.
- *
- * @param resolutionList resolution list
- * @param type resolvable type
- */
- void setResolutionList(List<YangResolutionInfo> resolutionList, ResolvableType type);
-
- /**
- * Returns unresolved imported list.
- *
- * @return unresolved imported list
- */
- List<YangImport> getImportList();
-
- /**
- * Adds to the import list.
- *
- * @param yangImport import to be added
- */
- void addToImportList(YangImport yangImport);
-
- /**
- * Create import list.
- *
- * @param importList import list
- */
- void setImportList(List<YangImport> importList);
-
- /**
- * Returns unresolved include list.
- *
- * @return unresolved include list
- */
- List<YangInclude> getIncludeList();
-
- /**
- * Adds to the include list.
- *
- * @param yangInclude include to be added
- */
- void addToIncludeList(YangInclude yangInclude);
-
- /**
- * Creates include list.
- *
- * @param includeList include list
- */
- void setIncludeList(List<YangInclude> includeList);
-
- /**
- * Returns prefix of resolution root node.
- *
- * @return prefix resolution root node prefix
- */
- String getPrefix();
-
- /**
- * Sets prefix of resolution list root node.
- *
- * @param prefix resolution root node prefix
- */
- void setPrefix(String prefix);
-
- /**
- * Resolves self file linking.
- *
- * @param type resolvable type
- * @throws DataModelException a violation in data model rule
- */
- void resolveSelfFileLinking(ResolvableType type)
- throws DataModelException;
-
- /**
- * Resolves inter file linking.
- *
- * @param type resolvable type
- * @throws DataModelException a violation in data model rule
- */
- void resolveInterFileLinking(ResolvableType type)
- 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/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfo.java b/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfoImpl.java
similarity index 77%
rename from src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfo.java
rename to src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfoImpl.java
index f239692..b8f63eb 100644
--- a/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfo.java
+++ b/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfoImpl.java
@@ -15,17 +15,18 @@
*/
package org.onosproject.yangutils.linker.impl;
+import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
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.
+ * Represents implementation of information about entity being resolved.
*
* @param <T> type of entity being resolved, uses / grouping
*/
-public class YangEntityToResolveInfo<T> {
+public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T> {
// Parsable node for which resolution is to be performed.
private T entityToResolve;
@@ -33,39 +34,22 @@
// Holder of the YANG construct for which resolution has to be carried out.
private YangNode holderOfEntityToResolve;
- /**
- * Retrieves the entity to be resolved.
- *
- * @return entity to be resolved
- */
+ @Override
public T getEntityToResolve() {
return entityToResolve;
}
- /**
- * Sets entity to be resolved.
- *
- * @param entityToResolve entity to be resolved
- */
+ @Override
public void setEntityToResolve(T entityToResolve) {
this.entityToResolve = entityToResolve;
}
- /**
- * Retrieves the parent node which contains the entity to be resolved.
- *
- * @return parent node which contains the entity to be resolved
- */
+ @Override
public YangNode getHolderOfEntityToResolve() {
return holderOfEntityToResolve;
}
- /**
- * Sets parent node which contains the entity to be resolved.
- *
- * @param holderOfEntityToResolve parent node which contains the entity to
- * be resolved
- */
+ @Override
public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
this.holderOfEntityToResolve = holderOfEntityToResolve;
}
diff --git a/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java b/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
index deaebb2..4e8a60a 100644
--- a/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
+++ b/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
@@ -16,14 +16,14 @@
package org.onosproject.yangutils.linker.impl;
+import java.util.HashSet;
import java.util.Set;
-
+import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.linker.ResolvableType;
import org.onosproject.yangutils.linker.YangLinker;
-import org.onosproject.yangutils.linker.YangReferenceResolver;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
@@ -34,9 +34,39 @@
*/
public class YangLinkerManager
implements YangLinker {
+
+ /*
+ * Set of all the YANG nodes, corresponding to the YANG files parsed by
+ * parser.
+ */
+ Set<YangNode> yangNodeSet = new HashSet<>();
+
+ /**
+ * Returns set of YANG node.
+ *
+ * @return set of YANG node
+ */
+ public Set<YangNode> getYangNodeSet() {
+ return yangNodeSet;
+ }
+
+ /**
+ * Creates YANG nodes set.
+ *
+ * @param yangFileInfoSet YANG file information set
+ */
+ public void createYangNodeSet(Set<YangFileInfo> yangFileInfoSet) {
+ for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+ getYangNodeSet().add(yangFileInfo.getRootNode());
+ }
+ }
+
@Override
public void resolveDependencies(Set<YangFileInfo> yangFileInfoSet) {
+ // Create YANG node set.
+ createYangNodeSet(yangFileInfoSet);
+
// Carry out linking of sub module with module.
linkSubModulesToParentModule(yangFileInfoSet);
@@ -64,7 +94,7 @@
YangNode yangNode = yangFileInfo.getRootNode();
if (yangNode instanceof YangSubModule) {
try {
- ((YangSubModule) yangNode).linkWithModule(yangFileInfoSet);
+ ((YangSubModule) yangNode).linkWithModule(getYangNodeSet());
} catch (DataModelException e) {
String errorInfo = "YANG file error: " + yangFileInfo.getYangFileName() + " at line: "
+ e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
@@ -85,7 +115,14 @@
for (YangFileInfo yangFileInfo : yangFileInfoSet) {
YangNode yangNode = yangFileInfo.getRootNode();
if (yangNode instanceof YangReferenceResolver) {
- ((YangReferenceResolver) yangNode).addReferencesToImportList(yangFileInfoSet);
+ try {
+ ((YangReferenceResolver) yangNode).addReferencesToImportList(getYangNodeSet());
+ } 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);
+ }
}
}
}
@@ -100,7 +137,14 @@
for (YangFileInfo yangFileInfo : yangFileInfoSet) {
YangNode yangNode = yangFileInfo.getRootNode();
if (yangNode instanceof YangReferenceResolver) {
- ((YangReferenceResolver) yangNode).addReferencesToIncludeList(yangFileInfoSet);
+ try {
+ ((YangReferenceResolver) yangNode).addReferencesToIncludeList(getYangNodeSet());
+ } 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/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java b/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
similarity index 94%
rename from src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java
rename to src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
index 83b11c4..0d43293 100644
--- a/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java
+++ b/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
@@ -17,14 +17,14 @@
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.YangReferenceResolver;
+import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUses;
@@ -32,7 +32,6 @@
import org.onosproject.yangutils.linker.Resolvable;
import org.onosproject.yangutils.linker.ResolvableStatus;
import org.onosproject.yangutils.linker.YangLinkingPhase;
-import org.onosproject.yangutils.linker.YangReferenceResolver;
import static org.onosproject.yangutils.linker.ResolvableStatus.INTER_FILE_LINKED;
import static org.onosproject.yangutils.linker.ResolvableStatus.INTRA_FILE_RESOLVED;
@@ -41,21 +40,22 @@
import static org.onosproject.yangutils.linker.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.linker.YangLinkingPhase.INTER_FILE;
import static org.onosproject.yangutils.linker.YangLinkingPhase.INTRA_FILE;
-import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
/**
- * Represents resolution object which will be resolved by linker.
+ * Represents implementation of resolution object which will be resolved by
+ * linker.
*
* @param <T> type of resolution entity uses / type
*/
-public class YangResolutionInfo<T>
- implements LocationInfo {
+public class YangResolutionInfoImpl<T>
+ implements YangResolutionInfo<T> {
/**
* Information about the entity that needs to be resolved.
*/
- private YangEntityToResolveInfo<T> entityToResolveInfo;
+ private YangEntityToResolveInfoImpl<T> entityToResolveInfo;
/**
* Error line number.
@@ -77,14 +77,14 @@
* Stack for type/uses is maintained for hierarchical references, this is
* used during resolution.
*/
- private Stack<YangEntityToResolveInfo<T>> partialResolvedStack;
+ private Stack<YangEntityToResolveInfoImpl<T>> partialResolvedStack;
/**
* It is private to ensure the overloaded method be invoked to create an
* object.
*/
@SuppressWarnings("unused")
- private YangResolutionInfo() {
+ private YangResolutionInfoImpl() {
}
@@ -96,8 +96,8 @@
* @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<>());
+ public YangResolutionInfoImpl(T dataNode, YangNode holderNode, int lineNumber, int charPositionInLine) {
+ setEntityToResolveInfo(new YangEntityToResolveInfoImpl<>());
getEntityToResolveInfo().setEntityToResolve(dataNode);
getEntityToResolveInfo().setHolderOfEntityToResolve(holderNode);
this.setLineNumber(lineNumber);
@@ -105,13 +105,7 @@
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
- */
+ @Override
public void resolveLinkingForResolutionInfo(YangReferenceResolver dataModelRootNode)
throws DataModelException {
@@ -431,11 +425,12 @@
if (((YangTypeDef) referredNode).getTypeDefBaseType().getDataType()
== YangDataTypes.DERIVED) {
- YangEntityToResolveInfo<YangType<?>> unResolvedEntityInfo = new YangEntityToResolveInfo<>();
+ YangEntityToResolveInfoImpl<YangType<?>> unResolvedEntityInfo
+ = new YangEntityToResolveInfoImpl<>();
unResolvedEntityInfo.setEntityToResolve(((YangTypeDef) referredNode)
.getTypeDefBaseType());
unResolvedEntityInfo.setHolderOfEntityToResolve(referredNode);
- addInPartialResolvedStack((YangEntityToResolveInfo<T>) unResolvedEntityInfo);
+ addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
}
} else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
@@ -462,10 +457,10 @@
YangNode curNode = node.getChild();
while (curNode != null) {
if (curNode instanceof YangUses) {
- YangEntityToResolveInfo<YangUses> unResolvedEntityInfo = new YangEntityToResolveInfo<>();
+ YangEntityToResolveInfoImpl<YangUses> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
unResolvedEntityInfo.setEntityToResolve((YangUses) curNode);
unResolvedEntityInfo.setHolderOfEntityToResolve(node);
- addInPartialResolvedStack((YangEntityToResolveInfo<T>) unResolvedEntityInfo);
+ addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
}
curNode = curNode.getNextSibling();
@@ -478,7 +473,7 @@
*
* @return partial resolved YANG construct stack
*/
- private Stack<YangEntityToResolveInfo<T>> getPartialResolvedStack() {
+ private Stack<YangEntityToResolveInfoImpl<T>> getPartialResolvedStack() {
return partialResolvedStack;
}
@@ -487,7 +482,7 @@
*
* @param partialResolvedStack partial resolved YANG construct stack
*/
- private void setPartialResolvedStack(Stack<YangEntityToResolveInfo<T>> partialResolvedStack) {
+ private void setPartialResolvedStack(Stack<YangEntityToResolveInfoImpl<T>> partialResolvedStack) {
this.partialResolvedStack = partialResolvedStack;
}
@@ -496,7 +491,7 @@
*
* @param partialResolvedInfo partial resolved YANG construct stack
*/
- private void addInPartialResolvedStack(YangEntityToResolveInfo<T> partialResolvedInfo) {
+ private void addInPartialResolvedStack(YangEntityToResolveInfoImpl<T> partialResolvedInfo) {
getPartialResolvedStack().push(partialResolvedInfo);
}
@@ -510,12 +505,8 @@
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() {
+ @Override
+ public YangEntityToResolveInfoImpl<T> getEntityToResolveInfo() {
return entityToResolveInfo;
}
@@ -525,7 +516,7 @@
* @param entityToResolveInfo information about the entity that needs to be
* resolved
*/
- private void setEntityToResolveInfo(YangEntityToResolveInfo<T> entityToResolveInfo) {
+ private void setEntityToResolveInfo(YangEntityToResolveInfoImpl<T> entityToResolveInfo) {
this.entityToResolveInfo = entityToResolveInfo;
}
@@ -569,13 +560,7 @@
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
- */
+ @Override
public void linkInterFile(YangReferenceResolver dataModelRootNode)
throws DataModelException {