YANG Grouping Linker Support
Change-Id: I2fec0c0bb4d1584e82ffba3228106897ccad2bf5
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/Resolvable.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/Resolvable.java
index 5e837a2..ab3462f 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/Resolvable.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/Resolvable.java
@@ -26,7 +26,7 @@
* Returns the status of resolution. If completely resolved returns enum
* value "RESOLVED", if not returns "UNRESOLVED", in case reference of
* grouping/typedef is added to uses/type but it's not resolved
- * "PARTIALLY_RESOLVED" is returned.
+ * "INTRA_FILE_RESOLVED" is returned.
*
* @return status of resolution
*/
@@ -36,7 +36,7 @@
* Set the status of type/uses resolution. If completely resolved set enum
* value "RESOLVED", if not set it to "UNRESOLVED", in case reference of
* grouping/typedef is added to uses/type but it's not resolved
- * "PARTIALLY_RESOLVED" should be set.
+ * "INTRA_FILE_RESOLVED" should be set.
*
* @param resolvableStatus status of resolution
*/
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolvableStatus.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolvableStatus.java
index 71b4e20..2514441 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolvableStatus.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/ResolvableStatus.java
@@ -22,17 +22,24 @@
public enum ResolvableStatus {
/**
- * Identifies that resolvable entity is resolved.
- */
- RESOLVED,
-
- /**
* Identifies that resolvable entity is unresolved.
*/
UNRESOLVED,
/**
- * Identifies that resolvable entity is partially resolved.
+ * Identifies that resolvable entity's reference is linked.
*/
- PARTIALLY_RESOLVED;
+ LINKED,
+
+ /**
+ * Identifies that resolvable entity is IntraFile resolved (i.e. complete
+ * linking with in the intra file).
+ */
+ INTRA_FILE_RESOLVED,
+
+ /**
+ * Identifies that resolvable entity is resolved.
+ */
+ RESOLVED;
+
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
index 374e2ab..adac640 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
@@ -75,6 +75,7 @@
* | when | 7.19.5 | 0..1 |-TODO |
* +--------------+---------+-------------+------------------+
*/
+
/**
* Representation of data model node to maintain information defined in YANG augment.
*/
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java
new file mode 100644
index 0000000..7e3d819
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java
@@ -0,0 +1,85 @@
+/*
+ * 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 org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+
+/**
+ * Represents information about entity being resolved.
+ */
+public class YangEntityToResolveInfo<T> {
+
+ // Parsable node for which resolution is to be performed.
+ private T entityToResolve;
+
+ // 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
+ */
+ public T getEntityToResolve() {
+ return entityToResolve;
+ }
+
+ /**
+ * Sets entity to be resolved.
+ *
+ * @param entityToResolve entity to be resolved
+ */
+ 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
+ */
+ 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
+ */
+ public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
+ this.holderOfEntityToResolve = holderOfEntityToResolve;
+ }
+
+
+ public String getEntityPrefix()
+ throws DataModelException {
+ if (getEntityToResolve() == null) {
+ return null;
+ }
+
+ String prefix;
+ T entityToResolve = (T) getEntityToResolve();
+ if (entityToResolve instanceof YangType) {
+ prefix = ((YangType<?>) entityToResolve).getPrefix();
+ } else if (entityToResolve instanceof YangUses) {
+ prefix = ((YangUses) entityToResolve).getPrefix();
+ } else {
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ }
+ return prefix;
+ }
+}
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 b079d3f..4ab3f2a 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
@@ -59,10 +59,12 @@
* | revision-date | 7.1.5.1 | 0..1 | string |
* +---------------+---------+-------------+------------------+
*/
+
/**
* Represents the information about the imported modules.
*/
-public class YangImport implements Parsable {
+public class YangImport
+ implements Parsable {
/**
* Name of the module that is being imported.
@@ -75,11 +77,6 @@
private String prefixId;
/**
- * Resolution information root node which is also the data model root node.
- */
- private HasResolutionInfo resolutionInfoNode;
-
- /**
* Reference:RFC 6020.
*
* The import's "revision-date" statement is used to specify the exact
@@ -118,7 +115,7 @@
* Returns the prefix used to identify the entities from the imported module.
*
* @return the prefix used to identify the entities from the imported
- * module
+ * module
*/
public String getPrefixId() {
return prefixId;
@@ -167,7 +164,8 @@
* @throws DataModelException a violation of data model rules
*/
@Override
- public void validateDataOnEntry() throws DataModelException {
+ public void validateDataOnEntry()
+ throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
@@ -178,26 +176,9 @@
* @throws DataModelException a violation of data model rules
*/
@Override
- public void validateDataOnExit() throws DataModelException {
+ public void validateDataOnExit()
+ throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
-
- /**
- * Returns the resolution information node.
- *
- * @return the resolution information node
- */
- public HasResolutionInfo getResolutionInfoNode() {
- return resolutionInfoNode;
- }
-
- /**
- * Sets the dresolution information node.
- *
- * @param resolutionInfoNode the resolution information node
- */
- public void setResolutionInfoNode(HasResolutionInfo resolutionInfoNode) {
- this.resolutionInfoNode = resolutionInfoNode;
- }
}
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 9010368..4892613 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
@@ -33,10 +33,12 @@
* | revision-date | 7.1.5.1 | 0..1 | string |
* +---------------+---------+-------------+------------------+
*/
+
/**
* Represents the information about the included sub-modules.
*/
-public class YangInclude implements Parsable {
+public class YangInclude
+ implements Parsable {
/**
* Name of the sub-module that is being included.
@@ -50,11 +52,6 @@
private String revision;
/**
- * Resolution information root node which is also the data model root node.
- */
- private HasResolutionInfo resolutionInfoNode;
-
- /**
* Creates a YANG include.
*/
public YangInclude() {
@@ -112,7 +109,8 @@
* @throws DataModelException a violation of data model rules
*/
@Override
- public void validateDataOnEntry() throws DataModelException {
+ public void validateDataOnEntry()
+ throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
@@ -123,26 +121,10 @@
* @throws DataModelException a violation of data model rules
*/
@Override
- public void validateDataOnExit() throws DataModelException {
+ public void validateDataOnExit()
+ throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
- /**
- * Returns the resolution information node.
- *
- * @return the resolution information node
- */
- public HasResolutionInfo getResolutionInfoNode() {
- return resolutionInfoNode;
- }
-
- /**
- * Sets the dresolution information node.
- *
- * @param resolutionInfoNode the resolution information node
- */
- public void setResolutionInfoNode(HasResolutionInfo resolutionInfoNode) {
- this.resolutionInfoNode = resolutionInfoNode;
- }
}
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
index b6c2f7c..c9c0064 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
@@ -20,19 +20,22 @@
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> {
- // Prefix associated with the linking.
- private String prefix;
-
- // Parsable node for which resolution is to be performed.
- private T entityToResolve;
-
- // Holder of the YANG construct for which resolution has to be carried out.
- private YangNode holderOfEntityToResolve;
+ /**
+ * Information about the entity that needs to be resolved.
+ */
+ private YangEntityToResolveInfo<T> entityToResolveInfo;
// Error Line number.
private int lineNumber;
@@ -40,24 +43,20 @@
// Error character position.
private int charPosition;
- // Status of resolution.
- private boolean isResolved;
-
/*
* Stack for type/uses is maintained for hierarchical references, this is
* used during resolution.
*/
- private Stack<T> partialResolvedStack;
-
- // Flag to indicate whether more references are detected.
- private boolean isMoreReferenceDetected;
+ private Stack<YangEntityToResolveInfo<T>> partialResolvedStack;
// Module/Sub-module prefix.
private String resolutionInfoRootNodePrefix;
/**
- * Create a resolution information object.
+ * It is private to ensure the overloaded method be invoked to create an
+ * object.
*/
+ @SuppressWarnings("unused")
private YangResolutionInfo() {
}
@@ -66,293 +65,268 @@
* Creates a resolution information object with all the inputs.
*
* @param dataNode current parsable data node
- * @param resolutionType type of resolution whether grouping/typedef
- * @param holderNode parent YANG node
- * @param prefix imported module prefix
- * @param lineNumber error line number
- * @param charPositionInLine error character position in line
- */
- public YangResolutionInfo(T dataNode, ResolutionType resolutionType,
- YangNode holderNode, String prefix, int lineNumber,
- int charPositionInLine) {
- this.setHolderOfEntityToResolve(holderNode);
- this.setEntityToResolve(dataNode);
- this.setPrefix(prefix);
- this.setLineNumber(lineNumber);
- this.setCharPosition(charPositionInLine);
- setPartialResolvedStack(new Stack<T>());
- }
-
- /**
- * Creates a resolution information object with all the inputs except prefix.
- *
- * @param dataNode current parsable data node
- * @param resolutionType type of resolution whether grouping/typedef
* @param holderNode parent YANG node
* @param lineNumber error line number
* @param charPositionInLine error character position in line
*/
- public YangResolutionInfo(T dataNode, ResolutionType resolutionType,
- YangNode holderNode, int lineNumber,
- int charPositionInLine) {
- this.setHolderOfEntityToResolve(holderNode);
- this.setEntityToResolve(dataNode);
+ 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
+ * @throws DataModelException DataModelException a violation of data model
+ * rules
*/
- public void resolveLinkingForResolutionInfo(String resolutionInfoNodePrefix) throws DataModelException {
+ 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 = getEntityToResolve();
+ T entityToResolve = getEntityToResolveInfo().getEntityToResolve();
// Check if linking is already done
if (entityToResolve instanceof Resolvable) {
Resolvable resolvable = (Resolvable) entityToResolve;
- if (resolvable.getResolvableStatus() == ResolvableStatus.RESOLVED ||
- resolvable.getResolvableStatus() == ResolvableStatus.PARTIALLY_RESOLVED) {
+ 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 YANG type to the stack.
- getPartialResolvedStack().push(entityToResolve);
+ // Push the initial entity to resolve in stack.
+ addInPartialResolvedStack(getEntityToResolveInfo());
- // Get holder of entity to resolve
- YangNode curNode = getHolderOfEntityToResolve();
-
- resolveLinkingWithAncestors(curNode);
+ linkAndResolvePartialResolvedStack();
}
/**
* Resolves linking with ancestors.
*
- * @param curNode current node for which ancestors to be checked
* @throws DataModelException a violation of data model rules
*/
- private void resolveLinkingWithAncestors(YangNode curNode) throws DataModelException {
+ private void linkAndResolvePartialResolvedStack()
+ throws DataModelException {
- while (curNode != null) {
- YangNode node = curNode.getChild();
- if (resolveLinkingForNodesChildAndSibling(node, curNode)) {
- return;
+ 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");
}
- curNode = curNode.getParent();
+
}
- // If curNode is null, it indicates an error condition in YANG file.
- 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;
+ }
+
+ /**
+ * Resolve the current entity in the stack.
+ */
+ private void resolveTopOfStack() {
+ ((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.
*
- * @param node current node
- * @param parentNode parent node of current node
- * @return flag to indicate whether resolution is done
- * @throws DataModelException
+ * @throws DataModelException data model error
*/
- private boolean resolveLinkingForNodesChildAndSibling(YangNode node, YangNode parentNode)
+ private void linkTopOfStackReferenceUpdateStack()
throws DataModelException {
- while ((node != null)) {
- isMoreReferenceDetected = false;
- // Check if node is of type, typedef or grouping
- if (isNodeOfResolveType(node)) {
- if (resolveLinkingForNode(node, parentNode)) {
- return true;
- }
- }
- if (isMoreReferenceDetected) {
- /*
- * If more reference are present, tree traversal must start from
- * first child again, to check the availability of
- * typedef/grouping.
- */
- node = parentNode.getChild();
- } else {
- node = node.getNextSibling();
- }
+
+ 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;
}
- return false;
- }
- /**
- * Resolves linking for a node.
- *
- * @param node current node
- * @param parentNode parent node of current node
- * @return flag to indicate whether resolution is done
- * @throws DataModelException a violation of data model rules
- */
- private boolean resolveLinkingForNode(YangNode node, YangNode parentNode) throws DataModelException {
-
- /*
- * Check if name of node name matches with the entity name under
- * resolution.
+ /**
+ * Try to resolve the top of the stack and update partial resolved stack
+ * if there is recursive references
*/
- if (isNodeNameSameAsResolutionInfoName(node)) {
- // Adds reference of entity to the node under resolution.
- addReferredEntityLink(node);
- // Check if referred entity has further reference to uses/type.
- if (!(isMoreReferencePresent(node))) {
- // Resolve all the entities in stack.
- resolveStackAndAddToStack(node);
- return true;
- } else {
- // Adds referred type/uses to the stack.
- addToPartialResolvedStack(node);
- /*
- * Check whether referred type is resolved, partially resolved
- * or unresolved.
+ 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
*/
- if (isReferenceFullyResolved()) {
- // Resolve the stack which is complete.
- resolveCompleteStack();
- return true;
- } else if (isReferencePartiallyResolved()) {
- /*
- * Update the resolution type to partially resolved for all
- * type/uses in stack
- */
- updateResolutionTypeToPartial();
- return true;
- } else {
- /*
- * Check if prefix is present to find that the derived
- * reference is for intra file or inter file, if it's
- * inter-file return and stop further processing.
- */
- if (isExternalPrefixPresent(node)) {
- /*
- * Update the resolution type to partially resolved for
- * all type/uses in stack
- */
- updateResolutionTypeToPartial();
- return true;
- } else {
- /*
- * If prefix is not present it indicates intra-file
- * dependency in this case set the node back to first
- * child, as referred entity may appear in any order and
- * continue with the resolution.
- */
- isMoreReferenceDetected = true;
- return false;
- }
- }
+ 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;
}
/**
- * Update resolution type to partial for all type/uses in stack.
+ * Check if the potential referred node is the actual referred node.
*
- * @throws DataModelException a violation of data model rules
- */
- private void updateResolutionTypeToPartial() throws DataModelException {
- // For all entries in stack calls for the resolution in type/uses.
- for (T entity : getPartialResolvedStack()) {
- if (!(entity instanceof Resolvable)) {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
- }
- if (((Resolvable) entity).getResolvableStatus() == ResolvableStatus.UNRESOLVED) {
- // Sets the resolution status in inside the type/uses.
- ((Resolvable) entity).setResolvableStatus(ResolvableStatus.PARTIALLY_RESOLVED);
- }
- }
- }
-
- /**
- * Adds referred type/uses to the stack and resolve the stack.
- *
- * @param node typedef/grouping node
- * @throws DataModelException a violation of data model rules
- */
- private void resolveStackAndAddToStack(YangNode node) throws DataModelException {
- if (getEntityToResolve() instanceof YangType) {
- // Adds to the stack only for YANG typedef.
- getPartialResolvedStack().push((T) ((YangTypeDef) node).getDataType());
- }
- // Don't add to stack in case of YANG grouping.
-
- // Resolve the complete stack.
- resolveCompleteStack();
- }
-
- /**
- * Check if the referred type/uses is partially resolved.
- *
- * @return true if reference is partially resolved, otherwise false
- */
- private boolean isReferencePartiallyResolved() {
- if (getPartialResolvedStack().peek() instanceof YangType) {
- /*
- * Checks if type is partially resolved.
- */
- if (((YangType) getPartialResolvedStack().peek())
- .getResolvableStatus() == ResolvableStatus.PARTIALLY_RESOLVED) {
- return true;
- }
- } else if (getPartialResolvedStack().peek() instanceof YangUses) {
- if (((YangUses) getPartialResolvedStack().peek())
- .getResolvableStatus() == ResolvableStatus.PARTIALLY_RESOLVED) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Check if the referred type/uses is resolved.
- *
- * @return true if reference is resolved, otherwise false
- */
- private boolean isReferenceFullyResolved() {
- if (getPartialResolvedStack().peek() instanceof YangType) {
- /*
- * Checks if type is partially resolved.
- */
- if (((YangType) getPartialResolvedStack().peek()).getResolvableStatus() == ResolvableStatus.RESOLVED) {
- return true;
- }
- } else if (getPartialResolvedStack().peek() instanceof YangUses) {
- if (((YangUses) getPartialResolvedStack().peek()).getResolvableStatus() == ResolvableStatus.RESOLVED) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Check if node is of resolve type i.e. of type typedef or grouping.
- *
- * @param node typedef/grouping 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 isNodeOfResolveType(YangNode node) throws DataModelException {
- if (getPartialResolvedStack().peek() instanceof YangType && entityToResolve instanceof YangType) {
- if (node instanceof YangTypeDef) {
- return true;
+ 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 (getPartialResolvedStack().peek() instanceof YangUses && entityToResolve instanceof YangUses) {
- if (node instanceof YangGrouping) {
- return true;
+ } 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");
@@ -369,13 +343,18 @@
* false
* @throws DataModelException a violation of data model rules
*/
- private boolean isNodeNameSameAsResolutionInfoName(YangNode node) throws DataModelException {
- if (getPartialResolvedStack().peek() instanceof YangType) {
- if (node.getName().equals(((YangType<?>) getPartialResolvedStack().peek()).getDataTypeName())) {
+
+ private boolean isNodeNameSameAsResolutionInfoName(YangNode node)
+ throws DataModelException {
+ if (getCurrentEntityToResolveFromStack() instanceof YangType) {
+ if (node.getName().contentEquals(
+ ((YangType<?>) getCurrentEntityToResolveFromStack())
+ .getDataTypeName())) {
return true;
}
- } else if (getPartialResolvedStack().peek() instanceof YangUses) {
- if (node.getName().equals(((YangUses) getPartialResolvedStack().peek()).getName())) {
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
+ if (node.getName().contentEquals(
+ ((YangUses) getCurrentEntityToResolveFromStack()).getName())) {
return true;
}
} else {
@@ -387,181 +366,91 @@
/**
* Adds reference of grouping/typedef in uses/type.
*
- * @param node grouping/typedef node
+ * @param referredNode grouping/typedef node being referred
* @throws DataModelException a violation of data model rules
*/
- private void addReferredEntityLink(YangNode node) throws DataModelException {
- if (getPartialResolvedStack().peek() instanceof YangType) {
- YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) ((YangType<?>) getPartialResolvedStack().peek())
- .getDataTypeExtendedInfo();
- derivedInfo.setReferredTypeDef((YangTypeDef) node);
- } else if (getPartialResolvedStack().peek() instanceof YangUses) {
- ((YangUses) getPartialResolvedStack().peek()).setRefGroup((YangGrouping) node);
+ 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");
}
}
/**
- * Checks if typedef/grouping has further reference to type/typedef.
+ * Return if there is any unresolved uses in grouping.
*
* @param node grouping/typedef node
- * @return true if referred entity is resolved, otherwise false
- * @throws DataModelException a violation of data model rules
*/
- private boolean isMoreReferencePresent(YangNode node) throws DataModelException {
- if (getEntityToResolve() instanceof YangType) {
- /*
- * Checks if typedef type is built-in type
- */
- if ((((YangTypeDef) node).getDataType().getDataType() != YangDataTypes.DERIVED)) {
- return false;
- }
- } else if (getEntityToResolve() instanceof YangUses) {
- /*
- * Search if the grouping has any uses child, if so return false,
- * else return true.
- */
- if (getUsesInGrouping(node) == null) {
- return false;
- }
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
- }
- return true;
- }
+ private void addUnResolvedUsesToStack(YangNode node) {
- /**
- * Return if there is any uses in grouping.
- *
- * @param node grouping/typedef node
- * @return if there is any uses in grouping, otherwise return null
- */
- private YangUses getUsesInGrouping(YangNode node) {
- YangNode curNode = ((YangGrouping) node).getChild();
+ /**
+ * Search the grouping node's children for presence of uses node.
+ */
+ YangNode curNode = node.getChild();
while (curNode != null) {
if (curNode instanceof YangUses) {
- break;
+ 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();
}
- return (YangUses) curNode;
- }
- /**
- * Resolve the complete stack.
- *
- * @throws DataModelException a violation of data model rules
- */
- private void resolveCompleteStack() throws DataModelException {
- // For all entries in stack calls for the resolution in type/uses.
- for (T entity : getPartialResolvedStack()) {
- if (!(entity instanceof Resolvable)) {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
- }
- ((Resolvable) entity).resolve();
- // Sets the resolution status in inside the type/uses.
- ((Resolvable) entity).setResolvableStatus(ResolvableStatus.RESOLVED);
- }
- /*
- * Sets the resolution status in resolution info present in resolution
- * list.
- */
- setIsResolved(true);
- }
-
- /**
- * Adds to partial resolved stack.
- *
- * @param node grouping/typedef node
- * @throws DataModelException a violation of data model rules
- */
- private void addToPartialResolvedStack(YangNode node) throws DataModelException {
- if (getPartialResolvedStack().peek() instanceof YangType) {
- // Adds to the stack only for YANG typedef.
- getPartialResolvedStack().push((T) ((YangTypeDef) node).getDataType());
- } else if (getPartialResolvedStack().peek() instanceof YangUses) {
- getPartialResolvedStack().push((T) getUsesInGrouping(node));
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
- }
- }
-
- /**
- * Check if prefix is associated with type/uses.
- *
- * @param node typedef/grouping node
- * @return true if prefix is present, otherwise false
- * @throws DataModelException a violation of data model rules
- */
- private boolean isExternalPrefixPresent(YangNode node) throws DataModelException {
- if (getEntityToResolve() instanceof YangType) {
- if (((YangTypeDef) node).getDataType().getPrefix() != null &&
- (!((YangTypeDef) node).getDataType().getPrefix().equals(resolutionInfoRootNodePrefix))) {
- return true;
- }
- } else if (getEntityToResolve() instanceof YangUses) {
- if (getUsesInGrouping(node).getPrefix() != null) {
- return true;
- }
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
- }
- return false;
- }
-
- /**
- * Returns prefix of imported module.
- *
- * @return prefix of imported module
- */
- public String getPrefix() {
- return prefix;
- }
-
- /**
- * Sets prefix of imported module.
- *
- * @param prefix of imported module
- */
- public void setPrefix(String prefix) {
- this.prefix = prefix;
- }
-
- /**
- * Returns parsable entity which is to be resolved.
- *
- * @return parsable entity which is to be resolved
- */
- public T getEntityToResolve() {
- return entityToResolve;
- }
-
- /**
- * Sets parsable entity to be resolved.
- *
- * @param entityToResolve YANG entity to be resolved
- */
- public void setEntityToResolve(T entityToResolve) {
- this.entityToResolve = entityToResolve;
- }
-
- /**
- * Returns parent YANG node holder for the entity to be resolved.
- *
- * @return parent YANG node holder
- */
- public YangNode getHolderOfEntityToResolve() {
- return holderOfEntityToResolve;
- }
-
- /**
- * Sets parent YANG node holder for the entity to be resolved.
- *
- * @param holderOfEntityToResolve parent YANG node holder
- */
- public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
- this.holderOfEntityToResolve = holderOfEntityToResolve;
+ return;
}
/**
@@ -601,29 +490,12 @@
}
/**
- * Returns status of resolution.
- *
- * @return resolution status
- */
- public boolean isResolved() {
- return isResolved;
- }
-
- /**
- * Sets status of resolution.
- *
- * @param isResolved resolution status
- */
- public void setIsResolved(boolean isResolved) {
- this.isResolved = isResolved;
- }
-
- /**
- * Returns stack of YANG type with partially resolved YANG construct hierarchy.
+ * Returns stack of YANG type with partially resolved YANG construct
+ * hierarchy.
*
* @return partial resolved YANG construct stack
*/
- public Stack<T> getPartialResolvedStack() {
+ private Stack<YangEntityToResolveInfo<T>> getPartialResolvedStack() {
return partialResolvedStack;
}
@@ -632,7 +504,45 @@
*
* @param partialResolvedStack partial resolved YANG construct stack
*/
- public void setPartialResolvedStack(Stack<T> partialResolvedStack) {
+ 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;
+ }
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java
index 15a6626..ce8b632 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java
@@ -104,9 +104,9 @@
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
- if (this.getName().equals(identifierName)) {
+ if (getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as rpc \""
- + this.getName() + "\"");
+ + getName() + "\"");
}
}
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 37d8a05..5b18fac 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
@@ -20,6 +20,8 @@
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
+import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED;
+
/*
* Reference:RFC 6020.
* The "type" statement takes as an argument a string that is the name
@@ -49,7 +51,8 @@
*
* @param <T> YANG data type info
*/
-public class YangType<T> implements Parsable, Resolvable {
+public class YangType<T>
+ implements Parsable, Resolvable {
/**
* YANG node identifier.
@@ -89,7 +92,7 @@
* Status of resolution. If completely resolved enum value is "RESOLVED",
* if not enum value is "UNRESOLVED", in case reference of grouping/typedef
* is added to uses/type but it's not resolved value of enum should be
- * "PARTIALLY_RESOLVED".
+ * "INTRA_FILE_RESOLVED".
*/
private ResolvableStatus resolvableStatus;
@@ -262,7 +265,8 @@
* @throws DataModelException a violation of data model rules
*/
@Override
- public void validateDataOnEntry() throws DataModelException {
+ public void validateDataOnEntry()
+ throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
@@ -273,7 +277,8 @@
* @throws DataModelException a violation of data model rules
*/
@Override
- public void validateDataOnExit() throws DataModelException {
+ public void validateDataOnExit()
+ throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
@@ -290,6 +295,20 @@
@Override
public void resolve() {
- //TODO: implement the method.
+ /*
+ Inherit the Restriction from the referred typedef definition.
+ */
+ if (getDataType() != YangDataTypes.DERIVED) {
+ throw new RuntimeException("Resolve should only be called for derrived data types");
+ }
+
+ YangDerivedInfo<?> derrivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo();
+ YangType<?> baseType = derrivedInfo.getReferredTypeDef().getTypeDefBaseType();
+ if (YangDataTypes.DERIVED == baseType.getDataType()) {
+ if (baseType.getResolvableStatus() == INTRA_FILE_RESOLVED) {
+ setResolvableStatus(INTRA_FILE_RESOLVED);
+ }
+ }
+ //TODO:
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
index 7b0204c..35998d4 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
@@ -179,7 +179,7 @@
*
* @return the data type
*/
- public YangType<?> getDataType() {
+ public YangType<?> getTypeDefBaseType() {
return dataType;
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
index 21aabc0..c75068c 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
@@ -16,13 +16,13 @@
package org.onosproject.yangutils.datamodel;
+import java.util.LinkedList;
+import java.util.List;
+
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
-import java.util.LinkedList;
-import java.util.List;
-
/*
* Reference RFC 6020.
*
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 c4025b6..22b9700 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
@@ -48,10 +48,13 @@
* | when | 7.19.5 | 0..1 | -TODO |
* +--------------+---------+-------------+------------------+
*/
+
/**
* Represents data model node to maintain information defined in YANG uses.
*/
-public class YangUses extends YangNode implements YangCommonInfo, Parsable, Resolvable {
+public class YangUses
+ extends YangNode
+ implements YangCommonInfo, Parsable, Resolvable {
/**
* YANG node identifier.
@@ -82,7 +85,7 @@
* Status of resolution. If completely resolved enum value is "RESOLVED",
* if not enum value is "UNRESOLVED", in case reference of grouping/typedef
* is added to uses/type but it's not resolved value of enum should be
- * "PARTIALLY_RESOLVED".
+ * "INTRA_FILE_RESOLVED".
*/
private ResolvableStatus resolvableStatus;
@@ -189,7 +192,8 @@
* @throws DataModelException a violation of data model rules
*/
@Override
- public void validateDataOnEntry() throws DataModelException {
+ public void validateDataOnEntry()
+ throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
@@ -199,7 +203,8 @@
* @throws DataModelException a violation of data model rules
*/
@Override
- public void validateDataOnExit() throws DataModelException {
+ public void validateDataOnExit()
+ throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
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 76e8f36..643eda5 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
@@ -20,6 +20,7 @@
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.HasResolutionInfo;
+import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
@@ -28,6 +29,7 @@
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.utils.YangConstructType;
+
/**
* Represents utilities for data model tree.
*/
@@ -43,7 +45,7 @@
* Detects the colliding identifier name in a given YANG node and its child.
*
* @param identifierName name for which collision detection is to be
- * checked
+ * 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
@@ -77,7 +79,7 @@
*
* @param leavesHolder leaves node against which collision to be checked
* @param identifierName name for which collision detection is to be
- * checked
+ * checked
* @throws DataModelException a violation of data model rules
*/
private static void detectCollidingLeaf(YangLeavesHolder leavesHolder, String identifierName)
@@ -96,7 +98,7 @@
*
* @param leavesHolder leaves node against which collision to be checked
* @param identifierName name for which collision detection is to be
- * checked
+ * checked
* @throws DataModelException a violation of data model rules
*/
private static void detectCollidingLeafList(YangLeavesHolder leavesHolder, String identifierName)
@@ -114,13 +116,17 @@
* 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) throws DataModelException {
+ public static void addResolutionInfo(YangResolutionInfo resolutionInfo)
+ throws DataModelException {
+
+
/* get the module node to add maintain the list of nested reference */
- YangNode curNode = resolutionInfo.getHolderOfEntityToResolve();
+ YangNode curNode = resolutionInfo.getEntityToResolveInfo()
+ .getHolderOfEntityToResolve();
while (!(curNode instanceof HasResolutionInfo)) {
curNode = curNode.getParent();
if (curNode == null) {
@@ -128,25 +134,58 @@
}
}
HasResolutionInfo resolutionNode = (HasResolutionInfo) curNode;
+
+ if (!isPrefixValid(resolutionInfo.getEntityToResolveInfo().getEntityPrefix(),
+ resolutionNode)) {
+ throw new DataModelException("The prefix used is not valid");
+ }
resolutionNode.addToResolutionList(resolutionInfo);
}
+ private static boolean isPrefixValid(String entityPrefix, HasResolutionInfo 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 resolutionInfoNode module/sub-module node
+ * @param dataModelRootNode module/sub-module node
* @throws DataModelException a violation of data model rules
*/
public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList,
- HasResolutionInfo resolutionInfoNode)
+ HasResolutionInfo dataModelRootNode)
throws DataModelException {
for (YangResolutionInfo resolutionInfo : resolutionList) {
- if (resolutionInfo.getPrefix() == null ||
- resolutionInfo.getPrefix().equals(resolutionInfoNode.getPrefix())) {
- resolutionInfo.resolveLinkingForResolutionInfo(resolutionInfoNode.getPrefix());
- }
+ resolutionInfo.resolveLinkingForResolutionInfo(dataModelRootNode.getPrefix());
}
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/YangDataModelFactory.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/YangDataModelFactory.java
index 6edd6a6..03d82d1 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/YangDataModelFactory.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/YangDataModelFactory.java
@@ -20,6 +20,7 @@
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangGrouping;
+import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangSubModule;
@@ -34,6 +35,7 @@
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
@@ -51,7 +53,7 @@
public final class YangDataModelFactory {
/**
- * Creates a YANG data model factory object.
+ * Utility class, hence private to prevent creating objects.
*/
private YangDataModelFactory() {
}
@@ -261,6 +263,23 @@
* generated
* @return the corresponding inherited node based on the target language
*/
+ public static YangLeaf getYangLeaf(GeneratedLanguage targetLanguage) {
+ switch (targetLanguage) {
+ case JAVA_GENERATION: {
+ return new YangJavaLeaf();
+ }
+ default: {
+ throw new RuntimeException("Only YANG to Java is supported.");
+ }
+ }
+ }
+ /**
+ * Returns based on the target language generate the inherited data model node.
+ *
+ * @param targetLanguage target language in which YANG mapping needs to be
+ * generated
+ * @return the corresponding inherited node based on the target language
+ */
public static YangRpc getYangRpcNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
case JAVA_GENERATION: {
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DescriptionListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DescriptionListener.java
index 32bd3aa..eddfa56 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DescriptionListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DescriptionListener.java
@@ -40,8 +40,9 @@
*/
/**
- * Represents listener based call back function corresponding to the "description"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ * Represents listener based call back function corresponding to the
+ * "description" rule defined in ANTLR grammar file for corresponding ABNF rule
+ * in RFC 6020.
*/
public final class DescriptionListener {
@@ -52,15 +53,14 @@
}
/**
- * It is called when parser receives an input matching the grammar
- * rule (description), perform validations and updates the data model
- * tree.
+ * It is called when parser receives an input matching the grammar rule
+ * (description), perform validations and updates the data model tree.
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processDescriptionEntry(TreeWalkListener listener,
- GeneratedYangParser.DescriptionStatementContext ctx) {
+ GeneratedYangParser.DescriptionStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, DESCRIPTION_DATA, ctx.string().getText(), ENTRY);
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/KeyListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/KeyListener.java
index 81223fd..9d215d2 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/KeyListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/KeyListener.java
@@ -45,8 +45,8 @@
*/
/**
- * Represesnts listener based call back function corresponding to the "key"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ * Represesnts listener based call back function corresponding to the "key" rule
+ * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class KeyListener {
@@ -57,15 +57,14 @@
}
/**
- * It is called when parser receives an input matching the grammar
- * rule (key), perform validations and updates the data model
- * tree.
+ * It is called when parser receives an input matching the grammar rule
+ * (key), perform validations and updates the data model tree.
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processKeyEntry(TreeWalkListener listener,
- GeneratedYangParser.KeyStatementContext ctx) {
+ GeneratedYangParser.KeyStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, KEY_DATA, ctx.key().getText(), ENTRY);
@@ -94,7 +93,7 @@
}
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, KEY_DATA, ctx.key().getText(),
- ENTRY));
+ ENTRY));
}
}
}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListener.java
index 738ffa9..b8e3b2d 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListener.java
@@ -27,10 +27,13 @@
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
+import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangLeaf;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
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;
+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;
@@ -108,7 +111,7 @@
int charPositionInLine = ctx.getStart().getCharPositionInLine();
detectCollidingChildUtil(listener, line, charPositionInLine, identifier, LEAF_DATA);
- YangLeaf leaf = new YangLeaf();
+ YangLeaf leaf = getYangLeaf(JAVA_GENERATION);
leaf.setLeafName(identifier);
Parsable tmpData = listener.getParsedDataStack().peek();
@@ -142,7 +145,7 @@
listener.getParsedDataStack().pop();
} else {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LEAF_DATA,
- ctx.identifier().getText(), EXIT));
+ ctx.identifier().getText(), EXIT));
}
}
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 b611d6e..416ce91 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
@@ -16,7 +16,6 @@
package org.onosproject.yangutils.parser.impl.listeners;
-import org.onosproject.yangutils.datamodel.ResolutionType;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangLeaf;
@@ -34,11 +33,14 @@
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.utils.YangConstructType;
+import static org.onosproject.yangutils.datamodel.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
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;
@@ -123,17 +125,15 @@
ctx.string().getText(), EXIT));
}
- // Get the prefix information
- String prefix = ((YangType<?>) type).getPrefix();
-
// Create empty derived info and attach it to type extended info.
YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
+ type.setResolvableStatus(UNRESOLVED);
+
// Add resolution information to the list
YangResolutionInfo resolutionInfo = new YangResolutionInfo<YangType>(type,
- ResolutionType.TYPEDEF_RESOLUTION, (YangNode) parentNodeOfLeaf, prefix, errorLine,
- errorPosition);
+ (YangNode) parentNodeOfLeaf, errorLine, errorPosition);
addToResolutionList(resolutionInfo, ctx);
}
break;
@@ -165,9 +165,9 @@
((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
// Add resolution information to the list
- YangResolutionInfo resolutionInfo = new YangResolutionInfo<YangType>(type,
- ResolutionType.TYPEDEF_RESOLUTION, (YangNode) parentNodeOfLeafList, prefix, errorLine,
- errorPosition);
+ YangResolutionInfo resolutionInfo =
+ new YangResolutionInfo<YangType>(type, (YangNode) parentNodeOfLeafList, errorLine,
+ errorPosition);
addToResolutionList(resolutionInfo, ctx);
}
break;
@@ -201,8 +201,8 @@
((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
// Add resolution information to the list
- YangResolutionInfo resolutionInfo = new YangResolutionInfo<YangType>(type,
- ResolutionType.TYPEDEF_RESOLUTION, (YangNode) typeDef, prefix, errorLine, errorPosition);
+ YangResolutionInfo resolutionInfo =
+ new YangResolutionInfo<YangType>(type, (YangNode) typeDef, errorLine, errorPosition);
addToResolutionList(resolutionInfo, ctx);
}
break;
@@ -244,7 +244,7 @@
* @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) {
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
index ffb50e9..150e0d1 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
@@ -205,7 +205,7 @@
Calendar date = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
- String dateForRevision = ((dateFormat.format(date.getTime())).replaceAll(SLASH, HYPHEN)).replaceAll(SPACE,
+ String dateForRevision = dateFormat.format(date.getTime()).replaceAll(SLASH, HYPHEN).replaceAll(SPACE,
EMPTY_STRING);
return dateForRevision;
}
@@ -218,8 +218,8 @@
* @param ctx yang construct's context to get the line number and character position
* @return valid node identifier
*/
- public static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString, YangConstructType
- yangConstruct, ParserRuleContext ctx) {
+ public static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString,
+ YangConstructType yangConstruct, ParserRuleContext ctx) {
String tmpIdentifierString = removeQuotesAndHandleConcat(nodeIdentifierString);
String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
if (tmpData.length == 1) {
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/HasJavaQualifiedTypeInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/HasJavaQualifiedTypeInfo.java
new file mode 100644
index 0000000..80b72cf
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/HasJavaQualifiedTypeInfo.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016 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.translator.tojava;
+
+/**
+ * Maintain the java qualified access details for an attribute or a class.
+ */
+public interface HasJavaQualifiedTypeInfo {
+
+ /**
+ * Obtain the java qualified details.
+ *
+ * @return java qualified type details
+ */
+ JavaQualifiedTypeInfo getJavaQualifiedInfo();
+
+ /**
+ * Assign the qualified type info.
+ *
+ * @param typeInfo qualified type information
+ */
+ void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo);
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
index 25ed389..f63a997 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
@@ -1055,7 +1055,7 @@
public void addTypeDefAttributeToTempFiles(YangNode curNode) throws IOException {
JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfTypeDef(curNode,
- ((YangTypeDef) curNode).getDataType(),
+ ((YangTypeDef) curNode).getTypeDefBaseType(),
((YangTypeDef) curNode).getName(), false);
addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeaf.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeaf.java
new file mode 100644
index 0000000..1ff57f4
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeaf.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2016 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.translator.tojava.javamodel;
+
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.translator.tojava.HasJavaQualifiedTypeInfo;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+
+/**
+ * Maintains java information corresponding to the YANG leaf.
+ */
+public class YangJavaLeaf extends YangLeaf
+ implements HasJavaQualifiedTypeInfo {
+
+ private JavaQualifiedTypeInfo javaQualifiedAccess;
+
+ /**
+ * Create a YANG leaf object with java qualified access details.
+ */
+ public YangJavaLeaf() {
+ super();
+ setJavaQualifiedInfo(new JavaQualifiedTypeInfo());
+ }
+
+ @Override
+ public JavaQualifiedTypeInfo getJavaQualifiedInfo() {
+ return javaQualifiedAccess;
+ }
+
+ @Override
+ public void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo) {
+ javaQualifiedAccess = typeInfo;
+
+ }
+
+}
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 eaf4076..52fb4ff 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
@@ -18,6 +18,7 @@
import java.io.IOException;
import java.util.ListIterator;
+
import org.junit.Test;
import org.onosproject.yangutils.datamodel.ResolvableStatus;
import org.onosproject.yangutils.datamodel.YangContainer;
@@ -46,7 +47,8 @@
* Checks self resolution when typedef and leaf using type are siblings.
*/
@Test
- public void processSelfResolutionWhenTypeAndTypedefAtRootLevel() throws IOException, ParserException {
+ public void processSelfResolutionWhenTypeAndTypedefAtRootLevel()
+ throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang");
@@ -79,7 +81,8 @@
* level where typedef is at the root.
*/
@Test
- public void processSelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy() throws IOException, ParserException {
+ public void processSelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy()
+ throws IOException, ParserException {
YangNode node =
manager.getDataModel("src/test/resources/SelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy.yang");
@@ -118,7 +121,8 @@
* of type.
*/
@Test
- public void processSelfFileLinkingTypedefAtRootIsAfterContainerHavingType() throws IOException, ParserException {
+ public void processSelfFileLinkingTypedefAtRootIsAfterContainerHavingType()
+ throws IOException, ParserException {
YangNode node =
manager.getDataModel("src/test/resources/SelfFileLinkingTypedefAtRootIsAfterContainerHavingType.yang");
@@ -157,7 +161,8 @@
* holder of type.
*/
@Test
- public void processSelfFileLinkingTypedefAtMiddleLevelAfterParentHolder() throws IOException, ParserException {
+ public void processSelfFileLinkingTypedefAtMiddleLevelAfterParentHolder()
+ throws IOException, ParserException {
YangNode node =
manager.getDataModel("src/test/resources/SelfFileLinkingTypedefAtMiddleLevelAfterParentHolder.yang");
@@ -194,7 +199,8 @@
* Checks self resolution when typedef hierarchical references are present.
*/
@Test
- public void processSelfFileLinkingWithTypdefHierarchicalReference() throws IOException, ParserException {
+ public void processSelfFileLinkingWithTypdefHierarchicalReference()
+ throws IOException, ParserException {
YangNode node =
manager.getDataModel("src/test/resources/SelfFileLinkingWithTypdefHierarchicalReference.yang");
@@ -227,16 +233,16 @@
YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
- assertThat(((YangDerivedInfo<?>) typeDef1.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangContainer.getChild().getNextSibling()));
- assertThat((typeDef1.getDataType().getResolvableStatus()),
+ assertThat((typeDef1.getTypeDefBaseType().getResolvableStatus()),
is(ResolvableStatus.RESOLVED));
YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
- assertThat(((YangDerivedInfo<?>) typeDef2.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((typeDef2.getDataType().getResolvableStatus()),
+ assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()),
is(ResolvableStatus.RESOLVED));
}
@@ -245,7 +251,8 @@
* with last type is unresolved.
*/
@Test
- public void processSelfFileLinkingWithTypdefHierarchicalRefUnresolved() throws IOException, ParserException {
+ public void processSelfFileLinkingWithTypdefHierarchicalRefUnresolved()
+ throws IOException, ParserException {
YangNode node =
manager.getDataModel("src/test/resources/SelfFileLinkingWithTypdefHierarchicalRefUnresolved.yang");
@@ -274,28 +281,29 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangList.getChild()));
assertThat((leafInfo.getDataType().getResolvableStatus()),
- is(ResolvableStatus.PARTIALLY_RESOLVED));
+ is(ResolvableStatus.INTRA_FILE_RESOLVED));
YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
- assertThat(((YangDerivedInfo<?>) typeDef1.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangContainer.getChild().getNextSibling()));
- assertThat((typeDef1.getDataType().getResolvableStatus()),
- is(ResolvableStatus.PARTIALLY_RESOLVED));
+ assertThat((typeDef1.getTypeDefBaseType().getResolvableStatus()),
+ is(ResolvableStatus.INTRA_FILE_RESOLVED));
YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
- assertThat(((YangDerivedInfo<?>) typeDef2.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((typeDef2.getDataType().getResolvableStatus()),
- is(ResolvableStatus.PARTIALLY_RESOLVED));
+ assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()),
+ is(ResolvableStatus.INTRA_FILE_RESOLVED));
}
/**
* Checks self resolution when type uses prefix of self module.
*/
@Test
- public void processSelfFileLinkingWithTypeWithSelfModulePrefix() throws IOException, ParserException {
+ public void processSelfFileLinkingWithTypeWithSelfModulePrefix()
+ throws IOException, ParserException {
YangNode node =
manager.getDataModel("src/test/resources/SelfFileLinkingWithTypeWithSelfModulePrefix.yang");
@@ -328,16 +336,16 @@
YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
- assertThat(((YangDerivedInfo<?>) typeDef1.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangContainer.getChild().getNextSibling()));
- assertThat((typeDef1.getDataType().getResolvableStatus()),
+ assertThat((typeDef1.getTypeDefBaseType().getResolvableStatus()),
is(ResolvableStatus.RESOLVED));
YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
- assertThat(((YangDerivedInfo<?>) typeDef2.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((typeDef2.getDataType().getResolvableStatus()),
+ assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()),
is(ResolvableStatus.RESOLVED));
}
@@ -346,7 +354,8 @@
* some uses external prefix.
*/
@Test
- public void processSelfFileLinkingWithTypeWithSelfAndExternalPrefixMix() throws IOException, ParserException {
+ public void processSelfFileLinkingWithTypeWithSelfAndExternalPrefixMix()
+ throws IOException, ParserException {
YangNode node =
manager.getDataModel("src/test/resources/SelfFileLinkingWithTypeWithSelfAndExternalPrefixMix.yang");
@@ -375,15 +384,15 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangList.getChild()));
assertThat((leafInfo.getDataType().getResolvableStatus()),
- is(ResolvableStatus.PARTIALLY_RESOLVED));
+ is(ResolvableStatus.INTRA_FILE_RESOLVED));
YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
- assertThat(((YangDerivedInfo<?>) typeDef2.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+ assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((typeDef2.getDataType().getResolvableStatus()),
+ assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()),
is(ResolvableStatus.RESOLVED));
}
@@ -392,7 +401,8 @@
* file.
*/
@Test(expected = ParserException.class)
- public void processSelfResolutionWhenTypeReferredTypedefNotDefined() throws IOException, ParserException {
+ public void processSelfResolutionWhenTypeReferredTypedefNotDefined()
+ throws IOException, ParserException {
YangNode node =
manager.getDataModel("src/test/resources/SelfResolutionWhenTypeReferredTypedefNotDefined.yang");
@@ -403,7 +413,8 @@
* level where typedef is is not an ancestor of type.
*/
@Test(expected = ParserException.class)
- public void processSelfFileLinkingTypedefNotFound() throws IOException, ParserException {
+ public void processSelfFileLinkingTypedefNotFound()
+ throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/SelfFileLinkingTypedefNotFound.yang");
}
@@ -412,7 +423,8 @@
* Checks hierarchical self resolution with self resolution failure scenario.
*/
@Test(expected = ParserException.class)
- public void processSelfFileLinkingWithHierarchicalTypeFailureScenario() throws IOException, ParserException {
+ public void processSelfFileLinkingWithHierarchicalTypeFailureScenario()
+ throws IOException, ParserException {
YangNode node =
manager.getDataModel("src/test/resources/SelfFileLinkingWithHierarchicalTypeFailureScenario.yang");
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/InputListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/InputListenerTest.java
index 7ec10cf..95c402a 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/InputListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/InputListenerTest.java
@@ -106,6 +106,6 @@
YangTypeDef typeDef = (YangTypeDef) yangInput.getChild();
assertThat(typeDef.getName(), is("my-type"));
assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
- assertThat(typeDef.getDataType().getDataType(), is(YangDataTypes.INT32));
+ assertThat(typeDef.getTypeDefBaseType().getDataType(), is(YangDataTypes.INT32));
}
}
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 e5e647a..a8f494b 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
@@ -128,7 +128,7 @@
assertThat(yangNode.getName(), is("Test"));
YangTypeDef typedef = (YangTypeDef) yangNode.getChild();
- YangStringRestriction stringRestriction = (YangStringRestriction) typedef.getDataType()
+ YangStringRestriction stringRestriction = (YangStringRestriction) typedef.getTypeDefBaseType()
.getDataTypeExtendedInfo();
YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction();
@@ -234,4 +234,4 @@
" 18446744073709551615.");
YangNode node = manager.getDataModel("src/test/resources/LengthWithInvalidInterval.yang");
}
-}
\ No newline at end of file
+}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/OutputListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/OutputListenerTest.java
index f6a5437..ded5c49 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/OutputListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/OutputListenerTest.java
@@ -108,6 +108,6 @@
assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
assertThat(typeDef.getName(), is("my-type"));
assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
- assertThat(typeDef.getDataType().getDataType(), is(YangDataTypes.INT32));
+ assertThat(typeDef.getTypeDefBaseType().getDataType(), is(YangDataTypes.INT32));
}
-}
\ No newline at end of file
+}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java
index ffd8470..fb0ec72 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java
@@ -108,7 +108,7 @@
assertThat(yangNode.getName(), is("Test"));
YangTypeDef typedef = (YangTypeDef) yangNode.getChild();
- YangStringRestriction stringRestriction = (YangStringRestriction) typedef.getDataType()
+ YangStringRestriction stringRestriction = (YangStringRestriction) typedef.getTypeDefBaseType()
.getDataTypeExtendedInfo();
YangPatternRestriction yangPatternRestriction = stringRestriction.getPatternRestriction();
@@ -166,4 +166,4 @@
.getPatternList().listIterator();
assertThat(patternListIterator.next(), is("-[0-9]+|[0-9]+"));
}
-}
\ No newline at end of file
+}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RpcListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RpcListenerTest.java
index adb88dc..3af045d 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RpcListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RpcListenerTest.java
@@ -61,6 +61,6 @@
YangTypeDef typeDef = (YangTypeDef) yangRpc.getChild();
assertThat(typeDef.getName(), is("my-type"));
assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
- assertThat(typeDef.getDataType().getDataType(), is(YangDataTypes.INT32));
+ assertThat(typeDef.getTypeDefBaseType().getDataType(), is(YangDataTypes.INT32));
}
}
diff --git a/utils/yangutils/src/test/resources/DerivedTypeStatement.yang b/utils/yangutils/src/test/resources/DerivedTypeStatement.yang
index 952b7d4..afbfd1d 100644
--- a/utils/yangutils/src/test/resources/DerivedTypeStatement.yang
+++ b/utils/yangutils/src/test/resources/DerivedTypeStatement.yang
@@ -2,6 +2,9 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
leaf invalid-interval {
type P:hello;
}
diff --git a/utils/yangutils/src/test/resources/DuplicateGroupingInList.yang b/utils/yangutils/src/test/resources/DuplicateGroupingInList.yang
index 2457cbe..a9d1b3b 100644
--- a/utils/yangutils/src/test/resources/DuplicateGroupingInList.yang
+++ b/utils/yangutils/src/test/resources/DuplicateGroupingInList.yang
@@ -2,6 +2,9 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
list valid {
key address;
grouping endpoint {
diff --git a/utils/yangutils/src/test/resources/DuplicateGroupingInModule.yang b/utils/yangutils/src/test/resources/DuplicateGroupingInModule.yang
index d18b166..ec01781 100644
--- a/utils/yangutils/src/test/resources/DuplicateGroupingInModule.yang
+++ b/utils/yangutils/src/test/resources/DuplicateGroupingInModule.yang
@@ -2,20 +2,23 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
grouping endpoint {
leaf address {
- type ip-address;
+ type P:ip-address;
}
leaf port {
- type port-number;
+ type P:port-number;
}
}
grouping endpoint {
leaf address {
- type ip-address;
+ type P:pip-address;
}
leaf port {
- type port-number;
+ type P:port-number;
}
}
}
diff --git a/utils/yangutils/src/test/resources/GroupingAttributes.yang b/utils/yangutils/src/test/resources/GroupingAttributes.yang
index 977adc5..f04641f 100644
--- a/utils/yangutils/src/test/resources/GroupingAttributes.yang
+++ b/utils/yangutils/src/test/resources/GroupingAttributes.yang
@@ -2,6 +2,9 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
list valid {
key address;
leaf address {
diff --git a/utils/yangutils/src/test/resources/GroupingInContainer.yang b/utils/yangutils/src/test/resources/GroupingInContainer.yang
index 7c51913..dfa8259 100644
--- a/utils/yangutils/src/test/resources/GroupingInContainer.yang
+++ b/utils/yangutils/src/test/resources/GroupingInContainer.yang
@@ -2,6 +2,9 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
container valid {
grouping endpoint {
leaf address {
diff --git a/utils/yangutils/src/test/resources/GroupingInList.yang b/utils/yangutils/src/test/resources/GroupingInList.yang
index a8fad09..c5966fc 100644
--- a/utils/yangutils/src/test/resources/GroupingInList.yang
+++ b/utils/yangutils/src/test/resources/GroupingInList.yang
@@ -2,6 +2,9 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
list valid {
key address;
leaf address {
diff --git a/utils/yangutils/src/test/resources/GroupingInModule.yang b/utils/yangutils/src/test/resources/GroupingInModule.yang
index 7d513a4..77fef1f 100644
--- a/utils/yangutils/src/test/resources/GroupingInModule.yang
+++ b/utils/yangutils/src/test/resources/GroupingInModule.yang
@@ -2,6 +2,9 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
grouping endpoint {
leaf address {
type P:ip-address;
diff --git a/utils/yangutils/src/test/resources/SelfFileLinkingWithTypdefHierarchicalRefUnresolved.yang b/utils/yangutils/src/test/resources/SelfFileLinkingWithTypdefHierarchicalRefUnresolved.yang
index 35c28b6..a3e4379 100644
--- a/utils/yangutils/src/test/resources/SelfFileLinkingWithTypdefHierarchicalRefUnresolved.yang
+++ b/utils/yangutils/src/test/resources/SelfFileLinkingWithTypdefHierarchicalRefUnresolved.yang
@@ -2,6 +2,9 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
typedef Percentage {
type P:Per;
}
diff --git a/utils/yangutils/src/test/resources/SelfFileLinkingWithTypeWithSelfAndExternalPrefixMix.yang b/utils/yangutils/src/test/resources/SelfFileLinkingWithTypeWithSelfAndExternalPrefixMix.yang
index 038c7de..d5f346e 100644
--- a/utils/yangutils/src/test/resources/SelfFileLinkingWithTypeWithSelfAndExternalPrefixMix.yang
+++ b/utils/yangutils/src/test/resources/SelfFileLinkingWithTypeWithSelfAndExternalPrefixMix.yang
@@ -2,6 +2,9 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
typedef Percentage {
type int32;
}
diff --git a/utils/yangutils/src/test/resources/UsesInList.yang b/utils/yangutils/src/test/resources/UsesInList.yang
index c4fd47d..b79e7b1 100644
--- a/utils/yangutils/src/test/resources/UsesInList.yang
+++ b/utils/yangutils/src/test/resources/UsesInList.yang
@@ -2,6 +2,9 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
+ import ietf-yang-types {
+ prefix "P";
+ }
list valid {
key address;
leaf address {
diff --git a/utils/yangutils/src/test/resources/ValidAugmentStatement.yang b/utils/yangutils/src/test/resources/ValidAugmentStatement.yang
index 59ebe67..6175c35 100644
--- a/utils/yangutils/src/test/resources/ValidAugmentStatement.yang
+++ b/utils/yangutils/src/test/resources/ValidAugmentStatement.yang
@@ -6,6 +6,9 @@
import interface-module {
prefix "if";
}
+ import ietf-yang-types {
+ prefix "P";
+ }
augment "/if:interfaces/if:ifEntry" {
when "if:ifType='ds0'";
leaf ds0ChannelNumber {
diff --git a/utils/yangutils/src/test/resources/ValidNotificationStatement.yang b/utils/yangutils/src/test/resources/ValidNotificationStatement.yang
index d588bb9..072df23 100644
--- a/utils/yangutils/src/test/resources/ValidNotificationStatement.yang
+++ b/utils/yangutils/src/test/resources/ValidNotificationStatement.yang
@@ -2,6 +2,9 @@
namespace "http://example.net/rock";
prefix "rock";
+ import ietf-yang-types {
+ prefix "P";
+ }
notification link-failure {
description "A link failure has been detected";
status deprecated;