Merge "[ONOS-5766] Define YANG compiler API"
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/ResolvableType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/ResolvableType.java
index 367c811..f062837 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/ResolvableType.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/ResolvableType.java
@@ -59,5 +59,10 @@
/**
* Identifies the compiler annotations.
*/
- YANG_COMPILER_ANNOTATION
+ YANG_COMPILER_ANNOTATION,
+
+ /**
+ * Identifies the deviation.
+ */
+ YANG_DEVIATION
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAugment.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAugment.java
index 4ea139d..e7e36c2 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAugment.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAugment.java
@@ -85,8 +85,8 @@
public abstract class YangAugment
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable,
- CollisionDetector, Resolvable,
- YangXPathResolver, YangWhenHolder, YangIfFeatureHolder {
+ CollisionDetector, Resolvable, YangXPathResolver, YangWhenHolder,
+ YangIfFeatureHolder {
private static final long serialVersionUID = 806201602L;
@@ -343,7 +343,17 @@
*/
@Override
public void addLeaf(YangLeaf leaf) {
- getListOfLeaf().add(leaf);
+ listOfLeaf.add(leaf);
+ }
+
+ /**
+ * Removes a leaf.
+ *
+ * @param leaf the leaf to be removed
+ */
+ @Override
+ public void removeLeaf(YangLeaf leaf) {
+ listOfLeaf.remove(leaf);
}
/**
@@ -373,7 +383,17 @@
*/
@Override
public void addLeafList(YangLeafList leafList) {
- getListOfLeafList().add(leafList);
+ listOfLeafList.add(leafList);
+ }
+
+ /**
+ * Removes a leaf-list.
+ *
+ * @param leafList the leaf-list to be removed
+ */
+ @Override
+ public void removeLeafList(YangLeafList leafList) {
+ listOfLeafList.remove(leafList);
}
@Override
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBase.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBase.java
index a0194bb..55ec045 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBase.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBase.java
@@ -51,6 +51,9 @@
// Referred identity parent information.
private YangIdentity referredIdentity;
+ // Reference to parent
+ private YangIdentity parentIdentity;
+
/**
* Status of resolution. If completely resolved enum value is "RESOLVED",
* if not enum value is "UNRESOLVED", in case reference of grouping/typedef/base/identityref
@@ -114,4 +117,22 @@
public Object resolve() throws DataModelException {
return null;
}
+
+ /**
+ * Returns the parent identity node.
+ *
+ * @return the parent identity node
+ */
+ public YangIdentity getParentIdentity() {
+ return parentIdentity;
+ }
+
+ /**
+ * Sets the parent identity node.
+ *
+ * @param parentIdentity the parent identity node to set
+ */
+ public void setParentIdentity(YangIdentity parentIdentity) {
+ this.parentIdentity = parentIdentity;
+ }
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangCase.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangCase.java
index 8c1f491..c2e1a01 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangCase.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangCase.java
@@ -268,6 +268,16 @@
}
/**
+ * Removes a leaf.
+ *
+ * @param leaf the leaf to be removed
+ */
+ @Override
+ public void removeLeaf(YangLeaf leaf) {
+ listOfLeaf.remove(leaf);
+ }
+
+ /**
* Returns the list of leaf-list.
*
* @return the list of leaf-list
@@ -298,6 +308,16 @@
}
/**
+ * Removes a leaf-list.
+ *
+ * @param leafList the leaf-list to be removed
+ */
+ @Override
+ public void removeLeafList(YangLeafList leafList) {
+ listOfLeafList.remove(leafList);
+ }
+
+ /**
* Returns the textual reference.
*
* @return the reference
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangChoice.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangChoice.java
index 8e54d48..f2ce166 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangChoice.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangChoice.java
@@ -79,7 +79,8 @@
extends YangNode
implements YangCommonInfo, Parsable, CollisionDetector,
YangAugmentableNode, YangWhenHolder, YangIfFeatureHolder,
- YangAppErrorHolder, YangIsFilterContentNodes, YangConfig {
+ YangAppErrorHolder, YangIsFilterContentNodes, YangConfig,
+ YangDefault, YangMandatory {
private static final long serialVersionUID = 806201604L;
@@ -168,6 +169,11 @@
private YangAppErrorInfo yangAppErrorInfo;
/**
+ * If mandatory leaf.
+ */
+ private boolean isMandatory;
+
+ /**
* Create a choice node.
*/
public YangChoice() {
@@ -341,6 +347,7 @@
*
* @return the default value
*/
+ @Override
public String getDefaultValueInString() {
return defaultValueInString;
}
@@ -350,6 +357,7 @@
*
* @param defaultValueInString the default value
*/
+ @Override
public void setDefaultValueInString(String defaultValueInString) {
this.defaultValueInString = defaultValueInString;
}
@@ -490,4 +498,22 @@
public void cloneAugmentInfo() {
yangAugmentedInfo = new ArrayList<>();
}
+
+ /**
+ * Returns true, if the leaf is mandatory; false otherwise.
+ *
+ * @return true if leaf is mandatory; false otherwise
+ */
+ public boolean isMandatory() {
+ return isMandatory;
+ }
+
+ /**
+ * Sets the mandatory flag.
+ *
+ * @param isReq the flag value to set
+ */
+ public void setMandatory(boolean isReq) {
+ isMandatory = isReq;
+ }
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangContainer.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangContainer.java
index 04d99a4..608e27d 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangContainer.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangContainer.java
@@ -269,7 +269,17 @@
*/
@Override
public void addLeaf(YangLeaf leaf) {
- getListOfLeaf().add(leaf);
+ listOfLeaf.add(leaf);
+ }
+
+ /**
+ * Removes a leaf.
+ *
+ * @param leaf the leaf to be removed
+ */
+ @Override
+ public void removeLeaf(YangLeaf leaf) {
+ listOfLeaf.remove(leaf);
}
/**
@@ -299,9 +309,18 @@
*/
@Override
public void addLeafList(YangLeafList leafList) {
- getListOfLeafList().add(leafList);
+ listOfLeafList.add(leafList);
}
+ /**
+ * Removes a leaf-list.
+ *
+ * @param leafList the leaf-list to be removed
+ */
+ @Override
+ public void removeLeafList(YangLeafList leafList) {
+ listOfLeafList.remove(leafList);
+ }
/**
* Returns the presence string if present.
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDefault.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDefault.java
new file mode 100644
index 0000000..810b706
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDefault.java
@@ -0,0 +1,38 @@
+/*
+ * 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.yang.compiler.datamodel;
+
+/**
+ * Abstraction of default entity. It is used to abstract the data holders of
+ * default statement.
+ */
+public interface YangDefault {
+
+ /**
+ * Returns the default value.
+ *
+ * @return the default value
+ */
+ String getDefaultValueInString();
+
+ /**
+ * Sets the default value.
+ *
+ * @param defaultValueInString the default value
+ */
+ void setDefaultValueInString(String defaultValueInString);
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviateAdd.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviateAdd.java
new file mode 100644
index 0000000..87603fd
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviateAdd.java
@@ -0,0 +1,291 @@
+/*
+ * 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.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DEVIATE_ADD;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The "deviate" statement defines how the device's implementation of
+ * the target node deviates from its original definition. The argument
+ * is one of the strings "not-supported", "add", "replace", or "delete".
+ *
+ * The argument "add" adds properties to the target node. The
+ * properties to add are identified by substatements to the "deviate"
+ * statement. If a property can only appear once, the property MUST NOT
+ * exist in the target node.
+ *
+ * The deviate's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | config | 7.19.1 | 0..1 | YangConfig |
+ * | default | 7.6.4 | 0..1 | String |
+ * | mandatory | 7.6.5 | 0..1 | boolean |
+ * | max-elements | 7.7.4 | 0..1 | YangMaxElement |
+ * | min-elements | 7.7.3 | 0..1 | YangMinElement |
+ * | must | 7.5.3 | 0..n | YangMust |
+ * | type | 7.4 | 0..1 | YangType |
+ * | unique | 7.8.3 | 0..n | String |
+ * | units | 7.3.3 | 0..1 | String |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents deviate add data represented in YANG.
+ */
+public class YangDeviateAdd implements YangConfig, Parsable,
+ YangMustHolder, YangUniqueHolder, YangMaxElementHolder,
+ YangMinElementHolder, YangUnits, YangMandatory, YangDefault,
+ Serializable {
+
+ private static final long serialVersionUID = 806201609L;
+
+ /**
+ * Textual units info.
+ */
+ private String units;
+
+ /**
+ * List of must statement constraints.
+ */
+ private List<YangMust> mustConstraintList;
+
+ /**
+ * List of unique leaf names.
+ */
+ private List<String> uniqueList;
+
+ /**
+ * Default value in string, needs to be converted to the target object,
+ * based on the type.
+ */
+ private String defaultValueInString;
+
+ /**
+ * Deviate's config data.
+ */
+ private boolean isConfig;
+
+ /**
+ * Mandatory constraint.
+ */
+ private boolean isMandatory;
+
+ /**
+ * Deviate's max element data.
+ */
+ private YangMaxElement maxElements;
+
+ /**
+ * Deviate's min element data.
+ */
+ private YangMinElement minElements;
+
+ /**
+ * Creates a YANG deviate add object.
+ */
+ public YangDeviateAdd() {
+ mustConstraintList = new LinkedList<>();
+ uniqueList = new LinkedList<>();
+ }
+
+ @Override
+ public boolean isConfig() {
+ return isConfig;
+ }
+
+ @Override
+ public void setConfig(boolean isConfig) {
+ this.isConfig = isConfig;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return DEVIATE_ADD;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // do nothing
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // do nothing
+ }
+
+ @Override
+ public List<YangMust> getListOfMust() {
+ return mustConstraintList;
+ }
+
+ @Override
+ public void setListOfMust(List<YangMust> mustConstraintList) {
+ this.mustConstraintList = mustConstraintList;
+ }
+
+ @Override
+ public void addMust(YangMust must) {
+ mustConstraintList.add(must);
+ }
+
+ /**
+ * Returns the max elements.
+ *
+ * @return the max elements
+ */
+ @Override
+ public YangMaxElement getMaxElements() {
+ return maxElements;
+ }
+
+ /**
+ * Sets the max elements.
+ *
+ * @param max the max elements
+ */
+ @Override
+ public void setMaxElements(YangMaxElement max) {
+ this.maxElements = max;
+ }
+
+ /**
+ * Returns the minimum elements.
+ *
+ * @return the minimum elements
+ */
+ @Override
+ public YangMinElement getMinElements() {
+ return minElements;
+ }
+
+ /**
+ * Sets the minimum elements.
+ *
+ * @param minElements the minimum elements
+ */
+ @Override
+ public void setMinElements(YangMinElement minElements) {
+ this.minElements = minElements;
+ }
+
+ /**
+ * Returns the units.
+ *
+ * @return the units
+ */
+ @Override
+ public String getUnits() {
+ return units;
+ }
+
+ /**
+ * Sets the units.
+ *
+ * @param units the units to set
+ */
+ @Override
+ public void setUnits(String units) {
+ this.units = units;
+ }
+
+ /**
+ * Returns if the leaf is mandatory.
+ *
+ * @return if leaf is mandatory
+ */
+ @Override
+ public boolean isMandatory() {
+ return isMandatory;
+ }
+
+ /**
+ * Sets if the leaf is mandatory.
+ *
+ * @param isReq if the leaf is mandatory
+ */
+ @Override
+ public void setMandatory(boolean isReq) {
+ isMandatory = isReq;
+ }
+
+ /**
+ * Returns the default value.
+ *
+ * @return the default value
+ */
+ @Override
+ public String getDefaultValueInString() {
+ return defaultValueInString;
+ }
+
+ /**
+ * Sets the default value.
+ *
+ * @param defaultValueInString the default value
+ */
+ @Override
+ public void setDefaultValueInString(String defaultValueInString) {
+ this.defaultValueInString = defaultValueInString;
+ }
+
+ /**
+ * Returns the list of unique field names.
+ *
+ * @return the list of unique field names
+ */
+ @Override
+ public List<String> getUniqueList() {
+ return uniqueList;
+ }
+
+ /**
+ * Sets the list of unique field names.
+ *
+ * @param uniqueList the list of unique field names
+ */
+ @Override
+ public void setUniqueList(List<String> uniqueList) {
+ this.uniqueList = uniqueList;
+ }
+
+ /**
+ * Adds a unique field name.
+ *
+ * @param unique unique field name
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void addUnique(String unique) throws DataModelException {
+ if (uniqueList.contains(unique)) {
+ throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
+ " unique");
+ }
+ uniqueList.add(unique);
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviateDelete.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviateDelete.java
new file mode 100644
index 0000000..d93cd93
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviateDelete.java
@@ -0,0 +1,201 @@
+/*
+ * 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.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DEVIATE_DELETE;
+
+/*
+ * Reference 6020.
+ *
+ * The "deviate" statement defines how the device's implementation of
+ * the target node deviates from its original definition. The argument
+ * is one of the strings "not-supported", "add", "replace", or "delete".
+ *
+ * The argument "delete" deletes properties from the target node. The
+ * properties to delete are identified by substatements to the "delete"
+ * statement. The substatement's keyword MUST match a corresponding
+ * keyword in the target node, and the argument's string MUST be equal
+ * to the corresponding keyword's argument string in the target node.
+ *
+ * The deviate's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | config | 7.19.1 | 0..1 | YangConfig |
+ * | default | 7.6.4 | 0..1 | String |
+ * | mandatory | 7.6.5 | 0..1 | boolean |
+ * | max-elements | 7.7.4 | 0..1 | YangMaxElement |
+ * | min-elements | 7.7.3 | 0..1 | YangMinElement |
+ * | must | 7.5.3 | 0..n | YangMust |
+ * | type | 7.4 | 0..1 | YangType |
+ * | unique | 7.8.3 | 0..n | String |
+ * | units | 7.3.3 | 0..1 | String |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents deviate delete data represented in YANG.
+ */
+public class YangDeviateDelete implements Parsable, YangMustHolder,
+ YangUniqueHolder, YangDefault, YangUnits, Serializable {
+
+ private static final long serialVersionUID = 806201609L;
+
+ /**
+ * Textual units info.
+ */
+ private String units;
+
+ /**
+ * List of must statement constraints.
+ */
+ private List<YangMust> mustConstraintList;
+
+ /**
+ * List of unique leaf names.
+ */
+ private List<String> uniqueList;
+
+ /**
+ * Default value in string, needs to be converted to the target object,
+ * based on the type.
+ */
+ private String defaultValueInString;
+
+ /**
+ * Creates a YANG deviate delete object.
+ */
+ public YangDeviateDelete() {
+ mustConstraintList = new LinkedList<>();
+ uniqueList = new LinkedList<>();
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return DEVIATE_DELETE;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // do nothing
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // do nothing
+ }
+
+ @Override
+ public List<YangMust> getListOfMust() {
+ return mustConstraintList;
+ }
+
+ @Override
+ public void setListOfMust(List<YangMust> mustConstraintList) {
+ this.mustConstraintList = mustConstraintList;
+ }
+
+ @Override
+ public void addMust(YangMust must) {
+ mustConstraintList.add(must);
+ }
+
+ /**
+ * Returns the units.
+ *
+ * @return the units
+ */
+ @Override
+ public String getUnits() {
+ return units;
+ }
+
+ /**
+ * Sets the units.
+ *
+ * @param units the units to set
+ */
+ @Override
+ public void setUnits(String units) {
+ this.units = units;
+ }
+
+ /**
+ * Returns the list of unique field names.
+ *
+ * @return the list of unique field names
+ */
+ @Override
+ public List<String> getUniqueList() {
+ return uniqueList;
+ }
+
+ /**
+ * Sets the list of unique field names.
+ *
+ * @param uniqueList the list of unique field names
+ */
+ @Override
+ public void setUniqueList(List<String> uniqueList) {
+ this.uniqueList = uniqueList;
+ }
+
+ /**
+ * Adds a unique field name.
+ *
+ * @param unique unique field name
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void addUnique(String unique)
+ throws DataModelException {
+ if (uniqueList.contains(unique)) {
+ throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
+ " unique");
+ }
+ uniqueList.add(unique);
+ }
+
+ /**
+ * Returns the default value.
+ *
+ * @return the default value
+ */
+ @Override
+ public String getDefaultValueInString() {
+ return defaultValueInString;
+ }
+
+ /**
+ * Sets the default value.
+ *
+ * @param defaultValueInString the default value
+ */
+ @Override
+ public void setDefaultValueInString(String defaultValueInString) {
+ this.defaultValueInString = defaultValueInString;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviateReplace.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviateReplace.java
new file mode 100644
index 0000000..b42d685
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviateReplace.java
@@ -0,0 +1,244 @@
+/*
+ * 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.yang.compiler.datamodel;
+
+/*
+ * Refernce 6020.
+ *
+ * The "deviate" statement defines how the device's implementation of
+ * the target node deviates from its original definition. The argument
+ * is one of the strings "not-supported", "add", "replace", or "delete".
+ *
+ * The argument "replace" replaces properties of the target node. The
+ * properties to replace are identified by substatements to the
+ * "deviate" statement. The properties to replace MUST exist in the
+ * target node.
+ *
+ * The deviate's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | config | 7.19.1 | 0..1 | YangConfig |
+ * | default | 7.6.4 | 0..1 | String |
+ * | mandatory | 7.6.5 | 0..1 | boolean |
+ * | max-elements | 7.7.4 | 0..1 | YangMaxElement |
+ * | min-elements | 7.7.3 | 0..1 | YangMinElement |
+ * | must | 7.5.3 | 0..n | YangMust |
+ * | type | 7.4 | 0..1 | YangType |
+ * | unique | 7.8.3 | 0..n | String |
+ * | units | 7.3.3 | 0..1 | String |
+ * +--------------+---------+-------------+------------------+
+ */
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DEVIATE_REPLACE;
+
+/**
+ * Represents deviate replace data represented in YANG.
+ */
+public class YangDeviateReplace implements YangUnits, YangMinElementHolder,
+ YangMaxElementHolder, YangMandatory, YangDefault, Parsable,
+ YangConfig, Serializable {
+
+ private static final long serialVersionUID = 806201609L;
+
+ /**
+ * Textual units info.
+ */
+ private String units;
+
+ /**
+ * Deviate's config data.
+ */
+ private boolean isConfig;
+
+ /**
+ * Deviate's max element data.
+ */
+ private YangMaxElement maxElements;
+
+ /**
+ * Deviate's min element data.
+ */
+ private YangMinElement minElements;
+
+ /**
+ * Mandatory constraint.
+ */
+ private boolean isMandatory;
+
+ /**
+ * Default value in string, needs to be converted to the target object,
+ * based on the type.
+ */
+ private String defaultValueInString;
+
+ /**
+ * Data type of the leaf.
+ */
+ private YangType<?> dataType;
+
+
+ @Override
+ public boolean isConfig() {
+ return isConfig;
+ }
+
+ @Override
+ public void setConfig(boolean isConfig) {
+ this.isConfig = isConfig;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return DEVIATE_REPLACE;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // do nothing
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // do nothing
+ }
+
+ /**
+ * Returns the max elements.
+ *
+ * @return the max elements
+ */
+ @Override
+ public YangMaxElement getMaxElements() {
+ return maxElements;
+ }
+
+ /**
+ * Sets the max elements.
+ *
+ * @param max the max elements
+ */
+ @Override
+ public void setMaxElements(YangMaxElement max) {
+ this.maxElements = max;
+ }
+
+ /**
+ * Returns the minimum elements.
+ *
+ * @return the minimum elements
+ */
+ @Override
+ public YangMinElement getMinElements() {
+ return minElements;
+ }
+
+ /**
+ * Sets the minimum elements.
+ *
+ * @param minElements the minimum elements
+ */
+ @Override
+ public void setMinElements(YangMinElement minElements) {
+ this.minElements = minElements;
+ }
+
+ /**
+ * Returns the units.
+ *
+ * @return the units
+ */
+ @Override
+ public String getUnits() {
+ return units;
+ }
+
+ /**
+ * Sets the units.
+ *
+ * @param units the units to set
+ */
+ @Override
+ public void setUnits(String units) {
+ this.units = units;
+ }
+
+ /**
+ * Returns if the leaf is mandatory.
+ *
+ * @return if leaf is mandatory
+ */
+ @Override
+ public boolean isMandatory() {
+ return isMandatory;
+ }
+
+ /**
+ * Sets if the leaf is mandatory.
+ *
+ * @param isReq if the leaf is mandatory
+ */
+ @Override
+ public void setMandatory(boolean isReq) {
+ isMandatory = isReq;
+ }
+
+ /**
+ * Returns the default value.
+ *
+ * @return the default value
+ */
+ @Override
+ public String getDefaultValueInString() {
+ return defaultValueInString;
+ }
+
+ /**
+ * Sets the default value.
+ *
+ * @param defaultValueInString the default value
+ */
+ @Override
+ public void setDefaultValueInString(String defaultValueInString) {
+ this.defaultValueInString = defaultValueInString;
+ }
+
+ /**
+ * Returns the data type.
+ *
+ * @return the data type
+ */
+ public YangType<?> getDataType() {
+ return dataType;
+ }
+
+ /**
+ * Sets the data type.
+ *
+ * @param dataType the data type to set
+ */
+ public void setDataType(YangType<?> dataType) {
+ this.dataType = dataType;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviation.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviation.java
new file mode 100644
index 0000000..57f9a53
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviation.java
@@ -0,0 +1,346 @@
+/*
+ * 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.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_NON_DATA_NODE;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DEVIATION_DATA;
+
+/**
+ * Represents deviation data represented in YANG.
+ */
+public class YangDeviation extends YangNode implements Parsable, YangDesc,
+ YangReference, YangXPathResolver, Resolvable, CollisionDetector {
+
+ private static final long serialVersionUID = 806201605L;
+
+ /**
+ * List of node identifiers.
+ */
+ private List<YangAtomicPath> targetNode;
+
+ /**
+ * Description of augment.
+ */
+ private String description;
+
+ /**
+ * Reference of the YANG augment.
+ */
+ private String reference;
+
+ /**
+ * Represents deviate-not-supported statement.
+ */
+ private boolean isDeviateNotSupported;
+
+ /**
+ * Represents deviate add statement.
+ */
+ private List<YangDeviateAdd> deviateAddList;
+
+ /**
+ * Represents deviate delete statement.
+ */
+ private List<YangDeviateDelete> deviateDeleteList;
+
+ /**
+ * Represents deviate replace statement.
+ */
+ private List<YangDeviateReplace> deviateReplaceList;
+
+ /**
+ * Status of resolution.
+ */
+ private ResolvableStatus resolvableStatus;
+
+ /**
+ * Creates a specific type of node.
+ *
+ * @param type of YANG node
+ * @param ysnContextInfoMap YSN context info map
+ */
+ public YangDeviation(YangNodeType type, Map<YangSchemaNodeIdentifier,
+ YangSchemaNodeContextInfo> ysnContextInfoMap) {
+ super(type, ysnContextInfoMap);
+ targetNode = new LinkedList<>();
+ resolvableStatus = ResolvableStatus.UNRESOLVED;
+ deviateAddList = new LinkedList<>();
+ deviateDeleteList = new LinkedList<>();
+ deviateReplaceList = new LinkedList<>();
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_NON_DATA_NODE;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ // do nothing
+ return null;
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ // do nothing
+ return null;
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ // do nothing
+ return null;
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier schemaNodeIdentifier,
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+ throws DataModelException {
+ // do nothing
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // do nothing
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier,
+ YangSchemaNode yangSchemaNode) {
+ // do nothing
+ }
+
+ /**
+ * Returns the augmented node.
+ *
+ * @return the augmented node
+ */
+ public List<YangAtomicPath> getTargetNode() {
+ return targetNode;
+ }
+
+ /**
+ * Sets the augmented node.
+ *
+ * @param nodeIdentifiers the augmented node
+ */
+ public void setTargetNode(List<YangAtomicPath> nodeIdentifiers) {
+ targetNode = nodeIdentifiers;
+ }
+
+ /**
+ * 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 description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Set the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return DEVIATION_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // do nothing
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // do nothing
+ }
+
+ @Override
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ @Override
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+ }
+
+ @Override
+ public Object resolve() throws DataModelException {
+ // Resolving of target node is being done in XPathLinker.
+ return null;
+ }
+
+ /**
+ * Returns the isDeviateNotSupported flag.
+ *
+ * @return if isDeviateNotSupported flag
+ */
+ public boolean isDeviateNotSupported() {
+ return isDeviateNotSupported;
+ }
+
+ /**
+ * Sets the isDeviateNotSupported flag.
+ *
+ * @param deviateNotSupported the flag value to set
+ */
+ public void setDeviateNotSupported(boolean deviateNotSupported) {
+ isDeviateNotSupported = deviateNotSupported;
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName,
+ YangConstructType dataType)
+ throws DataModelException {
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName,
+ YangConstructType dataType)
+ throws DataModelException {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException(
+ "YANG file error: Duplicate input identifier detected, " +
+ "same as input \"" +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+
+ /**
+ * Returns the list of deviate-add.
+ *
+ * @return the list of deviate-add
+ */
+ public List<YangDeviateAdd> getDeviateAdd() {
+ return deviateAddList;
+ }
+
+ /**
+ * Sets the list of deviate-add.
+ *
+ * @param deviateAdd the list of deviate-add to set
+ */
+ public void setDeviateAdd(List<YangDeviateAdd> deviateAdd) {
+ this.deviateAddList = deviateAdd;
+ }
+
+ /**
+ * Returns the list of deviate delete.
+ *
+ * @return the list of deviate delete
+ */
+ public List<YangDeviateDelete> getDeviateDelete() {
+ return deviateDeleteList;
+ }
+
+ /**
+ * Sets the list of deviate delete.
+ *
+ * @param deviateDelete the list of deviate delete to set
+ */
+ public void setDeviateDelete(List<YangDeviateDelete> deviateDelete) {
+ this.deviateDeleteList = deviateDelete;
+ }
+
+ /**
+ * Returns the list of deviate replace.
+ *
+ * @return the list of deviate replace
+ */
+ public List<YangDeviateReplace> getDeviateReplace() {
+ return deviateReplaceList;
+ }
+
+ /**
+ * Sets the list of deviate replace.
+ *
+ * @param deviateReplace the list of deviate-replace to set
+ */
+ public void setDeviateReplace(List<YangDeviateReplace> deviateReplace) {
+ this.deviateReplaceList = deviateReplace;
+ }
+
+ /**
+ * Adds a deviate-add.
+ *
+ * @param deviate the deviate-add to be added
+ */
+ public void addDeviateAdd(YangDeviateAdd deviate) {
+ deviateAddList.add(deviate);
+ }
+
+ /**
+ * Adds a deviate delete.
+ *
+ * @param deviate the deviate delete to be added
+ */
+ public void addDeviatedelete(YangDeviateDelete deviate) {
+ deviateDeleteList.add(deviate);
+ }
+
+ /**
+ * Adds a deviate replace.
+ *
+ * @param deviate the deviate replace to be added
+ */
+ public void addDeviateReplace(YangDeviateReplace deviate) {
+ deviateReplaceList.add(deviate);
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviationHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviationHolder.java
new file mode 100644
index 0000000..358a9b7
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDeviationHolder.java
@@ -0,0 +1,54 @@
+/*
+ * 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.yang.compiler.datamodel;
+
+/**
+ * Abstraction of deviation entity. It is used to abstract the data holders of
+ * deviation statement.
+ */
+public interface YangDeviationHolder {
+
+ /**
+ * Returns true if deviated node already cloned, false
+ * otherwise.
+ *
+ * @return the isDeviateNodeCloned flag
+ */
+ boolean isDeviatedNodeCloned();
+
+ /**
+ * Sets the deviatedNodeCloned flag.
+ *
+ * @param deviatedNodeCloned the flag to set
+ */
+ void setDeviatedNodeCloned(boolean deviatedNodeCloned);
+
+ /**
+ * Returns true if module defined only for deviation,
+ * false otherwise.
+ *
+ * @return the isDeviateNodeCloned flag
+ */
+ boolean isModuleForDeviation();
+
+ /**
+ * Sets the moduleForDeviation flag.
+ *
+ * @param moduleForDeviation the flag to set
+ */
+ void setModuleForDeviation(boolean moduleForDeviation);
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangGrouping.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangGrouping.java
index da87a1d..aa2303b 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangGrouping.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangGrouping.java
@@ -204,6 +204,16 @@
}
/**
+ * Removes a leaf.
+ *
+ * @param leaf the leaf to be removed
+ */
+ @Override
+ public void removeLeaf(YangLeaf leaf) {
+ listOfLeaf.remove(leaf);
+ }
+
+ /**
* Returns the list of leaf-list.
*
* @return the list of leaf-list
@@ -234,6 +244,16 @@
}
/**
+ * Removes a leaf-list.
+ *
+ * @param leafList the leaf-list to be removed
+ */
+ @Override
+ public void removeLeafList(YangLeafList leafList) {
+ listOfLeafList.remove(leafList);
+ }
+
+ /**
* Returns the textual reference.
*
* @return the reference
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentity.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentity.java
index 94732a9..316af01 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentity.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentity.java
@@ -20,6 +20,8 @@
import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
/*-
* Reference RFC 6020.
@@ -65,14 +67,21 @@
//YANG reference of the identity.
private String reference;
+ /*
+ * Identity extend list to contain list of all the direct/indirect derived
+ * identities.
+ */
+ private List<YangIdentity> extendList;
+
//Creates a identity type of node.
public YangIdentity() {
super(YangNodeType.IDENTITY_NODE, null);
+ extendList = new LinkedList<>();
}
@Override
public void addToChildSchemaMap(YangSchemaNodeIdentifier schemaNodeIdentifier,
- YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
throws DataModelException {
// Do nothing.
}
@@ -154,4 +163,31 @@
public void setBaseNode(YangBase baseNode) {
this.baseNode = baseNode;
}
+
+ /**
+ * Returns the list of derived identities which extends the identity.
+ *
+ * @return the list of derived identities which extends the identity
+ */
+ public List<YangIdentity> getExtendList() {
+ return extendList;
+ }
+
+ /**
+ * Sets the list of derived identity.
+ *
+ * @param extendList the list of derived identities
+ */
+ public void setExtendList(List<YangIdentity> extendList) {
+ this.extendList = extendList;
+ }
+
+ /**
+ * Adds a derived identity.
+ *
+ * @param identity derived identity
+ */
+ public void addToExtendList(YangIdentity identity) {
+ extendList.add(identity);
+ }
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentityRef.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentityRef.java
index 6c5817f..537f606 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentityRef.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentityRef.java
@@ -293,7 +293,8 @@
}
@Override
- public YangNode clone(YangUses yangUses) throws CloneNotSupportedException {
+ public YangNode clone(YangUses yangUses, boolean isDeviation)
+ throws CloneNotSupportedException {
return (YangNode) super.clone();
}
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangInput.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangInput.java
index 10d7188..a1019a5 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangInput.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangInput.java
@@ -183,6 +183,16 @@
listOfLeaf.add(leaf);
}
+ /**
+ * Removes a leaf.
+ *
+ * @param leaf the leaf to be removed
+ */
+ @Override
+ public void removeLeaf(YangLeaf leaf) {
+ listOfLeaf.remove(leaf);
+ }
+
@Override
public List<YangLeafList> getListOfLeafList() {
return unmodifiableList(listOfLeafList);
@@ -198,6 +208,16 @@
listOfLeafList.add(leafList);
}
+ /**
+ * Removes a leaf-list.
+ *
+ * @param leafList the leaf-list to be removed
+ */
+ @Override
+ public void removeLeafList(YangLeafList leafList) {
+ listOfLeafList.remove(leafList);
+ }
+
@Override
public void addAugmentation(YangAugment augmentInfo) {
yangAugmentedInfo.add(augmentInfo);
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java
index a1cf665..7d64d7f 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java
@@ -68,7 +68,7 @@
public abstract class YangLeaf extends DefaultLocationInfo
implements YangCommonInfo, Parsable, Cloneable, Serializable,
YangMustHolder, YangIfFeatureHolder, YangWhenHolder, YangSchemaNode,
- YangConfig {
+ YangConfig, YangUnits, YangDefault, YangMandatory {
private static final long serialVersionUID = 806201635L;
@@ -143,7 +143,8 @@
*/
private YangLeaf referredLeaf;
- private boolean isKeyLeaf;
+ private boolean isKeyLeaf;
+
/**
* Creates a YANG leaf.
*/
@@ -217,6 +218,7 @@
*
* @return if leaf is mandatory
*/
+ @Override
public boolean isMandatory() {
return isMandatory;
}
@@ -226,6 +228,7 @@
*
* @param isReq if the leaf is mandatory
*/
+ @Override
public void setMandatory(boolean isReq) {
isMandatory = isReq;
}
@@ -275,6 +278,7 @@
*
* @return the units
*/
+ @Override
public String getUnits() {
return units;
}
@@ -284,6 +288,7 @@
*
* @param units the units to set
*/
+ @Override
public void setUnits(String units) {
this.units = units;
}
@@ -293,6 +298,7 @@
*
* @return the default value
*/
+ @Override
public String getDefaultValueInString() {
return defaultValueInString;
}
@@ -302,6 +308,7 @@
*
* @param defaultValueInString the default value
*/
+ @Override
public void setDefaultValueInString(String defaultValueInString) {
this.defaultValueInString = defaultValueInString;
}
@@ -356,6 +363,19 @@
}
/**
+ * Returns the cloned leaf.
+ *
+ * @return returns cloned leaf
+ * @throws CloneNotSupportedException if the object's class does not
+ * support the interface
+ */
+ public YangLeaf cloneForDeviation()
+ throws CloneNotSupportedException {
+ YangLeaf cl = (YangLeaf) super.clone();
+ return cl;
+ }
+
+ /**
* Returns the type of the parsed data.
*
* @return returns LEAF_DATA
@@ -557,6 +577,7 @@
public void setReferredLeaf(YangLeaf leaf) {
referredLeaf = leaf;
}
+
/**
* Returns true if its a key leaf.
*
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java
index 2477d1a..93a0683 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java
@@ -64,7 +64,7 @@
public abstract class YangLeafList extends DefaultLocationInfo
implements YangCommonInfo, Parsable, Cloneable, Serializable,
YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangSchemaNode,
- YangConfig {
+ YangConfig, YangUnits, YangMaxElementHolder, YangMinElementHolder {
private static final long serialVersionUID = 806201637L;
@@ -235,6 +235,7 @@
*
* @return the maximum elements number
*/
+ @Override
public YangMaxElement getMaxElements() {
return maxElement;
}
@@ -244,6 +245,7 @@
*
* @param maxElement maximum elements number
*/
+ @Override
public void setMaxElements(YangMaxElement maxElement) {
this.maxElement = maxElement;
}
@@ -253,6 +255,7 @@
*
* @return the minimum elements number
*/
+ @Override
public YangMinElement getMinElements() {
return minElements;
}
@@ -262,6 +265,7 @@
*
* @param minElements the minimum elements number
*/
+ @Override
public void setMinElements(YangMinElement minElements) {
this.minElements = minElements;
}
@@ -311,6 +315,7 @@
*
* @return the units
*/
+ @Override
public String getUnits() {
return units;
}
@@ -320,6 +325,7 @@
*
* @param units the units to set
*/
+ @Override
public void setUnits(String units) {
this.units = units;
}
@@ -374,6 +380,19 @@
}
/**
+ * Returns the cloned leaf-list.
+ *
+ * @return returns cloned leaf-list
+ * @throws CloneNotSupportedException if the object's class does not
+ * support the interface
+ */
+ public YangLeafList cloneForDeviation()
+ throws CloneNotSupportedException {
+ YangLeafList cll = (YangLeafList) super.clone();
+ return cll;
+ }
+
+ /**
* Returns the type of the parsed data.
*
* @return returns LEAF_LIST_DATA
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeavesHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeavesHolder.java
index ad39253..e7e1fac 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeavesHolder.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeavesHolder.java
@@ -47,6 +47,13 @@
void addLeaf(YangLeaf leaf);
/**
+ * Removes leaf in data holder like container / list.
+ *
+ * @param leaf the leaf to be removed
+ */
+ void removeLeaf(YangLeaf leaf);
+
+ /**
* Returns the list of leaf-list from data holder like container / list.
*
* @return the list of leaf-list
@@ -68,6 +75,13 @@
void addLeafList(YangLeafList leafList);
/**
+ * Removes leaf-list in data holder like container / list.
+ *
+ * @param leafList the leaf-list to be removed
+ */
+ void removeLeafList(YangLeafList leafList);
+
+ /**
* Adds namespace for leafs and leaf-list, this is used in case of
* submodule.
*
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangList.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangList.java
index 343a8f2..ab01879 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangList.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangList.java
@@ -78,7 +78,8 @@
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangSchemaNode,
- YangIsFilterContentNodes, YangConfig {
+ YangIsFilterContentNodes, YangConfig, YangUniqueHolder,
+ YangMaxElementHolder, YangMinElementHolder {
private static final long serialVersionUID = 806201609L;
@@ -330,6 +331,7 @@
*
* @return the list of unique field names
*/
+ @Override
public List<String> getUniqueList() {
return uniqueList;
}
@@ -339,7 +341,8 @@
*
* @param uniqueList the list of unique field names
*/
- private void setUniqueList(List<String> uniqueList) {
+ @Override
+ public void setUniqueList(List<String> uniqueList) {
this.uniqueList = uniqueList;
}
@@ -391,6 +394,7 @@
* @param unique unique field name.
* @throws DataModelException a violation of data model rules
*/
+ @Override
public void addUnique(String unique)
throws DataModelException {
if (getUniqueList() == null) {
@@ -434,7 +438,17 @@
*/
@Override
public void addLeaf(YangLeaf leaf) {
- getListOfLeaf().add(leaf);
+ listOfLeaf.add(leaf);
+ }
+
+ /**
+ * Removes a leaf.
+ *
+ * @param leaf the leaf to be removed
+ */
+ @Override
+ public void removeLeaf(YangLeaf leaf) {
+ listOfLeaf.remove(leaf);
}
/**
@@ -464,7 +478,17 @@
*/
@Override
public void addLeafList(YangLeafList leafList) {
- getListOfLeafList().add(leafList);
+ listOfLeafList.add(leafList);
+ }
+
+ /**
+ * Removes a leaf-list.
+ *
+ * @param leafList the leaf-list to be removed
+ */
+ @Override
+ public void removeLeafList(YangLeafList leafList) {
+ listOfLeafList.remove(leafList);
}
/**
@@ -472,6 +496,7 @@
*
* @return the max elements
*/
+ @Override
public YangMaxElement getMaxElements() {
return maxElements;
}
@@ -481,6 +506,7 @@
*
* @param max the max elements
*/
+ @Override
public void setMaxElements(YangMaxElement max) {
this.maxElements = max;
}
@@ -490,6 +516,7 @@
*
* @return the minimum elements
*/
+ @Override
public YangMinElement getMinElements() {
return minElements;
}
@@ -499,6 +526,7 @@
*
* @param minElements the minimum elements
*/
+ @Override
public void setMinElements(YangMinElement minElements) {
this.minElements = minElements;
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMandatory.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMandatory.java
new file mode 100644
index 0000000..a436e61
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMandatory.java
@@ -0,0 +1,38 @@
+/*
+ * 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.yang.compiler.datamodel;
+
+/**
+ * Abstraction of mandatory entity. It is used to abstract the data holders of
+ * mandatory statement.
+ */
+public interface YangMandatory {
+
+ /**
+ * Returns true, if the leaf is mandatory; false otherwise.
+ *
+ * @return true if leaf is mandatory; false otherwise
+ */
+ boolean isMandatory();
+
+ /**
+ * Sets the mandatory flag.
+ *
+ * @param isReq the flag value to set
+ */
+ void setMandatory(boolean isReq);
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMaxElementHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMaxElementHolder.java
new file mode 100644
index 0000000..2e543db
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMaxElementHolder.java
@@ -0,0 +1,38 @@
+/*
+ * 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.yang.compiler.datamodel;
+
+/**
+ * Abstraction of max-element entity. It is used to abstract the data holders
+ * of max-element statement.
+ */
+public interface YangMaxElementHolder {
+
+ /**
+ * Returns the max elements.
+ *
+ * @return the max elements
+ */
+ YangMaxElement getMaxElements();
+
+ /**
+ * Sets the max elements.
+ *
+ * @param max the max elements
+ */
+ void setMaxElements(YangMaxElement max);
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMinElementHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMinElementHolder.java
new file mode 100644
index 0000000..d5c4375
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMinElementHolder.java
@@ -0,0 +1,38 @@
+/*
+ * 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.yang.compiler.datamodel;
+
+/**
+ * Abstraction of min-element entity. It is used to abstract the data holders
+ * of min-element statement.
+ */
+public interface YangMinElementHolder {
+
+ /**
+ * Returns the minimum elements.
+ *
+ * @return the minimum elements
+ */
+ YangMinElement getMinElements();
+
+ /**
+ * Sets the minimum elements.
+ *
+ * @param minElements the minimum elements
+ */
+ void setMinElements(YangMinElement minElements);
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangModule.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangModule.java
index 360b192..09dbc98 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangModule.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangModule.java
@@ -30,6 +30,7 @@
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_BASE;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_COMPILER_ANNOTATION;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_DERIVED_DATA_TYPE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_DEVIATION;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IDENTITYREF;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IF_FEATURE;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_LEAFREF;
@@ -87,7 +88,7 @@
extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable,
CollisionDetector, YangReferenceResolver, RpcNotificationContainer,
- YangFeatureHolder, YangIsFilterContentNodes, YangNamespace {
+ YangFeatureHolder, YangIsFilterContentNodes, YangNamespace, YangDeviationHolder {
private static final long serialVersionUID = 806201610L;
@@ -239,6 +240,11 @@
private List<YangResolutionInfo> compilerAnnotationList;
/**
+ * Deviation list.
+ */
+ private List<YangResolutionInfo> deviationList;
+
+ /**
* Extension list.
*/
private List<YangExtension> extensionList;
@@ -264,10 +270,19 @@
private String namespace;
/**
+ * Flag to check whether target node is already cloned.
+ */
+ private boolean isDeviatedNodeCloned;
+
+ /**
+ * Flag to check whether this module is only for deviation.
+ */
+ private boolean isModuleForDeviation;
+
+ /**
* Creates a YANG node of module type.
*/
public YangModule() {
-
super(YangNodeType.MODULE_NODE, new HashMap<>());
derivedTypeResolutionList = new LinkedList<>();
augmentResolutionList = new LinkedList<>();
@@ -277,6 +292,7 @@
baseResolutionList = new LinkedList<>();
identityRefResolutionList = new LinkedList<>();
compilerAnnotationList = new LinkedList<>();
+ deviationList = new LinkedList<>();
importList = new LinkedList<>();
includeList = new LinkedList<>();
listOfLeaf = new LinkedList<>();
@@ -423,6 +439,16 @@
}
/**
+ * Removes a leaf.
+ *
+ * @param leaf the leaf to be removed
+ */
+ @Override
+ public void removeLeaf(YangLeaf leaf) {
+ getListOfLeaf().remove(leaf);
+ }
+
+ /**
* Returns the list of leaf-list from module.
*
* @return the list of leaf-list
@@ -448,6 +474,16 @@
listOfLeafList.add(leafList);
}
+ /**
+ * Removes a leaf-list.
+ *
+ * @param leafList the leaf-list to be removed
+ */
+ @Override
+ public void removeLeafList(YangLeafList leafList) {
+ getListOfLeafList().remove(leafList);
+ }
+
@Override
public List<YangFeature> getFeatureList() {
return unmodifiableList(listOfFeature);
@@ -680,8 +716,10 @@
return unmodifiableList(baseResolutionList);
} else if (type == YANG_IDENTITYREF) {
return unmodifiableList(identityRefResolutionList);
- } else {
+ } else if (type == YANG_COMPILER_ANNOTATION) {
return unmodifiableList(compilerAnnotationList);
+ } else {
+ return unmodifiableList(deviationList);
}
}
@@ -704,6 +742,8 @@
identityRefResolutionList.add(info);
} else if (type == YANG_COMPILER_ANNOTATION) {
compilerAnnotationList.add(info);
+ } else if (type == YANG_DEVIATION) {
+ deviationList.add(info);
}
}
@@ -726,6 +766,8 @@
identityRefResolutionList = resolutionList;
} else if (type == YANG_COMPILER_ANNOTATION) {
compilerAnnotationList = resolutionList;
+ } else if (type == YANG_DEVIATION) {
+ deviationList = resolutionList;
}
}
@@ -817,4 +859,24 @@
public void setModuleNamespace(String namespace) {
this.namespace = namespace;
}
+
+ @Override
+ public boolean isDeviatedNodeCloned() {
+ return isDeviatedNodeCloned;
+ }
+
+ @Override
+ public void setDeviatedNodeCloned(boolean deviatedNodeCloned) {
+ this.isDeviatedNodeCloned = deviatedNodeCloned;
+ }
+
+ @Override
+ public boolean isModuleForDeviation() {
+ return isModuleForDeviation;
+ }
+
+ @Override
+ public void setModuleForDeviation(boolean moduleForDeviation) {
+ isModuleForDeviation = moduleForDeviation;
+ }
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java
index d962a39..8b7f597 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java
@@ -396,19 +396,22 @@
/**
* Clones the current node contents and create a new node.
*
- * @param yangUses YANG uses
+ * @param yangUses YANG uses
+ * @param isDeviation flag to identify cloning is for deviation
* @return cloned node
* @throws CloneNotSupportedException clone is not supported by the referred
* node
*/
- public YangNode clone(YangUses yangUses)
+ public YangNode clone(YangUses yangUses, boolean isDeviation)
throws CloneNotSupportedException {
YangNode clonedNode = (YangNode) super.clone();
- clonedNode.referredSchemaNode = this;
+
if (clonedNode instanceof YangLeavesHolder) {
try {
- cloneListOfLeaf((YangLeavesHolder) clonedNode, yangUses);
- cloneListOfLeafList((YangLeavesHolder) clonedNode, yangUses);
+ cloneListOfLeaf((YangLeavesHolder) clonedNode, yangUses,
+ isDeviation);
+ cloneListOfLeafList((YangLeavesHolder) clonedNode, yangUses,
+ isDeviation);
} catch (DataModelException e) {
throw new CloneNotSupportedException(e.getMessage());
}
@@ -418,9 +421,12 @@
clonedNode.setChild(null);
clonedNode.setNextSibling(null);
clonedNode.setPreviousSibling(null);
- clonedNode.yangSchemaNodeIdentifier =
- clonedNode.yangSchemaNodeIdentifier.clone();
- clonedNode.ysnContextInfoMap = new HashMap<>();
+ if (!isDeviation) {
+ clonedNode.yangSchemaNodeIdentifier =
+ clonedNode.yangSchemaNodeIdentifier.clone();
+ clonedNode.ysnContextInfoMap = new HashMap<>();
+ clonedNode.referredSchemaNode = this;
+ }
if (clonedNode instanceof YangAugmentableNode) {
((YangAugmentableNode) clonedNode).cloneAugmentInfo();
}
@@ -435,10 +441,11 @@
* @param srcRootNode source node for sub tree cloning
* @param dstRootNode destination node where the sub tree needs to be cloned
* @param yangUses YANG uses
+ * @param isDeviation flag to check whether cloning is for deviation
* @throws DataModelException data model error
*/
public static void cloneSubTree(YangNode srcRootNode, YangNode dstRootNode,
- YangUses yangUses)
+ YangUses yangUses, boolean isDeviation)
throws DataModelException {
YangNode nextNodeToClone = srcRootNode;
@@ -473,7 +480,7 @@
" in " + nextNodeToClone.getFileName() + "\"");
}
if (curTraversal != PARENT) {
- newNode = nextNodeToClone.clone(yangUses);
+ newNode = nextNodeToClone.clone(yangUses, isDeviation);
detectCollisionWhileCloning(clonedTreeCurNode, newNode,
curTraversal);
}
@@ -508,6 +515,7 @@
* update the traversal's current node.
*/
nextNodeToClone = nextNodeToClone.getChild();
+
} else if (nextNodeToClone.getNextSibling() != null) {
curTraversal = SIBILING;
@@ -525,6 +533,7 @@
" at " + nextNodeToClone.getCharPosition() +
" in " + nextNodeToClone.getFileName() + "\"");
}
+
}
/**
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNodeType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNodeType.java
index 1b178d3..994f197 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNodeType.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNodeType.java
@@ -112,5 +112,10 @@
/**
* Identityref node.
*/
- IDENTITYREF_NODE
+ IDENTITYREF_NODE,
+
+ /**
+ * Deviation node
+ */
+ DEVIATION_NODE
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNotification.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNotification.java
index 096b3dc..07a5958 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNotification.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNotification.java
@@ -216,6 +216,16 @@
listOfLeaf.add(leaf);
}
+ /**
+ * Removes a leaf.
+ *
+ * @param leaf the leaf to be removed
+ */
+ @Override
+ public void removeLeaf(YangLeaf leaf) {
+ listOfLeaf.remove(leaf);
+ }
+
@Override
public List<YangLeafList> getListOfLeafList() {
return unmodifiableList(listOfLeafList);
@@ -231,6 +241,16 @@
listOfLeafList.add(leafList);
}
+ /**
+ * Removes a leaf-list.
+ *
+ * @param leafList the leaf-list to be removed
+ */
+ @Override
+ public void removeLeafList(YangLeafList leafList) {
+ listOfLeafList.remove(leafList);
+ }
+
@Override
public String getReference() {
return reference;
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangOutput.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangOutput.java
index 2c206f0..6ce7aed 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangOutput.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangOutput.java
@@ -174,6 +174,16 @@
listOfLeaf.add(leaf);
}
+ /**
+ * Removes a leaf.
+ *
+ * @param leaf the leaf to be removed
+ */
+ @Override
+ public void removeLeaf(YangLeaf leaf) {
+ listOfLeaf.remove(leaf);
+ }
+
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
@@ -194,6 +204,16 @@
listOfLeafList.add(leafList);
}
+ /**
+ * Removes a leaf-list.
+ *
+ * @param leafList the leaf-list to be removed
+ */
+ @Override
+ public void removeLeafList(YangLeafList leafList) {
+ listOfLeafList.remove(leafList);
+ }
+
@Override
public void addAugmentation(YangAugment augmentInfo) {
yangAugmentedInfo.add(augmentInfo);
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSubModule.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSubModule.java
index d67b15f..a83ba5d 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSubModule.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSubModule.java
@@ -31,6 +31,7 @@
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_BASE;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_COMPILER_ANNOTATION;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_DERIVED_DATA_TYPE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_DEVIATION;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IDENTITYREF;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IF_FEATURE;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_LEAFREF;
@@ -96,7 +97,7 @@
extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable,
CollisionDetector, YangReferenceResolver, RpcNotificationContainer,
- YangFeatureHolder, YangIsFilterContentNodes, YangNamespace {
+ YangFeatureHolder, YangIsFilterContentNodes, YangNamespace, YangDeviationHolder {
private static final long serialVersionUID = 806201614L;
@@ -238,6 +239,11 @@
private List<YangResolutionInfo> compilerAnnotationList;
/**
+ * Deviation list.
+ */
+ private List<YangResolutionInfo> deviationList;
+
+ /**
* extension list.
*/
private List<YangExtension> extensionList;
@@ -268,6 +274,16 @@
private String namespace;
/**
+ * Flag to check whether target node is already cloned.
+ */
+ private boolean isDeviatedNodeCloned;
+
+ /**
+ * Flag to check whether this module is only for deviation.
+ */
+ private boolean isModuleForDeviation;
+
+ /**
* Creates a sub module node.
*/
public YangSubModule() {
@@ -280,12 +296,12 @@
baseResolutionList = new LinkedList<>();
identityRefResolutionList = new LinkedList<>();
compilerAnnotationList = new LinkedList<>();
+ deviationList = new LinkedList<>();
importList = new LinkedList<>();
includeList = new LinkedList<>();
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
extensionList = new LinkedList<>();
- compilerAnnotationList = new LinkedList<>();
listOfFeature = new LinkedList<>();
notificationEnumMap = new HashMap<>();
augments = new LinkedList<>();
@@ -473,6 +489,16 @@
}
/**
+ * Removes a leaf.
+ *
+ * @param leaf the leaf to be removed
+ */
+ @Override
+ public void removeLeaf(YangLeaf leaf) {
+ listOfLeaf.remove(leaf);
+ }
+
+ /**
* Returns the list of leaf-list.
*
* @return the list of leaf-list
@@ -498,6 +524,16 @@
}
/**
+ * Removes a leaf-list.
+ *
+ * @param leafList the leaf-list to be removed
+ */
+ @Override
+ public void removeLeafList(YangLeafList leafList) {
+ listOfLeafList.remove(leafList);
+ }
+
+ /**
* Returns the sub-modules organization.
*
* @return the organization
@@ -632,8 +668,10 @@
return unmodifiableList(baseResolutionList);
} else if (type == YANG_IDENTITYREF) {
return unmodifiableList(identityRefResolutionList);
- } else {
+ } else if (type == YANG_COMPILER_ANNOTATION) {
return unmodifiableList(compilerAnnotationList);
+ } else {
+ return unmodifiableList(deviationList);
}
}
@@ -656,6 +694,8 @@
identityRefResolutionList.add(resolutionInfo);
} else if (type == YANG_COMPILER_ANNOTATION) {
compilerAnnotationList.add(resolutionInfo);
+ } else if (type == YANG_DEVIATION) {
+ deviationList.add(resolutionInfo);
}
}
@@ -678,6 +718,8 @@
identityRefResolutionList = resolutionList;
} else if (type == YANG_COMPILER_ANNOTATION) {
compilerAnnotationList = resolutionList;
+ } else if (type == YANG_DEVIATION) {
+ deviationList = resolutionList;
}
}
@@ -824,4 +866,24 @@
public void setModuleNamespace(String namespace) {
this.namespace = namespace;
}
+
+ @Override
+ public boolean isDeviatedNodeCloned() {
+ return isDeviatedNodeCloned;
+ }
+
+ @Override
+ public void setDeviatedNodeCloned(boolean deviatedNodeCloned) {
+ this.isDeviatedNodeCloned = deviatedNodeCloned;
+ }
+
+ @Override
+ public boolean isModuleForDeviation() {
+ return isModuleForDeviation;
+ }
+
+ @Override
+ public void setModuleForDeviation(boolean moduleForDeviation) {
+ isModuleForDeviation = moduleForDeviation;
+ }
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangTypeDef.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangTypeDef.java
index 499269d..b02e800 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangTypeDef.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangTypeDef.java
@@ -67,7 +67,7 @@
public abstract class YangTypeDef
extends YangNode
implements YangCommonInfo, Parsable, YangTypeHolder, CollisionDetector,
- YangTranslatorOperatorNode {
+ YangTranslatorOperatorNode, YangUnits, YangDefault {
private static final long serialVersionUID = 806201615L;
@@ -141,6 +141,7 @@
*
* @return the default value
*/
+ @Override
public String getDefaultValueInString() {
return defaultValueInString;
}
@@ -150,6 +151,7 @@
*
* @param defaultValueInString the default value
*/
+ @Override
public void setDefaultValueInString(String defaultValueInString) {
this.defaultValueInString = defaultValueInString;
}
@@ -240,6 +242,7 @@
*
* @return the units
*/
+ @Override
public String getUnits() {
return units;
}
@@ -249,6 +252,7 @@
*
* @param units the units to set
*/
+ @Override
public void setUnits(String units) {
this.units = units;
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUniqueHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUniqueHolder.java
new file mode 100644
index 0000000..40fc343
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUniqueHolder.java
@@ -0,0 +1,50 @@
+/*
+ * 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.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+
+import java.util.List;
+
+/**
+ * Abstraction of unique entity. It is used to abstract the data holders of
+ * unique.
+ */
+public interface YangUniqueHolder {
+
+ /**
+ * Adds unique in data holder like list.
+ *
+ * @param unique the unique to be added
+ * @throws DataModelException if any violation of data model rules
+ */
+ void addUnique(String unique) throws DataModelException;
+
+ /**
+ * Sets the list of unique.
+ *
+ * @param uniqueList the list of unique to set
+ */
+ void setUniqueList(List<String> uniqueList);
+
+ /**
+ * Returns the list of unique from data holder like list.
+ *
+ * @return the list of unique
+ */
+ List<String> getUniqueList();
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUnits.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUnits.java
new file mode 100644
index 0000000..ed56e49
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUnits.java
@@ -0,0 +1,38 @@
+/*
+ * 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.yang.compiler.datamodel;
+
+/**
+ * Abstraction of units entity. It is used to abstract the data holders of
+ * units statement.
+ */
+public interface YangUnits {
+
+ /**
+ * Returns the units.
+ *
+ * @return the units
+ */
+ String getUnits();
+
+ /**
+ * Sets the units.
+ *
+ * @param units the units to set
+ */
+ void setUnits(String units);
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUses.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUses.java
index b622e28..496e615 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUses.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUses.java
@@ -424,7 +424,7 @@
}
try {
- cloneSubTree(referredGrouping, usesParentNode, this);
+ cloneSubTree(referredGrouping, usesParentNode, this, false);
} catch (DataModelException e) {
throw new DataModelException(e.getMessage());
}
@@ -551,7 +551,8 @@
}
@Override
- public YangNode clone(YangUses node) throws CloneNotSupportedException {
+ public YangNode clone(YangUses node, boolean isDeviation) throws
+ CloneNotSupportedException {
YangNode clnNode = (YangNode) super.clone();
clnNode.setParent(null);
clnNode.setChild(null);
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
index bfb5b8d..9ff2b15 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
@@ -17,12 +17,18 @@
package org.onosproject.yang.compiler.datamodel.utils;
import org.onosproject.yang.compiler.datamodel.CollisionDetector;
-import org.onosproject.yang.compiler.datamodel.ResolvableType;
import org.onosproject.yang.compiler.datamodel.YangAtomicPath;
import org.onosproject.yang.compiler.datamodel.YangAugment;
import org.onosproject.yang.compiler.datamodel.YangBase;
import org.onosproject.yang.compiler.datamodel.YangCompilerAnnotation;
+import org.onosproject.yang.compiler.datamodel.YangConfig;
+import org.onosproject.yang.compiler.datamodel.YangDefault;
import org.onosproject.yang.compiler.datamodel.YangDerivedInfo;
+import org.onosproject.yang.compiler.datamodel.YangDeviateAdd;
+import org.onosproject.yang.compiler.datamodel.YangDeviateDelete;
+import org.onosproject.yang.compiler.datamodel.YangDeviateReplace;
+import org.onosproject.yang.compiler.datamodel.YangDeviation;
+import org.onosproject.yang.compiler.datamodel.YangEntityToResolveInfo;
import org.onosproject.yang.compiler.datamodel.YangEntityToResolveInfoImpl;
import org.onosproject.yang.compiler.datamodel.YangEnumeration;
import org.onosproject.yang.compiler.datamodel.YangIdentityRef;
@@ -32,13 +38,22 @@
import org.onosproject.yang.compiler.datamodel.YangLeafList;
import org.onosproject.yang.compiler.datamodel.YangLeafRef;
import org.onosproject.yang.compiler.datamodel.YangLeavesHolder;
+import org.onosproject.yang.compiler.datamodel.YangMandatory;
+import org.onosproject.yang.compiler.datamodel.YangMaxElementHolder;
+import org.onosproject.yang.compiler.datamodel.YangMinElementHolder;
import org.onosproject.yang.compiler.datamodel.YangModule;
+import org.onosproject.yang.compiler.datamodel.YangMust;
+import org.onosproject.yang.compiler.datamodel.YangMustHolder;
import org.onosproject.yang.compiler.datamodel.YangNode;
+import org.onosproject.yang.compiler.datamodel.YangNotification;
import org.onosproject.yang.compiler.datamodel.YangReferenceResolver;
import org.onosproject.yang.compiler.datamodel.YangResolutionInfo;
import org.onosproject.yang.compiler.datamodel.YangRpc;
+import org.onosproject.yang.compiler.datamodel.YangSchemaNode;
import org.onosproject.yang.compiler.datamodel.YangType;
import org.onosproject.yang.compiler.datamodel.YangUnion;
+import org.onosproject.yang.compiler.datamodel.YangUniqueHolder;
+import org.onosproject.yang.compiler.datamodel.YangUnits;
import org.onosproject.yang.compiler.datamodel.YangUses;
import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
@@ -60,12 +75,20 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_AUGMENT;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_BASE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_COMPILER_ANNOTATION;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_DERIVED_DATA_TYPE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_DEVIATION;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IDENTITYREF;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IF_FEATURE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_LEAFREF;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_USES;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.ENUMERATION;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UNION;
-
/**
* Represents utilities for data model tree.
*/
@@ -200,35 +223,36 @@
}
}
YangReferenceResolver resolutionNode = (YangReferenceResolver) curNode;
-
- if (resolutionInfo.getEntityToResolveInfo()
- .getEntityToResolve() instanceof YangType) {
+ YangEntityToResolveInfo entityToResolveInfo = resolutionInfo.getEntityToResolveInfo();
+ if (entityToResolveInfo.getEntityToResolve()
+ instanceof YangType) {
resolutionNode.addToResolutionList(resolutionInfo,
- ResolvableType.YANG_DERIVED_DATA_TYPE);
- } else if (resolutionInfo.getEntityToResolveInfo()
- .getEntityToResolve() instanceof YangUses) {
+ YANG_DERIVED_DATA_TYPE);
+ } else if (entityToResolveInfo.getEntityToResolve()
+ instanceof YangUses) {
+ resolutionNode.addToResolutionList(resolutionInfo, YANG_USES);
+ } else if (entityToResolveInfo.getEntityToResolve()
+ instanceof YangAugment) {
+ resolutionNode.addToResolutionList(resolutionInfo, YANG_AUGMENT);
+ } else if (entityToResolveInfo.getEntityToResolve()
+ instanceof YangIfFeature) {
+ resolutionNode.addToResolutionList(resolutionInfo, YANG_IF_FEATURE);
+ } else if (entityToResolveInfo.getEntityToResolve()
+ instanceof YangLeafRef) {
+ resolutionNode.addToResolutionList(resolutionInfo, YANG_LEAFREF);
+ } else if (entityToResolveInfo.getEntityToResolve()
+ instanceof YangBase) {
+ resolutionNode.addToResolutionList(resolutionInfo, YANG_BASE);
+ } else if (entityToResolveInfo.getEntityToResolve()
+ instanceof YangIdentityRef) {
+ resolutionNode.addToResolutionList(resolutionInfo, YANG_IDENTITYREF);
+ } else if (entityToResolveInfo.getEntityToResolve()
+ instanceof YangCompilerAnnotation) {
resolutionNode.addToResolutionList(resolutionInfo,
- ResolvableType.YANG_USES);
- } else if (resolutionInfo.getEntityToResolveInfo()
- .getEntityToResolve() instanceof YangAugment) {
- resolutionNode.addToResolutionList(resolutionInfo,
- ResolvableType.YANG_AUGMENT);
- } else if (resolutionInfo.getEntityToResolveInfo()
- .getEntityToResolve() instanceof YangIfFeature) {
- resolutionNode.addToResolutionList(resolutionInfo,
- ResolvableType.YANG_IF_FEATURE);
- } else if (resolutionInfo.getEntityToResolveInfo()
- .getEntityToResolve() instanceof YangLeafRef) {
- resolutionNode.addToResolutionList(resolutionInfo,
- ResolvableType.YANG_LEAFREF);
- } else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangBase) {
- resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_BASE);
- } else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangIdentityRef) {
- resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_IDENTITYREF);
- } else if (resolutionInfo.getEntityToResolveInfo()
- .getEntityToResolve() instanceof YangCompilerAnnotation) {
- resolutionNode.addToResolutionList(resolutionInfo,
- ResolvableType.YANG_COMPILER_ANNOTATION);
+ YANG_COMPILER_ANNOTATION);
+ } else if (entityToResolveInfo.getEntityToResolve()
+ instanceof YangDeviation) {
+ resolutionNode.addToResolutionList(resolutionInfo, YANG_DEVIATION);
}
}
@@ -287,6 +311,25 @@
}
/**
+ * Checks if there is any rpc/notification defined in the module or
+ * sub-module.
+ *
+ * @param rootNode root node of the data model
+ * @return status of rpc/notification existence
+ */
+ public static boolean isRpcNotificationPresent(YangNode rootNode) {
+ YangNode childNode = rootNode.getChild();
+ while (childNode != null) {
+ if (childNode instanceof YangRpc ||
+ childNode instanceof YangNotification) {
+ return true;
+ }
+ childNode = childNode.getNextSibling();
+ }
+ return false;
+ }
+
+ /**
* Returns referred node in a given set.
*
* @param yangNodeSet YANG node set
@@ -350,22 +393,30 @@
* cloning. Under the cloned node, with cloned leaf, attributes are set
* and added to resolution list.
*
- * @param clonedNode holder node
- * @param yangUses YANG uses
+ * @param clonedNode holder node
+ * @param yangUses YANG uses
+ * @param isDeviation flag to identify cloning is for deviation
* @throws CloneNotSupportedException clone not supported error
* @throws DataModelException data model error
*/
- public static void cloneListOfLeaf(
- YangLeavesHolder clonedNode, YangUses yangUses)
+ public static void cloneListOfLeaf(YangLeavesHolder clonedNode,
+ YangUses yangUses,
+ boolean isDeviation)
throws CloneNotSupportedException, DataModelException {
List<YangLeaf> leaves = clonedNode.getListOfLeaf();
if (nonEmpty(leaves)) {
List<YangLeaf> clonedLeaves = new LinkedList<>();
for (YangLeaf leaf : leaves) {
- YangLeaf clonedLeaf = leaf.clone();
+ YangLeaf clonedLeaf;
+ if (!isDeviation) {
+ clonedLeaf = leaf.clone();
+ addUnresolvedType(yangUses, clonedLeaf,
+ (YangNode) clonedNode);
+ } else {
+ clonedLeaf = leaf.cloneForDeviation();
+ }
clonedLeaf.setReferredLeaf(leaf);
- addUnresolvedType(yangUses, clonedLeaf, (YangNode) clonedNode);
clonedLeaf.setContainedIn(clonedNode);
clonedLeaves.add(clonedLeaf);
}
@@ -413,23 +464,29 @@
* after cloning. Under the cloned node, with cloned leaf-list,
* attributes are set and added to resolution list.
*
- * @param clonedNode cloned holder
- * @param yangUses YANG uses
+ * @param clonedNode cloned holder
+ * @param yangUses YANG uses
+ * @param isDeviation flag to identify cloning is for deviation
* @throws CloneNotSupportedException clone not supported error
* @throws DataModelException data model error
*/
public static void cloneListOfLeafList(
- YangLeavesHolder clonedNode, YangUses yangUses)
+ YangLeavesHolder clonedNode, YangUses yangUses, boolean isDeviation)
throws CloneNotSupportedException, DataModelException {
List<YangLeafList> listOfLeafList = clonedNode.getListOfLeafList();
if (nonEmpty(listOfLeafList)) {
List<YangLeafList> clonedList = new LinkedList<>();
for (YangLeafList leafList : listOfLeafList) {
- YangLeafList clonedLeafList = leafList.clone();
+ YangLeafList clonedLeafList;
+ if (!isDeviation) {
+ clonedLeafList = leafList.clone();
+ addUnresolvedType(yangUses, clonedLeafList,
+ (YangNode) clonedNode);
+ } else {
+ clonedLeafList = leafList.cloneForDeviation();
+ }
clonedLeafList.setReferredSchemaLeafList(leafList);
- addUnresolvedType(yangUses, clonedLeafList,
- (YangNode) clonedNode);
clonedLeafList.setContainedIn(clonedNode);
clonedList.add(clonedLeafList);
}
@@ -844,4 +901,277 @@
return dataType.getDataType().equals(EMPTY);
}
}
+
+ /**
+ * Validates whether multiple deviation statement's Xpath is referring
+ * to same module.
+ *
+ * @param node YANG data model node
+ * @throws DataModelException if deviations referring to multiple module
+ */
+ public static void validateMultipleDeviationStatement(
+ YangReferenceResolver node) throws DataModelException {
+ List<YangResolutionInfo> deviationList = node
+ .getUnresolvedResolutionList(YANG_DEVIATION);
+ String prefix = null;
+ if (!deviationList.isEmpty()) {
+ YangDeviation firstDeviation = (YangDeviation) deviationList.get(0)
+ .getEntityToResolveInfo().getEntityToResolve();
+ YangAtomicPath atomic = firstDeviation.getTargetNode().get(0);
+ prefix = atomic.getNodeIdentifier().getPrefix();
+ }
+
+ Iterator<YangResolutionInfo> deviationIterator = deviationList.iterator();
+ while (deviationIterator.hasNext()) {
+ YangDeviation deviation = (YangDeviation) deviationIterator.next()
+ .getEntityToResolveInfo().getEntityToResolve();
+ List<YangAtomicPath> targetNode = deviation.getTargetNode();
+ YangAtomicPath atomicPath = targetNode.get(0);
+ if (!atomicPath.getNodeIdentifier().getPrefix().equals(prefix)) {
+ throw new DataModelException("YANG FILE ERROR : Deviations " +
+ "of multiple module is" +
+ " currently not " +
+ "supported.");
+ }
+ }
+ }
+
+ /**
+ * Removes node from data model tree.
+ *
+ * @param node YANG data model node
+ */
+ public static void deleteUnsupportedNodeFromTree(YangNode node) {
+ // unlink from parent
+ YangNode parentNode = node.getParent();
+ if (parentNode.getChild().equals(node)) {
+ parentNode.setChild(node.getNextSibling());
+ }
+
+ //unlink from siblings
+ YangNode previousSibling = node.getPreviousSibling();
+ YangNode nextSibling = node.getNextSibling();
+ if (nextSibling != null && previousSibling != null) {
+ previousSibling.setNextSibling(nextSibling);
+ nextSibling.setPreviousSibling(previousSibling);
+ } else if (nextSibling != null) {
+ nextSibling.setPreviousSibling(null);
+ } else if (previousSibling != null) {
+ previousSibling.setNextSibling(null);
+ }
+ node.setParent(null);
+ node.setPreviousSibling(null);
+ node.setNextSibling(null);
+ node.setChild(null);
+ }
+
+ /**
+ * Removes leaf/leaf-list from data model tree.
+ *
+ * @param node YANG data model node
+ * @param leafName name of leaf to be removed
+ */
+ public static void deleteUnsupportedLeafOrLeafList(YangLeavesHolder node,
+ String leafName) {
+ List<YangLeaf> leaves = node.getListOfLeaf();
+ if (leaves != null && !leaves.isEmpty()) {
+ for (YangLeaf leaf : leaves) {
+ if (leaf.getName().equals(leafName)) {
+ node.removeLeaf(leaf);
+ return;
+ }
+ }
+ }
+
+ List<YangLeafList> leafList = node.getListOfLeafList();
+ if (leafList != null && !leafList.isEmpty()) {
+ for (YangLeafList leaf : leafList) {
+ if (leaf.getName().equals(leafName)) {
+ node.removeLeafList(leaf);
+ return;
+ }
+ }
+ }
+ }
+
+ /**
+ * Updates the target data model with deviate delete sub statements.
+ *
+ * @param targetNode target node of deviation
+ * @param deviateDelete YANG deviate delete data model node
+ * @throws DataModelException if deviations referring to multiple module
+ */
+ public static void updateDeviateDeleteToTargetNode(YangSchemaNode targetNode,
+ YangDeviateDelete deviateDelete)
+ throws DataModelException {
+
+ // delete must statement
+ if (targetNode instanceof YangMustHolder
+ && !deviateDelete.getListOfMust().isEmpty()) {
+ deviateDelete.setListOfMust(new LinkedList<>());
+ }
+
+ // delete unique statement
+ if (targetNode instanceof YangUniqueHolder
+ && !deviateDelete.getUniqueList().isEmpty()) {
+ deviateDelete.setUniqueList(new LinkedList<>());
+ }
+
+ // delete units statement
+ if (targetNode instanceof YangUnits) {
+ ((YangUnits) targetNode).setUnits(null);
+ }
+
+ // delete default statement
+ if (targetNode instanceof YangDefault) {
+ ((YangDefault) targetNode)
+ .setDefaultValueInString(null);
+ }
+ }
+
+ /**
+ * Updates the target data model with deviate add sub statements.
+ *
+ * @param targetNode target node of deviation
+ * @param deviateAdd YANG deviate add data model node
+ * @throws DataModelException if deviations referring to multiple module
+ */
+ public static void updateDeviateAddToTargetNode(YangSchemaNode targetNode,
+ YangDeviateAdd deviateAdd)
+ throws DataModelException {
+ // update must statement
+ if (targetNode instanceof YangMustHolder
+ && !deviateAdd.getListOfMust().isEmpty()) {
+ Iterator<YangMust> mustList = deviateAdd.getListOfMust().listIterator();
+ while (mustList.hasNext()) {
+ ((YangMustHolder) targetNode).addMust(mustList.next());
+ }
+ }
+
+ // update unique statement
+ if (targetNode instanceof YangUniqueHolder
+ && !deviateAdd.getUniqueList().isEmpty()) {
+ Iterator<String> uniqueList = deviateAdd.getUniqueList()
+ .listIterator();
+ while (uniqueList.hasNext()) {
+ ((YangUniqueHolder) targetNode).addUnique(uniqueList.next());
+ }
+ }
+
+ // update config statement
+ if (targetNode instanceof YangConfig) {
+ ((YangConfig) targetNode).setConfig(deviateAdd.isConfig());
+ }
+
+ // update units statement
+ if (targetNode instanceof YangUnits) {
+ ((YangUnits) targetNode).setUnits(deviateAdd.getUnits());
+ }
+
+ // update default statement
+ if (targetNode instanceof YangDefault) {
+ ((YangDefault) targetNode)
+ .setDefaultValueInString(deviateAdd.getDefaultValueInString());
+ }
+
+ // update mandatory statement
+ if (targetNode instanceof YangMandatory) {
+ ((YangMandatory) targetNode).setMandatory(deviateAdd.isMandatory());
+ }
+
+ // update minelement statement
+ if (targetNode instanceof YangMinElementHolder) {
+ ((YangMinElementHolder) targetNode)
+ .setMinElements(deviateAdd.getMinElements());
+ }
+
+ // update max-element statement
+ if (targetNode instanceof YangMaxElementHolder) {
+ ((YangMaxElementHolder) targetNode)
+ .setMaxElements(deviateAdd.getMaxElements());
+ }
+ }
+
+ /**
+ * Replaces the substatements of deviate replace to target node.
+ *
+ * @param targetNode target node of deviation
+ * @param deviateReplace YANG deviate replace data model node
+ */
+ public static void updateDeviateReplaceToTargetNode(YangSchemaNode targetNode,
+ YangDeviateReplace deviateReplace) {
+
+ if (targetNode instanceof YangLeaf
+ && deviateReplace.getDataType() != null) {
+ ((YangLeaf) targetNode).setDataType(deviateReplace.getDataType());
+ }
+
+ if (targetNode instanceof YangLeafList
+ && deviateReplace.getDataType() != null) {
+ ((YangLeafList) targetNode).setDataType(deviateReplace
+ .getDataType());
+ }
+
+ // update config statement
+ if (targetNode instanceof YangConfig) {
+ ((YangConfig) targetNode).setConfig(deviateReplace.isConfig());
+ }
+
+ // update units statement
+ if (targetNode instanceof YangUnits) {
+ ((YangUnits) targetNode).setUnits(deviateReplace.getUnits());
+ }
+
+ // update default statement
+ if (targetNode instanceof YangDefault) {
+ ((YangDefault) targetNode)
+ .setDefaultValueInString(deviateReplace.getDefaultValueInString());
+ }
+
+ // update mandatory statement
+ if (targetNode instanceof YangMandatory) {
+ ((YangMandatory) targetNode).setMandatory(deviateReplace.isMandatory());
+ }
+
+ // update minelement statement
+ if (targetNode instanceof YangMinElementHolder) {
+ ((YangMinElementHolder) targetNode)
+ .setMinElements(deviateReplace.getMinElements());
+ }
+
+ // update max-element statement
+ if (targetNode instanceof YangMaxElementHolder) {
+ ((YangMaxElementHolder) targetNode)
+ .setMaxElements(deviateReplace.getMaxElements());
+ }
+ }
+
+ /**
+ * Searches for leaf/leaf-list in given leaf holder node.
+ *
+ * @param target leaf holder
+ * @param name leaf/leaf-list name
+ * @return leaf/leaf-list node
+ */
+ public static YangSchemaNode findLeafNode(YangLeavesHolder target,
+ String name) {
+ List<YangLeaf> leaves = target.getListOfLeaf();
+ if (leaves != null && !leaves.isEmpty()) {
+ for (YangLeaf leaf : leaves) {
+ if (leaf.getName().equals(name)) {
+ return leaf;
+ }
+ }
+ }
+
+ List<YangLeafList> listOfleafList = target.getListOfLeafList();
+ if (listOfleafList != null && !listOfleafList.isEmpty()) {
+ for (YangLeafList leafList : listOfleafList) {
+ if (leafList.getName().equals(name)) {
+ return leafList;
+ }
+ }
+ }
+ return null;
+ }
}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/YangConstructType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/YangConstructType.java
index 9c9aedf..edb1128 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/YangConstructType.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/YangConstructType.java
@@ -402,7 +402,27 @@
/**
* Identifies the YANG argument element parsed data.
*/
- ARGUMENT_DATA;
+ ARGUMENT_DATA,
+
+ /**
+ * Identifies the YANG deviate not supported element parsed data.
+ */
+ DEVIATE_NOT_SUPPORTED,
+
+ /**
+ * Identifies deviation add element parsed data.
+ */
+ DEVIATE_ADD,
+
+ /**
+ * Identifies deviation delete element parsed data.
+ */
+ DEVIATE_DELETE,
+
+ /**
+ * Identifies deviation replace element parsed data.
+ */
+ DEVIATE_REPLACE;
/**
* Returns the YANG construct keyword corresponding to enum values.
@@ -567,6 +587,14 @@
return "app-extended-name";
case ARGUMENT_DATA:
return "argument";
+ case DEVIATE_NOT_SUPPORTED:
+ return "deviate-not-supported-stmt";
+ case DEVIATE_ADD:
+ return "deviate-add";
+ case DEVIATE_DELETE:
+ return "deviate-delete";
+ case DEVIATE_REPLACE:
+ return "deviate-replace";
default:
return "yang";
}
diff --git a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/XpathLinkingTypes.java b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/XpathLinkingTypes.java
index a4345cf..e560fd8 100644
--- a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/XpathLinkingTypes.java
+++ b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/XpathLinkingTypes.java
@@ -27,5 +27,8 @@
LEAF_REF_LINKING,
// Compiler annotation linking.
- COMPILER_ANNOTATION_LINKING
+ COMPILER_ANNOTATION_LINKING,
+
+ // Deviation linking.
+ DEVIATION_LINKING
}
diff --git a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerManager.java b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerManager.java
index 61528be..2761480 100644
--- a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerManager.java
+++ b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangLinkerManager.java
@@ -33,6 +33,7 @@
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_BASE;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_COMPILER_ANNOTATION;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_DERIVED_DATA_TYPE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_DEVIATION;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IDENTITYREF;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IF_FEATURE;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_LEAFREF;
@@ -179,22 +180,17 @@
sort(yangNodeSortedList);
for (YangNode yangNode : yangNodeSortedList) {
try {
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(YANG_IF_FEATURE);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(YANG_USES);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(YANG_AUGMENT);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(YANG_DERIVED_DATA_TYPE);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(YANG_BASE);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(YANG_IDENTITYREF);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(YANG_LEAFREF);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(YANG_COMPILER_ANNOTATION);
+ YangReferenceResolver resolver = ((YangReferenceResolver)
+ yangNode);
+ resolver.resolveInterFileLinking(YANG_IF_FEATURE);
+ resolver.resolveInterFileLinking(YANG_USES);
+ resolver.resolveInterFileLinking(YANG_AUGMENT);
+ resolver.resolveInterFileLinking(YANG_DERIVED_DATA_TYPE);
+ resolver.resolveInterFileLinking(YANG_BASE);
+ resolver.resolveInterFileLinking(YANG_IDENTITYREF);
+ resolver.resolveInterFileLinking(YANG_LEAFREF);
+ resolver.resolveInterFileLinking(YANG_COMPILER_ANNOTATION);
+ resolver.resolveInterFileLinking(YANG_DEVIATION);
} catch (DataModelException e) {
String errorInfo = "Error in file: " + yangNode.getName() + " in " +
yangNode.getFileName() + " at " +
diff --git a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangResolutionInfoImpl.java b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangResolutionInfoImpl.java
index 3c1542c..a4590ca 100644
--- a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangResolutionInfoImpl.java
+++ b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangResolutionInfoImpl.java
@@ -16,6 +16,7 @@
package org.onosproject.yang.compiler.linker.impl;
+import org.onosproject.yang.compiler.datamodel.CollisionDetector;
import org.onosproject.yang.compiler.datamodel.DefaultLocationInfo;
import org.onosproject.yang.compiler.datamodel.Resolvable;
import org.onosproject.yang.compiler.datamodel.RpcNotificationContainer;
@@ -26,6 +27,11 @@
import org.onosproject.yang.compiler.datamodel.YangBase;
import org.onosproject.yang.compiler.datamodel.YangCompilerAnnotation;
import org.onosproject.yang.compiler.datamodel.YangDerivedInfo;
+import org.onosproject.yang.compiler.datamodel.YangDeviateAdd;
+import org.onosproject.yang.compiler.datamodel.YangDeviateDelete;
+import org.onosproject.yang.compiler.datamodel.YangDeviateReplace;
+import org.onosproject.yang.compiler.datamodel.YangDeviation;
+import org.onosproject.yang.compiler.datamodel.YangDeviationHolder;
import org.onosproject.yang.compiler.datamodel.YangEntityToResolveInfoImpl;
import org.onosproject.yang.compiler.datamodel.YangFeature;
import org.onosproject.yang.compiler.datamodel.YangFeatureHolder;
@@ -39,12 +45,14 @@
import org.onosproject.yang.compiler.datamodel.YangLeaf;
import org.onosproject.yang.compiler.datamodel.YangLeafList;
import org.onosproject.yang.compiler.datamodel.YangLeafRef;
+import org.onosproject.yang.compiler.datamodel.YangLeavesHolder;
import org.onosproject.yang.compiler.datamodel.YangList;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangNodeIdentifier;
import org.onosproject.yang.compiler.datamodel.YangReferenceResolver;
import org.onosproject.yang.compiler.datamodel.YangRelativePath;
import org.onosproject.yang.compiler.datamodel.YangResolutionInfo;
+import org.onosproject.yang.compiler.datamodel.YangSchemaNode;
import org.onosproject.yang.compiler.datamodel.YangType;
import org.onosproject.yang.compiler.datamodel.YangTypeDef;
import org.onosproject.yang.compiler.datamodel.YangUses;
@@ -65,18 +73,28 @@
import static org.onosproject.yang.compiler.datamodel.TraversalType.PARENT;
import static org.onosproject.yang.compiler.datamodel.TraversalType.ROOT;
import static org.onosproject.yang.compiler.datamodel.TraversalType.SIBILING;
+import static org.onosproject.yang.compiler.datamodel.YangNode.cloneSubTree;
import static org.onosproject.yang.compiler.datamodel.YangPathArgType.ABSOLUTE_PATH;
import static org.onosproject.yang.compiler.datamodel.YangPathArgType.RELATIVE_PATH;
import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsg;
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.addResolutionInfo;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.deleteUnsupportedLeafOrLeafList;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.deleteUnsupportedNodeFromTree;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.findLeafNode;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.updateDeviateAddToTargetNode;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.updateDeviateDeleteToTargetNode;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.updateDeviateReplaceToTargetNode;
import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.INTER_FILE_LINKED;
import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.LINKED;
import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.UNDEFINED;
import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.UNRESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.LEAF_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.LEAF_LIST_DATA;
import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.PATH_DATA;
import static org.onosproject.yang.compiler.linker.impl.XpathLinkingTypes.AUGMENT_LINKING;
+import static org.onosproject.yang.compiler.linker.impl.XpathLinkingTypes.DEVIATION_LINKING;
import static org.onosproject.yang.compiler.linker.impl.XpathLinkingTypes.LEAF_REF_LINKING;
import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.detectCollisionForAugmentedNode;
import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.fillPathPredicates;
@@ -87,6 +105,7 @@
import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.skipInvalidDataNodes;
import static org.onosproject.yang.compiler.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.FAILED_TO_FIND_ANNOTATION;
+import static org.onosproject.yang.compiler.utils.UtilConstants.FAILED_TO_FIND_DEVIATION;
import static org.onosproject.yang.compiler.utils.UtilConstants.FAILED_TO_FIND_LEAD_INFO_HOLDER;
import static org.onosproject.yang.compiler.utils.UtilConstants.FAILED_TO_LINK;
import static org.onosproject.yang.compiler.utils.UtilConstants.INVALID_ENTITY;
@@ -816,6 +835,8 @@
((YangUses) entity).setRefGroup((YangGrouping) refNode);
} else if (entity instanceof YangBase) {
((YangBase) entity).setReferredIdentity((YangIdentity) refNode);
+ addToIdentityExtendList(((YangIdentity) ((YangBase) entity).getParentIdentity()),
+ (YangIdentity) refNode);
} else if (entity instanceof YangIdentityRef) {
((YangIdentityRef) entity).setReferredIdentity((YangIdentity) refNode);
} else if (!(entity instanceof YangIfFeature) &&
@@ -828,6 +849,20 @@
((Resolvable) entity).setResolvableStatus(linkedStatus);
}
+ private void addToIdentityExtendList(YangIdentity baseIdentity, YangIdentity
+ referredIdentity) {
+ YangIdentity referredId = referredIdentity;
+ while (referredId != null) {
+ referredId.addToExtendList(baseIdentity);
+ YangBase base = referredId.getBaseNode();
+ if (base == null) {
+ return;
+ } else {
+ referredId = base.getReferredIdentity();
+ }
+ }
+ }
+
/**
* Checks if type/grouping has further reference to typedef/ unresolved
* uses. Add it to the partial resolve stack and return the status of
@@ -1094,10 +1129,227 @@
ex.setFileName(leafRef.getFileName());
throw ex;
}
+ } else if (entityToResolve instanceof YangDeviation) {
+ YangDeviation deviation = (YangDeviation) entityToResolve;
+ List<YangAtomicPath> path = deviation.getTargetNode();
+ YangAtomicPath targetPath = path.get(path.size() - 1);
+ YangSchemaNode target = findDeviationTarget(entityToResolve, root,
+ xPathLinker);
+
+ if (deviation.isDeviateNotSupported()) {
+ resolveDeviationNotSupported(target, targetPath);
+ } else {
+ List<YangDeviateAdd> deviateAddList = deviation.getDeviateAdd();
+
+ if (deviateAddList != null && !deviateAddList.isEmpty()) {
+ resolveDeviateAdd(deviateAddList, target, targetPath);
+ }
+
+ List<YangDeviateDelete> deviateDeleteList = deviation
+ .getDeviateDelete();
+ if (deviateDeleteList != null && !deviateDeleteList.isEmpty()) {
+ resolveDeviateDelete(deviateDeleteList, target, targetPath);
+ }
+
+ List<YangDeviateReplace> deviateReplaceList = deviation
+ .getDeviateReplace();
+ if (deviateReplaceList != null && !deviateReplaceList.isEmpty()) {
+ resolveDeviateReplace(deviateReplaceList, target, targetPath);
+ }
+ }
+
+ Resolvable resolvable = (Resolvable) entityToResolve;
+ resolvable.setResolvableStatus(RESOLVED);
}
}
/**
+ * Adds deviate add sub-statements to deviation target node.
+ *
+ * @param deviateAddList list of deviate add
+ * @param target deviation target node
+ * @param targetPath deviation target's last node
+ * @throws DataModelException if there is a data model error
+ */
+ private void resolveDeviateAdd(List<YangDeviateAdd> deviateAddList,
+ YangSchemaNode target,
+ YangAtomicPath targetPath)
+ throws DataModelException {
+ for (YangDeviateAdd deviate : deviateAddList) {
+ if (target.getName().equals(targetPath.getNodeIdentifier().getName())) {
+ updateDeviateAddToTargetNode(target, deviate);
+ } else {
+ YangSchemaNode leaf = findLeafNode((YangLeavesHolder) target, targetPath
+ .getNodeIdentifier().getName());
+ updateDeviateAddToTargetNode(leaf, deviate);
+ }
+ }
+ }
+
+ /**
+ * Removes deviate delete sub-statements from deviation target node.
+ *
+ * @param deviateDeleteList list of deviate delete
+ * @param target deviation target node
+ * @param targetPath deviation target's last node
+ * @throws DataModelException if there is a data model error
+ */
+ private void resolveDeviateDelete(List<YangDeviateDelete>
+ deviateDeleteList,
+ YangSchemaNode target,
+ YangAtomicPath targetPath)
+ throws DataModelException {
+ for (YangDeviateDelete deviate : deviateDeleteList) {
+ if (target.getName().equals(targetPath.getNodeIdentifier().getName())) {
+ updateDeviateDeleteToTargetNode(target, deviate);
+ } else {
+ YangSchemaNode leaf = findLeafNode((YangLeavesHolder) target, targetPath
+ .getNodeIdentifier().getName());
+ updateDeviateDeleteToTargetNode(leaf, deviate);
+ }
+ }
+ }
+
+ /**
+ * Replaces deviate replace sub-statements from deviation target node.
+ *
+ * @param deviateReplaceList list of deviate replace
+ * @param target deviation target node
+ * @param targetPath deviation target's last node
+ * @throws DataModelException if there is a data model error
+ */
+ private void resolveDeviateReplace(List<YangDeviateReplace>
+ deviateReplaceList,
+ YangSchemaNode target,
+ YangAtomicPath targetPath)
+ throws DataModelException {
+ for (YangDeviateReplace deviate : deviateReplaceList) {
+ if (target.getName().equals(targetPath.getNodeIdentifier().getName())) {
+ updateDeviateReplaceToTargetNode(target, deviate);
+ } else {
+ YangSchemaNode leaf = findLeafNode((YangLeavesHolder) target, targetPath
+ .getNodeIdentifier().getName());
+ updateDeviateReplaceToTargetNode(leaf, deviate);
+ }
+ }
+ }
+
+ /**
+ * Removes deviation target node from cloned data model.
+ *
+ * @param target deviation target node
+ * @param targetPath deviation target's last node
+ */
+ private void resolveDeviationNotSupported(YangSchemaNode target,
+ YangAtomicPath targetPath) {
+ if (target.getName().equals(targetPath.getNodeIdentifier().getName())) {
+ deleteUnsupportedNodeFromTree((YangNode) target);
+ } else {
+ deleteUnsupportedLeafOrLeafList((YangLeavesHolder) target,
+ targetPath.getNodeIdentifier().getName());
+ }
+ }
+
+ /**
+ * Returns the cloned node of deviation target node.
+ *
+ * @param entityToResolve entity to resolve
+ * @param root root node
+ * @param xPathLinker xpath Linker
+ * @throws DataModelException if there is a data model error
+ */
+ private YangSchemaNode findDeviationTarget(T entityToResolve,
+ YangReferenceResolver root,
+ YangXpathLinker<T> xPathLinker)
+ throws DataModelException {
+
+ YangNode targetNode;
+ YangDeviation deviation = (YangDeviation) entityToResolve;
+ List<YangAtomicPath> path = deviation.getTargetNode();
+ targetNode = xPathLinker.processXpathLinking(path, (YangNode) root,
+ DEVIATION_LINKING);
+
+ if (targetNode != null) {
+ YangNode clonedNode = cloneDeviatedModuleNode(targetNode, deviation);
+ return xPathLinker.parsePath(clonedNode);
+ } else {
+ throw new LinkerException(getErrorMsg(
+ FAILED_TO_FIND_DEVIATION, deviation.getName(),
+ deviation.getLineNumber(), deviation.getCharPosition(),
+ deviation.getFileName()));
+ }
+ }
+
+ /**
+ * Returns the cloned node of deviation target node.
+ *
+ * @param targetNode deviation target node
+ * @param deviation YANG deviation node
+ * @throws DataModelException if there is a data model error
+ */
+ private YangNode cloneDeviatedModuleNode(YangNode targetNode,
+ YangDeviation deviation)
+ throws DataModelException {
+
+ // get Root node of target schema
+ while (targetNode.getParent() != null) {
+ targetNode = targetNode.getParent();
+ }
+ YangNode srcNode = targetNode;
+ YangNode dstNode = deviation.getParent();
+
+ if (((YangDeviationHolder) dstNode).isDeviatedNodeCloned()) {
+ // Target Node is already cloned, no need to clone again
+ return dstNode;
+ }
+
+ // clone leaf and leaf-list of root level
+ YangLeavesHolder destLeafHolder = (YangLeavesHolder) dstNode;
+ YangLeavesHolder srcLeafHolder = (YangLeavesHolder) srcNode;
+ if (srcLeafHolder.getListOfLeaf() != null) {
+ for (YangLeaf leaf : srcLeafHolder.getListOfLeaf()) {
+ YangLeaf clonedLeaf;
+ try {
+ ((CollisionDetector) dstNode)
+ .detectCollidingChild(leaf.getName(), LEAF_DATA);
+ clonedLeaf = leaf.cloneForDeviation();
+ clonedLeaf.setReferredLeaf(leaf);
+ } catch (CloneNotSupportedException | DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
+
+ clonedLeaf.setContainedIn(destLeafHolder);
+ destLeafHolder.addLeaf(clonedLeaf);
+ }
+ }
+ if (srcLeafHolder.getListOfLeafList() != null) {
+ for (YangLeafList leafList : srcLeafHolder.getListOfLeafList()) {
+ YangLeafList clonedLeafList;
+ try {
+ ((CollisionDetector) destLeafHolder)
+ .detectCollidingChild(leafList.getName(), LEAF_LIST_DATA);
+ clonedLeafList = leafList.cloneForDeviation();
+ clonedLeafList.setReferredSchemaLeafList(leafList);
+ } catch (CloneNotSupportedException | DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
+ clonedLeafList.setContainedIn(destLeafHolder);
+ destLeafHolder.addLeafList(clonedLeafList);
+ }
+ }
+
+ // clone subtree
+ cloneSubTree(srcNode, dstNode, null, true);
+
+ /*
+ * Cloning of deviated module is done, set isDeviatedNodeCloned
+ * flag as true.
+ */
+ ((YangDeviationHolder) dstNode).setDeviatedNodeCloned(true);
+ return dstNode;
+ }
+
+ /**
* Returns the referenced prefix of entity under resolution.
*
* @return referenced prefix of entity under resolution
diff --git a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangXpathLinker.java b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangXpathLinker.java
index 02d1beb..1579bf1 100644
--- a/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangXpathLinker.java
+++ b/compiler/base/linker/src/main/java/org/onosproject/yang/compiler/linker/impl/YangXpathLinker.java
@@ -32,6 +32,7 @@
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangNodeIdentifier;
import org.onosproject.yang.compiler.datamodel.YangOutput;
+import org.onosproject.yang.compiler.datamodel.YangSchemaNode;
import org.onosproject.yang.compiler.datamodel.YangSubModule;
import org.onosproject.yang.compiler.datamodel.YangUses;
import org.onosproject.yang.compiler.linker.exceptions.LinkerException;
@@ -293,8 +294,7 @@
* @param root root node
* @return linked target node
*/
- private YangNode parsePath(YangNode root) {
-
+ public YangNode parsePath(YangNode root) {
YangNode tempNode = root;
Stack<YangNode> linkerStack = new Stack<>();
Iterator<YangAtomicPath> pathIterator = absPaths.iterator();
@@ -667,7 +667,7 @@
* @param index current index of list
* @return false if target node found
*/
- private boolean validate(YangNode tempNode, int index) {
+ private boolean validate(YangSchemaNode tempNode, int index) {
int size = absPaths.size();
if (tempNode != null && index != size) {
@@ -689,7 +689,16 @@
* @param curNodeId YANG node identifier
* @return linked target node
*/
- private YangNode searchTargetNode(YangNode node, YangNodeIdentifier curNodeId) {
+ private YangNode searchTargetNode(YangNode node,
+ YangNodeIdentifier curNodeId) {
+
+ if (linkingType == XpathLinkingTypes.DEVIATION_LINKING &&
+ node instanceof YangLeavesHolder) {
+ YangNode targetNode = searchTargetLeaf(node, curNodeId);
+ if (targetNode != null) {
+ return targetNode;
+ }
+ }
if (node != null) {
node = node.getChild();
@@ -708,12 +717,50 @@
!(node instanceof YangUses)) {
return node;
}
+
+ if (linkingType == XpathLinkingTypes.DEVIATION_LINKING &&
+ node instanceof YangLeavesHolder) {
+ YangNode targetNode = searchTargetLeaf(node, curNodeId);
+ if (targetNode != null) {
+ return targetNode;
+ }
+ }
node = node.getNextSibling();
}
return null;
}
/**
+ * Searches target leaf in root node.
+ *
+ * @param node root node
+ * @param curNodeId YANG node identifier
+ * @return linked target leaf node holder
+ */
+ private YangNode searchTargetLeaf(YangNode node,
+ YangNodeIdentifier curNodeId) {
+ YangLeavesHolder holder = (YangLeavesHolder) node;
+ List<YangLeafList> leavesList = holder.getListOfLeafList();
+ if (leavesList != null && !leavesList.isEmpty()) {
+ for (YangLeafList leafList : leavesList) {
+ if (leafList.getName().equals(curNodeId.getName())) {
+ return node;
+ }
+ }
+ }
+
+ List<YangLeaf> leaves = holder.getListOfLeaf();
+ if (leaves != null && !leaves.isEmpty()) {
+ for (YangLeaf leaf : leaves) {
+ if (leaf.getName().equals(curNodeId.getName())) {
+ return node;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
* Returns root prefix.
*
* @param root root node
diff --git a/compiler/base/parser/pom.xml b/compiler/base/parser/pom.xml
index 671bd15..4f2ee4f 100644
--- a/compiler/base/parser/pom.xml
+++ b/compiler/base/parser/pom.xml
@@ -55,7 +55,6 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
-
</dependencies>
<build>
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/TreeWalkListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/TreeWalkListener.java
index 42fe6ca..babe61e 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/TreeWalkListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/TreeWalkListener.java
@@ -42,6 +42,10 @@
import org.onosproject.yang.compiler.parser.impl.listeners.Decimal64Listener;
import org.onosproject.yang.compiler.parser.impl.listeners.DefaultListener;
import org.onosproject.yang.compiler.parser.impl.listeners.DescriptionListener;
+import org.onosproject.yang.compiler.parser.impl.listeners.DeviateAddListener;
+import org.onosproject.yang.compiler.parser.impl.listeners.DeviateDeleteListener;
+import org.onosproject.yang.compiler.parser.impl.listeners.DeviateReplaceListener;
+import org.onosproject.yang.compiler.parser.impl.listeners.DeviationListener;
import org.onosproject.yang.compiler.parser.impl.listeners.EnumListener;
import org.onosproject.yang.compiler.parser.impl.listeners.EnumerationListener;
import org.onosproject.yang.compiler.parser.impl.listeners.ErrorAppTagListener;
@@ -1473,14 +1477,12 @@
@Override
public void enterDeviationStatement(DeviationStatementContext ctx) {
- increaseUnsupportedYangConstructDepth();
- ListenerUtil.handleUnsupportedYangConstruct(YangConstructType.DEVIATION_DATA, ctx, UtilConstants.UNSUPPORTED_YANG_CONSTRUCT,
- getFileName());
+ DeviationListener.processDeviationEntry(this, ctx);
}
@Override
public void exitDeviationStatement(DeviationStatementContext ctx) {
- decreaseUnsupportedYangConstructDepth();
+ DeviationListener.processDeviationExit(this, ctx);
}
@Override
@@ -1495,32 +1497,32 @@
@Override
public void enterDeviateAddStatement(DeviateAddStatementContext ctx) {
- // do nothing.
+ DeviateAddListener.processDeviateAddEntry(this, ctx);
}
@Override
public void exitDeviateAddStatement(DeviateAddStatementContext ctx) {
- // do nothing.
+ DeviateAddListener.processDeviateAddExit(this, ctx);
}
@Override
public void enterDeviateDeleteStatement(DeviateDeleteStatementContext ctx) {
- // do nothing.
+ DeviateDeleteListener.processDeviateDeleteEntry(this, ctx);
}
@Override
public void exitDeviateDeleteStatement(DeviateDeleteStatementContext ctx) {
- // do nothing.
+ DeviateDeleteListener.processDeviateDeleteExit(this, ctx);
}
@Override
public void enterDeviateReplaceStatement(DeviateReplaceStatementContext ctx) {
- // do nothing.
+ DeviateReplaceListener.processDeviateReplaceEntry(this, ctx);
}
@Override
public void exitDeviateReplaceStatement(DeviateReplaceStatementContext ctx) {
- // do nothing.
+ DeviateReplaceListener.processDeviateReplaceExit(this, ctx);
}
@Override
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/BaseListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/BaseListener.java
index c05cd38..ac4975f 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/BaseListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/BaseListener.java
@@ -90,6 +90,7 @@
YangBase yangBase = new YangBase();
yangBase.setBaseIdentifier(nodeIdentifier);
((YangIdentity) tmpData).setBaseNode(yangBase);
+ yangBase.setParentIdentity(((YangIdentity) tmpData));
int errorLine = ctx.getStart().getLine();
int errorPosition = ctx.getStart().getCharPositionInLine();
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/ConfigListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/ConfigListener.java
index 186e1c8..6c6b8da 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/ConfigListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/ConfigListener.java
@@ -16,28 +16,6 @@
package org.onosproject.yang.compiler.parser.impl.listeners;
-import org.onosproject.yang.compiler.datamodel.YangContainer;
-import org.onosproject.yang.compiler.datamodel.YangLeaf;
-import org.onosproject.yang.compiler.datamodel.YangLeafList;
-import org.onosproject.yang.compiler.datamodel.YangList;
-import org.onosproject.yang.compiler.datamodel.utils.Parsable;
-import org.onosproject.yang.compiler.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yang.compiler.parser.exceptions.ParserException;
-import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorMessageConstruction;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerUtil;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerValidation;
-
-import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.CONFIG_DATA;
-import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
-import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
-import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerUtil.getValidBooleanValue;
-import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
@@ -53,6 +31,20 @@
* config : string;
*/
+import org.onosproject.yang.compiler.datamodel.YangConfig;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.CONFIG_DATA;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerUtil.getValidBooleanValue;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
/**
* Represents listener based call back function corresponding to the "config"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
@@ -78,30 +70,17 @@
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, CONFIG_DATA, "", ENTRY);
- boolean isConfig = getValidBooleanValue(ctx.config().getText(), CONFIG_DATA, ctx);
+ boolean isConfig = getValidBooleanValue(ctx.config().getText(),
+ CONFIG_DATA, ctx);
Parsable tmpData = listener.getParsedDataStack().peek();
- switch (tmpData.getYangConstructType()) {
- case LEAF_DATA:
- YangLeaf leaf = (YangLeaf) tmpData;
- leaf.setConfig(isConfig);
- break;
- case CONTAINER_DATA:
- YangContainer container = (YangContainer) tmpData;
- container.setConfig(isConfig);
- break;
- case LEAF_LIST_DATA:
- YangLeafList leafList = (YangLeafList) tmpData;
- leafList.setConfig(isConfig);
- break;
- case LIST_DATA:
- YangList yangList = (YangList) tmpData;
- yangList.setConfig(isConfig);
- break;
- case CHOICE_DATA: // TODO
- break;
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CONFIG_DATA, "", ENTRY));
+ if (tmpData instanceof YangConfig) {
+ YangConfig config = ((YangConfig) tmpData);
+ config.setConfig(isConfig);
+ } else {
+ throw new ParserException(
+ constructListenerErrorMessage(INVALID_HOLDER,
+ CONFIG_DATA, "", ENTRY));
}
}
}
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DefaultListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DefaultListener.java
index 0000aff..043cacd 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DefaultListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DefaultListener.java
@@ -39,9 +39,7 @@
* defaultStatement : DEFAULT_KEYWORD string STMTEND;
*/
-import org.onosproject.yang.compiler.datamodel.YangChoice;
-import org.onosproject.yang.compiler.datamodel.YangLeaf;
-import org.onosproject.yang.compiler.datamodel.YangTypeDef;
+import org.onosproject.yang.compiler.datamodel.YangDefault;
import org.onosproject.yang.compiler.datamodel.utils.Parsable;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
@@ -77,28 +75,20 @@
DefaultStatementContext ctx) {
// Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, DEFAULT_DATA, ctx.string().getText(), ENTRY);
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DEFAULT_DATA,
+ ctx.string().getText(), ENTRY);
+ String value = removeQuotesAndHandleConcat(ctx.string().getText());
Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case TYPEDEF_DATA: {
- YangTypeDef typeDef = (YangTypeDef) tmpNode;
- typeDef.setDefaultValueInString(removeQuotesAndHandleConcat(ctx.string().getText()));
- break;
- }
- case LEAF_DATA: {
- YangLeaf leaf = (YangLeaf) tmpNode;
- leaf.setDefaultValueInString(removeQuotesAndHandleConcat(ctx.string().getText()));
- break;
- }
- case CHOICE_DATA: {
- YangChoice choice = (YangChoice) tmpNode;
- choice.setDefaultValueInString(removeQuotesAndHandleConcat(ctx.string().getText()));
- break;
- }
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- DEFAULT_DATA, ctx.string().getText(), ENTRY));
+ if (tmpNode instanceof YangDefault) {
+ YangDefault defaultHolder = ((YangDefault) tmpNode);
+ defaultHolder.setDefaultValueInString(value);
+ } else {
+ throw new ParserException(
+ constructListenerErrorMessage(INVALID_HOLDER,
+ DEFAULT_DATA,
+ ctx.string().getText(),
+ ENTRY));
}
}
}
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviateAddListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviateAddListener.java
new file mode 100644
index 0000000..1e78332
--- /dev/null
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviateAddListener.java
@@ -0,0 +1,126 @@
+/*
+ * 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.yang.compiler.parser.impl.listeners;
+
+
+import org.onosproject.yang.compiler.datamodel.YangDeviateAdd;
+import org.onosproject.yang.compiler.datamodel.YangDeviation;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DEVIATE_ADD;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ *
+ * deviate-add-stmt = deviate-keyword sep add-keyword optsep
+ * (";" /
+ * "{" stmtsep
+ * [units-stmt stmtsep]
+ * *(must-stmt stmtsep)
+ * *(unique-stmt stmtsep)
+ * [default-stmt stmtsep]
+ * [config-stmt stmtsep]
+ * [mandatory-stmt stmtsep]
+ * [min-elements-stmt stmtsep]
+ * [max-elements-stmt stmtsep]
+ * "}")
+ *
+ * ANTLR grammar rule
+ * deviateAddStatement: DEVIATE_KEYWORD ADD_KEYWORD (STMTEND
+ * | LEFT_CURLY_BRACE (unitsStatement | mustStatement
+ * | uniqueStatement| defaultStatement| configStatement
+ * | mandatoryStatement | minElementsStatement
+ * | maxElementsStatement)*
+ * RIGHT_CURLY_BRACE);
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "deviate
+ * add" rule defined in ANTLR grammar file for corresponding ABNF rule in RFC
+ * 6020.
+ */
+public final class DeviateAddListener {
+
+ //No instantiation
+ private DeviateAddListener() {
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when
+ * parser receives an input matching the grammar rule(deviate add).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDeviateAddEntry(TreeWalkListener listener,
+ GeneratedYangParser.DeviateAddStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DEVIATE_ADD, null, ENTRY);
+
+ // TODO : Validate sub-statements cardinality
+
+ Parsable curData = listener.getParsedDataStack().peek();
+ if (curData instanceof YangDeviation) {
+ YangDeviation curNode = (YangDeviation) curData;
+ YangDeviateAdd deviationAdd = new YangDeviateAdd();
+ curNode.addDeviateAdd(deviationAdd);
+ listener.getParsedDataStack().push(deviationAdd);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
+ DEVIATE_ADD,
+ null,
+ ENTRY));
+ }
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when
+ * parser exits from grammar rule (deviate add).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDeviateAddExit(TreeWalkListener listener,
+ GeneratedYangParser.DeviateAddStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DEVIATE_ADD, null,
+ EXIT);
+
+ if (listener.getParsedDataStack().peek() instanceof YangDeviateAdd) {
+ listener.getParsedDataStack().pop();
+ } else {
+ throw new ParserException(constructListenerErrorMessage
+ (MISSING_CURRENT_HOLDER, DEVIATE_ADD,
+ null, EXIT));
+ }
+ }
+}
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviateDeleteListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviateDeleteListener.java
new file mode 100644
index 0000000..2c84791
--- /dev/null
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviateDeleteListener.java
@@ -0,0 +1,121 @@
+/*
+ * 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.yang.compiler.parser.impl.listeners;
+
+
+import org.onosproject.yang.compiler.datamodel.YangDeviateDelete;
+import org.onosproject.yang.compiler.datamodel.YangDeviation;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DEVIATE_DELETE;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ *
+ * deviate-delete-stmt = deviate-keyword sep delete-keyword optsep
+ * (";" /
+ * "{" stmtsep
+ * [units-stmt stmtsep]
+ * *(must-stmt stmtsep)
+ * *(unique-stmt stmtsep)
+ * [default-stmt stmtsep]
+ * "}")
+ *
+ * ANTLR grammar rule
+ * deviateDeleteStatement: DEVIATE_KEYWORD DELETE_KEYWORD (STMTEND
+ * | LEFT_CURLY_BRACE (unitsStatement | mustStatement |
+ * uniqueStatement | defaultStatement)* RIGHT_CURLY_BRACE);
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "deviate
+ * delete" rule defined in ANTLR grammar file for corresponding ABNF rule in RFC
+ * 6020.
+ */
+public final class DeviateDeleteListener {
+
+ // No instantiation
+ private DeviateDeleteListener() {
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when
+ * parser receives an input matching the grammar rule(deviate delete).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDeviateDeleteEntry(TreeWalkListener listener,
+ GeneratedYangParser
+ .DeviateDeleteStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DEVIATE_DELETE,
+ null, ENTRY);
+
+ // TODO : Validate sub-statements cardinality
+
+ Parsable curData = listener.getParsedDataStack().peek();
+ if (curData instanceof YangDeviation) {
+ YangDeviation curNode = (YangDeviation) curData;
+ YangDeviateDelete deviateDelete = new YangDeviateDelete();
+ curNode.addDeviatedelete(deviateDelete);
+ listener.getParsedDataStack().push(deviateDelete);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
+ DEVIATE_DELETE,
+ null,
+ ENTRY));
+ }
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when
+ * parser exits from grammar rule (deviate delete).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDeviateDeleteExit(TreeWalkListener listener,
+ GeneratedYangParser
+ .DeviateDeleteStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DEVIATE_DELETE, null,
+ EXIT);
+
+ if (listener.getParsedDataStack().peek() instanceof YangDeviateDelete) {
+ listener.getParsedDataStack().pop();
+ } else {
+ throw new ParserException(constructListenerErrorMessage
+ (MISSING_CURRENT_HOLDER, DEVIATE_DELETE,
+ null, EXIT));
+ }
+ }
+}
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviateReplaceListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviateReplaceListener.java
new file mode 100644
index 0000000..962aa60
--- /dev/null
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviateReplaceListener.java
@@ -0,0 +1,125 @@
+/*
+ * 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.yang.compiler.parser.impl.listeners;
+
+import org.onosproject.yang.compiler.datamodel.YangDeviateReplace;
+import org.onosproject.yang.compiler.datamodel.YangDeviation;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DEVIATE_REPLACE;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ *
+ * deviate-replace-stmt = deviate-keyword sep replace-keyword optsep
+ * (";" /
+ * "{" stmtsep
+ * [type-stmt stmtsep]
+ * [units-stmt stmtsep]
+ * [default-stmt stmtsep]
+ * [config-stmt stmtsep]
+ * [mandatory-stmt stmtsep]
+ * [min-elements-stmt stmtsep]
+ * [max-elements-stmt stmtsep]
+ * "}")
+ *
+ * ANTLR grammar rule
+ * deviateReplaceStatement: DEVIATE_KEYWORD REPLACE_KEYWORD (STMTEND
+ * | LEFT_CURLY_BRACE (typeStatement | unitsStatement
+ * | defaultStatement | configStatement
+ * | mandatoryStatement | minElementsStatement
+ * | maxElementsStatement)* RIGHT_CURLY_BRACE);
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "deviate
+ * replace" rule defined in ANTLR grammar file for corresponding ABNF rule in
+ * RFC 6020.
+ */
+public final class DeviateReplaceListener {
+
+ //No instantiation
+ private DeviateReplaceListener() {
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when
+ * parser receives an input matching the grammar rule(deviate replace).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDeviateReplaceEntry(TreeWalkListener listener,
+ GeneratedYangParser
+ .DeviateReplaceStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DEVIATE_REPLACE,
+ null, ENTRY);
+
+ // TODO : Validate sub-statements cardinality
+
+ Parsable curData = listener.getParsedDataStack().peek();
+ if (curData instanceof YangDeviation) {
+ YangDeviation curNode = (YangDeviation) curData;
+ YangDeviateReplace deviationReplace = new YangDeviateReplace();
+ curNode.addDeviateReplace(deviationReplace);
+ listener.getParsedDataStack().push(deviationReplace);
+ } else {
+ throw new ParserException(constructListenerErrorMessage
+ (INVALID_HOLDER,
+ DEVIATE_REPLACE,
+ null,
+ ENTRY));
+ }
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when
+ * parser exits from grammar rule (deviate replace).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDeviateReplaceExit(TreeWalkListener listener,
+ GeneratedYangParser.DeviateReplaceStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DEVIATE_REPLACE, null,
+ EXIT);
+
+ if (listener.getParsedDataStack().peek() instanceof YangDeviateReplace) {
+ listener.getParsedDataStack().pop();
+ } else {
+ throw new ParserException(constructListenerErrorMessage
+ (MISSING_CURRENT_HOLDER, DEVIATE_REPLACE,
+ null, EXIT));
+ }
+ }
+}
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviationListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviationListener.java
new file mode 100644
index 0000000..97f9be2
--- /dev/null
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviationListener.java
@@ -0,0 +1,234 @@
+/*
+ * 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.yang.compiler.parser.impl.listeners;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ *
+ * deviation-stmt = deviation-keyword sep
+ * deviation-arg-str optsep
+ * "{" stmtsep
+ * ;; these stmts can appear in any order
+ * [description-stmt stmtsep]
+ * [reference-stmt stmtsep]
+ * (deviate-not-supported-stmt /
+ * 1*(deviate-add-stmt /
+ * deviate-replace-stmt /
+ * deviate-delete-stmt))
+ * "}"
+ *
+ * ANTLR grammar rule
+ * deviationStatement: DEVIATION_KEYWORD deviation LEFT_CURLY_BRACE (
+ * descriptionStatement | referenceStatement | deviateNotSupportedStatement
+ * | deviateAddStatement | deviateReplaceStatement
+ * | deviateDeleteStatement)* RIGHT_CURLY_BRACE;
+ */
+
+import org.onosproject.yang.compiler.datamodel.YangAtomicPath;
+import org.onosproject.yang.compiler.datamodel.YangDeviation;
+import org.onosproject.yang.compiler.datamodel.YangDeviationHolder;
+import org.onosproject.yang.compiler.datamodel.YangNode;
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.linker.impl.YangResolutionInfoImpl;
+import org.onosproject.yang.compiler.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
+
+import java.util.List;
+
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.DEVIATION_NODE;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.addResolutionInfo;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DEVIATE_ADD;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DEVIATE_DELETE;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DEVIATE_NOT_SUPPORTED;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DEVIATE_REPLACE;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DEVIATION_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.REFERENCE_DATA;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerValidation.validateCardinalityMutuallyExclusive;
+
+/**
+ * Represents listener based call back function corresponding to the "deviation"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class DeviationListener {
+
+ /**
+ * Creates a new deviation listener.
+ */
+ private DeviationListener() {
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when
+ * parser receives an input matching the grammar rule(deviation).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDeviationEntry(TreeWalkListener listener,
+ GeneratedYangParser.DeviationStatementContext ctx) {
+
+ String deviationArg = removeQuotesAndHandleConcat(ctx.deviation().getText());
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DEVIATION_DATA,
+ deviationArg, ENTRY);
+
+ // Validates deviation argument string
+ List<YangAtomicPath> targetNode = getValidAbsoluteSchemaNodeId(deviationArg,
+ DEVIATION_DATA, ctx);
+
+ validateSubStatementsCardinality(ctx);
+
+ // Check for identifier collision
+ int line = ctx.getStart().getLine();
+ int charPositionInLine = ctx.getStart().getCharPositionInLine();
+ detectCollidingChildUtil(listener, line, charPositionInLine,
+ deviationArg, DEVIATION_DATA);
+
+ Parsable curData = listener.getParsedDataStack().peek();
+ if (curData instanceof YangDeviationHolder) {
+ YangDeviation deviation = new YangDeviation(DEVIATION_NODE, null);
+ deviation.setName(deviationArg);
+ deviation.setLineNumber(line);
+ deviation.setCharPosition(charPositionInLine);
+ deviation.setFileName(listener.getFileName());
+ deviation.setTargetNode(targetNode);
+ if (!ctx.deviateNotSupportedStatement().isEmpty()) {
+ deviation.setDeviateNotSupported(true);
+ }
+ YangNode curNode = (YangNode) curData;
+ try {
+ curNode.addChild(deviation);
+ ((YangDeviationHolder) curNode).setModuleForDeviation(true);
+ } catch (DataModelException e) {
+ throw new ParserException(
+ constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+ DEVIATION_DATA,
+ deviationArg,
+ ENTRY, e.getMessage()));
+ }
+ listener.getParsedDataStack().push(deviation);
+
+ // Adds resolution info to the list
+ YangResolutionInfoImpl<YangDeviation> info =
+ new YangResolutionInfoImpl<>(deviation, deviation.getParent(),
+ line, charPositionInLine);
+ addToResolution(info, ctx);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
+ DEVIATION_DATA,
+ deviationArg,
+ ENTRY));
+ }
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when
+ * parser exits from grammar rule (deviation).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDeviationExit(TreeWalkListener listener,
+ GeneratedYangParser.DeviationStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, DEVIATION_DATA, ctx
+ .deviation().getText(), EXIT);
+
+ if (listener.getParsedDataStack().peek() instanceof YangDeviation) {
+ listener.getParsedDataStack().pop();
+ } else {
+ throw new ParserException(constructListenerErrorMessage
+ (MISSING_CURRENT_HOLDER, DEVIATION_DATA,
+ ctx.deviation().getText(), EXIT));
+ }
+ }
+
+ /**
+ * Validates the cardinality of deviation sub-statements as per grammar.
+ *
+ * @param ctx context object of the grammar rule
+ */
+ private static void validateSubStatementsCardinality(GeneratedYangParser
+ .DeviationStatementContext ctx) {
+ validateCardinalityMaxOne(ctx.descriptionStatement(),
+ DESCRIPTION_DATA, DEVIATION_DATA,
+ ctx.deviation().getText());
+ validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA,
+ DEVIATION_DATA, ctx.deviation().getText());
+ validateCardinalityMaxOne(ctx.deviateNotSupportedStatement(),
+ DEVIATE_NOT_SUPPORTED,
+ DEVIATION_DATA, ctx.deviation().getText());
+ validateCardinalityMutuallyExclusive(ctx.deviateNotSupportedStatement(),
+ DEVIATE_NOT_SUPPORTED,
+ ctx.deviateAddStatement(),
+ DEVIATE_ADD,
+ DEVIATION_DATA,
+ ctx.deviation().getText(),
+ ctx);
+ validateCardinalityMutuallyExclusive(ctx.deviateNotSupportedStatement(),
+ DEVIATE_NOT_SUPPORTED,
+ ctx.deviateReplaceStatement(),
+ DEVIATE_REPLACE,
+ DEVIATION_DATA,
+ ctx.deviation().getText(),
+ ctx);
+ validateCardinalityMutuallyExclusive(ctx.deviateNotSupportedStatement(),
+ DEVIATE_NOT_SUPPORTED,
+ ctx.deviateDeleteStatement(),
+ DEVIATE_DELETE,
+ DEVIATION_DATA,
+ ctx.deviation().getText(),
+ ctx);
+ }
+
+ /**
+ * Add to resolution list.
+ *
+ * @param info resolution info
+ * @param ctx context object
+ */
+ private static void addToResolution(YangResolutionInfoImpl<YangDeviation> info,
+ GeneratedYangParser.DeviationStatementContext ctx) {
+ try {
+ addResolutionInfo(info);
+ } catch (DataModelException e) {
+ throw new ParserException(constructExtendedListenerErrorMessage(
+ UNHANDLED_PARSED_DATA, DEVIATION_DATA,
+ ctx.deviation().getText(), EXIT, e.getMessage()));
+ }
+ }
+}
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/MandatoryListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/MandatoryListener.java
index b711592..5f21154 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/MandatoryListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/MandatoryListener.java
@@ -16,7 +16,7 @@
package org.onosproject.yang.compiler.parser.impl.listeners;
-import org.onosproject.yang.compiler.datamodel.YangLeaf;
+import org.onosproject.yang.compiler.datamodel.YangMandatory;
import org.onosproject.yang.compiler.datamodel.utils.Parsable;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
@@ -73,18 +73,16 @@
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, MANDATORY_DATA, "", ENTRY);
- boolean isMandatory = getValidBooleanValue(ctx.mandatory().getText(), MANDATORY_DATA, ctx);
+ boolean isMandatory = getValidBooleanValue(ctx.mandatory().getText(),
+ MANDATORY_DATA, ctx);
Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case LEAF_DATA:
- YangLeaf leaf = (YangLeaf) tmpNode;
- leaf.setMandatory(isMandatory);
- break;
- case CHOICE_DATA: // TODO
- break;
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MANDATORY_DATA, "", ENTRY));
+ if (tmpNode instanceof YangMandatory) {
+ YangMandatory yangMandatory = ((YangMandatory) tmpNode);
+ yangMandatory.setMandatory(isMandatory);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(
+ INVALID_HOLDER, MANDATORY_DATA, "", ENTRY));
}
}
}
\ No newline at end of file
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/MaxElementsListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/MaxElementsListener.java
index ee7f1ef..f46b606 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/MaxElementsListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/MaxElementsListener.java
@@ -16,9 +16,8 @@
package org.onosproject.yang.compiler.parser.impl.listeners;
-import org.onosproject.yang.compiler.datamodel.YangLeafList;
-import org.onosproject.yang.compiler.datamodel.YangList;
import org.onosproject.yang.compiler.datamodel.YangMaxElement;
+import org.onosproject.yang.compiler.datamodel.YangMaxElementHolder;
import org.onosproject.yang.compiler.datamodel.utils.Parsable;
import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
@@ -85,17 +84,12 @@
maxElement.setCharPosition(ctx.getStart().getCharPositionInLine());
maxElement.setFileName(listener.getFileName());
Parsable tmpData = listener.getParsedDataStack().peek();
- switch (tmpData.getYangConstructType()) {
- case LEAF_LIST_DATA:
- YangLeafList leafList = (YangLeafList) tmpData;
- leafList.setMaxElements(maxElement);
- break;
- case LIST_DATA:
- YangList yangList = (YangList) tmpData;
- yangList.setMaxElements(maxElement);
- break;
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MAX_ELEMENT_DATA, "", ENTRY));
+ if (tmpData instanceof YangMaxElementHolder) {
+ YangMaxElementHolder holder = ((YangMaxElementHolder) tmpData);
+ holder.setMaxElements(maxElement);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(
+ INVALID_HOLDER, MAX_ELEMENT_DATA, "", ENTRY));
}
}
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/MinElementsListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/MinElementsListener.java
index ed80c4c..ed07598 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/MinElementsListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/MinElementsListener.java
@@ -16,15 +16,11 @@
package org.onosproject.yang.compiler.parser.impl.listeners;
-import org.onosproject.yang.compiler.datamodel.YangLeafList;
-import org.onosproject.yang.compiler.datamodel.YangList;
+import org.onosproject.yang.compiler.datamodel.YangMinElementHolder;
import org.onosproject.yang.compiler.datamodel.YangMinElement;
import org.onosproject.yang.compiler.datamodel.utils.Parsable;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerUtil;
import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.MIN_ELEMENT_DATA;
import static org.onosproject.yang.compiler.parser.antlrgencode.GeneratedYangParser.MinElementsStatementContext;
@@ -74,9 +70,11 @@
MinElementsStatementContext ctx) {
// Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, MIN_ELEMENT_DATA, ctx.minValue().getText(), ENTRY);
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, MIN_ELEMENT_DATA,
+ ctx.minValue().getText(), ENTRY);
- int minElementValue = getValidNonNegativeIntegerValue(ctx.minValue().getText(), MIN_ELEMENT_DATA, ctx);
+ int minElementValue = getValidNonNegativeIntegerValue(
+ ctx.minValue().getText(), MIN_ELEMENT_DATA, ctx);
YangMinElement minElement = new YangMinElement();
@@ -84,19 +82,15 @@
minElement.setLineNumber(ctx.getStart().getLine());
minElement.setCharPosition(ctx.getStart().getCharPositionInLine());
minElement.setFileName(listener.getFileName());
+
Parsable tmpData = listener.getParsedDataStack().peek();
- switch (tmpData.getYangConstructType()) {
- case LEAF_LIST_DATA:
- YangLeafList leafList = (YangLeafList) tmpData;
- leafList.setMinElements(minElement);
- break;
- case LIST_DATA:
- YangList yangList = (YangList) tmpData;
- yangList.setMinElements(minElement);
- break;
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MIN_ELEMENT_DATA,
- ctx.minValue().getText(), ENTRY));
+ if (tmpData instanceof YangMinElementHolder) {
+ YangMinElementHolder holder = ((YangMinElementHolder) tmpData);
+ holder.setMinElements(minElement);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(
+ INVALID_HOLDER, MIN_ELEMENT_DATA, ctx.minValue().getText(),
+ ENTRY));
}
}
}
\ No newline at end of file
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/ModuleListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/ModuleListener.java
index 346e35c..fa3a6f9 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/ModuleListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/ModuleListener.java
@@ -35,6 +35,7 @@
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IF_FEATURE;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_LEAFREF;
import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_USES;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.validateMultipleDeviationStatement;
import static org.onosproject.yang.compiler.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.MODULE_DATA;
import static org.onosproject.yang.compiler.parser.antlrgencode.GeneratedYangParser.ModuleStatementContext;
@@ -148,6 +149,16 @@
linkerException.setFileName(listener.getFileName());
throw linkerException;
}
+
+ /*
+ * Validate whether all deviation statement xpath is referring to same
+ * module
+ */
+ try {
+ validateMultipleDeviationStatement(module);
+ } catch (DataModelException e) {
+ throw new ParserException(e.getMessage());
+ }
}
private static void throwError(ListenerErrorType type,
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/SubModuleListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/SubModuleListener.java
index 7b18d5b..f1dbf66 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/SubModuleListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/SubModuleListener.java
@@ -25,12 +25,8 @@
import org.onosproject.yang.compiler.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorMessageConstruction;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerUtil;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerValidation;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.validateMultipleDeviationStatement;
import static org.onosproject.yang.compiler.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.MODULE_DATA;
import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.SUB_MODULE_DATA;
@@ -154,5 +150,15 @@
linkerException.setFileName(listener.getFileName());
throw linkerException;
}
+
+ /*
+ * Validate whether all deviation statement xpath is referring to same
+ * module
+ */
+ try {
+ validateMultipleDeviationStatement(subModule);
+ } catch (DataModelException e) {
+ throw new ParserException(e.getMessage());
+ }
}
}
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/TypeListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/TypeListener.java
index 0b16af7..7a23e7a 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/TypeListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/TypeListener.java
@@ -17,6 +17,7 @@
package org.onosproject.yang.compiler.parser.impl.listeners;
import org.onosproject.yang.compiler.datamodel.YangDerivedInfo;
+import org.onosproject.yang.compiler.datamodel.YangDeviateReplace;
import org.onosproject.yang.compiler.datamodel.YangLeaf;
import org.onosproject.yang.compiler.datamodel.YangLeafList;
import org.onosproject.yang.compiler.datamodel.YangNode;
@@ -32,7 +33,6 @@
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerUtil;
import static org.onosproject.yang.compiler.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.UNRESOLVED;
@@ -247,8 +247,10 @@
addToResolutionList(resolutionInfo, ctx);
}
break;
- //TODO: deviate replacement statement.
-
+ case DEVIATE_REPLACE:
+ YangDeviateReplace replace = (YangDeviateReplace) tmpData;
+ replace.setDataType(type);
+ break;
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
ctx.string().getText(), EXIT));
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/UniqueListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/UniqueListener.java
index e222422..c97d272 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/UniqueListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/UniqueListener.java
@@ -16,15 +16,12 @@
package org.onosproject.yang.compiler.parser.impl.listeners;
-import org.onosproject.yang.compiler.datamodel.YangList;
+import org.onosproject.yang.compiler.datamodel.YangUniqueHolder;
import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
import org.onosproject.yang.compiler.datamodel.utils.Parsable;
import org.onosproject.yang.compiler.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerUtil;
import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.UNIQUE_DATA;
import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
@@ -33,6 +30,7 @@
import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
+import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerUtil.SPACE;
import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yang.compiler.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
@@ -70,35 +68,43 @@
GeneratedYangParser.UniqueStatementContext ctx) {
// Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, UNIQUE_DATA, ctx.unique().getText(), ENTRY);
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, UNIQUE_DATA, ctx.unique()
+ .getText(), ENTRY);
Parsable tmpData = listener.getParsedDataStack().peek();
- if (listener.getParsedDataStack().peek() instanceof YangList) {
- YangList yangList = (YangList) tmpData;
- String tmpUniqueValue = removeQuotesAndHandleConcat(ctx.unique().getText());
+ if (listener.getParsedDataStack().peek() instanceof YangUniqueHolder) {
+ YangUniqueHolder uniqueHolder = (YangUniqueHolder) tmpData;
+ String tmpUniqueValue = removeQuotesAndHandleConcat(
+ ctx.unique().getText());
- if (tmpUniqueValue.contains(" ")) {
- String[] uniqueValues = tmpUniqueValue.split(" ");
+ if (tmpUniqueValue.contains(SPACE)) {
+ String[] uniqueValues = tmpUniqueValue.split(SPACE);
for (String uniqueValue : uniqueValues) {
try {
- yangList.addUnique(uniqueValue);
+ uniqueHolder.addUnique(uniqueValue);
} catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- UNIQUE_DATA,
- ctx.unique().getText(), ENTRY, e.getMessage()));
+ throw new ParserException(
+ constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+ UNIQUE_DATA,
+ ctx.unique().getText(),
+ ENTRY, e.getMessage()));
}
}
} else {
try {
- yangList.addUnique(tmpUniqueValue);
+ uniqueHolder.addUnique(tmpUniqueValue);
} catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, UNIQUE_DATA,
- ctx.unique().getText(), ENTRY, e.getMessage()));
+ throw new ParserException(
+ constructExtendedListenerErrorMessage(
+ UNHANDLED_PARSED_DATA, UNIQUE_DATA,
+ ctx.unique().getText(), ENTRY, e.getMessage()));
}
}
} else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, UNIQUE_DATA, ctx.unique().getText(),
- ENTRY));
+ throw new ParserException(
+ constructListenerErrorMessage(INVALID_HOLDER, UNIQUE_DATA,
+ ctx.unique().getText(),
+ ENTRY));
}
}
}
\ No newline at end of file
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/UnitsListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/UnitsListener.java
index f8db2cf..b5eb1f7 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/UnitsListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/UnitsListener.java
@@ -16,12 +16,15 @@
package org.onosproject.yang.compiler.parser.impl.listeners;
+import org.onosproject.yang.compiler.datamodel.YangDeviateAdd;
+import org.onosproject.yang.compiler.datamodel.YangDeviateDelete;
+import org.onosproject.yang.compiler.datamodel.YangDeviateReplace;
import org.onosproject.yang.compiler.datamodel.YangLeaf;
import org.onosproject.yang.compiler.datamodel.YangLeafList;
+import org.onosproject.yang.compiler.datamodel.YangTypeDef;
import org.onosproject.yang.compiler.datamodel.utils.Parsable;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
-import org.onosproject.yang.compiler.parser.impl.parserutils.ListenerErrorType;
import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.UNITS_DATA;
import static org.onosproject.yang.compiler.parser.antlrgencode.GeneratedYangParser.UnitsStatementContext;
@@ -78,11 +81,27 @@
leafList.setUnits(ctx.string().getText());
break;
case TYPEDEF_DATA:
- // TODO
+ YangTypeDef typeDef = (YangTypeDef) tmpData;
+ typeDef.setUnits(ctx.string().getText());
+ break;
+ case DEVIATE_ADD:
+ YangDeviateAdd deviateAdd = (YangDeviateAdd) tmpData;
+ deviateAdd.setUnits(ctx.string().getText());
+ break;
+ case DEVIATE_DELETE:
+ YangDeviateDelete deviateDelete = (YangDeviateDelete) tmpData;
+ deviateDelete.setUnits(ctx.string().getText());
+ break;
+ case DEVIATE_REPLACE:
+ YangDeviateReplace replace = (YangDeviateReplace) tmpData;
+ replace.setUnits(ctx.string().getText());
break;
default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, UNITS_DATA,
- ctx.string().getText(), ENTRY));
+ throw new ParserException(
+ constructListenerErrorMessage(INVALID_HOLDER,
+ UNITS_DATA,
+ ctx.string().getText(),
+ ENTRY));
}
}
}
\ No newline at end of file
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/parserutils/ListenerUtil.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/parserutils/ListenerUtil.java
index e71eb98..328b6bc 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/parserutils/ListenerUtil.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/parserutils/ListenerUtil.java
@@ -90,6 +90,7 @@
private static final String DATE_FORMAT = "yyyy-MM-dd";
private static final String REGEX_EQUAL = "[=]";
private static final String REGEX_OPEN_BRACE = "[(]";
+ public static final String SPACE = " ";
// No instantiation.
private ListenerUtil() {
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/parserutils/ListenerValidation.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/parserutils/ListenerValidation.java
index eeb1dc9..4b45fcd 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/parserutils/ListenerValidation.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/parserutils/ListenerValidation.java
@@ -240,4 +240,38 @@
throw parserException;
}
}
+
+ /**
+ * Checks if a either of one construct occurrence.
+ *
+ * @param ctx1 first optional child's context
+ * @param type1 first child construct for whom cardinality is
+ * to be validated
+ * @param ctx2 second optional child's context
+ * @param type2 second child construct for whom cardinality is
+ * to be validated
+ * @param type parent construct
+ * @param parentName parent name
+ * @param ctx parents's context
+ * @throws ParserException exception if cardinality check fails
+ */
+ public static void validateCardinalityMutuallyExclusive(List<?> ctx1,
+ YangConstructType type1,
+ List<?> ctx2,
+ YangConstructType type2,
+ YangConstructType type,
+ String parentName,
+ ParserRuleContext ctx)
+ throws ParserException {
+
+ if (!ctx1.isEmpty() && !ctx2.isEmpty()) {
+ String error = "YANG file error: Either " + getYangConstructType(type1)
+ + " or " + getYangConstructType(type2) + " should be present in "
+ + getYangConstructType(type) + " " + parentName + ".";
+ ParserException parserException = new ParserException(error);
+ parserException.setLine(ctx.getStart().getLine());
+ parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+ throw parserException;
+ }
+ }
}
diff --git a/compiler/base/parser/src/main/resources/GeneratedYang.g4 b/compiler/base/parser/src/main/resources/GeneratedYang.g4
index 3ba1201..af16c05 100644
--- a/compiler/base/parser/src/main/resources/GeneratedYang.g4
+++ b/compiler/base/parser/src/main/resources/GeneratedYang.g4
@@ -1207,9 +1207,12 @@
* [max-elements-stmt stmtsep]
* "}")
*/
- deviateAddStatement: DEVIATE_KEYWORD ADD_KEYWORD (STMTEND | (LEFT_CURLY_BRACE unitsStatement? mustStatement* uniqueStatement*
- defaultStatement? configStatement? mandatoryStatement? minElementsStatement? maxElementsStatement?
- RIGHT_CURLY_BRACE));
+ deviateAddStatement: DEVIATE_KEYWORD ADD_KEYWORD (STMTEND
+ | LEFT_CURLY_BRACE (unitsStatement | mustStatement
+ | uniqueStatement| defaultStatement| configStatement
+ | mandatoryStatement | minElementsStatement
+ | maxElementsStatement)*
+ RIGHT_CURLY_BRACE);
/**
* deviate-delete-stmt = deviate-keyword sep delete-keyword optsep
@@ -1222,7 +1225,8 @@
* "}")
*/
deviateDeleteStatement: DEVIATE_KEYWORD DELETE_KEYWORD (STMTEND
- | (LEFT_CURLY_BRACE unitsStatement? mustStatement* uniqueStatement* defaultStatement? RIGHT_CURLY_BRACE));
+ | LEFT_CURLY_BRACE (unitsStatement | mustStatement |
+ uniqueStatement | defaultStatement)* RIGHT_CURLY_BRACE);
/**
* deviate-replace-stmt = deviate-keyword sep replace-keyword optsep
@@ -1237,9 +1241,11 @@
* [max-elements-stmt stmtsep]
* "}")
*/
- deviateReplaceStatement: DEVIATE_KEYWORD REPLACE_KEYWORD (STMTEND | (LEFT_CURLY_BRACE typeStatement? unitsStatement?
- defaultStatement? configStatement? mandatoryStatement? minElementsStatement?
- maxElementsStatement? RIGHT_CURLY_BRACE));
+ deviateReplaceStatement: DEVIATE_KEYWORD REPLACE_KEYWORD (STMTEND
+ | LEFT_CURLY_BRACE (typeStatement | unitsStatement
+ | defaultStatement | configStatement
+ | mandatoryStatement | minElementsStatement
+ | maxElementsStatement)* RIGHT_CURLY_BRACE);
/**
* compiler-annotation-stmt = prefix:compiler-annotation-keyword string
diff --git a/compiler/base/parser/src/test/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviationListenerTest.java b/compiler/base/parser/src/test/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviationListenerTest.java
new file mode 100644
index 0000000..cca24d1
--- /dev/null
+++ b/compiler/base/parser/src/test/java/org/onosproject/yang/compiler/parser/impl/listeners/DeviationListenerTest.java
@@ -0,0 +1,212 @@
+/*
+ * 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.yang.compiler.parser.impl.listeners;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yang.compiler.datamodel.YangAtomicPath;
+import org.onosproject.yang.compiler.datamodel.YangDeviateAdd;
+import org.onosproject.yang.compiler.datamodel.YangDeviateDelete;
+import org.onosproject.yang.compiler.datamodel.YangDeviateReplace;
+import org.onosproject.yang.compiler.datamodel.YangDeviation;
+import org.onosproject.yang.compiler.datamodel.YangModule;
+import org.onosproject.yang.compiler.datamodel.YangNode;
+import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.MODULE_NODE;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.UNRESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.INT8;
+
+/**
+ * Test cases for testing deviation listener.
+ */
+public class DeviationListenerTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks deviation statement as sub-statement of module.
+ */
+ @Test
+ public void processDeviationNotSupported() throws IOException,
+ ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/" +
+ "ValidDeviationNotSupported.yang");
+
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ // Check whether the container is child of module
+ YangDeviation deviation = (YangDeviation) yangNode.getChild();
+ assertThat(deviation.getName(), is("/base:system/base:daytime"));
+ assertThat(deviation.getDescription(), is("\"desc\""));
+ assertThat(deviation.getReference(), is("\"ref\""));
+ assertThat(deviation.isDeviateNotSupported(), is(true));
+ List<YangAtomicPath> targetNode = deviation.getTargetNode();
+ assertThat(targetNode.get(0).getNodeIdentifier().getName(),
+ is("system"));
+ assertThat(targetNode.get(1).getNodeIdentifier().getName(),
+ is("daytime"));
+ assertThat(targetNode.get(0).getNodeIdentifier().getPrefix(),
+ is("base"));
+ assertThat(deviation.getResolvableStatus(), is(UNRESOLVED));
+ }
+
+ /**
+ * Checks deviation add statement as sub-statement of module.
+ */
+ @Test
+ public void processDeviationAddStatement() throws IOException,
+ ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/" +
+ "ValidDeviateAdd.yang");
+
+ assertThat((node instanceof YangModule), is(true));
+ assertThat(node.getNodeType(), is(MODULE_NODE));
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ YangDeviation deviation = (YangDeviation) yangNode.getChild();
+ assertThat(deviation.getName(), is("/base:system/base:user/base:type"));
+ assertThat(deviation.isDeviateNotSupported(), is(false));
+ List<YangAtomicPath> targetNode = deviation.getTargetNode();
+ assertThat(targetNode.get(0).getNodeIdentifier().getName(),
+ is("system"));
+ assertThat(targetNode.get(0).getNodeIdentifier().getPrefix(),
+ is("base"));
+ assertThat(targetNode.get(1).getNodeIdentifier().getName(),
+ is("user"));
+ assertThat(targetNode.get(2).getNodeIdentifier().getName(),
+ is("type"));
+
+ YangDeviateAdd deviateAdd = deviation.getDeviateAdd().get(0);
+ assertThat(deviateAdd.getUnits(), is("\"units\""));
+ assertThat(deviateAdd.getListOfMust().get(0).getConstraint(),
+ is("/base:system"));
+ assertThat(deviateAdd.getUniqueList().get(0), is("id"));
+ assertThat(deviateAdd.getDefaultValueInString(), is("admin"));
+ assertThat(deviateAdd.isConfig(), is(true));
+ assertThat(deviateAdd.isMandatory(), is(true));
+ assertThat(deviateAdd.getMinElements().getMinElement(), is(0));
+ assertThat(deviateAdd.getMaxElements().getMaxElement(), is(12343));
+ assertThat(deviation.getResolvableStatus(), is(UNRESOLVED));
+ }
+
+ /**
+ * Checks deviation delete statement as sub-statement of module.
+ */
+ @Test
+ public void processDeviationDeleteStatement() throws IOException,
+ ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/" +
+ "ValidDeviateDelete.yang");
+
+ assertThat((node instanceof YangModule), is(true));
+ assertThat(node.getNodeType(), is(MODULE_NODE));
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ YangDeviation deviation = (YangDeviation) yangNode.getChild();
+ assertThat(deviation.getName(), is("/base:system"));
+ assertThat(deviation.isDeviateNotSupported(), is(false));
+ List<YangAtomicPath> targetNode = deviation.getTargetNode();
+ assertThat(targetNode.get(0).getNodeIdentifier().getName(),
+ is("system"));
+ assertThat(targetNode.get(0).getNodeIdentifier().getPrefix(),
+ is("base"));
+
+ YangDeviateDelete deviateDelete = deviation.getDeviateDelete().get(0);
+ assertThat(deviateDelete.getUnits(), is("\"units\""));
+ assertThat(deviateDelete.getListOfMust().get(0).getConstraint(),
+ is("daytime or time"));
+ assertThat(deviateDelete.getUniqueList().get(0), is("id"));
+ assertThat(deviateDelete.getDefaultValueInString(), is("defaultValue"));
+ assertThat(deviation.getResolvableStatus(), is(UNRESOLVED));
+ }
+
+ /**
+ * Checks deviation replace statement as sub-statement of module.
+ */
+ @Test
+ public void processDeviationReplaceStatement() throws IOException,
+ ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/" +
+ "ValidDeviateReplace.yang");
+
+ assertThat((node instanceof YangModule), is(true));
+ assertThat(node.getNodeType(), is(MODULE_NODE));
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ YangDeviation deviation = (YangDeviation) yangNode.getChild();
+ assertThat(deviation.getName(), is("/base:system/base:name-server"));
+ assertThat(deviation.isDeviateNotSupported(), is(false));
+ List<YangAtomicPath> targetNode = deviation.getTargetNode();
+ assertThat(targetNode.get(0).getNodeIdentifier().getName(),
+ is("system"));
+ assertThat(targetNode.get(0).getNodeIdentifier().getPrefix(),
+ is("base"));
+ assertThat(targetNode.get(1).getNodeIdentifier().getName(),
+ is("name-server"));
+
+ YangDeviateReplace replace = deviation.getDeviateReplace().get(0);
+ assertThat(replace.getDataType().getDataType(), is(INT8));
+ assertThat(replace.getUnits(), is("\"units\""));
+ assertThat(replace.getDefaultValueInString(), is("0"));
+ assertThat(replace.isConfig(), is(true));
+ assertThat(replace.isMandatory(), is(true));
+ assertThat(replace.getMinElements().getMinElement(), is(0));
+ assertThat(replace.getMaxElements().getMaxElement(), is(3));
+ assertThat(deviation.getResolvableStatus(), is(UNRESOLVED));
+ }
+
+ /**
+ * Checks deviation unsupported statement and deviate add as
+ * sub-statement of module.
+ */
+ @Test
+ public void processInvalidDeviateStatement() throws
+ IOException, ParserException {
+ String error = "YANG file error: Either deviate-not-supported-stmt or" +
+ " deviate-replace should be present in deviation" +
+ " /base:system/base:daytime";
+ thrown.expect(ParserException.class);
+ thrown.expectMessage(error);
+ YangNode node = manager.getDataModel("src/test/resources/InvalidDeviateStatement.yang");
+ }
+}
+
diff --git a/compiler/base/parser/src/test/resources/InvalidDeviateStatement.yang b/compiler/base/parser/src/test/resources/InvalidDeviateStatement.yang
new file mode 100644
index 0000000..9068050
--- /dev/null
+++ b/compiler/base/parser/src/test/resources/InvalidDeviateStatement.yang
@@ -0,0 +1,19 @@
+module Test {
+ yang-version 1;
+ namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+ prefix On;
+ deviation /base:system/base:daytime {
+ description "desc";
+ reference "ref";
+ deviate not-supported;
+ deviate replace {
+ type int8;
+ units "units";
+ default "0";
+ config "true";
+ mandatory "true";
+ min-elements 0;
+ max-elements 3;
+ }
+ }
+}
diff --git a/compiler/base/parser/src/test/resources/ValidDeviateAdd.yang b/compiler/base/parser/src/test/resources/ValidDeviateAdd.yang
new file mode 100644
index 0000000..7915d54
--- /dev/null
+++ b/compiler/base/parser/src/test/resources/ValidDeviateAdd.yang
@@ -0,0 +1,17 @@
+module Test {
+ yang-version 1;
+ namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+ prefix On;
+ deviation /base:system/base:user/base:type {
+ deviate add {
+ units "units";
+ must "/base:system";
+ unique "id";
+ default "admin";
+ config "true";
+ mandatory "true";
+ min-elements "0";
+ max-elements "12343";
+ }
+ }
+}
diff --git a/compiler/base/parser/src/test/resources/ValidDeviateDelete.yang b/compiler/base/parser/src/test/resources/ValidDeviateDelete.yang
new file mode 100644
index 0000000..767f3de
--- /dev/null
+++ b/compiler/base/parser/src/test/resources/ValidDeviateDelete.yang
@@ -0,0 +1,13 @@
+module Test {
+ yang-version 1;
+ namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+ prefix On;
+ deviation "/base:system" {
+ deviate delete {
+ units "units";
+ must "daytime or time";
+ unique "id";
+ default "defaultValue";
+ }
+ }
+}
diff --git a/compiler/base/parser/src/test/resources/ValidDeviateReplace.yang b/compiler/base/parser/src/test/resources/ValidDeviateReplace.yang
new file mode 100644
index 0000000..dc7f0fb
--- /dev/null
+++ b/compiler/base/parser/src/test/resources/ValidDeviateReplace.yang
@@ -0,0 +1,16 @@
+module Test {
+ yang-version 1;
+ namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+ prefix On;
+ deviation /base:system/base:name-server {
+ deviate replace {
+ type int8;
+ units "units";
+ default "0";
+ config "true";
+ mandatory "true";
+ min-elements 0;
+ max-elements 3;
+ }
+ }
+}
diff --git a/compiler/base/parser/src/test/resources/ValidDeviationNotSupported.yang b/compiler/base/parser/src/test/resources/ValidDeviationNotSupported.yang
new file mode 100644
index 0000000..979f29f
--- /dev/null
+++ b/compiler/base/parser/src/test/resources/ValidDeviationNotSupported.yang
@@ -0,0 +1,10 @@
+module Test {
+ yang-version 1;
+ namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+ prefix On;
+ deviation /base:system/base:daytime {
+ description "desc";
+ reference "ref";
+ deviate not-supported;
+ }
+}
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/YangToolManager.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/YangToolManager.java
index 7378728..d4992cb 100644
--- a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/YangToolManager.java
+++ b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/YangToolManager.java
@@ -16,16 +16,17 @@
package org.onosproject.yang.compiler.base.tool;
-import org.onosproject.yang.compiler.parser.YangUtilsParser;
-import org.onosproject.yang.compiler.parser.exceptions.ParserException;
-import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
import org.onosproject.yang.compiler.base.tool.exception.YangToolException;
+import org.onosproject.yang.compiler.datamodel.YangDeviationHolder;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangReferenceResolver;
import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
import org.onosproject.yang.compiler.linker.YangLinker;
import org.onosproject.yang.compiler.linker.exceptions.LinkerException;
import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
+import org.onosproject.yang.compiler.parser.YangUtilsParser;
+import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
import org.slf4j.Logger;
@@ -302,7 +303,8 @@
yangNodeSortedList.addAll(yangNodeSet);
sort(yangNodeSortedList);
for (YangNode node : yangNodeSortedList) {
- if (node.isToTranslate()) {
+ if (node.isToTranslate() && !((YangDeviationHolder) node)
+ .isModuleForDeviation()) {
generateJavaCode(node, pluginConfig);
}
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/GeneratedTempFileType.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/GeneratedTempFileType.java
index ad410a1..cc0f4e3 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/GeneratedTempFileType.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/GeneratedTempFileType.java
@@ -137,21 +137,6 @@
public static final int LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK = 1 << 22;
/**
- * Is filter content match for leaves class.
- */
- public static final int FILTER_CONTENT_MATCH_FOR_LEAF_MASK = 1 << 23;
-
- /**
- * Is filter content match for leaf lists class.
- */
- public static final int FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK = 1 << 24;
-
- /**
- * Is filter content match for nodes class.
- */
- public static final int FILTER_CONTENT_MATCH_FOR_NODES_MASK = 1 << 25;
-
- /**
* Edit config class content for class.
*/
public static final int EDIT_CONTENT_MASK = 1 << 26;
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java
index 7b47f96..426806a 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java
@@ -18,7 +18,6 @@
import org.onosproject.yang.compiler.datamodel.RpcNotificationContainer;
import org.onosproject.yang.compiler.datamodel.YangAugment;
import org.onosproject.yang.compiler.datamodel.YangCase;
-import org.onosproject.yang.compiler.datamodel.YangChoice;
import org.onosproject.yang.compiler.datamodel.YangDataStructure;
import org.onosproject.yang.compiler.datamodel.YangLeaf;
import org.onosproject.yang.compiler.datamodel.YangLeafList;
@@ -57,9 +56,6 @@
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.EDIT_CONTENT_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
-import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
-import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
-import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
@@ -98,22 +94,16 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getImportString;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getOverRideString;
-import static org.onosproject.yang.compiler.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeaf;
-import static org.onosproject.yang.compiler.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeafList;
-import static org.onosproject.yang.compiler.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForNode;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorErrorType.INVALID_LEAF_HOLDER;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorErrorType.INVALID_NODE;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorErrorType.INVALID_PARENT_NODE;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorErrorType.MISSING_PARENT_NODE;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorUtils.getBeanFiles;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorUtils.getErrorMsg;
-import static org.onosproject.yang.compiler.utils.UtilConstants.AUGMENT_MAP_TYPE;
import static org.onosproject.yang.compiler.utils.UtilConstants.BIT_SET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.BOOLEAN_DATA_TYPE;
import static org.onosproject.yang.compiler.utils.UtilConstants.BUILDER;
import static org.onosproject.yang.compiler.utils.UtilConstants.CLASS_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_CURLY_BRACKET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT;
import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT_CAPS;
import static org.onosproject.yang.compiler.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
@@ -123,34 +113,27 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yang.compiler.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
import static org.onosproject.yang.compiler.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
-import static org.onosproject.yang.compiler.utils.UtilConstants.HASH_MAP;
import static org.onosproject.yang.compiler.utils.UtilConstants.INTERFACE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_UTIL_PKG;
import static org.onosproject.yang.compiler.utils.UtilConstants.KEYS;
import static org.onosproject.yang.compiler.utils.UtilConstants.MAP;
+import static org.onosproject.yang.compiler.utils.UtilConstants.MODEL_OBJECT;
+import static org.onosproject.yang.compiler.utils.UtilConstants.MODEL_OBJECT_PKG;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.OPERATION_TYPE_ATTRIBUTE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.OPERATION_TYPE_CLASS;
import static org.onosproject.yang.compiler.utils.UtilConstants.OP_PARAM;
import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
import static org.onosproject.yang.compiler.utils.UtilConstants.PRIVATE;
import static org.onosproject.yang.compiler.utils.UtilConstants.PROTECTED;
import static org.onosproject.yang.compiler.utils.UtilConstants.QUESTION_MARK;
-import static org.onosproject.yang.compiler.utils.UtilConstants.REFLECT_IMPORTS;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yang.compiler.utils.UtilConstants.SERVICE;
import static org.onosproject.yang.compiler.utils.UtilConstants.SLASH;
import static org.onosproject.yang.compiler.utils.UtilConstants.SPACE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SUBTREE_FILTERED;
import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE_LEAF;
-import static org.onosproject.yang.compiler.utils.UtilConstants.YANG;
-import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_AUGMENTED_INFO_MAP;
-import static org.onosproject.yang.compiler.utils.io.impl.FileSystemUtil.*;
+import static org.onosproject.yang.compiler.utils.io.impl.FileSystemUtil.closeFile;
+import static org.onosproject.yang.compiler.utils.io.impl.FileSystemUtil.readAppendFile;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.ADD_TO_LIST;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
-import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCamelCase;
@@ -159,9 +142,6 @@
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.mergeJavaFiles;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.validateLineLength;
-import static org.onosproject.yang.compiler.utils.UtilConstants.BIT_SET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_UTIL_PKG;
-import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE_LEAF;
/**
* Represents implementation of java code fragments temporary implementations.
@@ -406,21 +386,6 @@
private File leafIdAttributeTempFileHandle;
/**
- * Temporary file handle for is content match method for leaf-list.
- */
- private File getSubtreeFilteringForListTempFileHandle;
-
- /**
- * Temporary file handle for is content match method for node.
- */
- private File getSubtreeFilteringForChildNodeTempFileHandle;
-
- /**
- * Temporary file handle for is content match method for leaf.
- */
- private File subtreeFilteringForLeafTempFileHandle;
-
- /**
* Temporary file handle for edit content file.
*/
private File editContentTempFileHandle;
@@ -465,6 +430,7 @@
*/
if (javaFlagSet(INTERFACE_MASK)) {
addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK |
+ SETTER_FOR_INTERFACE_MASK |
ADD_TO_LIST_INTERFACE_MASK |
LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK);
}
@@ -492,10 +458,7 @@
addGeneratedTempFile(
ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
HASH_CODE_IMPL_MASK | EQUALS_IMPL_MASK |
- TO_STRING_IMPL_MASK | ADD_TO_LIST_IMPL_MASK |
- FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK |
- FILTER_CONTENT_MATCH_FOR_LEAF_MASK |
- FILTER_CONTENT_MATCH_FOR_NODES_MASK);
+ TO_STRING_IMPL_MASK | ADD_TO_LIST_IMPL_MASK);
}
/*
* Initialize temp files to generate type class.
@@ -559,18 +522,6 @@
leafIdAttributeTempFileHandle =
getTemporaryFileHandle(LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME);
}
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK)) {
- subtreeFilteringForLeafTempFileHandle =
- getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_FILE_NAME);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK)) {
- getSubtreeFilteringForListTempFileHandle =
- getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK)) {
- getSubtreeFilteringForChildNodeTempFileHandle =
- getTemporaryFileHandle(FILTER_CONTENT_MATCH_NODE_FILE_NAME);
- }
if (tempFlagSet(EDIT_CONTENT_MASK)) {
editContentTempFileHandle =
getTemporaryFileHandle(EDIT_CONTENT_FILE_NAME);
@@ -622,18 +573,6 @@
TempJavaBeanFragmentFiles tempFiles =
getBeanFiles((JavaCodeGeneratorInfo) parent);
tempFiles.setAttrNode(curNode);
- JavaFileInfoTranslator fileInfo = ((JavaCodeGeneratorInfo) parent)
- .getJavaFileInfo();
- if (curNode instanceof YangChoice && curNode.isOpTypeReq()) {
- JavaQualifiedTypeInfoTranslator info = new
- JavaQualifiedTypeInfoTranslator();
- info.setClassInfo(INVOCATION_TARGET_EXCEPTION);
- info.setPkgInfo(REFLECT_IMPORTS);
- info.setForInterface(false);
- tempFiles.getJavaImportData().addImportInfo(
- info, getCapitalCase(fileInfo.getJavaName()),
- fileInfo.getPackage());
- }
JavaAttributeInfo attr = getCurNodeAsAttributeInTarget(
curNode, parent, isList, tempFiles);
tempFiles.addJavaSnippetInfoToApplicableTempFiles(attr, config);
@@ -691,17 +630,6 @@
}
qualified = parentImportData.addImportInfo(typeInfo, className,
fileInfo.getPackage());
- if (!qualified && !(curNode instanceof YangChoice) &&
- targetNode.isOpTypeReq()) {
- String name = DEFAULT_CAPS + typeInfo.getClassInfo();
- JavaQualifiedTypeInfoTranslator qInfo =
- new JavaQualifiedTypeInfoTranslator();
- qInfo.setForInterface(false);
- qInfo.setPkgInfo(typeInfo.getPkgInfo());
- qInfo.setClassInfo(name);
- parentImportData.addImportInfo(qInfo, className,
- fileInfo.getPackage());
- }
}
boolean collectionSet = false;
if (curNode instanceof YangList) {
@@ -1065,43 +993,6 @@
}
/**
- * Adds is filter content match for leaf.
- *
- * @param attr java attribute
- * @throws IOException when fails to do IO operations
- */
- private void addSubTreeFilteringForLeaf(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(subtreeFilteringForLeafTempFileHandle,
- getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) +
- NEW_LINE);
- }
-
- /**
- * Adds is filter content match for leaf-list.
- *
- * @param attr java attribute
- * @throws IOException when fails to do IO operations
- */
- private void addSubtreeFilteringForLeafList(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(getSubtreeFilteringForListTempFileHandle,
- getSubtreeFilteringForLeafList(attr) + NEW_LINE);
- }
-
- /**
- * Adds is filter content match for nodes.
- *
- * @param attr java attribute
- * @throws IOException when fails to do IO operations
- */
- private void addSubtreeFilteringForChildNode(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(getSubtreeFilteringForChildNodeTempFileHandle,
- getSubtreeFilteringForNode(attr, attrNode) + NEW_LINE);
- }
-
- /**
* Adds attribute for class.
*
* @param attr attribute info
@@ -1149,10 +1040,6 @@
String setter = getSetterForClass(attr, getGeneratedJavaClassName(),
getGeneratedJavaFiles());
String javadoc = getOverRideString();
- if (attr.getAttributeName().equals(SUBTREE_FILTERED)) {
- javadoc = getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
- false, null);
- }
appendToFile(setterImplTempFileHandle, javadoc + setter);
}
@@ -1172,10 +1059,6 @@
if (ds != null) {
annotation = ds.name();
}
- if (attr.getAttributeName().equals(SUBTREE_FILTERED)) {
- javadoc = getJavaDoc(GETTER_METHOD, attr.getAttributeName(),
- false, annotation);
- }
if (javaFlagSet(BUILDER_CLASS_MASK)) {
appendToFile(getterImplTempFileHandle, javadoc + getter);
} else {
@@ -1559,42 +1442,6 @@
}
}
- /**
- * Adds operation type to temp files.
- *
- * @param curNode current YANG node
- * @param config YANG plugin config
- * @throws IOException IO exception
- */
- protected void addOperationTypeToTempFiles(YangNode curNode,
- YangPluginConfig config)
- throws IOException {
- JavaQualifiedTypeInfoTranslator typeInfo =
- new JavaQualifiedTypeInfoTranslator();
- typeInfo.setClassInfo(OPERATION_TYPE_CLASS);
- JavaFileInfo curInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- JavaFileInfo info;
- if (curNode instanceof RpcNotificationContainer) {
- info = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- } else {
- info = ((JavaFileInfoContainer) getModuleNode(curNode))
- .getJavaFileInfo();
- }
-
- typeInfo.setPkgInfo(info.getPackage().toLowerCase() + PERIOD +
- getCapitalCase(info.getJavaName()));
- String curNodeName = getCapitalCase(curInfo.getJavaName());
- boolean isQualified = false;
- if (!(curNode instanceof RpcNotificationContainer)) {
- isQualified = javaImportData.addImportInfo(typeInfo, curNodeName,
- curInfo.getPackage());
- }
- JavaAttributeInfo attributeInfo =
- getAttributeInfoForTheData(typeInfo, YANG + curNodeName +
- OPERATION_TYPE_ATTRIBUTE, null, isQualified, false);
- addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
- }
-
private YangNode getModuleNode(YangNode curNode) {
YangNode tempNode = curNode.getParent();
while (!(tempNode instanceof RpcNotificationContainer)) {
@@ -1624,78 +1471,6 @@
addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
}
- /**
- * Adds value leaf flag to temp files.
- *
- * @param config YANG plugin config
- * @throws IOException IO exception
- */
- protected void addSelectLeafFlag(YangPluginConfig config)
- throws IOException {
- JavaQualifiedTypeInfoTranslator typeInfo =
- new JavaQualifiedTypeInfoTranslator();
- typeInfo.setClassInfo(BIT_SET);
- typeInfo.setPkgInfo(JAVA_UTIL_PKG);
- JavaAttributeInfo attributeInfo =
- getAttributeInfoForTheData(typeInfo, SELECT_LEAF, null, false, false);
- addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
- }
-
- /**
- * Adds sub tree filtering to temp files.
- *
- * @param config YANG plugin config
- * @throws IOException IO exception
- */
- protected void addIsSubTreeFilteredFlag(YangPluginConfig config)
- throws IOException {
- JavaQualifiedTypeInfoTranslator typeInfo =
- new JavaQualifiedTypeInfoTranslator();
- typeInfo.setClassInfo(BOOLEAN_DATA_TYPE);
- typeInfo.setPkgInfo(null);
- JavaAttributeInfo attributeInfo =
- getAttributeInfoForTheData(typeInfo, SUBTREE_FILTERED, null, false, false);
- addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
- }
-
- /**
- * Adds value leaf flag to temp files.
- *
- * @param config YANG plugin config
- * @param curNode current yang node
- * @throws IOException IO exception
- */
- protected void addYangAugmentedMap(YangPluginConfig config, YangNode curNode)
- throws IOException {
- JavaFileInfoTranslator info = ((JavaCodeGeneratorInfo) curNode)
- .getJavaFileInfo();
- JavaQualifiedTypeInfoTranslator typeInfo =
- new JavaQualifiedTypeInfoTranslator();
- typeInfo.setClassInfo(AUGMENT_MAP_TYPE);
- //Fix for add yangAugmentedInfo in equals/hashcode/and to string method.
- typeInfo.setPkgInfo(null);
- typeInfo.setForInterface(false);
- JavaAttributeInfo attributeInfo =
- getAttributeInfoForTheData(typeInfo, YANG_AUGMENTED_INFO_MAP,
- null, false, false);
- //MAP
- addImportInfoOfNode(MAP, COLLECTION_IMPORTS,
- getCapitalCase(info.getJavaName()),
- info.getPackage(), true);
- //HASH map
- addImportInfoOfNode(HASH_MAP, COLLECTION_IMPORTS,
- getCapitalCase(info.getJavaName()),
- info.getPackage(), false);
-
- if (curNode.isOpTypeReq()) {
- //exception
- addImportInfoOfNode(INVOCATION_TARGET_EXCEPTION, REFLECT_IMPORTS,
- getCapitalCase(info.getJavaName()),
- info.getPackage(), false);
- }
- addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
- }
-
private JavaQualifiedTypeInfoTranslator addImportInfoOfNode(
String cls, String pkg, String nodeName, String nodePkg,
boolean isForInterface) {
@@ -1722,27 +1497,20 @@
isAttributePresent = true;
String attrName = newAttrInfo.getAttributeName();
//Boolean flag for operation type attr info generation control.
- boolean required = !attrName.equals(VALUE_LEAF) &&
- !attrName.equals(SELECT_LEAF) &&
- !attrName.equals(YANG_AUGMENTED_INFO_MAP);
- //Boolean flag for subtree for nodes info generation control.
- boolean subTreeForChild =
- tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK) &&
- newAttrInfo.getAttributeType() == null &&
- !attrName.contains(OPERATION_TYPE_ATTRIBUTE) &&
- required && !attrName.equals(SUBTREE_FILTERED);
- ;
+ boolean required = !attrName.equals(VALUE_LEAF);
+
if (tempFlagSet(ATTRIBUTES_MASK)) {
addAttribute(newAttrInfo);
}
- if (tempFlagSet(GETTER_FOR_INTERFACE_MASK) &&
- !attrName.equals(SUBTREE_FILTERED)) {
+
+ if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
addGetterForInterface(newAttrInfo);
}
- if (tempFlagSet(SETTER_FOR_INTERFACE_MASK) && required &&
- !attrName.equals(SUBTREE_FILTERED)) {
+
+ if (tempFlagSet(SETTER_FOR_INTERFACE_MASK) && required) {
addSetterForInterface(newAttrInfo);
}
+
if (tempFlagSet(SETTER_FOR_CLASS_MASK) && required) {
addSetterImpl(newAttrInfo);
}
@@ -1766,17 +1534,7 @@
addAddToListInterface(newAttrInfo);
}
YangType attrType = newAttrInfo.getAttributeType();
- if (subTreeForChild) {
- addSubtreeFilteringForChildNode(newAttrInfo);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK) &&
- !listAttr && attrType != null) {
- addSubTreeFilteringForLeaf(newAttrInfo);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) &&
- listAttr && attrType != null) {
- addSubtreeFilteringForLeafList(newAttrInfo);
- }
+
if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) &&
!listAttr && attrType != null) {
leafCount++;
@@ -1787,6 +1545,7 @@
if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
addGetterImpl(newAttrInfo);
}
+
if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
JavaQualifiedTypeInfoTranslator typeInfo =
getQualifiedInfoOfFromString(newAttrInfo,
@@ -1847,10 +1606,15 @@
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
- if (curNode.isOpTypeReq()) {
- addImportInfoOfNode(BIT_SET, JAVA_UTIL_PKG, getGeneratedJavaClassName(),
+ addImportInfoOfNode(MODEL_OBJECT, MODEL_OBJECT_PKG, getGeneratedJavaClassName(),
+ getJavaFileInfo().getPackage(), false);
+
+ if (curNode instanceof RpcNotificationContainer) {
+ addImportInfoOfNode(MAP, JAVA_UTIL_PKG,
+ getGeneratedJavaClassName(),
getJavaFileInfo().getPackage(), false);
}
+
if (isAttributePresent) {
//Object utils
addImportInfoOfNode(JAVA_UTIL_OBJECTS_IMPORT_CLASS, JAVA_UTIL_PKG,
@@ -1905,6 +1669,18 @@
removeCaseParentImport(curNode, imports);
}
+ if ((fileType & DEFAULT_CLASS_MASK) != 0) {
+ //add model object to extend list
+ JavaQualifiedTypeInfoTranslator typeInfo = new
+ JavaQualifiedTypeInfoTranslator();
+ typeInfo.setClassInfo(MODEL_OBJECT);
+ typeInfo.setForInterface(false);
+ typeInfo.setPkgInfo(MODEL_OBJECT_PKG);
+ typeInfo.setQualified(false);
+ getBeanFiles(curNode).getJavaExtendsListHolder()
+ .addToExtendsList(typeInfo, curNode, getBeanFiles(curNode));
+ }
+
if ((fileType & BUILDER_CLASS_MASK) != 0 ||
(fileType & DEFAULT_CLASS_MASK) != 0) {
@@ -1930,6 +1706,7 @@
mergeJavaFiles(builderClassJavaFileHandle,
implClassJavaFileHandle);
}
+
insertDataIntoJavaFile(implClassJavaFileHandle, CLOSE_CURLY_BRACKET);
validateLineLength(implClassJavaFileHandle);
}
@@ -1944,6 +1721,7 @@
getJavaFileHandle(getJavaClassName(
KEY_CLASS_FILE_NAME_SUFFIX));
generateKeyClassFile(keyClassJavaFileHandle, curNode);
+
}
}
//Close all the file handles.
@@ -2012,15 +1790,6 @@
if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK)) {
closeFile(leafIdAttributeTempFileHandle);
}
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK)) {
- closeFile(subtreeFilteringForLeafTempFileHandle);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK)) {
- closeFile(getSubtreeFilteringForListTempFileHandle);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK)) {
- closeFile(getSubtreeFilteringForChildNodeTempFileHandle);
- }
if (tempFlagSet(EDIT_CONTENT_MASK)) {
closeFile(editContentTempFileHandle);
}
@@ -2078,15 +1847,6 @@
}
/**
- * Returns temp file for is content match.
- *
- * @return temp file for is content match
- */
- public File getSubtreeFilteringForLeafTempFileHandle() {
- return subtreeFilteringForLeafTempFileHandle;
- }
-
- /**
* Returns temp file for edit content file.
*
* @return temp file for edit content file
@@ -2096,24 +1856,6 @@
}
/**
- * Returns temp file for is content match.
- *
- * @return temp file for is content match
- */
- public File getGetSubtreeFilteringForListTempFileHandle() {
- return getSubtreeFilteringForListTempFileHandle;
- }
-
- /**
- * Returns temp file for is content match.
- *
- * @return temp file for is content match
- */
- public File getGetSubtreeFilteringForChildNodeTempFileHandle() {
- return getSubtreeFilteringForChildNodeTempFileHandle;
- }
-
- /**
* Checks if a given flag is set in generated java files.
* Returns true if ANY flag is set in a bitwise-ORed argument, e.g.
* <pre>
@@ -2146,4 +1888,5 @@
public void setAttrNode(YangNode attrNode) {
this.attrNode = attrNode;
}
+
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/YangJavaModelUtils.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/YangJavaModelUtils.java
index 4cc70c2..ddc83f2 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/YangJavaModelUtils.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/YangJavaModelUtils.java
@@ -51,7 +51,7 @@
import java.util.Map;
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
-import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.isRpcNotificationPresent;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yang.compiler.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
@@ -263,16 +263,6 @@
if (isLeafPresent) {
bean.addValueLeafFlag(config, (YangNode) info);
}
- if (((YangNode) info).isOpTypeReq()) {
- // Add operation type as an attribute.
- bean.addOperationTypeToTempFiles((YangNode) info,
- config);
- bean.addIsSubTreeFilteredFlag(config);
- if (isLeafPresent) {
- //Add select leaf flag attribute to temp file.
- bean.addSelectLeafFlag(config);
- }
- }
} else if (info instanceof YangTypeHolder) {
/*
* Typedef
@@ -429,9 +419,6 @@
generateCodeOfNode(info, config);
TempJavaBeanFragmentFiles tempFiles = getBeanFiles(info);
- if (!(info instanceof YangChoice)) {
- tempFiles.addYangAugmentedMap(config, (YangNode) info);
- }
if (info instanceof YangCase) {
YangNode parent = ((YangCase) info).getParent();
JavaQualifiedTypeInfoTranslator typeInfo =
@@ -514,7 +501,7 @@
}
updatePackageInfo(info, config, rootPkg);
- if (isRpcChildNodePresent((YangNode) info)) {
+ if (isRpcNotificationPresent((YangNode) info)) {
info.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
}
generateTempFiles(info, config);
@@ -557,16 +544,6 @@
}
/**
- * Returns true if get/set method of root node are required.
- *
- * @param node root node
- * @return true if get/set method of root node are required
- */
- public static boolean isGetSetOfRootNodeRequired(YangNode node) {
- return isNodeCodeGenRequired(node, false);
- }
-
- /**
* Returns true if either get/set method of root node are required or root
* node contains any data node. This check is done depending on the
* boolean parameter indicating whether check to be performed for root
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaModuleTranslator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaModuleTranslator.java
index dbc6803..51fb388 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaModuleTranslator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaModuleTranslator.java
@@ -28,6 +28,8 @@
import java.io.IOException;
import java.util.ArrayList;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.isRpcNotificationPresent;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
@@ -133,7 +135,9 @@
try {
generateCodeOfRootNode(this, yangPlugin, modulePkg);
//Add augmented rpc name
- tempFileHandle.getServiceTempFiles().addAugmentedRpcMethod(this);
+ if (isRpcChildNodePresent(this)) {
+ tempFileHandle.getServiceTempFiles().addAugmentedRpcMethod(this);
+ }
} catch (IOException e) {
throw new TranslatorException(getErrorMsg(FAIL_AT_ENTRY, this,
e.getLocalizedMessage()));
@@ -173,8 +177,10 @@
.getCodeGenerateForSbi() == null ||
!getJavaFileInfo().getPluginConfig()
.getCodeGenerateForSbi().equals(SBI)) {
- getTempJavaCodeFragmentFiles()
- .generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
+ if (isRpcNotificationPresent(this)) {
+ getTempJavaCodeFragmentFiles()
+ .generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
+ }
}
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaSubModuleTranslator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
index 5cee773..76e3ff7 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
@@ -29,6 +29,8 @@
import java.io.IOException;
import java.util.ArrayList;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.isRpcNotificationPresent;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
@@ -145,8 +147,10 @@
}
try {
generateCodeOfRootNode(this, yangPlugin, subModulePkg);
- tempFileHandle.getServiceTempFiles().addAugmentedRpcMethod(
- this);
+ if (isRpcChildNodePresent(this)) {
+ tempFileHandle.getServiceTempFiles().addAugmentedRpcMethod(
+ this);
+ }
} catch (IOException e) {
throw new TranslatorException(getErrorMsg(FAIL_AT_ENTRY, this,
e.getLocalizedMessage()));
@@ -183,8 +187,10 @@
.getCodeGenerateForSbi() == null ||
!getJavaFileInfo().getPluginConfig()
.getCodeGenerateForSbi().equals(SBI)) {
- getTempJavaCodeFragmentFiles().generateJavaFile(
- GENERATE_SERVICE_AND_MANAGER, this);
+ if (isRpcNotificationPresent(this)) {
+ getTempJavaCodeFragmentFiles().generateJavaFile(
+ GENERATE_SERVICE_AND_MANAGER, this);
+ }
}
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/ClassDefinitionGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/ClassDefinitionGenerator.java
index 115d220..896426a 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/ClassDefinitionGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/ClassDefinitionGenerator.java
@@ -71,6 +71,7 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.IMPLEMENTS;
import static org.onosproject.yang.compiler.utils.UtilConstants.INTERFACE;
import static org.onosproject.yang.compiler.utils.UtilConstants.LISTENER_SERVICE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.MODEL_OBJECT;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yang.compiler.utils.UtilConstants.OP_PARAM;
@@ -239,16 +240,10 @@
*/
private static String getImplClassDefinition(String yangName,
YangNode curNode) {
- if (!(curNode instanceof YangCase)) {
- String clsDef = getClassDefinitionForWhenExtended(
- curNode, yangName, DEFAULT_CLASS_MASK);
- if (clsDef != null) {
- return clsDef;
- }
- }
- if (curNode instanceof RpcNotificationContainer) {
- return getDefaultDefinitionWithImpl(
- CLASS, getSuffixedName(yangName, OP_PARAM), PUBLIC, yangName);
+ String clsDef = getClassDefinitionForWhenExtended(
+ curNode, yangName, DEFAULT_CLASS_MASK);
+ if (clsDef != null) {
+ return clsDef;
}
return getDefaultDefinitionWithImpl(CLASS, getDefaultName(yangName),
PUBLIC, yangName);
@@ -416,16 +411,26 @@
def.toString(), holder));
break;
case BUILDER_CLASS_MASK:
+ boolean isModelObject = false;
+ for (JavaQualifiedTypeInfoTranslator info : holder.getExtendsList()) {
+ if (info.getClassInfo().equals(MODEL_OBJECT)) {
+ isModelObject = true;
+ }
+ }
def.append(STATIC).append(SPACE).append(CLASS)
- .append(SPACE).append(yangName).append(BUILDER)
- .append(SPACE).append(EXTEND).append(SPACE);
- def = new StringBuilder(getDefinitionString(def.toString(),
- holder));
+ .append(SPACE).append(yangName).append(BUILDER);
+ if (!isModelObject) {
+ def.append(SPACE).append(EXTEND).append(SPACE);
+ def = new StringBuilder(getDefinitionString(def.toString(),
+ holder));
+ }
def.append(SPACE).append(IMPLEMENTS).append(SPACE)
.append(yangName).append(PERIOD)
.append(yangName).append(BUILDER);
break;
case DEFAULT_CLASS_MASK:
+
+ // class defination
if (curNode instanceof RpcNotificationContainer) {
def.append(CLASS).append(SPACE).append(yangName)
.append(OP_PARAM).append(SPACE).append(EXTEND)
@@ -435,9 +440,18 @@
.append(yangName).append(SPACE).append(EXTEND)
.append(SPACE);
}
- def = new StringBuilder(getDefinitionString(def.toString(),
- holder));
- def.append(SPACE).append(IMPLEMENTS).append(SPACE)
+
+ // append with extendList
+ if (curNode instanceof YangCase) {
+ def = new StringBuilder(getDefinitionStringForCase(def.toString(),
+ holder));
+ } else {
+ def = new StringBuilder(getDefinitionString(def.toString(),
+ holder));
+ }
+
+ // append implements
+ def.append(IMPLEMENTS).append(SPACE)
.append(yangName);
break;
default:
@@ -472,4 +486,24 @@
def = builder.toString();
return trimAtLast(def, COMMA);
}
+
+ /**
+ * Returns updated class definition for case.
+ *
+ * @param def current definition
+ * @param holder extend list holder
+ * @return updated class definition
+ */
+ private static String getDefinitionStringForCase(String def,
+ JavaExtendsListHolder holder) {
+ StringBuilder builder = new StringBuilder(def);
+ for (JavaQualifiedTypeInfoTranslator info : holder.getExtendsList()) {
+ if (!info.getClassInfo().equals(MODEL_OBJECT)) {
+ continue;
+ }
+ builder.append(info.getClassInfo() + COMMA + SPACE);
+ }
+ def = builder.toString();
+ return trimAtLast(def, COMMA);
+ }
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaCodeSnippetGen.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaCodeSnippetGen.java
index 810123c..9cb4cca 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaCodeSnippetGen.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaCodeSnippetGen.java
@@ -43,7 +43,6 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.ENUM;
import static org.onosproject.yang.compiler.utils.UtilConstants.EQUAL;
import static org.onosproject.yang.compiler.utils.UtilConstants.FOUR_SPACE_INDENTATION;
-import static org.onosproject.yang.compiler.utils.UtilConstants.HASH_MAP;
import static org.onosproject.yang.compiler.utils.UtilConstants.INT;
import static org.onosproject.yang.compiler.utils.UtilConstants.INT_MAX_RANGE_ATTR;
import static org.onosproject.yang.compiler.utils.UtilConstants.INT_MIN_RANGE_ATTR;
@@ -55,14 +54,12 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
-import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_CLOSE_DIAMOND_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
import static org.onosproject.yang.compiler.utils.UtilConstants.PRIVATE;
import static org.onosproject.yang.compiler.utils.UtilConstants.PUBLIC;
import static org.onosproject.yang.compiler.utils.UtilConstants.QUEUE;
import static org.onosproject.yang.compiler.utils.UtilConstants.QUOTES;
import static org.onosproject.yang.compiler.utils.UtilConstants.SCHEMA_NAME;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yang.compiler.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yang.compiler.utils.UtilConstants.SET;
import static org.onosproject.yang.compiler.utils.UtilConstants.SET_VALUE_PARA;
@@ -78,7 +75,6 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.ULONG_MAX_RANGE_ATTR;
import static org.onosproject.yang.compiler.utils.UtilConstants.ULONG_MIN_RANGE_ATTR;
import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE_LEAF;
-import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_AUGMENTED_INFO_MAP;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.enumJavaDocForInnerClass;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.getJavaDoc;
@@ -147,15 +143,10 @@
attrDef.append(attrType).append(SPACE)
.append(attrName);
//Initialize select leaf/value leaf/ augment map attribute.
- if (attrName.equals(SELECT_LEAF) || attrName.equals(VALUE_LEAF)) {
+ if (attrName.equals(VALUE_LEAF)) {
attrDef.append(SPACE).append(EQUAL).append(SPACE).append(NEW)
.append(SPACE).append(BIT_SET)
.append(OPEN_CLOSE_BRACKET_STRING);
- } else if (attrName.equals(YANG_AUGMENTED_INFO_MAP)) {
- attrDef.append(SPACE).append(EQUAL).append(SPACE).append(NEW)
- .append(SPACE).append(HASH_MAP)
- .append(OPEN_CLOSE_DIAMOND_STRING)
- .append(OPEN_CLOSE_BRACKET_STRING);
}
attrDef.append(signatureClose());
@@ -405,38 +396,6 @@
}
/**
- * Returns operation type enum.
- *
- * @return operation type enum
- */
- static String getOperationTypeEnum() {
- return " /**\n" +
- " * Specify the node specific operation in protocols " +
- "like NETCONF.\n" +
- " * Applicable in protocol edit operation, not applicable" +
- " in query operation\n" +
- " */\n" +
- " public static enum OnosYangOpType {\n" +
- " MERGE,\n" +
- " REPLACE,\n" +
- " CREATE,\n" +
- " DELETE,\n" +
- " REMOVE,\n" +
- " NONE\n" +
- " }\n";
- }
-
- /**
- * Returns attribute in constructor for yang augmented info map.
- *
- * @return augment info map
- */
- static String getYangAugmentedMapObjectForConstruct() {
- return " this.yangAugmentedInfoMap = builderObject" +
- ".yangAugmentedInfoMap();\n";
- }
-
- /**
* Returns set value parameter for union class.
*
* @return set value parameter for union class.
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaExtendsListHolder.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaExtendsListHolder.java
index 2ae1905..ce22cda 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaExtendsListHolder.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaExtendsListHolder.java
@@ -74,13 +74,15 @@
*/
public void addToExtendsList(JavaQualifiedTypeInfoTranslator info, YangNode node,
TempJavaFragmentFiles tempJavaFragmentFiles) {
- JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
+
+ JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) node)
+ .getJavaFileInfo();
JavaImportData importData = tempJavaFragmentFiles.getJavaImportData();
- boolean qualified = importData.addImportInfo(info,
- getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
-
- /*true means import should be added*/
+ boolean qualified = importData
+ .addImportInfo(info, getCapitalCase(fileInfo.getJavaName()),
+ fileInfo.getPackage());
+ /*true means import should be added*/
getExtendedClassStore().put(info, qualified);
addToExtendsList(info);
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGenerator.java
index 546ed05..b9c609e 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGenerator.java
@@ -17,8 +17,6 @@
package org.onosproject.yang.compiler.translator.tojava.utils;
import org.onosproject.yang.compiler.datamodel.RpcNotificationContainer;
-import org.onosproject.yang.compiler.datamodel.YangAugmentableNode;
-import org.onosproject.yang.compiler.datamodel.YangChoice;
import org.onosproject.yang.compiler.datamodel.YangEnumeration;
import org.onosproject.yang.compiler.datamodel.YangLeavesHolder;
import org.onosproject.yang.compiler.datamodel.YangNode;
@@ -78,9 +76,7 @@
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
-import static org.onosproject.yang.compiler.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget;
import static org.onosproject.yang.compiler.translator.tojava.TempJavaFragmentFiles.getListOfAttributesForKey;
-import static org.onosproject.yang.compiler.translator.tojava.YangJavaModelUtils.isGetSetOfRootNodeRequired;
import static org.onosproject.yang.compiler.translator.tojava.utils.IndentationType.FOUR_SPACE;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaCodeSnippetGen.addStaticAttributeIntRange;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaCodeSnippetGen.addStaticAttributeLongRange;
@@ -88,17 +84,15 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition;
-import static org.onosproject.yang.compiler.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeEnum;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaCodeSnippetGen.getSetValueParaForUnionClass;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodBodyTypes.ENUM_METHOD_INT_VALUE;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodBodyTypes.ENUM_METHOD_STRING_VALUE;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.builderMethod;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.generateBuildMethodForSubTree;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodInterface;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForService;
+import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getAddAugmentationString;
+import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getAugmentationString;
+import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getAugmentationsString;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getBitSetEnumClassFromString;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getBitSetEnumClassToString;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getCompareToForKeyClass;
@@ -112,39 +106,24 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getGetter;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getGetterForClass;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getGetterString;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getInterfaceLeafIdEnumSignature;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getRangeValidatorMethodForUnion;
+import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationString;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getSetterForClass;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getSetterForSelectLeaf;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getToStringForEnumClass;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getToStringForType;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getUnionToStringMethod;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoImpl;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoInterface;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.isLeafValueSetInterface;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.isSelectLeafSetInterface;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.setSelectLeafSetInterface;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getImportString;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getInterfaceLeafIdEnumMethods;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getIsSelectLeafSet;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getIsValueLeafSet;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.methodClose;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.signatureClose;
-import static org.onosproject.yang.compiler.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getAugmentableSubTreeFiltering;
-import static org.onosproject.yang.compiler.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessChildNodeSubtreeFiltering;
-import static org.onosproject.yang.compiler.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessLeafListSubtreeFiltering;
-import static org.onosproject.yang.compiler.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessLeafSubtreeFiltering;
-import static org.onosproject.yang.compiler.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubTreeFilteringEnd;
-import static org.onosproject.yang.compiler.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubTreeForChoiceInterface;
-import static org.onosproject.yang.compiler.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubtreeFilteringStart;
-import static org.onosproject.yang.compiler.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubtreeFunctionBody;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorUtils.addDefaultConstructor;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorUtils.getBeanFiles;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorUtils.getTypeFiles;
@@ -238,18 +217,8 @@
initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode,
className);
- // Generate ENUM interface
- if (curNode instanceof RpcNotificationContainer) {
- insertDataIntoJavaFile(file, getOperationTypeEnum());
- }
List<String> methods = new ArrayList<>();
- //Add only for choice class
- if (curNode instanceof YangChoice) {
- insertDataIntoJavaFile(file, getProcessSubTreeForChoiceInterface(
- curNode));
- }
-
if (attrPresent) {
// Add getter methods to interface file.
try {
@@ -273,16 +242,8 @@
}
}
- if (curNode instanceof YangAugmentableNode &&
- !(curNode instanceof YangChoice)) {
- methods.add(getYangAugmentInfoInterface());
- }
-
if (leavesPresent) {
methods.add(isLeafValueSetInterface());
- if (curNode.isOpTypeReq()) {
- methods.add(isSelectLeafSetInterface());
- }
}
for (String method : methods) {
insertDataIntoJavaFile(file, method);
@@ -349,15 +310,6 @@
}
}
- if (curNode instanceof YangAugmentableNode &&
- !(curNode instanceof YangChoice)) {
- methods.add(getAddAugmentInfoMethodInterface(className + BUILDER));
- methods.add(getYangAugmentInfoInterface());
- }
-
- if (leavesPresent) {
- methods.add(setSelectLeafSetInterface(className));
- }
//Add build method to builder interface file.
methods.add(((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles()
@@ -432,12 +384,6 @@
ADD_TO_LIST_IMPL_MASK, getBeanFiles(curNode), path));
insertDataIntoJavaFile(file, NEW_LINE);
-
- //Add operation attribute methods.
- if (leavesPresent && curNode.isOpTypeReq()) {
- insertDataIntoJavaFile(file, NEW_LINE);
- methods.add(getSetterForSelectLeaf(className));
- }
} catch (IOException e) {
throw new IOException(getErrorMsg(className, BUILDER_CLASS));
}
@@ -445,18 +391,11 @@
insertDataIntoJavaFile(file, NEW_LINE);
}
- if (curNode instanceof YangAugmentableNode) {
- methods.add(getAddAugmentInfoMethodImpl(className + BUILDER));
- methods.add(getYangAugmentInfoImpl());
- }
-
// Add default constructor and build method impl.
methods.add(((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles()
.addBuildMethodImpl());
- if (curNode.isOpTypeReq()) {
- methods.add(generateBuildMethodForSubTree(curNode));
- }
+
methods.add(addDefaultConstructor(curNode, PUBLIC, BUILDER));
//Add methods in builder class.
@@ -618,9 +557,6 @@
insertDataIntoJavaFile(file, NEW_LINE);
}
- if (curNode instanceof YangAugmentableNode) {
- methods.add(getYangAugmentInfoImpl());
- }
try {
//Constructor.
String constructor = getConstructorStart(className, rootNode) +
@@ -628,35 +564,6 @@
CONSTRUCTOR_IMPL_MASK, getBeanFiles(curNode), path)
+ methodClose(FOUR_SPACE);
methods.add(constructor);
- if (curNode.isOpTypeReq()) {
- String augmentableSubTreeFiltering = EMPTY_STRING;
- if (curNode instanceof YangAugmentableNode) {
- // add is filter content match.
- augmentableSubTreeFiltering = getAugmentableSubTreeFiltering();
- }
- methods.add(getProcessSubtreeFilteringStart(curNode) +
- getProcessSubtreeFunctionBody(curNode) +
- augmentableSubTreeFiltering +
- getProcessSubTreeFilteringEnd(name));
-
- if (curNode instanceof YangLeavesHolder) {
- if (((YangLeavesHolder) curNode).getListOfLeaf() != null &&
- !((YangLeavesHolder) curNode).getListOfLeaf().isEmpty()) {
- methods.add(getProcessLeafSubtreeFiltering(curNode,
- path));
- }
- if (((YangLeavesHolder) curNode).getListOfLeafList() != null &&
- !((YangLeavesHolder) curNode).getListOfLeafList().isEmpty()) {
- methods.add(getProcessLeafListSubtreeFiltering(curNode,
- path));
- }
- }
-
- if (curNode.getChild() != null) {
- methods.add(getProcessChildNodeSubtreeFiltering(curNode,
- path));
- }
- }
} catch (IOException e) {
throw new IOException(getErrorMsg(className, IMPL_CLASS));
}
@@ -666,10 +573,15 @@
methods.add(builderMethod(className));
if (leavesPresent) {
methods.add(getIsValueLeafSet());
- if (curNode.isOpTypeReq()) {
- methods.add(getIsSelectLeafSet());
- }
}
+
+ if (curNode instanceof RpcNotificationContainer) {
+ methods.add(getAddAugmentationString());
+ methods.add(getRemoveAugmentationString());
+ methods.add(getAugmentationsString());
+ methods.add(getAugmentationString());
+ }
+
// Add methods in impl class.
for (String method : methods) {
insertDataIntoJavaFile(file, method);
@@ -1129,25 +1041,8 @@
curNode, className);
List<String> methods = new ArrayList<>();
- JavaAttributeInfo rootAttribute =
- getCurNodeAsAttributeInTarget(curNode, curNode, false,
- tempFiles);
try {
-
- if (isGetSetOfRootNodeRequired(curNode)) {
- //Getter methods.
- methods.add(getGetterString(rootAttribute,
- GENERATE_SERVICE_AND_MANAGER) +
- NEW_LINE);
- // Setter methods.
- methods.add(getSetterString(rootAttribute, className,
- GENERATE_SERVICE_AND_MANAGER) +
- NEW_LINE);
- }
-
- methods.add(getAugmentsDataMethodForService(curNode));
-
if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles()
.getServiceTempFiles() != null) {
JavaCodeGeneratorInfo javaGenInfo =
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGeneratorUtils.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGeneratorUtils.java
index 81c7cb1..6c1ac6b 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGeneratorUtils.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGeneratorUtils.java
@@ -71,9 +71,6 @@
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK;
-import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
-import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
-import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
@@ -210,21 +207,6 @@
tempHandle.getAddToListImplTempFileHandle(),
path);
}
- if ((tempFiles & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getSubtreeFilteringForLeafTempFileHandle(),
- path);
- }
- if ((tempFiles & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getGetSubtreeFilteringForListTempFileHandle(),
- path);
- }
- if ((tempFiles & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getGetSubtreeFilteringForChildNodeTempFileHandle(),
- path);
- }
if ((tempFiles & EDIT_CONTENT_MASK) != 0) {
return tempHandle.getTemporaryDataFromFileHandle(
tempHandle.getEditContentTempFileHandle(),
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodBodyTypes.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodBodyTypes.java
index a5fcef3..2622809 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodBodyTypes.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodBodyTypes.java
@@ -48,15 +48,6 @@
//add to list method body.
ADD_TO_LIST,
- //Augment map getter for full map.
- AUGMENTED_MAP_GETTER,
-
- //Augment map getter for value.
- AUGMENTED_MAP_GET_VALUE,
-
- //Augment map add
- AUGMENTED_MAP_ADD,
-
//Manager methods
MANAGER_METHODS,
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java
index 81e86a7..e25971f 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java
@@ -17,7 +17,6 @@
package org.onosproject.yang.compiler.translator.tojava.utils;
import org.onosproject.yang.compiler.datamodel.InvalidOpTypeHolder;
-import org.onosproject.yang.compiler.datamodel.RpcNotificationContainer;
import org.onosproject.yang.compiler.datamodel.YangAppDataStructure;
import org.onosproject.yang.compiler.datamodel.YangAtomicPath;
import org.onosproject.yang.compiler.datamodel.YangCompilerAnnotation;
@@ -52,8 +51,6 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getCurNodeName;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodBodyTypes.AUGMENTED_MAP_ADD;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodBodyTypes.AUGMENTED_MAP_GET_VALUE;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodBodyTypes.GETTER;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodBodyTypes.MANAGER_METHODS;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodBodyTypes.SETTER;
@@ -96,10 +93,13 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.multiAttrMethodSignature;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.signatureClose;
import static org.onosproject.yang.compiler.utils.UtilConstants.ADD;
+import static org.onosproject.yang.compiler.utils.UtilConstants.ADD_AUGMENTATION;
import static org.onosproject.yang.compiler.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.AND;
import static org.onosproject.yang.compiler.utils.UtilConstants.APPEND;
import static org.onosproject.yang.compiler.utils.UtilConstants.ARRAY_LIST_INIT;
+import static org.onosproject.yang.compiler.utils.UtilConstants.AUGMENTATION;
+import static org.onosproject.yang.compiler.utils.UtilConstants.AUGMENTATIONS;
import static org.onosproject.yang.compiler.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yang.compiler.utils.UtilConstants.BASE64;
import static org.onosproject.yang.compiler.utils.UtilConstants.BIG_INTEGER;
@@ -109,7 +109,7 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.BUILD;
import static org.onosproject.yang.compiler.utils.UtilConstants.BUILDER;
import static org.onosproject.yang.compiler.utils.UtilConstants.BUILDER_LOWER_CASE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.BUILD_FOR_FILTER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CAMEL_CLASS;
import static org.onosproject.yang.compiler.utils.UtilConstants.CASE;
import static org.onosproject.yang.compiler.utils.UtilConstants.CLASS;
import static org.onosproject.yang.compiler.utils.UtilConstants.CLASS_STRING;
@@ -148,15 +148,17 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.INSTANCE_OF;
import static org.onosproject.yang.compiler.utils.UtilConstants.INT;
import static org.onosproject.yang.compiler.utils.UtilConstants.IS_EMPTY;
-import static org.onosproject.yang.compiler.utils.UtilConstants.IS_SELECT_LEAF;
import static org.onosproject.yang.compiler.utils.UtilConstants.KEYS;
import static org.onosproject.yang.compiler.utils.UtilConstants.LEAF;
import static org.onosproject.yang.compiler.utils.UtilConstants.LEAF_IDENTIFIER;
+import static org.onosproject.yang.compiler.utils.UtilConstants.LEFT_ANGULAR_BRACKET;
import static org.onosproject.yang.compiler.utils.UtilConstants.LINKED_HASH_MAP;
import static org.onosproject.yang.compiler.utils.UtilConstants.LINKED_HASH_SET;
import static org.onosproject.yang.compiler.utils.UtilConstants.LONG;
+import static org.onosproject.yang.compiler.utils.UtilConstants.MAP;
import static org.onosproject.yang.compiler.utils.UtilConstants.MAX_RANGE;
import static org.onosproject.yang.compiler.utils.UtilConstants.MIN_RANGE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.MODEL_OBJECT;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEG_ONE;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
@@ -178,19 +180,18 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
import static org.onosproject.yang.compiler.utils.UtilConstants.PRIORITY_QUEUE;
import static org.onosproject.yang.compiler.utils.UtilConstants.PRIVATE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.PROCESS_SUBTREE_FILTERING;
import static org.onosproject.yang.compiler.utils.UtilConstants.PROTECTED;
import static org.onosproject.yang.compiler.utils.UtilConstants.PUBLIC;
import static org.onosproject.yang.compiler.utils.UtilConstants.PUT;
import static org.onosproject.yang.compiler.utils.UtilConstants.QUESTION_MARK;
import static org.onosproject.yang.compiler.utils.UtilConstants.QUOTES;
+import static org.onosproject.yang.compiler.utils.UtilConstants.REMOVE_AUGMENTATION;
import static org.onosproject.yang.compiler.utils.UtilConstants.RETURN;
+import static org.onosproject.yang.compiler.utils.UtilConstants.RIGHT_ANGULAR_BRACKET;
import static org.onosproject.yang.compiler.utils.UtilConstants.RPC_INPUT_VAR_NAME;
import static org.onosproject.yang.compiler.utils.UtilConstants.SCHEMA_NAME;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SELECT_ALL_CHILD;
import static org.onosproject.yang.compiler.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yang.compiler.utils.UtilConstants.SET_METHOD_PREFIX;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SET_SELECT_LEAF;
import static org.onosproject.yang.compiler.utils.UtilConstants.SET_VALUE_PARA;
import static org.onosproject.yang.compiler.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
import static org.onosproject.yang.compiler.utils.UtilConstants.SPACE;
@@ -199,9 +200,9 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.STATIC;
import static org.onosproject.yang.compiler.utils.UtilConstants.STRING_BUILDER_VAR;
import static org.onosproject.yang.compiler.utils.UtilConstants.STRING_DATA_TYPE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SUBTREE_FILTERED;
import static org.onosproject.yang.compiler.utils.UtilConstants.SUFFIX_S;
import static org.onosproject.yang.compiler.utils.UtilConstants.SWITCH;
+import static org.onosproject.yang.compiler.utils.UtilConstants.TEMPLATE_T;
import static org.onosproject.yang.compiler.utils.UtilConstants.THIS;
import static org.onosproject.yang.compiler.utils.UtilConstants.TMP_VAL;
import static org.onosproject.yang.compiler.utils.UtilConstants.TO_CAPS;
@@ -214,9 +215,8 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE_CAPS;
import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE_LEAF;
import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE_LEAF_SET;
+import static org.onosproject.yang.compiler.utils.UtilConstants.VARIABLE_C;
import static org.onosproject.yang.compiler.utils.UtilConstants.VOID;
-import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_AUGMENTED_INFO;
-import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
import static org.onosproject.yang.compiler.utils.UtilConstants.ZERO;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
@@ -227,9 +227,7 @@
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
-import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.generateForAddAugmentation;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.generateForBuilderMethod;
-import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.generateForGetAugmentation;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.generateForGetMethodWithAttribute;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.generateForValidatorMethod;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.getJavaDoc;
@@ -371,6 +369,46 @@
}
/**
+ * Returns add augmentation method string.
+ *
+ * @return add augmentation string
+ */
+ public static String getAddAugmentationString() {
+ return getOverRideString() +
+ getAddAugmentation();
+ }
+
+ /**
+ * Returns remove augmentation method string.
+ *
+ * @return remove augmentation string
+ */
+ public static String getRemoveAugmentationString() {
+ return getOverRideString() +
+ getRemoveAugmentation();
+ }
+
+ /**
+ * Returns augmentations method string.
+ *
+ * @return augmentations string
+ */
+ public static String getAugmentationsString() {
+ return getOverRideString() +
+ getAugmentations();
+ }
+
+ /**
+ * Returns augmentation method string.
+ *
+ * @return augmentation string
+ */
+ public static String getAugmentationString() {
+ return getOverRideString() +
+ getAugmentation();
+ }
+
+ /**
* Returns the getter method strings for class file.
*
* @param attr attribute info
@@ -761,6 +799,62 @@
}
/**
+ * Returns the add augmentation strings for class file.
+ *
+ * @return add augmentation method for class
+ */
+ private static String getAddAugmentation() {
+ return methodSignature(ADD_AUGMENTATION, EMPTY_STRING, PUBLIC, OBJ,
+ VOID, MODEL_OBJECT, CLASS_TYPE) +
+ methodClose(FOUR_SPACE);
+ }
+
+ /**
+ * Returns the remove augmentation strings for class file.
+ *
+ * @return remove augmentation method for class
+ */
+ private static String getRemoveAugmentation() {
+ return methodSignature(REMOVE_AUGMENTATION, EMPTY_STRING, PUBLIC,
+ OBJ, VOID, MODEL_OBJECT, CLASS_TYPE) +
+ methodClose(FOUR_SPACE);
+ }
+
+ /**
+ * Returns the augmentations method for class file.
+ *
+ * @return augmentations method for class
+ */
+ private static String getAugmentations() {
+ String methodReturnType = MAP + LEFT_ANGULAR_BRACKET + CAMEL_CLASS +
+ LEFT_ANGULAR_BRACKET + QUESTION_MARK + SPACE + EXTEND +
+ SPACE + MODEL_OBJECT + RIGHT_ANGULAR_BRACKET + COMMA +
+ SPACE + MODEL_OBJECT + RIGHT_ANGULAR_BRACKET;
+ return methodSignature(AUGMENTATIONS, EMPTY_STRING, PUBLIC, null,
+ methodReturnType, null, CLASS_TYPE) + NEW_LINE +
+ getReturnString(NULL, EIGHT_SPACE_INDENTATION) + SEMI_COLON +
+ NEW_LINE + methodClose(FOUR_SPACE);
+ }
+
+ /**
+ * Returns the augmentation strings for class file.
+ *
+ * @return augmentation method for class
+ */
+ private static String getAugmentation() {
+ String methodReturnType = LEFT_ANGULAR_BRACKET + TEMPLATE_T + SPACE +
+ EXTEND + SPACE + MODEL_OBJECT + RIGHT_ANGULAR_BRACKET + SPACE +
+ TEMPLATE_T;
+ String paraReturntype = CAMEL_CLASS + LEFT_ANGULAR_BRACKET + TEMPLATE_T +
+ RIGHT_ANGULAR_BRACKET;
+ return methodSignature(AUGMENTATION, EMPTY_STRING, PUBLIC, VARIABLE_C,
+ methodReturnType,
+ paraReturntype, CLASS_TYPE) + NEW_LINE +
+ getReturnString(NULL, EIGHT_SPACE_INDENTATION) + SEMI_COLON +
+ NEW_LINE + methodClose(FOUR_SPACE);
+ }
+
+ /**
* Returns to string method's open strings.
*
* @return string method's open string
@@ -1185,72 +1279,6 @@
}
/**
- * Returns interface of add augmentation.
- *
- * @param className class name
- * @return interface of add augmentation
- */
- static String getAddAugmentInfoMethodInterface(String className) {
- StringBuilder builder = new StringBuilder(generateForAddAugmentation(className));
- LinkedHashMap<String, String> map = new LinkedHashMap<>();
- map.put(VALUE, OBJECT_STRING);
- map.put(CLASS + OBJECT_STRING, CLASS_STRING);
- builder.append(multiAttrMethodSignature(ADD_STRING + YANG_AUGMENTED_INFO,
- null, null, className, map,
- INTERFACE_TYPE));
- return builder.toString();
- }
-
- /**
- * Returns implementation of add augmentation.
- *
- * @param className class name
- * @return implementation of add augmentation
- */
- static String getAddAugmentInfoMethodImpl(String className) {
- StringBuilder builder = new StringBuilder(getOverRideString());
- LinkedHashMap<String, String> map = new LinkedHashMap<>();
- map.put(VALUE, OBJECT_STRING);
- map.put(CLASS + OBJECT_STRING, CLASS_STRING);
- builder.append(multiAttrMethodSignature(ADD_STRING + YANG_AUGMENTED_INFO,
- null, PUBLIC,
- className, map, CLASS_TYPE))
- .append(methodBody(AUGMENTED_MAP_ADD, null, null,
- EIGHT_SPACE_INDENTATION, null, null, false, null))
- .append(getReturnString(THIS, EIGHT_SPACE_INDENTATION))
- .append(signatureClose())
- .append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
-
- /**
- * Returns interface of get YANG augment info.
- *
- * @return interface of get YANG augment info
- */
- static String getYangAugmentInfoInterface() {
- return generateForGetAugmentation() +
- methodSignature(YANG_AUGMENTED_INFO_LOWER_CASE, EMPTY_STRING,
- null, CLASS + OBJECT_STRING,
- OBJECT_STRING, CLASS_STRING, INTERFACE_TYPE);
- }
-
- /**
- * Returns implementation of get YANG augment info.
- *
- * @return implementation of get YANG augment info
- */
- static String getYangAugmentInfoImpl() {
- return getOverRideString() +
- methodSignature(YANG_AUGMENTED_INFO_LOWER_CASE, EMPTY_STRING,
- PUBLIC, CLASS + OBJECT_STRING, OBJECT_STRING,
- CLASS_STRING, CLASS_TYPE) +
- methodBody(AUGMENTED_MAP_GET_VALUE, null, null,
- EIGHT_SPACE_INDENTATION, null, null, false, null) +
- methodClose(FOUR_SPACE);
- }
-
- /**
* Returns enum's constructor.
*
* @param className enum's class name
@@ -1671,42 +1699,6 @@
}
/**
- * Returns is select leaf set interface.
- *
- * @return is select leaf set interface
- */
- static String isSelectLeafSetInterface() {
- String method = "\n /**\n" +
- " * Checks if the leaf is set to be a selected leaf.\n" +
- " *\n" +
- " * @param leaf if leaf needs to be selected\n" +
- " * @return result of leaf value set in object\n" +
- " */\n";
- return method + methodSignature(IS_SELECT_LEAF, EMPTY_STRING, null,
- LEAF, BOOLEAN_DATA_TYPE, LEAF_IDENTIFIER,
- INTERFACE_TYPE);
- }
-
- /**
- * Returns set select leaf set interface.
- *
- * @param name node name
- * @return set select leaf set interface
- */
- static String setSelectLeafSetInterface(String name) {
- String method = " /**\n" +
- " * Set a leaf to be selected.\n" +
- " *\n" +
- " * @param leaf leaf needs to be selected\n" +
- " * @return builder object for select leaf\n" +
- " */\n";
- return method + methodSignature(SET_SELECT_LEAF, EMPTY_STRING,
- null, LEAF, name +
- BUILDER, LEAF_IDENTIFIER,
- INTERFACE_TYPE) + NEW_LINE;
- }
-
- /**
* Returns leaf identifier interface enum signature.
*
* @param name name of node
@@ -1721,22 +1713,6 @@
}
/**
- * Returns setter for select leaf.
- *
- * @param name name of node
- * @return setter for select leaf
- */
- static String getSetterForSelectLeaf(String name) {
- return "\n" +
- " " + OVERRIDE + "\n" +
- " public " + name + BUILDER +
- " selectLeaf(LeafIdentifier leaf) {\n" +
- " selectLeafFlags.set(leaf.getLeafIndex());\n" +
- " return this;\n" +
- " }\n";
- }
-
- /**
* Generates fromString code for bits.
*
* @return generated fromString code for bits.
@@ -1966,57 +1942,6 @@
}
/**
- * Returns is filter content match interface.
- *
- * @param name name of node
- * @return is filter content match interface
- */
- static String processSubtreeFilteringInterface(String name) {
- String method = " /**\n" +
- " * Checks if the passed " + name +
- " maps the content match query condition.\n" +
- " *\n" +
- " * @param " + getSmallCase(name) + SPACE +
- getSmallCase(name) + SPACE + "being passed to check" +
- " for" +
- " content match\n" +
- " * @param isSelectAllSchemaChild is select all schema child\n" +
- " * @return match result\n" +
- " */\n";
- LinkedHashMap<String, String> map = new LinkedHashMap<>();
- map.put(getSmallCase(name), name);
- map.put(SELECT_ALL_CHILD, BOOLEAN_DATA_TYPE);
-
- return method + multiAttrMethodSignature(PROCESS_SUBTREE_FILTERING,
- EMPTY_STRING, EMPTY_STRING,
- name, map, INTERFACE_TYPE);
- }
-
- /**
- * Returns build method for subtree filtering in class.
- *
- * @param node YANG node
- * @return build method for subtree filtering in class
- */
- static String generateBuildMethodForSubTree(YangNode node) {
- String name = getCapitalCase(node.getJavaClassNameOrBuiltInType());
- StringBuilder builder = new StringBuilder(getJavaDoc(BUILD_METHOD,
- name, false, null));
- String def = DEFAULT_CAPS + name;
- if (node instanceof RpcNotificationContainer) {
- def = name + OP_PARAM;
- }
- builder.append(methodSignature(BUILD_FOR_FILTER, null, PUBLIC, null,
- name, null, CLASS_TYPE))
- .append(EIGHT_SPACE_INDENTATION).append(SUBTREE_FILTERED)
- .append(SPACE).append(EQUAL).append(SPACE).append(TRUE)
- .append(signatureClose()).append(methodBody(
- MethodBodyTypes.BUILD, def, null, EIGHT_SPACE_INDENTATION,
- null, null, false, null)).append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
-
- /**
* To string method for identity.
*
* @param name name of identity
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java
index 2befdde..d381805 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java
@@ -106,7 +106,6 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yang.compiler.utils.UtilConstants.OBJECT;
-import static org.onosproject.yang.compiler.utils.UtilConstants.OBJECT_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.OF;
import static org.onosproject.yang.compiler.utils.UtilConstants.OMIT_NULL_VALUE_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
@@ -120,7 +119,6 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.PARSE_SHORT;
import static org.onosproject.yang.compiler.utils.UtilConstants.PATTERN;
import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
-import static org.onosproject.yang.compiler.utils.UtilConstants.PUT;
import static org.onosproject.yang.compiler.utils.UtilConstants.QUEUE;
import static org.onosproject.yang.compiler.utils.UtilConstants.QUOTES;
import static org.onosproject.yang.compiler.utils.UtilConstants.QUOTE_STRING;
@@ -151,7 +149,6 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.ULONG_MIN_RANGE;
import static org.onosproject.yang.compiler.utils.UtilConstants.VALIDATE_RANGE;
import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_AUGMENTED_INFO_MAP;
import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_UTILS_TODO;
import static org.onosproject.yang.compiler.utils.UtilConstants.ZERO;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCamelCase;
@@ -348,18 +345,6 @@
signatureClose();
case DEFAULT_CONSTRUCTOR:
return EMPTY_STRING;
- case AUGMENTED_MAP_ADD:
- return space + YANG_AUGMENTED_INFO_MAP +
- PERIOD + PUT + OPEN_PARENTHESIS + CLASS +
- OBJECT_STRING + COMMA + SPACE + VALUE +
- CLOSE_PARENTHESIS + signatureClose();
- case AUGMENTED_MAP_GET_VALUE:
- return getReturnString(
- YANG_AUGMENTED_INFO_MAP + PERIOD + GET + getOpenCloseParaWithValue(
- CLASS + OBJECT_STRING) + signatureClose(), space);
- case AUGMENTED_MAP_GETTER:
- return getReturnString(YANG_AUGMENTED_INFO_MAP +
- signatureClose(), space);
case MANAGER_METHODS:
body = space + YANG_UTILS_TODO + NEW_LINE;
builder.append(body);
@@ -649,53 +634,6 @@
}
/**
- * Returns is select leaf set.
- *
- * @return is select leaf set
- */
- static String getIsSelectLeafSet() {
- return " @Override\n" +
- " public boolean isSelectLeaf(LeafIdentifier leaf) {\n" +
- " return selectLeafFlags.get(leaf.getLeafIndex());\n" +
- " }\n";
- }
-
- /**
- * Returns getter methods for operation attributes.
- *
- * @return getter methods for operation attributes
- */
- static String getValueLeafGetters() {
- return "\n" +
- " /**\n" +
- " * Returns the valueLeafFlags.\n" +
- " *\n" +
- " * @return value of valueLeafFlags\n" +
- " */\n" +
- " public BitSet getValueLeafFlags() {\n" +
- " return valueLeafFlags;\n" +
- " }\n" +
- "\n";
- }
-
- /**
- * Returns getter methods for operation attributes.
- *
- * @return getter methods for operation attributes
- */
- static String getSelectLeafGetters() {
- return " /**\n" +
- " * Returns the selectLeafFlags.\n" +
- " *\n" +
- " * @return value of selectLeafFlags\n" +
- " */\n" +
- " public BitSet getSelectLeafFlags() {\n" +
- " return selectLeafFlags;\n" +
- " }\n" +
- "\n";
- }
-
- /**
* Returns interface leaf identifier enum method.
*
* @return interface leaf identifier enum method
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
deleted file mode 100644
index 51f236d..0000000
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
+++ /dev/null
@@ -1,1238 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yang.compiler.translator.tojava.utils;
-
-import org.onosproject.yang.compiler.datamodel.RpcNotificationContainer;
-import org.onosproject.yang.compiler.datamodel.YangAugment;
-import org.onosproject.yang.compiler.datamodel.YangCase;
-import org.onosproject.yang.compiler.datamodel.YangChoice;
-import org.onosproject.yang.compiler.datamodel.YangDataStructure;
-import org.onosproject.yang.compiler.datamodel.YangLeafRef;
-import org.onosproject.yang.compiler.datamodel.YangLeavesHolder;
-import org.onosproject.yang.compiler.datamodel.YangNode;
-import org.onosproject.yang.compiler.datamodel.YangType;
-import org.onosproject.yang.compiler.translator.exception.TranslatorException;
-import org.onosproject.yang.compiler.translator.tojava.JavaAttributeInfo;
-import org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yang.compiler.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yang.compiler.translator.tojava.JavaFileInfoTranslator;
-
-import java.io.IOException;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
-import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
-import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
-import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
-import static org.onosproject.yang.compiler.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
-import static org.onosproject.yang.compiler.translator.tojava.utils.IndentationType.EIGHT_SPACE;
-import static org.onosproject.yang.compiler.translator.tojava.utils.IndentationType.FOUR_SPACE;
-import static org.onosproject.yang.compiler.translator.tojava.utils.IndentationType.SIXTEEN_SPACE;
-import static org.onosproject.yang.compiler.translator.tojava.utils.IndentationType.TWELVE_SPACE;
-import static org.onosproject.yang.compiler.translator.tojava.utils.IndentationType.TWENTY_EIGHT_SPACE;
-import static org.onosproject.yang.compiler.translator.tojava.utils.IndentationType.TWENTY_FOUR_SPACE;
-import static org.onosproject.yang.compiler.translator.tojava.utils.IndentationType.TWENTY_SPACE;
-import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getYangDataStructure;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getAppInstanceAttrString;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getElseIfConditionBegin;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getEqualEqualString;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getForLoopString;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getIfConditionBegin;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getLeafFlagSetString;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getNewInstance;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getOpenCloseParaWithValue;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getReturnString;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getTwoParaEqualsString;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.methodClose;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.multiAttrMethodSignature;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.signatureClose;
-import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorUtils.getBeanFiles;
-import static org.onosproject.yang.compiler.utils.UtilConstants.ADD_STRING;
-import static org.onosproject.yang.compiler.utils.UtilConstants.AND_OPERATION;
-import static org.onosproject.yang.compiler.utils.UtilConstants.APP_INSTANCE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.BIT_SET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.BOOLEAN_DATA_TYPE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.BREAK;
-import static org.onosproject.yang.compiler.utils.UtilConstants.BUILDER;
-import static org.onosproject.yang.compiler.utils.UtilConstants.BUILDER_LOWER_CASE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.BUILD_FOR_FILTER;
-import static org.onosproject.yang.compiler.utils.UtilConstants.CLASS_STRING;
-import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_CURLY_BRACKET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_PARENTHESIS;
-import static org.onosproject.yang.compiler.utils.UtilConstants.COMMA;
-import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT;
-import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT_CAPS;
-import static org.onosproject.yang.compiler.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
-import static org.onosproject.yang.compiler.utils.UtilConstants.ELSE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yang.compiler.utils.UtilConstants.ENTRY;
-import static org.onosproject.yang.compiler.utils.UtilConstants.ENTRY_SET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.EQUAL;
-import static org.onosproject.yang.compiler.utils.UtilConstants.EQUALS_STRING;
-import static org.onosproject.yang.compiler.utils.UtilConstants.EXTEND;
-import static org.onosproject.yang.compiler.utils.UtilConstants.FALSE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.FLAG;
-import static org.onosproject.yang.compiler.utils.UtilConstants.GET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.GET_KEY;
-import static org.onosproject.yang.compiler.utils.UtilConstants.GET_VALUE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.INSTANCE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG;
-import static org.onosproject.yang.compiler.utils.UtilConstants.IS_EMPTY;
-import static org.onosproject.yang.compiler.utils.UtilConstants.IS_SELECT_ALL_SCHEMA_CHILD_FLAG;
-import static org.onosproject.yang.compiler.utils.UtilConstants.KEYS;
-import static org.onosproject.yang.compiler.utils.UtilConstants.LEAF_IDENTIFIER;
-import static org.onosproject.yang.compiler.utils.UtilConstants.MAP;
-import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.NOT;
-import static org.onosproject.yang.compiler.utils.UtilConstants.NULL;
-import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
-import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_CURLY_BRACKET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_PARENTHESIS;
-import static org.onosproject.yang.compiler.utils.UtilConstants.OP_PARAM;
-import static org.onosproject.yang.compiler.utils.UtilConstants.OR_OPERATION;
-import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
-import static org.onosproject.yang.compiler.utils.UtilConstants.PRIVATE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.PROCESS_CHILD_NODE_STF_PARAM;
-import static org.onosproject.yang.compiler.utils.UtilConstants.PROCESS_LEAF_LIST_STF_PARAM;
-import static org.onosproject.yang.compiler.utils.UtilConstants.PROCESS_LEAF_STF_PARAM;
-import static org.onosproject.yang.compiler.utils.UtilConstants.PROCESS_SUBTREE_FILTERING;
-import static org.onosproject.yang.compiler.utils.UtilConstants.PUBLIC;
-import static org.onosproject.yang.compiler.utils.UtilConstants.QUESTION_MARK;
-import static org.onosproject.yang.compiler.utils.UtilConstants.RESULT;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SELECT_ALL_CHILD;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SELECT_ALL_CHILD_SCHEMA_PARAM;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SELECT_LEAF;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SELECT_OR_CONTAINMENT_NODE_PARAM;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SEMI_COLON;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SET_METHOD_PREFIX;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SPACE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.STF_BUILDER_PARAM;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SUBTREE_FILTERED;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SUBTREE_FILTERING_RESULT_BUILDER;
-import static org.onosproject.yang.compiler.utils.UtilConstants.THIRTY_TWO_SPACE_INDENTATION;
-import static org.onosproject.yang.compiler.utils.UtilConstants.TO;
-import static org.onosproject.yang.compiler.utils.UtilConstants.TRUE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
-import static org.onosproject.yang.compiler.utils.UtilConstants.TWENTY_EIGHT_SPACE_INDENTATION;
-import static org.onosproject.yang.compiler.utils.UtilConstants.TWENTY_FOUR_SPACE_INDENTATION;
-import static org.onosproject.yang.compiler.utils.UtilConstants.TWENTY_SPACE_INDENTATION;
-import static org.onosproject.yang.compiler.utils.UtilConstants.TWO;
-import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE_LEAF;
-import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE_LEAF_SET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.ZERO;
-import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCamelCase;
-import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCapitalCase;
-
-/**
- * Represents generator for subtree filtering methods of generated files
- * based on the file type.
- */
-public final class SubtreeFilteringMethodsGenerator {
-
- /**
- * private to make it a util.
- */
- private SubtreeFilteringMethodsGenerator() {
- }
-
- /**
- * Returns process sub tree for choice interface class.
- *
- * @param node choice node
- * @return process sub tree for choice interface class
- */
- static String getProcessSubTreeForChoiceInterface(YangNode node) {
- if (!(node instanceof YangChoice)) {
- throw new TranslatorException("process sub tree for interface is " +
- "only allowed in choice " +
- "node.");
- }
- JavaFileInfoTranslator info = ((JavaCodeGeneratorInfo) node)
- .getJavaFileInfo();
-
- String name = info.getJavaName();
- String returnType = getCapitalCase(name);
-
- String javadoc = "\n /**\n" +
- " * Applications need not to implement process subtree " +
- "of " + name + "\n * it will be overridden by " +
- "corresponding case class.\n" +
- " *\n" +
- " * @param " + APP_INSTANCE + SPACE +
- APP_INSTANCE + SPACE + "being passed to check" +
- " for" +
- " content match\n" +
- " * @param isSelectAllSchemaChild is select all schema child\n" +
- " * @return match result\n" +
- " */\n";
- StringBuilder builder = new StringBuilder(javadoc);
- Map<String, String> param = new LinkedHashMap<>();
- param.put(APP_INSTANCE, returnType);
- param.put(SELECT_ALL_CHILD_SCHEMA_PARAM, BOOLEAN_DATA_TYPE);
- builder.append(multiAttrMethodSignature(PROCESS_SUBTREE_FILTERING, null,
- DEFAULT, returnType, param,
- CLASS_TYPE))
- .append(getReturnString(NULL, EIGHT_SPACE_INDENTATION))
- .append(signatureClose()).append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
-
- /**
- * Returns is filter content match for leaf.
- *
- * @param javaAttributeInfo java attribute
- * @param type data type
- * @return is filter content match for leaf
- */
- public static String getSubtreeFilteringForLeaf(
- JavaAttributeInfo javaAttributeInfo, YangType<?> type) {
- String attrQualifiedType;
- String attributeName = javaAttributeInfo.getAttributeName();
- attrQualifiedType = getIfFilterContentMatchMethodImpl(attributeName,
- type);
- /* if (valueLeafFlags.get(LeafIdentifier.LEAF.getLeafIndex())) {
- * if (appInstance.leaf() != leaf()) {
- * return false;
- * } else {
- * subTreeFilteringResultBuilder.leaf(appInstance.leaf());
- * }
- * } else if (selectLeafFlags.get(LeafIdentifier.LEAF.getLeafIndex()) ||
- * isSelectAllSchemaChild) {
- * isAnySelectOrContainmentNode = true;
- * subTreeFilteringResultBuilder.leaf(appInstance.leaf());
- * }*/
-
-/* if (isSubTreeFiltered && !appInstance.isLeafValueSet(
- LeafIdentifier.LEAF2)) {
- subTreeFilteringResultBuilder.leaf2(leaf2());
- } else {
- return false;
- }*/
- String condition = SUBTREE_FILTERED + SPACE + AND_OPERATION + SPACE + NOT +
- APP_INSTANCE + PERIOD + VALUE_LEAF_SET +
- getOpenCloseParaWithValue(
- LEAF_IDENTIFIER + PERIOD + attributeName.toUpperCase());
- return getIfConditionBegin(EIGHT_SPACE_INDENTATION, getLeafFlagSetString(
- attributeName, VALUE_LEAF, EMPTY_STRING, GET)) +
- getIfConditionBegin(TWELVE_SPACE_INDENTATION, attrQualifiedType) +
- getIfConditionBegin(SIXTEEN_SPACE_INDENTATION, condition) +
- TWENTY_SPACE_INDENTATION + SUBTREE_FILTERING_RESULT_BUILDER +
- PERIOD + attributeName + getOpenCloseParaWithValue(
- attributeName + OPEN_CLOSE_BRACKET_STRING) + signatureClose() +
- SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + ELSE +
- OPEN_CURLY_BRACKET + NEW_LINE + getReturnString(
- FALSE, TWENTY_SPACE_INDENTATION) + signatureClose() +
- SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE +
- TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + ELSE +
- OPEN_CURLY_BRACKET + NEW_LINE +
- getSubTreeBuilderCallString(SIXTEEN_SPACE_INDENTATION, attributeName,
- TWELVE_SPACE) +
- getElseIfConditionBegin(EIGHT_SPACE_INDENTATION, getLeafFlagSetString(
- attributeName, SELECT_LEAF, EMPTY_STRING, GET) + SPACE +
- OR_OPERATION + SPACE + IS_SELECT_ALL_SCHEMA_CHILD_FLAG) +
- getSelectOrContainmentAssignString() +
- getSubTreeBuilderCallString(TWELVE_SPACE_INDENTATION, attributeName,
- EIGHT_SPACE);
- }
-
- private static String getSubTreeBuilderCallString(String indent, String
- name, IndentationType type) {
- return indent + SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + name +
- getOpenCloseParaWithValue(APP_INSTANCE + PERIOD + name +
- OPEN_CLOSE_BRACKET_STRING) +
- signatureClose() + methodClose(type);
- }
-
- private static String getAttrTypeForFcmWhenPrimitiveDataType(
- String attributeName) {
- return/* TODO: Need to check if we can expose the value leaf flag in
- interface.
- NOT + APP_INSTANCE + PERIOD + GET_VALUE_LEAF_FLAGS +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- GET_METHOD_PREFIX + OPEN_PARENTHESIS + LEAF_IDENTIFIER +
- PERIOD + attributeName.toUpperCase() + PERIOD
- + GET_LEAF_INDEX + OR_OPERATION +*/
- APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE + NOT + EQUAL + SPACE +
- attributeName + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS;
- }
-
- private static String attrTypeForFcmWhenNonPrimitiveDataTypes(String name) {
- /*
- * appInstance.name() == null || name().equals(appInstance.name())
- */
- return getEqualEqualString(getAppInstanceAttrString(name), NULL) +
- SPACE + OR_OPERATION + SPACE + NOT + OPEN_PARENTHESIS +
- getTwoParaEqualsString(name + OPEN_CLOSE_BRACKET_STRING,
- getAppInstanceAttrString(name))
- + CLOSE_PARENTHESIS;
- }
-
- private static String getIfFilterContentMatchMethodImpl(
- String name, YangType dataType) {
- String attrQualifiedType;
- if (dataType.getDataType().isPrimitiveDataType()) {
- attrQualifiedType = getAttrTypeForFcmWhenPrimitiveDataType(name);
- } else if (dataType.getDataType() == LEAFREF) {
-
- // When leafref in grouping.
- if (((YangLeafRef) dataType.getDataTypeExtendedInfo())
- .isInGrouping()) {
- attrQualifiedType = attrTypeForFcmWhenNonPrimitiveDataTypes(name);
- } else {
- YangType type = ((YangLeafRef) dataType.getDataTypeExtendedInfo())
- .getEffectiveDataType();
- if (type.getDataType().isPrimitiveDataType()) {
- attrQualifiedType = getAttrTypeForFcmWhenPrimitiveDataType(name);
- } else {
- attrQualifiedType = attrTypeForFcmWhenNonPrimitiveDataTypes(
- name);
- }
- }
- } else {
- attrQualifiedType = attrTypeForFcmWhenNonPrimitiveDataTypes(name);
- }
- return attrQualifiedType;
- }
-
- /**
- * Returns is filter content match for leaf.
- *
- * @param javaAttributeInfo java attribute
- * @return is filter content match for leaf
- */
- public static String getSubtreeFilteringForLeafList(
- JavaAttributeInfo javaAttributeInfo) {
- return getSubtreeFilteringForList(javaAttributeInfo, true, null);
- }
-
- /**
- * Returns is filter content match for child node.
- *
- * @param curNode current node
- * @param path path of temp file
- * @return is filter content match for child node
- */
- static String getProcessChildNodeSubtreeFiltering(YangNode curNode, String path)
- throws IOException {
- /* Generate code will look like this.
- private boolean processChildNodesSubTreeFiltering(Link
- appInstance, LinkBuilder subTreeFilteringResultBuilder,
- Boolean isAnySelectOrContainmentNode, boolean isSelectAllSchemaChild) {
- if (isSelectAllSchemaChild) {
- for (Areas areas : appInstance.areas()) {
- subTreeFilteringResultBuilder.addToAreas(areas);
- }
- } else if (areas() != null) {
- isAnySelectOrContainmentNode = true;
- if (!areas().isEmpty()) {
- if (appInstance.areas() != null && !appInstance.areas().isEmpty()) {
- for (Areas areas : areas()) {
- for (Areas areas2 : appInstance.areas()) {
- Areas result = areas.processSubtreeFiltering(areas2, false);
- if (result != null) {
- subTreeFilteringResultBuilder.addToAreas(result);
- }
- }
- }
- }
- } else {
- if (appInstance.areas() != null && !appInstance.areas().isEmpty()) {
- for (Areas areas : appInstance.areas()) {
- subTreeFilteringResultBuilder.addToAreas(areas);
- }
- }
- }
- }
-
- return true;
- }*/
- return getProcessStfMethods(PROCESS_CHILD_NODE_STF_PARAM, curNode,
- path, FILTER_CONTENT_MATCH_FOR_NODES_MASK);
- }
-
- /**
- * Returns is filter content match for leaf list.
- *
- * @param curNode current node
- * @param path path of temp file
- * @return is filter content match for leaf list
- */
- static String getProcessLeafListSubtreeFiltering(YangNode curNode, String path)
- throws IOException {
- /* Generate code will look like this.
- private boolean processLeafListSubTreeFiltering(Link appInstance, LinkBuilder subTreeFilteringResultBuilder,
- Boolean isAnySelectOrContainmentNode, boolean isSelectAllSchemaChild) {
- if (isSelectAllSchemaChild) {
- for (String portId : appInstance.portId()) {
- subTreeFilteringResultBuilder.addToPortId(portId);
- }
- } else if (portId() != null) {
- if (!portId().isEmpty()) {
- if (appInstance.portId() == null || appInstance.portId().isEmpty()) {
- return false;
- }
- for (String portId : portId()) {
- boolean flag = false;
- for (String portId2 : appInstance.portId()) {
- if (portId.equals(portId2)) {
- flag = true;
- subTreeFilteringResultBuilder.addToPortId(portId2);
- break;
- }
- }
- if (!flag) {
- return false;
- }
- }
- } else {
- isAnySelectOrContainmentNode = true;
- if (appInstance.portId() != null && !appInstance.portId().isEmpty()) {
- for (String portId : appInstance.portId()) {
- subTreeFilteringResultBuilder.addToPortId(portId);
- }
- }
- }
- }
-
- return true;
- }*/
- return getProcessStfMethods(PROCESS_LEAF_LIST_STF_PARAM, curNode, path,
- FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK);
- }
-
- /**
- * Returns is filter content match for leaf.
- *
- * @param curNode current node
- * @param path path of temp file
- * @return is filter content match for leaf
- */
- static String getProcessLeafSubtreeFiltering(YangNode curNode, String path)
- throws IOException {
- /* Generate code will look like this.
- private boolean processLeafSubtreeFiltering(Link appInstance, LinkBuilder subTreeFilteringResultBuilder,
- Boolean isAnySelectOrContainmentNode, boolean isSelectAllSchemaChild) {
- if (valueLeafFlags.get(LeafIdentifier.PORT.getLeafIndex())) {
- if (appInstance.port() != port()) {
- return false;
- } else {
- subTreeFilteringResultBuilder.port(appInstance.port());
- }
- } else if (selectLeafFlags.get(LeafIdentifier.PORT.getLeafIndex()) || isSelectAllSchemaChild) {
- isAnySelectOrContainmentNode = true;
- subTreeFilteringResultBuilder.port(appInstance.port());
- }
-
- return true;
- }*/
- return getProcessStfMethods(PROCESS_LEAF_STF_PARAM, curNode, path,
- FILTER_CONTENT_MATCH_FOR_LEAF_MASK);
- }
-
- /**
- * Returns is filter content match for leaf.
- *
- * @param curNode current node
- * @return is filter content match for leaf
- */
- static String getProcessSubtreeFilteringStart(YangNode curNode) {
-
- /* Generate code will look like this.
- public Link processSubtreeFiltering(Link appInstance, boolean isSelectAllSchemaChild) {
- LinkBuilder subTreeFilteringResultBuilder = new LinkBuilder();
- Boolean isAnySelectOrContainmentNode = false;
- */
- StringBuilder builder = new StringBuilder();
- JavaFileInfoTranslator javaFileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- String instance = APP_INSTANCE;
- String name = getCapitalCase(javaFileInfo.getJavaName());
- String builderNamePrefix = getCapitalCase(javaFileInfo.getJavaName());
- String caseName = getNameOfClassForIfCase(curNode);
- String returnType;
- if (curNode instanceof RpcNotificationContainer) {
- returnType = name + OP_PARAM;
- } else {
- returnType = DEFAULT_CAPS + name;
- }
- if (caseName != null) {
- instance = INSTANCE;
- name = caseName;
- }
-
- String javadoc = "\n /**\n" +
- " * Checks if the passed " + name + " maps the content " +
- "match query condition.\n" +
- " *\n" +
- " * @param " + instance + SPACE + instance + SPACE +
- "being passed to check for content match\n" +
- " * @param isSelectAllSchemaChild is select all schema " +
- "child\n" +
- " * @return match result\n" +
- " */\n";
- Map<String, String> param = new LinkedHashMap<>();
- param.put(instance, name);
- param.put(SELECT_ALL_CHILD_SCHEMA_PARAM, BOOLEAN_DATA_TYPE);
- builder.append(javadoc)
- .append(multiAttrMethodSignature(PROCESS_SUBTREE_FILTERING, null,
- PUBLIC, returnType, param,
- CLASS_TYPE));
-
- builder.append(getNewInstance(builderNamePrefix + BUILDER,
- SUBTREE_FILTERING_RESULT_BUILDER,
- EIGHT_SPACE_INDENTATION, EMPTY_STRING));
- builder.append(getNewInstance(BIT_SET,
- IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG,
- EIGHT_SPACE_INDENTATION, EMPTY_STRING));
- if (caseName != null) {
- builder.append(getCaseCastString(javaFileInfo, instance, curNode));
- }
-
- return builder.toString();
- }
-
- /**
- * Returns all process sub tree method implementations.
- *
- * @param methodName method name
- * @param curNode current node
- * @param path path for temporary file
- * @param file temp file
- * @return method implementations
- * @throws IOException when fails to fetch data from temp files
- */
- private static String getProcessStfMethods(
- String methodName, YangNode curNode, String path, int file)
- throws IOException {
- StringBuilder builder = new StringBuilder(EMPTY_STRING);
- JavaFileInfoTranslator javaFileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- String instance = APP_INSTANCE;
- String name = getCapitalCase(javaFileInfo.getJavaName());
- String builderNamePrefix = getCapitalCase(javaFileInfo.getJavaName());
- String caseName = getNameOfClassForIfCase(curNode);
- if (caseName != null) {
- instance = INSTANCE;
- name = caseName;
- }
-
- Map<String, String> param = new LinkedHashMap<>();
- param.put(instance, name);
- param.put(STF_BUILDER_PARAM, builderNamePrefix + BUILDER);
- param.put(SELECT_OR_CONTAINMENT_NODE_PARAM, BIT_SET);
- param.put(SELECT_ALL_CHILD_SCHEMA_PARAM, BOOLEAN_DATA_TYPE);
-
- builder.append(multiAttrMethodSignature(methodName, null,
- PRIVATE, BOOLEAN_DATA_TYPE, param, CLASS_TYPE));
-
- if (caseName != null) {
- builder.append(getCaseCastString(javaFileInfo, instance, curNode));
- }
- builder.append(getDataFromTempFileHandle(file,
- getBeanFiles(curNode), path))
- .append(getReturnString(TRUE, EIGHT_SPACE_INDENTATION)).append(
- signatureClose()).append(methodClose(FOUR_SPACE))
- .append(NEW_LINE);
- return builder.toString();
- }
-
- /**
- * Returns the body for process subtree filtering.
- *
- * @param curNode node for which the code is being generated
- * @return body of subtree filtering
- */
- static String getProcessSubtreeFunctionBody(YangNode curNode) {
- StringBuilder builder = new StringBuilder();
-
- /* if (!processLeafSubtreeFiltering(appInstance, subTreeFilteringResultBuilder,
- isAnySelectOrContainmentNode, isSelectAllSchemaChild)) {
- return null;
- }
- if (!processLeafListSubTreeFiltering(appInstance, subTreeFilteringResultBuilder,
- isAnySelectOrContainmentNode, isSelectAllSchemaChild)) {
- return null;
- }
- if (!processChildNodesSubTreeFiltering(appInstance, subTreeFilteringResultBuilder,
- isAnySelectOrContainmentNode, isSelectAllSchemaChild)) {
- return null;
- }
- */
- if (curNode instanceof YangLeavesHolder) {
- YangLeavesHolder holder = (YangLeavesHolder) curNode;
- if (!holder.getListOfLeaf().isEmpty()) {
- builder.append(getInnerStfMethodClass(PROCESS_LEAF_STF_PARAM));
- }
- if (!holder.getListOfLeafList().isEmpty()) {
- builder.append(getInnerStfMethodClass(PROCESS_LEAF_LIST_STF_PARAM));
- }
- }
- if (curNode.getChild() != null) {
- builder.append(getInnerStfMethodClass(PROCESS_CHILD_NODE_STF_PARAM));
- }
-
- return builder.toString();
- }
-
- //Method calls for process subtree filtering method.
- private static String getInnerStfMethodClass(String name) {
- StringBuilder builder = new StringBuilder()
- .append(getIfConditionBegin(EIGHT_SPACE_INDENTATION,
- getMethodCallsConditionsForStfMethods(name)))
- .append(getReturnString(NULL, TWELVE_SPACE_INDENTATION)).append(
- signatureClose()).append(methodClose(EIGHT_SPACE));
- return builder.toString();
- }
-
- // Condition for if check in process sub tree method.
- private static String getMethodCallsConditionsForStfMethods(String name) {
- return NOT + name + getOpenCloseParaWithValue(getConditionString());
- }
-
- //variable call for conditional method call
- private static String getConditionString() {
- return APP_INSTANCE + COMMA + SPACE + SUBTREE_FILTERING_RESULT_BUILDER +
- COMMA + SPACE + SELECT_OR_CONTAINMENT_NODE_PARAM + COMMA + SPACE +
- SELECT_ALL_CHILD;
- }
-
- /**
- * Returns is filter content match for node.
- *
- * @param attr attribute info
- * @param node YANG node
- * @return is filter content match for node
- */
- public static String getSubtreeFilteringForNode(JavaAttributeInfo attr, YangNode node) {
- boolean isList = attr.isListAttr();
- if (isList) {
- return getSubtreeFilteringForList(attr, false, node);
- } else {
- return getSubtreeFilteringForChildNode(attr, node);
- }
- }
-
- /**
- * Returns is filter content match close.
- *
- * @param name name of class
- * @return is filter content match close
- */
- static String getProcessSubTreeFilteringEnd(String name) {
- /* generate code will look like this.
- if (!isSelectAllSchemaChild && !isAnySelectOrContainmentNode) {
- return processSubtreeFiltering(appInstance, true);
- }
- return subTreeFilteringResultBuilder.build();
- */
-
- StringBuilder builder = new StringBuilder();
- String cond1 = NOT + IS_SELECT_ALL_SCHEMA_CHILD_FLAG + SPACE + AND_OPERATION +
- SPACE + NOT + IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG +
- PERIOD + GET + getOpenCloseParaWithValue(ZERO);
- String call = PROCESS_SUBTREE_FILTERING + getOpenCloseParaWithValue(
- APP_INSTANCE + COMMA + SPACE + TRUE);
- builder.append(getIfConditionBegin(EIGHT_SPACE_INDENTATION, cond1))
- .append(getReturnString(call, TWELVE_SPACE_INDENTATION))
- .append(signatureClose()).append(methodClose(EIGHT_SPACE));
-
- call = getOpenCloseParaWithValue(name) + SPACE +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + BUILD_FOR_FILTER +
- OPEN_CLOSE_BRACKET_STRING;
- builder.append(getReturnString(call, EIGHT_SPACE_INDENTATION))
- .append(signatureClose()).append(methodClose(FOUR_SPACE))
- .append(NEW_LINE);
- return builder.toString();
- }
-
- /**
- * Returns filter content match for child nodes.
- *
- * @param attr attribute to be added
- * @param node YANG node
- * @return filter content match for child nodes
- */
- private static String getSubtreeFilteringForChildNode(JavaAttributeInfo attr,
- YangNode node) {
- StringBuilder builder = new StringBuilder();
- String name = attr.getAttributeName();
- String clsInfo = attr.getImportInfo()
- .getClassInfo();
- String type = DEFAULT_CAPS + attr.getImportInfo()
- .getClassInfo();
- if (attr.isQualifiedName()) {
- type = attr.getImportInfo().getPkgInfo() + PERIOD +
- type;
- clsInfo = attr.getImportInfo().getPkgInfo() + PERIOD +
- clsInfo;
- }
- String classCast = getOpenCloseParaWithValue(type) + SPACE;
- String cast = getOpenCloseParaWithValue(classCast + name);
- if (node != null && node instanceof YangChoice) {
- cast = name;
- }
-
- String resultString = cast + NEW_LINE + TWENTY_EIGHT_SPACE_INDENTATION +
- PERIOD + PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS
- + APP_INSTANCE + PERIOD + name + OPEN_CLOSE_BRACKET_STRING
- + COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLON +
- NEW_LINE;
-
- String cond1 = name + OPEN_CLOSE_BRACKET_STRING + SPACE + NOT + EQUAL +
- SPACE + NULL + SPACE + OR_OPERATION + SPACE + SELECT_ALL_CHILD;
- builder.append(getIfConditionBegin(EIGHT_SPACE_INDENTATION, cond1))
- .append(getSelectOrContainmentAssignString());
-
- builder.append(getIfConditionBegin(TWELVE_SPACE_INDENTATION,
- getAppInstanceCondition(name, NOT)));
-
- String assignment = SIXTEEN_SPACE_INDENTATION + clsInfo + SPACE + RESULT +
- SPACE + EQUAL + SPACE + NULL + signatureClose();
-
- builder.append(assignment)
- .append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
- SELECT_ALL_CHILD));
-/*
- result = ((DefaultInterfaces)(DefaultInterfaces.builder()
- .build())).processSubtreeFiltering(appInstance.interfaces(),
- true);*/
-
- assignment = getDummyObjectCreation(node, name, clsInfo, type,
- classCast, false, false);
- builder.append(assignment).append(SIXTEEN_SPACE_INDENTATION).append(
- CLOSE_CURLY_BRACKET).append(ELSE).append(OPEN_CURLY_BRACKET)
- .append(NEW_LINE);
-
- assignment = TWENTY_SPACE_INDENTATION + RESULT + SPACE + EQUAL + SPACE
- + resultString;
- cond1 = RESULT + SPACE + NOT + EQUAL + SPACE + NULL;
-
- builder.append(assignment).append(methodClose(SIXTEEN_SPACE))
- .append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION, cond1));
-
- assignment = TWENTY_SPACE_INDENTATION + SUBTREE_FILTERING_RESULT_BUILDER +
- PERIOD + name + getOpenCloseParaWithValue(RESULT) +
- signatureClose();
- builder.append(assignment).append(methodClose(SIXTEEN_SPACE)).append(
- TWELVE_SPACE_INDENTATION).append(CLOSE_CURLY_BRACKET)
- .append(getSubTreeFilteredCondition(name)).append(methodClose(EIGHT_SPACE));
- return builder.toString();
- }
-
- private static String getAppInstanceCondition(String name, String condition) {
- return APP_INSTANCE + PERIOD + name + OPEN_CLOSE_BRACKET_STRING + SPACE +
- condition + EQUAL + SPACE + NULL;
- }
-
- private static String getSelectOrContainmentAssignString() {
- return TWELVE_SPACE_INDENTATION + IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG +
- PERIOD + SET_METHOD_PREFIX + getOpenCloseParaWithValue(ZERO) +
- signatureClose();
- }
-
- /**
- * Returns filter content match for list types.
- *
- * @param javaAttributeInfo attribute information
- * @param isLeafList if for leaf list
- * @param node YANG node
- * @return filter content match for list types
- */
- private static String getSubtreeFilteringForList(
- JavaAttributeInfo javaAttributeInfo, boolean isLeafList,
- YangNode node) {
- StringBuilder builder = new StringBuilder();
- String caps = getCapitalCase(javaAttributeInfo.getAttributeName());
- String name = javaAttributeInfo.getAttributeName();
- String type = javaAttributeInfo.getImportInfo().getClassInfo();
- if (javaAttributeInfo.getAttributeType() != null && javaAttributeInfo
- .getAttributeType().getDataType() == IDENTITYREF) {
- type = CLASS_STRING + DIAMOND_OPEN_BRACKET +
- QUESTION_MARK + SPACE + EXTEND + SPACE +
- type + DIAMOND_CLOSE_BRACKET;
- }
-
- YangDataStructure struct =
- getYangDataStructure(javaAttributeInfo.getCompilerAnnotation());
-
- boolean isMap = false;
- if (struct != null && struct == YangDataStructure.MAP) {
- isMap = true;
- }
-
- String clsInfo = DEFAULT_CAPS + type;
- if (javaAttributeInfo.isQualifiedName()) {
- if (javaAttributeInfo.getAttributeType() != null && javaAttributeInfo
- .getAttributeType().getDataType() == IDENTITYREF) {
- type = CLASS_STRING + DIAMOND_OPEN_BRACKET +
- QUESTION_MARK + SPACE + EXTEND + SPACE +
- javaAttributeInfo.getImportInfo().getPkgInfo() + PERIOD +
- type + DIAMOND_CLOSE_BRACKET;
- } else {
- type = javaAttributeInfo.getImportInfo().getPkgInfo() + PERIOD +
- type;
- }
- clsInfo = javaAttributeInfo.getImportInfo().getPkgInfo() + PERIOD +
- clsInfo;
- }
-
- String classCast = getOpenCloseParaWithValue(clsInfo) + SPACE;
- String cast = getOpenCloseParaWithValue(classCast + name);
-
- if (node != null && node instanceof YangChoice) {
- cast = name;
- }
- String validPass;
- //If map is in DS then need to pass name.getValue() to processSubTree.
- if (isMap) {
- validPass = name + TWO + PERIOD + GET_VALUE;
- } else {
- validPass = name + TWO;
- }
- String resultString = cast + NEW_LINE + TWENTY_EIGHT_SPACE_INDENTATION +
- PERIOD + PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS +
- validPass + COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLON +
- NEW_LINE;
- /*
- * If select all schema child
- */
- String forCondition;
- String mapEntry;
- String para;
- //If map is there in DS the for loop should run for map entry.
- if (!isMap) {
- forCondition = getForLoopString(SIXTEEN_SPACE_INDENTATION, type, name,
- getAppInstanceAttrString(name));
- } else {
- mapEntry = MAP + PERIOD + ENTRY + DIAMOND_OPEN_BRACKET + type +
- KEYS + COMMA + SPACE + type + DIAMOND_CLOSE_BRACKET + SPACE;
- para = getAppInstanceAttrString(name) + PERIOD + ENTRY_SET;
- forCondition = getForLoopString(SIXTEEN_SPACE_INDENTATION,
- mapEntry, name, para);
- }
- builder.append(getIfConditionBegin(EIGHT_SPACE_INDENTATION,
- IS_SELECT_ALL_SCHEMA_CHILD_FLAG))
- .append(getIfConditionBegin(TWELVE_SPACE_INDENTATION,
- getAppInstanceCondition(name, NOT)))
- .append(forCondition);
- String assignment;
- String result;
- //If map is added then while creating dummy object need to used name
- // .getValue() and to add the result in subTreeBuilder need to pass
- // using key and value, key will be name.getKey() and value will be
- // result.
- if (isMap) {
- result = getOpenCloseParaWithValue(name + PERIOD + GET_KEY + COMMA +
- SPACE + RESULT);
- } else {
- result = getOpenCloseParaWithValue(RESULT);
- }
- if (!isLeafList) {
- builder.append(TWENTY_SPACE_INDENTATION).append(type).append(SPACE)
- .append(RESULT).append(signatureClose());
- assignment = getDummyObjectCreation(node, name, type, clsInfo,
- classCast, true, isMap);
- builder.append(assignment);
- assignment = TWENTY_SPACE_INDENTATION +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
- getCapitalCase(TO) + caps + result +
- signatureClose();
- builder.append(assignment);
- } else {
- assignment = TWENTY_SPACE_INDENTATION +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
- getCapitalCase(TO) + caps + getOpenCloseParaWithValue(name) +
- signatureClose();
- builder.append(assignment);
- }
- builder.append(methodClose(SIXTEEN_SPACE))
- .append(TWELVE_SPACE_INDENTATION).append(CLOSE_CURLY_BRACKET);
-
-/* } else {
- if (isSubTreeFiltered && leafList2() != null) {
- subTreeFilteringResultBuilder.addToLeafList2(leafList2());
- }
- }*/
- builder.append(getSubTreeFilteredCondition(name));
-
- String cond = name + OPEN_CLOSE_BRACKET_STRING + SPACE + NOT + EQUAL +
- SPACE + NULL;
-
- //If need to explicitly participate in query
- builder.append(getElseIfConditionBegin(EIGHT_SPACE_INDENTATION, cond));
-
- if (!isLeafList) {
- builder.append(getSelectOrContainmentAssignString());
- }
-
- //If there is any parameter in the query condition
- cond = NOT + name + OPEN_CLOSE_BRACKET_STRING + PERIOD + IS_EMPTY;
- builder.append(getIfConditionBegin(TWELVE_SPACE_INDENTATION, cond));
-
- if (isLeafList) {
- cond = getAppInstanceCondition(name, EQUAL) + SPACE + OR_OPERATION +
- SPACE + APP_INSTANCE + PERIOD + name +
- OPEN_CLOSE_BRACKET_STRING + PERIOD + IS_EMPTY;
- /*
- * If there is no app instance to perform content match
- */
- builder.append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION, cond))
- .append(getReturnString(FALSE, TWENTY_SPACE_INDENTATION))
- .append(signatureClose())
- .append(methodClose(SIXTEEN_SPACE))
- // for instance iterator
- .append(getForLoopString(SIXTEEN_SPACE_INDENTATION, type, name,
- name + OPEN_CLOSE_BRACKET_STRING));
-
- assignment = TWENTY_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
- FLAG + SPACE + EQUAL + SPACE + FALSE + signatureClose();
- builder.append(assignment)
- // for app instance iterator
- .append(getForLoopString(TWENTY_SPACE_INDENTATION, type,
- name + TWO,
- getAppInstanceAttrString(name)));
-
- cond = name + PERIOD + EQUALS_STRING
- + OPEN_PARENTHESIS + name + TWO + CLOSE_PARENTHESIS;
- //the content match leaf list attribute value matches
- builder.append(getIfConditionBegin(TWENTY_FOUR_SPACE_INDENTATION,
- cond));
-
- assignment = TWENTY_EIGHT_SPACE_INDENTATION + FLAG + SPACE + EQUAL +
- SPACE + TRUE + SEMI_COLON + NEW_LINE;
- builder.append(assignment);
- assignment = TWENTY_EIGHT_SPACE_INDENTATION +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
- getCapitalCase(TO) + caps + getOpenCloseParaWithValue(name + TWO) +
- signatureClose();
- builder.append(assignment).append(TWENTY_EIGHT_SPACE_INDENTATION)
- .append(BREAK).append(signatureClose())
- //the content match leaf list attribute value matches
- .append(methodClose(TWENTY_FOUR_SPACE))
- // for app instance iterator
- .append(methodClose(TWENTY_SPACE))
- //if the content match failed
- .append(getIfConditionBegin(TWENTY_SPACE_INDENTATION, NOT +
- FLAG))
- .append(getReturnString(FALSE, TWENTY_FOUR_SPACE_INDENTATION))
- .append(signatureClose()).append(methodClose(TWENTY_SPACE))// if flag == false
- .append(methodClose(SIXTEEN_SPACE)); // for instance iterator
- } else {
- cond = getAppInstanceCondition(name, NOT) + SPACE + AND_OPERATION +
- SPACE + NOT + getAppInstanceAttrString(name) +
- PERIOD + IS_EMPTY;
- //Same here for loop for map entry.
- if (!isMap) {
- forCondition = getForLoopString(TWENTY_SPACE_INDENTATION, type,
- name + TWO,
- getAppInstanceAttrString(name));
- } else {
- mapEntry = MAP + PERIOD + ENTRY + DIAMOND_OPEN_BRACKET + type +
- KEYS + COMMA + SPACE + type + DIAMOND_CLOSE_BRACKET + SPACE;
- para = getAppInstanceAttrString(name) + PERIOD + ENTRY_SET;
- forCondition = getForLoopString(TWENTY_SPACE_INDENTATION,
- mapEntry, name + TWO, para);
- }
- String forCondition2;
- //Same here for loop for map entry.
- if (!isMap) {
- forCondition2 = getForLoopString(SIXTEEN_SPACE_INDENTATION, type, name,
- name + OPEN_CLOSE_BRACKET_STRING);
- } else {
- mapEntry = MAP + PERIOD + ENTRY + DIAMOND_OPEN_BRACKET + type +
- KEYS + COMMA + SPACE + type + DIAMOND_CLOSE_BRACKET + SPACE;
- para = name + OPEN_CLOSE_BRACKET_STRING + PERIOD + ENTRY_SET;
- forCondition2 = getForLoopString(SIXTEEN_SPACE_INDENTATION,
- mapEntry, name, para);
- }
- /*if there is any app instance entry*/
- builder.append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
- cond))
- //loop all the app instance(s)
- .append(forCondition2)
- .append(forCondition);
-
- assignment = TWENTY_EIGHT_SPACE_INDENTATION + type + SPACE +
- RESULT + SPACE + EQUAL + SPACE + resultString;
- builder.append(assignment);
- cond = RESULT + SPACE + NOT + EQUAL + SPACE + NULL;
- builder.append(getIfConditionBegin(TWENTY_EIGHT_SPACE_INDENTATION, cond));
-
- //If map is added then while creating dummy object need to used name
- // .getValue() and to add the result in subTreeBuilder need to pass
- // using key and value, key will be name.getKey() and value will be
- // result.
- if (isMap) {
- result = getOpenCloseParaWithValue(name + TWO + PERIOD + GET_KEY +
- COMMA +
- SPACE + RESULT);
- } else {
- result = getOpenCloseParaWithValue(RESULT);
- }
- assignment = THIRTY_TWO_SPACE_INDENTATION +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
- getCapitalCase(TO) + caps + result + signatureClose();
- builder.append(assignment).append(methodClose(TWENTY_EIGHT_SPACE))
- //loop all the app instance(s)
- .append(methodClose(TWENTY_FOUR_SPACE))
- //loop all the query condition instance(s)
- .append(methodClose(TWENTY_SPACE))
- .append(SIXTEEN_SPACE_INDENTATION).append(CLOSE_CURLY_BRACKET)
- .append(getSubTreeFilteredCondition(name));
- //if there is any app instance entry
- }
-
- cond = TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
- + ELSE + OPEN_CURLY_BRACKET + NEW_LINE;
- builder.append(cond);
-
- if (isLeafList) {
- builder.append(getSelectOrContainmentAssignString());
- }
-
- //need to pass name.getKey() and name.getValue() while adding to
- // subtree builder.
- if (!isMap) {
- forCondition = getForLoopString(SIXTEEN_SPACE_INDENTATION, type,
- name, getAppInstanceAttrString(name));
- } else {
- mapEntry = MAP + PERIOD + ENTRY + DIAMOND_OPEN_BRACKET + type +
- KEYS + COMMA + SPACE + type + DIAMOND_CLOSE_BRACKET + SPACE;
- para = getAppInstanceAttrString(name) + PERIOD + ENTRY_SET;
- forCondition = getForLoopString(SIXTEEN_SPACE_INDENTATION,
- mapEntry, name, para);
- }
- cond = getAppInstanceCondition(name, NOT) + SPACE + AND_OPERATION +
- SPACE + NOT + getAppInstanceAttrString(name) + PERIOD + IS_EMPTY;
- builder.append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION, cond))
- .append(forCondition);
- if (isMap) {
- result = getOpenCloseParaWithValue(name + PERIOD + GET_KEY + COMMA +
- SPACE + name + PERIOD +
- GET_VALUE);
- } else {
- result = getOpenCloseParaWithValue(name);
- }
- assignment = TWENTY_FOUR_SPACE_INDENTATION +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
- getCapitalCase(TO) + caps + result + signatureClose();
- builder.append(assignment).append(methodClose(TWENTY_SPACE))// Close collection Iteration loop
- // close if condition
- .append(methodClose(SIXTEEN_SPACE))
- .append(methodClose(TWELVE_SPACE))// close else condition
- .append(methodClose(EIGHT_SPACE));// close else if condition
-
- return builder.toString();
- }
-
- public static String getAugmentableSubTreeFiltering() {
- return " if (yangAugmentedInfoMap.isEmpty()) {\n" +
- " java.util.Set<Map.Entry<Class<?>, Object>> " +
- "augment =" +
- " appInstance.yangAugmentedInfoMap().entrySet();\n" +
- " if (augment != null && !augment.isEmpty()) {\n" +
- " java.util.Iterator<Map.Entry<Class<?>, " +
- "Object>> augItr =" +
- " augment.iterator();\n" +
- " while (augItr.hasNext()) {\n" +
- " Map.Entry<Class<?>, Object> aug =" +
- " augItr.next();\n" +
- " Class<?> augClass = aug.getKey();\n" +
- " String augClassName = augClass.getName();\n" +
- " int index = augClassName.lastIndexOf('.');\n" +
- " String classPackage = augClassName.substring(0, index) +\n" +
- " \".\" + \"Default\" + augClass.getSimpleName() + \"$\"\n" +
- " + augClass.getSimpleName() + \"Builder\";\n" +
- " ClassLoader classLoader = augClass.getClassLoader();\n" +
- " try {\n" +
- " Class<?> builderClass;\n" +
- " builderClass = classLoader.loadClass(classPackage);\n" +
- " Object builderObj = builderClass.newInstance();\n" +
- " java.lang.reflect.Method method = " +
- "builderClass.getMethod(\"build\");\n" +
- " Object defaultObj = method.invoke(builderObj);\n" +
- " Class<?> defaultClass = defaultObj.getClass();\n" +
- " method = defaultClass.getMethod(" +
- "\"processSubtreeFiltering\", augClass, boolean.class);\n" +
- " Object result = method.invoke(" +
- "defaultObj, aug.getValue(), true);\n" +
- " subTreeFilteringResultBuilder." +
- "addYangAugmentedInfo(result, augClass);\n" +
- " } catch (ClassNotFoundException | InstantiationException\n" +
- " | NoSuchMethodException |\n" +
- " InvocationTargetException | IllegalAccessException e) {\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " } else {\n" +
- " java.util.Set<Map.Entry<Class<?>, Object>> augment = yangAugmentedInfoMap\n" +
- " .entrySet();\n" +
- " java.util.Iterator<Map.Entry<Class<?>, Object>> augItr = augment.iterator();\n" +
- " while (augItr.hasNext()) {\n" +
- " Map.Entry<Class<?>, Object> aug = augItr.next();\n" +
- " Class<?> augClass = aug.getKey();\n" +
- " Object appInstanceInfo = appInstance." +
- "yangAugmentedInfo(augClass);\n" +
- " if (appInstanceInfo == null) {\n" +
- " subTreeFilteringResultBuilder." +
- "addYangAugmentedInfo(aug.getValue(), aug.getKey());\n" +
- " } else {\n" +
- " Object processSubtreeFiltering;\n" +
- " try {\n" +
- " processSubtreeFiltering = " +
- "aug.getValue().getClass()\n" +
- " .getMethod(\"processSubtreeFiltering\"," +
- " aug.getKey(), boolean.class)\n" +
- " .invoke(aug.getValue(), appInstanceInfo, true);\n" +
- " if (processSubtreeFiltering != null) {\n" +
- " subTreeFilteringResultBuilder\n" +
- " .addYangAugmentedInfo(" +
- "processSubtreeFiltering, aug.getKey());\n" +
- " }\n" +
- " } catch (NoSuchMethodException | InvocationTargetException |\n" +
- " IllegalAccessException e) {\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n";
- }
-
- private static String getSubTreeFilteredCondition(String name) {
- StringBuilder builder = new StringBuilder();
- String cond = SUBTREE_FILTERED + SPACE + AND_OPERATION + SPACE + name +
- OPEN_CLOSE_BRACKET_STRING + SPACE + NOT + EQUAL + SPACE + NULL;
-
- builder.append(ELSE).append(OPEN_CURLY_BRACKET).append(NEW_LINE)
- .append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION, cond))
- .append(TWENTY_SPACE_INDENTATION)
- .append(SUBTREE_FILTERING_RESULT_BUILDER).append(PERIOD)
- .append(name).append(getOpenCloseParaWithValue(name)).append(
- signatureClose()).append(SIXTEEN_SPACE_INDENTATION).append(
- CLOSE_CURLY_BRACKET).append(NEW_LINE).append(TWELVE_SPACE_INDENTATION)
- .append(CLOSE_CURLY_BRACKET).append(NEW_LINE);
- return builder.toString();
- }
-
- private static String getNameOfClassForIfCase(YangNode curNode) {
- String name = null;
- JavaFileInfoTranslator parentInfo;
- if (curNode instanceof YangCase) {
- YangNode parent = curNode.getParent();
- if (parent instanceof YangChoice) {
- parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
- name = getCapitalCase(parentInfo.getJavaName());
- } else if (parent instanceof YangAugment) {
- parentInfo = ((JavaFileInfoContainer) ((YangAugment) parent)
- .getAugmentedNode()).getJavaFileInfo();
- if (parentInfo != null) {
- name = getCapitalCase(parentInfo.getJavaName());
- } else {
- name = getCapitalCase(getCamelCase(
- ((YangAugment) parent).getAugmentedNode().getName(),
- null));
- }
- }
- }
- return name;
- }
-
- private static String getCaseCastString(
- JavaFileInfoTranslator javaFileInfo, String instance, YangNode curNode) {
- if (curNode instanceof YangCase) {
- String caseName = DEFAULT_CAPS + getCapitalCase(
- javaFileInfo.getJavaName());
- return EIGHT_SPACE_INDENTATION + caseName + SPACE + APP_INSTANCE + SPACE +
- EQUAL + SPACE + OPEN_PARENTHESIS + caseName +
- CLOSE_PARENTHESIS + SPACE + instance + signatureClose();
- }
- return null;
- }
-
- private static String getDummyObjectCreation(YangNode node, String name,
- String clsInfo, String type,
- String classCast, boolean isList,
- boolean isMap) {
- String para = getAppInstanceAttrString(name);
- if (isList) {
- if (isMap) {
- para = name + PERIOD + GET_VALUE;
- } else {
- para = name;
- }
- }
- if (node != null && node instanceof YangChoice) {
- return getChoiceReflectionResult(name, clsInfo);
- }
- return TWENTY_SPACE_INDENTATION + RESULT + SPACE + EQUAL + SPACE +
- getOpenCloseParaWithValue(
- classCast + type + PERIOD + BUILDER_LOWER_CASE +
- OPEN_CLOSE_BRACKET_STRING + NEW_LINE +
- TWENTY_EIGHT_SPACE_INDENTATION + PERIOD +
- BUILD_FOR_FILTER + OPEN_CLOSE_BRACKET_STRING) +
- PERIOD + PROCESS_SUBTREE_FILTERING + getOpenCloseParaWithValue(
- para + COMMA + SPACE + TRUE) + signatureClose();
- }
-
- private static String getChoiceReflectionResult(String name, String returnType) {
- String call = "appInstance." + name + "()";
- return " Class<?>[] classArray = " + call + "" +
- ".getClass()" +
- ".getInterfaces();\n" +
- " Class<?> caseIntf = classArray[0];\n" +
- " try {\n" +
- " ClassLoader classLoader = this" +
- ".getClass().getClassLoader();\n" +
- " String className = \"Default\" + " +
- "caseIntf.getSimpleName();\n" +
- " className = caseIntf.getPackage()" +
- ".getName() + \".\" + className;\n" +
- " Class<?> caseClass = classLoader" +
- ".loadClass(className);\n" +
- " java.lang.reflect.Constructor<?> " +
- "constructor = caseClass.getDeclaredConstructor();\n" +
- " constructor.setAccessible(true);\n" +
- " Object obj1 = constructor" +
- ".newInstance();\n" +
- " java.lang.reflect.Method method =" +
- " caseClass.getMethod(\"builder\");\n" +
- " Object obj = method.invoke(obj1);\n" +
- " Class<?> builderClass = obj.getClass();\n" +
- " method = builderClass.getMethod(\"build\");\n" +
- " Object obj2 = method.invoke(obj);\n" +
- " Class<?> input = this.getClass()" +
- ".getMethod(" + "\"" + name + "\").getReturnType();\n" +
- " method = caseClass.getMethod" +
- "(\"processSubtreeFiltering\", input,\n" +
- " boolean.class);\n" +
- " result = (" + returnType + ") method.invoke" +
- "(obj2, " + call + ", true);\n" +
- " } catch (NoSuchMethodException | InstantiationException |\n" +
- " IllegalAccessException | " +
- "InvocationTargetException |\n" +
- " ClassNotFoundException e) {\n" +
- " e.printStackTrace();\n" +
- " }\n";
- }
-}
diff --git a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
index 05073fc..22a8f98 100644
--- a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
+++ b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
@@ -18,6 +18,7 @@
import java.io.File;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
/**
@@ -331,23 +332,6 @@
* Static attribute for space.
*/
public static final String SPACE = " ";
- /**
- * Static attribute for space.
- */
- public static final String TWO = "2";
- /**
- * Static attribute for space.
- */
- public static final String FLAG = "flag";
- /**
- * Static attribute for result.
- */
- public static final String RESULT = "result";
-
- /**
- * Static attribute for isSelectAllSchemaChild.
- */
- public static final String SELECT_ALL_CHILD = "isSelectAllSchemaChild";
/**
* Static attribute for schema name.
@@ -651,16 +635,6 @@
public static final String KEYS = "Keys";
/**
- * Static attribute for key syntax.
- */
- public static final String GET_KEY = "getKey()";
-
- /**
- * Static attribute for key syntax.
- */
- public static final String GET_VALUE = "getValue()";
-
- /**
* Static attribute for -1 to syntax.
*/
public static final String NEG_ONE = "-1";
@@ -908,36 +882,6 @@
*/
public static final String OP_PARAM = "OpParam";
-
- /**
- * Static attribute for is filter content match method prefix.
- */
- public static final String PROCESS_SUBTREE_FILTERING =
- "processSubtreeFiltering";
-
- /**
- * variable name of the subtree filtering result builder.
- */
- public static final String SUBTREE_FILTERING_RESULT_BUILDER =
- "subTreeFilteringResultBuilder";
-
- /**
- * variable name of the subtree filtering result flag.
- */
- public static final String IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG =
- "isAnySelectOrContainmentNode";
-
- /**
- * variable name of the subtree filtering to select all child.
- */
- public static final String IS_SELECT_ALL_SCHEMA_CHILD_FLAG =
- "isSelectAllSchemaChild";
-
- /**
- * Static attribute for break prefix.
- */
- public static final String BREAK = "break";
-
/**
* Static attribute for isEmpty.
*/
@@ -979,21 +923,6 @@
public static final String VALUE_LEAF = "valueLeafFlags";
/**
- * Static attribute for is selectLeafFlags method prefix.
- */
- public static final String SELECT_LEAF = "selectLeafFlags";
-
- /**
- * Static attribute for is isSelectLeaf method prefix.
- */
- public static final String IS_SELECT_LEAF = "isSelectLeaf";
-
- /**
- * Static attribute for is selectLeaf method prefix.
- */
- public static final String SET_SELECT_LEAF = "selectLeaf";
-
- /**
* Static attribute for is LeafIdentifier enum prefix.
*/
public static final String LEAF_IDENTIFIER = "LeafIdentifier";
@@ -1228,20 +1157,20 @@
* List of keywords in java, this is used for checking if the input does not
* contain these keywords.
*/
- public static final List<String> JAVA_KEY_WORDS =
- Arrays.asList("abstract", "assert", "boolean", "break", "byte",
- "case", "catch", "char", "class", "const", "continue",
- "default", "do", "double", "else", "extends", "false",
- "final", "finally", "float", "for", "goto", "if",
- "implements", "import", "instanceof", "enum", "int",
- "interface", "long", "native", "new", "null",
- "package", "private", "protected", "public", "return",
- "short", "static", "strictfp", "super", "switch",
- "synchronized", "this", "throw", "throws", "transient",
- "true", "try", "void", "volatile", "while", "list",
- "map", "arrayList", "hashMap", "linkedList", "notify",
- "notifyAll", "Method",
- "collections");
+ public static final List<String> JAVA_KEY_WORDS = Collections
+ .unmodifiableList(Arrays.asList("abstract", "assert", "boolean", "break", "byte",
+ "case", "catch", "char", "class", "const", "continue",
+ "default", "do", "double", "else", "extends", "false",
+ "final", "finally", "float", "for", "goto", "if",
+ "implements", "import", "instanceof", "enum", "int",
+ "interface", "long", "native", "new", "null",
+ "package", "private", "protected", "public", "return",
+ "short", "static", "strictfp", "super", "switch",
+ "synchronized", "this", "throw", "throws", "transient",
+ "true", "try", "void", "volatile", "while", "list",
+ "map", "arrayList", "hashMap", "linkedList", "notify",
+ "notifyAll", "Method",
+ "collections"));
/**
* Static attribute for regex for all the special characters.
@@ -1511,6 +1440,11 @@
public static final String JAVA_UTIL_PKG = "java.util";
/**
+ * Static attribute for model object import package.
+ */
+ public static final String MODEL_OBJECT_PKG = "org.onosproject.yang.model";
+
+ /**
* Static attribute for java utilities import package.
*/
public static final String JAVA_UTIL_REGEX_PKG = "java.util.regex";
@@ -1536,23 +1470,6 @@
public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects";
/**
- * Static attribute for AugmentedInfo class.
- */
- public static final String YANG_AUGMENTED_INFO = "YangAugmentedInfo";
-
- /**
- * Static attribute for AugmentedInfo class.
- */
- public static final String YANG_AUGMENTED_INFO_LOWER_CASE =
- "yangAugmentedInfo";
-
- /**
- * Static attribute for AugmentedInfo class.
- */
- public static final String YANG_AUGMENTED_INFO_MAP =
- "yangAugmentedInfoMap";
-
- /**
* Static attribute for augmented.
*/
public static final String AUGMENTED = "Augmented";
@@ -1671,6 +1588,13 @@
"compiler annotation ";
/**
+ * Static attribute for compiler annotation resolve entity error
+ * information.
+ */
+ public static final String FAILED_TO_FIND_DEVIATION = "Failed to link " +
+ "deviation ";
+
+ /**
* Static attribute for failed to link entity error information.
*/
public static final String FAILED_TO_LINK = "Failed to link ";
@@ -1765,12 +1689,6 @@
public static final String ONE = "1";
/**
- * Static attribute for YANG node operation type class.
- */
- public static final String OPERATION_TYPE_CLASS =
- "OnosYangOpType";
-
- /**
* Static attribute for YANG node operation type attribute.
*/
public static final String OPERATION_TYPE_ATTRIBUTE =
@@ -1874,39 +1792,6 @@
*/
public static final String AT = " at ";
- /**
- * Static param for processChildNodesSubTreeFiltering.
- */
- public static final String PROCESS_CHILD_NODE_STF_PARAM =
- "processChildNodesSubTreeFiltering";
-
- /**
- * Static param for processLeafListSubTreeFiltering.
- */
- public static final String PROCESS_LEAF_LIST_STF_PARAM =
- "processLeafListSubTreeFiltering";
- /**
- * Static param for processLeafListSubTreeFiltering.
- */
- public static final String PROCESS_LEAF_STF_PARAM =
- "processLeafSubtreeFiltering";
- /**
- * Static param for subTreeFilteringResultBuilder.
- */
- public static final String STF_BUILDER_PARAM =
- "subTreeFilteringResultBuilder";
-
- /**
- * Static param for isAnySelectOrContainmentNode.
- */
- public static final String SELECT_OR_CONTAINMENT_NODE_PARAM =
- "isAnySelectOrContainmentNode";
- /**
- * Static param for isSelectAllSchemaChild.
- */
- public static final String SELECT_ALL_CHILD_SCHEMA_PARAM =
- "isSelectAllSchemaChild";
-
//File type extension for java classes.
public static final String JAVA_FILE_EXTENSION = ".java";
@@ -1920,6 +1805,56 @@
*/
public static final String LAST = "last";
+ /**
+ * Static param for model object.
+ */
+ public static final String MODEL_OBJECT = "ModelObject";
+
+ /**
+ * Static param for add augmentation.
+ */
+ public static final String ADD_AUGMENTATION = "addAugmentation";
+
+ /**
+ * Static param for remove augmentation.
+ */
+ public static final String REMOVE_AUGMENTATION = "removeAugmentation";
+
+ /**
+ * Static param for augmentations.
+ */
+ public static final String AUGMENTATIONS = "augmentations";
+
+ /**
+ * Static param for augmentation.
+ */
+ public static final String AUGMENTATION = "augmentation";
+
+ /**
+ * Static param for variable c.
+ */
+ public static final String VARIABLE_C = "c";
+
+ /**
+ * Static param for left angular bracket.
+ */
+ public static final String LEFT_ANGULAR_BRACKET = "<";
+
+ /**
+ * Static param for right angular brace.
+ */
+ public static final String RIGHT_ANGULAR_BRACKET = ">";
+
+ /**
+ * Static param for template t.
+ */
+ public static final String TEMPLATE_T = "T";
+
+ /**
+ * Static param for class.
+ */
+ public static final String CAMEL_CLASS = "Class";
+
// No instantiation.
private UtilConstants() {
}
diff --git a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/io/impl/JavaDocGen.java b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/io/impl/JavaDocGen.java
index 89ab368..07af02e 100644
--- a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/io/impl/JavaDocGen.java
+++ b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/io/impl/JavaDocGen.java
@@ -386,18 +386,6 @@
" * valueLeafFlags identify the leafs whose value are " +
"explicitly set\n" +
" * Applicable in protocol edit and query operation.\n" +
- " * </p>\n" +
- " *\n" +
- " * <p>\n" +
- " * selectLeafFlags identify the leafs to be selected, in" +
- " a query operation.\n" +
- " * </p>\n" +
- " *\n" +
- " * <p>\n" +
- " * Operation type specify the node specific operation in" +
- " protocols like NETCONF.\n" +
- " * Applicable in protocol edit operation, not applicable" +
- " in query operation.\n" +
" * </p>\n";
}
@@ -524,37 +512,6 @@
}
/**
- * Generates javaDocs for add augmentation method.
- *
- * @param name builder class name
- * @return javaDocs
- */
- public static String generateForAddAugmentation(String name) {
- return getJavaDocStartLine(YANG_AUGMENTED_INFO_LOWER_CASE,
- JAVA_DOC_SETTERS_COMMON) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(YANG_AUGMENTED_INFO_LOWER_CASE, VALUE) +
- getJavaDocParamLine(YANG_AUGMENTED_INFO_LOWER_CASE, CLASS +
- OBJECT_STRING) +
- getJavaDocReturnLine(name) + getJavaDocEndLine();
- }
-
- /**
- * Returns javadoc for get augmentation method.
- *
- * @return javadoc for get augmentation method
- */
- public static String generateForGetAugmentation() {
- return NEW_LINE + getJavaDocStartLine(YANG_AUGMENTED_INFO_LOWER_CASE,
- JAVA_DOC_GETTERS) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(YANG_AUGMENTED_INFO_LOWER_CASE, CLASS +
- OBJECT_STRING) +
- getJavaDocReturnLine(YANG_AUGMENTED_INFO) +
- getJavaDocEndLine();
- }
-
- /**
* Returns javadoc for validator method.
*
* @return javadoc for validator method
diff --git a/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangPluginUtils.java b/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangPluginUtils.java
index c5f0e69..1a43f6c 100644
--- a/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangPluginUtils.java
+++ b/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangPluginUtils.java
@@ -18,7 +18,6 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Dependency;
-import org.apache.maven.model.Plugin;
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
import org.onosproject.yang.compiler.base.tool.YangToolManager;
@@ -30,13 +29,9 @@
import java.io.File;
import java.io.IOException;
-import java.io.PrintWriter;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import static org.onosproject.yang.compiler.utils.UtilConstants.COLON;
-import static org.onosproject.yang.compiler.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.HYPHEN;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAR;
import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
@@ -51,10 +46,6 @@
private static final Logger log = getLogger(YangPluginUtils.class);
- private static final String TEXT_FILE_EXTENSION = ".txt";
- private static final String VERSION_META_DATA = "VersionMetaData";
- private static final String PLUGIN_ARTIFACT = "onos-yang-maven-plugin";
-
private YangPluginUtils() {
}
@@ -80,7 +71,6 @@
*/
static void copyYangFilesToTarget(String outputDir, MavenProject project)
throws IOException {
-
addToProjectResource(outputDir + SLASH + TEMP + SLASH, project);
}
@@ -104,39 +94,6 @@
if (operation) {
addToProjectResource(directory + SLASH + TEMP + SLASH, project);
}
-
- if (operation) {
- addVersionMetaDataFile(project, serFileDirPath);
- }
- }
-
- /**
- * Adds version meta data files for YSR to know version of YANG tools.
- *
- * @param project maven project
- * @param dir directory
- * @throws IOException when fails to do IO operations
- */
- private static void addVersionMetaDataFile(MavenProject project, String dir)
- throws IOException {
- List<Plugin> plugins = project.getBuildPlugins();
- Iterator<Plugin> it = plugins.iterator();
- Plugin plugin = it.next();
- String data = EMPTY_STRING;
- while (it.hasNext()) {
- if (plugin.getArtifactId().equals(PLUGIN_ARTIFACT)) {
- data = plugin.getGroupId() + COLON + plugin.getArtifactId()
- + COLON + plugin.getVersion();
- }
- plugin = it.next();
- }
- if (data.equals(EMPTY_STRING)) {
- throw new IOException("Invalid artifact for " + PLUGIN_ARTIFACT);
- }
- String verFileName = dir + VERSION_META_DATA + TEXT_FILE_EXTENSION;
- PrintWriter out = new PrintWriter(verFileName);
- out.print(data);
- out.close();
}
/**
diff --git a/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangUtilManager.java b/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangUtilManager.java
index a9d0ce0..903c705 100644
--- a/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangUtilManager.java
+++ b/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangUtilManager.java
@@ -25,6 +25,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.rtinfo.RuntimeInformation;
+import org.onosproject.yang.compiler.datamodel.YangDeviationHolder;
import org.onosproject.yang.compiler.parser.YangUtilsParser;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
@@ -295,7 +296,7 @@
* TODO: Delete me and use the tool code for UT test cases
* Creates YANG nodes set.
*/
- protected void createYangNodeSet() {
+ public void createYangNodeSet() {
for (YangFileInfo yangFileInfo : yangFileInfoSet) {
yangNodeSet.add(yangFileInfo.getRootNode());
}
@@ -351,7 +352,8 @@
yangNodeSortedList.addAll(yangNodeSet);
sort(yangNodeSortedList);
for (YangNode node : yangNodeSortedList) {
- if (node.isToTranslate()) {
+ if (node.isToTranslate() && (!((YangDeviationHolder) node)
+ .isModuleForDeviation())) {
JavaCodeGeneratorUtil.generateJavaCode(node, yangPlugin);
}
}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ChoiceCaseTranslatorTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ChoiceCaseTranslatorTest.java
index 395792a..3a1976b 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ChoiceCaseTranslatorTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ChoiceCaseTranslatorTest.java
@@ -18,9 +18,9 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
+import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
-import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IdentityTranslatorTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IdentityTranslatorTest.java
index bb02522..2835a64 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IdentityTranslatorTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IdentityTranslatorTest.java
@@ -18,6 +18,10 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
+import org.onosproject.yang.compiler.datamodel.YangIdentity;
+import org.onosproject.yang.compiler.datamodel.YangModule;
+import org.onosproject.yang.compiler.datamodel.YangNode;
+import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
@@ -26,12 +30,20 @@
import java.io.File;
import java.io.IOException;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.MODULE_NODE;
+import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.updateFilePriority;
+import static org.onosproject.yang.compiler.utils.io.YangPluginConfig.compileCode;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.deleteDirectory;
+
/**
* Translator test case for identity.
*/
public class IdentityTranslatorTest {
private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
private static final String DIR = "target/identity/";
private static final String COMP = System.getProperty("user.dir") + File
.separator + DIR;
@@ -44,7 +56,7 @@
@Test
public void processTranslator() throws IOException,
ParserException, MojoExecutionException {
- YangIoUtils.deleteDirectory(DIR);
+ deleteDirectory(DIR);
String searchDir = "src/test/resources/identityTranslator";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
@@ -54,7 +66,63 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(DIR);
utilManager.translateToJava(yangPluginConfig);
- YangPluginConfig.compileCode(COMP);
- YangIoUtils.deleteDirectory(DIR);
+ compileCode(COMP);
+ deleteDirectory(DIR);
+ }
+
+ /**
+ * Checks translation should not result in any exception.
+ *
+ * @throws MojoExecutionException
+ */
+ @Test
+ public void processMultipleLevelIdentity() throws IOException,
+ ParserException, MojoExecutionException {
+ deleteDirectory(DIR);
+ String searchDir = "src/test/resources/multipleIdentity";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ updateFilePriority(utilManager.getYangNodeSet());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ for (YangNode rootNode : utilManager.getYangNodeSet()) {
+ if (rootNode.getName().equals("test")) {
+ selfNode = 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("test"));
+
+ YangIdentity id = ((YangIdentity) yangNode.getChild());
+ assertThat(id.getName(), is("identity3"));
+
+ assertThat(id.getExtendList().get(0).getName(), is("identity2"));
+ assertThat(id.getExtendList().get(1).getName(), is("identity1"));
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(DIR);
+ utilManager.translateToJava(yangPluginConfig);
+ compileCode(COMP);
+ deleteDirectory(DIR);
}
}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileDeviationLinkingTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileDeviationLinkingTest.java
new file mode 100644
index 0000000..e1cf83f
--- /dev/null
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileDeviationLinkingTest.java
@@ -0,0 +1,551 @@
+/*
+ * 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.yang.compiler.plugin.maven;
+
+import org.junit.Test;
+import org.onosproject.yang.compiler.datamodel.YangAtomicPath;
+import org.onosproject.yang.compiler.datamodel.YangContainer;
+import org.onosproject.yang.compiler.datamodel.YangDeviateAdd;
+import org.onosproject.yang.compiler.datamodel.YangDeviateDelete;
+import org.onosproject.yang.compiler.datamodel.YangDeviateReplace;
+import org.onosproject.yang.compiler.datamodel.YangDeviation;
+import org.onosproject.yang.compiler.datamodel.YangLeaf;
+import org.onosproject.yang.compiler.datamodel.YangLeavesHolder;
+import org.onosproject.yang.compiler.datamodel.YangModule;
+import org.onosproject.yang.compiler.datamodel.YangNode;
+import org.onosproject.yang.compiler.linker.exceptions.LinkerException;
+import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
+import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yang.compiler.translator.tojava.JavaFileInfoTranslator;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.MODULE_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangStatusType.CURRENT;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.UNRESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.INT8;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
+import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.updateFilePriority;
+import static org.onosproject.yang.compiler.utils.io.YangPluginConfig.compileCode;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.deleteDirectory;
+
+
+/**
+ * Unit test case for deviation linking.
+ */
+public class InterFileDeviationLinkingTest {
+
+ private static final String DIR = "target/deviationTest/";
+ private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
+ private static final String COMP = System.getProperty("user.dir") + File
+ .separator + DIR;
+
+ /**
+ * Checks deviation not supported statement linking.
+ */
+ @Test
+ public void processDeviationNotSupportedLinking() throws IOException,
+ ParserException {
+
+ String searchDir = "src/test/resources/deviationLinking";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode refNode = null;
+ YangNode selfNode = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ updateFilePriority(utilManager.getYangNodeSet());
+
+ Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
+
+ while (yangNodeIterator.hasNext()) {
+ YangNode rootNode = yangNodeIterator.next();
+ if (rootNode.getName().equals("deviation-module")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("Test2")) {
+ refNode = rootNode;
+ }
+ }
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the deviation module info is set correctly after
+ // parsing.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("deviation-module"));
+
+ // Check whether the container is child of module
+ YangDeviation deviation = (YangDeviation) yangNode.getChild();
+ assertThat(deviation.getName(), is("/t:ospf"));
+ assertThat(deviation.getDescription(), is("\"desc\""));
+ assertThat(deviation.getReference(), is("\"ref\""));
+ assertThat(deviation.isDeviateNotSupported(), is(true));
+ List<YangAtomicPath> targetNode = deviation.getTargetNode();
+ assertThat(targetNode.get(0).getNodeIdentifier().getName(), is("ospf"));
+ assertThat(targetNode.get(0).getNodeIdentifier().getPrefix(), is("t"));
+ assertThat(deviation.getResolvableStatus(), is(UNRESOLVED));
+
+ // Check whether the base module - test information is set correctly.
+ YangModule yangRefNode = (YangModule) refNode;
+ assertThat(yangRefNode.getName(), is("Test2"));
+
+ YangNode ospfNode = yangRefNode.getChild();
+ assertThat(ospfNode.getName(), is("ospf"));
+
+ YangNode testValid = ospfNode.getNextSibling();
+ assertThat(testValid.getName(), is("valid"));
+
+ assertThat(testValid.getNextSibling(), nullValue());
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(DIR);
+ utilManager.translateToJava(yangPluginConfig);
+
+ compileCode(COMP);
+ deleteDirectory(DIR);
+
+ // 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.
+ yangRefNode = (YangModule) refNode;
+ assertThat(yangRefNode.getName(), is("Test2"));
+
+ YangNode childNode2 = yangRefNode.getChild();
+ assertThat(childNode2.getName(), is("ospf"));
+
+ testValid = childNode2.getNextSibling();
+ assertThat(testValid.getName(), is("valid"));
+
+ // Check whether the module name is set correctly.
+ yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("deviation-module"));
+
+ YangNode deviationValid = yangNode.getChild().getNextSibling()
+ .getNextSibling();
+ assertThat(deviationValid.getName(), is("valid"));
+
+ List<YangLeaf> lisfOfLeaf = ((YangLeavesHolder) deviationValid).getListOfLeaf();
+ assertThat(lisfOfLeaf.isEmpty(), is(true));
+ assertThat(deviationValid.getNextSibling(), nullValue());
+
+ assertThat(testValid.getYangSchemaNodeIdentifier(), is
+ (deviationValid.getYangSchemaNodeIdentifier()));
+
+ JavaFileInfoTranslator deviateJavaFile = ((JavaFileInfoContainer)
+ deviationValid).getJavaFileInfo();
+
+ JavaFileInfoTranslator testJavaFile = ((JavaFileInfoContainer)
+ testValid).getJavaFileInfo();
+ assertThat(testJavaFile, is(deviateJavaFile));
+ }
+
+ /**
+ * Checks deviate add statement linking.
+ */
+ @Test
+ public void processDeviationAddLinking() throws IOException,
+ ParserException {
+
+ String searchDir = "src/test/resources/deviationLinking";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode refNode = null;
+ YangNode selfNode = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ updateFilePriority(utilManager.getYangNodeSet());
+
+ Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
+
+ while (yangNodeIterator.hasNext()) {
+ YangNode rootNode = yangNodeIterator.next();
+ if (rootNode.getName().equals("deviation-module2")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("Test2")) {
+ refNode = rootNode;
+ }
+ }
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the deviation module info is set correctly after
+ // parsing.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("deviation-module2"));
+
+ // Check whether the container is child of module
+ YangDeviation deviation = (YangDeviation) yangNode.getChild();
+ assertThat(deviation.getName(), is("/t:ospf"));
+ assertThat(deviation.getDescription(), is("\"desc\""));
+ assertThat(deviation.getReference(), is("\"ref\""));
+
+ List<YangAtomicPath> targetNode = deviation.getTargetNode();
+ assertThat(targetNode.get(0).getNodeIdentifier().getName(), is("ospf"));
+ assertThat(targetNode.get(0).getNodeIdentifier().getPrefix(), is("t"));
+
+ YangDeviateAdd deviateAdd = deviation.getDeviateAdd().get(0);
+ assertThat(deviateAdd.getListOfMust().get(0).getConstraint(),
+ is("/base:system"));
+ assertThat(deviateAdd.isConfig(), is(false));
+ assertThat(deviation.getResolvableStatus(), is(UNRESOLVED));
+
+ // Check whether the base module - test information is set correctly.
+ YangModule yangRefNode = (YangModule) refNode;
+ assertThat(yangRefNode.getName(), is("Test2"));
+
+ YangNode ospfNode = yangRefNode.getChild();
+ assertThat(ospfNode.getName(), is("ospf"));
+ assertThat(((YangContainer) ospfNode).getListOfMust().isEmpty(), is(true));
+ assertThat(((YangContainer) ospfNode).isConfig(), is(true));
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(DIR);
+ utilManager.translateToJava(yangPluginConfig);
+
+ compileCode(COMP);
+ deleteDirectory(DIR);
+
+ // 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.
+ yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("deviation-module2"));
+
+ YangContainer deviationValid = ((YangContainer) yangNode.getChild()
+ .getNextSibling()
+ .getNextSibling());
+ assertThat(deviationValid.getName(), is("ospf"));
+ assertThat(deviationValid.getListOfMust().get(0).getConstraint(),
+ is("/base:system"));
+ assertThat(deviationValid.isConfig(), is(false));
+ }
+
+ /**
+ * Checks deviate delete statement linking.
+ */
+ @Test
+ public void processDeviationDeleteLinking() throws IOException,
+ ParserException {
+
+ String searchDir = "src/test/resources/deviationLinking";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode refNode = null;
+ YangNode selfNode = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ updateFilePriority(utilManager.getYangNodeSet());
+
+ Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
+
+ while (yangNodeIterator.hasNext()) {
+ YangNode rootNode = yangNodeIterator.next();
+ if (rootNode.getName().equals("deviation-module4")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("Test2")) {
+ refNode = rootNode;
+ }
+ }
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the deviation module info is set correctly after
+ // parsing.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("deviation-module4"));
+
+ // Check whether the container is child of module
+ YangDeviation deviation = (YangDeviation) yangNode.getChild();
+ assertThat(deviation.getName(), is("/t:ospf/t:process-id"));
+ assertThat(deviation.getDescription(), is("\"desc\""));
+ assertThat(deviation.getReference(), is("\"ref\""));
+
+ List<YangAtomicPath> targetNode = deviation.getTargetNode();
+ assertThat(targetNode.get(0).getNodeIdentifier().getName(), is("ospf"));
+ assertThat(targetNode.get(0).getNodeIdentifier().getPrefix(), is("t"));
+ assertThat(targetNode.get(1).getNodeIdentifier().getName(), is("process-id"));
+ assertThat(targetNode.get(1).getNodeIdentifier().getPrefix(), is("t"));
+
+ YangDeviateDelete delete = deviation.getDeviateDelete().get(0);
+ assertThat(delete.getUnits(), is("\"units\""));
+ assertThat(delete.getDefaultValueInString(), is("defaultValue"));
+ assertThat(deviation.getResolvableStatus(), is(UNRESOLVED));
+
+ // Check whether the base module - test information is set correctly.
+ YangModule yangRefNode = (YangModule) refNode;
+ assertThat(yangRefNode.getName(), is("Test2"));
+
+ YangNode ospfNode = yangRefNode.getChild();
+ assertThat(ospfNode.getName(), is("ospf"));
+ YangLeaf leaf = ((YangLeavesHolder) ospfNode).getListOfLeaf().get(0);
+ assertThat(leaf.getName(), is("process-id"));
+ assertThat(leaf.getDataType().getDataType(), is(UINT16));
+ assertThat(leaf.getUnits(), is("\"seconds\""));
+ assertThat(leaf.getStatus(), is(CURRENT));
+ assertThat(leaf.getReference(), is("\"RFC 6020\""));
+ assertThat(leaf.getDefaultValueInString(), is("1"));
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(DIR);
+ utilManager.translateToJava(yangPluginConfig);
+
+ compileCode(COMP);
+ deleteDirectory(DIR);
+
+ // 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.
+ yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("deviation-module4"));
+
+ YangContainer ospf = (YangContainer) yangNode.getChild()
+ .getNextSibling();
+ assertThat(ospf.getName(), is("ospf"));
+
+ leaf = ospf.getListOfLeaf().get(0);
+ assertThat(leaf.getName(), is("process-id"));
+ assertThat(leaf.getDataType().getDataType(), is(UINT16));
+ assertThat(leaf.getUnits(), nullValue());
+ assertThat(leaf.getDefaultValueInString(), nullValue());
+ }
+
+ /**
+ * Checks deviate replace statement linking.
+ */
+ @Test
+ public void processDeviationReplaceLinking() throws IOException,
+ ParserException {
+
+ String searchDir = "src/test/resources/deviationLinking";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode refNode = null;
+ YangNode selfNode = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ updateFilePriority(utilManager.getYangNodeSet());
+
+ Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
+
+ while (yangNodeIterator.hasNext()) {
+ YangNode rootNode = yangNodeIterator.next();
+ if (rootNode.getName().equals("deviation-module3")) {
+ selfNode = rootNode;
+ } else if (rootNode.getName().equals("Test2")) {
+ refNode = rootNode;
+ }
+ }
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the deviation module info is set correctly after
+ // parsing.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("deviation-module3"));
+
+ // Check whether the container is child of module
+ YangDeviation deviation = (YangDeviation) yangNode.getChild();
+ assertThat(deviation.getName(), is("/t:ospf/t:process-id"));
+ assertThat(deviation.getDescription(), is("\"desc\""));
+ assertThat(deviation.getReference(), is("\"ref\""));
+
+ List<YangAtomicPath> targetNode = deviation.getTargetNode();
+ assertThat(targetNode.get(0).getNodeIdentifier().getName(), is("ospf"));
+ assertThat(targetNode.get(0).getNodeIdentifier().getPrefix(), is("t"));
+ assertThat(targetNode.get(1).getNodeIdentifier().getName(), is("process-id"));
+ assertThat(targetNode.get(1).getNodeIdentifier().getPrefix(), is("t"));
+
+ YangDeviateReplace replace = deviation.getDeviateReplace().get(0);
+ assertThat(replace.getDataType().getDataType(), is(INT8));
+ assertThat(replace.getUnits(), is("\"units\""));
+ assertThat(replace.getDefaultValueInString(), is("0"));
+ assertThat(replace.isConfig(), is(true));
+ assertThat(replace.isMandatory(), is(true));
+ assertThat(replace.getMinElements().getMinElement(), is(0));
+ assertThat(replace.getMaxElements().getMaxElement(), is(3));
+ assertThat(deviation.getResolvableStatus(), is(UNRESOLVED));
+
+ // Check whether the base module - test information is set correctly.
+ YangModule yangRefNode = (YangModule) refNode;
+ assertThat(yangRefNode.getName(), is("Test2"));
+
+ YangNode ospfNode = yangRefNode.getChild();
+ assertThat(ospfNode.getName(), is("ospf"));
+ YangLeaf leaf = ((YangLeavesHolder) ospfNode).getListOfLeaf().get(0);
+ assertThat(leaf.getName(), is("process-id"));
+ assertThat(leaf.getDataType().getDataType(), is(UINT16));
+ assertThat(leaf.getUnits(), is("\"seconds\""));
+ assertThat(leaf.getStatus(), is(CURRENT));
+ assertThat(leaf.getReference(), is("\"RFC 6020\""));
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(DIR);
+ utilManager.translateToJava(yangPluginConfig);
+
+ compileCode(COMP);
+ deleteDirectory(DIR);
+
+ // 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.
+ yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("deviation-module3"));
+
+ YangContainer ospf = (YangContainer) yangNode.getChild()
+ .getNextSibling();
+ assertThat(ospf.getName(), is("ospf"));
+
+ leaf = ospf.getListOfLeaf().get(0);
+ assertThat(leaf.getName(), is("process-id"));
+ assertThat(leaf.getDataType().getDataType(), is(INT8));
+ assertThat(leaf.getUnits(), is("\"units\""));
+ assertThat(leaf.getDefaultValueInString(), is("0"));
+ assertThat(leaf.isConfig(), is(true));
+ assertThat(leaf.isMandatory(), is(true));
+ assertThat(leaf.getStatus(), is(CURRENT));
+ assertThat(leaf.getReference(), is("\"RFC 6020\""));
+ }
+
+ /**
+ * Checks whether exception is thrown when deviation target is invalid.
+ */
+ @Test(expected = LinkerException.class)
+ public void processDeviationInvalidTarget() throws IOException,
+ ParserException {
+
+ String searchDir = "src/test/resources/InvalidDeviation";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ YangNode selfNode = null;
+
+ // Create YANG node set
+ yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+
+ // Add references to import list.
+ yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+
+ updateFilePriority(utilManager.getYangNodeSet());
+
+ Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
+
+ while (yangNodeIterator.hasNext()) {
+ YangNode rootNode = yangNodeIterator.next();
+ if (rootNode.getName().equals("deviation-module5")) {
+ selfNode = rootNode;
+ }
+ }
+
+ // Check whether the node type is set properly to module.
+ assertThat(selfNode.getNodeType(), is(MODULE_NODE));
+
+ // Check whether the deviation module info is set correctly after
+ // parsing.
+ YangModule yangNode = (YangModule) selfNode;
+ assertThat(yangNode.getName(), is("deviation-module5"));
+
+ // Check whether the container is child of module
+ YangDeviation deviation = (YangDeviation) yangNode.getChild();
+ assertThat(deviation.getName(), is("/t:ospf/t:intf-id"));
+ assertThat(deviation.getDescription(), is("\"desc\""));
+ assertThat(deviation.getReference(), is("\"ref\""));
+
+ List<YangAtomicPath> targetNode = deviation.getTargetNode();
+ assertThat(targetNode.get(0).getNodeIdentifier().getName(), is("ospf"));
+ assertThat(targetNode.get(0).getNodeIdentifier().getPrefix(), is("t"));
+ assertThat(targetNode.get(1).getNodeIdentifier().getName(), is("intf-id"));
+ assertThat(targetNode.get(1).getNodeIdentifier().getPrefix(), is("t"));
+
+ // Carry out inter-file linking.
+ yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(DIR);
+ utilManager.translateToJava(yangPluginConfig);
+ }
+}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/YangJavaModelUtilsTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/YangJavaModelUtilsTest.java
index e1cad16..6612ab6 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/YangJavaModelUtilsTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/YangJavaModelUtilsTest.java
@@ -20,9 +20,9 @@
import org.hamcrest.core.Is;
import org.junit.Test;
import org.onosproject.yang.compiler.datamodel.YangNode;
+import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.translator.tojava.YangJavaModelUtils;
import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import java.io.IOException;
@@ -47,11 +47,9 @@
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(false, Is.is(YangJavaModelUtils.isGetSetOfRootNodeRequired(node)));
assertThat(true, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
}
if (node.getName().equals("test6")) {
- assertThat(true, Is.is(YangJavaModelUtils.isGetSetOfRootNodeRequired(node)));
assertThat(true, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
}
}
@@ -68,7 +66,6 @@
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(true, Is.is(YangJavaModelUtils.isGetSetOfRootNodeRequired(node)));
assertThat(true, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
}
}
@@ -85,7 +82,6 @@
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(true, Is.is(YangJavaModelUtils.isGetSetOfRootNodeRequired(node)));
assertThat(true, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
}
}
@@ -102,11 +98,9 @@
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(true, Is.is(YangJavaModelUtils.isGetSetOfRootNodeRequired(node)));
assertThat(false, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
}
if (node.getName().equals("test6")) {
- assertThat(true, Is.is(YangJavaModelUtils.isGetSetOfRootNodeRequired(node)));
assertThat(false, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
}
}
@@ -124,11 +118,9 @@
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(false, Is.is(YangJavaModelUtils.isGetSetOfRootNodeRequired(node)));
assertThat(false, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
}
if (node.getName().equals("test6")) {
- assertThat(true, Is.is(YangJavaModelUtils.isGetSetOfRootNodeRequired(node)));
assertThat(false, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
}
}
@@ -145,7 +137,6 @@
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(false, Is.is(YangJavaModelUtils.isGetSetOfRootNodeRequired(node)));
assertThat(false, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
}
}
@@ -163,11 +154,9 @@
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(false, Is.is(YangJavaModelUtils.isGetSetOfRootNodeRequired(node)));
assertThat(true, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
}
if (node.getName().equals("test6")) {
- assertThat(true, Is.is(YangJavaModelUtils.isGetSetOfRootNodeRequired(node)));
assertThat(true, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
}
}
@@ -185,7 +174,6 @@
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(true, Is.is(YangJavaModelUtils.isGetSetOfRootNodeRequired(node)));
assertThat(false, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
}
}
diff --git a/compiler/plugin/maven/src/test/resources/InvalidDeviation/InvalidDeviationTarget.yang b/compiler/plugin/maven/src/test/resources/InvalidDeviation/InvalidDeviationTarget.yang
new file mode 100644
index 0000000..eff4726
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/InvalidDeviation/InvalidDeviationTarget.yang
@@ -0,0 +1,16 @@
+module deviation-module5 {
+ yang-version 1;
+ namespace test:deviation5;
+ prefix On;
+ import "target" {
+ prefix "t";
+ }
+ deviation /t:ospf/t:intf-id {
+ description "desc";
+ reference "ref";
+ deviate delete {
+ units "units";
+ default "defaultValue";
+ }
+ }
+}
diff --git a/compiler/plugin/maven/src/test/resources/InvalidDeviation/deviationTarget.yang b/compiler/plugin/maven/src/test/resources/InvalidDeviation/deviationTarget.yang
new file mode 100644
index 0000000..cddfd0c
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/InvalidDeviation/deviationTarget.yang
@@ -0,0 +1,14 @@
+module target {
+ yang-version 1;
+ namespace "test:deviation";
+ prefix test;
+ container ospf {
+ leaf process-id {
+ type "uint16";
+ units "seconds";
+ status current;
+ reference "RFC 6020";
+ default "1";
+ }
+ }
+}
\ No newline at end of file
diff --git a/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationAddStatement.yang b/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationAddStatement.yang
new file mode 100644
index 0000000..5aa8ba5
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationAddStatement.yang
@@ -0,0 +1,22 @@
+module deviation-module2 {
+ yang-version 1;
+ namespace test:deviation2;
+ prefix On;
+ import "Test2" {
+ prefix "t";
+ }
+ deviation /t:ospf {
+ description "desc";
+ reference "ref";
+ deviate add {
+ must "/base:system";
+ config "false";
+ }
+ }
+
+ deviation /t:valid/t:invalid-interval {
+ description "desc";
+ reference "ref";
+ deviate not-supported;
+ }
+}
diff --git a/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationDeleteStatement.yang b/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationDeleteStatement.yang
new file mode 100644
index 0000000..e129726
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationDeleteStatement.yang
@@ -0,0 +1,16 @@
+module deviation-module4 {
+ yang-version 1;
+ namespace test:deviation4;
+ prefix On;
+ import "Test2" {
+ prefix "t";
+ }
+ deviation /t:ospf/t:process-id {
+ description "desc";
+ reference "ref";
+ deviate delete {
+ units "units";
+ default "defaultValue";
+ }
+ }
+}
diff --git a/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationNotSupported.yang b/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationNotSupported.yang
new file mode 100644
index 0000000..3cce4c5
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationNotSupported.yang
@@ -0,0 +1,19 @@
+module deviation-module {
+ yang-version 1;
+ namespace test:deviation;
+ prefix On;
+ import "Test2" {
+ prefix "t";
+ }
+ deviation /t:ospf {
+ description "desc";
+ reference "ref";
+ deviate not-supported;
+ }
+
+ deviation /t:valid/t:invalid-interval {
+ description "desc";
+ reference "ref";
+ deviate not-supported;
+ }
+}
diff --git a/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationReplaceStatement.yang b/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationReplaceStatement.yang
new file mode 100644
index 0000000..6ed6545
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationReplaceStatement.yang
@@ -0,0 +1,21 @@
+module deviation-module3 {
+ yang-version 1;
+ namespace test:deviation3;
+ prefix On;
+ import "Test2" {
+ prefix "t";
+ }
+ deviation /t:ospf/t:process-id {
+ description "desc";
+ reference "ref";
+ deviate replace {
+ type int8;
+ units "units";
+ default "0";
+ config "true";
+ mandatory "true";
+ min-elements 0;
+ max-elements 3;
+ }
+ }
+}
diff --git a/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationTarget.yang b/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationTarget.yang
new file mode 100644
index 0000000..e072c08
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/deviationLinking/DeviationTarget.yang
@@ -0,0 +1,23 @@
+module Test2 {
+ yang-version 1;
+ namespace "test2:deviation";
+ prefix test;
+ container ospf {
+ leaf process-id {
+ type "uint16";
+ units "seconds";
+ status current;
+ reference "RFC 6020";
+ default "1";
+ }
+ }
+
+ container valid {
+ leaf invalid-interval {
+ type "uint16";
+ units "seconds";
+ status current;
+ reference "RFC 6020";
+ }
+ }
+}
\ No newline at end of file
diff --git a/compiler/plugin/maven/src/test/resources/multipleIdentity/test.yang b/compiler/plugin/maven/src/test/resources/multipleIdentity/test.yang
new file mode 100644
index 0000000..05b4875
--- /dev/null
+++ b/compiler/plugin/maven/src/test/resources/multipleIdentity/test.yang
@@ -0,0 +1,21 @@
+module test {
+ namespace "identitytest";
+ prefix test ;
+
+ identity identity3;
+
+ identity identity2 {
+ base "identity3";
+ }
+
+ identity identity1 {
+ base "identity2";
+ }
+ container node {
+ leaf node-id{
+ type identityref {
+ base "identity1";
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/model/pom.xml b/model/pom.xml
index 73403f1..36c2f69 100644
--- a/model/pom.xml
+++ b/model/pom.xml
@@ -39,6 +39,12 @@
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/model/src/main/java/org/onosproject/yang/model/DataNode.java b/model/src/main/java/org/onosproject/yang/model/DataNode.java
index 257b5de..d927455 100644
--- a/model/src/main/java/org/onosproject/yang/model/DataNode.java
+++ b/model/src/main/java/org/onosproject/yang/model/DataNode.java
@@ -28,7 +28,7 @@
*
* @return node schema identifier
*/
- SchemaIdentifier identifier();
+ SchemaId identifier();
/**
* Returns the type of node.
diff --git a/model/src/main/java/org/onosproject/yang/model/KeyLeaf.java b/model/src/main/java/org/onosproject/yang/model/KeyLeaf.java
new file mode 100644
index 0000000..6d782e4
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/KeyLeaf.java
@@ -0,0 +1,68 @@
+/*
+ * 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.yang.model;
+
+/**
+ * Represents the List's key leaf value.
+ */
+public class KeyLeaf {
+ private SchemaId leafSchema;
+ private Object leafVal;
+
+ private KeyLeaf() {
+
+ }
+
+ /**
+ * Constructs a key leaf with all the identifier and value initialized.
+ *
+ * @param name name of the leaf
+ * @param nameSpace namespace of leaf
+ * @param leafVal value of leaf
+ */
+ public KeyLeaf(String name, String nameSpace, Object leafVal) {
+ leafSchema = new SchemaId(name, nameSpace);
+ this.leafVal = leafVal;
+ }
+
+ /**
+ * Returns the node schema schemaId.
+ *
+ * @return node schema schemaId
+ */
+ public SchemaId leafSchema() {
+ return leafSchema;
+ }
+
+ /**
+ * Returns value contained in leaf node.
+ *
+ * @return value contained in leaf node
+ */
+ public Object leafValue() {
+ return leafVal;
+ }
+
+ /**
+ * Returns value as string, for usage in serializers.
+ *
+ * @return string representation of value
+ */
+ public String leafValAsString() {
+ return leafVal.toString();
+ }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafListKey.java b/model/src/main/java/org/onosproject/yang/model/LeafListKey.java
new file mode 100644
index 0000000..904d6bd
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/LeafListKey.java
@@ -0,0 +1,86 @@
+/*
+ * 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.yang.model;
+
+/**
+ * Representation of an entity which identifies a uniquely branching
+ * leaf-list entry corresponding to a multi instance leaf schema.
+ */
+public class LeafListKey extends NodeKey<LeafListKey>
+ implements Comparable<LeafListKey> {
+ private Object val;
+
+ /**
+ * Create object from builder.
+ *
+ * @param builder initialized builder
+ */
+ private LeafListKey(LeafListKeyBuilder builder) {
+ super(builder);
+ val = builder.val;
+ }
+
+ /**
+ * Returns value of node, this is only valid for multi-instance leaf, node.
+ *
+ * @return value maintained in the node
+ */
+ Object value() {
+ return val;
+ }
+
+ /**
+ * Returns value as string, for usage in serializers.
+ *
+ * @return string representation of value
+ */
+ String asString() {
+ return val.toString();
+ }
+
+ public static class LeafListKeyBuilder
+ extends NodeKeyBuilder<LeafListKeyBuilder> {
+
+ private Object val;
+
+ /**
+ * constructor used while constructing the key from scratch.
+ */
+ public LeafListKeyBuilder() {
+
+ }
+
+ /**
+ * Adds the value for for the leaf list node identifier.
+ *
+ * @param val leaf list value
+ */
+ LeafListKeyBuilder value(Object val) {
+ this.val = val;
+ return this;
+ }
+
+ /**
+ * Creates a leaf list entry identifier.
+ *
+ * @return leaf list entry identifier
+ */
+ public LeafListKey build() {
+ return new LeafListKey(this);
+ }
+ }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ListKey.java b/model/src/main/java/org/onosproject/yang/model/ListKey.java
new file mode 100644
index 0000000..87107fc
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ListKey.java
@@ -0,0 +1,97 @@
+/*
+ * 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.yang.model;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Represents an entity which identifies a unique branching node
+ * corresponding to a multi instance schema definition.
+ */
+public class ListKey extends NodeKey<ListKey> implements Comparable<ListKey> {
+
+ private List<KeyLeaf> keyLeafs;
+
+ /**
+ * Create object from builder.
+ *
+ * @param builder initialized builder
+ */
+ private ListKey(ListKeyBuilder builder) {
+ super(builder);
+ keyLeafs = builder.keyLeafs;
+ }
+
+ /**
+ * Returns the list of key leaf nodes of a multi instance node, which
+ * uniquely identifies the branching node entry corresponding to a multi
+ * instance schema definition.
+ *
+ * @return List of key leaf nodes
+ */
+ List<KeyLeaf> keyLeafs() {
+ return keyLeafs;
+ }
+
+ public int compareTo(ListKey o) {
+ //TODO: implement me
+ return 0;
+ }
+
+ public static class ListKeyBuilder extends NodeKeyBuilder<ListKeyBuilder> {
+ private List<KeyLeaf> keyLeafs = new LinkedList<>();
+
+ /**
+ * used to construct the key from scratch.
+ */
+ public ListKeyBuilder() {
+
+ }
+
+ /**
+ * used to construct a key from an existing node key.
+ *
+ * @param base existing node key
+ */
+ public ListKeyBuilder(NodeKeyBuilder base) {
+ super(base);
+ }
+
+ /**
+ * Adds the key leaf for the list resource.
+ *
+ * @param name key leaf name
+ * @param nameSpace key laef namespace
+ * @param val value of key
+ */
+ void addKeyLeaf(String name, String nameSpace, Object val) {
+ KeyLeaf keyLeaf = new KeyLeaf(name, nameSpace, val);
+ keyLeafs.add(keyLeaf);
+ }
+
+ /**
+ * Creates the list key object.
+ *
+ * @return list key
+ */
+ public ListKey build() {
+ return new ListKey(this);
+ }
+ }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelConstants.java b/model/src/main/java/org/onosproject/yang/model/ModelConstants.java
new file mode 100644
index 0000000..4c24cdd
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ModelConstants.java
@@ -0,0 +1,27 @@
+/*
+ * 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.yang.model;
+
+/**
+ * Constants used in model package.
+ */
+final class ModelConstants {
+ static final String INCOMPLETE_SCHEMA_INFO = "Schema info is not complete";
+ static final String LEAF_IS_TERMINAL = "Leaf must be the terminal node";
+ static final String NON_KEY_LEAF = "Leaf list is not a key of list";
+ static final String NO_KEY_SET = "Resource Identifier is empty";
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelException.java b/model/src/main/java/org/onosproject/yang/model/ModelException.java
new file mode 100644
index 0000000..460991c
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ModelException.java
@@ -0,0 +1,55 @@
+/*
+ * 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.yang.model;
+
+/**
+ * Represents the Model Exception.
+ */
+public class ModelException extends RuntimeException {
+
+ private static final long serialVersionUID = 20161223L;
+
+ /**
+ * Creates a new YANG tool exception with given message.
+ *
+ * @param message the detail of exception in string
+ */
+ public ModelException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new tool exception from given message and cause.
+ *
+ * @param message the detail of exception in string
+ * @param cause underlying cause of the error
+ */
+ public ModelException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new tool exception from cause.
+ *
+ * @param cause underlying cause of the error
+ */
+ public ModelException(final Throwable cause) {
+ super(cause);
+ }
+
+}
+
diff --git a/model/src/main/java/org/onosproject/yang/model/MultiInstanceLeafKey.java b/model/src/main/java/org/onosproject/yang/model/MultiInstanceLeafKey.java
deleted file mode 100644
index 8be8bbe..0000000
--- a/model/src/main/java/org/onosproject/yang/model/MultiInstanceLeafKey.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yang.model;
-
-/**
- * Abstraction of an entity which identifies a uniquely branching leaf
- * corresponding to a multi instance leaf schema.
- */
-public interface MultiInstanceLeafKey extends NodeKey {
-
- /**
- * Returns value of node, this is only valid for multi-instance leaf, node.
- *
- * @return value maintained in the node
- */
- Object value();
-
- /**
- * Returns value as string, for usage in serializers.
- *
- * @return string representation of value
- */
- String asString();
-}
diff --git a/model/src/main/java/org/onosproject/yang/model/MultiInstanceNodeKey.java b/model/src/main/java/org/onosproject/yang/model/MultiInstanceNodeKey.java
deleted file mode 100644
index 5677891..0000000
--- a/model/src/main/java/org/onosproject/yang/model/MultiInstanceNodeKey.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.onosproject.yang.model;
-
-import java.util.List;
-
-/**
- * Abstraction of an entity which identifies a unique branching node
- * corresponding to a multi instance schema definition.
- */
-public interface MultiInstanceNodeKey extends NodeKey {
-
- /**
- * Returns the list of key leaf nodes of a multi instance node, which
- * uniquely identifies the branching node entry corresponding to a multi
- * instance schema definition.
- *
- * @return List of key leaf nodes
- */
- List<LeafNode> keyLeafs();
-}
diff --git a/model/src/main/java/org/onosproject/yang/model/NodeKey.java b/model/src/main/java/org/onosproject/yang/model/NodeKey.java
index 1f6dbfe..8e83e49 100644
--- a/model/src/main/java/org/onosproject/yang/model/NodeKey.java
+++ b/model/src/main/java/org/onosproject/yang/model/NodeKey.java
@@ -17,11 +17,25 @@
package org.onosproject.yang.model;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.yang.model.ModelConstants.INCOMPLETE_SCHEMA_INFO;
+
/**
* Abstraction of an entity which identifies a node uniquely among its
* siblings.
*/
-public interface NodeKey extends Comparable<NodeKey> {
+public class NodeKey<E extends NodeKey> implements Comparable<E> {
+
+ private SchemaId schemaId;
+
+ /**
+ * Create object from builder.
+ *
+ * @param builder initialized builder
+ */
+ protected NodeKey(NodeKeyBuilder builder) {
+ schemaId = builder.schemaId;
+ }
/**
* Returns the schema identifier as minimal key required to identify a
@@ -29,5 +43,68 @@
*
* @return schema identifier of a key
*/
- SchemaIdentifier identifier();
+ public SchemaId schemaId() {
+ return schemaId;
+ }
+
+ @Override
+ public int compareTo(NodeKey o) {
+ //TODO: implement me
+ return 0;
+ }
+
+ public static class NodeKeyBuilder<B extends NodeKeyBuilder<B>> {
+ private SchemaId schemaId;
+
+ /**
+ * Create the node key from scratch.
+ */
+ public NodeKeyBuilder() {
+
+ }
+
+ /**
+ * Support the derived object to inherit from existing node key builder.
+ *
+ * @param base existing node key builder
+ */
+ protected NodeKeyBuilder(NodeKeyBuilder base) {
+ checkNotNull(base.schemaId, INCOMPLETE_SCHEMA_INFO);
+ schemaId = base.schemaId;
+ }
+
+ /**
+ * set the schema identifier.
+ *
+ * @param schema schema identifier
+ * @return current builder
+ */
+ public B schemaId(SchemaId schema) {
+ schemaId = schema;
+ return (B) this;
+ }
+
+ /**
+ * set the schema identifier.
+ *
+ * @param name name of the node
+ * @param nameSpace name space of the node
+ * @return current builder
+ */
+ public B schemaId(String name, String nameSpace) {
+ schemaId = new SchemaId(name, nameSpace);
+ return (B) this;
+ }
+
+ /**
+ * construct the node key.
+ *
+ * @return node key
+ */
+ public NodeKey build() {
+ checkNotNull(schemaId.name(), INCOMPLETE_SCHEMA_INFO);
+ checkNotNull(schemaId.namespace(), INCOMPLETE_SCHEMA_INFO);
+ return new NodeKey(this);
+ }
+ }
}
diff --git a/model/src/main/java/org/onosproject/yang/model/ResourceId.java b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
new file mode 100644
index 0000000..7f99c8c
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
@@ -0,0 +1,154 @@
+/*
+ * 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.yang.model;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.onosproject.yang.model.ModelConstants.LEAF_IS_TERMINAL;
+import static org.onosproject.yang.model.ModelConstants.NON_KEY_LEAF;
+import static org.onosproject.yang.model.ModelConstants.NO_KEY_SET;
+
+/**
+ * Representation of an entity which identifies a resource in the logical tree
+ * data store. It is a list of node keys to identify the branch point
+ * hierarchy to reach a resource in the instance tree.
+ */
+
+public class ResourceId {
+ private List<NodeKey> nodeKeyList;
+
+ /**
+ * Create object from builder.
+ *
+ * @param builder initialized builder
+ */
+ private ResourceId(Builder builder) {
+ nodeKeyList = builder.nodeKeyList;
+ }
+
+ /**
+ * Returns the list of node key used to uniquely identify the branch in the
+ * logical tree starting from root.
+ *
+ * @return node key uniquely identifying the branch
+ */
+ public List<NodeKey> nodeKeys() {
+ return nodeKeyList;
+ }
+
+ /**
+ * Retrieves a new resource builder.
+ *
+ * @return resource builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder to construct resource identifier.
+ */
+ public static class Builder {
+
+ private List<NodeKey> nodeKeyList = new LinkedList<>();
+ private NodeKey.NodeKeyBuilder curKeyBuilder = null;
+
+ /**
+ * Adds the descendent node's schema identity.
+ *
+ * @param name name of descendent node
+ * @param nameSpace name space pf descendent node
+ * @return updated builder pointing to the specified schema location
+ */
+ public Builder addBranchPointSchema(String name, String nameSpace) {
+ if (curKeyBuilder != null) {
+ if (curKeyBuilder instanceof LeafListKey.LeafListKeyBuilder) {
+ throw new ModelException(LEAF_IS_TERMINAL);
+ }
+ nodeKeyList.add(curKeyBuilder.build());
+ }
+
+ curKeyBuilder = new NodeKey.NodeKeyBuilder();
+ curKeyBuilder.schemaId(name, nameSpace);
+
+ return this;
+ }
+
+ /**
+ * Adds a multi instance attribute's node identity.
+ *
+ * @param name name of the leaf list
+ * @param nameSpace name space of leaf list
+ * @param val value of attribute to identify the instance
+ * @return updated builder pointing to the specific attribute
+ * value instance
+ */
+ public Builder addLeafListBranchPoint(String name, String nameSpace,
+ Object val) {
+ LeafListKey.LeafListKeyBuilder leafListKeyBuilder;
+ if (curKeyBuilder instanceof LeafListKey.LeafListKeyBuilder) {
+ throw new ModelException(NON_KEY_LEAF);
+ }
+ leafListKeyBuilder = new LeafListKey.LeafListKeyBuilder()
+ .schemaId(name, nameSpace).value(val);
+
+ curKeyBuilder = leafListKeyBuilder;
+ return this;
+ }
+
+ /**
+ * Adds a multi instance nodes key attribute value to identify
+ * the branch point of instance tree.
+ *
+ * @param name name of the key attribute
+ * @param nameSpace name space of key attribute
+ * @param val value of the key leaf, to match in the list entry
+ * @return updated builder with list branching information
+ */
+ public Builder addKeyLeaf(String name, String nameSpace, Object val) {
+ ListKey.ListKeyBuilder listKeyBuilder;
+ if (!(curKeyBuilder instanceof ListKey.ListKeyBuilder)) {
+ if (curKeyBuilder instanceof LeafListKey.LeafListKeyBuilder) {
+ throw new ModelException(LEAF_IS_TERMINAL);
+ }
+
+ listKeyBuilder = new ListKey.ListKeyBuilder(curKeyBuilder);
+ } else {
+ listKeyBuilder = (ListKey.ListKeyBuilder) curKeyBuilder;
+ }
+
+ listKeyBuilder.addKeyLeaf(name, nameSpace, val);
+ curKeyBuilder = listKeyBuilder;
+ return this;
+ }
+
+ /**
+ * Builds a resource identifier to based on set path information of
+ * the resource.
+ *
+ * @return built resource identifier
+ */
+ public ResourceId build() {
+ if (curKeyBuilder == null) {
+ throw new ModelException(NO_KEY_SET);
+ }
+ nodeKeyList.add(curKeyBuilder.build());
+ return new ResourceId(this);
+ }
+ }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ResourceIdentifier.java b/model/src/main/java/org/onosproject/yang/model/ResourceIdentifier.java
deleted file mode 100644
index fb40c48..0000000
--- a/model/src/main/java/org/onosproject/yang/model/ResourceIdentifier.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yang.model;
-
-/**
- * Abstraction of an entity which identifies a resource in the logical tree
- * data store. It is a recursive approach to locate a resource in the
- * instance tree.
- */
-
- /*-- Assume the below schema
- * container node1{
- * list node2{
- * key node3;
- * leaf node3{
- * type string;
- * }
- * leaf-list node4{
- * type string
- * }
- * }
- * }
- * Assume an instance tree as below
- * node1
- * |----node2
- * | |----node3
- * | | |----"val1"
- * | |----node4
- * | | |----"val2"
- * | | |----"val3"
- * |----node2
- * | |----node3
- * | | |----"val4"
- * | |----node4
- * | | |----"val5"
- * | | |----"val6"
- * <p>
- *
- * Assume a resource identifier variable a is pointing to node4 with val3,
- * then its value is as follows
- *
- * //identifies node1
- * NodeKey containerKey = a.nodeKey();
- * SchemaIdentifier schemaId = containerKey.identifier();//"node1"
- *
- * //identifies a specific entry of list node2
- * MultiInstanceNodeKey listKey;
- * listKey = (MultiInstanceNodeKey) a.descendentIdentifier().nodeKey();
- * schemaId = listKey.identifier();//"node2"
- * List<LeafNode> keyLeaves = listKey.keyLeafs();
- * LeafNode key = keyLeaves.get(0);
- * schemaId = key.identifier();//"node3"
- * String keyVal = key.asString();//"val1"
- *
- * //identifiers a specific entry of leaf-list node4
- * MultiInstanceLeafKey leafKey;
- * leafKey = (MultiInstanceLeafKey) a.descendentIdentifier().
- * descendentIdentifier().nodeKey();
- * schemaId = leafKey.identifier();//"node4"
- * keyVal = leafKey.asString();//val3
- *
- * ResourceIdentifier termination = a.descendentIdentifier().descendentIdentifier().
- * descendentIdentifier(); //null
- *
- */
-public interface ResourceIdentifier {
- /**
- * Returns the node key used to uniquely identify the branch in the
- * logical tree.
- *
- * @return node key uniquely identifying the branch
- */
- NodeKey nodeKey();
-
- /**
- * Returns the descendent resource identifier.
- *
- * @return descendent resource identifier
- */
- ResourceIdentifier descendentIdentifier();
-}
diff --git a/model/src/main/java/org/onosproject/yang/model/SchemaIdentifier.java b/model/src/main/java/org/onosproject/yang/model/SchemaId.java
similarity index 61%
rename from model/src/main/java/org/onosproject/yang/model/SchemaIdentifier.java
rename to model/src/main/java/org/onosproject/yang/model/SchemaId.java
index a180afb..e25f8b4 100644
--- a/model/src/main/java/org/onosproject/yang/model/SchemaIdentifier.java
+++ b/model/src/main/java/org/onosproject/yang/model/SchemaId.java
@@ -16,18 +16,38 @@
package org.onosproject.yang.model;
+import static org.onosproject.yang.model.ModelConstants.INCOMPLETE_SCHEMA_INFO;
+
/**
- * Abstraction of an entity which identifies a schema node in the schema / data
- * tree.
+ * Representation of an entity which identifies a schema node in the schema /
+ * data tree.
*/
-public interface SchemaIdentifier {
+public class SchemaId {
+
+ private String name;
+ private String nameSpace;
+
+ private SchemaId() {
+
+ }
+
+ public SchemaId(String name, String nameSpace) {
+ if (name == null || nameSpace == null) {
+ throw new ModelException(INCOMPLETE_SCHEMA_INFO);
+ }
+ this.name = name;
+ this.nameSpace = nameSpace;
+ }
+
/**
* Returns node schema name. This is mandatory to identify node according
* to schema.
*
* @return node name
*/
- String name();
+ String name() {
+ return name;
+ }
/**
* Returns node's namespace. This is mandatory serializers must translate
@@ -35,5 +55,7 @@
*
* @return node's namespace
*/
- String namespace();
+ String namespace() {
+ return nameSpace;
+ }
}
diff --git a/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java b/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
new file mode 100644
index 0000000..7a4bb62
--- /dev/null
+++ b/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2016. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+ * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
+ * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
+ * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
+ * Vestibulum commodo. Ut rhoncus gravida arcu.
+ */
+
+package org.onosproject.yang.model;
+
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test resource id
+ */
+
+public class ResourceIdTest {
+
+ @Test
+ public void resourceIdConstruction() {
+ String sampleResId = "/card=8/port=5,eth/stats";
+ String[] resourcePath = sampleResId.split("/");
+
+ ResourceId.Builder resBldr = new ResourceId.Builder();
+
+ int i = 0;
+ int j;
+ while (i < resourcePath.length) {
+ if (resourcePath[i].equals("")) {
+ i++;
+ continue;
+ }
+
+ String[] nameValue = resourcePath[i].split("=");
+ resBldr.addBranchPointSchema(nameValue[0], "testNameSpace");
+ if (nameValue.length == 1) {
+ i++;
+ continue;
+ }
+
+ String[] keys = nameValue[1].split(",");
+
+ j = 0;
+ while (j < keys.length) {
+ //TODO: get schema name of key using YANG runtime
+ String keyName = getKeyName(nameValue[0], j);
+ resBldr.addKeyLeaf(keyName, "testNameSpace", keys[j]);
+ j++;
+ }
+ i++;
+ }
+
+ ResourceId res = resBldr.build();
+ List<NodeKey> keys = res.nodeKeys();
+ assertEquals("invalid augmented node created", "card",
+ keys.get(0).schemaId().name());
+ assertEquals("invalid augmented node created", ListKey.class,
+ keys.get(0).getClass());
+ ListKey listKey = (ListKey) keys.get(0);
+ assertEquals("invalid augmented node created", "slot",
+ listKey.keyLeafs().get(0).leafSchema().name());
+ }
+
+ private String getKeyName(String s, int j) {
+ if (s.equals("card")) {
+ return "slot";
+ }
+ if (s.equals("port")) {
+ if (j == 0) {
+ return "portno";
+ }
+ }
+ return "type";
+ }
+
+}