[ONOS-4650][ONOS-4726][ONOS-4727] [ONOS-4728]Implement must parser + when parser + feature + if-feature + revision defect fix
Change-Id: I0a3aee6c1c6b72ef7da7f7f565fd0f149fe3fd42
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
index 9521f41..058e947 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
@@ -29,5 +29,10 @@
/**
* Identifies the uses.
*/
- YANG_USES
+ YANG_USES,
+
+ /**
+ * Identifies the if-feature.
+ */
+ YANG_IF_FEATURE
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
index 84f0173..ae9ff3a 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
@@ -65,14 +65,14 @@
* | choice | 7.9 | 0..n |-child nodes |
* | container | 7.5 | 0..n |-child nodes |
* | description | 7.19.3 | 0..1 |-string |
- * | if-feature | 7.18.2 | 0..n |-TODO |
+ * | if-feature | 7.18.2 | 0..n |-YangIfFeature |
* | leaf | 7.6 | 0..n |-YangLeaf |
* | leaf-list | 7.7 | 0..n |-YangLeafList |
* | list | 7.8 | 0..n |-child nodes |
* | reference | 7.19.4 | 0..1 |-String |
* | status | 7.19.2 | 0..1 |-YangStatus |
* | uses | 7.12 | 0..n |-child nodes |
- * | when | 7.19.5 | 0..1 |-TODO |
+ * | when | 7.19.5 | 0..1 |-YangWhen |
* +--------------+---------+-------------+------------------+
*/
@@ -81,7 +81,7 @@
*/
public class YangAugment
extends YangNode
- implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201602L;
@@ -121,6 +121,16 @@
private YangStatusType status;
/**
+ * When data of the node.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
* Create a YANG augment node.
*/
public YangAugment() {
@@ -146,6 +156,26 @@
}
/**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
* Returns the description.
*
* @return the description
@@ -341,4 +371,21 @@
this.name = name;
}
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
index a00b77d..eb7d6fd 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
@@ -78,14 +78,14 @@
* | choice | 7.9 | 0..n |-child nodes |
* | container | 7.5 | 0..n |-child nodes |
* | description | 7.19.3 | 0..1 |-string |
- * | if-feature | 7.18.2 | 0..n |-TODO |
+ * | if-feature | 7.18.2 | 0..n |-YangIfFeature |
* | leaf | 7.6 | 0..n |-YangLeaf |
* | leaf-list | 7.7 | 0..n |-YangLeafList |
* | list | 7.8 | 0..n |-child nodes |
* | reference | 7.19.4 | 0..1 |-string |
* | status | 7.19.2 | 0..1 |-YangStatus |
* | uses | 7.12 | 0..n |-child node |
- * | when | 7.19.5 | 0..1 |-TODO |
+ * | when | 7.19.5 | 0..1 |-YangWhen |
* +--------------+---------+-------------+------------------+
*/
@@ -94,7 +94,8 @@
*/
public class YangCase
extends YangNode
- implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder,
+ YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201603L;
@@ -131,6 +132,16 @@
private YangStatusType status;
/**
+ * When data of the node.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
* Creates a choice node.
*/
public YangCase() {
@@ -138,6 +149,26 @@
}
/**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
* Returns the case name.
*
* @return case name
@@ -343,4 +374,22 @@
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java
index 85ba107..5262119 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java
@@ -15,6 +15,8 @@
*/
package org.onosproject.yangutils.datamodel;
+import java.util.LinkedList;
+import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
@@ -46,21 +48,23 @@
* | container | 7.5 | 0..n |-child case nodes |
* | default | 7.9.3 | 0..1 |-string |
* | description | 7.19.3 | 0..1 |-string |
- * | if-feature | 7.18.2 | 0..n |-TODO |
+ * | if-feature | 7.18.2 | 0..n |-YangIfFeature |
* | leaf | 7.6 | 0..n |-child case nodes |
* | leaf-list | 7.7 | 0..n |-child case nodes |
* | list | 7.8 | 0..n |-child case nodes |
* | mandatory | 7.9.4 | 0..1 |-string |
* | reference | 7.19.4 | 0..1 |-string |
* | status | 7.19.2 | 0..1 |-string |
- * | when | 7.19.5 | 0..1 |-TODO |
+ * | when | 7.19.5 | 0..1 |-YangWhen |
* +--------------+---------+-------------+------------------+
*/
+
/**
* Represents data model node to maintain information defined in YANG choice.
*/
public class YangChoice extends YangNode
- implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
+ implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder, YangWhenHolder,
+ YangIfFeatureHolder {
private static final long serialVersionUID = 806201604L;
@@ -143,6 +147,16 @@
private String defaultValueInString;
/**
+ * When data of the node.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
* Create a choice node.
*/
public YangChoice() {
@@ -150,6 +164,26 @@
}
/**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
* Returns the choice name.
*
* @return choice name
@@ -365,4 +399,23 @@
node = node.getNextSibling();
}
}
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
index e23bf02..7bb34e2 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
@@ -70,17 +70,17 @@
* | container | 7.5 | 0..n | -child nodes |
* | description | 7.19.3 | 0..1 | -string |
* | grouping | 7.11 | 0..n | -child nodes |
- * | if-feature | 7.18.2 | 0..n | -TODO |
+ * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
* | leaf | 7.6 | 0..n | -YangLeaf |
* | leaf-list | 7.7 | 0..n | -YangLeafList |
* | list | 7.8 | 0..n | -child nodes |
- * | must | 7.5.3 | 0..n | -TODO |
+ * | must | 7.5.3 | 0..n | -YangMust |
* | presence | 7.5.5 | 0..1 | -boolean |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* | typedef | 7.3 | 0..n | -child nodes |
* | uses | 7.12 | 0..n | -child nodes |
- * | when | 7.19.5 | 0..1 | -TODO |
+ * | when | 7.19.5 | 0..1 | -YangWhen |
* +--------------+---------+-------------+------------------+
*/
@@ -89,7 +89,8 @@
*/
public class YangContainer
extends YangNode
- implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder,
+ YangMustHolder, YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201605L;
@@ -135,6 +136,21 @@
private YangStatusType status = YangStatusType.CURRENT;
/**
+ * List of must statement constraints.
+ */
+ private List<YangMust> mustConstraintList;
+
+ /**
+ * When data of the node.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
* Create a container node.
*/
public YangContainer() {
@@ -142,6 +158,26 @@
}
/**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
* Returns the YANG name of container.
*
* @return the name of container as defined in YANG file
@@ -445,4 +481,41 @@
+ getName() + "\"");
}
}
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
+ public List<YangMust> getListOfMust() {
+ return mustConstraintList;
+ }
+
+ @Override
+ public void setListOfMust(List<YangMust> mustConstraintList) {
+ this.mustConstraintList = mustConstraintList;
+ }
+
+ @Override
+ public void addMust(YangMust must) {
+ if (getListOfMust() == null) {
+ setListOfMust(new LinkedList<>());
+ }
+ getListOfMust().add(must);
+ }
+
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangFeature.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangFeature.java
new file mode 100644
index 0000000..f8f656b
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangFeature.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The "feature" statement is used to define a mechanism by which
+ * portions of the schema are marked as conditional. A feature name is
+ * defined that can later be referenced using the "if-feature" statement.
+ * Schema nodes tagged with a feature are ignored by the device unless
+ * the device supports the given feature. This allows portions of the
+ * YANG module to be conditional based on conditions on the device.
+ * The model can represent the abilities of the device within the model,
+ * giving a richer model that allows for differing device abilities and roles.
+ *
+ * The argument to the "feature" statement is the name of the new
+ * feature, and follows the rules for identifiers. This name is used by the
+ * "if-feature" statement to tie the schema nodes to the feature.
+ *
+ * The feature's Substatements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | description | 7.19.3 | 0..1 | -string |
+ * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG feature.
+ */
+public class YangFeature implements YangCommonInfo, Parsable, YangIfFeatureHolder, Serializable {
+
+ private static final long serialVersionUID = 806201635L;
+
+ /**
+ * Name of the feature.
+ */
+ private String name;
+
+ /**
+ * Description of feature.
+ */
+ private String description;
+
+ /**
+ * Reference of the feature.
+ */
+ private String reference;
+
+ /**
+ * Status of feature.
+ */
+ private YangStatusType statusType;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ @Override
+ public YangStatusType getStatus() {
+ return statusType;
+ }
+
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.statusType = status;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.FEATURE_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ //TODO : To be implemented
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ //TODO : To be implemented
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangFeatureHolder.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangFeatureHolder.java
new file mode 100644
index 0000000..a3e15f2
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangFeatureHolder.java
@@ -0,0 +1,44 @@
+/*Copyright 2016.year Open Networking Laboratory
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.*/
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.List;
+
+/**
+ * Abstraction of feature entity. It is used to abstract the data holders of feature.
+ */
+public interface YangFeatureHolder {
+
+ /**
+ * Returns the list of feature from data holder like container / list.
+ *
+ * @return the list of feature
+ */
+ List<YangFeature> getFeatureList();
+
+ /**
+ * Adds feature in feature list.
+ *
+ * @param feature the feature to be added
+ */
+ void addFeatureList(YangFeature feature);
+
+ /**
+ * Sets the list of feature.
+ *
+ * @param listOfFeature the list of feature to set
+ */
+ void setListOfFeature(List<YangFeature> listOfFeature);
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIfFeature.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIfFeature.java
new file mode 100644
index 0000000..a44fbdc
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIfFeature.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The "if-feature" statement makes its parent statement conditional.
+ * The argument is the name of a feature, as defined by a "feature"
+ * statement. The parent statement is implemented by servers that
+ * support this feature. If a prefix is present on the feature name, it
+ * refers to a feature defined in the module that was imported with that
+ * prefix, or the local module if the prefix matches the local module's
+ * prefix. Otherwise, a feature with the matching name MUST be defined
+ * in the current module or an included submodule.
+ *
+ * Since submodules cannot include the parent module, any features in
+ * the module that need to be exposed to submodules MUST be defined in a
+ * submodule. Submodules can then include this submodule to find the
+ * definition of the feature.
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG if-feature.
+ */
+public class YangIfFeature implements Parsable, Resolvable, Serializable {
+
+ private static final long serialVersionUID = 806201635L;
+
+ /**
+ * if-feature argument.
+ */
+ YangNodeIdentifier name;
+
+ /**
+ * Referred feature information.
+ */
+ YangFeature referredFeature;
+
+ /**
+ * Referred feature parent information.
+ */
+ YangNode referredFeatureHolder;
+
+ /**
+ * 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
+ * "INTRA_FILE_RESOLVED".
+ */
+ private ResolvableStatus resolvableStatus;
+
+ /**
+ * Returns referred feature holder.
+ *
+ * @return referred feature holder
+ */
+ public YangNode getReferredFeatureHolder() {
+ return referredFeatureHolder;
+ }
+
+ /**
+ * Sets the referred feature holder.
+ *
+ * @param referredFeatureHolder referred feature holder
+ */
+ public void setReferredFeatureHolder(YangNode referredFeatureHolder) {
+ this.referredFeatureHolder = referredFeatureHolder;
+ }
+
+ /**
+ * Returns prefix associated with identifier.
+ *
+ * @return prefix associated with identifier
+ */
+ public String getPrefix() {
+ return name.getPrefix();
+ }
+
+ /**
+ * Sets prefix associated with identifier.
+ *
+ * @param prefix prefix associated with identifier
+ */
+ public void setPrefix(String prefix) {
+ name.setPrefix(prefix);
+ }
+
+ /**
+ * Returns referred feature associated with if-feature.
+ *
+ * @return referred feature associated with if-feature
+ */
+ public YangFeature getReferredFeature() {
+ return referredFeature;
+ }
+
+ /**
+ * Sets referred feature associated with if-feature.
+ *
+ * @param referredFeature referred feature associated with if-feature
+ */
+ public void setReferredFeature(YangFeature referredFeature) {
+ this.referredFeature = referredFeature;
+ }
+
+ /**
+ * Returns the YANG name of if-feature.
+ *
+ * @return the name of if-feature as defined in YANG file
+ */
+ public YangNodeIdentifier getName() {
+ return name;
+ }
+
+ /**
+ * Sets the YANG name of if-feature.
+ *
+ * @param name the name of if-feature as defined in YANG file
+ */
+ public void setName(YangNodeIdentifier name) {
+ this.name = name;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.IF_FEATURE_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // do nothing, no validation required for if-feature
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // do nothing, no validation required for if-feature
+ }
+
+ @Override
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ @Override
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+ }
+
+ @Override
+ public void resolve() throws DataModelException {
+ YangFeature feature = getReferredFeature();
+
+ // check whether feature has if-feature
+ List<YangIfFeature> ifFeatureList = feature.getIfFeatureList();
+ if (ifFeatureList != null && !ifFeatureList.isEmpty()) {
+ Iterator<YangIfFeature> ifFeatureIterator = ifFeatureList.iterator();
+ while (ifFeatureIterator.hasNext()) {
+ YangIfFeature ifFeature = ifFeatureIterator.next();
+ if (ifFeature.getResolvableStatus() != ResolvableStatus.RESOLVED) {
+ setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
+ return;
+ }
+ }
+ }
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIfFeatureHolder.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIfFeatureHolder.java
new file mode 100644
index 0000000..46c3233
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIfFeatureHolder.java
@@ -0,0 +1,44 @@
+/*Copyright 2016.year Open Networking Laboratory
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.*/
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.List;
+
+/**
+ * Abstraction of if-feature entity. It is used to abstract the data holders of if-feature.
+ */
+public interface YangIfFeatureHolder {
+
+ /**
+ * Returns the list of if-feature from data holder like container / list.
+ *
+ * @return the list of if-feature
+ */
+ List<YangIfFeature> getIfFeatureList();
+
+ /**
+ * Adds if-feature in if-feature list.
+ *
+ * @param ifFeature the if-feature to be added
+ */
+ void addIfFeatureList(YangIfFeature ifFeature);
+
+ /**
+ * Sets the list of if-feature.
+ *
+ * @param ifFeatureList the list of if-feature to set
+ */
+ void setIfFeatureList(List<YangIfFeature> ifFeatureList);
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java
index 0fcf663..f6405e1 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
+import java.util.Date;
import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
@@ -61,7 +62,7 @@
* | substatement | section | cardinality |data model mapping|
* +---------------+---------+-------------+------------------+
* | prefix | 7.1.4 | 1 | string |
- * | revision-date | 7.1.5.1 | 0..1 | string |
+ * | revision-date | 7.1.5.1 | 0..1 | Date |
* +---------------+---------+-------------+------------------+
*/
@@ -91,7 +92,7 @@
* the most recent "revision" statement in the imported module. organization
* which defined the YANG module.
*/
- private String revision;
+ private Date revision;
/**
* Reference to node which is imported.
@@ -152,7 +153,7 @@
*
* @return the revision of the imported module
*/
- public String getRevision() {
+ public Date getRevision() {
return revision;
}
@@ -161,7 +162,7 @@
*
* @param rev set the revision of the imported module
*/
- public void setRevision(String rev) {
+ public void setRevision(Date rev) {
revision = rev;
}
@@ -245,7 +246,7 @@
*/
public void addReferenceToImport(Set<YangNode> yangNodeSet) throws DataModelException {
String importedModuleName = getModuleName();
- String importedModuleRevision = getRevision();
+ Date importedModuleRevision = getRevision();
YangNode moduleNode = null;
/*
* Find the imported module node for a given module name with a
@@ -266,7 +267,7 @@
if (moduleNode != null) {
if (moduleNode instanceof YangModule) {
- if (getRevision() == null || getRevision().isEmpty()) {
+ if (getRevision() == null) {
setImportedNode(moduleNode);
return;
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java
index 5970a24..48b796f 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
+import java.util.Date;
import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
@@ -56,7 +57,7 @@
* The include's "revision-date" statement is used to specify the exact
* version of the submodule to import.
*/
- private String revision;
+ private Date revision;
/**
* Reference to node which is included.
@@ -98,7 +99,7 @@
*
* @return the revision
*/
- public String getRevision() {
+ public Date getRevision() {
return revision;
}
@@ -107,7 +108,7 @@
*
* @param revision the revision to set
*/
- public void setRevision(String revision) {
+ public void setRevision(Date revision) {
this.revision = revision;
}
@@ -182,7 +183,7 @@
*/
public YangSubModule addReferenceToInclude(Set<YangNode> yangNodeSet) throws DataModelException {
String includedSubModuleName = getSubModuleName();
- String includedSubModuleRevision = getRevision();
+ Date includedSubModuleRevision = getRevision();
YangNode subModuleNode = null;
/*
@@ -204,7 +205,7 @@
if (subModuleNode != null) {
if (subModuleNode instanceof YangSubModule) {
- if (getRevision() == null || getRevision().isEmpty()) {
+ if (getRevision() == null) {
setIncludedNode(subModuleNode);
return (YangSubModule) subModuleNode;
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
index 0391518..0c717a6 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
@@ -17,7 +17,8 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
-
+import java.util.LinkedList;
+import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
@@ -43,16 +44,16 @@
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | config | 7.19.1 | 0..1 | - boolean |
- * | default | 7.6.4 | 0..1 | - TODO |
+ * | default | 7.6.4 | 0..1 | - string |
* | description | 7.19.3 | 0..1 | - string |
- * | if-feature | 7.18.2 | 0..n | - TODO |
+ * | if-feature | 7.18.2 | 0..n | - YangIfFeature |
* | mandatory | 7.6.5 | 0..1 | - boolean |
- * | must | 7.5.3 | 0..n | - TODO |
+ * | must | 7.5.3 | 0..n | - YangMust |
* | reference | 7.19.4 | 0..1 | - string |
* | status | 7.19.2 | 0..1 | - YangStatus |
* | type | 7.6.3 | 1 | - YangType |
* | units | 7.3.3 | 0..1 | - String |
- * | when | 7.19.5 | 0..1 | - TODO |
+ * | when | 7.19.5 | 0..1 | - YangWhen |
* +--------------+---------+-------------+------------------+
*/
@@ -60,7 +61,8 @@
* Represents leaf data represented in YANG.
*/
public class YangLeaf
- implements YangCommonInfo, Parsable, Cloneable, Serializable {
+ implements YangCommonInfo, Parsable, Cloneable, Serializable,
+ YangMustHolder, YangIfFeatureHolder, YangWhenHolder {
private static final long serialVersionUID = 806201635L;
@@ -111,11 +113,26 @@
private String defaultValueInString;
/**
+ * When data of the leaf.
+ */
+ private YangWhen when;
+
+ /**
* YANG Node in which the leaf is contained.
*/
private transient YangLeavesHolder containedIn;
/**
+ * List of must statement constraints.
+ */
+ private List<YangMust> mustConstraintList;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
* Creates a YANG leaf.
*/
public YangLeaf() {
@@ -158,6 +175,26 @@
}
/**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
* Returns the description.
*
* @return the description
@@ -346,4 +383,40 @@
// TODO auto-generated method stub, to be implemented by parser
}
+
+ @Override
+ public List<YangMust> getListOfMust() {
+ return mustConstraintList;
+ }
+
+ @Override
+ public void setListOfMust(List<YangMust> mustConstraintList) {
+ this.mustConstraintList = mustConstraintList;
+ }
+
+ @Override
+ public void addMust(YangMust must) {
+ if (getListOfMust() == null) {
+ setListOfMust(new LinkedList<>());
+ }
+ getListOfMust().add(must);
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java
index 2ce44fb..febae0e 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java
@@ -17,7 +17,8 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
-
+import java.util.LinkedList;
+import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
@@ -39,16 +40,16 @@
* +--------------+---------+-------------+------------------+
* | config | 7.19.1 | 0..1 | -boolean |
* | description | 7.19.3 | 0..1 | -string |
- * | if-feature | 7.18.2 | 0..n | -TODO |
+ * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
* | max-elements | 7.7.4 | 0..1 | -int |
* | min-elements | 7.7.3 | 0..1 | -int |
- * | must | 7.5.3 | 0..n | -TODO |
+ * | must | 7.5.3 | 0..n | -YangMust |
* | ordered-by | 7.7.5 | 0..1 | -TODO |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* | type | 7.4 | 1 | -YangType |
* | units | 7.3.3 | 0..1 | -string |
- * | when | 7.19.5 | 0..1 | -TODO |
+ * | when | 7.19.5 | 0..1 | -YangWhen |
* +--------------+---------+-------------+------------------+
*/
@@ -56,7 +57,8 @@
* Represents leaf-list data represented in YANG.
*/
public class YangLeafList
- implements YangCommonInfo, Parsable, Cloneable, Serializable {
+ implements YangCommonInfo, Parsable, Cloneable, Serializable,
+ YangMustHolder, YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201637L;
@@ -133,6 +135,21 @@
private transient YangLeavesHolder containedIn;
/**
+ * List of must statement constraints.
+ */
+ private List<YangMust> mustConstraintList;
+
+ /**
+ * When data of the leaf.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
* Creates a YANG leaf-list.
*/
public YangLeafList() {
@@ -175,6 +192,26 @@
}
/**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
* Returns the description.
*
* @return the description
@@ -363,4 +400,40 @@
// TODO auto-generated method stub, to be implemented by parser
}
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
+ public List<YangMust> getListOfMust() {
+ return mustConstraintList;
+ }
+
+ @Override
+ public void setListOfMust(List<YangMust> mustConstraintList) {
+ this.mustConstraintList = mustConstraintList;
+ }
+
+ @Override
+ public void addMust(YangMust must) {
+ if (getListOfMust() == null) {
+ setListOfMust(new LinkedList<>());
+ }
+ getListOfMust().add(must);
+ }
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
index 632c5b7..a1e13ac 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
@@ -46,21 +46,21 @@
* | container | 7.5 | 0..n |-child nodes |
* | description | 7.19.3 | 0..1 |-string |
* | grouping | 7.11 | 0..n |-child nodes |
- * | if-feature | 7.18.2 | 0..n |-TODO |
+ * | if-feature | 7.18.2 | 0..n |-YangIfFeature |
* | key | 7.8.2 | 0..1 |-String list |
* | leaf | 7.6 | 0..n |-YangLeaf |
* | leaf-list | 7.7 | 0..n |-YangLeafList |
* | list | 7.8 | 0..n |-child nodes |
* | max-elements | 7.7.4 | 0..1 |-int |
* | min-elements | 7.7.3 | 0..1 |-int |
- * | must | 7.5.3 | 0..n |-TODO |
+ * | must | 7.5.3 | 0..n |-YangMust |
* | ordered-by | 7.7.5 | 0..1 |-TODO |
* | reference | 7.19.4 | 0..1 |-string |
* | status | 7.19.2 | 0..1 |-YangStatus |
* | typedef | 7.3 | 0..n |-child nodes |
* | unique | 7.8.3 | 0..n |-TODO |
- * | uses | 7.12 | 0..n |-child nodes(TODO)|
- * | when | 7.19.5 | 0..1 |-TODO |
+ * | uses | 7.12 | 0..n |-child nodes |
+ * | when | 7.19.5 | 0..1 |-YangWhen |
* +--------------+---------+-------------+------------------+
*/
@@ -69,7 +69,8 @@
*/
public class YangList
extends YangNode
- implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder,
+ YangMustHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201609L;
@@ -165,10 +166,24 @@
/**
* Status of the node.
*/
-
private YangStatusType status = YangStatusType.CURRENT;
/**
+ * List of must statement constraints.
+ */
+ private List<YangMust> mustConstraintList;
+
+ /**
+ * When data of the node.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
* Creates a YANG list object.
*/
public YangList() {
@@ -176,6 +191,24 @@
}
/**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
* Returns the YANG list name.
*
* @return YANG list name
@@ -643,4 +676,40 @@
return false;
// TODO When grouping linking is done this method has to be modified.
}
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
+ public List<YangMust> getListOfMust() {
+ return mustConstraintList;
+ }
+
+ @Override
+ public void setListOfMust(List<YangMust> mustConstraintList) {
+ this.mustConstraintList = mustConstraintList;
+ }
+
+ @Override
+ public void addMust(YangMust must) {
+ if (getListOfMust() == null) {
+ setListOfMust(new LinkedList<>());
+ }
+ getListOfMust().add(must);
+ }
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
index f14cfeb..16348e5 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
@@ -74,7 +74,7 @@
public class YangModule
extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
- RpcNotificationContainer {
+ RpcNotificationContainer, YangFeatureHolder {
private static final long serialVersionUID = 806201610L;
@@ -85,7 +85,7 @@
/**
* Reference:RFC 6020.
- * <p>
+ *
* The "contact" statement provides contact information for the module. The
* argument is a string that is used to specify contact information for the
* person or persons to whom technical queries concerning this module should
@@ -96,7 +96,7 @@
/**
* Reference:RFC 6020.
- * <p>
+ *
* The "description" statement takes as an argument a string that contains a
* human-readable textual description of this definition. The text is
* provided in a language (or languages) chosen by the module developer; for
@@ -125,13 +125,18 @@
private List<YangLeafList> listOfLeafList;
/**
+ * List of feature at root level in the module.
+ */
+ private List<YangFeature> listOfFeature;
+
+ /**
* Name space of the module.
*/
private YangNameSpace nameSpace;
/**
* 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
@@ -201,6 +206,11 @@
private List<YangResolutionInfo> usesResolutionList;
/**
+ * if-feature resolution list.
+ */
+ private List<YangResolutionInfo> ifFeatureResolutionList;
+
+ /**
* Creates a YANG node of module type.
*/
public YangModule() {
@@ -208,6 +218,7 @@
super(YangNodeType.MODULE_NODE);
derivedTypeResolutionList = new LinkedList<>();
usesResolutionList = new LinkedList<>();
+ ifFeatureResolutionList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
@@ -373,6 +384,24 @@
getListOfLeafList().add(leafList);
}
+ @Override
+ public List<YangFeature> getFeatureList() {
+ return listOfFeature;
+ }
+
+ @Override
+ public void addFeatureList(YangFeature feature) {
+ if (getFeatureList() == null) {
+ setListOfFeature(new LinkedList<>());
+ }
+ getFeatureList().add(feature);
+ }
+
+ @Override
+ public void setListOfFeature(List<YangFeature> listOfFeature) {
+ this.listOfFeature = listOfFeature;
+ }
+
/**
* Returns the name space of module elements.
*
@@ -558,10 +587,11 @@
public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
return derivedTypeResolutionList;
- } else {
+ } else if (type == ResolvableType.YANG_USES) {
return usesResolutionList;
+ } else {
+ return ifFeatureResolutionList;
}
-
}
@Override
@@ -571,6 +601,8 @@
derivedTypeResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList.add(resolutionInfo);
+ } else if (type == ResolvableType.YANG_IF_FEATURE) {
+ ifFeatureResolutionList.add(resolutionInfo);
}
}
@@ -581,6 +613,8 @@
derivedTypeResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList = resolutionList;
+ } else if (type == ResolvableType.YANG_IF_FEATURE) {
+ ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
}
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMust.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMust.java
index ead6c5d..c579003 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMust.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMust.java
@@ -55,7 +55,7 @@
/**
* Constraint info.
*/
- private String constratint;
+ private String constraint;
/**
* Description string.
@@ -78,17 +78,17 @@
*
* @return the constraint
*/
- public String getConstratint() {
- return constratint;
+ public String getConstraint() {
+ return constraint;
}
/**
* Sets the constraint.
*
- * @param constratint the constraint to set
+ * @param constraint the constraint to set
*/
- public void setConstratint(String constratint) {
- this.constratint = constratint;
+ public void setConstraint(String constraint) {
+ this.constraint = constraint;
}
/**
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMustHolder.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMustHolder.java
new file mode 100644
index 0000000..badd3d9
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMustHolder.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.List;
+
+/**
+ * Abstraction of must entity. It is used to abstract the data holders of must.
+ */
+public interface YangMustHolder {
+
+ /**
+ * Returns the list of must from data holder like container / list.
+ *
+ * @return the list of must
+ */
+ List<YangMust> getListOfMust();
+
+ /**
+ * Sets the list of must.
+ *
+ * @param mustConstraintList the list of must to set
+ */
+ void setListOfMust(List<YangMust> mustConstraintList);
+
+ /**
+ * Adds must in data holder like container / list.
+ *
+ * @param must the must to be added
+ */
+ void addMust(YangMust must);
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
index 6fba390..62ee584 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
@@ -60,7 +60,7 @@
* | container | 7.5 | 0..n | -child nodes |
* | description | 7.19.3 | 0..1 | -string |
* | grouping | 7.11 | 0..n | -child nodes |
- * | if-feature | 7.18.2 | 0..n | -TODO |
+ * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
* | leaf | 7.6 | 0..n | -YangLeaf |
* | leaf-list | 7.7 | 0..n | -YangLeafList |
* | list | 7.8 | 0..n | -child nodes |
@@ -76,7 +76,8 @@
*/
public class YangNotification
extends YangNode
- implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder,
+ YangIfFeatureHolder {
private static final long serialVersionUID = 806201611L;
@@ -111,6 +112,11 @@
private YangStatusType status = YangStatusType.CURRENT;
/**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
* Create a notification node.
*/
public YangNotification() {
@@ -221,4 +227,22 @@
public void setStatus(YangStatusType status) {
this.status = status;
}
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRevision.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRevision.java
index aa326fd..0a5342c 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRevision.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRevision.java
@@ -16,7 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
-
+import java.util.Date;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
@@ -41,6 +41,7 @@
* | reference | 7.19.4 | 0..1 |sring |
* +--------------+---------+-------------+------------------+
*/
+
/**
* Represents the information about the revision.
*/
@@ -51,7 +52,7 @@
/**
* Revision date. Date string in the format "YYYY-MM-DD"
*/
- private String revDate;
+ private Date revDate;
/**
* Description of revision.
@@ -74,7 +75,7 @@
*
* @return the revision date
*/
- public String getRevDate() {
+ public Date getRevDate() {
return revDate;
}
@@ -83,7 +84,7 @@
*
* @param revDate the revision date to set
*/
- public void setRevDate(String revDate) {
+ public void setRevDate(Date revDate) {
this.revDate = revDate;
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java
index 62b8dd1..72060ad 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java
@@ -16,6 +16,8 @@
package org.onosproject.yangutils.datamodel;
+import java.util.LinkedList;
+import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
@@ -44,7 +46,7 @@
* +--------------+---------+-------------+------------------+
* | description | 7.19.3 | 0..1 | -string |
* | grouping | 7.11 | 0..n | -child nodes |
- * | if-feature | 7.18.2 | 0..n | -TODO |
+ * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
* | input | 7.13.2 | 0..1 | -child nodes |
* | output | 7.13.3 | 0..1 | -child nodes |
* | reference | 7.19.4 | 0..1 | -string |
@@ -57,7 +59,7 @@
* Represents data model node to maintain information defined in YANG rpc.
*/
public class YangRpc extends YangNode implements YangCommonInfo, Parsable,
- CollisionDetector {
+ CollisionDetector, YangIfFeatureHolder {
private static final long serialVersionUID = 806201613L;
@@ -82,6 +84,11 @@
private YangStatusType status = YangStatusType.CURRENT;
/**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
* Create a rpc node.
*/
public YangRpc() {
@@ -156,4 +163,22 @@
public void setStatus(YangStatusType status) {
this.status = status;
}
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
index 8e1ba9d..be7a0c0 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
@@ -57,7 +57,7 @@
* | description | 7.19.3 | 0..1 | - string |
* | deviation | 7.18.3 | 0..n | - TODO |
* | extension | 7.17 | 0..n | - TODO |
- * | feature | 7.18.1 | 0..n | - TODO |
+ * | feature | 7.18.1 | 0..n | - YangFeature |
* | grouping | 7.11 | 0..n | - child nodes |
* | identity | 7.16 | 0..n | - TODO |
* | import | 7.1.5 | 0..n | - YangImport |
@@ -82,7 +82,7 @@
public class YangSubModule
extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
- RpcNotificationContainer {
+ RpcNotificationContainer, YangFeatureHolder {
private static final long serialVersionUID = 806201614L;
@@ -133,6 +133,11 @@
private List<YangLeafList> listOfLeafList;
/**
+ * List of feature at root level in the module.
+ */
+ private List<YangFeature> listOfFeature;
+
+ /**
* Organization owner of the sub-module.
*/
private String organization;
@@ -199,12 +204,18 @@
private List<YangResolutionInfo> usesResolutionList;
/**
+ * if-feature resolution list.
+ */
+ private List<YangResolutionInfo> ifFeatureResolutionList;
+
+ /**
* Creates a sub module node.
*/
public YangSubModule() {
super(YangNodeType.SUB_MODULE_NODE);
derivedTypeResolutionList = new LinkedList<>();
usesResolutionList = new LinkedList<>();
+ ifFeatureResolutionList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
@@ -538,8 +549,10 @@
public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
return derivedTypeResolutionList;
- } else {
+ } else if (type == ResolvableType.YANG_USES) {
return usesResolutionList;
+ } else {
+ return ifFeatureResolutionList;
}
}
@@ -550,6 +563,8 @@
derivedTypeResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList.add(resolutionInfo);
+ } else if (type == ResolvableType.YANG_IF_FEATURE) {
+ ifFeatureResolutionList.add(resolutionInfo);
}
}
@@ -560,6 +575,8 @@
derivedTypeResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList = resolutionList;
+ } else if (type == ResolvableType.YANG_IF_FEATURE) {
+ ifFeatureResolutionList = resolutionList;
}
}
@@ -601,4 +618,22 @@
yangImport.addReferenceToImport(yangNodeSet);
}
}
+
+ @Override
+ public List<YangFeature> getFeatureList() {
+ return listOfFeature;
+ }
+
+ @Override
+ public void addFeatureList(YangFeature feature) {
+ if (getFeatureList() == null) {
+ setListOfFeature(new LinkedList<>());
+ }
+ getFeatureList().add(feature);
+ }
+
+ @Override
+ public void setListOfFeature(List<YangFeature> listOfFeature) {
+ this.listOfFeature = listOfFeature;
+ }
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
index b0d9ed9..6f7137d 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
@@ -48,11 +48,11 @@
* +--------------+---------+-------------+------------------+
* | augment | 7.15 | 0..1 | -child nodes |
* | description | 7.19.3 | 0..1 | -string |
- * | if-feature | 7.18.2 | 0..n | -TODO |
+ * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
* | refine | 7.12.2 | 0..1 | -TODO |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
- * | when | 7.19.5 | 0..1 | -TODO |
+ * | when | 7.19.5 | 0..1 | -YangWhen |
* +--------------+---------+-------------+------------------+
*/
@@ -61,7 +61,8 @@
*/
public class YangUses
extends YangNode
- implements YangCommonInfo, Parsable, Resolvable, CollisionDetector {
+ implements YangCommonInfo, Parsable, Resolvable, CollisionDetector, YangWhenHolder,
+ YangIfFeatureHolder {
private static final long serialVersionUID = 806201617L;
@@ -91,6 +92,16 @@
private YangStatusType status;
/**
+ * When data of the node.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
* 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
@@ -144,6 +155,26 @@
}
/**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
* Returns the description.
*
* @return the description
@@ -503,4 +534,22 @@
public List<List<YangLeafList>> getUsesResolvedListOfLeafList() {
return resolvedGroupingLeafLists;
}
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangWhen.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangWhen.java
new file mode 100644
index 0000000..c508681
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangWhen.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The "when" statement makes its parent data definition statement
+ * conditional. The node defined by the parent data definition
+ * statement is only valid when the condition specified by the "when"
+ * statement is satisfied.
+ *
+ * The statement's argument is an XPath expression, which is used to formally
+ * specify this condition. If the XPath expression conceptually evaluates to
+ * "true" for a particular instance, then the node defined by the parent data
+ * definition statement is valid; otherwise, it is not.
+ *
+ * The when's sub-statements
+ *
+ * +---------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +---------------+---------+-------------+------------------+
+ * | description | 7.19.3 | 0..1 | -string |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * +---------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents information defined in YANG when.
+ */
+public class YangWhen implements YangDesc, YangReference, Parsable, Serializable {
+
+ private static final long serialVersionUID = 806201646L;
+
+ /**
+ * When condition info.
+ */
+ private String condition;
+
+ /**
+ * Description string.
+ */
+ private String description;
+
+ /**
+ * Reference string.
+ */
+ private String reference;
+
+ /**
+ * Creates a YANG when restriction.
+ */
+ public YangWhen() {
+ }
+
+ /**
+ * Returns the condition.
+ *
+ * @return the condition
+ */
+ public String getCondition() {
+ return condition;
+ }
+
+ /**
+ * Sets the condition.
+ *
+ * @param condition the condition to set
+ */
+ public void setCondition(String condition) {
+ this.condition = condition;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the textual reference.
+ *
+ * @return the reference
+ */
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ /**
+ * Sets the textual reference.
+ *
+ * @param reference the reference to set
+ */
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns WHEN_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.WHEN_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangWhenHolder.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangWhenHolder.java
new file mode 100644
index 0000000..1c7df4d
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangWhenHolder.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/**
+ * Abstraction of when entity. It is used to abstract the data holders of when.
+ */
+public interface YangWhenHolder {
+
+ /**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ YangWhen getWhen();
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ void setWhen(YangWhen when);
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
index 659773f..4b8a3a1 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -21,6 +21,7 @@
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.ResolvableType;
+import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
@@ -29,13 +30,14 @@
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-
/**
* Represents utilities for data model tree.
*/
public final class DataModelUtils {
+
/**
* Creates a new data model tree utility.
*/
@@ -161,11 +163,15 @@
.getEntityToResolve() instanceof YangType) {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_DERIVED_DATA_TYPE);
- } else {
+ } else if (resolutionInfo.getEntityToResolveInfo()
+ .getEntityToResolve() instanceof YangUses) {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_USES);
+ } else if (resolutionInfo.getEntityToResolveInfo()
+ .getEntityToResolve() instanceof YangIfFeature) {
+ resolutionNode.addToResolutionList(resolutionInfo,
+ ResolvableType.YANG_IF_FEATURE);
}
-
}
/**
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/ResolvableStatus.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/ResolvableStatus.java
index d476c8b..d31f67b 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/ResolvableStatus.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/ResolvableStatus.java
@@ -46,6 +46,11 @@
* Identifies that resolvable entity is inter file linked (i.e. complete
* linking with external files).
*/
- INTER_FILE_LINKED
+ INTER_FILE_LINKED,
+
+ /**
+ * Identifies that resolvable entity is referred node is not defined.
+ */
+ UNDEFINED
}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfoImpl.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfoImpl.java
index 6b6be58..17285f6 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfoImpl.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangEntityToResolveInfoImpl.java
@@ -18,6 +18,7 @@
import java.io.Serializable;
import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
+import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangUses;
@@ -76,6 +77,8 @@
prefix = ((YangType<?>) entityToBeResolved).getPrefix();
} else if (entityToBeResolved instanceof YangUses) {
prefix = ((YangUses) entityToBeResolved).getPrefix();
+ } else if (entityToBeResolved instanceof YangIfFeature) {
+ prefix = ((YangIfFeature) entityToBeResolved).getPrefix();
} else {
throw new LinkerException("Linker Exception: Entity to resolved is other than type/uses");
}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
index 96e1bcc..dc321bd 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
@@ -156,6 +156,8 @@
throws LinkerException {
for (YangNode yangNode : yangNodeSet) {
try {
+ ((YangReferenceResolver) yangNode)
+ .resolveInterFileLinking(ResolvableType.YANG_IF_FEATURE);
((YangReferenceResolver) yangNode).resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
index 2a710dc..0b5a464 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
@@ -17,15 +17,22 @@
package org.onosproject.yangutils.linker.impl;
import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
import java.util.Stack;
import org.onosproject.yangutils.datamodel.Resolvable;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
+import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
+import org.onosproject.yangutils.datamodel.YangFeature;
+import org.onosproject.yangutils.datamodel.YangFeatureHolder;
import org.onosproject.yangutils.datamodel.YangGrouping;
+import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangType;
@@ -39,9 +46,11 @@
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.LINKED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
+import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNDEFINED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.linker.YangLinkingPhase.INTER_FILE;
import static org.onosproject.yangutils.linker.YangLinkingPhase.INTRA_FILE;
+import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
@@ -64,7 +73,7 @@
/**
* Error line number.
*/
- private transient int lineNumber;
+ private transient int lineNumber;
/**
* Error character position in number.
@@ -115,7 +124,7 @@
setCurReferenceResolver(dataModelRootNode);
- // Current node to resolve, it can be a YANG type or YANG uses.
+ // Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature.
T entityToResolve = getEntityToResolveInfo().getEntityToResolve();
// Check if linking is already done
@@ -128,7 +137,8 @@
return;
}
} else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ throw new DataModelException("Data Model Exception: Entity to resolved is other than " +
+ "type/uses/if-feature");
}
// Push the initial entity to resolve in stack.
@@ -154,57 +164,60 @@
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(INTRA_FILE);
- getPartialResolvedStack().pop();
- break;
- }
-
- case INTRA_FILE_RESOLVED: {
- /*
- * Pop the top of the stack.
- */
- getPartialResolvedStack().pop();
- break;
- }
-
- case UNRESOLVED: {
- linkTopOfStackReferenceUpdateStack();
-
- if (resolvable.getResolvableStatus() == UNRESOLVED) {
- // If current entity is still not resolved, then
- // linking/resolution has failed.
- String errorInfo;
- if (resolvable instanceof YangType) {
- errorInfo = TYPEDEF_LINKER_ERROR;
- } else {
- errorInfo = GROUPING_LINKER_ERROR;
- }
- DataModelException dataModelException = new DataModelException(errorInfo);
- dataModelException.setLine(getLineNumber());
- dataModelException.setCharPosition(getCharPosition());
- throw dataModelException;
+ 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;
}
- break;
- }
- default: {
- throw new DataModelException("Data Model Exception: Unsupported, linker state");
- }
+
+ 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(INTRA_FILE);
+ getPartialResolvedStack().pop();
+ break;
+ }
+
+ case INTRA_FILE_RESOLVED: {
+ /*
+ * Pop the top of the stack.
+ */
+ getPartialResolvedStack().pop();
+ break;
+ }
+
+ case UNRESOLVED: {
+ linkTopOfStackReferenceUpdateStack();
+
+ if (resolvable.getResolvableStatus() == UNRESOLVED) {
+ // If current entity is still not resolved, then
+ // linking/resolution has failed.
+ String errorInfo;
+ if (resolvable instanceof YangType) {
+ errorInfo = TYPEDEF_LINKER_ERROR;
+ } else if (resolvable instanceof YangUses) {
+ errorInfo = GROUPING_LINKER_ERROR;
+ } else {
+ errorInfo = FEATURE_LINKER_ERROR;
+ }
+ DataModelException dataModelException =
+ new DataModelException(errorInfo);
+ dataModelException.setLine(getLineNumber());
+ dataModelException.setCharPosition(getCharPosition());
+ throw dataModelException;
+ }
+ break;
+ }
+ default: {
+ throw new DataModelException("Data Model Exception: Unsupported, linker state");
+ }
}
@@ -222,8 +235,9 @@
private void resolveTopOfStack(YangLinkingPhase linkingPhase)
throws DataModelException {
((Resolvable) getCurrentEntityToResolveFromStack()).resolve();
- if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != INTRA_FILE_RESOLVED) {
- // Sets the resolution status in inside the type/uses.
+ if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != INTRA_FILE_RESOLVED
+ && ((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != UNDEFINED) {
+ // Sets the resolution status in inside the type/uses/if-feature.
((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(RESOLVED);
}
}
@@ -253,21 +267,27 @@
YangNode potentialAncestorWithReferredNode = getPartialResolvedStack().peek()
.getHolderOfEntityToResolve();
- /**
- * Traverse up in the ancestor tree to check if the referred node is
- * defined
- */
- while (potentialAncestorWithReferredNode != null) {
+ if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
+ resolveSelfFileLinkingForIfFeature(potentialAncestorWithReferredNode);
+ return;
+ } else {
/**
- * Check for the referred node defined in a ancestor scope
+ * Traverse up in the ancestor tree to check if the referred node is
+ * defined
*/
- YangNode potentialReferredNode = potentialAncestorWithReferredNode.getChild();
- if (isReferredNodeInSiblingListProcessed(potentialReferredNode)) {
- return;
- }
+ while (potentialAncestorWithReferredNode != null) {
- potentialAncestorWithReferredNode = potentialAncestorWithReferredNode.getParent();
+ /**
+ * Check for the referred node defined in a ancestor scope
+ */
+ YangNode potentialReferredNode = potentialAncestorWithReferredNode.getChild();
+ if (isReferredNodeInSiblingListProcessed(potentialReferredNode)) {
+ return;
+ }
+
+ potentialAncestorWithReferredNode = potentialAncestorWithReferredNode.getParent();
+ }
}
/*
@@ -280,6 +300,56 @@
}
/**
+ * Resolves self file linking for if-feature.
+ *
+ * @param potentialAncestorWithReferredNode if-feature holder node
+ * @throws DataModelException DataModelException a violation of data model
+ * rules
+ */
+ private void resolveSelfFileLinkingForIfFeature(YangNode potentialAncestorWithReferredNode)
+ throws DataModelException {
+
+ YangFeatureHolder featureHolder = getFeatureHolder(potentialAncestorWithReferredNode);
+ YangNode potentialReferredNode = (YangNode) featureHolder;
+ if (isReferredNode(potentialReferredNode)) {
+
+ // Adds reference link of entity to the node under resolution.
+ addReferredEntityLink(potentialReferredNode, LINKED);
+
+ /**
+ * resolve the reference and update the partial resolution stack
+ * with any further recursive references
+ */
+ addUnresolvedRecursiveReferenceToStack(potentialReferredNode);
+ return;
+ }
+
+ /*
+ * In case prefix is not present it's a candidate for inter-file
+ * resolution via include list.
+ */
+ if (getRefPrefix() == null) {
+ ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
+ }
+ }
+
+
+ /**
+ * Returns feature holder(module/sub-module node) .
+ *
+ * @param potentialAncestorWithReferredNode if-feature holder node
+ */
+ private YangFeatureHolder getFeatureHolder(YangNode potentialAncestorWithReferredNode) {
+ while (potentialAncestorWithReferredNode != null) {
+ if (potentialAncestorWithReferredNode instanceof YangFeatureHolder) {
+ return (YangFeatureHolder) potentialAncestorWithReferredNode;
+ }
+ potentialAncestorWithReferredNode = potentialAncestorWithReferredNode.getParent();
+ }
+ return null;
+ }
+
+ /**
* Checks if the reference in self file or in external file.
*
* @return true if self file reference, false otherwise
@@ -352,6 +422,14 @@
*/
return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
}
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
+ if (potentialReferredNode instanceof YangFeatureHolder) {
+ /*
+ * 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");
}
@@ -381,12 +459,31 @@
((YangUses) getCurrentEntityToResolveFromStack()).getName())) {
return true;
}
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
+ return isFeatureDefinedInNode(node);
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
}
return false;
}
+ private boolean isFeatureDefinedInNode(YangNode node) throws DataModelException {
+ YangNodeIdentifier ifFeature = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getName();
+ List<YangFeature> featureList = ((YangFeatureHolder) node).getFeatureList();
+ if (featureList != null && !featureList.isEmpty()) {
+ Iterator<YangFeature> iterator = featureList.iterator();
+ while (iterator.hasNext()) {
+ YangFeature feature = iterator.next();
+ if (ifFeature.getName().equals(feature.getName())) {
+ ((YangIfFeature) getCurrentEntityToResolveFromStack()).setReferredFeature(feature);
+ ((YangIfFeature) getCurrentEntityToResolveFromStack()).setReferredFeatureHolder(node);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
/**
* Adds reference of grouping/typedef in uses/type.
*
@@ -403,6 +500,8 @@
} else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
((YangUses) getCurrentEntityToResolveFromStack())
.setRefGroup((YangGrouping) referredNode);
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
+ // do nothing , referred node is already set
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
}
@@ -440,6 +539,8 @@
* return true, else return false.
*/
addUnResolvedUsesToStack(referredNode);
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
+ addUnResolvedIfFeatureToStack(referredNode);
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
}
@@ -469,6 +570,26 @@
}
/**
+ * Returns if there is any unresolved if-feature in feature.
+ *
+ * @param node module/submodule node
+ */
+ private void addUnResolvedIfFeatureToStack(YangNode node) {
+ YangFeature refFeature = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getReferredFeature();
+ List<YangIfFeature> ifFeatureList = refFeature.getIfFeatureList();
+ if (ifFeatureList != null && !ifFeatureList.isEmpty()) {
+ Iterator<YangIfFeature> ifFeatureIterator = ifFeatureList.iterator();
+ while (ifFeatureIterator.hasNext()) {
+ YangIfFeature ifFeature = ifFeatureIterator.next();
+ YangEntityToResolveInfo<YangIfFeature> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
+ unResolvedEntityInfo.setEntityToResolve(ifFeature);
+ unResolvedEntityInfo.setHolderOfEntityToResolve(node);
+ addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
+ }
+ }
+ }
+
+ /**
* Returns stack of YANG type with partially resolved YANG construct
* hierarchy.
*
@@ -600,6 +721,8 @@
refPrefix = ((YangType<?>) getCurrentEntityToResolveFromStack()).getPrefix();
} else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
refPrefix = ((YangUses) getCurrentEntityToResolveFromStack()).getPrefix();
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
+ refPrefix = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getPrefix();
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
}
@@ -623,41 +746,50 @@
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 RESOLVED: {
+ /*
+ * If the entity is already resolved in the stack, then pop
+ * it and continue with the remaining stack elements to
+ * resolve
+ */
+ getPartialResolvedStack().pop();
+ break;
+ }
- case INTER_FILE_LINKED: {
- /*
- * If the top of the stack is already linked then resolve
- * the references and pop the entity and continue with
- * remaining stack elements to resolve
- */
- resolveTopOfStack(INTER_FILE);
- getPartialResolvedStack().pop();
- break;
- }
+ case INTER_FILE_LINKED: {
+ /*
+ * If the top of the stack is already linked then resolve
+ * the references and pop the entity and continue with
+ * remaining stack elements to resolve
+ */
+ resolveTopOfStack(INTER_FILE);
+ getPartialResolvedStack().pop();
+ break;
+ }
- case INTRA_FILE_RESOLVED: {
- /*
- * If the top of the stack is intra file resolved then check
- * if top of stack is linked, if not link it using
- * import/include list and push the linked referred entity
- * to the stack, otherwise only push it to the stack.
- */
- linkInterFileTopOfStackRefUpdateStack();
- break;
- }
+ case INTRA_FILE_RESOLVED: {
+ /*
+ * If the top of the stack is intra file resolved then check
+ * if top of stack is linked, if not link it using
+ * import/include list and push the linked referred entity
+ * to the stack, otherwise only push it to the stack.
+ */
+ linkInterFileTopOfStackRefUpdateStack();
+ break;
+ }
- default: {
- throw new DataModelException("Data Model Exception: Unsupported, linker state");
- }
+ case UNDEFINED: {
+ /*
+ * In case of if-feature resolution, if referred "feature" is not
+ * defined then the resolvable status will be undefined.
+ */
+ getPartialResolvedStack().pop();
+ break;
+ }
+
+ default: {
+ throw new DataModelException("Data Model Exception: Unsupported, linker state");
+ }
}
@@ -701,6 +833,11 @@
return;
}
}
+
+ if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
+ ((YangIfFeature) getCurrentEntityToResolveFromStack()).setResolvableStatus(UNDEFINED);
+ return;
+ }
// Exception when referred typedef/grouping is not found.
DataModelException dataModelException = new DataModelException("YANG file error: Referred " +
"typedef/grouping for a given type/uses can't be found.");
@@ -735,6 +872,8 @@
linkedNode = findRefTypedef(yangInclude.getIncludedNode());
} else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
linkedNode = findRefGrouping(yangInclude.getIncludedNode());
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
+ linkedNode = findRefFeature(yangInclude.getIncludedNode());
}
if (linkedNode != null) {
// Add the link to external entity.
@@ -776,6 +915,8 @@
linkedNode = findRefTypedef(yangImport.getImportedNode());
} else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
linkedNode = findRefGrouping(yangImport.getImportedNode());
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
+ linkedNode = findRefFeature(yangImport.getImportedNode());
}
if (linkedNode != null) {
// Add the link to external entity.
@@ -816,6 +957,8 @@
return (T) derivedInfo.getReferredTypeDef();
} else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
return (T) ((YangUses) getCurrentEntityToResolveFromStack()).getRefGroup();
+ } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
+ return (T) ((YangIfFeature) getCurrentEntityToResolveFromStack()).getReferredFeatureHolder();
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
}
@@ -842,6 +985,29 @@
}
/**
+ * Finds the referred feature node at the root level of imported/included node.
+ *
+ * @param refNode module/sub-module node
+ * @return referred feature
+ */
+ private YangNode findRefFeature(YangNode refNode) {
+ YangNodeIdentifier ifFeature = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getName();
+ List<YangFeature> featureList = ((YangFeatureHolder) refNode).getFeatureList();
+
+ if (featureList != null && !featureList.isEmpty()) {
+ Iterator<YangFeature> iterator = featureList.iterator();
+ while (iterator.hasNext()) {
+ YangFeature feature = iterator.next();
+ if (ifFeature.getName().equals(feature.getName())) {
+ ((YangIfFeature) getCurrentEntityToResolveFromStack()).setReferredFeature(feature);
+ return refNode;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
* Finds the referred typedef node at the root level of imported/included node.
*
* @param refNode module/sub-module node
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
index 194d32f..8f08842 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
@@ -40,7 +40,9 @@
import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener;
import org.onosproject.yangutils.parser.impl.listeners.EnumListener;
import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
+import org.onosproject.yangutils.parser.impl.listeners.FeatureListener;
import org.onosproject.yangutils.parser.impl.listeners.GroupingListener;
+import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener;
import org.onosproject.yangutils.parser.impl.listeners.ImportListener;
import org.onosproject.yangutils.parser.impl.listeners.IncludeListener;
import org.onosproject.yangutils.parser.impl.listeners.InputListener;
@@ -53,6 +55,7 @@
import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener;
import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener;
import org.onosproject.yangutils.parser.impl.listeners.ModuleListener;
+import org.onosproject.yangutils.parser.impl.listeners.MustListener;
import org.onosproject.yangutils.parser.impl.listeners.NotificationListener;
import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener;
import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener;
@@ -76,6 +79,7 @@
import org.onosproject.yangutils.parser.impl.listeners.UsesListener;
import org.onosproject.yangutils.parser.impl.listeners.ValueListener;
import org.onosproject.yangutils.parser.impl.listeners.VersionListener;
+import org.onosproject.yangutils.parser.impl.listeners.WhenListener;
import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT;
import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
@@ -473,22 +477,22 @@
@Override
public void enterFeatureStatement(GeneratedYangParser.FeatureStatementContext ctx) {
- handleUnsupportedYangConstruct(YangConstructType.FEATURE_DATA, ctx, CURRENTLY_UNSUPPORTED);
+ FeatureListener.processFeatureEntry(this, ctx);
}
@Override
public void exitFeatureStatement(GeneratedYangParser.FeatureStatementContext ctx) {
- //TODO: to be implemented
+ FeatureListener.processFeatureExit(this, ctx);
}
@Override
public void enterFeatureBody(GeneratedYangParser.FeatureBodyContext ctx) {
- //TODO : to be implemented
+ // do nothing
}
@Override
public void exitFeatureBody(GeneratedYangParser.FeatureBodyContext ctx) {
- //TODO : to be implemented
+ // do nothing.
}
@Override
@@ -503,12 +507,12 @@
@Override
public void enterIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext ctx) {
- // TODO: to be implemented
+ IfFeatureListener.processIfFeatureEntry(this, ctx);
}
@Override
public void exitIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext ctx) {
- // TODO: to be implemented
+ // do nothing.
}
@Override
@@ -813,12 +817,12 @@
@Override
public void enterMustStatement(GeneratedYangParser.MustStatementContext ctx) {
- // TODO: to be implemented
+ MustListener.processMustEntry(this, ctx);
}
@Override
public void exitMustStatement(GeneratedYangParser.MustStatementContext ctx) {
- // TODO: to be implemented
+ MustListener.processMustExit(this, ctx);
}
@Override
@@ -1083,12 +1087,12 @@
@Override
public void enterWhenStatement(GeneratedYangParser.WhenStatementContext ctx) {
- // TODO: to be implemented
+ WhenListener.processWhenEntry(this, ctx);
}
@Override
public void exitWhenStatement(GeneratedYangParser.WhenStatementContext ctx) {
- // TODO: to be implemented
+ WhenListener.processWhenExit(this, ctx);
}
@Override
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FeatureListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FeatureListener.java
new file mode 100644
index 0000000..6a70f31
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FeatureListener.java
@@ -0,0 +1,119 @@
+/*
+ * 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.parser.impl.listeners;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * feature-stmt = feature-keyword sep identifier-arg-str optsep
+ * (";" /
+ * "{" stmtsep
+ * ;; these stmts can appear in any order
+ * *(if-feature-stmt stmtsep)
+ * [status-stmt stmtsep]
+ * [description-stmt stmtsep]
+ * [reference-stmt stmtsep]
+ * "}")
+ *
+ *
+ *
+ * ANTLR grammar rule
+ * featureStatement : FEATURE_KEYWORD string (STMTEND | LEFT_CURLY_BRACE featureBody RIGHT_CURLY_BRACE);
+ */
+
+import org.onosproject.yangutils.datamodel.YangFeature;
+import org.onosproject.yangutils.datamodel.YangFeatureHolder;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.FEATURE_DATA;
+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.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;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/**
+ * Represents listener based call back function corresponding to the "feature"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class FeatureListener {
+
+ /**
+ * Creates a new feature listener.
+ */
+ private FeatureListener() {
+ }
+
+ /**
+ * Performs validation and updates the data model tree.It is called when parser receives
+ * an input matching the grammar rule (feature).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processFeatureEntry(TreeWalkListener listener,
+ GeneratedYangParser.FeatureStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, FEATURE_DATA, ctx.string().getText(), ENTRY);
+
+ String identifier = getValidIdentifier(ctx.string().getText(), FEATURE_DATA, ctx);
+
+ // Obtain the node of the stack.
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ if (tmpNode instanceof YangFeatureHolder) {
+ YangFeatureHolder featureHolder = (YangFeatureHolder) tmpNode;
+
+ YangFeature feature = new YangFeature();
+ feature.setName(identifier);
+
+ featureHolder.addFeatureList(feature);
+ listener.getParsedDataStack().push(feature);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, FEATURE_DATA,
+ ctx.string().getText(), ENTRY));
+ }
+ }
+
+ /**
+ * Perform validations and updates the data model tree.It is called when parser exits from
+ * grammar rule(feature).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processFeatureExit(TreeWalkListener listener,
+ GeneratedYangParser.FeatureStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, FEATURE_DATA, ctx.string().getText(), EXIT);
+
+ if (listener.getParsedDataStack().peek() instanceof YangFeature) {
+ listener.getParsedDataStack().pop();
+ } else {
+ throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, FEATURE_DATA,
+ ctx.string().getText(), EXIT));
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IfFeatureListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IfFeatureListener.java
new file mode 100644
index 0000000..29899de
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IfFeatureListener.java
@@ -0,0 +1,143 @@
+/*
+ * 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.parser.impl.listeners;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ *
+ * if-feature-stmt = if-feature-keyword sep identifier-ref-arg-str
+ * optsep stmtend
+ *
+ * ANTLR grammar rule
+ * ifFeatureStatement : IF_FEATURE_KEYWORD string STMTEND;
+ */
+
+import org.onosproject.yangutils.datamodel.YangFeature;
+import org.onosproject.yangutils.datamodel.YangIfFeature;
+import org.onosproject.yangutils.datamodel.YangIfFeatureHolder;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangLeafList;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+import org.onosproject.yangutils.datamodel.YangResolutionInfo;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
+import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IF_FEATURE_DATA;
+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.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/**
+ * Represents listener based call back function corresponding to the "if-feature"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class IfFeatureListener {
+
+ /**
+ * Creates a new IfFeature listener.
+ */
+ private IfFeatureListener() {
+ }
+
+ /**
+ * Performs validation and updates the data model tree.It is called when parser receives
+ * an input matching the grammar rule (if-feature).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processIfFeatureEntry(TreeWalkListener listener,
+ GeneratedYangParser.IfFeatureStatementContext ctx) {
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, IF_FEATURE_DATA, ctx.string().getText(), ENTRY);
+
+ // Validate if-feature argument string
+ YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(),
+ IF_FEATURE_DATA, ctx);
+
+ YangIfFeature ifFeature = new YangIfFeature();
+ ifFeature.setName(nodeIdentifier);
+ ifFeature.setResolvableStatus(UNRESOLVED);
+ YangIfFeatureHolder ifFeatureHolder;
+
+ // Obtain the node of the stack.
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ if (tmpNode instanceof YangIfFeatureHolder) {
+ ifFeatureHolder = (YangIfFeatureHolder) tmpNode;
+ ifFeatureHolder.addIfFeatureList(ifFeature);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IF_FEATURE_DATA,
+ ctx.string().getText(), ENTRY));
+ }
+
+ // Add resolution information to the list
+ Parsable parentNode;
+ if (tmpNode instanceof YangLeafList || tmpNode instanceof YangLeaf
+ || tmpNode instanceof YangFeature) {
+ Parsable leafData = listener.getParsedDataStack().pop();
+ parentNode = listener.getParsedDataStack().peek();
+ listener.getParsedDataStack().push(leafData);
+ } else {
+ parentNode = tmpNode;
+ }
+
+ // Verify parent node of leaf
+ if (!(parentNode instanceof YangNode)) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IF_FEATURE_DATA,
+ ctx.string().getText(), EXIT));
+ }
+
+ int errorLine = ctx.getStart().getLine();
+ int errorPosition = ctx.getStart().getCharPositionInLine();
+ YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangIfFeature>(ifFeature,
+ (YangNode) parentNode, errorLine,
+ errorPosition);
+ addToResolutionList(resolutionInfo, ctx);
+ }
+
+ /**
+ * Add to resolution list.
+ *
+ * @param resolutionInfo resolution information.
+ * @param ctx context object of the grammar rule
+ */
+ private static void addToResolutionList(YangResolutionInfo<YangIfFeature> resolutionInfo,
+ GeneratedYangParser.IfFeatureStatementContext ctx) {
+
+ try {
+ addResolutionInfo(resolutionInfo);
+ } catch (DataModelException e) {
+ throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+ IF_FEATURE_DATA, ctx.string().getText(), EXIT, e.getMessage()));
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
index ef1af2d..05cfdb3 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
@@ -16,11 +16,13 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import java.util.Date;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
@@ -34,8 +36,8 @@
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;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getCurrentDateForRevision;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.setCurrentDateForRevision;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangModuleNode;
@@ -91,13 +93,6 @@
yangModule.setVersion((byte) 1);
}
- if (ctx.moduleBody().revisionStatements().revisionStatement().isEmpty()) {
- String currentDate = setCurrentDateForRevision();
- YangRevision currentRevision = new YangRevision();
- currentRevision.setRevDate(currentDate);
- yangModule.setRevision(currentRevision);
- }
-
listener.getParsedDataStack().push(yangModule);
}
@@ -113,12 +108,23 @@
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, MODULE_DATA, ctx.identifier().getText(), EXIT);
- if (!(listener.getParsedDataStack().peek() instanceof YangModule)) {
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ if (!(tmpNode instanceof YangModule)) {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA,
ctx.identifier().getText(), EXIT));
}
+
+ if (((YangModule) tmpNode).getRevision() == null) {
+ Date currentDate = getCurrentDateForRevision();
+ YangRevision currentRevision = new YangRevision();
+ currentRevision.setRevDate(currentDate);
+ ((YangModule) tmpNode).setRevision(currentRevision);
+ }
+
try {
((YangReferenceResolver) listener.getParsedDataStack()
+ .peek()).resolveSelfFileLinking(ResolvableType.YANG_IF_FEATURE);
+ ((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MustListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MustListener.java
new file mode 100644
index 0000000..b6cbf20
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MustListener.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangMust;
+import org.onosproject.yangutils.datamodel.YangMustHolder;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MUST_DATA;
+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.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;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ *
+ * must-stmt = must-keyword sep string optsep
+ * (";" /
+ * "{" stmtsep
+ * ;; these stmts can appear in any order
+ * [error-message-stmt stmtsep]
+ * [error-app-tag-stmt stmtsep]
+ * [description-stmt stmtsep]
+ * [reference-stmt stmtsep]
+ * "}")
+ *
+ * ANTLR grammar rule
+ * mustStatement : MUST_KEYWORD string (STMTEND | LEFT_CURLY_BRACE commonStatements RIGHT_CURLY_BRACE);
+ */
+
+/**
+ * Represents listener based call back function corresponding to the
+ * "must" rule defined in ANTLR grammar file for corresponding ABNF rule
+ * in RFC 6020.
+ */
+public final class MustListener {
+
+ /**
+ * Creates a new must listener.
+ */
+ private MustListener() {
+ }
+
+ /**
+ * Perform validations and updates the data model tree.It is called when parser
+ * receives an input matching the grammar rule (must).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processMustEntry(TreeWalkListener listener,
+ GeneratedYangParser.MustStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, MUST_DATA, ctx.string().getText(), ENTRY);
+ String constraint = removeQuotesAndHandleConcat(ctx.string().getText());
+
+ // Obtain the node of the stack.
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ if (tmpNode instanceof YangMustHolder) {
+
+ YangMust must = new YangMust();
+ must.setConstraint(constraint);
+
+ YangMustHolder mustHolder = (YangMustHolder) tmpNode;
+ mustHolder.addMust(must);
+
+ listener.getParsedDataStack().push(must);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MUST_DATA,
+ ctx.string().getText(), ENTRY));
+ }
+
+ }
+
+ /**
+ * Performs validation and updates the data model tree.It is called when parser
+ * exits from grammar rule (must).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processMustExit(TreeWalkListener listener,
+ GeneratedYangParser.MustStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, MUST_DATA, ctx.string().getText(), EXIT);
+
+ if (listener.getParsedDataStack().peek() instanceof YangMust) {
+ listener.getParsedDataStack().pop();
+ } else {
+ throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MUST_DATA,
+ ctx.string().getText(), EXIT));
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListener.java
index bb701a6..3ff67fe 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListener.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import java.util.Date;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.utils.Parsable;
@@ -28,8 +29,7 @@
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_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.isDateValid;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidDateFromString;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
@@ -87,13 +87,7 @@
checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATE_DATA, ctx.dateArgumentString().getText(),
ENTRY);
- String date = removeQuotesAndHandleConcat(ctx.dateArgumentString().getText());
- if (!isDateValid(date)) {
- ParserException parserException = new ParserException("YANG file error: Input date is not correct");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
+ Date date = getValidDateFromString(ctx.dateArgumentString().getText(), ctx);
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListener.java
index 36d028a..cb633b8 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListener.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import java.util.Date;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.YangSubModule;
@@ -31,8 +32,7 @@
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;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.isDateValid;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidDateFromString;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
@@ -88,20 +88,7 @@
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.dateArgumentString().getText(), ENTRY);
- // Validate for reverse chronological order of revision & for revision
- // value.
- if (!validateRevision(listener, ctx)) {
- return;
- // TODO to be implemented.
- }
-
- String date = removeQuotesAndHandleConcat(ctx.dateArgumentString().getText());
- if (!isDateValid(date)) {
- ParserException parserException = new ParserException("YANG file error: Input date is not correct");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
+ Date date = getValidDateFromString(ctx.dateArgumentString().getText(), ctx);
YangRevision revisionNode = new YangRevision();
revisionNode.setRevDate(date);
@@ -134,12 +121,26 @@
switch (tmpNode.getYangConstructType()) {
case MODULE_DATA: {
YangModule module = (YangModule) tmpNode;
- module.setRevision((YangRevision) tmpRevisionNode);
+ if (module.getRevision() != null) {
+ Date curRevisionDate = module.getRevision().getRevDate();
+ if (curRevisionDate.before(((YangRevision) tmpRevisionNode).getRevDate())) {
+ module.setRevision((YangRevision) tmpRevisionNode);
+ }
+ } else {
+ module.setRevision((YangRevision) tmpRevisionNode);
+ }
break;
}
case SUB_MODULE_DATA: {
YangSubModule subModule = (YangSubModule) tmpNode;
- subModule.setRevision((YangRevision) tmpRevisionNode);
+ if (subModule.getRevision() != null) {
+ Date curRevisionDate = subModule.getRevision().getRevDate();
+ if (curRevisionDate.before(((YangRevision) tmpRevisionNode).getRevDate())) {
+ subModule.setRevision((YangRevision) tmpRevisionNode);
+ }
+ } else {
+ subModule.setRevision((YangRevision) tmpRevisionNode);
+ }
break;
}
default:
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
index 639906a..b2223b8 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
@@ -16,11 +16,13 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import java.util.Date;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
@@ -34,8 +36,8 @@
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;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getCurrentDateForRevision;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.setCurrentDateForRevision;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangSubModuleNode;
@@ -94,13 +96,6 @@
yangSubModule.setVersion((byte) 1);
}
- if (ctx.submoduleBody().revisionStatements().revisionStatement().isEmpty()) {
- String currentDate = setCurrentDateForRevision();
- YangRevision currentRevision = new YangRevision();
- currentRevision.setRevDate(currentDate);
- yangSubModule.setRevision(currentRevision);
- }
-
listener.getParsedDataStack().push(yangSubModule);
}
@@ -118,12 +113,23 @@
checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(),
EXIT);
- if (!(listener.getParsedDataStack().peek() instanceof YangSubModule)) {
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ if (!(tmpNode instanceof YangSubModule)) {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA,
ctx.identifier().getText(), EXIT));
}
+
+ if (((YangSubModule) tmpNode).getRevision() == null) {
+ Date currentDate = getCurrentDateForRevision();
+ YangRevision currentRevision = new YangRevision();
+ currentRevision.setRevDate(currentDate);
+ ((YangSubModule) tmpNode).setRevision(currentRevision);
+ }
+
try {
((YangReferenceResolver) listener.getParsedDataStack().peek())
+ .resolveSelfFileLinking(ResolvableType.YANG_IF_FEATURE);
+ ((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/WhenListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/WhenListener.java
new file mode 100644
index 0000000..15092a1
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/WhenListener.java
@@ -0,0 +1,119 @@
+/*
+ * 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.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangWhen;
+import org.onosproject.yangutils.datamodel.YangWhenHolder;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_DATA;
+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.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;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ *
+ * when-stmt = when-keyword sep string optsep
+ * (";" /
+ * "{" stmtsep
+ * ;; these stmts can appear in any order
+ * [description-stmt stmtsep]
+ * [reference-stmt stmtsep]
+ * "}")
+ *
+ * ANTLR grammar rule
+ * whenStatement : WHEN_KEYWORD string (STMTEND | LEFT_CURLY_BRACE ((descriptionStatement? referenceStatement?)
+ * | (referenceStatement? descriptionStatement?)) RIGHT_CURLY_BRACE);
+ */
+
+/**
+ * Represents listener based call back function corresponding to the
+ * "when" rule defined in ANTLR grammar file for corresponding ABNF rule
+ * in RFC 6020.
+ */
+public final class WhenListener {
+
+ /**
+ * Creates a new when listener.
+ */
+ private WhenListener() {
+ }
+
+ /**
+ * Perform validations and updates the data model tree.It is called when parser
+ * receives an input matching the grammar rule (when).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processWhenEntry(TreeWalkListener listener,
+ GeneratedYangParser.WhenStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, WHEN_DATA, ctx.string().getText(), ENTRY);
+ String condition = removeQuotesAndHandleConcat(ctx.string().getText());
+
+ YangWhenHolder whenHolder;
+
+ // Obtain the node of the stack.
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ if (tmpNode instanceof YangWhenHolder) {
+ whenHolder = (YangWhenHolder) tmpNode;
+
+ YangWhen when = new YangWhen();
+ when.setCondition(condition);
+
+ whenHolder.setWhen(when);
+ listener.getParsedDataStack().push(when);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
+ WHEN_DATA, ctx.string().getText(), ENTRY));
+ }
+ }
+
+ /**
+ * Performs validation and updates the data model tree.It is called when parser
+ * exits from grammar rule (when).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processWhenExit(TreeWalkListener listener,
+ GeneratedYangParser.WhenStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, WHEN_DATA, ctx.string().getText(), EXIT);
+
+ if (listener.getParsedDataStack().peek() instanceof YangWhen) {
+ listener.getParsedDataStack().pop();
+ } else {
+ throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, WHEN_DATA,
+ ctx.string().getText(), EXIT));
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
index d05c8d0..e2097fc 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
@@ -18,7 +18,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.Calendar;
+import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
@@ -30,20 +30,18 @@
import org.onosproject.yangutils.parser.exceptions.ParserException;
import static org.onosproject.yangutils.utils.UtilConstants.ADD;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
-import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.CARET;
+import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
-import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
-import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
-import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_IDENTIFIER;
+import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
+import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
+import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
+import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR;
/**
* Represents an utility for listener.
@@ -256,17 +254,24 @@
}
/**
- * Sets current date and makes it in usable format for revision.
+ * Returns current date and makes it in usable format for revision.
*
* @return usable current date format for revision
*/
- public static String setCurrentDateForRevision() {
+ public static Date getCurrentDateForRevision() {
- Calendar date = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
- String dateForRevision = dateFormat.format(date.getTime()).replaceAll(SLASH, HYPHEN).replaceAll(SPACE,
- EMPTY_STRING);
- return dateForRevision;
+
+ Date date = new Date();
+ String dateInString = dateFormat.format(date);
+ try {
+ //if not valid, it will throw ParseException
+ Date now = dateFormat.parse(dateInString);
+ return date;
+ } catch (ParseException e) {
+ ParserException parserException = new ParserException("YANG file error: Input date is not correct");
+ throw parserException;
+ }
}
/**
@@ -373,4 +378,35 @@
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
+
+ /**
+ * Returns date and makes it in usable format for revision.
+ *
+ * @param dateInString date argument string from yang file
+ * @param ctx yang construct's context to get the line number and character position
+ * @return date format for revision
+ */
+ public static Date getValidDateFromString(String dateInString, ParserRuleContext ctx) {
+ String dateArgument = removeQuotesAndHandleConcat(dateInString);
+ if (dateArgument == null || !dateArgument.matches(DATE_PATTERN)) {
+ ParserException parserException = new ParserException("YANG file error: Input date is not correct");
+ parserException.setLine(ctx.getStart().getLine());
+ parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+ throw parserException;
+ }
+
+ SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
+ sdf.setLenient(false);
+
+ try {
+ //if not valid, it will throw ParseException
+ Date date = sdf.parse(dateArgument);
+ return date;
+ } catch (ParseException e) {
+ ParserException parserException = new ParserException("YANG file error: Input date is not correct");
+ parserException.setLine(ctx.getStart().getLine());
+ parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+ throw parserException;
+ }
+ }
}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
index c9b2765..8c938ed 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
@@ -18,7 +18,9 @@
import java.io.File;
import java.io.IOException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
@@ -59,6 +61,7 @@
private static final int INDEX_TWO = 2;
private static final int VALUE_CHECK = 10;
private static final String ZERO = "0";
+ private static final String DATE_FORMAT = "yyyy-MM-dd";
/**
* Create instance of java identifier syntax.
@@ -75,7 +78,7 @@
* @param conflictResolver object of YANG to java naming conflict util
* @return the root package string
*/
- public static String getRootPackage(byte version, String nameSpace, String revision,
+ public static String getRootPackage(byte version, String nameSpace, Date revision,
YangToJavaNamingConflictUtil conflictResolver) {
String pkg;
@@ -125,30 +128,23 @@
*
* @param date YANG module revision
* @return revision string
- * @throws TranslatorException when date is invalid.
*/
- private static String getYangRevisionStr(String date) throws TranslatorException {
-
- String[] revisionArr = date.split(HYPHEN);
+ private static String getYangRevisionStr(Date date) {
+ SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
+ String dateInString = sdf.format(date);
+ String[] revisionArr = dateInString.split(HYPHEN);
String rev = REVISION_PREFIX;
rev = rev + revisionArr[INDEX_ZERO];
- if (Integer.parseInt(revisionArr[INDEX_ONE]) <= MAX_MONTHS
- && Integer.parseInt(revisionArr[INDEX_TWO]) <= MAX_DAYS) {
- for (int i = INDEX_ONE; i < revisionArr.length; i++) {
-
- Integer val = Integer.parseInt(revisionArr[i]);
- if (val < VALUE_CHECK) {
- rev = rev + ZERO;
- }
- rev = rev + val;
+ for (int i = INDEX_ONE; i < revisionArr.length; i++) {
+ Integer val = Integer.parseInt(revisionArr[i]);
+ if (val < VALUE_CHECK) {
+ rev = rev + ZERO;
}
-
- return rev;
- } else {
- throw new TranslatorException("Date in revision is not proper: " + date);
+ rev = rev + val;
}
+ return rev;
}
/**
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 37b8992..f4999b6 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -1140,6 +1140,12 @@
+ "grouping for given uses";
/**
+ * Static attribute for grouping linker error information.
+ */
+ public static final String FEATURE_LINKER_ERROR = "YANG file error: Unable to find feature "
+ + "for given if-feature";
+
+ /**
* Static attribute for reference.
*/
public static final String REFERENCE = "Reference";
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ImportListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ImportListenerTest.java
index 9797e5e..b52da4a 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ImportListenerTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ImportListenerTest.java
@@ -16,14 +16,15 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
-import java.io.IOException;
-
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
@@ -33,6 +34,8 @@
public class ImportListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
+ private static final String DATE_FORMAT = "yyyy-MM-dd";
+ private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
/**
* Checks if mandatory parameter prefix is present in import.
@@ -65,12 +68,12 @@
* Checks if import listener updates the data model tree.
*/
@Test
- public void processImportValidEntry() throws IOException, ParserException {
+ public void processImportValidEntry() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/ImportValidEntry.yang");
// Checks for the revision value in data model tree.
- assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
+ assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03")));
// Checks for the prefix id in data model tree.
assertThat(((YangModule) node).getImportList().get(0).getPrefixId(), is("On2"));
// Checks for the module name in data model tree.
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListenerTest.java
index 452fc89..e2bb239 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListenerTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListenerTest.java
@@ -16,14 +16,15 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
-import java.io.IOException;
-
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
@@ -33,6 +34,8 @@
public class IncludeListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
+ private static final String DATE_FORMAT = "yyyy-MM-dd";
+ private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
/**
* Checks if include listener with ; is valid and updates the data
@@ -65,43 +68,43 @@
* and updates the data model tree.
*/
@Test
- public void processIncludeWithDate() throws IOException, ParserException {
+ public void processIncludeWithDate() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/IncludeWithDate.yang");
// Checks for the sub module name in data model tree.
assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut"));
- assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
+ assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
}
/**
* Checks if include has more than one occurrence.
*/
@Test
- public void processIncludeMultiInstance() throws IOException, ParserException {
+ public void processIncludeMultiInstance() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/IncludeMultiInstance.yang");
// Checks for the sub module name in data model tree.
assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut"));
- assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
+ assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
assertThat(((YangModule) node).getIncludeList().get(1).getSubModuleName(), is("sdn"));
- assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
+ assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
}
/**
* Checks if include and import can come in any order.
*/
@Test
- public void processIncludeImportAnyOrder() throws IOException, ParserException {
+ public void processIncludeImportAnyOrder() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/IncludeImportAnyOrder.yang");
// Checks for the sub module name in data model tree.
assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut"));
- assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
+ assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
assertThat(((YangModule) node).getIncludeList().get(1).getSubModuleName(), is("sdn"));
- assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
+ assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
}
/**
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MustListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MustListenerTest.java
new file mode 100644
index 0000000..2649d4d
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/MustListenerTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangMust;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ListIterator;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing must listener functionality.
+ */
+public class MustListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if must listener updates the data model.
+ */
+ @Test
+ public void processContainerSubStatementMust() throws IOException, ParserException {
+ YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementMust.yang");
+
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ YangContainer yangContainer = (YangContainer) yangNode.getChild();
+ assertThat(yangContainer.getName(), is("interface"));
+
+ String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
+ List<YangMust> mustConstraintList = yangContainer.getListOfMust();
+ assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint));
+ }
+
+ /**
+ * Checks if must listener updates the data model.
+ */
+ @Test
+ public void processLeafSubStatementMust() throws IOException, ParserException {
+ YangNode node = manager.getDataModel("src/test/resources/LeafSubStatementMust.yang");
+
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getListOfMust().iterator().next().getConstraint(), is("ifType != 'ethernet'"));
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListenerTest.java
index c12b377..8a00480 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListenerTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListenerTest.java
@@ -16,14 +16,15 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
-import java.io.IOException;
-
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
@@ -33,6 +34,8 @@
public class RevisionDateListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
+ private static final String DATE_FORMAT = "yyyy-MM-dd";
+ private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
/**
* Checks if revision date syntax is correct in include.
@@ -56,26 +59,26 @@
* Checks revision date in quotes inside include.
*/
@Test
- public void processRevisionDateInQuotesAtInclude() throws IOException, ParserException {
+ public void processRevisionDateInQuotesAtInclude() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtInclude.yang");
// Checks for the version value in data model tree.
- assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
- assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
- assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
+ assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03")));
+ assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
+ assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
}
/**
* Checks revision date in quotes inside import.
*/
@Test
- public void processRevisionDateInQuotesAtImport() throws IOException, ParserException {
+ public void processRevisionDateInQuotesAtImport() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtImport.yang");
// Checks for the version value in data model tree.
- assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
- assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
- assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
+ assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03")));
+ assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
+ assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
}
/**
@@ -100,13 +103,13 @@
* Checks if revision date listener updates the data model tree.
*/
@Test
- public void processRevisionDateValidEntry() throws IOException, ParserException {
+ public void processRevisionDateValidEntry() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/RevisionDateValidEntry.yang");
// Checks for the version value in data model tree.
- assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
- assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
- assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
+ assertThat(((YangModule) node).getImportList().get(0).getRevision(), is(simpleDateFormat.parse("2015-02-03")));
+ assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is(simpleDateFormat.parse("2016-02-03")));
+ assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is(simpleDateFormat.parse("2014-02-03")));
}
}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java
index a5eeb04..fbeacc8 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java
@@ -16,14 +16,15 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
-import java.io.IOException;
-
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
@@ -34,18 +35,19 @@
public class RevisionListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
+ private static final String DATE_FORMAT = "yyyy-MM-dd";
+ private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
/**
* Checks if revision doesn't have optional parameters "revision and
* description".
*/
@Test
- public void processRevisionNoOptionalParameter() throws IOException, ParserException {
+ public void processRevisionNoOptionalParameter() throws IOException, ParserException, ParseException {
YangNode node = manager.getDataModel("src/test/resources/RevisionNoOptionalParameter.yang");
-
// Checks for the version value in data model tree.
- assertThat(((YangModule) node).getRevision().getRevDate(), is("2016-02-03"));
+ assertThat(((YangModule) node).getRevision().getRevDate(), is(simpleDateFormat.parse("2016-02-03")));
}
/**
@@ -75,4 +77,14 @@
YangNode node = manager.getDataModel("src/test/resources/RevisionAbsence.yang");
assertThat(((YangModule) node).getRevision().getRevDate(), notNullValue());
}
+
+ /**
+ * Checks latest date is stored when there are multiple revisions.
+ */
+ @Test
+ public void processWithMultipleRevision() throws IOException, ParserException, ParseException {
+
+ YangNode node = manager.getDataModel("src/test/resources/MultipleRevision.yang");
+ assertThat(((YangModule) node).getRevision().getRevDate(), is(simpleDateFormat.parse("2013-07-15")));
+ }
}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/WhenListenerTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/WhenListenerTest.java
new file mode 100644
index 0000000..fcba7c0
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/WhenListenerTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangList;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+import java.util.ListIterator;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing when listener functionality.
+ */
+public class WhenListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if when listener updates the data model.
+ */
+ @Test
+ public void processContainerSubStatementWhen() throws IOException, ParserException {
+ YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementWhen.yang");
+
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ YangList yangList = (YangList) yangNode.getChild();
+ assertThat(yangList.getName(), is("interface-switching-capability"));
+
+ YangContainer container = (YangContainer) yangList.getNextSibling();
+ assertThat(container.getName(), is("time-division-multiplex-capable"));
+
+ String expectedConstraint = "../switching-capability = 'TDM'";
+ assertThat(container.getWhen().getCondition(), is(expectedConstraint));
+ }
+
+ /**
+ * Checks if when listener updates the data model.
+ */
+ @Test
+ public void processLeafSubStatementWhen() throws IOException, ParserException {
+ YangNode node = manager.getDataModel("src/test/resources/LeafSubStatementWhen.yang");
+
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getWhen().getCondition(), is("ifType != 'ethernet'"));
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIfFeatureLinkingTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIfFeatureLinkingTest.java
new file mode 100644
index 0000000..c4c501d
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIfFeatureLinkingTest.java
@@ -0,0 +1,454 @@
+/*
+ * 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.plugin.manager;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ListIterator;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangFeature;
+import org.onosproject.yangutils.datamodel.YangIfFeature;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.linker.impl.YangLinkerManager;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
+import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
+
+/**
+ * Test cases for testing inter file linking.
+ */
+public class InterFileIfFeatureLinkingTest {
+
+ private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
+
+ /**
+ * Checks inter file feature linking with imported file.
+ */
+ @Test
+ public void processFeatureInImportedFile()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfilefeatureimport";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("syslog1")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("syslog2")) {
+ refNode1 = rootNode;
+ } else {
+ refNode2 = rootNode;
+ }
+ }
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("syslog1"));
+
+ ListIterator<YangFeature> featureIterator = yangNode.getFeatureList().listIterator();
+ YangFeature feature = featureIterator.next();
+ assertThat(feature.getName(), is("frr-te"));
+
+ YangIfFeature ifFeature = feature.getIfFeatureList().iterator().next();
+ assertThat(ifFeature.getName().getName(), is("p2mp-te"));
+ assertThat(ifFeature.getName().getPrefix(), is("sys2"));
+ assertThat(ifFeature.getResolvableStatus(), is(RESOLVED));
+
+ YangContainer container = (YangContainer) selfNode.getChild();
+ assertThat(container.getName(), is("speed"));
+ YangLeaf leaf = container.getListOfLeaf().iterator().next();
+ assertThat(leaf.getName(), is("local-storage-limit"));
+
+ List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
+ ifFeature = ifFeatureList.iterator().next();
+ assertThat(ifFeature.getName().getName(), is("frr-te"));
+ assertThat(ifFeature.getResolvableStatus(), is(RESOLVED));
+ }
+
+ /**
+ * Checks inter file feature linking with included file.
+ */
+ @Test
+ public void processFeatureInIncludedFile()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfilefeatureinclude";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Carry out linking of sub module with module.
+ yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Add references to include list.
+ yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("syslog3")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("syslog4")) {
+ refNode1 = rootNode;
+ } else {
+ refNode2 = rootNode;
+ }
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("syslog3"));
+
+ ListIterator<YangFeature> featureIterator = yangNode.getFeatureList().listIterator();
+ YangFeature feature = featureIterator.next();
+ assertThat(feature.getName(), is("frr-te"));
+
+ YangIfFeature ifFeature = feature.getIfFeatureList().iterator().next();
+ assertThat(ifFeature.getName().getName(), is("p2mp-te"));
+ assertThat(ifFeature.getResolvableStatus(), is(RESOLVED));
+
+ YangContainer container = (YangContainer) selfNode.getChild();
+ assertThat(container.getName(), is("speed"));
+ YangLeaf leaf = container.getListOfLeaf().iterator().next();
+ assertThat(leaf.getName(), is("local-storage-limit"));
+
+ List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
+ ifFeature = ifFeatureList.iterator().next();
+ assertThat(ifFeature.getName().getName(), is("frr-te"));
+ assertThat(ifFeature.getResolvableStatus(), is(RESOLVED));
+ }
+
+ /**
+ * Checks inter file feature linking with imported file with dependency.
+ */
+ @Test
+ public void processFeatureInImportedFileWithDependency()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfilefeatureimportdependency";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("syslog1")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("syslog2")) {
+ refNode1 = rootNode;
+ } else {
+ refNode2 = rootNode;
+ }
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("syslog1"));
+
+ ListIterator<YangFeature> featureIterator = yangNode.getFeatureList().listIterator();
+ YangFeature feature = featureIterator.next();
+ assertThat(feature.getName(), is("frr-te"));
+
+ YangIfFeature ifFeature = feature.getIfFeatureList().iterator().next();
+ assertThat(ifFeature.getName().getName(), is("p2mp-te"));
+ assertThat(ifFeature.getName().getPrefix(), is("sys2"));
+ assertThat(ifFeature.getResolvableStatus(), is(RESOLVED));
+
+ YangContainer container = (YangContainer) selfNode.getChild();
+ assertThat(container.getName(), is("speed"));
+ YangLeaf leaf = container.getListOfLeaf().iterator().next();
+ assertThat(leaf.getName(), is("local-storage-limit"));
+
+ List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
+ ifFeature = ifFeatureList.iterator().next();
+ assertThat(ifFeature.getName().getName(), is("frr-te"));
+ assertThat(ifFeature.getResolvableStatus(), is(RESOLVED));
+ }
+
+ /**
+ * Checks inter file feature linking with included file with dependency.
+ */
+ @Test
+ public void processFeatureInIncludedFileWithDependency()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfilefeatureincludedependency";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Carry out linking of sub module with module.
+ yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
+
+ // Add references to include list.
+ yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("syslog1")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("syslog2")) {
+ refNode1 = rootNode;
+ } else {
+ refNode2 = rootNode;
+ }
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("syslog1"));
+
+ ListIterator<YangFeature> featureIterator = yangNode.getFeatureList().listIterator();
+ YangFeature feature = featureIterator.next();
+ assertThat(feature.getName(), is("frr-te"));
+
+ YangIfFeature ifFeature = feature.getIfFeatureList().iterator().next();
+ assertThat(ifFeature.getName().getName(), is("p2mp-te"));
+ assertThat(ifFeature.getResolvableStatus(), is(RESOLVED));
+
+ YangContainer container = (YangContainer) selfNode.getChild();
+ assertThat(container.getName(), is("speed"));
+ YangLeaf leaf = container.getListOfLeaf().iterator().next();
+ assertThat(leaf.getName(), is("local-storage-limit"));
+
+ List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
+ ifFeature = ifFeatureList.iterator().next();
+ assertThat(ifFeature.getName().getName(), is("frr-te"));
+ assertThat(ifFeature.getResolvableStatus(), is(RESOLVED));
+ }
+
+ /**
+ * Checks inter file feature linking with imported file with dependency
+ * feature undefined.
+ */
+ @Test
+ public void processFeatureInImportedFileWithDependencyUndefined()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfilefeatureimportdependencyUndefined";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("syslog1")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("syslog2")) {
+ refNode1 = rootNode;
+ } else {
+ refNode2 = rootNode;
+ }
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("syslog1"));
+
+ ListIterator<YangFeature> featureIterator = yangNode.getFeatureList().listIterator();
+ YangFeature feature = featureIterator.next();
+ assertThat(feature.getName(), is("frr-te"));
+
+ YangIfFeature ifFeature = feature.getIfFeatureList().iterator().next();
+ assertThat(ifFeature.getName().getName(), is("p2mp-te"));
+ assertThat(ifFeature.getName().getPrefix(), is("sys2"));
+ assertThat(ifFeature.getResolvableStatus(), is(INTRA_FILE_RESOLVED));
+
+ YangContainer container = (YangContainer) selfNode.getChild();
+ assertThat(container.getName(), is("speed"));
+ YangLeaf leaf = container.getListOfLeaf().iterator().next();
+ assertThat(leaf.getName(), is("local-storage-limit"));
+
+ List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
+ ifFeature = ifFeatureList.iterator().next();
+ assertThat(ifFeature.getName().getName(), is("frr-te"));
+ assertThat(ifFeature.getResolvableStatus(), is(INTRA_FILE_RESOLVED));
+ }
+
+ /**
+ * Checks inter file feature linking with included file with dependency
+ * feature undefined.
+ */
+ @Test
+ public void processFeatureInIncludedFileWithDependencyUndefined()
+ throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/interfilefeatureincludedependencyUndefined";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+ YangNode refNode1 = null;
+ YangNode refNode2 = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Carry out linking of sub module with module.
+ yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ // Add references to include list.
+ yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("syslog1")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("syslog2")) {
+ refNode1 = rootNode;
+ } else {
+ refNode2 = rootNode;
+ }
+ }
+
+ // Check whether the data model tree returned is of type module.
+ assertThat(selfNode instanceof YangModule, is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("syslog1"));
+
+ ListIterator<YangFeature> featureIterator = yangNode.getFeatureList().listIterator();
+ YangFeature feature = featureIterator.next();
+ assertThat(feature.getName(), is("frr-te"));
+
+ YangIfFeature ifFeature = feature.getIfFeatureList().iterator().next();
+ assertThat(ifFeature.getName().getName(), is("p2mp-te"));
+ assertThat(ifFeature.getResolvableStatus(), is(INTRA_FILE_RESOLVED));
+
+ YangContainer container = (YangContainer) selfNode.getChild();
+ assertThat(container.getName(), is("speed"));
+ YangLeaf leaf = container.getListOfLeaf().iterator().next();
+ assertThat(leaf.getName(), is("local-storage-limit"));
+
+ List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
+ ifFeature = ifFeatureList.iterator().next();
+ assertThat(ifFeature.getName().getName(), is("frr-te"));
+ assertThat(ifFeature.getResolvableStatus(), is(INTRA_FILE_RESOLVED));
+ }
+}
+
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileIfFeatureLinkingTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileIfFeatureLinkingTest.java
new file mode 100644
index 0000000..a44ae9a
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileIfFeatureLinkingTest.java
@@ -0,0 +1,220 @@
+/*
+ * 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.plugin.manager;
+
+import java.io.IOException;
+import java.util.List;
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangFeature;
+import org.onosproject.yangutils.datamodel.YangIfFeature;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+/**
+ * Test cases for testing if-feature intra file linking.
+ */
+public class IntraFileIfFeatureLinkingTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks self resolution when feature defined in same file.
+ */
+ @Test
+ public void processSelfFileLinkingWithFeature()
+ throws IOException, ParserException {
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/SelfFileLinkingWithFeature.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("syslog"));
+
+ List<YangFeature> featureList = yangNode.getFeatureList();
+ YangFeature feature = featureList.iterator().next();
+ assertThat(feature.getName(), is("local-storage"));
+
+ YangContainer container = (YangContainer) yangNode.getChild();
+ assertThat(container.getName(), is("speed"));
+
+ List<YangLeaf> listOfLeaf = container.getListOfLeaf();
+ YangLeaf leaf = listOfLeaf.iterator().next();
+ assertThat(leaf.getName(), is("local-storage-limit"));
+
+ List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
+ YangIfFeature ifFeature = ifFeatureList.iterator().next();
+ assertThat(ifFeature.getName().getName(), is("local-storage"));
+ assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+ }
+
+ /**
+ * Checks self resolution when feature is undefined.
+ */
+ @Test
+ public void processSelfFileLinkingWithFeatureUndefined()
+ throws IOException, ParserException {
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/SelfFileLinkingWithFeatureUndefined.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("syslog"));
+
+ YangContainer container = (YangContainer) yangNode.getChild();
+ assertThat(container.getName(), is("speed"));
+
+ List<YangLeaf> listOfLeaf = container.getListOfLeaf();
+ YangLeaf leaf = listOfLeaf.iterator().next();
+ assertThat(leaf.getName(), is("local-storage-limit"));
+
+ List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
+ YangIfFeature ifFeature = ifFeatureList.iterator().next();
+ assertThat(ifFeature.getName().getName(), is("local-storage"));
+ assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.INTRA_FILE_RESOLVED));
+ }
+
+ /**
+ * Checks self resolution of feature with multiple dependency.
+ */
+ @Test
+ public void processSelfFileLinkingWithMultipleDependency() throws IOException, ParserException {
+ YangNode node = manager
+ .getDataModel("src/test/resources/SelfFileLinkingWithMultipleDependency.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("syslog"));
+
+ List<YangFeature> featureList = yangNode.getFeatureList();
+ YangFeature feature = featureList.iterator().next();
+ assertThat(feature.getName(), is("p2mp-te"));
+
+ YangContainer container = (YangContainer) yangNode.getChild();
+ assertThat(container.getName(), is("speed"));
+
+ List<YangLeaf> listOfLeaf = container.getListOfLeaf();
+ YangLeaf leaf = listOfLeaf.iterator().next();
+ assertThat(leaf.getName(), is("local-storage-limit"));
+
+ List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
+ YangIfFeature ifFeature = ifFeatureList.iterator().next();
+ assertThat(ifFeature.getName().getName(), is("frr-te"));
+ assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+ }
+
+ /**
+ * Checks self resolution of feature with multiple dependency undefined.
+ */
+ @Test
+ public void processSelfFileLinkingWithMultipleDependencyUnresolved() throws IOException, ParserException {
+ YangNode node = manager
+ .getDataModel("src/test/resources/SelfFileLinkingWithMultipleDependencyUnresolved.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("syslog"));
+
+ List<YangFeature> featureList = yangNode.getFeatureList();
+ YangFeature feature = featureList.iterator().next();
+ assertThat(feature.getName(), is("frr-te"));
+
+ YangContainer container = (YangContainer) yangNode.getChild();
+ assertThat(container.getName(), is("speed"));
+
+ List<YangLeaf> listOfLeaf = container.getListOfLeaf();
+ YangLeaf leaf = listOfLeaf.iterator().next();
+ assertThat(leaf.getName(), is("local-storage-limit"));
+
+ List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
+ YangIfFeature ifFeature = ifFeatureList.iterator().next();
+ assertThat(ifFeature.getName().getName(), is("frr-te"));
+ assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.INTRA_FILE_RESOLVED));
+ }
+
+ /**
+ * Checks self resolution when feature is defined in same file in submodule.
+ */
+ @Test
+ public void processSelfFileLinkingWithFeatureInSubModule()
+ throws IOException, ParserException {
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/SelfFileLinkingWithFeatureInSubModule.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangSubModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.SUB_MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangSubModule yangNode = (YangSubModule) node;
+ assertThat(yangNode.getName(), is("syslog"));
+
+ List<YangFeature> featureList = yangNode.getFeatureList();
+ YangFeature feature = featureList.iterator().next();
+ assertThat(feature.getName(), is("local-storage"));
+
+ YangContainer container = (YangContainer) yangNode.getChild();
+ assertThat(container.getName(), is("speed"));
+
+ List<YangLeaf> listOfLeaf = container.getListOfLeaf();
+ YangLeaf leaf = listOfLeaf.iterator().next();
+ assertThat(leaf.getName(), is("local-storage-limit"));
+
+ List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
+ YangIfFeature ifFeature = ifFeatureList.iterator().next();
+ assertThat(ifFeature.getName().getName(), is("local-storage"));
+ assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
index 24f4904..bfde08d 100644
--- a/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
+++ b/utils/yangutils/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
@@ -20,6 +20,9 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -104,6 +107,8 @@
private static final String WITH_SMALL = "test_this";
private static final String WITH_CAMEL_CASE_WITH_PREFIX = "123addPrefixTry";
private static final String WITH_CAMEL_CASE_WITH_PREFIX1 = "abc1234567890Ss1123G123Gaa";
+ private static final String DATE_FORMAT = "yyyy-MM-dd";
+ private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
private static YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
private static final String BASE_DIR_PKG = "target.UnitTestCase.";
private static final String DIR_PATH = "exist1.exist2.exist3";
@@ -140,9 +145,10 @@
* Unit test for root package generation with revision complexity.
*/
@Test
- public void getRootPackageTest() {
+ public void getRootPackageTest() throws ParseException {
conflictResolver.setPrefixForIdentifier(null);
- String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1, conflictResolver);
+ Date date = simpleDateFormat.parse(DATE1);
+ String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, date, conflictResolver);
assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true));
}
@@ -151,31 +157,34 @@
* Unit test for root package generation with invalid prefix.
*/
@Test
- public void getRootPackageWithInvalidPrefix() throws TranslatorException {
+ public void getRootPackageWithInvalidPrefix() throws TranslatorException, ParseException {
thrown.expect(TranslatorException.class);
thrown.expectMessage("The given prefix in pom.xml is invalid.");
conflictResolver.setPrefixForIdentifier(INVALID_PREFIX);
- String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE_FOR_INVALID_PREFIX, DATE1, conflictResolver);
+ Date date = simpleDateFormat.parse(DATE1);
+ String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE_FOR_INVALID_PREFIX, date,
+ conflictResolver);
}
/**
* Unit test for root package generation with special characters presence.
*/
@Test
- public void getRootPackageWithSpecialCharactersTest() {
+ public void getRootPackageWithSpecialCharactersTest() throws ParseException {
conflictResolver.setPrefixForIdentifier(VALID_PREFIX);
- String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1, conflictResolver);
+ Date date = simpleDateFormat.parse(DATE1);
+ String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, date, conflictResolver);
assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true));
conflictResolver.setPrefixForIdentifier(null);
- String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1, conflictResolver);
+ String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, date, conflictResolver);
assertThat(rootPackage1.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + VALID_NAME_SPACE2 + PERIOD + DATE_WITH_REV1), is(true));
- String rootPackage2 = getRootPackage((byte) 1, INVALID_NAME_SPACE3, DATE1, conflictResolver);
+ String rootPackage2 = getRootPackage((byte) 1, INVALID_NAME_SPACE3, date, conflictResolver);
assertThat(rootPackage2.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + VALID_NAME_SPACE4 + PERIOD + DATE_WITH_REV1), is(true));
conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1);
- String rootPackage3 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1, conflictResolver);
+ String rootPackage3 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, date, conflictResolver);
assertThat(rootPackage3.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + VALID_NAME_SPACE3 + PERIOD + DATE_WITH_REV1), is(true));
@@ -185,8 +194,9 @@
* Unit test for root package generation without complexity in revision.
*/
@Test
- public void getRootPackageWithRevTest() {
- String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2, null);
+ public void getRootPackageWithRevTest() throws ParseException {
+ Date date = simpleDateFormat.parse(DATE2);
+ String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, date, null);
assertThat(rootPkgWithRev.equals(
DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2),
is(true));
diff --git a/utils/yangutils/plugin/src/test/resources/ContainerSubStatementMust.yang b/utils/yangutils/plugin/src/test/resources/ContainerSubStatementMust.yang
new file mode 100644
index 0000000..c089850
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/ContainerSubStatementMust.yang
@@ -0,0 +1,24 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ container interface {
+ leaf ifType {
+ type enumeration {
+ enum ethernet;
+ enum atm;
+ }
+ }
+ leaf ifMTU {
+ type uint32;
+ }
+ must "ifType != 'ethernet' or " +
+ "(ifType = 'ethernet' and ifMTU = 1500)" {
+ description "An ethernet MTU must be 1500";
+ }
+ must "ifType != 'atm' or " +
+ "(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
+ description "An atm MTU must be 64 .. 17966";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/ContainerSubStatementWhen.yang b/utils/yangutils/plugin/src/test/resources/ContainerSubStatementWhen.yang
new file mode 100644
index 0000000..644b2ff
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/ContainerSubStatementWhen.yang
@@ -0,0 +1,32 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ list interface-switching-capability {
+ key "switching-capability";
+ description
+ "List of Interface Switching Capabilities Descriptors (ISCD)
+ for this link.";
+ reference
+ "RFC3471: Generalized Multi-Protocol Label Switching (GMPLS)
+ Signaling Functional Description.
+ RFC4203: OSPF Extensions in Support of Generalized
+ Multi-Protocol Label Switching (GMPLS).";
+ leaf switching-capability {
+ type string;
+ description
+ "Switching Capability for this interface.";
+ }
+ }
+ container time-division-multiplex-capable {
+ when "../switching-capability = 'TDM'" {
+ description "Valid only for TDM";
+ }
+ description
+ "Interface has time-division multiplex capabilities.";
+
+ leaf minimum-lsp-bandwidth {
+ type decimal64;
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/LeafSubStatementMust.yang b/utils/yangutils/plugin/src/test/resources/LeafSubStatementMust.yang
new file mode 100644
index 0000000..6d7e626
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/LeafSubStatementMust.yang
@@ -0,0 +1,14 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf ifType {
+ type enumeration {
+ enum ethernet;
+ enum atm;
+ }
+ must "ifType != 'ethernet'" {
+ description "ifType is not ethernet";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/LeafSubStatementWhen.yang b/utils/yangutils/plugin/src/test/resources/LeafSubStatementWhen.yang
new file mode 100644
index 0000000..239e0b6
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/LeafSubStatementWhen.yang
@@ -0,0 +1,14 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf ifType {
+ when "ifType != 'ethernet'" {
+ description "ifType is not ethernet";
+ }
+ type enumeration {
+ enum ethernet;
+ enum atm;
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/MultipleRevision.yang b/utils/yangutils/plugin/src/test/resources/MultipleRevision.yang
new file mode 100755
index 0000000..4ce440c
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/MultipleRevision.yang
@@ -0,0 +1,26 @@
+module Test {
+ yang-version 1;
+ namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+ prefix test;
+
+ revision 2013-07-15 {
+ description
+ "This revision adds the following new data types:
+ - yang-identifier
+ - hex-string
+ - uuid
+ - dotted-quad";
+ reference
+ "RFC 6991: Common YANG Data Types";
+ }
+ revision 2013-07-14 {
+ description
+ "This revision adds the following new data types:
+ - yang-identifier
+ - hex-string
+ - uuid
+ - dotted-quad";
+ reference
+ "RFC 6991: Common YANG Data Types";
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithFeature.yang b/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithFeature.yang
new file mode 100644
index 0000000..53de63a
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithFeature.yang
@@ -0,0 +1,23 @@
+module syslog {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix "sys";
+ feature local-storage {
+ description
+ "This feature means the device supports local
+ storage (memory, flash or disk) that can be used to
+ store syslog messages.";
+ }
+
+ container speed {
+ leaf local-storage-limit {
+ if-feature local-storage;
+ type uint64;
+ units "kilobyte";
+ config false;
+ description
+ "The amount of local storage that can be
+ used to hold syslog messages.";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithFeatureInSubModule.yang b/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithFeatureInSubModule.yang
new file mode 100644
index 0000000..09b8b37
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithFeatureInSubModule.yang
@@ -0,0 +1,24 @@
+submodule syslog {
+ yang-version 1;
+ belongs-to "syslog1" {
+ prefix "sys";
+ }
+ feature local-storage {
+ description
+ "This feature means the device supports local
+ storage (memory, flash or disk) that can be used to
+ store syslog messages.";
+ }
+
+ container speed {
+ leaf local-storage-limit {
+ if-feature local-storage;
+ type uint64;
+ units "kilobyte";
+ config false;
+ description
+ "The amount of local storage that can be
+ used to hold syslog messages.";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithFeatureUndefined.yang b/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithFeatureUndefined.yang
new file mode 100644
index 0000000..f55c61a
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithFeatureUndefined.yang
@@ -0,0 +1,17 @@
+module syslog {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix "sys";
+
+ container speed {
+ leaf local-storage-limit {
+ if-feature local-storage;
+ type uint64;
+ units "kilobyte";
+ config false;
+ description
+ "The amount of local storage that can be
+ used to hold syslog messages.";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithMultipleDependency.yang b/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithMultipleDependency.yang
new file mode 100644
index 0000000..d230f99
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithMultipleDependency.yang
@@ -0,0 +1,26 @@
+module syslog {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix "sys";
+
+ feature p2mp-te {
+ description "Indicates support for P2MP-TE";
+ }
+
+ feature frr-te {
+ description "Indicates support for TE FastReroute (FRR)";
+ if-feature p2mp-te;
+ }
+
+ container speed {
+ leaf local-storage-limit {
+ if-feature frr-te;
+ type uint64;
+ units "kilobyte";
+ config false;
+ description
+ "The amount of local storage that can be
+ used to hold syslog messages.";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithMultipleDependencyUnresolved.yang b/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithMultipleDependencyUnresolved.yang
new file mode 100644
index 0000000..02bca89
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithMultipleDependencyUnresolved.yang
@@ -0,0 +1,22 @@
+module syslog {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix "sys";
+
+ feature frr-te {
+ description "Indicates support for TE FastReroute (FRR)";
+ if-feature p2mp-te;
+ }
+
+ container speed {
+ leaf local-storage-limit {
+ if-feature frr-te;
+ type uint64;
+ units "kilobyte";
+ config false;
+ description
+ "The amount of local storage that can be
+ used to hold syslog messages.";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithMultipleFeature.yang b/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithMultipleFeature.yang
new file mode 100644
index 0000000..407023c
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/SelfFileLinkingWithMultipleFeature.yang
@@ -0,0 +1,26 @@
+module syslog {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix "sys";
+
+ feature p2mp-te {
+ description "Indicates support for P2MP-TE";
+ }
+
+ feature frr-te {
+ description "Indicates support for TE FastReroute (FRR)";
+ if-feature p2mp-te;
+ }
+
+ container speed {
+ leaf local-storage-limit {
+ if-feature local-storage;
+ type uint64;
+ units "kilobyte";
+ config false;
+ description
+ "The amount of local storage that can be
+ used to hold syslog messages.";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureimport/featureFile1.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureimport/featureFile1.yang
new file mode 100644
index 0000000..e78e583
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureimport/featureFile1.yang
@@ -0,0 +1,26 @@
+module syslog1 {
+ yang-version 1;
+ namespace "http://huawei1.com";
+ prefix "sys1";
+
+ import "syslog2" {
+ prefix "sys2";
+ }
+
+ feature frr-te {
+ description "Indicates support for TE FastReroute (FRR)";
+ if-feature "sys2:p2mp-te";
+ }
+
+ container speed {
+ leaf local-storage-limit {
+ if-feature frr-te;
+ type uint64;
+ units "kilobyte";
+ config false;
+ description
+ "The amount of local storage that can be
+ used to hold syslog messages.";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureimport/featureFile2.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureimport/featureFile2.yang
new file mode 100644
index 0000000..782571c
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureimport/featureFile2.yang
@@ -0,0 +1,9 @@
+module syslog2 {
+ yang-version 1;
+ namespace "http://huawei2.com";
+ prefix "sys2";
+
+ feature p2mp-te {
+ description "Indicates support for P2MP-TE";
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependency/featurefile1.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependency/featurefile1.yang
new file mode 100644
index 0000000..e78e583
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependency/featurefile1.yang
@@ -0,0 +1,26 @@
+module syslog1 {
+ yang-version 1;
+ namespace "http://huawei1.com";
+ prefix "sys1";
+
+ import "syslog2" {
+ prefix "sys2";
+ }
+
+ feature frr-te {
+ description "Indicates support for TE FastReroute (FRR)";
+ if-feature "sys2:p2mp-te";
+ }
+
+ container speed {
+ leaf local-storage-limit {
+ if-feature frr-te;
+ type uint64;
+ units "kilobyte";
+ config false;
+ description
+ "The amount of local storage that can be
+ used to hold syslog messages.";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependency/featurefile2.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependency/featurefile2.yang
new file mode 100644
index 0000000..fcaf8e0
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependency/featurefile2.yang
@@ -0,0 +1,14 @@
+module syslog2 {
+ yang-version 1;
+ namespace "http://huawei2.com";
+ prefix "sys2";
+
+ import "syslog3" {
+ prefix "sys3";
+ }
+
+ feature p2mp-te {
+ description "Indicates support for P2MP-TE";
+ if-feature "sys3:extended-admin-groups";
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependency/featurefile3.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependency/featurefile3.yang
new file mode 100644
index 0000000..13d6787
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependency/featurefile3.yang
@@ -0,0 +1,11 @@
+module syslog3 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys3";
+
+ feature extended-admin-groups {
+ description
+ "Indicates support for TE link extended admin
+ groups.";
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependencyUndefined/featurefile1.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependencyUndefined/featurefile1.yang
new file mode 100644
index 0000000..e78e583
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependencyUndefined/featurefile1.yang
@@ -0,0 +1,26 @@
+module syslog1 {
+ yang-version 1;
+ namespace "http://huawei1.com";
+ prefix "sys1";
+
+ import "syslog2" {
+ prefix "sys2";
+ }
+
+ feature frr-te {
+ description "Indicates support for TE FastReroute (FRR)";
+ if-feature "sys2:p2mp-te";
+ }
+
+ container speed {
+ leaf local-storage-limit {
+ if-feature frr-te;
+ type uint64;
+ units "kilobyte";
+ config false;
+ description
+ "The amount of local storage that can be
+ used to hold syslog messages.";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependencyUndefined/featurefile2.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependencyUndefined/featurefile2.yang
new file mode 100644
index 0000000..199a6a6
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependencyUndefined/featurefile2.yang
@@ -0,0 +1,15 @@
+module syslog2 {
+ yang-version 1;
+ namespace "http://huawei2.com";
+ prefix "sys2";
+
+ import "syslog3" {
+ prefix "sys3";
+ }
+
+ feature p2mp-te {
+ description "Indicates support for P2MP-TE";
+ if-feature "sys3:extended-admin-groups";
+ }
+}
+
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependencyUndefined/featurefile3.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependencyUndefined/featurefile3.yang
new file mode 100644
index 0000000..f638139
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureimportdependencyUndefined/featurefile3.yang
@@ -0,0 +1,5 @@
+module syslog3 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys3";
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureinclude/featureFile3.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureinclude/featureFile3.yang
new file mode 100644
index 0000000..b387853
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureinclude/featureFile3.yang
@@ -0,0 +1,24 @@
+module syslog3 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys3";
+
+ include "syslog4";
+
+ feature frr-te {
+ description "Indicates support for TE FastReroute (FRR)";
+ if-feature "p2mp-te";
+ }
+
+ container speed {
+ leaf local-storage-limit {
+ if-feature frr-te;
+ type uint64;
+ units "kilobyte";
+ config false;
+ description
+ "The amount of local storage that can be
+ used to hold syslog messages.";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureinclude/featureFile4.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureinclude/featureFile4.yang
new file mode 100644
index 0000000..30e1ce5
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureinclude/featureFile4.yang
@@ -0,0 +1,10 @@
+submodule syslog4 {
+ yang-version 1;
+ belongs-to "syslog3" {
+ prefix "sys3";
+ }
+
+ feature p2mp-te {
+ description "Indicates support for P2MP-TE";
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependency/featurefile1.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependency/featurefile1.yang
new file mode 100644
index 0000000..a30c85a
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependency/featurefile1.yang
@@ -0,0 +1,24 @@
+module syslog1 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys1";
+
+ include "syslog2";
+
+ feature frr-te {
+ description "Indicates support for TE FastReroute (FRR)";
+ if-feature "p2mp-te";
+ }
+
+ container speed {
+ leaf local-storage-limit {
+ if-feature frr-te;
+ type uint64;
+ units "kilobyte";
+ config false;
+ description
+ "The amount of local storage that can be
+ used to hold syslog messages.";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependency/featurefile2.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependency/featurefile2.yang
new file mode 100644
index 0000000..370490a
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependency/featurefile2.yang
@@ -0,0 +1,16 @@
+submodule syslog2 {
+ yang-version 1;
+ belongs-to "syslog1" {
+ prefix "sys1";
+ }
+
+ import "syslog3" {
+ prefix "sys3";
+ }
+
+ feature p2mp-te {
+ description "Indicates support for P2MP-TE";
+ if-feature "sys3:extended-admin-groups";
+ }
+}
+
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependency/featurefile3.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependency/featurefile3.yang
new file mode 100644
index 0000000..13d6787
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependency/featurefile3.yang
@@ -0,0 +1,11 @@
+module syslog3 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys3";
+
+ feature extended-admin-groups {
+ description
+ "Indicates support for TE link extended admin
+ groups.";
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependencyUndefined/featurefile1.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependencyUndefined/featurefile1.yang
new file mode 100644
index 0000000..a30c85a
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependencyUndefined/featurefile1.yang
@@ -0,0 +1,24 @@
+module syslog1 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys1";
+
+ include "syslog2";
+
+ feature frr-te {
+ description "Indicates support for TE FastReroute (FRR)";
+ if-feature "p2mp-te";
+ }
+
+ container speed {
+ leaf local-storage-limit {
+ if-feature frr-te;
+ type uint64;
+ units "kilobyte";
+ config false;
+ description
+ "The amount of local storage that can be
+ used to hold syslog messages.";
+ }
+ }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependencyUndefined/featurefile2.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependencyUndefined/featurefile2.yang
new file mode 100644
index 0000000..370490a
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependencyUndefined/featurefile2.yang
@@ -0,0 +1,16 @@
+submodule syslog2 {
+ yang-version 1;
+ belongs-to "syslog1" {
+ prefix "sys1";
+ }
+
+ import "syslog3" {
+ prefix "sys3";
+ }
+
+ feature p2mp-te {
+ description "Indicates support for P2MP-TE";
+ if-feature "sys3:extended-admin-groups";
+ }
+}
+
diff --git a/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependencyUndefined/featurefile3.yang b/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependencyUndefined/featurefile3.yang
new file mode 100644
index 0000000..f638139
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/interfilefeatureincludedependencyUndefined/featurefile3.yang
@@ -0,0 +1,5 @@
+module syslog3 {
+ yang-version 1;
+ namespace "http://huawei3.com";
+ prefix "sys3";
+}
diff --git a/utils/yangutils/plugin/src/test/resources/interfileietf/ietf-te-topology.yang b/utils/yangutils/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
index 849828f..b5fd1d9 100644
--- a/utils/yangutils/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
+++ b/utils/yangutils/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
@@ -68,7 +68,7 @@
* Features
*/
- /*feature configuration-schedule {
+ feature configuration-schedule {
description
"This feature indicates that the system supports
configuration scheduling.";
@@ -91,7 +91,7 @@
description
"This feature indicates that the system supports
template configuration.";
- }*/
+ }
/*
* Typedefs
diff --git a/utils/yangutils/plugin/src/test/resources/interfileietf/ietf-te-types.yang b/utils/yangutils/plugin/src/test/resources/interfileietf/ietf-te-types.yang
index 0962720..6268832 100644
--- a/utils/yangutils/plugin/src/test/resources/interfileietf/ietf-te-types.yang
+++ b/utils/yangutils/plugin/src/test/resources/interfileietf/ietf-te-types.yang
@@ -257,7 +257,7 @@
}*/
/* TE basic features */
- /*feature p2mp-te {
+ feature p2mp-te {
description
"Indicates support for P2MP-TE";
}
@@ -291,7 +291,7 @@
feature named-path-constraints {
description
"Indicates support for named path constraints";
- }*/
+ }
grouping explicit-route-subobject {
description