[ONOS-4636]YANG Grouping linking bug fix + YANG Code review comment fix
Change-Id: I68ee8dd08266a02593e217cef1a9bb010037d673
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java b/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
index adac640..bd160d1 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
@@ -79,7 +79,8 @@
/**
* Representation of data model node to maintain information defined in YANG augment.
*/
-public class YangAugment extends YangNode
+public class YangAugment
+ extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
/**
@@ -163,13 +164,15 @@
}
@Override
- public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
// Detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
- public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
if (this.getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as input \""
+ this.getName() + "\"");
@@ -191,7 +194,8 @@
*
* @param leafsList the list of leaf to set
*/
- private void setListOfLeaf(List<YangLeaf> leafsList) {
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
@@ -224,7 +228,8 @@
*
* @param listOfLeafList the list of leaf-list to set
*/
- private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
@@ -298,7 +303,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
}
@@ -308,7 +314,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/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java b/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
index 6787dc9..abe4b1a 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
@@ -88,10 +88,12 @@
* | when | 7.19.5 | 0..1 |-TODO |
* +--------------+---------+-------------+------------------+
*/
+
/**
* Represents data model node to maintain information defined in YANG case.
*/
-public class YangCase extends YangNode
+public class YangCase
+ extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
@@ -188,7 +190,8 @@
*
* @param leafsList the list of leaf to set
*/
- private void setListOfLeaf(List<YangLeaf> leafsList) {
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
@@ -221,7 +224,8 @@
*
* @param listOfLeafList the list of leaf-list to set
*/
- private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
@@ -295,7 +299,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
}
@@ -305,12 +310,14 @@
* @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
}
@Override
- public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
if (!(getParent() instanceof YangChoice)) {
throw new DataModelException("Internal Data Model Tree Error: Invalid/Missing holder in case " +
getName());
@@ -320,7 +327,8 @@
}
@Override
- public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
if (dataType == CASE_DATA) {
if (getName().equals(identifierName)) {
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java b/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
index 3930433..ccb824b 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
@@ -87,7 +87,8 @@
/**
* Represents data model node to maintain information defined in YANG container.
*/
-public class YangContainer extends YangNode
+public class YangContainer
+ extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
@@ -211,7 +212,8 @@
*
* @param leafsList the list of leaf to set
*/
- private void setListOfLeaf(List<YangLeaf> leafsList) {
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
@@ -245,7 +247,8 @@
*
* @param listOfLeafList the list of leaf-list to set
*/
- private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
@@ -338,7 +341,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
}
@@ -348,7 +352,8 @@
* @throws DataModelException a violation of data model rules
*/
@Override
- public void validateDataOnExit() throws DataModelException {
+ public void validateDataOnExit()
+ throws DataModelException {
List<YangLeaf> leaves = getListOfLeaf();
List<YangLeafList> leafLists = getListOfLeafList();
@@ -397,7 +402,8 @@
* @param leafLists list of leaf-list attributes of container
* @throws DataModelException a violation of data model rules
*/
- private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists) throws DataModelException {
+ private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists)
+ throws DataModelException {
/*
* If a node has "config" set to "false", no node underneath it can have
@@ -423,13 +429,15 @@
}
@Override
- public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
- public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
if (getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as container \""
+ getName() + "\"");
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java b/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
index 613237a..3cfdc38 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
@@ -17,7 +17,8 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.linker.impl.ResolvableStatus;
+import org.onosproject.yangutils.linker.ResolvableStatus;
+
import com.google.common.base.Strings;
import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
@@ -30,8 +31,8 @@
import static org.onosproject.yangutils.datamodel.YangDataTypes.LEAFREF;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.YangDataTypes.UNION;
-import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_RESOLVED;
-import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
+import static org.onosproject.yangutils.linker.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yangutils.linker.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.utils.RestrictionResolver.isOfRangeRestrictedType;
import static org.onosproject.yangutils.utils.RestrictionResolver.processLengthRestriction;
import static org.onosproject.yangutils.utils.RestrictionResolver.processRangeRestriction;
@@ -41,7 +42,8 @@
*
* @param <T> extended information.
*/
-public class YangDerivedInfo<T> implements LocationInfo {
+public class YangDerivedInfo<T>
+ implements LocationInfo, Cloneable {
/**
* YANG typedef reference.
@@ -224,8 +226,11 @@
* @return resolution status
* @throws DataModelException a violation in data mode rule
*/
- public ResolvableStatus resolve() throws DataModelException {
+ public ResolvableStatus resolve()
+ throws DataModelException {
+
YangType<?> baseType = getReferredTypeDef().getTypeDefBaseType();
+
/*
* Checks the data type of the referred typedef, if it's derived,
* obtain effective built-in type and restrictions from it's derived
@@ -238,6 +243,7 @@
if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) {
throw new DataModelException("Linker Error: Referred typedef is not resolved for type.");
}
+
/*
* Check if the referred typedef is intra file resolved, if yes sets
* current status also to intra file resolved .
@@ -401,6 +407,7 @@
}
}
}
+
/*
* Check if the data type is the one which can't be restricted, in
* this case check whether no self restrictions should be present.
@@ -414,6 +421,7 @@
throw new DataModelException("YANG file error: Restrictions can't be applied to a given type");
}
}
+
// Throw exception for unsupported types
throw new DataModelException("Linker error: Unable to process the derived type.");
}
@@ -424,7 +432,8 @@
* @param refStringRestriction referred string restriction of typedef
* @throws DataModelException a violation in data model rule
*/
- private void resolveStringRestriction(YangStringRestriction refStringRestriction) throws DataModelException {
+ private void resolveStringRestriction(YangStringRestriction refStringRestriction)
+ throws DataModelException {
YangStringRestriction curStringRestriction = null;
YangRangeRestriction refRangeRestriction = null;
YangPatternRestriction refPatternRestriction = null;
@@ -522,7 +531,8 @@
* @return resolved length restriction
* @throws DataModelException a violation in data model rule
*/
- private YangRangeRestriction resolveLengthRestriction(YangRangeRestriction refLengthRestriction) throws
+ private YangRangeRestriction resolveLengthRestriction(YangRangeRestriction refLengthRestriction)
+ throws
DataModelException {
/*
@@ -572,7 +582,8 @@
* @param curRestriction self restriction
*/
private void resolveLengthAndRangeRestriction(YangRangeRestriction refRestriction,
- YangRangeRestriction curRestriction) throws DataModelException {
+ YangRangeRestriction curRestriction)
+ throws DataModelException {
for (Object curInterval : curRestriction.getAscendingRangeIntervals()) {
if (!(curInterval instanceof YangRangeInterval)) {
throw new DataModelException("Linker error: Current range intervals not processed correctly.");
@@ -594,7 +605,8 @@
* @param refRangeRestriction referred range restriction of typedef
* @throws DataModelException a violation in data model rule
*/
- private void resolveRangeRestriction(YangRangeRestriction refRangeRestriction) throws DataModelException {
+ private void resolveRangeRestriction(YangRangeRestriction refRangeRestriction)
+ throws DataModelException {
/*
* Check that string restriction should be null when built-in type is
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java b/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
index 9bf924a..38b8266 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
@@ -31,7 +31,9 @@
/**
* Represents the enumeration data type information.
*/
-public class YangEnumeration extends YangNode implements Parsable, CollisionDetector {
+public class YangEnumeration
+ extends YangNode
+ implements Parsable, CollisionDetector {
// Enumeration info set.
private SortedSet<YangEnum> enumSet;
@@ -71,7 +73,8 @@
* @param enumInfo the ENUM information to be added
* @throws DataModelException due to violation in data model rules
*/
- public void addEnumInfo(YangEnum enumInfo) throws DataModelException {
+ public void addEnumInfo(YangEnum enumInfo)
+ throws DataModelException {
if (!getEnumSet().add(enumInfo)) {
throw new DataModelException("YANG ENUM already exists");
}
@@ -113,7 +116,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,21 +127,24 @@
* @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
}
@Override
- public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
/*
- Do nothing.The implementation for this is not required.
+ Do nothing, since it is not part of the schema tree, it is only type of an existing node in schema tree.
*/
}
@Override
- public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
/*
- Do nothing.The implementation for this is not required.
+ Do nothing, since it is not part of the schema tree, it is only type of an existing node in schema tree.
*/
}
}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangGrouping.java b/src/main/java/org/onosproject/yangutils/datamodel/YangGrouping.java
index 47abdca..68f7587 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangGrouping.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangGrouping.java
@@ -77,7 +77,8 @@
/**
* Represents data model node to maintain information defined in YANG grouping.
*/
-public class YangGrouping extends YangNode
+public class YangGrouping
+ extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
/**
@@ -174,7 +175,8 @@
*
* @param leafsList the list of leaf to set
*/
- private void setListOfLeaf(List<YangLeaf> leafsList) {
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
@@ -203,7 +205,8 @@
*
* @param listOfLeafList the list of leaf-list to set
*/
- private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
@@ -273,7 +276,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
}
@@ -283,7 +287,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
}
@@ -299,13 +304,15 @@
* module.
*/
@Override
- public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
- public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
if (getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as grouping \"" +
getName() + "\"");
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java b/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
index 4d7f2df..8aceaa4 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
@@ -68,7 +68,8 @@
/**
* Represents data model node to maintain information defined in YANG input.
*/
-public class YangInput extends YangNode
+public class YangInput
+ extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
/**
@@ -96,13 +97,15 @@
}
@Override
- public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
// Detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
- public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
if (this.getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as input \""
+ this.getName() + "\"");
@@ -115,12 +118,14 @@
}
@Override
- public void validateDataOnEntry() throws DataModelException {
+ public void validateDataOnEntry()
+ throws DataModelException {
//TODO: implement the method.
}
@Override
- public void validateDataOnExit() throws DataModelException {
+ public void validateDataOnExit()
+ throws DataModelException {
//TODO: implement the method.
}
@@ -130,6 +135,12 @@
}
@Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+
+ @Override
public void addLeaf(YangLeaf leaf) {
getListOfLeaf().add(leaf);
}
@@ -140,6 +151,11 @@
}
@Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ @Override
public void addLeafList(YangLeafList leafList) {
getListOfLeafList().add(leafList);
}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java b/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
index f59cdcc..9adeff7 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
@@ -58,7 +58,7 @@
* Represents leaf data represented in YANG.
*/
public class YangLeaf
- implements YangCommonInfo, Parsable {
+ implements YangCommonInfo, Parsable, Cloneable {
/**
* Name of leaf.
@@ -107,6 +107,11 @@
private String defaultValueInString;
/**
+ * YANG Node in which the leaf is contained.
+ */
+ YangLeavesHolder containedIn;
+
+ /**
* Creates a YANG leaf.
*/
public YangLeaf() {
@@ -281,6 +286,30 @@
}
/**
+ * Retrieves the YANG node in which the leaf is defined.
+ *
+ * @return the YANG node in which the leaf is defined
+ */
+ public YangLeavesHolder getContainedIn() {
+ return containedIn;
+ }
+
+ /**
+ * Assigns the YANG node in which the leaf is defined.
+ *
+ * @param containedIn the YANG node in which the leaf is defined
+ */
+ public void setContainedIn(YangLeavesHolder containedIn) {
+ this.containedIn = containedIn;
+ }
+
+ @Override
+ public YangLeaf clone()
+ throws CloneNotSupportedException {
+ return (YangLeaf) super.clone();
+ }
+
+ /**
* Returns the type of the parsed data.
*
* @return returns LEAF_DATA
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java b/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java
index 0e0bc3e..5794420 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java
@@ -54,7 +54,7 @@
* Represents leaf-list data represented in YANG.
*/
public class YangLeafList
- implements YangCommonInfo, Parsable {
+ implements YangCommonInfo, Parsable, Cloneable {
/**
* Name of leaf-list.
@@ -124,6 +124,11 @@
private YangType<?> dataType;
/**
+ * YANG Node in which the leaf is contained.
+ */
+ YangLeavesHolder containedIn;
+
+ /**
* Creates a YANG leaf-list.
*/
public YangLeafList() {
@@ -298,6 +303,30 @@
}
/**
+ * Retrieves the YANG node in which the leaf is defined.
+ *
+ * @return the YANG node in which the leaf is defined
+ */
+ public YangLeavesHolder getContainedIn() {
+ return containedIn;
+ }
+
+ /**
+ * Assigns the YANG node in which the leaf is defined.
+ *
+ * @param containedIn the YANG node in which the leaf is defined
+ */
+ public void setContainedIn(YangLeavesHolder containedIn) {
+ this.containedIn = containedIn;
+ }
+
+ @Override
+ public YangLeafList clone()
+ throws CloneNotSupportedException {
+ return (YangLeafList) super.clone();
+ }
+
+ /**
* Returns the type of the parsed data.
*
* @return returns LEAF_LIST_DATA
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangLeavesHolder.java b/src/main/java/org/onosproject/yangutils/datamodel/YangLeavesHolder.java
index 37ecc8f..a21ed34 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangLeavesHolder.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangLeavesHolder.java
@@ -33,6 +33,13 @@
List<YangLeaf> getListOfLeaf();
/**
+ * Sets the list of leaves.
+ *
+ * @param leafsList the list of leaf to set
+ */
+ void setListOfLeaf(List<YangLeaf> leafsList);
+
+ /**
* Adds leaf in data holder like container / list.
*
* @param leaf the leaf to be added
@@ -47,6 +54,13 @@
List<YangLeafList> getListOfLeafList();
/**
+ * Sets the list of leaf-list.
+ *
+ * @param listOfLeafList the list of leaf-list to set
+ */
+ void setListOfLeafList(List<YangLeafList> listOfLeafList);
+
+ /**
* Adds leaf-list in data holder like container / list.
*
* @param leafList the leaf-list to be added
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangList.java b/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
index cd45bdc..834a0ad 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
@@ -67,7 +67,8 @@
/**
* Represents list data represented in YANG.
*/
-public class YangList extends YangNode
+public class YangList
+ extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
@@ -254,7 +255,8 @@
* @param key key field name.
* @throws DataModelException a violation of data model rules
*/
- public void addKey(String key) throws DataModelException {
+ public void addKey(String key)
+ throws DataModelException {
if (getKeyList() == null) {
setKeyList(new LinkedList<String>());
}
@@ -282,7 +284,8 @@
*
* @param leafsList the list of leaf to set
*/
- private void setListOfLeaf(List<YangLeaf> leafsList) {
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
@@ -315,7 +318,8 @@
*
* @param listOfLeafList the list of leaf-list to set
*/
- private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
@@ -425,7 +429,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
}
@@ -435,7 +440,8 @@
* @throws DataModelException a violation of data model rules
*/
@Override
- public void validateDataOnExit() throws DataModelException {
+ public void validateDataOnExit()
+ throws DataModelException {
List<String> keys = getKeyList();
List<YangLeaf> leaves = getListOfLeaf();
List<YangLeafList> leafLists = getListOfLeafList();
@@ -493,7 +499,8 @@
* @param leafLists list of leaf-list attributes of YANG list
* @throws DataModelException a violation of data model rules
*/
- private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists) throws DataModelException {
+ private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists)
+ throws DataModelException {
/*
* If a node has "config" set to "false", no node underneath it can have
@@ -526,7 +533,8 @@
* @param keys list of key attributes of list
* @throws DataModelException a violation of data model rules
*/
- private void validateKey(List<YangLeaf> leaves, List<YangLeafList> leafLists, List<String> keys) throws
+ private void validateKey(List<YangLeaf> leaves, List<YangLeafList> leafLists, List<String> keys)
+ throws
DataModelException {
boolean leafFound = false;
List<YangLeaf> keyLeaves = new LinkedList<>();
@@ -595,13 +603,15 @@
}
@Override
- public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
- public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
if (getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as list \"" +
getName() + "\"");
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java b/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
index 26df1f5..11b089d 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
@@ -19,9 +19,11 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
-import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
+import org.onosproject.yangutils.linker.ResolvableType;
+import org.onosproject.yangutils.linker.YangReferenceResolver;
import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
@@ -74,7 +76,8 @@
/**
* Represents data model node to maintain information defined in YANG module.
*/
-public class YangModule extends YangNode
+public class YangModule
+ extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
RpcNotificationContainer {
@@ -85,7 +88,7 @@
/**
* Reference:RFC 6020.
- * <p>
+ *
* The "contact" statement provides contact information for the module. The
* argument is a string that is used to specify contact information for the
* person or persons to whom technical queries concerning this module should
@@ -96,7 +99,7 @@
/**
* Reference:RFC 6020.
- * <p>
+ *
* The "description" statement takes as an argument a string that contains a
* human-readable textual description of this definition. The text is
* provided in a language (or languages) chosen by the module developer; for
@@ -131,7 +134,7 @@
/**
* Reference:RFC 6020.
- * <p>
+ *
* The "organization" statement defines the party responsible for this
* module. The argument is a string that is used to specify a textual
* description of the organization(s) under whose auspices this module was
@@ -193,7 +196,12 @@
* matching "typedef" or "grouping" statement among the immediate
* sub-statements of each ancestor statement.
*/
- private List<YangResolutionInfo> unresolvedResolutionList;
+ private List<YangResolutionInfo> derivedTypeResolutionList;
+
+ /**
+ * uses resolution list.
+ */
+ private List<YangResolutionInfo> usesResolutionList;
/**
* Creates a YANG node of module type.
@@ -201,7 +209,8 @@
public YangModule() {
super(YangNodeType.MODULE_NODE);
- unresolvedResolutionList = new LinkedList<YangResolutionInfo>();
+ derivedTypeResolutionList = new LinkedList<YangResolutionInfo>();
+ usesResolutionList = new LinkedList<YangResolutionInfo>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
@@ -326,6 +335,11 @@
return listOfLeaf;
}
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
/**
* Adds a leaf in module.
*
@@ -346,6 +360,12 @@
return listOfLeafList;
}
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+
/**
* Adds a leaf-list in module.
*
@@ -413,17 +433,19 @@
}
@Override
- public void resolveSelfFileLinking() throws DataModelException {
+ public void resolveSelfFileLinking(ResolvableType type)
+ throws DataModelException {
// Get the list to be resolved.
- List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
+ List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
// Resolve linking for a resolution list.
resolveLinkingForResolutionList(resolutionList, this);
}
@Override
- public void resolveInterFileLinking() throws DataModelException {
+ public void resolveInterFileLinking(ResolvableType type)
+ throws DataModelException {
// Get the list to be resolved.
- List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
+ List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
// Resolve linking for a resolution list.
linkInterFileReferences(resolutionList, this);
}
@@ -500,7 +522,8 @@
* @throws DataModelException a violation of data model rules
*/
@Override
- public void validateDataOnEntry() throws DataModelException {
+ public void validateDataOnEntry()
+ throws DataModelException {
/*
* Module is root in the data model tree, hence there is no entry
* validation
@@ -513,7 +536,8 @@
* @throws DataModelException a violation of data model rules
*/
@Override
- public void validateDataOnExit() throws DataModelException {
+ public void validateDataOnExit()
+ throws DataModelException {
/*
* TODO: perform symbol linking for the imported or included YANG info.
* TODO: perform symbol resolution for referred YANG entities.
@@ -521,29 +545,47 @@
}
@Override
- public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
- public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
// Not required as module doesn't have any parent.
}
@Override
- public List<YangResolutionInfo> getUnresolvedResolutionList() {
- return unresolvedResolutionList;
+ public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
+ if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
+ return derivedTypeResolutionList;
+ } else {
+ return usesResolutionList;
+ }
+
}
@Override
- public void addToResolutionList(YangResolutionInfo resolutionInfo) {
- unresolvedResolutionList.add(resolutionInfo);
+ public void addToResolutionList(YangResolutionInfo resolutionInfo,
+ ResolvableType type) {
+ if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
+ derivedTypeResolutionList.add(resolutionInfo);
+ } else if (type == ResolvableType.YANG_USES) {
+ usesResolutionList.add(resolutionInfo);
+ }
}
@Override
- public void setResolutionList(List<YangResolutionInfo> resolutionList) {
- unresolvedResolutionList = resolutionList;
+ public void setResolutionList(List<YangResolutionInfo> resolutionList,
+ ResolvableType type) {
+ if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
+ derivedTypeResolutionList = resolutionList;
+ } else if (type == ResolvableType.YANG_USES) {
+ usesResolutionList = resolutionList;
+ }
+
}
@Override
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java b/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
index 811c76e..f9d5b26 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
@@ -16,12 +16,6 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.parser.Parsable;
-import org.onosproject.yangutils.translator.tojava.TraversalType;
-
-import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD;
-import static org.onosproject.yangutils.translator.tojava.TraversalType.PARENT;
-import static org.onosproject.yangutils.translator.tojava.TraversalType.SIBILING;
/**
* Represents base class of a node in data model tree.
@@ -229,179 +223,4 @@
newChild.setPreviousSibling(curNode);
}
}
-
- /**
- * Clone the current node contents and create a new node.
- *
- * @return cloned node
- * @throws CloneNotSupportedException clone is not supported by the referred
- * node
- */
- @Override
- public YangNode clone()
- throws CloneNotSupportedException {
- YangNode clonedNode = (YangNode) super.clone();
- clonedNode.setParent(null);
- clonedNode.setChild(null);
- clonedNode.setNextSibling(null);
- clonedNode.setPreviousSibling(null);
- return clonedNode;
- }
-
- /**
- * Clone the subtree from the specified source node to the mentioned target
- * node. The source and target root node cloning is carried out by the
- * caller.
- *
- * @param srcRootNode source node for sub tree cloning
- * @param dstRootNode destination node where the sub tree needs to be cloned
- * @throws DataModelException data model error
- */
- public static void cloneSubTree(YangNode srcRootNode, YangNode dstRootNode)
- throws DataModelException {
-
- YangNode nextNodeToClone = srcRootNode;
- TraversalType curTraversal;
-
- YangNode clonedTreeCurNode = dstRootNode;
- YangNode newNode = null;
-
- nextNodeToClone = nextNodeToClone.getChild();
- if (nextNodeToClone == null) {
- return;
- } else {
- /**
- * Root level cloning is taken care in the caller.
- */
- curTraversal = CHILD;
- }
-
- /**
- * Caller ensures the cloning of the root nodes
- */
- try {
- while (nextNodeToClone != srcRootNode) {
- if (nextNodeToClone == null) {
- throw new DataModelException("Internal error: Cloning failed, source tree null pointer reached");
- }
- if (curTraversal != PARENT) {
- newNode = nextNodeToClone.clone();
- detectCollisionWhileCloning(clonedTreeCurNode, newNode, curTraversal);
- }
-
- if (curTraversal == CHILD) {
-
- /**
- * add the new node to the cloned tree.
- */
- clonedTreeCurNode.addChild(newNode);
-
- /**
- * update the cloned tree's traversal current node as the
- * new node.
- */
- clonedTreeCurNode = newNode;
- } else if (curTraversal == SIBILING) {
-
- clonedTreeCurNode.addNextSibling(newNode);
- clonedTreeCurNode = newNode;
- } else if (curTraversal == PARENT) {
- clonedTreeCurNode = clonedTreeCurNode.getParent();
- }
-
- if (curTraversal != PARENT && nextNodeToClone.getChild() != null) {
- curTraversal = CHILD;
-
- /**
- * update the traversal's current node.
- */
- nextNodeToClone = nextNodeToClone.getChild();
-
- } else if (nextNodeToClone.getNextSibling() != null) {
-
- curTraversal = SIBILING;
-
- nextNodeToClone = nextNodeToClone.getNextSibling();
- } else {
- curTraversal = PARENT;
- nextNodeToClone = nextNodeToClone.getParent();
- }
- }
- } catch (CloneNotSupportedException e) {
- throw new DataModelException("Failed to clone the tree");
- }
-
- }
-
- /**
- * Detects collision when the grouping is deep copied to the uses's parent.
- *
- * @param currentNode parent/previous sibling node for the new node
- * @param newNode node which has to be added
- * @param addAs traversal type of the node
- * @throws DataModelException data model error
- */
- private static void detectCollisionWhileCloning(YangNode currentNode, YangNode newNode, TraversalType addAs)
- throws DataModelException {
- if (!(currentNode instanceof CollisionDetector)
- || !(newNode instanceof Parsable)) {
- throw new DataModelException("Node in data model tree does not support collision detection");
- }
-
- CollisionDetector collisionDetector = (CollisionDetector) currentNode;
- Parsable parsable = (Parsable) newNode;
- if (addAs == TraversalType.CHILD) {
- collisionDetector.detectCollidingChild(newNode.getName(), parsable.getYangConstructType());
- } else if (addAs == TraversalType.SIBILING) {
- currentNode = currentNode.getParent();
- if (!(currentNode instanceof CollisionDetector)) {
- throw new DataModelException("Node in data model tree does not support collision detection");
- }
- collisionDetector = (CollisionDetector) currentNode;
- collisionDetector.detectCollidingChild(newNode.getName(), parsable.getYangConstructType());
- } else {
- throw new DataModelException("Errored tree cloning");
- }
-
- }
-
- /**
- * Add a new next sibling.
- *
- * @param newSibling new sibling to be added
- * @throws DataModelException data model error
- */
- private void addNextSibling(YangNode newSibling)
- throws DataModelException {
-
- if (newSibling.getNodeType() == null) {
- throw new DataModelException("Cloned abstract node cannot be inserted into a tree");
- }
-
- if (newSibling.getParent() == null) {
- /**
- * Since the siblings needs to have a common parent, set the parent
- * as the current node's parent
- */
- newSibling.setParent(getParent());
-
- } else {
- throw new DataModelException("Node is already part of a tree, and cannot be added as a sibling");
- }
-
- if (newSibling.getPreviousSibling() == null) {
- newSibling.setPreviousSibling(this);
- setNextSibling(newSibling);
- } else {
- throw new DataModelException("New sibling to be added is not atomic, it already has a previous sibling");
- }
-
- if (newSibling.getChild() != null) {
- throw new DataModelException("Sibling to be added is not atomic, it already has a child");
- }
-
- if (newSibling.getNextSibling() != null) {
- throw new DataModelException("Sibling to be added is not atomic, it already has a next sibling");
- }
- }
}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java b/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
index 5e81f64..e70261f 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
@@ -74,7 +74,8 @@
/**
* Represents data model node to maintain information defined in YANG notification.
*/
-public class YangNotification extends YangNode
+public class YangNotification
+ extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
@@ -117,13 +118,15 @@
}
@Override
- public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
// Detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
- public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
if (this.getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as notification \""
+ this.getName() + "\"");
@@ -136,12 +139,14 @@
}
@Override
- public void validateDataOnEntry() throws DataModelException {
+ public void validateDataOnEntry()
+ throws DataModelException {
//TODO: implement the method.
}
@Override
- public void validateDataOnExit() throws DataModelException {
+ public void validateDataOnExit()
+ throws DataModelException {
//TODO: implement the method.
}
@@ -161,6 +166,11 @@
}
@Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ @Override
public void addLeaf(YangLeaf leaf) {
getListOfLeaf().add(leaf);
}
@@ -171,6 +181,11 @@
}
@Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ @Override
public void addLeafList(YangLeafList leafList) {
getListOfLeafList().add(leafList);
}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java b/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
index 97072cf..2cb4c34 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
@@ -67,7 +67,8 @@
/**
* Represents data model node to maintain information defined in YANG output.
*/
-public class YangOutput extends YangNode
+public class YangOutput
+ extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
/**
@@ -95,13 +96,15 @@
}
@Override
- public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
// Detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
- public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
if (this.getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate identifier detected, same as output \""
+ this.getName() + "\"");
@@ -114,12 +117,14 @@
}
@Override
- public void validateDataOnEntry() throws DataModelException {
+ public void validateDataOnEntry()
+ throws DataModelException {
//TODO: implement the method.
}
@Override
- public void validateDataOnExit() throws DataModelException {
+ public void validateDataOnExit()
+ throws DataModelException {
//TODO: implement the method.
}
@@ -134,11 +139,22 @@
}
@Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ @Override
public List<YangLeafList> getListOfLeafList() {
return listOfLeafList;
}
@Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+
+ @Override
public void addLeafList(YangLeafList leafList) {
getListOfLeafList().add(leafList);
}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java b/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
index 7a54aaf..89c49dd 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
@@ -19,9 +19,11 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
-import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
+import org.onosproject.yangutils.linker.ResolvableType;
+import org.onosproject.yangutils.linker.YangReferenceResolver;
import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
@@ -82,7 +84,8 @@
/**
* Represents data model node to maintain information defined in YANG sub-module.
*/
-public class YangSubModule extends YangNode
+public class YangSubModule
+ extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
RpcNotificationContainer {
@@ -156,6 +159,7 @@
* Prefix of parent module.
*/
private String prefix;
+
/*-
* Reference RFC 6020.
*
@@ -190,14 +194,20 @@
* matching "typedef" or "grouping" statement among the immediate
* sub-statements of each ancestor statement.
*/
- private List<YangResolutionInfo> unresolvedResolutionList;
+ private List<YangResolutionInfo> derivedTypeResolutionList;
+
+ /**
+ * uses resolution list.
+ */
+ private List<YangResolutionInfo> usesResolutionList;
/**
* Creates a sub module node.
*/
public YangSubModule() {
super(YangNodeType.SUB_MODULE_NODE);
- unresolvedResolutionList = new LinkedList<YangResolutionInfo>();
+ derivedTypeResolutionList = new LinkedList<YangResolutionInfo>();
+ usesResolutionList = new LinkedList<YangResolutionInfo>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
@@ -341,17 +351,19 @@
}
@Override
- public void resolveSelfFileLinking() throws DataModelException {
+ public void resolveSelfFileLinking(ResolvableType type)
+ throws DataModelException {
// Get the list to be resolved.
- List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
+ List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
// Resolve linking for a resolution list.
resolveLinkingForResolutionList(resolutionList, this);
}
@Override
- public void resolveInterFileLinking() throws DataModelException {
+ public void resolveInterFileLinking(ResolvableType type)
+ throws DataModelException {
// Get the list to be resolved.
- List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList();
+ List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
// Resolve linking for a resolution list.
linkInterFileReferences(resolutionList, this);
}
@@ -366,6 +378,11 @@
return listOfLeaf;
}
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
/**
* Adds a leaf.
*
@@ -386,6 +403,11 @@
return listOfLeafList;
}
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
/**
* Adds a leaf-list.
*
@@ -486,7 +508,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
}
@@ -496,34 +519,52 @@
* @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
}
@Override
- public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
- public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
// Not required as module doesn't have any parent.
}
@Override
- public List<YangResolutionInfo> getUnresolvedResolutionList() {
- return unresolvedResolutionList;
+ public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
+ if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
+ return derivedTypeResolutionList;
+ } else {
+ return usesResolutionList;
+ }
}
@Override
- public void addToResolutionList(YangResolutionInfo resolutionInfo) {
- this.unresolvedResolutionList.add(resolutionInfo);
+ public void addToResolutionList(YangResolutionInfo resolutionInfo,
+ ResolvableType type) {
+ if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
+ derivedTypeResolutionList.add(resolutionInfo);
+ } else if (type == ResolvableType.YANG_USES) {
+ usesResolutionList.add(resolutionInfo);
+ }
}
@Override
- public void setResolutionList(List<YangResolutionInfo> resolutionList) {
- this.unresolvedResolutionList = resolutionList;
+ public void setResolutionList(List<YangResolutionInfo> resolutionList,
+ ResolvableType type) {
+ if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
+ derivedTypeResolutionList = resolutionList;
+ } else if (type == ResolvableType.YANG_USES) {
+ usesResolutionList = resolutionList;
+ }
+
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangType.java b/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
index 4421619..41e07e4 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
@@ -17,9 +17,9 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.Resolvable;
+import org.onosproject.yangutils.linker.ResolvableStatus;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
-import org.onosproject.yangutils.linker.impl.Resolvable;
-import org.onosproject.yangutils.linker.impl.ResolvableStatus;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
@@ -247,7 +247,8 @@
}
@Override
- public void resolve() throws LinkerException {
+ public void resolve()
+ throws LinkerException {
/*
* Check whether the data type is derived.
*/
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java b/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
index 4eae3a2..d2d8bc2 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
@@ -15,10 +15,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.linker.Resolvable;
+import org.onosproject.yangutils.linker.ResolvableStatus;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
-import org.onosproject.yangutils.linker.impl.Resolvable;
-import org.onosproject.yangutils.linker.impl.ResolvableStatus;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
@@ -96,12 +99,30 @@
private ResolvableStatus resolvableStatus;
/**
+ * Effective list of nodes of grouping that needs to replicated at YANG uses.
+ */
+ List<YangNode> resolvedGroupingNodes;
+
+ /**
+ * Effective list of leaves of grouping that needs to replicated at YANG uses.
+ */
+ List<List<YangLeaf>> resolvedGroupingLeaves;
+
+ /**
+ * Effective list of leaf lists of grouping that needs to replicated at YANG uses.
+ */
+ List<List<YangLeafList>> resolvedGroupingLeafLists;
+
+ /**
* Creates an YANG uses node.
*/
public YangUses() {
super(YangNodeType.USES_NODE);
nodeIdentifier = new YangNodeIdentifier();
resolvableStatus = ResolvableStatus.UNRESOLVED;
+ resolvedGroupingNodes = new LinkedList<YangNode>();
+ resolvedGroupingLeaves = new LinkedList<List<YangLeaf>>();
+ resolvedGroupingLeafLists = new LinkedList<List<YangLeafList>>();
}
/**
@@ -277,36 +298,132 @@
}
YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode;
- if (referredGrouping.getListOfLeaf() != null) {
- for (YangLeaf leaf : referredGrouping.getListOfLeaf()) {
- try {
- ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getName(),
- YangConstructType.LEAF_DATA);
- } catch (DataModelException e) {
- throw new LinkerException(e.getMessage());
- }
- usesParentLeavesHolder.addLeaf(leaf);
- }
- }
- if (referredGrouping.getListOfLeafList() != null) {
- for (YangLeafList leafList : referredGrouping.getListOfLeafList()) {
- try {
- ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getName(),
- YangConstructType.LEAF_LIST_DATA);
- } catch (DataModelException e) {
- throw new LinkerException(e.getMessage());
- }
- usesParentLeavesHolder.addLeafList(leafList);
- }
+ if (referredGrouping.getListOfLeaf() != null
+ && referredGrouping.getListOfLeaf().size() != 0) {
+ addLeavesOfGrouping(
+ cloneLeavesList(referredGrouping.getListOfLeaf(),
+ usesParentLeavesHolder));
}
- try {
- YangNode.cloneSubTree(getRefGroup(), usesParentNode);
- } catch (DataModelException e) {
- throw new LinkerException(e.getMessage());
+ if (referredGrouping.getListOfLeafList() != null
+ && referredGrouping.getListOfLeafList().size() != 0) {
+ addListOfLeafListOfGrouping(
+ cloneListOfLeafList(referredGrouping.getListOfLeafList(),
+ usesParentLeavesHolder));
+ }
+
+ YangNode childInGrouping = referredGrouping.getChild();
+
+ while (childInGrouping != null) {
+ if ((childInGrouping instanceof YangEnumeration)
+ || (childInGrouping instanceof YangUnion)
+ || (childInGrouping instanceof YangTypeDef)) {
+
+ /*
+ * No need to copy the leaves, union / enum class,
+ * as these will be generated in the scope of grouping
+ */
+ childInGrouping = childInGrouping.getNextSibling();
+ continue;
+ } else if ((childInGrouping instanceof YangUses)) {
+ addResolvedUsesInfoOfGrouping((YangUses) childInGrouping,
+ usesParentLeavesHolder);
+ } else {
+ addNodeOfGrouping(childInGrouping);
+ }
+
+ childInGrouping = childInGrouping.getNextSibling();
}
}
+ /**
+ * Clone the resolved uses contained in grouping to the uses of grouping.
+ *
+ * @param usesInGrouping resolved uses in grouping
+ * @param usesHolder holder of uses
+ */
+ private void addResolvedUsesInfoOfGrouping(YangUses usesInGrouping,
+ YangLeavesHolder usesHolder) {
+ for (YangNode usesResolvedNode :
+ usesInGrouping.getUsesResolvedNodeList()) {
+ addNodeOfGrouping(usesResolvedNode);
+ }
+
+ for (List<YangLeaf> leavesList :
+ usesInGrouping.getUsesResolvedLeavesList()) {
+ addLeavesOfGrouping(cloneLeavesList(leavesList, usesHolder));
+ }
+
+ for (List<YangLeafList> listOfLeafLists :
+ usesInGrouping.getUsesResolvedListOfLeafList()) {
+ addListOfLeafListOfGrouping(
+ cloneListOfLeafList(listOfLeafLists, usesHolder));
+ }
+ }
+
+ /**
+ * Clone the list of leaves and return the cloned list leaves.
+ *
+ * @param listOfLeaves list of leaves to be cloned
+ * @param usesParentNode parent of the cloned location
+ * @return cloned list of leaves
+ */
+ private List<YangLeaf> cloneLeavesList(List<YangLeaf> listOfLeaves,
+ YangLeavesHolder usesParentNode) {
+ if ((listOfLeaves == null) || listOfLeaves.size() == 0) {
+ throw new LinkerException("No leaves to clone");
+ }
+
+ List<YangLeaf> newLeavesList = new LinkedList<YangLeaf>();
+ for (YangLeaf leaf : listOfLeaves) {
+ YangLeaf clonedLeaf;
+ try {
+ ((CollisionDetector) usesParentNode).detectCollidingChild(leaf.getName(),
+ YangConstructType.LEAF_DATA);
+ clonedLeaf = leaf.clone();
+ } catch (CloneNotSupportedException | DataModelException e) {
+ throw new LinkerException(e.getMessage());
+ }
+
+ clonedLeaf.setContainedIn(usesParentNode);
+ newLeavesList.add(clonedLeaf);
+ }
+
+ return newLeavesList;
+ }
+
+ /**
+ * Clone the list of leaf list.
+ *
+ * @param listOfLeafList list of leaf list that needs to be cloned
+ * @param usesParentNode parent of uses
+ * @return cloned list of leaf list
+ */
+ private List<YangLeafList> cloneListOfLeafList(List<YangLeafList> listOfLeafList,
+ YangLeavesHolder usesParentNode) {
+ if ((listOfLeafList == null) || listOfLeafList.size() == 0) {
+ throw new LinkerException("No leaf lists to clone");
+ }
+
+ List<YangLeafList> newListOfLeafList = new LinkedList<YangLeafList>();
+ for (YangLeafList leafList : listOfLeafList) {
+ YangLeafList clonedLeafList;
+ try {
+ ((CollisionDetector) usesParentNode).detectCollidingChild(leafList.getName(),
+ YangConstructType.LEAF_LIST_DATA);
+ clonedLeafList = leafList.clone();
+ } catch (CloneNotSupportedException | DataModelException e) {
+ throw new LinkerException(e.getMessage());
+ }
+
+ clonedLeafList.setContainedIn(usesParentNode);
+ newListOfLeafList.add(clonedLeafList);
+ }
+
+ return newListOfLeafList;
+ }
+
+
@Override
public ResolvableStatus getResolvableStatus() {
return resolvableStatus;
@@ -318,12 +435,14 @@
}
@Override
- public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
- public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
if (getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as uses \""
@@ -331,4 +450,61 @@
}
}
+
+ /**
+ * Adds the node under grouping to the effective uses resolved info.
+ *
+ * @param nodeInGrouping node defined under grouping which needs to be copied in
+ * the context of uses
+ */
+ public void addNodeOfGrouping(YangNode nodeInGrouping) {
+ resolvedGroupingNodes.add(nodeInGrouping);
+ }
+
+ /**
+ * Returns the effective list of nodes added due to uses linking.
+ *
+ * @return effective list of nodes added due to uses linking
+ */
+ public List<YangNode> getUsesResolvedNodeList() {
+ return resolvedGroupingNodes;
+ }
+
+ /**
+ * Adds the leaves under grouping to the effective uses resolved info.
+ *
+ * @param leavesInGrouping Leaves defined under grouping which needs to be copied in
+ * the context of uses
+ */
+ public void addLeavesOfGrouping(List<YangLeaf> leavesInGrouping) {
+ resolvedGroupingLeaves.add(leavesInGrouping);
+ }
+
+ /**
+ * Returns the effective list of Leaves added due to uses linking.
+ *
+ * @return effective list of Leaves added due to uses linking
+ */
+ public List<List<YangLeaf>> getUsesResolvedLeavesList() {
+ return resolvedGroupingLeaves;
+ }
+
+ /**
+ * Adds the leaf-lists under grouping to the effective uses resolved info.
+ *
+ * @param leafListsInGrouping leaf-lists defined under grouping which needs to be copied in
+ * the context of uses
+ */
+ public void addListOfLeafListOfGrouping(List<YangLeafList> leafListsInGrouping) {
+ resolvedGroupingLeafLists.add(leafListsInGrouping);
+ }
+
+ /**
+ * Returns the effective list of Leaves added due to uses linking.
+ *
+ * @return effective list of Leaves added due to uses linking
+ */
+ public List<List<YangLeafList>> getUsesResolvedListOfLeafList() {
+ return resolvedGroupingLeafLists;
+ }
}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
index ea17891..29d384b 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -18,15 +18,18 @@
import java.util.List;
import java.util.Set;
+
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangRpc;
+import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.ResolvableType;
+import org.onosproject.yangutils.linker.YangReferenceResolver;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
@@ -45,8 +48,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
+ * @param identifierName name for which collision detection is to be checked
* @param dataType type of YANG node asking for detecting collision
* @param node instance of calling node
* @throws DataModelException a violation of data model rules
@@ -77,8 +79,7 @@
/**
* Detects colliding of uses and grouping only with uses and grouping respectively.
*
- * @param identifierName name for which collision detection is to be
- * checked
+ * @param identifierName name for which collision detection is to be checked
* @param dataType type of YANG node asking for detecting collision
* @param node node instance of calling node
* @throws DataModelException a violation of data model rules
@@ -101,8 +102,7 @@
* Detects the colliding identifier name in a given leaf node.
*
* @param listOfLeaf List of leaves to detect collision
- * @param identifierName name for which collision detection is to be
- * checked
+ * @param identifierName name for which collision detection is to be checked
* @throws DataModelException a violation of data model rules
*/
private static void detectCollidingLeaf(List<YangLeaf> listOfLeaf, String identifierName)
@@ -123,8 +123,7 @@
* Detects the colliding identifier name in a given leaf-list node.
*
* @param listOfLeafList list of leaf-lists to detect collision
- * @param identifierName name for which collision detection is to be
- * checked
+ * @param identifierName name for which collision detection is to be checked
* @throws DataModelException a violation of data model rules
*/
private static void detectCollidingLeafList(List<YangLeafList> listOfLeafList, String identifierName)
@@ -144,8 +143,7 @@
/**
* Add a resolution information.
*
- * @param resolutionInfo information about the YANG construct which has to
- * be resolved
+ * @param resolutionInfo information about the YANG construct which has to be resolved
* @throws DataModelException a violation of data model rules
*/
public static void addResolutionInfo(YangResolutionInfo resolutionInfo)
@@ -162,7 +160,15 @@
}
YangReferenceResolver resolutionNode = (YangReferenceResolver) curNode;
- resolutionNode.addToResolutionList(resolutionInfo);
+ if (resolutionInfo.getEntityToResolveInfo()
+ .getEntityToResolve() instanceof YangType) {
+ resolutionNode.addToResolutionList(resolutionInfo,
+ ResolvableType.YANG_DERIVED_DATA_TYPE);
+ } else {
+ resolutionNode.addToResolutionList(resolutionInfo,
+ ResolvableType.YANG_USES);
+ }
+
}
/**
@@ -173,7 +179,7 @@
* @throws DataModelException a violation of data model rules
*/
public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList,
- YangReferenceResolver dataModelRootNode)
+ YangReferenceResolver dataModelRootNode)
throws DataModelException {
for (YangResolutionInfo resolutionInfo : resolutionList) {
@@ -189,7 +195,7 @@
* @throws DataModelException a violation of data model rules
*/
public static void linkInterFileReferences(List<YangResolutionInfo> resolutionList,
- YangReferenceResolver dataModelRootNode)
+ YangReferenceResolver dataModelRootNode)
throws DataModelException {
/*
* Run through the resolution list, find type/uses referring to