[ONOS-4350] Inter Jar dependency implementation and code restructuring.
Change-Id: Iacac75e4187aed93ce1754c170a9c19707e5b8c3
diff --git a/utils/yangutils/datamodel/pom.xml b/utils/yangutils/datamodel/pom.xml
new file mode 100644
index 0000000..9fb30d1
--- /dev/null
+++ b/utils/yangutils/datamodel/pom.xml
@@ -0,0 +1,35 @@
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yangutils</artifactId>
+ <version>1.7.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>yangutils-datamodel</artifactId>
+ <version>1.7.0-SNAPSHOT</version>
+ <name>onos-yang-utils-datamodel</name>
+ <packaging>jar</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/CollisionDetector.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/CollisionDetector.java
new file mode 100644
index 0000000..ad6a904
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/CollisionDetector.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/**
+ * Abstraction of YANG collision function. Abstracted to unify the collision
+ * detection functionality.
+ */
+public interface CollisionDetector {
+ /**
+ * Checks for the colliding child.
+ *
+ * @param identifierName name of identifier for which collision to be
+ * checked
+ * @param dataType type of the YANG construct for which collision to be
+ * checked
+ * @throws DataModelException if there is any collision in YANG rules in
+ * parsed data, corresponding exception should be thrown
+ */
+ void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException;
+
+ /**
+ * Check for the self collision.
+ *
+ * @param identifierName name of identifier for which collision to be
+ * checked
+ * @param dataType type of the YANG construct for which collision to be
+ * checked
+ * @throws DataModelException if there is any collision in YANG rules in
+ * parsed data, corresponding exception should be thrown
+ */
+ void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException;
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/LocationInfo.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/LocationInfo.java
new file mode 100644
index 0000000..edd8849
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/LocationInfo.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+/**
+ * Abstraction of location information, this is used during resolution is
+ * carried out and line/character position in line is required to point
+ * out the error location in YANG file.
+ */
+public interface LocationInfo {
+
+ /**
+ * Returns the line number YANG construct in file.
+ *
+ * @return the line number YANG construct in file
+ */
+ int getLineNumber();
+
+ /**
+ * Returns the character position in line.
+ *
+ * @return the character position in line
+ */
+ int getCharPosition();
+
+ /**
+ * Sets line number of YANG construct.
+ *
+ * @param lineNumber the line number of YANG construct in file
+ */
+ void setLineNumber(int lineNumber);
+
+ /**
+ * Sets character position of YANG construct.
+ *
+ * @param charPositionInLine character position of YANG construct in file
+ */
+ void setCharPosition(int charPositionInLine);
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/Resolvable.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/Resolvable.java
new file mode 100644
index 0000000..571873b
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/Resolvable.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.yangutils.datamodel;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
+
+/**
+ * Abstraction of YANG resolvable information. Abstracted to obtain the
+ * information required for linking resolution.
+ */
+public interface Resolvable {
+
+ /**
+ * Returns the status of resolution. If completely resolved returns enum
+ * value "RESOLVED", if not returns "UNRESOLVED", in case reference of
+ * grouping/typedef is added to uses/type but it's not resolved
+ * "INTRA_FILE_RESOLVED" is returned.
+ *
+ * @return status of resolution
+ */
+ ResolvableStatus getResolvableStatus();
+
+ /**
+ * Set the status of type/uses resolution. If completely resolved set enum
+ * value "RESOLVED", if not set it to "UNRESOLVED", in case reference of
+ * grouping/typedef is added to uses/type but it's not resolved
+ * "INTRA_FILE_RESOLVED" should be set.
+ *
+ * @param resolvableStatus status of resolution
+ */
+ void setResolvableStatus(ResolvableStatus resolvableStatus);
+
+ /**
+ * Resolves the linking.
+ *
+ * @throws DataModelException data model exception
+ */
+ void resolve()
+ throws DataModelException;
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
new file mode 100644
index 0000000..9521f41
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+/**
+ * Type of the resolvable info.
+ */
+public enum ResolvableType {
+
+ /**
+ * Identifies the derived data type.
+ */
+ YANG_DERIVED_DATA_TYPE,
+
+ /**
+ * Identifies the uses.
+ */
+ YANG_USES
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/RpcNotificationContainer.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/RpcNotificationContainer.java
new file mode 100644
index 0000000..2d29f9e
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/RpcNotificationContainer.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+/**
+ * Represents class having rpc and notification.
+ */
+public interface RpcNotificationContainer {
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppErrorInfo.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppErrorInfo.java
new file mode 100644
index 0000000..671aa08
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppErrorInfo.java
@@ -0,0 +1,48 @@
+/*Copyright 2016.year Open Networking Laboratory
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.*/
+package org.onosproject.yangutils.datamodel;
+
+/**
+ * Abstraction of error message and application info processing.
+ */
+public interface YangAppErrorInfo {
+
+ /**
+ * Returns the application's error message for data error.
+ *
+ * @return application's error message for data error.
+ */
+ String getGetErrorMessage();
+
+ /**
+ * Sets the application's error message for data error.
+ *
+ * @param errorMessage application's error message for data error.
+ */
+ void setErrorMessage(String errorMessage);
+
+ /**
+ * Returns the application's error tag for data error.
+ *
+ * @return application's error tag for data error.
+ */
+ String getGetErrorAppTag();
+
+ /**
+ * Sets the application's error tag for data error.
+ *
+ * @param errorMessage application's error tag for data error.
+ */
+ void setErrorAppTag(String errorMessage);
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
new file mode 100644
index 0000000..84f0173
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
@@ -0,0 +1,344 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The "augment" statement allows a module or submodule to add to the
+ * schema tree defined in an external module, or the current module and
+ * its submodules, and to add to the nodes from a grouping in a "uses"
+ * statement. The argument is a string that identifies a node in the
+ * schema tree. This node is called the augment's target node. The
+ * target node MUST be either a container, list, choice, case, input,
+ * output, or notification node. It is augmented with the nodes defined
+ * in the sub-statements that follow the "augment" statement.
+ *
+ * The argument string is a schema node identifier.
+ * If the "augment" statement is on the top level in a module or
+ * submodule, the absolute form of a schema node identifier
+ * MUST be used. If the "augment" statement is a sub-statement to the
+ * "uses" statement, the descendant form MUST be used.
+ *
+ * If the target node is a container, list, case, input, output, or
+ * notification node, the "container", "leaf", "list", "leaf-list",
+ * "uses", and "choice" statements can be used within the "augment"
+ * statement.
+ *
+ * If the target node is a choice node, the "case" statement, or a case
+ * shorthand statement can be used within the "augment" statement.
+ *
+ * If the target node is in another module, then nodes added by the
+ * augmentation MUST NOT be mandatory nodes.
+ *
+ * The "augment" statement MUST NOT add multiple nodes with the same
+ * name from the same module to the target node.
+ * The augment's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | anyxml | 7.10 | 0..n |-not supported |
+ * | case | 7.9.2 | 0..n |-child nodes |
+ * | choice | 7.9 | 0..n |-child nodes |
+ * | container | 7.5 | 0..n |-child nodes |
+ * | description | 7.19.3 | 0..1 |-string |
+ * | if-feature | 7.18.2 | 0..n |-TODO |
+ * | leaf | 7.6 | 0..n |-YangLeaf |
+ * | leaf-list | 7.7 | 0..n |-YangLeafList |
+ * | list | 7.8 | 0..n |-child nodes |
+ * | reference | 7.19.4 | 0..1 |-String |
+ * | status | 7.19.2 | 0..1 |-YangStatus |
+ * | uses | 7.12 | 0..n |-child nodes |
+ * | when | 7.19.5 | 0..1 |-TODO |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Representation of data model node to maintain information defined in YANG augment.
+ */
+public class YangAugment
+ extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
+
+ private static final long serialVersionUID = 806201602L;
+
+ /**
+ * Augment target node.
+ */
+ private String name;
+
+ /**
+ * Description of augment.
+ */
+ private String description;
+
+ /**
+ * List of leaves.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf-lists.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ /**
+ * List of node identifiers.
+ */
+ private List<YangNodeIdentifier> targetNode;
+
+ /**
+ * Reference of the YANG augment.
+ */
+ private String reference;
+
+ /**
+ * Status of the node.
+ */
+ private YangStatusType status;
+
+ /**
+ * Create a YANG augment node.
+ */
+ public YangAugment() {
+ super(YangNodeType.AUGMENT_NODE);
+ }
+
+ /**
+ * Returns the augmented node.
+ *
+ * @return the augmented node
+ */
+ public List<YangNodeIdentifier> getTargetNode() {
+ return targetNode;
+ }
+
+ /**
+ * Sets the augmented node.
+ *
+ * @param nodeIdentifiers the augmented node
+ */
+ public void setTargetNode(List<YangNodeIdentifier> nodeIdentifiers) {
+ targetNode = nodeIdentifiers;
+ }
+
+ /**
+ * 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 void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Duplicate input identifier detected, same as input \""
+ + getName() + "\"");
+ }
+ }
+
+ /**
+ * Returns the list of leaves.
+ *
+ * @return the list of leaves
+ */
+ @Override
+ public List<YangLeaf> getListOfLeaf() {
+ return listOfLeaf;
+ }
+
+ /**
+ * Sets the list of leaves.
+ *
+ * @param leafsList the list of leaf to set
+ */
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ /**
+ * Adds a leaf.
+ *
+ * @param leaf the leaf to be added
+ */
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+ if (getListOfLeaf() == null) {
+ setListOfLeaf(new LinkedList<YangLeaf>());
+ }
+
+ getListOfLeaf().add(leaf);
+ }
+
+ /**
+ * Returns the list of leaf-list.
+ *
+ * @return the list of leaf-list
+ */
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return listOfLeafList;
+ }
+
+ /**
+ * Sets the list of leaf-list.
+ *
+ * @param listOfLeafList the list of leaf-list to set
+ */
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ /**
+ * Adds a leaf-list.
+ *
+ * @param leafList the leaf-list to be added
+ */
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+ if (getListOfLeafList() == null) {
+ setListOfLeafList(new LinkedList<YangLeafList>());
+ }
+
+ getListOfLeafList().add(leafList);
+ }
+
+ /**
+ * 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 status.
+ *
+ * @return the status
+ */
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ /**
+ * Returns the type of the data as belongs-to.
+ *
+ * @return returns AUGMENT_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.AUGMENT_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Returns the target nodes name where the augmentation is being done.
+ *
+ * @return target nodes name where the augmentation is being done
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the target nodes name where the augmentation is being done.
+ *
+ * @param name target nodes name where the augmentation is being done
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugmentationHolder.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugmentationHolder.java
new file mode 100644
index 0000000..aa2b678
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugmentationHolder.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+/**
+ * Represents YANG constructs which can be augmented.
+ */
+public interface YangAugmentationHolder {
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangBelongsTo.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangBelongsTo.java
new file mode 100644
index 0000000..9cb8dde
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangBelongsTo.java
@@ -0,0 +1,219 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+import java.util.Set;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
+
+/*-
+ * Reference 6020.
+ *
+ * The "belongs-to" statement specifies the module to which the
+ * submodule belongs. The argument is an identifier that is the name of
+ * the module.
+ *
+ * A submodule MUST only be included by the module to which it belongs,
+ * or by another submodule that belongs to that module.
+ *
+ * The mandatory "prefix" sub-statement assigns a prefix for the module
+ * to which the submodule belongs. All definitions in the local
+ * submodule and any included submodules can be accessed by using the
+ * prefix.
+ *
+ * The belongs-to's sub-statements
+ *
+ * +--------------+---------+-------------+
+ * | substatement | section | cardinality |
+ * +--------------+---------+-------------+
+ * | prefix | 7.1.4 | 1 |
+ * +--------------+---------+-------------+
+ */
+
+/**
+ * Represents the belongs-to data type information.
+ */
+public class YangBelongsTo implements Parsable, LocationInfo, Serializable {
+
+ private static final long serialVersionUID = 806201639L;
+
+ /**
+ * Reference RFC 6020.
+ *
+ * The "belongs-to" statement specifies the module to which the submodule
+ * belongs. The argument is an identifier that is the name of the module.
+ */
+ private String belongsToModuleName;
+
+ /**
+ * Module node to which sub-module belongs to.
+ */
+ private YangNode moduleNode;
+
+ /**
+ * Reference RFC 6020.
+ *
+ * The mandatory "prefix" substatement assigns a prefix for the module to
+ * which the submodule belongs. All definitions in the local submodule and
+ * any included submodules can be accessed by using the prefix.
+ */
+ private String prefix;
+
+ // Error Line number.
+ private transient int lineNumber;
+
+ // Error character position.
+ private transient int charPosition;
+
+ /**
+ * Create a belongs to object.
+ */
+ public YangBelongsTo() {
+
+ }
+
+ /**
+ * Returns the belongs to module name.
+ *
+ * @return the belongs to module name
+ */
+ public String getBelongsToModuleName() {
+ return belongsToModuleName;
+ }
+
+ /**
+ * Sets the belongs to module name.
+ *
+ * @param belongsToModuleName the belongs to module name to set
+ */
+ public void setBelongsToModuleName(String belongsToModuleName) {
+ this.belongsToModuleName = belongsToModuleName;
+ }
+
+ /**
+ * Returns the prefix.
+ *
+ * @return the prefix
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * Sets the prefix.
+ *
+ * @param prefix the prefix to set
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ /**
+ * Returns the module data model node.
+ *
+ * @return the module data model node
+ */
+ public YangNode getModuleNode() {
+ return moduleNode;
+ }
+
+ /**
+ * Sets the module node.
+ *
+ * @param moduleNode module data model node
+ */
+ public void setModuleNode(YangNode moduleNode) {
+ this.moduleNode = moduleNode;
+ }
+
+ /**
+ * Returns the type of the data as belongs-to.
+ *
+ * @return ParsedDataType returns BELONGS_TO_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.BELONGS_TO_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ @Override
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ @Override
+ public int getCharPosition() {
+ return charPosition;
+ }
+
+ @Override
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ @Override
+ public void setCharPosition(int charPositionInLine) {
+ charPosition = charPositionInLine;
+ }
+
+ /**
+ * Links the belongs to with a module.
+ *
+ * @param yangNodeSet YANG file information set
+ * @throws DataModelException a violation in data model rule
+ */
+ public void linkWithModule(Set<YangNode> yangNodeSet)
+ throws DataModelException {
+ String belongsToModuleName = getBelongsToModuleName();
+ YangNode moduleNode = findReferredNode(yangNodeSet, belongsToModuleName);
+ if (moduleNode != null) {
+ if (moduleNode instanceof YangModule) {
+ setModuleNode(moduleNode);
+ return;
+ }
+ }
+ DataModelException exception = new DataModelException("YANG file error : Module " + belongsToModuleName +
+ "to which sub-module belongs to is not found.");
+ exception.setLine(getLineNumber());
+ exception.setCharPosition(getCharPosition());
+ throw exception;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangBit.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangBit.java
new file mode 100644
index 0000000..5db6b54
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangBit.java
@@ -0,0 +1,229 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*-
+ * The "bit" statement, which is a sub-statement to the "type" statement,
+ * MUST be present if the type is "bits". It is repeatedly used to
+ * specify each assigned named bit of a bits type. It takes as an
+ * argument a string that is the assigned name of the bit. It is
+ * followed by a block of sub-statements that holds detailed bit
+ * information.
+ * All assigned names in a bits type MUST be unique.
+ *
+ * The bit's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | description | 7.19.3 | 0..1 | - string |
+ * | reference | 7.19.4 | 0..1 | - string |
+ * | status | 7.19.2 | 0..1 | - YangStatus |
+ * | position | 9.7.4.2 | 0..1 | - int |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents the bit data type information.
+ */
+public class YangBit implements YangCommonInfo, Parsable, Serializable {
+
+ private static final long serialVersionUID = 806201640L;
+
+ /**
+ * Name of the bit.
+ */
+ private String bitName;
+
+ /**
+ * Description of the bit field.
+ */
+ private String description;
+
+ /**
+ * Reference info of the bit field.
+ */
+ private String reference;
+
+ /**
+ * Status of the bit field.
+ */
+ private YangStatusType status;
+
+ /**
+ * Position of the bit whose name bit is described.
+ */
+ private int position;
+
+ /**
+ * Create a YANG bit type object.
+ */
+ public YangBit() {
+
+ }
+
+ /**
+ * Returns bit name.
+ *
+ * @return the bit name
+ */
+ public String getBitName() {
+ return bitName;
+ }
+
+ /**
+ * Sets the bit name.
+ *
+ * @param bitName the bit name to set
+ */
+ public void setBitName(String bitName) {
+ this.bitName = bitName;
+ }
+
+ /**
+ * Returns description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns 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 status.
+ *
+ * @return the status
+ */
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ /**
+ * Returns bit position.
+ *
+ * @return the position
+ */
+ public int getPosition() {
+ return position;
+ }
+
+ /**
+ * Sets the bit position.
+ *
+ * @param position the position to set
+ */
+ public void setPosition(int position) {
+ this.position = position;
+ }
+
+ /**
+ * Returns the type of the data.
+ *
+ * @return ParsedDataType returns BIT_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.BIT_DATA;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangBit) {
+ final YangBit other = (YangBit) obj;
+ return Objects.equals(bitName, other.bitName);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(bitName);
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangBits.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangBits.java
new file mode 100644
index 0000000..84076dd
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangBits.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The bits built-in type represents a bit set. That is, a bits value
+ * is a set of flags identified by small integer position numbers
+ * starting at 0. Each bit number has an assigned name.
+ */
+
+/**
+ * Represents the bits data type information.
+ */
+public class YangBits implements Parsable, Serializable {
+
+ private static final long serialVersionUID = 806201641L;
+
+ // Bits information set.
+ private Set<YangBit> bitSet;
+
+ // BITS name.
+ private String bitsName;
+
+ /**
+ * Creates a YANG bits type object.
+ */
+ public YangBits() {
+ setBitSet(new HashSet<YangBit>());
+ }
+
+ /**
+ * Returns the bit set.
+ *
+ * @return the bit set
+ */
+ public Set<YangBit> getBitSet() {
+ return bitSet;
+ }
+
+ /**
+ * Sets the bit set.
+ *
+ * @param bitSet the bit set
+ */
+ private void setBitSet(Set<YangBit> bitSet) {
+ this.bitSet = bitSet;
+ }
+
+ /**
+ * Adds bit info.
+ *
+ * @param bitInfo the bit information to be added
+ * @throws DataModelException due to violation in data model rules
+ */
+ public void addBitInfo(YangBit bitInfo) throws DataModelException {
+ if (!getBitSet().add(bitInfo)) {
+ throw new DataModelException("YANG file error: Duplicate identifier detected, same as bit \""
+ + bitInfo.getBitName() + "\"");
+ }
+ }
+
+ /**
+ * Returns the type of the data.
+ *
+ * @return ParsedDataType returns BITS_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.BITS_DATA;
+ }
+
+ /**
+ * Returns the bits name.
+ *
+ * @return name of the bits
+ */
+ public String getBitsName() {
+ return bitsName;
+ }
+
+ /**
+ * Sets bits name.
+ *
+ * @param bitsName bit name to be set
+ */
+ public void setBitsName(String bitsName) {
+ this.bitsName = bitsName;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
new file mode 100644
index 0000000..a00b77d
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCase.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.yangutils.datamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_DATA;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The "case" statement is used to define branches of the choice. It takes as an
+ * argument an identifier, followed by a block of sub-statements that holds
+ * detailed case information.
+ *
+ * The identifier is used to identify the case node in the schema tree. A case
+ * node does not exist in the data tree.
+ *
+ * Within a "case" statement, the "anyxml", "choice", "container", "leaf",
+ * "list", "leaf-list", and "uses" statements can be used to define child nodes
+ * to the case node. The identifiers of all these child nodes MUST be unique
+ * within all cases in a choice. For example, the following is illegal:
+ *
+ * choice interface-type { // This example is illegal YANG
+ * case a {
+ * leaf ethernet { ... }
+ * }
+ * case b {
+ * container ethernet { ...}
+ * }
+ * }
+ *
+ * As a shorthand, the "case" statement can be omitted if the branch
+ * contains a single "anyxml", "container", "leaf", "list", or
+ * "leaf-list" statement. In this case, the identifier of the case node
+ * is the same as the identifier in the branch statement. The following
+ * example:
+ *
+ * choice interface-type {
+ * container ethernet { ... }
+ * }
+ *
+ * is equivalent to:
+ *
+ * choice interface-type {
+ * case ethernet {
+ * container ethernet { ... }
+ * }
+ * }
+ *
+ * The case identifier MUST be unique within a choice.
+ *
+ * The case's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | anyxml | 7.10 | 0..n |-not supported |
+ * | choice | 7.9 | 0..n |-child nodes |
+ * | container | 7.5 | 0..n |-child nodes |
+ * | description | 7.19.3 | 0..1 |-string |
+ * | if-feature | 7.18.2 | 0..n |-TODO |
+ * | leaf | 7.6 | 0..n |-YangLeaf |
+ * | leaf-list | 7.7 | 0..n |-YangLeafList |
+ * | list | 7.8 | 0..n |-child nodes |
+ * | reference | 7.19.4 | 0..1 |-string |
+ * | status | 7.19.2 | 0..1 |-YangStatus |
+ * | uses | 7.12 | 0..n |-child node |
+ * | when | 7.19.5 | 0..1 |-TODO |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG case.
+ */
+public class YangCase
+ extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
+
+ private static final long serialVersionUID = 806201603L;
+
+ /**
+ * Case name.
+ */
+ private String name;
+
+ // TODO: default field identification for the case
+
+ /**
+ * Description of case.
+ */
+ private String description;
+
+ /**
+ * List of leaves.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf lists.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ /**
+ * Reference of the module.
+ */
+ private String reference;
+
+ /**
+ * Status of the node.
+ */
+ private YangStatusType status;
+
+ /**
+ * Creates a choice node.
+ */
+ public YangCase() {
+ super(YangNodeType.CASE_NODE);
+ }
+
+ /**
+ * Returns the case name.
+ *
+ * @return case name
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the case name.
+ *
+ * @param name case name
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the list of leaves.
+ *
+ * @return the list of leaves
+ */
+ @Override
+ public List<YangLeaf> getListOfLeaf() {
+ return listOfLeaf;
+ }
+
+ /**
+ * Sets the list of leaves.
+ *
+ * @param leafsList the list of leaf to set
+ */
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ /**
+ * Adds a leaf.
+ *
+ * @param leaf the leaf to be added
+ */
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+ if (getListOfLeaf() == null) {
+ setListOfLeaf(new LinkedList<YangLeaf>());
+ }
+
+ getListOfLeaf().add(leaf);
+ }
+
+ /**
+ * Returns the list of leaf-list.
+ *
+ * @return the list of leaf-list
+ */
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return listOfLeafList;
+ }
+
+ /**
+ * Sets the list of leaf-list.
+ *
+ * @param listOfLeafList the list of leaf-list to set
+ */
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ /**
+ * Adds a leaf-list.
+ *
+ * @param leafList the leaf-list to be added
+ */
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+ if (getListOfLeafList() == null) {
+ setListOfLeafList(new LinkedList<YangLeafList>());
+ }
+
+ getListOfLeafList().add(leafList);
+ }
+
+ /**
+ * 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 status.
+ *
+ * @return the status
+ */
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ /**
+ * Returns the type of the data.
+ *
+ * @return returns CASE_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return CASE_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ if (!(getParent() instanceof YangChoice)) {
+ throw new DataModelException("Internal Data Model Tree Error: Invalid/Missing holder in case " +
+ getName());
+ }
+ // Traverse up in tree to ask parent choice start collision detection.
+ ((CollisionDetector) getParent()).detectCollidingChild(identifierName, dataType);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+
+ if (dataType == CASE_DATA) {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException("YANG File Error: Identifier collision detected in case \"" +
+ getName() + "\"");
+ }
+ return;
+ }
+
+ // Asks helper to detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java
new file mode 100644
index 0000000..85ba107
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java
@@ -0,0 +1,368 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE_DATA;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The "choice" statement defines a set of alternatives, only one of
+ * which may exist at any one time. The argument is an identifier,
+ * followed by a block of sub-statements that holds detailed choice
+ * information. The identifier is used to identify the choice node in
+ * the schema tree. A choice node does not exist in the data tree.
+ *
+ * A choice consists of a number of branches, defined with the "case"
+ * sub-statement. Each branch contains a number of child nodes. The
+ * nodes from at most one of the choice's branches exist at the same
+ * time.
+ *
+ * The choice's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | anyxml | 7.10 | 0..n |-not supported |
+ * | case | 7.9.2 | 0..n |-YangChoice |
+ * | config | 7.19.1 | 0..1 |-boolean |
+ * | container | 7.5 | 0..n |-child case nodes |
+ * | default | 7.9.3 | 0..1 |-string |
+ * | description | 7.19.3 | 0..1 |-string |
+ * | if-feature | 7.18.2 | 0..n |-TODO |
+ * | leaf | 7.6 | 0..n |-child case nodes |
+ * | leaf-list | 7.7 | 0..n |-child case nodes |
+ * | list | 7.8 | 0..n |-child case nodes |
+ * | mandatory | 7.9.4 | 0..1 |-string |
+ * | reference | 7.19.4 | 0..1 |-string |
+ * | status | 7.19.2 | 0..1 |-string |
+ * | when | 7.19.5 | 0..1 |-TODO |
+ * +--------------+---------+-------------+------------------+
+ */
+/**
+ * Represents data model node to maintain information defined in YANG choice.
+ */
+public class YangChoice extends YangNode
+ implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
+
+ private static final long serialVersionUID = 806201604L;
+
+ /**
+ * Name of choice.
+ */
+ private String name;
+
+ /**
+ * If the choice represents config data.
+ */
+ private boolean isConfig;
+
+ /**
+ * Reference RFC 6020.
+ *
+ * The "default" statement indicates if a case should be considered as the
+ * default if no child nodes from any of the choice's cases exist. The
+ * argument is the identifier of the "case" statement. If the "default"
+ * statement is missing, there is no default case.
+ *
+ * The "default" statement MUST NOT be present on choices where "mandatory"
+ * is true.
+ *
+ * The default case is only important when considering the default values of
+ * nodes under the cases. The default values for nodes under the default
+ * case are used if none of the nodes under any of the cases are present.
+ *
+ * There MUST NOT be any mandatory nodes directly under the default case.
+ *
+ * Default values for child nodes under a case are only used if one of the
+ * nodes under that case is present, or if that case is the default case. If
+ * none of the nodes under a case are present and the case is not the
+ * default case, the default values of the cases' child nodes are ignored.
+ *
+ * the default case to be used if no case members is present.
+ */
+ private String defaultCase;
+
+ /**
+ * Description of choice.
+ */
+ private String description;
+
+ /**
+ * Reference RFC 6020.
+ *
+ * The "mandatory" statement, which is optional, takes as an argument the
+ * string "true" or "false", and puts a constraint on valid data. If
+ * "mandatory" is "true", at least one node from exactly one of the choice's
+ * case branches MUST exist.
+ *
+ * If not specified, the default is "false".
+ *
+ * The behavior of the constraint depends on the type of the choice's
+ * closest ancestor node in the schema tree which is not a non-presence
+ * container:
+ *
+ * o If this ancestor is a case node, the constraint is enforced if any
+ * other node from the case exists.
+ *
+ * o Otherwise, it is enforced if the ancestor node exists.
+ */
+ private String mandatory;
+
+ /**
+ * Reference of the choice.
+ */
+ private String reference;
+
+ /**
+ * Status of the node.
+ */
+ private YangStatusType status;
+
+ /**
+ * Default value in string, needs to be converted to the target object,
+ * based on the type.
+ */
+ private String defaultValueInString;
+
+ /**
+ * Create a choice node.
+ */
+ public YangChoice() {
+ super(YangNodeType.CHOICE_NODE);
+ }
+
+ /**
+ * Returns the choice name.
+ *
+ * @return choice name
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the choice name.
+ *
+ * @param name choice name
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns config flag.
+ *
+ * @return the config flag
+ */
+ public boolean isConfig() {
+ return isConfig;
+ }
+
+ /**
+ * Sets config flag.
+ *
+ * @param isCfg the config flag
+ */
+ public void setConfig(boolean isCfg) {
+ isConfig = isCfg;
+ }
+
+ /**
+ * Returns the default case.
+ *
+ * @return the default case
+ */
+ public String getDefaultCase() {
+ return defaultCase;
+ }
+
+ /**
+ * Sets the default case.
+ *
+ * @param defaultCase the default case to set
+ */
+ public void setDefaultCase(String defaultCase) {
+ this.defaultCase = defaultCase;
+ }
+
+ /**
+ * Returns the mandatory status.
+ *
+ * @return the mandatory status
+ */
+ public String getMandatory() {
+ return mandatory;
+ }
+
+ /**
+ * Sets the mandatory status.
+ *
+ * @param mandatory the mandatory status
+ */
+ public void setMandatory(String mandatory) {
+ this.mandatory = mandatory;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the textual reference.
+ *
+ * @return the reference
+ */
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ /**
+ * Sets the textual reference.
+ *
+ * @param reference the reference to set
+ */
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ /**
+ * Returns the status.
+ *
+ * @return the status
+ */
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ /**
+ * Returns the default value.
+ *
+ * @return the default value
+ */
+ public String getDefaultValueInString() {
+ return defaultValueInString;
+ }
+
+ /**
+ * Sets the default value.
+ *
+ * @param defaultValueInString the default value
+ */
+ public void setDefaultValueInString(String defaultValueInString) {
+ this.defaultValueInString = defaultValueInString;
+ }
+
+ /**
+ * Returns the type of the data.
+ *
+ * @return choice data
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return CHOICE_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+
+ if (getParent() instanceof YangCase && dataType != YangConstructType.CASE_DATA) {
+ ((CollisionDetector) getParent()).detectCollidingChild(identifierName, dataType);
+ }
+ YangNode node = getChild();
+ while (node != null) {
+ if (node instanceof CollisionDetector) {
+ ((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
+ }
+ node = node.getNextSibling();
+ }
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+
+ if (dataType == CHOICE_DATA) {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Identifier collision detected in choice \"" +
+ getName() + "\"");
+ }
+ return;
+ }
+
+ YangNode node = getChild();
+ while (node != null) {
+ if (node instanceof CollisionDetector) {
+ ((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
+ }
+ node = node.getNextSibling();
+ }
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCommonInfo.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCommonInfo.java
new file mode 100644
index 0000000..89b7dc0
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCommonInfo.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+/**
+ * Abstraction of YANG entity's common meta data. Abstracted to unify the
+ * parsing and translator processing.
+ */
+public interface YangCommonInfo extends YangDesc, YangReference, YangStatus {
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
new file mode 100644
index 0000000..e23bf02
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
@@ -0,0 +1,448 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The "container" statement is used to define an interior data node in the
+ * schema tree. It takes one argument, which is an identifier, followed by a
+ * block of sub-statements that holds detailed container information.
+ *
+ * A container node does not have a value, but it has a list of child nodes in
+ * the data tree. The child nodes are defined in the container's sub-statements.
+ *
+ * Containers with Presence
+ *
+ * YANG supports two styles of containers, those that exist only for organizing
+ * the hierarchy of data nodes, and those whose presence in the configuration
+ * has an explicit meaning.
+ *
+ * In the first style, the container has no meaning of its own, existing only to
+ * contain child nodes. This is the default style.
+ *
+ * For example, the set of scrambling options for Synchronous Optical Network
+ * (SONET) interfaces may be placed inside a "scrambling" container to enhance
+ * the organization of the configuration hierarchy, and to keep these nodes
+ * together. The "scrambling" node itself has no meaning, so removing the node
+ * when it becomes empty relieves the user from performing this task.
+ *
+ * In the second style, the presence of the container itself is configuration
+ * data, representing a single bit of configuration data. The container acts as
+ * both a configuration knob and a means of organizing related configuration.
+ * These containers are explicitly created and deleted.
+ *
+ * YANG calls this style a "presence container" and it is indicated using the
+ * "presence" statement, which takes as its argument a text string indicating
+ * what the presence of the node means.
+ *
+ * The container's Substatements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | anyxml | 7.10 | 0..n | -not supported |
+ * | choice | 7.9 | 0..n | -child nodes |
+ * | config | 7.19.1 | 0..1 | -boolean |
+ * | container | 7.5 | 0..n | -child nodes |
+ * | description | 7.19.3 | 0..1 | -string |
+ * | grouping | 7.11 | 0..n | -child nodes |
+ * | if-feature | 7.18.2 | 0..n | -TODO |
+ * | leaf | 7.6 | 0..n | -YangLeaf |
+ * | leaf-list | 7.7 | 0..n | -YangLeafList |
+ * | list | 7.8 | 0..n | -child nodes |
+ * | must | 7.5.3 | 0..n | -TODO |
+ * | presence | 7.5.5 | 0..1 | -boolean |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * | typedef | 7.3 | 0..n | -child nodes |
+ * | uses | 7.12 | 0..n | -child nodes |
+ * | when | 7.19.5 | 0..1 | -TODO |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG container.
+ */
+public class YangContainer
+ extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
+
+ private static final long serialVersionUID = 806201605L;
+
+ /**
+ * Name of the container.
+ */
+ private String name;
+
+ /**
+ * If container maintains config data.
+ */
+ private Boolean isConfig;
+
+ /**
+ * Description of container.
+ */
+ private String description;
+
+ /**
+ * List of leaves contained.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf-lists contained.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ /**
+ * If it is a presence container, then the textual documentation of presence
+ * usage.
+ */
+ private String presence;
+
+ /**
+ * Reference of the module.
+ */
+ private String reference;
+
+ /**
+ * Status of the node.
+ */
+ private YangStatusType status = YangStatusType.CURRENT;
+
+ /**
+ * Create a container node.
+ */
+ public YangContainer() {
+ super(YangNodeType.CONTAINER_NODE);
+ }
+
+ /**
+ * Returns the YANG name of container.
+ *
+ * @return the name of container as defined in YANG file
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the YANG name of container.
+ *
+ * @param name the name of container as defined in YANG file
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the config flag.
+ *
+ * @return the isConfig
+ */
+ public Boolean isConfig() {
+ return isConfig;
+ }
+
+ /**
+ * Sets the config flag.
+ *
+ * @param isCfg the config flag
+ */
+ public void setConfig(boolean isCfg) {
+ isConfig = isCfg;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the list of leaves.
+ *
+ * @return the list of leaves
+ */
+ @Override
+ public List<YangLeaf> getListOfLeaf() {
+ return listOfLeaf;
+ }
+
+ /**
+ * Sets the list of leaves.
+ *
+ * @param leafsList the list of leaf to set
+ */
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ /**
+ * Adds a leaf.
+ *
+ * @param leaf the leaf to be added
+ */
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+
+ if (getListOfLeaf() == null) {
+ setListOfLeaf(new LinkedList<YangLeaf>());
+ }
+
+ getListOfLeaf().add(leaf);
+ }
+
+ /**
+ * Returns the list of leaf-list.
+ *
+ * @return the list of leaf-list
+ */
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return listOfLeafList;
+ }
+
+ /**
+ * Sets the list of leaf-list.
+ *
+ * @param listOfLeafList the list of leaf-list to set
+ */
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ /**
+ * Adds a leaf-list.
+ *
+ * @param leafList the leaf-list to be added
+ */
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+
+ if (getListOfLeafList() == null) {
+ setListOfLeafList(new LinkedList<YangLeafList>());
+ }
+
+ getListOfLeafList().add(leafList);
+ }
+
+ /**
+ * Returns the presence string if present.
+ *
+ * @return the presence
+ */
+ public String getPresence() {
+ return presence;
+ }
+
+ /**
+ * Sets the presence string.
+ *
+ * @param presence the presence flag
+ */
+ public void setPresence(String presence) {
+ this.presence = presence;
+ }
+
+ /**
+ * 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 status.
+ *
+ * @return the status
+ */
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ /**
+ * Returns the type of the data.
+ *
+ * @return returns CONTAINER_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.CONTAINER_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ List<YangLeaf> leaves = getListOfLeaf();
+ List<YangLeafList> leafLists = getListOfLeafList();
+
+ setDefaultConfigValueToChild(leaves, leafLists);
+ validateConfig(leaves, leafLists);
+ }
+
+ /**
+ * Sets the config's value to all leaf if leaf's config statement is not
+ * specified.
+ *
+ * @param leaves list of leaf attributes of container
+ * @param leafLists list of leaf-list attributes of container
+ */
+ private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) {
+
+ /*
+ * If "config" is not specified, the default is the same as the parent
+ * schema node's "config" value.
+ */
+ if (leaves != null) {
+ for (YangLeaf leaf : leaves) {
+ if (leaf.isConfig() == null) {
+ leaf.setConfig(isConfig);
+ }
+ }
+ }
+
+ /*
+ * If "config" is not specified, the default is the same as the parent
+ * schema node's "config" value.
+ */
+ if (leafLists != null) {
+ for (YangLeafList leafList : leafLists) {
+ if (leafList.isConfig() == null) {
+ leafList.setConfig(isConfig);
+ }
+ }
+ }
+ }
+
+ /**
+ * Validates config statement of container.
+ *
+ * @param leaves list of leaf attributes of container
+ * @param leafLists list of leaf-list attributes of container
+ * @throws DataModelException a violation of data model rules
+ */
+ private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists)
+ throws DataModelException {
+
+ /*
+ * If a node has "config" set to "false", no node underneath it can have
+ * "config" set to "true".
+ */
+ if (!isConfig && leaves != null) {
+ for (YangLeaf leaf : leaves) {
+ if (leaf.isConfig()) {
+ throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " +
+ "it can have \"config\" set to \"true\".");
+ }
+ }
+ }
+
+ if (!isConfig && leafLists != null) {
+ for (YangLeafList leafList : leafLists) {
+ if (leafList.isConfig()) {
+ throw new DataModelException("If a container has \"config\" set to \"false\", no node underneath " +
+ "it can have \"config\" set to \"true\".");
+ }
+ }
+ }
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Asks helper to detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Duplicate input identifier detected, same as container \""
+ + getName() + "\"");
+ }
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataTypes.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataTypes.java
new file mode 100644
index 0000000..32408d9
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataTypes.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+/**
+ * Represents ENUM to identify the YANG data type.
+ */
+public enum YangDataTypes {
+ /**
+ * Reference:RFC 6020.
+ *
+ * int8 represents integer values between -128 and 127, inclusively.
+ */
+ INT8,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * int16 represents integer values between -32768 and 32767, inclusively.
+ */
+ INT16,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * int32 represents integer values between -2147483648 and 2147483647,
+ * inclusively.
+ */
+ INT32,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * int64 represents integer values between -9223372036854775808 and
+ * 9223372036854775807, inclusively.
+ */
+ INT64,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * uint8 represents integer values between 0 and 255, inclusively.
+ */
+ UINT8,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * uint16 represents integer values between 0 and 65535, inclusively.
+ */
+ UINT16,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * uint32 represents integer values between 0 and 4294967295, inclusively.
+ */
+ UINT32,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * uint64 represents integer values between 0 and 18446744073709551615,
+ * inclusively.
+ */
+ UINT64,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The decimal64 type represents a subset of the real numbers, which can be
+ * represented by decimal numerals. The value space of decimal64 is the set
+ * of numbers that can be obtained by multiplying a 64-bit signed integer by
+ * a negative power of ten, i.e., expressible as "i x 10^-n" where i is an
+ * integer64 and n is an integer between 1 and 18, inclusively.
+ */
+ DECIMAL64, // TODO: need to implement in type.
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The string built-in type represents human-readable strings in YANG. Legal
+ * characters are tab, carriage return, line feed, and the legal characters
+ * of Unicode and ISO/IEC 10646
+ */
+ STRING,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The boolean built-in type represents a boolean value.
+ */
+ BOOLEAN,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The enumeration built-in type represents values from a set of assigned
+ * names.
+ */
+ ENUMERATION,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The bits built-in type represents a bit set. That is, a bits value is a
+ * set of flags identified by small integer position numbers starting at 0.
+ * Each bit number has an assigned name.
+ */
+ BITS,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The binary built-in type represents any binary data, i.e., a sequence of
+ * octets.
+ */
+ BINARY,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The leafref type is used to reference a particular leaf instance in the
+ * data tree. The "path" sub-statement (Section 9.9.2) selects a set of leaf
+ * instances, and the leafref value space is the set of values of these leaf
+ * instances.
+ *
+ * If the leaf with the leafref type represents configuration data, the leaf
+ * it refers to MUST also represent configuration. Such a leaf puts a
+ * constraint on valid data. All leafref nodes MUST reference existing leaf
+ * instances or leafs with default values in use for the data to be valid.
+ *
+ * There MUST NOT be any circular chains of leafrefs.
+ *
+ * If the leaf that the leafref refers to is conditional based on one or
+ * more features, then the leaf with the leafref type MUST also be
+ * conditional based on at least the same set of features.
+ */
+ LEAFREF, // TODO: need to implement in type.
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The identityref type is used to reference an existing identity.
+ */
+ IDENTITYREF,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The empty built-in type represents a leaf that does not have any value,
+ * it conveys information by its presence or absence.
+ *
+ * An empty type cannot have a default value.
+ */
+ EMPTY,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The union built-in type represents a value that corresponds to one of its
+ * member types.
+ *
+ * When the type is "union", the "type" statement MUST be present. It is
+ * used to repeatedly specify each member type of the union. It takes as an
+ * argument a string that is the name of a member type.
+ *
+ * A member type can be of any built-in or derived type, except it MUST NOT
+ * be one of the built-in types "empty" or "leafref".
+ *
+ * When a string representing a union data type is validated, the string is
+ * validated against each member type, in the order they are specified in
+ * the "type" statement, until a match is found.
+ *
+ * Any default value or "units" property defined in the member types is not
+ * inherited by the union type.
+ */
+ UNION,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The instance-identifier built-in type is used to uniquely identify a
+ * particular instance node in the data tree.
+ *
+ * The syntax for an instance-identifier is a subset of the XPath
+ * abbreviated syntax, formally defined by the rule "instance-identifier".
+ * It is used to uniquely identify a node in the data tree. Predicates are
+ * used only for specifying the values for the key nodes for list entries, a
+ * value of a leaf-list entry, or a positional index for a list without
+ * keys. For identifying list entries with keys, each predicate consists of
+ * one equality test per key, and each key MUST have a corresponding
+ * predicate.
+ *
+ * If the leaf with the instance-identifier type represents configuration
+ * data, and the "require-instance" property is "true", the node it refers
+ * to MUST also represent configuration. Such a leaf puts a constraint on
+ * valid data. All such leaf nodes MUST reference existing nodes or leaf
+ * nodes with their default value in use for the data to be valid.
+ */
+ INSTANCE_IDENTIFIER,
+
+ /**
+ * Derived data type.
+ */
+ DERIVED;
+
+ /**
+ * Returns YANG data type for corresponding type name.
+ *
+ * @param name type name from YANG file.
+ * @return YANG data type for corresponding type name.
+ */
+ public static YangDataTypes getType(String name) {
+ name = name.replace("\"", "");
+ for (YangDataTypes yangDataType : values()) {
+ if (yangDataType.name().toLowerCase().equals(name)) {
+ return yangDataType;
+ }
+ }
+ return YangDataTypes.DERIVED;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
new file mode 100644
index 0000000..bedeead
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
@@ -0,0 +1,681 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
+
+import com.google.common.base.Strings;
+
+import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.BITS;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.EMPTY;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.ENUMERATION;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.IDENTITYREF;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.LEAFREF;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UNION;
+import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
+import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.isOfRangeRestrictedType;
+import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processLengthRestriction;
+import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction;
+
+/**
+ * Represents the derived information.
+ *
+ * @param <T> extended information.
+ */
+public class YangDerivedInfo<T>
+ implements LocationInfo, Cloneable, Serializable {
+
+ private static final long serialVersionUID = 806201641L;
+
+ /**
+ * YANG typedef reference.
+ */
+ private YangTypeDef referredTypeDef;
+
+ /**
+ * Resolved additional information about data type after linking, example
+ * restriction info, named values, etc. The extra information is based
+ * on the data type. Based on the data type, the extended info can vary.
+ */
+ private T resolvedExtendedInfo;
+
+ /**
+ * Line number of pattern restriction in YANG file.
+ */
+ private int lineNumber;
+
+ /**
+ * Position of pattern restriction in line.
+ */
+ private int charPositionInLine;
+
+ /**
+ * Effective built-in type, requried in case type of typedef is again a
+ * derived type. This information is to be added during linking.
+ */
+ private YangDataTypes effectiveBuiltInType;
+
+ /**
+ * Length restriction string to temporary store the length restriction when the type
+ * is derived.
+ */
+ private String lengthRestrictionString;
+
+ /**
+ * Range restriction string to temporary store the range restriction when the type
+ * is derived.
+ */
+ private String rangeRestrictionString;
+
+ /**
+ * Pattern restriction string to temporary store the pattern restriction when the type
+ * is derived.
+ */
+ private YangPatternRestriction patternRestriction;
+
+ /**
+ * Returns the referred typedef reference.
+ *
+ * @return referred typedef reference
+ */
+ public YangTypeDef getReferredTypeDef() {
+ return referredTypeDef;
+ }
+
+ /**
+ * Sets the referred typedef reference.
+ *
+ * @param referredTypeDef referred typedef reference
+ */
+ public void setReferredTypeDef(YangTypeDef referredTypeDef) {
+ this.referredTypeDef = referredTypeDef;
+ }
+
+ /**
+ * Returns resolved extended information after successful linking.
+ *
+ * @return resolved extended information
+ */
+ public T getResolvedExtendedInfo() {
+ return resolvedExtendedInfo;
+ }
+
+ /**
+ * Sets resolved extended information after successful linking.
+ *
+ * @param resolvedExtendedInfo resolved extended information
+ */
+ public void setResolvedExtendedInfo(T resolvedExtendedInfo) {
+ this.resolvedExtendedInfo = resolvedExtendedInfo;
+ }
+
+ @Override
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ @Override
+ public int getCharPosition() {
+ return charPositionInLine;
+ }
+
+ @Override
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ @Override
+ public void setCharPosition(int charPositionInLine) {
+ this.charPositionInLine = charPositionInLine;
+ }
+
+ /**
+ * Returns the length restriction string.
+ *
+ * @return the length restriction string
+ */
+ public String getLengthRestrictionString() {
+ return lengthRestrictionString;
+ }
+
+ /**
+ * Sets the length restriction string.
+ *
+ * @param lengthRestrictionString the length restriction string
+ */
+ public void setLengthRestrictionString(String lengthRestrictionString) {
+ this.lengthRestrictionString = lengthRestrictionString;
+ }
+
+ /**
+ * Returns the range restriction string.
+ *
+ * @return the range restriction string
+ */
+ public String getRangeRestrictionString() {
+ return rangeRestrictionString;
+ }
+
+ /**
+ * Sets the range restriction string.
+ *
+ * @param rangeRestrictionString the range restriction string
+ */
+ public void setRangeRestrictionString(String rangeRestrictionString) {
+ this.rangeRestrictionString = rangeRestrictionString;
+ }
+
+ /**
+ * Returns the pattern restriction.
+ *
+ * @return the pattern restriction
+ */
+ public YangPatternRestriction getPatternRestriction() {
+ return patternRestriction;
+ }
+
+ /**
+ * Sets the pattern restriction.
+ *
+ * @param patternRestriction the pattern restriction
+ */
+ public void setPatternRestriction(YangPatternRestriction patternRestriction) {
+ this.patternRestriction = patternRestriction;
+ }
+
+ /**
+ * Returns effective built-in type.
+ *
+ * @return effective built-in type
+ */
+ public YangDataTypes getEffectiveBuiltInType() {
+ return effectiveBuiltInType;
+ }
+
+ /**
+ * Sets effective built-in type.
+ *
+ * @param effectiveBuiltInType effective built-in type
+ */
+ public void setEffectiveBuiltInType(YangDataTypes effectiveBuiltInType) {
+ this.effectiveBuiltInType = effectiveBuiltInType;
+ }
+
+ /**
+ * Resolves the type derived info, by obtaining the effective built-in type
+ * and resolving the restrictions.
+ *
+ * @return resolution status
+ * @throws DataModelException a violation in data mode rule
+ */
+ public ResolvableStatus resolve()
+ throws DataModelException {
+
+ YangType<?> baseType = getReferredTypeDef().getTypeDefBaseType();
+
+ /*
+ * Checks the data type of the referred typedef, if it's derived, obtain
+ * effective built-in type and restrictions from it's derived info,
+ * otherwise take from the base type of type itself.
+ */
+ if (baseType.getDataType() == DERIVED) {
+ /*
+ * Check whether the referred typedef is resolved.
+ */
+ if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) {
+ throw new DataModelException("Linker Error: Referred typedef is not resolved for type.");
+ }
+
+ /*
+ * Check if the referred typedef is intra file resolved, if yes sets
+ * current status also to intra file resolved .
+ */
+ if (getReferredTypeDef().getTypeDefBaseType().getResolvableStatus() == INTRA_FILE_RESOLVED) {
+ return INTRA_FILE_RESOLVED;
+ }
+ setEffectiveBuiltInType(((YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo())
+ .getEffectiveBuiltInType());
+ YangDerivedInfo refDerivedInfo = (YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo();
+ /*
+ * Check whether the effective built-in type can have range
+ * restrictions, if yes call resolution of range.
+ */
+ if (isOfRangeRestrictedType(getEffectiveBuiltInType())) {
+ if (refDerivedInfo.getResolvedExtendedInfo() == null) {
+ resolveRangeRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
+ throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
+ "type.");
+ }
+ resolveRangeRestriction((YangRangeRestriction) refDerivedInfo.getResolvedExtendedInfo());
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ /*
+ * If the effective built-in type is of type string calls for
+ * string resolution.
+ */
+ } else if (getEffectiveBuiltInType() == STRING) {
+ if (refDerivedInfo.getResolvedExtendedInfo() == null) {
+ resolveStringRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangStringRestriction)) {
+ throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
+ "type.");
+ }
+ resolveStringRestriction((YangStringRestriction) refDerivedInfo.getResolvedExtendedInfo());
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ } else if (getEffectiveBuiltInType() == BINARY) {
+ if (refDerivedInfo.getResolvedExtendedInfo() == null) {
+ resolveLengthRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve length restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
+ throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
+ "type.");
+ }
+ resolveLengthRestriction((YangRangeRestriction) refDerivedInfo.getResolvedExtendedInfo());
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve length restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ }
+ } else {
+ setEffectiveBuiltInType(baseType.getDataType());
+ /*
+ * Check whether the effective built-in type can have range
+ * restrictions, if yes call resolution of range.
+ */
+ if (isOfRangeRestrictedType(getEffectiveBuiltInType())) {
+ if (baseType.getDataTypeExtendedInfo() == null) {
+ resolveRangeRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(baseType.getDataTypeExtendedInfo() instanceof YangRangeRestriction)) {
+ throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
+ "type.");
+ }
+ resolveRangeRestriction((YangRangeRestriction) baseType.getDataTypeExtendedInfo());
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ /*
+ * If the effective built-in type is of type string calls for
+ * string resolution.
+ */
+ } else if (getEffectiveBuiltInType() == STRING) {
+ if (baseType.getDataTypeExtendedInfo() == null) {
+ resolveStringRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(baseType.getDataTypeExtendedInfo() instanceof YangStringRestriction)) {
+ throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
+ "type.");
+ }
+ resolveStringRestriction((YangStringRestriction) baseType.getDataTypeExtendedInfo());
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ } else if (getEffectiveBuiltInType() == BINARY) {
+ if (baseType.getDataTypeExtendedInfo() == null) {
+ resolveLengthRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve length restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(baseType.getDataTypeExtendedInfo() instanceof YangRangeRestriction)) {
+ throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
+ "type.");
+ }
+ resolveLengthRestriction((YangRangeRestriction) baseType.getDataTypeExtendedInfo());
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve length restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ }
+ }
+
+ /*
+ * Check if the data type is the one which can't be restricted, in this
+ * case check whether no self restrictions should be present.
+ */
+ if (isOfValidNonRestrictedType(getEffectiveBuiltInType())) {
+ if (Strings.isNullOrEmpty(getLengthRestrictionString())
+ && Strings.isNullOrEmpty(getRangeRestrictionString())
+ && getPatternRestriction() == null) {
+ return RESOLVED;
+ } else {
+ throw new DataModelException("YANG file error: Restrictions can't be applied to a given type");
+ }
+ }
+
+ // Throw exception for unsupported types
+ throw new DataModelException("Linker error: Unable to process the derived type.");
+ }
+
+ /**
+ * Resolves the string restrictions.
+ *
+ * @param refStringRestriction referred string restriction of typedef
+ * @throws DataModelException a violation in data model rule
+ */
+ private void resolveStringRestriction(YangStringRestriction refStringRestriction)
+ throws DataModelException {
+ YangStringRestriction curStringRestriction = null;
+ YangRangeRestriction refRangeRestriction = null;
+ YangPatternRestriction refPatternRestriction = null;
+
+ /*
+ * Check that range restriction should be null when built-in type is
+ * string.
+ */
+ if (!Strings.isNullOrEmpty(getRangeRestrictionString())) {
+ DataModelException dataModelException = new DataModelException("YANG file error: Range restriction " +
+ "should't be present for string data type.");
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ /*
+ * If referred restriction and self restriction both are null, no
+ * resolution is required.
+ */
+ if (refStringRestriction == null && Strings.isNullOrEmpty(getLengthRestrictionString())
+ && getPatternRestriction() == null) {
+ return;
+ }
+
+ /*
+ * If referred string restriction is not null, take value of length and
+ * pattern restriction and assign.
+ */
+ if (refStringRestriction != null) {
+ refRangeRestriction = refStringRestriction.getLengthRestriction();
+ refPatternRestriction = refStringRestriction.getPatternRestriction();
+ }
+
+ YangRangeRestriction lengthRestriction = resolveLengthRestriction(refRangeRestriction);
+ YangPatternRestriction patternRestriction = resolvePatternRestriction(refPatternRestriction);
+
+ /*
+ * Check if either of length or pattern restriction is present, if yes
+ * create string restriction and assign value.
+ */
+ if (lengthRestriction != null || patternRestriction != null) {
+ curStringRestriction = new YangStringRestriction();
+ curStringRestriction.setLengthRestriction(lengthRestriction);
+ curStringRestriction.setPatternRestriction(patternRestriction);
+ }
+ setResolvedExtendedInfo((T) curStringRestriction);
+ }
+
+ /**
+ * Resolves pattern restriction.
+ *
+ * @param refPatternRestriction referred pattern restriction of typedef
+ * @return resolved pattern restriction
+ */
+ private YangPatternRestriction resolvePatternRestriction(YangPatternRestriction refPatternRestriction) {
+ /*
+ * If referred restriction and self restriction both are null, no
+ * resolution is required.
+ */
+ if (refPatternRestriction == null && getPatternRestriction() == null) {
+ return null;
+ }
+
+ /*
+ * If self restriction is null, and referred restriction is present
+ * shallow copy the referred to self.
+ */
+ if (getPatternRestriction() == null) {
+ return refPatternRestriction;
+ }
+
+ /*
+ * If referred restriction is null, and self restriction is present
+ * carry out self resolution.
+ */
+ if (refPatternRestriction == null) {
+ return getPatternRestriction();
+ }
+
+ /*
+ * Get patterns of referred type and add it to current pattern
+ * restrictions.
+ */
+ for (String pattern : refPatternRestriction.getPatternList()) {
+ getPatternRestriction().addPattern(pattern);
+ }
+ return getPatternRestriction();
+ }
+
+ /**
+ * Resolves the length restrictions.
+ *
+ * @param refLengthRestriction referred length restriction of typedef
+ * @return resolved length restriction
+ * @throws DataModelException a violation in data model rule
+ */
+ private YangRangeRestriction resolveLengthRestriction(YangRangeRestriction refLengthRestriction)
+ throws DataModelException {
+
+ /*
+ * If referred restriction and self restriction both are null, no
+ * resolution is required.
+ */
+ if (refLengthRestriction == null && Strings.isNullOrEmpty(getLengthRestrictionString())) {
+ return null;
+ }
+
+ /*
+ * If self restriction is null, and referred restriction is present
+ * shallow copy the referred to self.
+ */
+ if (Strings.isNullOrEmpty(getLengthRestrictionString())) {
+ return refLengthRestriction;
+ }
+
+ /*
+ * If referred restriction is null, and self restriction is present
+ * carry out self resolution.
+ */
+ if (refLengthRestriction == null) {
+ YangRangeRestriction curLengthRestriction = processLengthRestriction(null, lineNumber,
+ charPositionInLine, false, getLengthRestrictionString());
+ return curLengthRestriction;
+ }
+
+ /*
+ * Carry out self resolution based with obtained effective built-in type
+ * and MIN/MAX values as per the referred typedef's values.
+ */
+ YangRangeRestriction curLengthRestriction = processLengthRestriction(refLengthRestriction, lineNumber,
+ charPositionInLine, true, getLengthRestrictionString());
+
+ // Resolve the range with referred typedef's restriction.
+ resolveLengthAndRangeRestriction(refLengthRestriction, curLengthRestriction);
+ return curLengthRestriction;
+ }
+
+ /**
+ * Resolves the length/range self and referred restriction, to check whether
+ * the all the range interval in self restriction is stricter than the
+ * referred typedef's restriction.
+ *
+ * @param refRestriction referred restriction
+ * @param curRestriction self restriction
+ */
+ private void resolveLengthAndRangeRestriction(YangRangeRestriction refRestriction,
+ YangRangeRestriction curRestriction)
+ throws DataModelException {
+ for (Object curInterval : curRestriction.getAscendingRangeIntervals()) {
+ if (!(curInterval instanceof YangRangeInterval)) {
+ throw new DataModelException("Linker error: Current range intervals not processed correctly.");
+ }
+ try {
+ refRestriction.isValidInterval((YangRangeInterval) curInterval);
+ } catch (DataModelException e) {
+ DataModelException dataModelException = new DataModelException(e);
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+ }
+ }
+
+ /**
+ * Resolves the range restrictions.
+ *
+ * @param refRangeRestriction referred range restriction of typedef
+ * @throws DataModelException a violation in data model rule
+ */
+ private void resolveRangeRestriction(YangRangeRestriction refRangeRestriction)
+ throws DataModelException {
+
+ /*
+ * Check that string restriction should be null when built-in type is of
+ * range type.
+ */
+ if (!Strings.isNullOrEmpty(getLengthRestrictionString()) || getPatternRestriction() != null) {
+ DataModelException dataModelException = new DataModelException("YANG file error: Length/Pattern " +
+ "restriction should't be present for int/uint/decimal data type.");
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ /*
+ * If referred restriction and self restriction both are null, no
+ * resolution is required.
+ */
+ if (refRangeRestriction == null && Strings.isNullOrEmpty(getRangeRestrictionString())) {
+ return;
+ }
+
+ /*
+ * If self restriction is null, and referred restriction is present
+ * shallow copy the referred to self.
+ */
+ if (Strings.isNullOrEmpty(getRangeRestrictionString())) {
+ setResolvedExtendedInfo((T) refRangeRestriction);
+ return;
+ }
+
+ /*
+ * If referred restriction is null, and self restriction is present
+ * carry out self resolution.
+ */
+ if (refRangeRestriction == null) {
+ YangRangeRestriction curRangeRestriction = processRangeRestriction(null, lineNumber,
+ charPositionInLine, false, getRangeRestrictionString(), getEffectiveBuiltInType());
+ setResolvedExtendedInfo((T) curRangeRestriction);
+ return;
+ }
+
+ /*
+ * Carry out self resolution based with obtained effective built-in type
+ * and MIN/MAX values as per the referred typedef's values.
+ */
+ YangRangeRestriction curRangeRestriction = processRangeRestriction(refRangeRestriction, lineNumber,
+ charPositionInLine, true, getRangeRestrictionString(), getEffectiveBuiltInType());
+
+ // Resolve the range with referred typedef's restriction.
+ resolveLengthAndRangeRestriction(refRangeRestriction, curRangeRestriction);
+ setResolvedExtendedInfo((T) curRangeRestriction);
+ }
+
+ /**
+ * Returns whether the data type is of non restricted type.
+ *
+ * @param dataType data type to be checked
+ * @return true, if data type can't be restricted, false otherwise
+ */
+ private boolean isOfValidNonRestrictedType(YangDataTypes dataType) {
+ return dataType == BOOLEAN
+ || dataType == ENUMERATION
+ || dataType == BITS
+ || dataType == EMPTY
+ || dataType == UNION
+ || dataType == IDENTITYREF
+ || dataType == LEAFREF;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDesc.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDesc.java
new file mode 100644
index 0000000..8c9d60e
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDesc.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.yangutils.datamodel;
+
+/**
+ * Abstraction of textual description for a YANG entity. Abstracted to unify the
+ * parsing and translator processing of description.
+ */
+public interface YangDesc {
+
+ /**
+ * Returns the description of YANG entity.
+ *
+ * @return the description of YANG entity.
+ */
+ String getDescription();
+
+ /**
+ * Set the description of YANG entity.
+ *
+ * @param description set the description of YANG entity.
+ */
+ void setDescription(String description);
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java
new file mode 100644
index 0000000..77323f1
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.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.yangutils.datamodel;
+
+/**
+ * Abstraction of information about entity being resolved.
+ *
+ * @param <T> type of entity being resolved, uses / grouping
+ */
+public interface YangEntityToResolveInfo<T> {
+
+ /**
+ * Retrieves the entity to be resolved.
+ *
+ * @return entity to be resolved
+ */
+ T getEntityToResolve();
+
+ /**
+ * Sets entity to be resolved.
+ *
+ * @param entityToResolve entity to be resolved
+ */
+ void setEntityToResolve(T entityToResolve);
+
+ /**
+ * Retrieves the parent node which contains the entity to be resolved.
+ *
+ * @return parent node which contains the entity to be resolved
+ */
+ YangNode getHolderOfEntityToResolve();
+
+ /**
+ * Sets parent node which contains the entity to be resolved.
+ *
+ * @param holderOfEntityToResolve parent node which contains the entity to
+ * be resolved
+ */
+ void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve);
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java
new file mode 100644
index 0000000..04ea232
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java
@@ -0,0 +1,240 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*-
+ * The "ENUM" statement, which is a sub-statement to the "type"
+ * statement, MUST be present if the type is "enumeration". It is
+ * repeatedly used to specify each assigned name of an enumeration type.
+ * It takes as an argument a string which is the assigned name. The
+ * string MUST NOT be empty and MUST NOT have any leading or trailing
+ * whitespace characters. The use of Unicode control codes SHOULD be
+ * avoided.
+ *
+ * The statement is optionally followed by a block of sub-statements that
+ * holds detailed ENUM information.
+ * All assigned names in an enumeration MUST be unique.
+ *
+ * The ENUM's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | description | 7.19.3 | 0..1 | - string |
+ * | reference | 7.19.4 | 0..1 | - string |
+ * | status | 7.19.2 | 0..1 | - YangStatus |
+ * | value | 9.6.4.2 | 0..1 | - int |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents the ENUM data type information.
+ */
+public class YangEnum implements YangCommonInfo, Parsable, Comparable<YangEnum>, Serializable {
+
+ private static final long serialVersionUID = 806201643L;
+
+ /**
+ * Named value for the ENUM.
+ */
+ private String namedValue;
+
+ /**
+ * Description of the ENUM value.
+ */
+ private String description;
+
+ /**
+ * Reference info of the ENUM value.
+ */
+ private String reference;
+
+ /**
+ * Status of the ENUM value.
+ */
+ private YangStatusType status;
+
+ /**
+ * Value of ENUM.
+ */
+ private int value;
+
+ /**
+ * Create a YANG ENUM.
+ */
+ public YangEnum() {
+
+ }
+
+ /**
+ * Returns the named value.
+ *
+ * @return the named value
+ */
+ public String getNamedValue() {
+ return namedValue;
+ }
+
+ /**
+ * Sets the named value.
+ *
+ * @param namedValue the named value to set
+ */
+ public void setNamedValue(String namedValue) {
+ this.namedValue = namedValue;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the textual reference.
+ *
+ * @return the reference
+ */
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ /**
+ * Sets the textual reference.
+ *
+ * @param reference the reference to set
+ */
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ /**
+ * Returns the status.
+ *
+ * @return the status
+ */
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ /**
+ * Returns the value.
+ *
+ * @return the value
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the value.
+ *
+ * @param value the value to set
+ */
+ public void setValue(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Returns the type of the data.
+ *
+ * @return ParsedDataType returns ENUM_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.ENUM_DATA;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangEnum) {
+ final YangEnum other = (YangEnum) obj;
+ return Objects.equals(namedValue, other.namedValue);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(namedValue);
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ @Override
+ public int compareTo(YangEnum otherEnum) {
+ if (namedValue.equals(otherEnum.getNamedValue())) {
+ return 0;
+ }
+ return new Integer(value).compareTo(otherEnum.getValue());
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
new file mode 100644
index 0000000..cf23464
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*
+ * The enumeration built-in type represents values from a set of
+ * assigned names.
+ */
+
+/**
+ * Represents the enumeration data type information.
+ */
+public class YangEnumeration
+ extends YangNode
+ implements Parsable, CollisionDetector {
+
+ private static final long serialVersionUID = 806201606L;
+
+ // Enumeration info set.
+ private SortedSet<YangEnum> enumSet;
+
+ // Enumeration name.
+ private String name;
+
+ /**
+ * Creates an enumeration object.
+ */
+ public YangEnumeration() {
+ super(YangNodeType.ENUMERATION_NODE);
+ setEnumSet(new TreeSet<YangEnum>());
+ }
+
+ /**
+ * Returns the ENUM set.
+ *
+ * @return the ENUM set
+ */
+ public SortedSet<YangEnum> getEnumSet() {
+ return enumSet;
+ }
+
+ /**
+ * Sets the ENUM set.
+ *
+ * @param enumSet the ENUM set to set
+ */
+ private void setEnumSet(SortedSet<YangEnum> enumSet) {
+ this.enumSet = enumSet;
+ }
+
+ /**
+ * Adds ENUM information.
+ *
+ * @param enumInfo the ENUM information to be added
+ * @throws DataModelException due to violation in data model rules
+ */
+ public void addEnumInfo(YangEnum enumInfo)
+ throws DataModelException {
+ if (!getEnumSet().add(enumInfo)) {
+ throw new DataModelException("YANG ENUM already exists");
+ }
+ }
+
+ /**
+ * Returns enumeration name.
+ *
+ * @return the enumeration name
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the enumeration name.
+ *
+ * @param name enumeration name
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the type of the data.
+ *
+ * @return returns ENUMERATION_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.ENUMERATION_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ /*
+ Do nothing, since it is not part of the schema tree, it is only type of an existing node in schema tree.
+ */
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ /*
+ Do nothing, since it is not part of the schema tree, it is only type of an existing node in schema tree.
+ */
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangGrouping.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangGrouping.java
new file mode 100644
index 0000000..0f6ba7a
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangGrouping.java
@@ -0,0 +1,324 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The "grouping" statement is used to define a reusable block of nodes,
+ * which may be used locally in the module, in modules that include it,
+ * and by other modules that import from it. It takes one argument,
+ * which is an identifier, followed by a block of sub-statements that
+ * holds detailed grouping information.
+ *
+ * The "grouping" statement is not a data definition statement and, as
+ * such, does not define any nodes in the schema tree.
+ *
+ * A grouping is like a "structure" or a "record" in conventional
+ * programming languages.
+ * Once a grouping is defined, it can be referenced in a "uses"
+ * statement. A grouping MUST NOT reference itself,
+ * neither directly nor indirectly through a chain of other groupings.
+ *
+ * If the grouping is defined at the top level of a YANG module or
+ * submodule, the grouping's identifier MUST be unique within the
+ * module.
+ *
+ * A grouping is more than just a mechanism for textual substitution,
+ * but defines a collection of nodes. Identifiers appearing inside the
+ * grouping are resolved relative to the scope in which the grouping is
+ * defined, not where it is used. Prefix mappings, type names, grouping
+ * names, and extension usage are evaluated in the hierarchy where the
+ * "grouping" statement appears. For extensions, this means that
+ * extensions are applied to the grouping node, not the uses node.
+ *
+ * The grouping's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | anyxml | 7.10 | 0..n |-not supported |
+ * | choice | 7.9 | 0..n |-child nodes |
+ * | container | 7.5 | 0..n |-child nodes |
+ * | description | 7.19.3 | 0..1 |-string |
+ * | grouping | 7.11 | 0..n |-child nodes |
+ * | leaf | 7.6 | 0..n |-YangLeaf |
+ * | leaf-list | 7.7 | 0..n |-YangLeafList |
+ * | list | 7.8 | 0..n |-child nodes |
+ * | reference | 7.19.4 | 0..1 |-string |
+ * | status | 7.19.2 | 0..1 |-YangStatus |
+ * | typedef | 7.3 | 0..n |-child nodes |
+ * | uses | 7.12 | 0..n |-child nodes |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG grouping.
+ */
+public class YangGrouping
+ extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
+
+ private static final long serialVersionUID = 806201607L;
+
+ /**
+ * Name of the grouping.
+ */
+ private String name;
+
+ /**
+ * Description.
+ */
+ private String description;
+
+ /**
+ * List of leaves.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf lists.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ /**
+ * Reference of the module.
+ */
+ private String reference;
+
+ /**
+ * Status of the node.
+ */
+ private YangStatusType status;
+
+ /**
+ * Creates the grouping node.
+ */
+ public YangGrouping() {
+ super(YangNodeType.GROUPING_NODE);
+ listOfLeaf = new LinkedList<YangLeaf>();
+ listOfLeafList = new LinkedList<YangLeafList>();
+ }
+
+ /**
+ * Returns YANG grouping name.
+ *
+ * @return YANG grouping name
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets YANG grouping name.
+ *
+ * @param name YANG grouping name
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the list of leaves.
+ *
+ * @return the list of leaves
+ */
+ @Override
+ public List<YangLeaf> getListOfLeaf() {
+ return listOfLeaf;
+ }
+
+ /**
+ * Sets the list of leaves.
+ *
+ * @param leafsList the list of leaf to set
+ */
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ /**
+ * Adds a leaf.
+ *
+ * @param leaf the leaf to be added
+ */
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+ getListOfLeaf().add(leaf);
+ }
+
+ /**
+ * Returns the list of leaf-list.
+ *
+ * @return the list of leaf-list
+ */
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return listOfLeafList;
+ }
+
+ /**
+ * Sets the list of leaf-list.
+ *
+ * @param listOfLeafList the list of leaf-list to set
+ */
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ /**
+ * Adds a leaf-list.
+ *
+ * @param leafList the leaf-list to be added
+ */
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+ getListOfLeafList().add(leafList);
+ }
+
+ /**
+ * 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 status.
+ *
+ * @return the status
+ */
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ /**
+ * Returns the type of the data.
+ *
+ * @return returns GROUPING_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.GROUPING_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /*
+ * Reference RFC6020
+ *
+ * Once a grouping is defined, it can be referenced in a "uses"
+ * statement (see Section 7.12). A grouping MUST NOT reference itself,
+ * neither directly nor indirectly through a chain of other groupings.
+ *
+ * If the grouping is defined at the top level of a YANG module or
+ * submodule, the grouping's identifier MUST be unique within the
+ * module.
+ */
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Asks helper to detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Duplicate input identifier detected, same as grouping \"" +
+ getName() + "\"");
+ }
+ }
+ // TODO A grouping MUST NOT reference itself, neither directly nor indirectly through a chain of other groupings.
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java
new file mode 100644
index 0000000..0fcf663
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangImport.java
@@ -0,0 +1,288 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+import java.util.Set;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
+
+/*
+ * Reference:RFC 6020.
+ * The "import" statement makes definitions from one module available
+ * inside another module or submodule. The argument is the name of the
+ * module to import, and the statement is followed by a block of
+ * sub statements that holds detailed import information.
+ * When a module is imported, the importing module may:
+ * o use any grouping and typedef defined at the top level in the
+ * imported module or its submodules.
+ *
+ * o use any extension, feature, and identity defined in the imported
+ * module or its submodules.
+ *
+ * o use any node in the imported module's schema tree in "must",
+ * "path", and "when" statements, or as the target node in "augment"
+ * and "deviation" statements.
+ *
+ * The mandatory "prefix" sub statement assigns a prefix for the imported
+ * module that is scoped to the importing module or submodule. Multiple
+ * "import" statements may be specified to import from different
+ * modules.
+ * When the optional "revision-date" sub-statement is present, any
+ * typedef, grouping, extension, feature, and identity referenced by
+ * definitions in the local module are taken from the specified revision
+ * of the imported module. It is an error if the specified revision of
+ * the imported module does not exist. If no "revision-date"
+ * sub-statement is present, it is undefined from which revision of the
+ * module they are taken.
+ *
+ * Multiple revisions of the same module MUST NOT be imported.
+ *
+ * The import's Substatements
+ *
+ * +---------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +---------------+---------+-------------+------------------+
+ * | prefix | 7.1.4 | 1 | string |
+ * | revision-date | 7.1.5.1 | 0..1 | string |
+ * +---------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents the information about the imported modules.
+ */
+public class YangImport
+ implements Parsable, LocationInfo, Serializable {
+
+ private static final long serialVersionUID = 806201642L;
+
+ /**
+ * Name of the module that is being imported.
+ */
+ private String name;
+
+ /**
+ * Prefix used to identify the entities from the imported module.
+ */
+ private String prefixId;
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * The import's "revision-date" statement is used to specify the exact
+ * version of the module to import. The "revision-date" statement MUST match
+ * the most recent "revision" statement in the imported module. organization
+ * which defined the YANG module.
+ */
+ private String revision;
+
+ /**
+ * Reference to node which is imported.
+ */
+ private YangNode importedNode;
+
+ // Error Line number.
+ private transient int lineNumber;
+
+ // Error character position.
+ private transient int charPosition;
+
+ /**
+ * Creates a YANG import.
+ */
+ public YangImport() {
+ }
+
+ /**
+ * Returns the imported module name.
+ *
+ * @return the module name
+ */
+ public String getModuleName() {
+ return name;
+ }
+
+ /**
+ * Sets module name.
+ *
+ * @param moduleName the module name to set
+ */
+ public void setModuleName(String moduleName) {
+ name = moduleName;
+ }
+
+ /**
+ * Returns the prefix used to identify the entities from the imported module.
+ *
+ * @return the prefix used to identify the entities from the imported
+ * module
+ */
+ public String getPrefixId() {
+ return prefixId;
+ }
+
+ /**
+ * Sets prefix identifier.
+ *
+ * @param prefixId set the prefix identifier of the imported module
+ */
+ public void setPrefixId(String prefixId) {
+ this.prefixId = prefixId;
+ }
+
+ /**
+ * Returns the revision of the imported module.
+ *
+ * @return the revision of the imported module
+ */
+ public String getRevision() {
+ return revision;
+ }
+
+ /**
+ * Sets the revision of the imported module.
+ *
+ * @param rev set the revision of the imported module
+ */
+ public void setRevision(String rev) {
+ revision = rev;
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns IMPORT_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.IMPORT_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+
+ }
+
+ /**
+ * Returns imported node.
+ *
+ * @return imported node
+ */
+ public YangNode getImportedNode() {
+ return importedNode;
+ }
+
+ /**
+ * Sets imported node.
+ *
+ * @param importedNode imported node
+ */
+ public void setImportedNode(YangNode importedNode) {
+ this.importedNode = importedNode;
+ }
+
+ @Override
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ @Override
+ public int getCharPosition() {
+ return charPosition;
+ }
+
+ @Override
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ @Override
+ public void setCharPosition(int charPositionInLine) {
+ charPosition = charPositionInLine;
+ }
+
+ /**
+ * Adds reference to an import.
+ *
+ * @param yangNodeSet YANG file info set
+ * @throws DataModelException a violation of data model rules
+ */
+ public void addReferenceToImport(Set<YangNode> yangNodeSet) throws DataModelException {
+ String importedModuleName = getModuleName();
+ String importedModuleRevision = getRevision();
+ YangNode moduleNode = null;
+ /*
+ * Find the imported module node for a given module name with a
+ * specified revision if revision is not null.
+ */
+ if (importedModuleRevision != null) {
+ String importedModuleNameWithRevision = importedModuleName + "@" + importedModuleRevision;
+ moduleNode = findReferredNode(yangNodeSet, importedModuleNameWithRevision);
+ }
+
+ /*
+ * Find the imported module node for a given module name without
+ * revision if can't find with revision.
+ */
+ if (moduleNode == null) {
+ moduleNode = findReferredNode(yangNodeSet, importedModuleName);
+ }
+
+ if (moduleNode != null) {
+ if (moduleNode instanceof YangModule) {
+ if (getRevision() == null || getRevision().isEmpty()) {
+ setImportedNode(moduleNode);
+ return;
+ }
+ // Match revision if import is with revision.
+ if (((YangModule) moduleNode).getRevision().getRevDate().equals(importedModuleRevision)) {
+ setImportedNode(moduleNode);
+ return;
+ }
+ }
+ }
+
+ // Exception if there is no match.
+ DataModelException exception = new DataModelException("YANG file error : Imported module "
+ + importedModuleName + " with revision " + importedModuleRevision + " is not found.");
+ exception.setLine(getLineNumber());
+ exception.setCharPosition(getCharPosition());
+ throw exception;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java
new file mode 100644
index 0000000..5970a24
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInclude.java
@@ -0,0 +1,242 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+import java.util.Set;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
+
+/*
+ * Reference:RFC 6020.
+ * The "include" statement is used to make content from a submodule
+ * available to that submodule's parent module, or to another submodule
+ * of that parent module. The argument is an identifier that is the
+ * name of the submodule to include.
+ * The includes's Substatements
+ *
+ * +---------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +---------------+---------+-------------+------------------+
+ * | revision-date | 7.1.5.1 | 0..1 | string |
+ * +---------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents the information about the included sub-modules.
+ */
+public class YangInclude
+ implements Parsable, LocationInfo, Serializable {
+
+ private static final long serialVersionUID = 806201644L;
+
+ /**
+ * Name of the sub-module that is being included.
+ */
+ private String subModuleName;
+
+ /**
+ * The include's "revision-date" statement is used to specify the exact
+ * version of the submodule to import.
+ */
+ private String revision;
+
+ /**
+ * Reference to node which is included.
+ */
+ private YangNode includedNode;
+
+ // Error Line number.
+ private transient int lineNumber;
+
+ // Error character position.
+ private transient int charPosition;
+
+ /**
+ * Creates a YANG include.
+ */
+ public YangInclude() {
+ }
+
+ /**
+ * Returns the name of included sub-module.
+ *
+ * @return the sub-module name
+ */
+ public String getSubModuleName() {
+ return subModuleName;
+ }
+
+ /**
+ * Sets the name of included sub-modules.
+ *
+ * @param subModuleName the sub-module name to set
+ */
+ public void setSubModuleName(String subModuleName) {
+ this.subModuleName = subModuleName;
+ }
+
+ /**
+ * Returns the revision.
+ *
+ * @return the revision
+ */
+ public String getRevision() {
+ return revision;
+ }
+
+ /**
+ * Sets the revision.
+ *
+ * @param revision the revision to set
+ */
+ public void setRevision(String revision) {
+ this.revision = revision;
+ }
+
+ /**
+ * Returns the type of parsed data.
+ *
+ * @return returns INCLUDE_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.INCLUDE_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+
+ }
+
+ public YangNode getIncludedNode() {
+ return includedNode;
+ }
+
+ public void setIncludedNode(YangNode includedNode) {
+ this.includedNode = includedNode;
+ }
+
+ @Override
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ @Override
+ public int getCharPosition() {
+ return charPosition;
+ }
+
+ @Override
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ @Override
+ public void setCharPosition(int charPositionInLine) {
+ charPosition = charPositionInLine;
+ }
+
+ /**
+ * Adds reference to an include.
+ *
+ * @param yangNodeSet YANG node set
+ * @return YANG sub module node
+ * @throws DataModelException a violation of data model rules
+ */
+ public YangSubModule addReferenceToInclude(Set<YangNode> yangNodeSet) throws DataModelException {
+ String includedSubModuleName = getSubModuleName();
+ String includedSubModuleRevision = getRevision();
+ YangNode subModuleNode = null;
+
+ /*
+ * Find the included sub-module node for a given module name with a
+ * specified revision if revision is not null.
+ */
+ if (includedSubModuleRevision != null) {
+ String includedSubModuleNameWithRevision = includedSubModuleName + "@" + includedSubModuleRevision;
+ subModuleNode = findReferredNode(yangNodeSet, includedSubModuleNameWithRevision);
+ }
+
+ /*
+ * Find the imported sub module node for a given module name without
+ * revision if can't find with revision.
+ */
+ if (subModuleNode == null) {
+ subModuleNode = findReferredNode(yangNodeSet, includedSubModuleName);
+ }
+
+ if (subModuleNode != null) {
+ if (subModuleNode instanceof YangSubModule) {
+ if (getRevision() == null || getRevision().isEmpty()) {
+ setIncludedNode(subModuleNode);
+ return (YangSubModule) subModuleNode;
+ }
+ // Match revision if inclusion is with revision.
+ if (((YangSubModule) subModuleNode).getRevision().getRevDate().equals(includedSubModuleRevision)) {
+ setIncludedNode(subModuleNode);
+ return (YangSubModule) subModuleNode;
+ }
+ }
+ }
+ // Exception if there is no match.
+ DataModelException exception = new DataModelException("YANG file error : Included sub module " +
+ includedSubModuleName + "with a given revision is not found.");
+ exception.setLine(getLineNumber());
+ exception.setCharPosition(getCharPosition());
+ throw exception;
+ }
+
+ /**
+ * Reports an error when included sub-module doesn't meet condition that
+ * "included sub-modules should belong module, as defined by the
+ * "belongs-to" statement or sub-modules are only allowed to include other
+ * sub-modules belonging to the same module.
+ *
+ * @throws DataModelException a violation in data model rule
+ */
+ public void reportIncludeError() throws DataModelException {
+ DataModelException exception = new DataModelException("YANG file error : Included sub-module " +
+ getSubModuleName() + "doesn't belongs to parent module also it doesn't belongs" +
+ "to sub-module belonging to the same parent module.");
+ exception.setLine(getLineNumber());
+ exception.setCharPosition(getCharPosition());
+ throw exception;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
new file mode 100644
index 0000000..7238a3e
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The "input" statement, which is optional, is used to define input
+ * parameters to the RPC operation. It does not take an argument. The
+ * substatements to "input" define nodes under the RPC's input node.
+ *
+ * If a leaf in the input tree has a "mandatory" statement with the
+ * value "true", the leaf MUST be present in a NETCONF RPC invocation.
+ * Otherwise, the server MUST return a "missing-element" error.
+ *
+ * If a leaf in the input tree has a default value, the NETCONF server
+ * MUST use this value in the same cases as described in Section 7.6.1.
+ * In these cases, the server MUST operationally behave as if the leaf
+ * was present in the NETCONF RPC invocation with the default value as
+ * its value.
+ *
+ * If a "config" statement is present for any node in the input tree,
+ * the "config" statement is ignored.
+ *
+ * If any node has a "when" statement that would evaluate to false, then
+ * this node MUST NOT be present in the input tree.
+ *
+ * The input substatements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | anyxml | 7.10 | 0..n | -not supported |
+ * | choice | 7.9 | 0..n | -child nodes |
+ * | container | 7.5 | 0..n | -child nodes |
+ * | grouping | 7.11 | 0..n | -child nodes |
+ * | leaf | 7.6 | 0..n | -YangLeaf |
+ * | leaf-list | 7.7 | 0..n | -YangLeafList |
+ * | list | 7.8 | 0..n | -child nodes |
+ * | typedef | 7.3 | 0..n | -child nodes |
+ * | uses | 7.12 | 0..n | -child nodes |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG input.
+ */
+public class YangInput
+ extends YangNode
+ implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
+
+ private static final long serialVersionUID = 806201608L;
+
+ /**
+ * Name of the input.
+ */
+ private String name;
+
+ /**
+ * List of leaves contained.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf-lists contained.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ /**
+ * Create a rpc input node.
+ */
+ public YangInput() {
+ super(YangNodeType.INPUT_NODE);
+ listOfLeaf = new LinkedList<YangLeaf>();
+ listOfLeafList = new LinkedList<YangLeafList>();
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Duplicate input identifier detected, same as input \""
+ + getName() + "\"");
+ }
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.INPUT_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ //TODO: implement the method.
+ }
+
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ //TODO: implement the method.
+ }
+
+ @Override
+ public List<YangLeaf> getListOfLeaf() {
+ return listOfLeaf;
+ }
+
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+ getListOfLeaf().add(leaf);
+ }
+
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return listOfLeafList;
+ }
+
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+ getListOfLeafList().add(leafList);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
new file mode 100644
index 0000000..0391518
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeaf.java
@@ -0,0 +1,349 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*
+ * Reference:RFC 6020.
+ * The "leaf" statement is used to define a leaf node in the schema
+ * tree. It takes one argument, which is an identifier, followed by a
+ * block of sub-statements that holds detailed leaf information.
+ *
+ * A leaf node has a value, but no child nodes in the data tree.
+ * Conceptually, the value in the data tree is always in the canonical
+ * form.
+ *
+ * A leaf node exists in zero or one instances in the data tree.
+ *
+ * The "leaf" statement is used to define a scalar variable of a
+ * particular built-in or derived type.
+ *
+ * The leaf's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | config | 7.19.1 | 0..1 | - boolean |
+ * | default | 7.6.4 | 0..1 | - TODO |
+ * | description | 7.19.3 | 0..1 | - string |
+ * | if-feature | 7.18.2 | 0..n | - TODO |
+ * | mandatory | 7.6.5 | 0..1 | - boolean |
+ * | must | 7.5.3 | 0..n | - TODO |
+ * | reference | 7.19.4 | 0..1 | - string |
+ * | status | 7.19.2 | 0..1 | - YangStatus |
+ * | type | 7.6.3 | 1 | - YangType |
+ * | units | 7.3.3 | 0..1 | - String |
+ * | when | 7.19.5 | 0..1 | - TODO |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents leaf data represented in YANG.
+ */
+public class YangLeaf
+ implements YangCommonInfo, Parsable, Cloneable, Serializable {
+
+ private static final long serialVersionUID = 806201635L;
+
+ /**
+ * Name of leaf.
+ */
+ private String name;
+
+ /**
+ * If the leaf is a config parameter.
+ */
+ private Boolean isConfig;
+
+ /**
+ * description of leaf.
+ */
+ private String description;
+
+ /**
+ * If mandatory leaf.
+ */
+ private boolean isMandatory;
+
+ /**
+ * The textual reference to this leaf.
+ */
+ private String reference;
+
+ /**
+ * Status of leaf in YANG definition.
+ */
+ private YangStatusType status = YangStatusType.CURRENT;
+
+ /**
+ * Textual units info.
+ */
+ private String units;
+
+ /**
+ * Data type of the leaf.
+ */
+ private YangType<?> dataType;
+
+ /**
+ * Default value in string, needs to be converted to the target object,
+ * based on the type.
+ */
+ private String defaultValueInString;
+
+ /**
+ * YANG Node in which the leaf is contained.
+ */
+ private transient YangLeavesHolder containedIn;
+
+ /**
+ * Creates a YANG leaf.
+ */
+ public YangLeaf() {
+ }
+
+ /**
+ * Returns the name of leaf.
+ *
+ * @return the leaf name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of leaf.
+ *
+ * @param leafName the leaf name to set
+ */
+ public void setLeafName(String leafName) {
+ name = leafName;
+ }
+
+ /**
+ * Returns the config flag.
+ *
+ * @return if config flag
+ */
+ public Boolean isConfig() {
+ return isConfig;
+ }
+
+ /**
+ * Sets the config flag.
+ *
+ * @param isCfg the flag value to set
+ */
+ public void setConfig(boolean isCfg) {
+ isConfig = isCfg;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns if the leaf is mandatory.
+ *
+ * @return if leaf is mandatory
+ */
+ public boolean isMandatory() {
+ return isMandatory;
+ }
+
+ /**
+ * Sets if the leaf is mandatory.
+ *
+ * @param isReq if the leaf is mandatory
+ */
+ public void setMandatory(boolean isReq) {
+ isMandatory = isReq;
+ }
+
+ /**
+ * 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 status.
+ *
+ * @return the status
+ */
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ /**
+ * Returns the units.
+ *
+ * @return the units
+ */
+ public String getUnits() {
+ return units;
+ }
+
+ /**
+ * Sets the units.
+ *
+ * @param units the units to set
+ */
+ public void setUnits(String units) {
+ this.units = units;
+ }
+
+ /**
+ * Returns the default value.
+ *
+ * @return the default value
+ */
+ public String getDefaultValueInString() {
+ return defaultValueInString;
+ }
+
+ /**
+ * Sets the default value.
+ *
+ * @param defaultValueInString the default value
+ */
+ 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;
+ }
+
+ /**
+ * Retrieves the YANG node in which the leaf is defined.
+ *
+ * @return the YANG node in which the leaf is defined
+ */
+ public YangLeavesHolder getContainedIn() {
+ return containedIn;
+ }
+
+ /**
+ * Assigns the YANG node in which the leaf is defined.
+ *
+ * @param containedIn the YANG node in which the leaf is defined
+ */
+ public void setContainedIn(YangLeavesHolder containedIn) {
+ this.containedIn = containedIn;
+ }
+
+ @Override
+ public YangLeaf clone()
+ throws CloneNotSupportedException {
+ return (YangLeaf) super.clone();
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns LEAF_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.LEAF_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java
new file mode 100644
index 0000000..2ce44fb
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafList.java
@@ -0,0 +1,366 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*
+ * Reference:RFC 6020.
+ * Where the "leaf" statement is used to define a simple scalar variable
+ * of a particular type, the "leaf-list" statement is used to define an
+ * array of a particular type. The "leaf-list" statement takes one
+ * argument, which is an identifier, followed by a block of
+ * sub-statements that holds detailed leaf-list information.
+ *
+ * The values in a leaf-list MUST be unique.
+ *
+ * The leaf-list's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | config | 7.19.1 | 0..1 | -boolean |
+ * | description | 7.19.3 | 0..1 | -string |
+ * | if-feature | 7.18.2 | 0..n | -TODO |
+ * | max-elements | 7.7.4 | 0..1 | -int |
+ * | min-elements | 7.7.3 | 0..1 | -int |
+ * | must | 7.5.3 | 0..n | -TODO |
+ * | ordered-by | 7.7.5 | 0..1 | -TODO |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * | type | 7.4 | 1 | -YangType |
+ * | units | 7.3.3 | 0..1 | -string |
+ * | when | 7.19.5 | 0..1 | -TODO |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents leaf-list data represented in YANG.
+ */
+public class YangLeafList
+ implements YangCommonInfo, Parsable, Cloneable, Serializable {
+
+ private static final long serialVersionUID = 806201637L;
+
+ /**
+ * Name of leaf-list.
+ */
+ private String name;
+
+ /**
+ * If the leaf-list is a config parameter.
+ */
+ private Boolean isConfig;
+
+ /**
+ * Description of leaf-list.
+ */
+ private String description;
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The "max-elements" statement, which is optional, takes as an argument a
+ * positive integer or the string "unbounded", which puts a constraint on
+ * valid list entries. A valid leaf-list or list always has at most
+ * max-elements entries.
+ *
+ * If no "max-elements" statement is present, it defaults to "unbounded".
+ */
+ private int maxElelements = Integer.MAX_VALUE;
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * The "min-elements" statement, which is optional, takes as an argument a
+ * non-negative integer that puts a constraint on valid list entries. A
+ * valid leaf-list or list MUST have at least min-elements entries.
+ *
+ * If no "min-elements" statement is present, it defaults to zero.
+ *
+ * The behavior of the constraint depends on the type of the leaf-list's or
+ * list's closest ancestor node in the schema tree that is not a non-
+ * presence container:
+ *
+ * o If this ancestor is a case node, the constraint is enforced if any
+ * other node from the case exists.
+ *
+ * o Otherwise, it is enforced if the ancestor node exists.
+ */
+ private int minElements = 0;
+
+ /**
+ * The textual reference to this leaf-list.
+ */
+ private String reference;
+
+ /**
+ * Status of the leaf-list in the YANG definition.
+ */
+ private YangStatusType status = YangStatusType.CURRENT;
+
+ /**
+ * Textual units.
+ */
+ private String units;
+
+ /**
+ * Data type of leaf-list.
+ */
+ private YangType<?> dataType;
+
+ /**
+ * YANG Node in which the leaf is contained.
+ */
+ private transient YangLeavesHolder containedIn;
+
+ /**
+ * Creates a YANG leaf-list.
+ */
+ public YangLeafList() {
+ }
+
+ /**
+ * Returns the leaf-list name.
+ *
+ * @return the leaf-list name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the leaf-list name.
+ *
+ * @param leafListName the leaf-list name to set
+ */
+ public void setLeafName(String leafListName) {
+ name = leafListName;
+ }
+
+ /**
+ * Returns the config flag.
+ *
+ * @return the config flag
+ */
+ public Boolean isConfig() {
+ return isConfig;
+ }
+
+ /**
+ * Sets the config flag.
+ *
+ * @param isCfg the config flag
+ */
+ public void setConfig(boolean isCfg) {
+ isConfig = isCfg;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the max elements no.
+ *
+ * @return the max elements no
+ */
+ public int getMaxElelements() {
+ return maxElelements;
+ }
+
+ /**
+ * Sets the max elements no.
+ *
+ * @param maxElelements max elements no
+ */
+ public void setMaxElelements(int maxElelements) {
+ this.maxElelements = maxElelements;
+ }
+
+ /**
+ * Returns the min elements no.
+ *
+ * @return the min elements no
+ */
+ public int getMinElements() {
+ return minElements;
+ }
+
+ /**
+ * Sets the min elements no.
+ *
+ * @param minElements the min elements no
+ */
+ public void setMinElements(int minElements) {
+ this.minElements = minElements;
+ }
+
+ /**
+ * 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 status.
+ *
+ * @return the status
+ */
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ /**
+ * Returns the units.
+ *
+ * @return the units
+ */
+ public String getUnits() {
+ return units;
+ }
+
+ /**
+ * Sets the units.
+ *
+ * @param units the units to set
+ */
+ public void setUnits(String units) {
+ this.units = units;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Retrieves the YANG node in which the leaf is defined.
+ *
+ * @return the YANG node in which the leaf is defined
+ */
+ public YangLeavesHolder getContainedIn() {
+ return containedIn;
+ }
+
+ /**
+ * Assigns the YANG node in which the leaf is defined.
+ *
+ * @param containedIn the YANG node in which the leaf is defined
+ */
+ public void setContainedIn(YangLeavesHolder containedIn) {
+ this.containedIn = containedIn;
+ }
+
+ @Override
+ public YangLeafList clone()
+ throws CloneNotSupportedException {
+ return (YangLeafList) super.clone();
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns LEAF_LIST_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.LEAF_LIST_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeavesHolder.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeavesHolder.java
new file mode 100644
index 0000000..a21ed34
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeavesHolder.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.List;
+
+/**
+ * Abstraction of atomic configurable/status entity. It is used to abstract the
+ * data holders of leaf or leaf list. Used in leaves parsing or attribute code
+ * generation.
+ */
+public interface YangLeavesHolder {
+
+ /**
+ * Returns the list of leaves from data holder like container / list.
+ *
+ * @return the list of leaves
+ */
+ List<YangLeaf> getListOfLeaf();
+
+ /**
+ * Sets the list of leaves.
+ *
+ * @param leafsList the list of leaf to set
+ */
+ void setListOfLeaf(List<YangLeaf> leafsList);
+
+ /**
+ * Adds leaf in data holder like container / list.
+ *
+ * @param leaf the leaf to be added
+ */
+ void addLeaf(YangLeaf leaf);
+
+ /**
+ * Returns the list of leaf-list from data holder like container / list.
+ *
+ * @return the list of leaf-list
+ */
+ List<YangLeafList> getListOfLeafList();
+
+ /**
+ * Sets the list of leaf-list.
+ *
+ * @param listOfLeafList the list of leaf-list to set
+ */
+ void setListOfLeafList(List<YangLeafList> listOfLeafList);
+
+ /**
+ * Adds leaf-list in data holder like container / list.
+ *
+ * @param leafList the leaf-list to be added
+ */
+ void addLeafList(YangLeafList leafList);
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
new file mode 100644
index 0000000..a89c09e
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * Binary can be restricted with "length" statements alone.
+ *
+ */
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
+
+/**
+ * Represents the restriction for length data type.
+ */
+public class YangLengthRestriction implements YangDesc, YangReference, YangAppErrorInfo, Parsable, Serializable {
+
+ /*-
+ * Reference RFC 6020.
+ * The length Statement
+ *
+ * The "length" statement, which is an optional sub-statement to the
+ * "type" statement, takes as an argument a length expression string.
+ * It is used to restrict the built-in type "string", or types derived
+ * from "string".
+ * A "length" statement restricts the number of unicode characters in
+ * the string.
+ * A length range consists of an explicit value, or a lower bound, two
+ * consecutive dots "..", and an upper bound. Multiple values or ranges
+ * can be given, separated by "|". Length-restricting values MUST NOT
+ * be negative. If multiple values or ranges are given, they all MUST
+ * be disjoint and MUST be in ascending order. If a length restriction
+ * is applied to an already length-restricted type, the new restriction
+ * MUST be equal or more limiting, that is, raising the lower bounds,
+ * reducing the upper bounds, removing explicit length values or ranges,
+ * or splitting ranges into multiple ranges with intermediate gaps. A
+ * length value is a non-negative integer, or one of the special values
+ * "min" or "max". "min" and "max" mean the minimum and maximum length
+ * accepted for the type being restricted, respectively. An
+ * implementation is not required to support a length value larger than
+ * 18446744073709551615.
+ * The length's sub-statements
+ *
+ * +---------------+---------+-------------+-----------------+
+ * | substatement | section | cardinality | mapped data type|
+ * +---------------+---------+-------------+-----------------+
+ * | description | 7.19.3 | 0..1 | string |
+ * | error-app-tag | 7.5.4.2 | 0..1 | string |
+ * | error-message | 7.5.4.1 | 0..1 | string |
+ * | reference | 7.19.4 | 0..1 | string |
+ * +---------------+---------+-------------+-----------------+
+ */
+
+ private static final long serialVersionUID = 806201645L;
+
+ /**
+ * Length restriction information.
+ */
+ private YangRangeRestriction<YangUint64> lengthRestriction;
+
+ /**
+ * Textual reference.
+ */
+ private String reference;
+
+ /**
+ * Application's error message, to be used for data error.
+ */
+ private String errorMessage;
+
+ /**
+ * Application's error tag, to be filled in data validation error response.
+ */
+ private String errorAppTag;
+
+ /**
+ * Textual description.
+ */
+ private String description;
+
+ /**
+ * Creates a YANG length restriction object.
+ */
+ public YangLengthRestriction() {
+ }
+
+ /**
+ * Returns the length restriction on the string data.
+ *
+ * @return length restriction on the string data
+ */
+ public YangRangeRestriction<YangUint64> getLengthRestriction() {
+ return lengthRestriction;
+ }
+
+ /**
+ * Sets the length restriction on the string data.
+ *
+ * @param lengthRestriction length restriction on the string data
+ */
+ public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) {
+ this.lengthRestriction = lengthRestriction;
+ }
+
+ /**
+ * Returns the textual reference of the length restriction.
+ *
+ * @return textual reference of the length restriction
+ */
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ /**
+ * Sets the textual reference of the length restriction.
+ *
+ * @param ref textual reference of the length restriction
+ */
+ @Override
+ public void setReference(String ref) {
+ reference = ref;
+ }
+
+ /**
+ * Returns the description of the length restriction.
+ *
+ * @return description of the length restriction
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description of the length restriction.
+ *
+ * @param desc description of the length restriction
+ */
+ @Override
+ public void setDescription(String desc) {
+ description = desc;
+
+ }
+
+ /**
+ * Returns application's error message, to be used for data error.
+ *
+ * @return Application's error message, to be used for data error
+ */
+ @Override
+ public String getGetErrorMessage() {
+ return errorMessage;
+ }
+
+ /**
+ * Sets Application's error message, to be used for data error.
+ *
+ * @param errMsg Application's error message, to be used for data error
+ */
+ @Override
+ public void setErrorMessage(String errMsg) {
+ errorMessage = errMsg;
+
+ }
+
+ /**
+ * Returns application's error tag, to be used for data error.
+ *
+ * @return application's error tag, to be used for data error
+ */
+ @Override
+ public String getGetErrorAppTag() {
+ return errorAppTag;
+ }
+
+ /**
+ * Sets application's error tag, to be used for data error.
+ *
+ * @param errTag application's error tag, to be used for data error.
+ */
+ @Override
+ public void setErrorAppTag(String errTag) {
+ errorAppTag = errTag;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.PATTERN_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO: implement the method.
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO: implement the method.
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
new file mode 100644
index 0000000..632c5b7
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
@@ -0,0 +1,646 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+
+/*
+ * The "list" statement is used to define an interior data node in the
+ * schema tree. A list node may exist in multiple instances in the data
+ * tree. Each such instance is known as a list entry. The "list"
+ * statement takes one argument, which is an identifier, followed by a
+ * block of sub-statements that holds detailed list information.
+ *
+ * A list entry is uniquely identified by the values of the list's keys,
+ * if defined.
+ *
+ * The list's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | anyxml | 7.10 | 0..n |-not supported |
+ * | choice | 7.9 | 0..n |-child nodes |
+ * | config | 7.19.1 | 0..1 |-boolean |
+ * | container | 7.5 | 0..n |-child nodes |
+ * | description | 7.19.3 | 0..1 |-string |
+ * | grouping | 7.11 | 0..n |-child nodes |
+ * | if-feature | 7.18.2 | 0..n |-TODO |
+ * | key | 7.8.2 | 0..1 |-String list |
+ * | leaf | 7.6 | 0..n |-YangLeaf |
+ * | leaf-list | 7.7 | 0..n |-YangLeafList |
+ * | list | 7.8 | 0..n |-child nodes |
+ * | max-elements | 7.7.4 | 0..1 |-int |
+ * | min-elements | 7.7.3 | 0..1 |-int |
+ * | must | 7.5.3 | 0..n |-TODO |
+ * | ordered-by | 7.7.5 | 0..1 |-TODO |
+ * | reference | 7.19.4 | 0..1 |-string |
+ * | status | 7.19.2 | 0..1 |-YangStatus |
+ * | typedef | 7.3 | 0..n |-child nodes |
+ * | unique | 7.8.3 | 0..n |-TODO |
+ * | uses | 7.12 | 0..n |-child nodes(TODO)|
+ * | when | 7.19.5 | 0..1 |-TODO |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents list data represented in YANG.
+ */
+public class YangList
+ extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
+
+ private static final long serialVersionUID = 806201609L;
+
+ /**
+ * Name of the YANG list.
+ */
+ private String name;
+
+ /**
+ * If list maintains config data.
+ */
+ private Boolean isConfig;
+
+ /**
+ * Description of list.
+ */
+ private String description;
+
+ /**
+ * Reference RFC 6020.
+ *
+ * The "key" statement, which MUST be present if the list represents
+ * configuration, and MAY be present otherwise, takes as an argument a
+ * string that specifies a space-separated list of leaf identifiers of this
+ * list. A leaf identifier MUST NOT appear more than once in the key. Each
+ * such leaf identifier MUST refer to a child leaf of the list. The leafs
+ * can be defined directly in sub-statements to the list, or in groupings
+ * used in the list.
+ *
+ * The combined values of all the leafs specified in the key are used to
+ * uniquely identify a list entry. All key leafs MUST be given values when a
+ * list entry is created. Thus, any default values in the key leafs or their
+ * types are ignored. It also implies that any mandatory statement in the
+ * key leafs are ignored.
+ *
+ * A leaf that is part of the key can be of any built-in or derived type,
+ * except it MUST NOT be the built-in type "empty".
+ *
+ * All key leafs in a list MUST have the same value for their "config" as
+ * the list itself.
+ *
+ * List of key leaf names.
+ */
+ private List<String> keyList;
+
+ /**
+ * List of leaves.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf-lists.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ /**
+ * Reference RFC 6020.
+ *
+ * The "max-elements" statement, which is optional, takes as an argument a
+ * positive integer or the string "unbounded", which puts a constraint on
+ * valid list entries. A valid leaf-list or list always has at most
+ * max-elements entries.
+ *
+ * If no "max-elements" statement is present, it defaults to "unbounded".
+ */
+ private int maxElements = Integer.MAX_VALUE;
+
+ /**
+ * Reference RFC 6020.
+ *
+ * The "min-elements" statement, which is optional, takes as an argument a
+ * non-negative integer that puts a constraint on valid list entries. A
+ * valid leaf-list or list MUST have at least min-elements entries.
+ *
+ * If no "min-elements" statement is present, it defaults to zero.
+ *
+ * The behavior of the constraint depends on the type of the leaf-list's or
+ * list's closest ancestor node in the schema tree that is not a non-
+ * presence container:
+ *
+ * o If this ancestor is a case node, the constraint is enforced if any
+ * other node from the case exists.
+ *
+ * o Otherwise, it is enforced if the ancestor node exists.
+ */
+ private int minElements = 0;
+
+ /**
+ * reference.
+ */
+ private String reference;
+
+ /**
+ * Status of the node.
+ */
+
+ private YangStatusType status = YangStatusType.CURRENT;
+
+ /**
+ * Creates a YANG list object.
+ */
+ public YangList() {
+ super(YangNodeType.LIST_NODE);
+ }
+
+ /**
+ * Returns the YANG list name.
+ *
+ * @return YANG list name
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the YANG list name.
+ *
+ * @param name YANG list name
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the config flag.
+ *
+ * @return the isConfig
+ */
+ public Boolean isConfig() {
+ return isConfig;
+ }
+
+ /**
+ * Sets the config flag.
+ *
+ * @param isCfg the config flag
+ */
+ public void setConfig(boolean isCfg) {
+ isConfig = isCfg;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the list of key field names.
+ *
+ * @return the list of key field names
+ */
+ public List<String> getKeyList() {
+ return keyList;
+ }
+
+ /**
+ * Sets the list of key field names.
+ *
+ * @param keyList the list of key field names
+ */
+ private void setKeyList(List<String> keyList) {
+ this.keyList = keyList;
+ }
+
+ /**
+ * Adds a key field name.
+ *
+ * @param key key field name.
+ * @throws DataModelException a violation of data model rules
+ */
+ public void addKey(String key)
+ throws DataModelException {
+ if (getKeyList() == null) {
+ setKeyList(new LinkedList<String>());
+ }
+
+ if (getKeyList().contains(key)) {
+ throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
+ " key");
+ }
+
+ getKeyList().add(key);
+ }
+
+ /**
+ * Returns the list of leaves.
+ *
+ * @return the list of leaves
+ */
+ @Override
+ public List<YangLeaf> getListOfLeaf() {
+ return listOfLeaf;
+ }
+
+ /**
+ * Sets the list of leaves.
+ *
+ * @param leafsList the list of leaf to set
+ */
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ /**
+ * Adds a leaf.
+ *
+ * @param leaf the leaf to be added
+ */
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+ if (getListOfLeaf() == null) {
+ setListOfLeaf(new LinkedList<YangLeaf>());
+ }
+
+ getListOfLeaf().add(leaf);
+ }
+
+ /**
+ * Returns the list of leaf-list.
+ *
+ * @return the list of leaf-list
+ */
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return listOfLeafList;
+ }
+
+ /**
+ * Sets the list of leaf-list.
+ *
+ * @param listOfLeafList the list of leaf-list to set
+ */
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ /**
+ * Adds a leaf-list.
+ *
+ * @param leafList the leaf-list to be added
+ */
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+ if (getListOfLeafList() == null) {
+ setListOfLeafList(new LinkedList<YangLeafList>());
+ }
+
+ getListOfLeafList().add(leafList);
+ }
+
+ /**
+ * Returns the max elements.
+ *
+ * @return the max elements
+ */
+ public int getMaxElements() {
+ return maxElements;
+ }
+
+ /**
+ * Sets the max elements.
+ *
+ * @param max the max elements
+ */
+ public void setMaxElements(int max) {
+ maxElements = max;
+ }
+
+ /**
+ * Returns the minimum elements.
+ *
+ * @return the minimum elements
+ */
+ public int getMinElements() {
+ return minElements;
+ }
+
+ /**
+ * Sets the minimum elements.
+ *
+ * @param minElements the minimum elements
+ */
+ public void setMinElements(int minElements) {
+ this.minElements = minElements;
+ }
+
+ /**
+ * 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 status.
+ *
+ * @return the status
+ */
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns LIST_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.LIST_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ List<String> keys = getKeyList();
+ List<YangLeaf> leaves = getListOfLeaf();
+ List<YangLeafList> leafLists = getListOfLeafList();
+
+ setDefaultConfigValueToChild(leaves, leafLists);
+ validateConfig(leaves, leafLists);
+
+ /* A list must have atleast one key leaf if config is true */
+ if (isConfig && (keys == null || leaves == null && leafLists == null) && !isUsesPresentInList()
+ && !isListPresentInGrouping()) {
+ throw new DataModelException("A list must have atleast one key leaf if config is true;");
+ } else if (keys != null) {
+ validateKey(leaves, leafLists, keys);
+ }
+ }
+
+ /**
+ * Sets the config's value to all leaf if leaf's config statement is not
+ * specified.
+ *
+ * @param leaves list of leaf attributes of YANG list
+ * @param leafLists list of leaf-list attributes of YANG list
+ */
+ private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) {
+
+ /*
+ * If "config" is not specified, the default is the same as the parent
+ * schema node's "config" value.
+ */
+ if (leaves != null) {
+ for (YangLeaf leaf : leaves) {
+ if (leaf.isConfig() == null) {
+ leaf.setConfig(isConfig);
+ }
+ }
+ }
+
+ /*
+ * If "config" is not specified, the default is the same as the parent
+ * schema node's "config" value.
+ */
+ if (leafLists != null) {
+ for (YangLeafList leafList : leafLists) {
+ if (leafList.isConfig() == null) {
+ leafList.setConfig(isConfig);
+ }
+ }
+ }
+ }
+
+ /**
+ * Validates config statement of YANG list.
+ *
+ * @param leaves list of leaf attributes of YANG list
+ * @param leafLists list of leaf-list attributes of YANG list
+ * @throws DataModelException a violation of data model rules
+ */
+ private void validateConfig(List<YangLeaf> leaves, List<YangLeafList> leafLists)
+ throws DataModelException {
+
+ /*
+ * If a node has "config" set to "false", no node underneath it can have
+ * "config" set to "true".
+ */
+ if (!isConfig && leaves != null) {
+ for (YangLeaf leaf : leaves) {
+ if (leaf.isConfig()) {
+ throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
+ "it can have \"config\" set to \"true\".");
+ }
+ }
+ }
+
+ if (!isConfig && leafLists != null) {
+ for (YangLeafList leafList : leafLists) {
+ if (leafList.isConfig()) {
+ throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
+ "it can have \"config\" set to \"true\".");
+ }
+ }
+ }
+ }
+
+ /**
+ * Validates key statement of list.
+ *
+ * @param leaves list of leaf attributes of list
+ * @param leafLists list of leaf-list attributes of list
+ * @param keys list of key attributes of list
+ * @throws DataModelException a violation of data model rules
+ */
+ private void validateKey(List<YangLeaf> leaves, List<YangLeafList> leafLists, List<String> keys)
+ throws
+ DataModelException {
+ boolean leafFound = false;
+ List<YangLeaf> keyLeaves = new LinkedList<>();
+ List<YangLeafList> keyLeafLists = new LinkedList<>();
+
+ /*
+ * 1. Leaf identifier must refer to a child leaf of the list 2. A leaf
+ * that is part of the key must not be the built-in type "empty".
+ */
+ for (String key : keys) {
+ if (leaves != null && !leaves.isEmpty()) {
+ for (YangLeaf leaf : leaves) {
+ if (key.equals(leaf.getName())) {
+ if (leaf.getDataType().getDataType() == YangDataTypes.EMPTY) {
+ throw new DataModelException(" A leaf that is part of the key must not be the built-in " +
+ "type \"empty\".");
+ }
+ leafFound = true;
+ keyLeaves.add(leaf);
+ break;
+ }
+ }
+ }
+
+ if (leafLists != null && !leafLists.isEmpty()) {
+ for (YangLeafList leafList : leafLists) {
+ if (key.equals(leafList.getName())) {
+ if (leafList.getDataType().getDataType() == YangDataTypes.EMPTY) {
+ throw new DataModelException(" A leaf-list that is part of the key" +
+ " must not be the built-in type \"empty\".");
+ }
+ leafFound = true;
+ keyLeafLists.add(leafList);
+ break;
+ }
+ }
+ }
+
+ if (!leafFound && !isUsesPresentInList() && !isListPresentInGrouping()) {
+ throw new DataModelException("An identifier, in key, must refer to a child leaf of the list");
+ }
+ leafFound = false;
+ }
+
+ /*
+ * All key leafs in a list MUST have the same value for their "config"
+ * as the list itself.
+ */
+ for (YangLeaf keyLeaf : keyLeaves) {
+ if (isConfig != keyLeaf.isConfig()) {
+ throw new DataModelException("All key leafs in a list must have the same value for their" +
+ " \"config\" as the list itself.");
+ }
+ }
+
+ /*
+ * All key leafs in a list MUST have the same value for their "config"
+ * as the list itself.
+ */
+ for (YangLeafList keyLeafList : keyLeafLists) {
+ if (isConfig() != keyLeafList.isConfig()) {
+ throw new DataModelException("All key leaf-lists in a list must have the same value for their" +
+ " \"config\" as the list itself.");
+ }
+ }
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Asks helper to detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Duplicate input identifier detected, same as list \"" +
+ getName() + "\"");
+ }
+ }
+
+ private boolean isUsesPresentInList() {
+ YangNode node = getChild();
+ while (node != null) {
+ if (node instanceof YangUses) {
+ return true;
+ }
+ node = node.getNextSibling();
+ }
+ return false;
+ // TODO When grouping linking is done this method has to be modified.
+ }
+
+ private boolean isListPresentInGrouping() {
+ YangNode node = getParent();
+ while (node != null) {
+ if (node instanceof YangGrouping) {
+ return true;
+ }
+ node = node.getParent();
+ }
+ return false;
+ // TODO When grouping linking is done this method has to be modified.
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
new file mode 100644
index 0000000..f14cfeb
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
@@ -0,0 +1,618 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.linkInterFileReferences;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
+
+/*-
+ * Reference:RFC 6020.
+ * The "module" statement defines the module's name,
+ * and groups all statements that belong to the module together. The "module"
+ * statement's argument is the name of the module, followed by a block of
+ * sub statements that hold detailed module information.
+ * The module's sub statements
+ *
+ * +--------------+---------+-------------+-----------------------+
+ * |sub statement | section | cardinality | data model mapping |
+ * +--------------+---------+-------------+-----------------------+
+ * | anyxml | 7.10 | 0..n | not supported |
+ * | augment | 7.15 | 0..n | child nodes |
+ * | choice | 7.9 | 0..n | child nodes |
+ * | contact | 7.1.8 | 0..1 | string |
+ * | container | 7.5 | 0..n | child nodes |
+ * | description | 7.19.3 | 0..1 | string |
+ * | deviation | 7.18.3 | 0..n | TODO |
+ * | extension | 7.17 | 0..n | TODO |
+ * | feature | 7.18.1 | 0..n | TODO |
+ * | grouping | 7.11 | 0..n | child nodes |
+ * | identity | 7.16 | 0..n | TODO |
+ * | import | 7.1.5 | 0..n | list of import info |
+ * | include | 7.1.6 | 0..n | list of include info |
+ * | leaf | 7.6 | 0..n | list of leaf info |
+ * | leaf-list | 7.7 | 0..n | list of leaf-list info|
+ * | list | 7.8 | 0..n | child nodes |
+ * | namespace | 7.1.3 | 1 | string/uri |
+ * | notification | 7.14 | 0..n | TODO |
+ * | organization | 7.1.7 | 0..1 | string |
+ * | prefix | 7.1.4 | 1 | string |
+ * | reference | 7.19.4 | 0..1 | string |
+ * | revision | 7.1.9 | 0..n | revision |
+ * | rpc | 7.13 | 0..n | TODO |
+ * | typedef | 7.3 | 0..n | child nodes |
+ * | uses | 7.12 | 0..n | child nodes |
+ * | YANG-version | 7.1.2 | 0..1 | int |
+ * +--------------+---------+-------------+-----------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG module.
+ */
+public class YangModule
+ extends YangNode
+ implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
+ RpcNotificationContainer {
+
+ private static final long serialVersionUID = 806201610L;
+
+ /**
+ * Name of the module.
+ */
+ private String name;
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * The "contact" statement provides contact information for the module. The
+ * argument is a string that is used to specify contact information for the
+ * person or persons to whom technical queries concerning this module should
+ * be sent, such as their name, postal address, telephone number, and
+ * electronic mail address.
+ */
+ private String contact;
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * The "description" statement takes as an argument a string that contains a
+ * human-readable textual description of this definition. The text is
+ * provided in a language (or languages) chosen by the module developer; for
+ * the sake of interoperability.
+ */
+ private String description;
+
+ /**
+ * List of YANG modules imported.
+ */
+ private List<YangImport> importList;
+
+ /**
+ * List of YANG sub-modules included.
+ */
+ private List<YangInclude> includeList;
+
+ /**
+ * List of leaves at root level in the module.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf-lists at root level in the module.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ /**
+ * Name space of the module.
+ */
+ private YangNameSpace nameSpace;
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * The "organization" statement defines the party responsible for this
+ * module. The argument is a string that is used to specify a textual
+ * description of the organization(s) under whose auspices this module was
+ * developed.
+ */
+ private String organization;
+
+ /**
+ * Prefix to refer to the objects in module.
+ */
+ private String prefix;
+
+ /**
+ * Reference of the module.
+ */
+ private String reference;
+
+ /**
+ * Revision info of the module.
+ */
+ private YangRevision revision;
+
+ /**
+ * YANG version.
+ */
+ private byte version;
+
+ /*-
+ * Reference RFC 6020.
+ *
+ * Nested typedefs and groupings.
+ * Typedefs and groupings may appear nested under many YANG statements,
+ * allowing these to be lexically scoped by the hierarchy under which
+ * they appear. This allows types and groupings to be defined near
+ * where they are used, rather than placing them at the top level of the
+ * hierarchy. The close proximity increases readability.
+ *
+ * Scoping also allows types to be defined without concern for naming
+ * conflicts between types in different submodules. Type names can be
+ * specified without adding leading strings designed to prevent name
+ * collisions within large modules.
+ *
+ * Finally, scoping allows the module author to keep types and groupings
+ * private to their module or submodule, preventing their reuse. Since
+ * only top-level types and groupings (i.e., those appearing as
+ * sub-statements to a module or submodule statement) can be used outside
+ * the module or submodule, the developer has more control over what
+ * pieces of their module are presented to the outside world, supporting
+ * the need to hide internal information and maintaining a boundary
+ * between what is shared with the outside world and what is kept
+ * private.
+ *
+ * Scoped definitions MUST NOT shadow definitions at a higher scope. A
+ * type or grouping cannot be defined if a higher level in the schema
+ * hierarchy has a definition with a matching identifier.
+ *
+ * A reference to an unprefixed type or grouping, or one which uses the
+ * prefix of the current module, is resolved by locating the closest
+ * matching "typedef" or "grouping" statement among the immediate
+ * sub-statements of each ancestor statement.
+ */
+ private List<YangResolutionInfo> derivedTypeResolutionList;
+
+ /**
+ * uses resolution list.
+ */
+ private List<YangResolutionInfo> usesResolutionList;
+
+ /**
+ * Creates a YANG node of module type.
+ */
+ public YangModule() {
+
+ super(YangNodeType.MODULE_NODE);
+ derivedTypeResolutionList = new LinkedList<>();
+ usesResolutionList = new LinkedList<>();
+ importList = new LinkedList<YangImport>();
+ includeList = new LinkedList<YangInclude>();
+ listOfLeaf = new LinkedList<YangLeaf>();
+ listOfLeafList = new LinkedList<YangLeafList>();
+ }
+
+ /**
+ * Returns name of the module.
+ *
+ * @return module name
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets module name.
+ *
+ * @param moduleName module name
+ */
+ @Override
+ public void setName(String moduleName) {
+ name = moduleName;
+ }
+
+ /**
+ * Returns the contact details of the module owner.
+ *
+ * @return the contact details of YANG owner
+ */
+ public String getContact() {
+ return contact;
+ }
+
+ /**
+ * Sets the contact details of the module owner.
+ *
+ * @param contact the contact details of YANG owner
+ */
+ public void setContact(String contact) {
+ this.contact = contact;
+ }
+
+ /**
+ * Returns the description of module.
+ *
+ * @return the description of YANG module
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description of module.
+ *
+ * @param description set the description of YANG module
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the list of imported modules.
+ *
+ * @return the list of imported modules
+ */
+ @Override
+ public List<YangImport> getImportList() {
+ return importList;
+ }
+
+ /**
+ * Adds the imported module information to the import list.
+ *
+ * @param importedModule module being imported
+ */
+ @Override
+ public void addToImportList(YangImport importedModule) {
+ getImportList().add(importedModule);
+ }
+
+ @Override
+ public void setImportList(List<YangImport> importList) {
+ this.importList = importList;
+ }
+
+ /**
+ * Returns the list of included sub modules.
+ *
+ * @return the included list of sub modules
+ */
+ @Override
+ public List<YangInclude> getIncludeList() {
+ return includeList;
+ }
+
+ /**
+ * Adds the included sub module information to the include list.
+ *
+ * @param includeModule submodule being included
+ */
+ @Override
+ public void addToIncludeList(YangInclude includeModule) {
+ getIncludeList().add(includeModule);
+ }
+
+ @Override
+ public void setIncludeList(List<YangInclude> includeList) {
+ this.includeList = includeList;
+ }
+
+ /**
+ * Returns the list of leaves in module.
+ *
+ * @return the list of leaves
+ */
+ @Override
+ public List<YangLeaf> getListOfLeaf() {
+ return listOfLeaf;
+ }
+
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ /**
+ * Adds a leaf in module.
+ *
+ * @param leaf the leaf to be added
+ */
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+ getListOfLeaf().add(leaf);
+ }
+
+ /**
+ * Returns the list of leaf-list from module.
+ *
+ * @return the list of leaf-list
+ */
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return listOfLeafList;
+ }
+
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+
+ /**
+ * Adds a leaf-list in module.
+ *
+ * @param leafList the leaf-list to be added
+ */
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+ getListOfLeafList().add(leafList);
+ }
+
+ /**
+ * Returns the name space of module elements.
+ *
+ * @return the nameSpace
+ */
+ public YangNameSpace getNameSpace() {
+ return nameSpace;
+ }
+
+ /**
+ * Sets the name space of module elements.
+ *
+ * @param nameSpace the nameSpace to set
+ */
+ public void setNameSpace(YangNameSpace nameSpace) {
+ this.nameSpace = nameSpace;
+ }
+
+ /**
+ * Returns the modules organization.
+ *
+ * @return the organization
+ */
+ public String getOrganization() {
+ return organization;
+ }
+
+ /**
+ * Sets the modules organization.
+ *
+ * @param org the organization to set
+ */
+ public void setOrganization(String org) {
+ organization = org;
+ }
+
+ /**
+ * Returns the prefix.
+ *
+ * @return the prefix
+ */
+ @Override
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * Sets the prefix.
+ *
+ * @param prefix the prefix to set
+ */
+ @Override
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ @Override
+ public void resolveSelfFileLinking(ResolvableType type)
+ throws DataModelException {
+ // Get the list to be resolved.
+ List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
+ // Resolve linking for a resolution list.
+ resolveLinkingForResolutionList(resolutionList, this);
+ }
+
+ @Override
+ public void resolveInterFileLinking(ResolvableType type)
+ throws DataModelException {
+ // Get the list to be resolved.
+ List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
+ // Resolve linking for a resolution list.
+ linkInterFileReferences(resolutionList, this);
+ }
+
+ /**
+ * 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 revision.
+ *
+ * @return the revision
+ */
+ public YangRevision getRevision() {
+ return revision;
+ }
+
+ /**
+ * Sets the revision.
+ *
+ * @param revision the revision to set
+ */
+ public void setRevision(YangRevision revision) {
+ this.revision = revision;
+ }
+
+ /**
+ * Returns the version.
+ *
+ * @return the version
+ */
+ public byte getVersion() {
+ return version;
+ }
+
+ /**
+ * Sets the version.
+ *
+ * @param version the version to set
+ */
+ public void setVersion(byte version) {
+ this.version = version;
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns MODULE_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.MODULE_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ /*
+ * Module is root in the data model tree, hence there is no entry
+ * validation
+ */
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ /*
+ * TODO: perform symbol linking for the imported or included YANG info.
+ * TODO: perform symbol resolution for referred YANG entities.
+ */
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Asks helper to detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Not required as module doesn't have any parent.
+ }
+
+ @Override
+ public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
+ if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
+ return derivedTypeResolutionList;
+ } else {
+ return usesResolutionList;
+ }
+
+ }
+
+ @Override
+ public void addToResolutionList(YangResolutionInfo resolutionInfo,
+ ResolvableType type) {
+ if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
+ derivedTypeResolutionList.add(resolutionInfo);
+ } else if (type == ResolvableType.YANG_USES) {
+ usesResolutionList.add(resolutionInfo);
+ }
+ }
+
+ @Override
+ public void setResolutionList(List<YangResolutionInfo> resolutionList,
+ ResolvableType type) {
+ if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
+ derivedTypeResolutionList = resolutionList;
+ } else if (type == ResolvableType.YANG_USES) {
+ usesResolutionList = resolutionList;
+ }
+
+ }
+
+ @Override
+ public void addReferencesToImportList(Set<YangNode> yangNodeSet)
+ throws DataModelException {
+ Iterator<YangImport> importInfoIterator = getImportList().iterator();
+ // Run through the imported list to add references.
+ while (importInfoIterator.hasNext()) {
+ YangImport yangImport = importInfoIterator.next();
+ yangImport.addReferenceToImport(yangNodeSet);
+ }
+ }
+
+ @Override
+ public void addReferencesToIncludeList(Set<YangNode> yangNodeSet)
+ throws DataModelException {
+ Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator();
+ // Run through the included list to add references.
+ while (includeInfoIterator.hasNext()) {
+ YangInclude yangInclude = includeInfoIterator.next();
+ YangSubModule subModule = null;
+ try {
+ subModule = yangInclude.addReferenceToInclude(yangNodeSet);
+ } catch (DataModelException e) {
+ throw e;
+ }
+ // Check if the referred sub-modules parent is self
+ if (!(subModule.getBelongsTo().getModuleNode() == this)) {
+ yangInclude.reportIncludeError();
+ }
+ }
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMust.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMust.java
new file mode 100644
index 0000000..ead6c5d
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMust.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*-
+ * The "must" statement, which is optional, takes as an argument a string that
+ * contains an XPath expression. It is used to formally declare a constraint
+ * on valid data.
+ *
+ * When a datastore is validated, all "must" constraints are conceptually
+ * evaluated once for each data node in the data tree, and for all leafs with
+ * default values in use. If a data node does not exist in the data tree, and
+ * it does not have a default value, its "must" statements are not evaluated.
+ *
+ * All such constraints MUST evaluate to true for the data to be valid.
+ *
+ * The must's sub-statements
+ *
+ * +---------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +---------------+---------+-------------+------------------+
+ * | description | 7.19.3 | 0..1 | -string |
+ * | error-app-tag | 7.5.4.2 | 0..1 | -not supported |
+ * | error-message | 7.5.4.1 | 0..1 | -not supported |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * +---------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents information defined in YANG must.
+ */
+public class YangMust implements YangDesc, YangReference, Parsable, Serializable {
+
+ private static final long serialVersionUID = 806201646L;
+
+ /**
+ * Constraint info.
+ */
+ private String constratint;
+
+ /**
+ * Description string.
+ */
+ private String description;
+
+ /**
+ * Reference string.
+ */
+ private String reference;
+
+ /**
+ * Creates a YANG must restriction.
+ */
+ public YangMust() {
+ }
+
+ /**
+ * Returns the constraint.
+ *
+ * @return the constraint
+ */
+ public String getConstratint() {
+ return constratint;
+ }
+
+ /**
+ * Sets the constraint.
+ *
+ * @param constratint the constraint to set
+ */
+ public void setConstratint(String constratint) {
+ this.constratint = constratint;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the textual reference.
+ *
+ * @return the reference
+ */
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ /**
+ * Sets the textual reference.
+ *
+ * @param reference the reference to set
+ */
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns MUST_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.MUST_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNameSpace.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNameSpace.java
new file mode 100644
index 0000000..60f327f
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNameSpace.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*
+ * Reference:RFC 6020.
+ * The "namespace" statement defines the XML namespace that all
+ * identifiers defined by the module are qualified by, with the
+ * exception of data node identifiers defined inside a grouping.
+ * The argument to the "namespace" statement is the URI of the
+ * namespace.
+ */
+
+/**
+ * Represents name space to be used for the XML data tree.
+ */
+public class YangNameSpace implements Parsable, Serializable {
+
+ private static final long serialVersionUID = 806201647L;
+
+ private String uri;
+
+ /**
+ * Creats a YANG name space object.
+ */
+ public YangNameSpace() {
+ }
+
+ /**
+ * Returns the name space URI.
+ *
+ * @return the URI
+ */
+ public String getUri() {
+ return uri;
+ }
+
+ /**
+ * Sets the name space URI.
+ *
+ * @param uri the URI to set
+ */
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns NAMESPACE_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.NAMESPACE_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
new file mode 100644
index 0000000..20b1686
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
@@ -0,0 +1,230 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+
+/**
+ * Represents base class of a node in data model tree.
+ */
+public abstract class YangNode
+ implements Cloneable, Serializable {
+
+ private static final long serialVersionUID = 806201601L;
+
+ /**
+ * Type of node.
+ */
+ private YangNodeType nodeType;
+
+ /**
+ * Parent reference.
+ */
+ private YangNode parent;
+
+ /**
+ * First child reference.
+ */
+ private YangNode child;
+
+ /**
+ * Next sibling reference.
+ */
+ private YangNode nextSibling;
+
+ /**
+ * Previous sibling reference.
+ */
+ private YangNode previousSibling;
+
+ /**
+ * Returns the nodes name.
+ *
+ * @return nodes name
+ */
+ public abstract String getName();
+
+ /**
+ * Sets the nodes name.
+ *
+ * @param name nodes name
+ */
+ public abstract void setName(String name);
+
+ /**
+ * Creates a YANG node object.
+ */
+ @SuppressWarnings("unused")
+ private YangNode() {
+
+ }
+
+ /**
+ * Creates a specific type of node.
+ *
+ * @param type of YANG node
+ */
+ protected YangNode(YangNodeType type) {
+ setNodeType(type);
+ }
+
+ /**
+ * Returns the node type.
+ *
+ * @return node type
+ */
+ public YangNodeType getNodeType() {
+ return nodeType;
+ }
+
+ /**
+ * Sets the node type.
+ *
+ * @param nodeType type of node
+ */
+ private void setNodeType(YangNodeType nodeType) {
+ this.nodeType = nodeType;
+ }
+
+ /**
+ * Returns the parent of node.
+ *
+ * @return parent of node
+ */
+ public YangNode getParent() {
+ return parent;
+ }
+
+ /**
+ * Sets the parent of node.
+ *
+ * @param parent node
+ */
+ public void setParent(YangNode parent) {
+ this.parent = parent;
+ }
+
+ /**
+ * Returns the first child of node.
+ *
+ * @return first child of node
+ */
+ public YangNode getChild() {
+ return child;
+ }
+
+ /**
+ * Sets the first instance of a child node.
+ *
+ * @param child is only child to be set
+ */
+ public void setChild(YangNode child) {
+ this.child = child;
+ }
+
+ /**
+ * Returns the next sibling of node.
+ *
+ * @return next sibling of node
+ */
+ public YangNode getNextSibling() {
+ return nextSibling;
+ }
+
+ /**
+ * Sets the next sibling of node.
+ *
+ * @param sibling YANG node
+ */
+ private void setNextSibling(YangNode sibling) {
+ nextSibling = sibling;
+ }
+
+ /**
+ * Returns the previous sibling.
+ *
+ * @return previous sibling node
+ */
+ public YangNode getPreviousSibling() {
+ return previousSibling;
+ }
+
+ /**
+ * Sets the previous sibling.
+ *
+ * @param previousSibling points to predecessor sibling
+ */
+ private void setPreviousSibling(YangNode previousSibling) {
+ this.previousSibling = previousSibling;
+ }
+
+ /**
+ * Adds a child node, the children sibling list will be sorted based on node
+ * type.
+ *
+ * @param newChild refers to a child to be added
+ * @throws DataModelException due to violation in data model rules
+ */
+ public void addChild(YangNode newChild)
+ throws DataModelException {
+ if (newChild.getNodeType() == null) {
+ throw new DataModelException("Abstract node cannot be inserted into a tree");
+ }
+
+ if (newChild.getParent() == null) {
+ newChild.setParent(this);
+ } else if (newChild.getParent() != this) {
+ throw new DataModelException("Node is already part of a tree");
+ }
+
+ if (newChild.getChild() != null) {
+ throw new DataModelException("Child to be added is not atomic, it already has a child");
+ }
+
+ if (newChild.getNextSibling() != null) {
+ throw new DataModelException("Child to be added is not atomic, it already has a next sibling");
+ }
+
+ if (newChild.getPreviousSibling() != null) {
+ throw new DataModelException("Child to be added is not atomic, it already has a previous sibling");
+ }
+
+ /* First child to be added */
+ if (getChild() == null) {
+ setChild(newChild);
+ return;
+ }
+
+ YangNode curNode;
+ curNode = getChild();
+
+ /*
+ * Get the predecessor child of new child
+ */
+ while (curNode.getNextSibling() != null) {
+
+ curNode = curNode.getNextSibling();
+ }
+
+ /* If the new node needs to be the last child */
+ if (curNode.getNextSibling() == null) {
+ curNode.setNextSibling(newChild);
+ newChild.setPreviousSibling(curNode);
+ }
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNodeIdentifier.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNodeIdentifier.java
new file mode 100644
index 0000000..8c0ff9f
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNodeIdentifier.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+
+/**
+ * Represents YANG node identifier which is a combination of prefix and name.
+ */
+public class YangNodeIdentifier implements Serializable {
+
+ private static final long serialVersionUID = 806201648L;
+
+ // Name of the node.
+ private String name;
+
+ // Prefix of the node.
+ private String prefix;
+
+ /**
+ * Creates an instance of YANG node identifier.
+ */
+ public YangNodeIdentifier() {
+ }
+
+ /**
+ * Returns name of the node identifier.
+ *
+ * @return name of the node identifier
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets name of the node identifier.
+ *
+ * @param name name of the node identifier
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns prefix of the node identifier.
+ *
+ * @return name of the node identifier
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * Sets prefix of the node identifier.
+ *
+ * @param prefix prefix of the node identifier
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNodeType.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNodeType.java
new file mode 100644
index 0000000..35fe918
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNodeType.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+/**
+ * Represents node type in data model tree corresponding to YANG schema.
+ */
+public enum YangNodeType {
+ /**
+ * Node contains module information.
+ */
+ MODULE_NODE,
+
+ /**
+ * Node contains sub module information.
+ */
+ SUB_MODULE_NODE,
+
+ /**
+ * Node contains "YANG's typedef" information.
+ */
+ TYPEDEF_NODE,
+
+ /**
+ * Node contains "YANG's type" information.
+ */
+ TYPE_NODE,
+
+ /**
+ * Node contains "YANG's choice" information.
+ */
+ CHOICE_NODE,
+
+ /**
+ * Node contains "YANG's case" information.
+ */
+ CASE_NODE,
+
+ /**
+ * Node contains "YANG's enumeration" information.
+ */
+ ENUMERATION_NODE,
+
+ /**
+ * Node contains grouping information.
+ */
+ GROUPING_NODE,
+
+ /**
+ * Node contains "YANG's uses" information.
+ */
+ USES_NODE,
+
+ /**
+ * Node contains augmentation information.
+ */
+ AUGMENT_NODE,
+
+ /**
+ * Node contains "YANG's container" information.
+ */
+ CONTAINER_NODE,
+
+ /**
+ * Node contains "YANG's notification" information.
+ */
+ NOTIFICATION_NODE,
+
+ /**
+ * Node contains "YANG's input" information.
+ */
+ INPUT_NODE,
+
+ /**
+ * Node contains "YANG's output" information.
+ */
+ OUTPUT_NODE,
+
+ /**
+ * Node contains "YANG's rpc" information.
+ */
+ RPC_NODE,
+
+ /**
+ * Node contains "YANG's union" information.
+ */
+ UNION_NODE,
+
+ /**
+ * Node contains "YANG's list" information.
+ */
+ LIST_NODE
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
new file mode 100644
index 0000000..6fba390
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
@@ -0,0 +1,224 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+
+/*
+ * Reference RFC 6020.
+ *
+ * YANG allows the definition of notifications suitable for NETCONF.
+ * YANG data definition statements are used to model the content of the
+ * notification.
+ *
+ * The "notification" statement is used to define a NETCONF
+ * notification. It takes one argument, which is an identifier,
+ * followed by a block of substatements that holds detailed notification
+ * information. The "notification" statement defines a notification
+ * node in the schema tree.
+ *
+ * If a leaf in the notification tree has a "mandatory" statement with
+ * the value "true", the leaf MUST be present in a NETCONF notification.
+ *
+ * If a leaf in the notification tree has a default value, the NETCONF
+ * client MUST use this value in the same cases as described in
+ * Section 7.6.1. In these cases, the client MUST operationally behave
+ * as if the leaf was present in the NETCONF notification with the
+ * default value as its value.
+ *
+ * If a "config" statement is present for any node in the notification
+ * tree, the "config" statement is ignored.
+ *
+ * The notification's substatements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | anyxml | 7.10 | 0..n | -not supported |
+ * | choice | 7.9 | 0..n | -child nodes |
+ * | container | 7.5 | 0..n | -child nodes |
+ * | description | 7.19.3 | 0..1 | -string |
+ * | grouping | 7.11 | 0..n | -child nodes |
+ * | if-feature | 7.18.2 | 0..n | -TODO |
+ * | leaf | 7.6 | 0..n | -YangLeaf |
+ * | leaf-list | 7.7 | 0..n | -YangLeafList |
+ * | list | 7.8 | 0..n | -child nodes |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * | typedef | 7.3 | 0..n | -child nodes |
+ * | uses | 7.12 | 0..n | -child nodes |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG notification.
+ */
+public class YangNotification
+ extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
+
+ private static final long serialVersionUID = 806201611L;
+
+ /**
+ * Name of the notification.
+ */
+ private String name;
+
+ /**
+ * Description of notification.
+ */
+ private String description;
+
+ /**
+ * List of leaves contained.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf-lists contained.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ /**
+ * Reference of the module.
+ */
+ private String reference;
+
+ /**
+ * Status of the node.
+ */
+ private YangStatusType status = YangStatusType.CURRENT;
+
+ /**
+ * Create a notification node.
+ */
+ public YangNotification() {
+ super(YangNodeType.NOTIFICATION_NODE);
+ listOfLeaf = new LinkedList<YangLeaf>();
+ listOfLeafList = new LinkedList<YangLeafList>();
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Duplicate input identifier detected, same as notification \""
+ + getName() + "\"");
+ }
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.NOTIFICATION_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ //TODO: implement the method.
+ }
+
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ //TODO: implement the method.
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Override
+ public List<YangLeaf> getListOfLeaf() {
+ return listOfLeaf;
+ }
+
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+ getListOfLeaf().add(leaf);
+ }
+
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return listOfLeafList;
+ }
+
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+ getListOfLeafList().add(leafList);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
new file mode 100644
index 0000000..f06ca01
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The "output" statement, which is optional, is used to define output
+ * parameters to the RPC operation. It does not take an argument. The
+ * substatements to "output" define nodes under the RPC's output node.
+ *
+ * If a leaf in the output tree has a "mandatory" statement with the
+ * value "true", the leaf MUST be present in a NETCONF RPC reply.
+ *
+ * If a leaf in the output tree has a default value, the NETCONF client
+ * MUST use this value in the same cases as described in Section 7.6.1.
+ * In these cases, the client MUST operationally behave as if the leaf
+ * was present in the NETCONF RPC reply with the default value as its
+ * value.
+ *
+ * If a "config" statement is present for any node in the output tree,
+ * the "config" statement is ignored.
+ *
+ * If any node has a "when" statement that would evaluate to false, then
+ * this node MUST NOT be present in the output tree.
+ *
+ * The output substatements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | anyxml | 7.10 | 0..n | -not supported |
+ * | choice | 7.9 | 0..n | -child nodes |
+ * | container | 7.5 | 0..n | -child nodes |
+ * | grouping | 7.11 | 0..n | -child nodes |
+ * | leaf | 7.6 | 0..n | -YangLeaf |
+ * | leaf-list | 7.7 | 0..n | -YangLeafList |
+ * | list | 7.8 | 0..n | -child nodes |
+ * | typedef | 7.3 | 0..n | -child nodes |
+ * | uses | 7.12 | 0..n | -child nodes |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG output.
+ */
+public class YangOutput
+ extends YangNode
+ implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
+
+ private static final long serialVersionUID = 806201612L;
+
+ /**
+ * Name of the output.
+ */
+ private String name;
+
+ /**
+ * List of leaves contained.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf-lists contained.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ /**
+ * Create a rpc output node.
+ */
+ public YangOutput() {
+ super(YangNodeType.OUTPUT_NODE);
+ listOfLeaf = new LinkedList<YangLeaf>();
+ listOfLeafList = new LinkedList<YangLeafList>();
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Duplicate identifier detected, same as output \""
+ + getName() + "\"");
+ }
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.OUTPUT_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ //TODO: implement the method.
+ }
+
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ //TODO: implement the method.
+ }
+
+ @Override
+ public List<YangLeaf> getListOfLeaf() {
+ return listOfLeaf;
+ }
+
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+ getListOfLeaf().add(leaf);
+ }
+
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return listOfLeafList;
+ }
+
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+ getListOfLeafList().add(leafList);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
new file mode 100644
index 0000000..939b732
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.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.yangutils.datamodel;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The pattern Statement
+ *
+ * The "pattern" statement, which is an optional sub-statement to the
+ * "type" statement, takes as an argument a regular expression string.
+ * It is used to restrict the built-in type "string", or types derived
+ * from "string", to values that match the pattern.
+ *
+ * If the type has multiple "pattern" statements, the expressions are
+ * ANDed together, i.e., all such expressions have to match.
+ *
+ * If a pattern restriction is applied to an already pattern-restricted
+ * type, values must match all patterns in the base type, in addition to
+ * the new patterns.
+ * The pattern's sub-statements
+ *
+ * +---------------+---------+-------------+
+ * | substatement | section | cardinality |
+ * +---------------+---------+-------------+
+ * | description | 7.19.3 | 0..1 |
+ * | error-app-tag | 7.5.4.2 | 0..1 |
+ * | error-message | 7.5.4.1 | 0..1 |
+ * | reference | 7.19.4 | 0..1 |
+ * +---------------+---------+-------------+
+ */
+
+/**
+ * Represents pattern restriction information. The regular expression restriction on string
+ * data type.
+ */
+public class YangPatternRestriction implements Serializable {
+
+ private static final long serialVersionUID = 806201649L;
+
+ /**
+ * Pattern restriction defined for the current type.
+ */
+ private List<String> patternList;
+
+ /**
+ * Creates a YANG pattern restriction object.
+ */
+ public YangPatternRestriction() {
+ setPatternList(new LinkedList<String>());
+ }
+
+ /**
+ * Returns the pattern restriction defined for the current type.
+ *
+ * @return pattern restriction defined for the current type.
+ */
+ public List<String> getPatternList() {
+ return patternList;
+ }
+
+ /**
+ * Sets the pattern restriction defined for the current type.
+ *
+ * @param pattern pattern restriction defined for the current type..
+ */
+ private void setPatternList(List<String> pattern) {
+ patternList = pattern;
+ }
+
+ /**
+ * Adds a new pattern to the list of pattern restriction.
+ *
+ * @param newPattern pattern restriction.
+ */
+ public void addPattern(String newPattern) {
+ getPatternList().add(newPattern);
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeInterval.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeInterval.java
new file mode 100644
index 0000000..4ee9787
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeInterval.java
@@ -0,0 +1,81 @@
+/*Copyright 2016.year Open Networking Laboratory
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.*/
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
+
+/**
+ * Represents single interval information of a range.
+ *
+ * @param <T> range type based on the data type
+ */
+public class YangRangeInterval<T extends YangBuiltInDataTypeInfo<T>> implements Serializable {
+
+ private static final long serialVersionUID = 806201650L;
+
+ /**
+ * Starting value of the range interval.
+ */
+ private T startValue;
+
+ /**
+ * Last value of the range interval.
+ */
+ private T endValue;
+
+ /**
+ * Creates YANG range interval object.
+ */
+ public YangRangeInterval() {
+ }
+
+ /**
+ * Returns the starting value of the range interval.
+ *
+ * @return the starting value of the range interval
+ */
+ public T getStartValue() {
+ return startValue;
+ }
+
+ /**
+ * Sets the starting value of the range interval.
+ *
+ * @param startValue the starting value of the range interval
+ */
+ public void setStartValue(T startValue) {
+ this.startValue = startValue;
+ }
+
+ /**
+ * Returns the last value of the range interval.
+ *
+ * @return last value of the range interval
+ */
+ public T getEndValue() {
+ return endValue;
+ }
+
+ /**
+ * Sets the last value of the range interval.
+ *
+ * @param endValue last value of the range interval
+ */
+ public void setEndValue(T endValue) {
+ this.endValue = endValue;
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
new file mode 100644
index 0000000..654ac93
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
@@ -0,0 +1,338 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
+
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The range Statement
+ *
+ * The "range" statement, which is an optional sub-statement to the
+ * "type" statement, takes as an argument a range expression string. It
+ * is used to restrict integer and decimal built-in types, or types
+ * derived from those.
+ *
+ * A range consists of an explicit value, or a lower-inclusive bound,
+ * two consecutive dots "..", and an upper-inclusive bound. Multiple
+ * values or ranges can be given, separated by "|". If multiple values
+ * or ranges are given, they all MUST be disjoint and MUST be in
+ * ascending order. If a range restriction is applied to an already
+ * range-restricted type, the new restriction MUST be equal or more
+ * limiting, that is raising the lower bounds, reducing the upper
+ * bounds, removing explicit values or ranges, or splitting ranges into
+ * multiple ranges with intermediate gaps. Each explicit value and
+ * range boundary value given in the range expression MUST match the
+ * type being restricted, or be one of the special values "min" or
+ * "max". "min" and "max" mean the minimum and maximum value accepted
+ * for the type being restricted, respectively.
+ */
+
+/**
+ * Represents ascending range restriction information.
+ *
+ * @param <T> range type (data type)
+ */
+public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
+ implements YangDesc, YangReference, YangAppErrorInfo, Parsable, Serializable {
+
+ private static final long serialVersionUID = 8062016051L;
+
+ /**
+ * Ascending list of range interval restriction. If the restriction is a
+ * single value, the start and end length of the range is same.
+ */
+ private List<YangRangeInterval<T>> ascendingRangeIntervals;
+
+ /**
+ * Textual reference.
+ */
+ private String reference;
+
+ /**
+ * Application's error message, to be used for data error.
+ */
+ private String errorMessage;
+
+ /**
+ * Application's error tag, to be filled in data validation error response.
+ */
+ private String errorAppTag;
+
+ /**
+ * Textual description.
+ */
+ private String description;
+
+ /**
+ * Creates YANG range restriction object.
+ */
+ public YangRangeRestriction() {
+ }
+
+ /**
+ * Returns the list of range interval restriction in ascending order.
+ *
+ * @return list of range interval restriction in ascending order
+ */
+ public List<YangRangeInterval<T>> getAscendingRangeIntervals() {
+ return ascendingRangeIntervals;
+ }
+
+ /**
+ * Sets the list of range interval restriction in ascending order.
+ *
+ * @param rangeList list of range interval restriction in ascending order
+ */
+ private void setAscendingRangeIntervals(List<YangRangeInterval<T>> rangeList) {
+ ascendingRangeIntervals = rangeList;
+ }
+
+ /**
+ * Returns the minimum valid value as per the restriction.
+ *
+ * @return minimum restricted value
+ * @throws DataModelException data model exception for minimum restriction
+ */
+ public T getMinRestrictedvalue() throws DataModelException {
+ if (getAscendingRangeIntervals() == null) {
+ throw new DataModelException("No range restriction info");
+ }
+ if (getAscendingRangeIntervals().isEmpty()) {
+ throw new DataModelException("No range interval info");
+ }
+ return getAscendingRangeIntervals().get(0).getStartValue();
+ }
+
+ /**
+ * Returns the maximum valid value as per the restriction.
+ *
+ * @return minimum maximum value
+ * @throws DataModelException data model exception for maximum restriction
+ */
+ public T getMaxRestrictedvalue() throws DataModelException {
+ if (getAscendingRangeIntervals() == null) {
+ throw new DataModelException("No range restriction info");
+ }
+ if (getAscendingRangeIntervals().isEmpty()) {
+ throw new DataModelException("No range interval info");
+ }
+ return getAscendingRangeIntervals()
+ .get(getAscendingRangeIntervals().size() - 1).getEndValue();
+ }
+
+ /**
+ * Adds new interval to extend its range in the last. i.e. newly added
+ * interval needs to be bigger than the biggest interval in the list.
+ *
+ * @param newInterval restricted length interval
+ * @throws DataModelException data model exception for range restriction
+ */
+ public void addRangeRestrictionInterval(YangRangeInterval<T> newInterval) throws DataModelException {
+
+ checkNotNull(newInterval);
+ checkNotNull(newInterval.getStartValue());
+
+ if (getAscendingRangeIntervals() == null) {
+ /*
+ * First interval that is being added, and it must be the smallest
+ * interval.
+ */
+ setAscendingRangeIntervals(new LinkedList<YangRangeInterval<T>>());
+ getAscendingRangeIntervals().add(newInterval);
+ return;
+ }
+
+ T curMaxvalue = getMaxRestrictedvalue();
+
+ if (newInterval.getStartValue().compareTo(curMaxvalue) != 1) {
+ throw new DataModelException(
+ "New added range interval is lesser than the old interval(s)");
+ }
+
+ getAscendingRangeIntervals()
+ .add(getAscendingRangeIntervals().size(), newInterval);
+ }
+
+ /**
+ * Validates if the given value is correct as per the restriction.
+ *
+ * @param valueInString value
+ * @return true, if the value is confirming to restriction, false otherwise
+ * @throws DataModelException data model error
+ */
+ public boolean isValidValueString(String valueInString) throws DataModelException {
+
+ if (getAscendingRangeIntervals() == null
+ || getAscendingRangeIntervals().isEmpty()) {
+ // Throw exception, At least one default range needs to be set in
+ // constructor or in linker.
+ throw new DataModelException("Range interval missing in range restriction.");
+
+ }
+
+ YangDataTypes type = getAscendingRangeIntervals().get(0).getStartValue().getYangType();
+ YangBuiltInDataTypeInfo<?> value = getDataObjectFromString(valueInString, type);
+
+ for (YangRangeInterval<T> interval : getAscendingRangeIntervals()) {
+ int rangeStartCompareRes = interval.getStartValue().compareTo((T) value);
+ int rangeEndCompareRes = interval.getEndValue().compareTo((T) value);
+
+ if (rangeStartCompareRes <= 0 && rangeEndCompareRes >= 0) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Validates if the given interval is correct as per the restriction.
+ *
+ * @param rangeInterval range interval
+ * @return true, if the interval is confirming to restriction, false otherwise
+ * @throws DataModelException data model error
+ */
+ public boolean isValidInterval(YangRangeInterval rangeInterval) throws DataModelException {
+
+ if (getAscendingRangeIntervals() == null
+ || getAscendingRangeIntervals().isEmpty()) {
+ // Throw exception, At least one default range needs to be set in
+ // constructor or in linker.
+ throw new DataModelException("Range interval missing in range restriction.");
+ }
+
+ for (YangRangeInterval<T> interval : getAscendingRangeIntervals()) {
+ int rangeStartCompareRes = interval.getStartValue().compareTo((T) rangeInterval.getStartValue());
+ int rangeEndCompareRes = interval.getEndValue().compareTo((T) rangeInterval.getEndValue());
+
+ if (rangeStartCompareRes <= 0 && rangeEndCompareRes >= 0) {
+ return true;
+ }
+ }
+ throw new DataModelException("Range interval doesn't fall within the referred restriction ranges");
+ }
+
+ /**
+ * Returns the textual reference of the length restriction.
+ *
+ * @return textual reference of the length restriction
+ */
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ /**
+ * Sets the textual reference of the length restriction.
+ *
+ * @param ref textual reference of the length restriction
+ */
+ @Override
+ public void setReference(String ref) {
+ reference = ref;
+ }
+
+ /**
+ * Returns the description of the length restriction.
+ *
+ * @return description of the length restriction
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description of the length restriction.
+ *
+ * @param desc description of the length restriction
+ */
+ @Override
+ public void setDescription(String desc) {
+ description = desc;
+
+ }
+
+ /**
+ * Returns application's error message, to be used for data error.
+ *
+ * @return Application's error message, to be used for data error
+ */
+ @Override
+ public String getGetErrorMessage() {
+ return errorMessage;
+ }
+
+ /**
+ * Sets Application's error message, to be used for data error.
+ *
+ * @param errMsg Application's error message, to be used for data error
+ */
+ @Override
+ public void setErrorMessage(String errMsg) {
+ errorMessage = errMsg;
+
+ }
+
+ /**
+ * Returns application's error tag, to be used for data error.
+ *
+ * @return application's error tag, to be used for data error
+ */
+ @Override
+ public String getGetErrorAppTag() {
+ return errorAppTag;
+ }
+
+ /**
+ * Sets application's error tag, to be used for data error.
+ *
+ * @param errTag application's error tag, to be used for data error.
+ */
+ @Override
+ public void setErrorAppTag(String errTag) {
+ errorAppTag = errTag;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.RANGE_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO: implement the method.
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO: implement the method.
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangReference.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangReference.java
new file mode 100644
index 0000000..44397a3
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangReference.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.yangutils.datamodel;
+
+/**
+ * Abstraction of textual reference for a YANG entity. Abstracted to unify the
+ * parsing and translator processing of reference.
+ */
+public interface YangReference {
+
+ /**
+ * Returns the textual reference.
+ *
+ * @return the reference
+ */
+ String getReference();
+
+ /**
+ * Sets the textual reference.
+ *
+ * @param reference the reference to set
+ */
+ void setReference(String reference);
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangReferenceResolver.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangReferenceResolver.java
new file mode 100644
index 0000000..8be3242
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangReferenceResolver.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.List;
+import java.util.Set;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+
+/**
+ * Abstraction of YANG dependency resolution information. Abstracted to obtain the
+ * resolution information.
+ */
+public interface YangReferenceResolver {
+
+ /**
+ * Returns unresolved resolution list.
+ *
+ * @param type resolvable type
+ * @return list of resolution information objects
+ */
+ List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type);
+
+ /**
+ * Adds to the resolution list.
+ *
+ * @param resolutionInfo resolution information
+ * @param type resolvable type
+ */
+ void addToResolutionList(YangResolutionInfo resolutionInfo, ResolvableType type);
+
+ /**
+ * Creates resolution list.
+ *
+ * @param resolutionList resolution list
+ * @param type resolvable type
+ */
+ void setResolutionList(List<YangResolutionInfo> resolutionList, ResolvableType type);
+
+ /**
+ * Returns unresolved imported list.
+ *
+ * @return unresolved imported list
+ */
+ List<YangImport> getImportList();
+
+ /**
+ * Adds to the import list.
+ *
+ * @param yangImport import to be added
+ */
+ void addToImportList(YangImport yangImport);
+
+ /**
+ * Create import list.
+ *
+ * @param importList import list
+ */
+ void setImportList(List<YangImport> importList);
+
+ /**
+ * Returns unresolved include list.
+ *
+ * @return unresolved include list
+ */
+ List<YangInclude> getIncludeList();
+
+ /**
+ * Adds to the include list.
+ *
+ * @param yangInclude include to be added
+ */
+ void addToIncludeList(YangInclude yangInclude);
+
+ /**
+ * Creates include list.
+ *
+ * @param includeList include list
+ */
+ void setIncludeList(List<YangInclude> includeList);
+
+ /**
+ * Returns prefix of resolution root node.
+ *
+ * @return prefix resolution root node prefix
+ */
+ String getPrefix();
+
+ /**
+ * Sets prefix of resolution list root node.
+ *
+ * @param prefix resolution root node prefix
+ */
+ void setPrefix(String prefix);
+
+ /**
+ * Resolves self file linking.
+ *
+ * @param type resolvable type
+ * @throws DataModelException a violation in data model rule
+ */
+ void resolveSelfFileLinking(ResolvableType type)
+ throws DataModelException;
+
+ /**
+ * Resolves inter file linking.
+ *
+ * @param type resolvable type
+ * @throws DataModelException a violation in data model rule
+ */
+ void resolveInterFileLinking(ResolvableType type)
+ throws DataModelException;
+
+ /**
+ * Adds references to include.
+ *
+ * @param yangNodeSet YANG node info set
+ * @throws DataModelException a violation of data model rules
+ */
+ void addReferencesToIncludeList(Set<YangNode> yangNodeSet)
+ throws DataModelException;
+
+ /**
+ * Adds references to import.
+ *
+ * @param yangNodeSet YANG node info set
+ * @throws DataModelException a violation of data model rules
+ */
+ void addReferencesToImportList(Set<YangNode> yangNodeSet)
+ throws DataModelException;
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
new file mode 100644
index 0000000..c63e832
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.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.yangutils.datamodel;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+
+/**
+ * Abstraction of resolution object which will be resolved by linker.
+ *
+ * @param <T> type of resolution entity uses / type
+ */
+public interface YangResolutionInfo<T> extends LocationInfo {
+
+ /**
+ * Resolves linking with all the ancestors node for a resolution info.
+ *
+ * @param dataModelRootNode module/sub-module node
+ * @throws DataModelException DataModelException a violation of data model
+ * rules
+ */
+ void resolveLinkingForResolutionInfo(YangReferenceResolver dataModelRootNode)
+ throws DataModelException;
+
+ /**
+ * Retrieves information about the entity that needs to be resolved.
+ *
+ * @return information about the entity that needs to be resolved
+ */
+ YangEntityToResolveInfo<T> getEntityToResolveInfo();
+
+ /**
+ * Performs inter file linking of uses/type referring to typedef/grouping
+ * of other YANG file.
+ *
+ * @param dataModelRootNode module/sub-module node
+ * @throws DataModelException a violation in data model rule
+ */
+ void linkInterFile(YangReferenceResolver dataModelRootNode)
+ throws DataModelException;
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRevision.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRevision.java
new file mode 100644
index 0000000..aa326fd
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRevision.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*
+ * Reference:RFC 6020.
+ * The "revision" statement specifies the editorial revision history of
+ * the module, including the initial revision. A series of revision
+ * statements detail the changes in the module's definition. The
+ * argument is a date string in the format "YYYY-MM-DD", followed by a
+ * block of sub-statements that holds detailed revision information. A
+ * module SHOULD have at least one initial "revision" statement. For
+ * every published editorial change, a new one SHOULD be added in front
+ * of the revisions sequence, so that all revisions are in reverse
+ * chronological order.
+ * The revision's sub-statement
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | description | 7.19.3 | 0..1 |string |
+ * | reference | 7.19.4 | 0..1 |sring |
+ * +--------------+---------+-------------+------------------+
+ */
+/**
+ * Represents the information about the revision.
+ */
+public class YangRevision implements YangDesc, YangReference, Parsable, Serializable {
+
+ private static final long serialVersionUID = 8062016052L;
+
+ /**
+ * Revision date. Date string in the format "YYYY-MM-DD"
+ */
+ private String revDate;
+
+ /**
+ * Description of revision.
+ */
+ private String description;
+
+ /**
+ * Textual reference for revision.
+ */
+ private String reference;
+
+ /**
+ * Creates a YANG revision object.
+ */
+ public YangRevision() {
+ }
+
+ /**
+ * Returns the revision date.
+ *
+ * @return the revision date
+ */
+ public String getRevDate() {
+ return revDate;
+ }
+
+ /**
+ * Sets the revision date.
+ *
+ * @param revDate the revision date to set
+ */
+ public void setRevDate(String revDate) {
+ this.revDate = revDate;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the textual reference.
+ *
+ * @return the reference
+ */
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ /**
+ * Sets the textual reference.
+ *
+ * @param reference the reference to set
+ */
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns REVISION_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.REVISION_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java
new file mode 100644
index 0000000..62b8dd1
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The "rpc" statement is used to define a NETCONF RPC operation. It
+ * takes one argument, which is an identifier, followed by a block of
+ * substatements that holds detailed rpc information. This argument is
+ * the name of the RPC, and is used as the element name directly under
+ * the <rpc> element, as designated by the substitution group
+ * "rpcOperation" in [RFC4741].
+ *
+ * The "rpc" statement defines an rpc node in the schema tree. Under
+ * the rpc node, a schema node with the name "input", and a schema node
+ * with the name "output" are also defined. The nodes "input" and
+ * "output" are defined in the module's namespace.
+ *
+ * The rpc substatements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | description | 7.19.3 | 0..1 | -string |
+ * | grouping | 7.11 | 0..n | -child nodes |
+ * | if-feature | 7.18.2 | 0..n | -TODO |
+ * | input | 7.13.2 | 0..1 | -child nodes |
+ * | output | 7.13.3 | 0..1 | -child nodes |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * | typedef | 7.3 | 0..n | -child nodes |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG rpc.
+ */
+public class YangRpc extends YangNode implements YangCommonInfo, Parsable,
+ CollisionDetector {
+
+ private static final long serialVersionUID = 806201613L;
+
+ /**
+ * Name of the rpc.
+ */
+ private String name;
+
+ /**
+ * Description of rpc.
+ */
+ private String description;
+
+ /**
+ * Reference of the module.
+ */
+ private String reference;
+
+ /**
+ * Status of the node.
+ */
+ private YangStatusType status = YangStatusType.CURRENT;
+
+ /**
+ * Create a rpc node.
+ */
+ public YangRpc() {
+ super(YangNodeType.RPC_NODE);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ // Detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Duplicate input identifier detected, same as rpc \""
+ + getName() + "\"");
+ }
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.RPC_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ //TODO: implement the method.
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ //TODO: implement the method.
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStatus.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStatus.java
new file mode 100644
index 0000000..2b3c626
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStatus.java
@@ -0,0 +1,35 @@
+/*Copyright 2016.year Open Networking Laboratory
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.*/
+package org.onosproject.yangutils.datamodel;
+
+/**
+ * Abstraction for status on a YANG entity. Abstracted to unify the parsing and
+ * translator processing of status.
+ */
+public interface YangStatus {
+
+ /**
+ * Returns the status.
+ *
+ * @return the status
+ */
+ YangStatusType getStatus();
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ void setStatus(YangStatusType status);
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStatusType.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStatusType.java
new file mode 100644
index 0000000..d5ac982
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStatusType.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+/*
+ * Reference:RFC 6020.
+ * The "status" statement takes as an argument one of the strings
+ * "current", "deprecated", or "obsolete". If no status is specified,
+ * the default is "current".
+ */
+
+/**
+ * Represents the status of YANG entities.
+ */
+public enum YangStatusType {
+ /**
+ * Reference:RFC 6020.
+ *
+ * "current" means that the definition is current and valid.
+ */
+ CURRENT,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * "deprecated" indicates an obsolete definition, but it
+ * permits new/ continued implementation in order to foster interoperability
+ * with older/existing implementations.
+ */
+ DEPRECATED,
+
+ /**
+ * Reference:RFC 6020.
+ *
+ * "obsolete" means the definition is obsolete and
+ * SHOULD NOT be implemented and/or can be removed from implementations.
+ */
+ OBSOLETE
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
new file mode 100644
index 0000000..ce626ed
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
@@ -0,0 +1,256 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * A string can be restricted with the "length" and "pattern" statements.
+ *
+ */
+
+/**
+ * Represents the restriction for string data type.
+ */
+public class YangStringRestriction implements YangDesc, YangReference, YangAppErrorInfo, Parsable, Serializable {
+
+ /*-
+ * Reference RFC 6020.
+ * The length Statement
+ *
+ * The "length" statement, which is an optional sub-statement to the
+ * "type" statement, takes as an argument a length expression string.
+ * It is used to restrict the built-in type "string", or types derived
+ * from "string".
+ * A "length" statement restricts the number of unicode characters in
+ * the string.
+ * A length range consists of an explicit value, or a lower bound, two
+ * consecutive dots "..", and an upper bound. Multiple values or ranges
+ * can be given, separated by "|". Length-restricting values MUST NOT
+ * be negative. If multiple values or ranges are given, they all MUST
+ * be disjoint and MUST be in ascending order. If a length restriction
+ * is applied to an already length-restricted type, the new restriction
+ * MUST be equal or more limiting, that is, raising the lower bounds,
+ * reducing the upper bounds, removing explicit length values or ranges,
+ * or splitting ranges into multiple ranges with intermediate gaps. A
+ * length value is a non-negative integer, or one of the special values
+ * "min" or "max". "min" and "max" mean the minimum and maximum length
+ * accepted for the type being restricted, respectively. An
+ * implementation is not required to support a length value larger than
+ * 18446744073709551615.
+ * The length's sub-statements
+ *
+ * +---------------+---------+-------------+-----------------+
+ * | substatement | section | cardinality | mapped data type|
+ * +---------------+---------+-------------+-----------------+
+ * | description | 7.19.3 | 0..1 | string |
+ * | error-app-tag | 7.5.4.2 | 0..1 | string |
+ * | error-message | 7.5.4.1 | 0..1 | string |
+ * | reference | 7.19.4 | 0..1 | string |
+ * +---------------+---------+-------------+-----------------+
+ */
+
+ private static final long serialVersionUID = 8062016053L;
+
+ /**
+ * Length restriction information.
+ */
+ private YangRangeRestriction<YangUint64> lengthRestriction;
+
+ /**
+ * Effective pattern restriction for the type.
+ */
+ private YangPatternRestriction patternRestriction;
+
+ /**
+ * Textual reference.
+ */
+ private String reference;
+
+ /**
+ * Application's error message, to be used for data error.
+ */
+ private String errorMessage;
+
+ /**
+ * Application's error tag, to be filled in data validation error response.
+ */
+ private String errorAppTag;
+
+ /**
+ * Textual description.
+ */
+ private String description;
+
+ /**
+ * Creates a YANG string restriction object.
+ */
+ public YangStringRestriction() {
+ }
+
+ /**
+ * Returns the length restriction on the string data.
+ *
+ * @return length restriction on the string data
+ */
+ public YangRangeRestriction<YangUint64> getLengthRestriction() {
+ return lengthRestriction;
+ }
+
+ /**
+ * Sets the length restriction on the string data.
+ *
+ * @param lengthRestriction length restriction on the string data
+ */
+ public void setLengthRestriction(YangRangeRestriction<YangUint64> lengthRestriction) {
+ this.lengthRestriction = lengthRestriction;
+ }
+
+ /**
+ * Returns the pattern restriction for the type.
+ *
+ * @return pattern restriction for the type
+ */
+ public YangPatternRestriction getPatternRestriction() {
+ return patternRestriction;
+ }
+
+ /**
+ * Sets the pattern restriction for the type.
+ *
+ * @param patternRestriction pattern restriction for the type
+ */
+ public void setPatternRestriction(YangPatternRestriction patternRestriction) {
+ this.patternRestriction = patternRestriction;
+ }
+
+ /**
+ * Adds a new pattern restriction for the type.
+ *
+ * @param newPattern new pattern restriction for the type
+ */
+ public void addPattern(String newPattern) {
+ if (getPatternRestriction() == null) {
+ setPatternRestriction(new YangPatternRestriction());
+ }
+ getPatternRestriction().addPattern(newPattern);
+ }
+
+ /**
+ * Returns the textual reference of the string restriction.
+ *
+ * @return textual reference of the string restriction
+ */
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ /**
+ * Sets the textual reference of the string restriction.
+ *
+ * @param ref textual reference of the string restriction
+ */
+ @Override
+ public void setReference(String ref) {
+ reference = ref;
+ }
+
+ /**
+ * Returns the description of the string restriction.
+ *
+ * @return description of the string restriction
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description of the string restriction.
+ *
+ * @param desc description of the string restriction
+ */
+ @Override
+ public void setDescription(String desc) {
+ description = desc;
+
+ }
+
+ /**
+ * Returns application's error message, to be used for data error.
+ *
+ * @return Application's error message, to be used for data error
+ */
+ @Override
+ public String getGetErrorMessage() {
+ return errorMessage;
+ }
+
+ /**
+ * Sets Application's error message, to be used for data error.
+ *
+ * @param errMsg Application's error message, to be used for data error
+ */
+ @Override
+ public void setErrorMessage(String errMsg) {
+ errorMessage = errMsg;
+
+ }
+
+ /**
+ * Returns application's error tag, to be used for data error.
+ *
+ * @return application's error tag, to be used for data error
+ */
+ @Override
+ public String getGetErrorAppTag() {
+ return errorAppTag;
+ }
+
+ /**
+ * Sets application's error tag, to be used for data error.
+ *
+ * @param errTag application's error tag, to be used for data error.
+ */
+ @Override
+ public void setErrorAppTag(String errTag) {
+ errorAppTag = errTag;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.PATTERN_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO: implement the method.
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO: implement the method.
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
new file mode 100644
index 0000000..8e1ba9d
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
@@ -0,0 +1,604 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.linkInterFileReferences;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
+
+/*
+ * Reference RFC 6020.
+ *
+ * While the primary unit in YANG is a module, a YANG module can itself
+ * be constructed out of several submodules. Submodules allow a module
+ * designer to split a complex model into several pieces where all the
+ * submodules contribute to a single namespace, which is defined by the
+ * module that includes the submodules.
+ *
+ * The "submodule" statement defines the submodule's name, and groups
+ * all statements that belong to the submodule together. The
+ * "submodule" statement's argument is the name of the submodule,
+ * followed by a block of sub-statements that hold detailed submodule
+ * information.
+ *
+ * The submodule's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | anyxml | 7.10 | 0..n | - not supported |
+ * | augment | 7.15 | 0..n | - child nodes |
+ * | belongs-to | 7.2.2 | 1 | - YangBelongsTo |
+ * | choice | 7.9 | 0..n | - child nodes |
+ * | contact | 7.1.8 | 0..1 | - string |
+ * | container | 7.5 | 0..n | - child nodes |
+ * | description | 7.19.3 | 0..1 | - string |
+ * | deviation | 7.18.3 | 0..n | - TODO |
+ * | extension | 7.17 | 0..n | - TODO |
+ * | feature | 7.18.1 | 0..n | - TODO |
+ * | grouping | 7.11 | 0..n | - child nodes |
+ * | identity | 7.16 | 0..n | - TODO |
+ * | import | 7.1.5 | 0..n | - YangImport |
+ * | include | 7.1.6 | 0..n | - YangInclude |
+ * | leaf | 7.6 | 0..n | - YangLeaf |
+ * | leaf-list | 7.7 | 0..n | - YangLeafList |
+ * | list | 7.8 | 0..n | - child nodes |
+ * | notification | 7.14 | 0..n | - TODO |
+ * | organization | 7.1.7 | 0..1 | - string |
+ * | reference | 7.19.4 | 0..1 | - string |
+ * | revision | 7.1.9 | 0..n | - string |
+ * | rpc | 7.13 | 0..n | - TODO |
+ * | typedef | 7.3 | 0..n | - child nodes |
+ * | uses | 7.12 | 0..n | - child nodes |
+ * | YANG-version | 7.1.2 | 0..1 | - int |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG sub-module.
+ */
+public class YangSubModule
+ extends YangNode
+ implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
+ RpcNotificationContainer {
+
+ private static final long serialVersionUID = 806201614L;
+
+ /**
+ * Name of sub module.
+ */
+ private String name;
+
+ /**
+ * Module to which it belongs to.
+ */
+ private YangBelongsTo belongsTo;
+
+ /**
+ * Reference RFC 6020.
+ * <p>
+ * The "contact" statement provides contact information for the module. The
+ * argument is a string that is used to specify contact information for the
+ * person or persons to whom technical queries concerning this module should
+ * be sent, such as their name, postal address, telephone number, and
+ * electronic mail address.
+ */
+ private String contact;
+
+ /**
+ * Description.
+ */
+ private String description;
+
+ /**
+ * List of YANG modules imported.
+ */
+ private List<YangImport> importList;
+
+ /**
+ * List of YANG sub-modules included.
+ */
+ private List<YangInclude> includeList;
+
+ /**
+ * List of leaves at root level in the sub-module.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf-lists at root level in the sub-module.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ /**
+ * Organization owner of the sub-module.
+ */
+ private String organization;
+
+ /**
+ * Reference of the sub-module.
+ */
+ private String reference;
+
+ /**
+ * Revision info of the sub-module.
+ */
+ private YangRevision revision;
+
+ /**
+ * YANG version.
+ */
+ private byte version;
+
+ /**
+ * Prefix of parent module.
+ */
+ private String prefix;
+
+ /*-
+ * Reference RFC 6020.
+ *
+ * Nested typedefs and groupings.
+ * Typedefs and groupings may appear nested under many YANG statements,
+ * allowing these to be lexically scoped by the hierarchy under which
+ * they appear. This allows types and groupings to be defined near
+ * where they are used, rather than placing them at the top level of the
+ * hierarchy. The close proximity increases readability.
+ *
+ * Scoping also allows types to be defined without concern for naming
+ * conflicts between types in different submodules. Type names can be
+ * specified without adding leading strings designed to prevent name
+ * collisions within large modules.
+ *
+ * Finally, scoping allows the module author to keep types and groupings
+ * private to their module or submodule, preventing their reuse. Since
+ * only top-level types and groupings (i.e., those appearing as
+ * sub-statements to a module or submodule statement) can be used outside
+ * the module or submodule, the developer has more control over what
+ * pieces of their module are presented to the outside world, supporting
+ * the need to hide internal information and maintaining a boundary
+ * between what is shared with the outside world and what is kept
+ * private.
+ *
+ * Scoped definitions MUST NOT shadow definitions at a higher scope. A
+ * type or grouping cannot be defined if a higher level in the schema
+ * hierarchy has a definition with a matching identifier.
+ *
+ * A reference to an unprefixed type or grouping, or one which uses the
+ * prefix of the current module, is resolved by locating the closest
+ * matching "typedef" or "grouping" statement among the immediate
+ * sub-statements of each ancestor statement.
+ */
+ private List<YangResolutionInfo> derivedTypeResolutionList;
+
+ /**
+ * uses resolution list.
+ */
+ private List<YangResolutionInfo> usesResolutionList;
+
+ /**
+ * Creates a sub module node.
+ */
+ public YangSubModule() {
+ super(YangNodeType.SUB_MODULE_NODE);
+ derivedTypeResolutionList = new LinkedList<>();
+ usesResolutionList = new LinkedList<>();
+ importList = new LinkedList<YangImport>();
+ includeList = new LinkedList<YangInclude>();
+ listOfLeaf = new LinkedList<YangLeaf>();
+ listOfLeafList = new LinkedList<YangLeafList>();
+ }
+
+ /**
+ * Returns the YANG name of the sub module.
+ *
+ * @return YANG name of the sub module
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets YANG name of the sub module.
+ *
+ * @param subModuleName YANG name of the sub module
+ */
+ @Override
+ public void setName(String subModuleName) {
+ name = subModuleName;
+ }
+
+ /**
+ * Returns the module info.
+ *
+ * @return the belongs to info
+ */
+ public YangBelongsTo getBelongsTo() {
+ return belongsTo;
+ }
+
+ /**
+ * Sets the module info.
+ *
+ * @param belongsTo module info to set
+ */
+ public void setBelongsTo(YangBelongsTo belongsTo) {
+ this.belongsTo = belongsTo;
+ }
+
+ /**
+ * Returns the contact.
+ *
+ * @return the contact
+ */
+ public String getContact() {
+ return contact;
+ }
+
+ /**
+ * Sets the contact.
+ *
+ * @param contact the contact to set
+ */
+ public void setContact(String contact) {
+ this.contact = contact;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the list of imported modules.
+ *
+ * @return the list of imported modules
+ */
+ @Override
+ public List<YangImport> getImportList() {
+ return importList;
+ }
+
+ /**
+ * Adds the imported module information to the import list.
+ *
+ * @param importedModule module being imported
+ */
+ @Override
+ public void addToImportList(YangImport importedModule) {
+ getImportList().add(importedModule);
+ }
+
+ @Override
+ public void setImportList(List<YangImport> importList) {
+ this.importList = importList;
+ }
+
+ /**
+ * Returns the list of included sub modules.
+ *
+ * @return the included list of sub modules
+ */
+ @Override
+ public List<YangInclude> getIncludeList() {
+ return includeList;
+ }
+
+ /**
+ * Returns the included sub module information to the include list.
+ *
+ * @param includeModule submodule being included
+ */
+ @Override
+ public void addToIncludeList(YangInclude includeModule) {
+ getIncludeList().add(includeModule);
+ }
+
+ @Override
+ public void setIncludeList(List<YangInclude> includeList) {
+ this.includeList = includeList;
+ }
+
+ @Override
+ public String getPrefix() {
+ return prefix;
+ }
+
+ @Override
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ @Override
+ public void resolveSelfFileLinking(ResolvableType type)
+ throws DataModelException {
+ // Get the list to be resolved.
+ List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
+ // Resolve linking for a resolution list.
+ resolveLinkingForResolutionList(resolutionList, this);
+ }
+
+ @Override
+ public void resolveInterFileLinking(ResolvableType type)
+ throws DataModelException {
+ // Get the list to be resolved.
+ List<YangResolutionInfo> resolutionList = getUnresolvedResolutionList(type);
+ // Resolve linking for a resolution list.
+ linkInterFileReferences(resolutionList, this);
+ }
+
+ /**
+ * Returns the list of leaves.
+ *
+ * @return the list of leaves
+ */
+ @Override
+ public List<YangLeaf> getListOfLeaf() {
+ return listOfLeaf;
+ }
+
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ /**
+ * Adds a leaf.
+ *
+ * @param leaf the leaf to be added
+ */
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+ getListOfLeaf().add(leaf);
+ }
+
+ /**
+ * Returns the list of leaf-list.
+ *
+ * @return the list of leaf-list
+ */
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return listOfLeafList;
+ }
+
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ /**
+ * Adds a leaf-list.
+ *
+ * @param leafList the leaf-list to be added
+ */
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+ getListOfLeafList().add(leafList);
+ }
+
+ /**
+ * Returns the sub-modules organization.
+ *
+ * @return the organization
+ */
+ public String getOrganization() {
+ return organization;
+ }
+
+ /**
+ * Sets the sub-modules organization.
+ *
+ * @param org the organization to set
+ */
+ public void setOrganization(String org) {
+ organization = org;
+ }
+
+ /**
+ * 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 revision.
+ *
+ * @return the revision
+ */
+ public YangRevision getRevision() {
+ return revision;
+ }
+
+ /**
+ * Sets the revision.
+ *
+ * @param revision the revision to set
+ */
+ public void setRevision(YangRevision revision) {
+ this.revision = revision;
+ }
+
+ /**
+ * Returns the version.
+ *
+ * @return the version
+ */
+ public byte getVersion() {
+ return version;
+ }
+
+ /**
+ * Sets the version.
+ *
+ * @param version the version to set
+ */
+ public void setVersion(byte version) {
+ this.version = version;
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns SUB_MODULE_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.SUB_MODULE_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Asks helper to detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Not required as module doesn't have any parent.
+ }
+
+ @Override
+ public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
+ if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
+ return derivedTypeResolutionList;
+ } else {
+ return usesResolutionList;
+ }
+ }
+
+ @Override
+ public void addToResolutionList(YangResolutionInfo resolutionInfo,
+ ResolvableType type) {
+ if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
+ derivedTypeResolutionList.add(resolutionInfo);
+ } else if (type == ResolvableType.YANG_USES) {
+ usesResolutionList.add(resolutionInfo);
+ }
+ }
+
+ @Override
+ public void setResolutionList(List<YangResolutionInfo> resolutionList,
+ ResolvableType type) {
+ if (type == ResolvableType.YANG_DERIVED_DATA_TYPE) {
+ derivedTypeResolutionList = resolutionList;
+ } else if (type == ResolvableType.YANG_USES) {
+ usesResolutionList = resolutionList;
+ }
+
+ }
+
+ /**
+ * Links the sub-module with module.
+ *
+ * @param yangNodeSet YANG file information set
+ * @throws DataModelException a violation in data model rule
+ */
+ public void linkWithModule(Set<YangNode> yangNodeSet)
+ throws DataModelException {
+ getBelongsTo().linkWithModule(yangNodeSet);
+ }
+
+ @Override
+ public void addReferencesToIncludeList(Set<YangNode> yangNodeSet)
+ throws DataModelException {
+ Iterator<YangInclude> includeInfoIterator = getIncludeList().iterator();
+ // Run through the included list to add references.
+ while (includeInfoIterator.hasNext()) {
+ YangInclude yangInclude = includeInfoIterator.next();
+ YangSubModule subModule = null;
+ subModule = yangInclude.addReferenceToInclude(yangNodeSet);
+ // Check if the referred sub-modules parent is self
+ if (!(subModule.getBelongsTo().getModuleNode() == getBelongsTo().getModuleNode())) {
+ yangInclude.reportIncludeError();
+ }
+ }
+ }
+
+ @Override
+ public void addReferencesToImportList(Set<YangNode> yangNodeSet)
+ throws DataModelException {
+ Iterator<YangImport> importInfoIterator = getImportList().iterator();
+ // Run through the imported list to add references.
+ while (importInfoIterator.hasNext()) {
+ YangImport yangImport = importInfoIterator.next();
+ yangImport.addReferenceToImport(yangNodeSet);
+ }
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangType.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
new file mode 100644
index 0000000..a19167a
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
@@ -0,0 +1,274 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
+
+/*
+ * Reference:RFC 6020.
+ * The "type" statement takes as an argument a string that is the name
+ * of a YANG built-in type or a derived type, followed by an optional
+ * block of sub-statements that are used to put further restrictions
+ * on the type.
+ *
+ * The restrictions that can be applied depend on the type being restricted.
+ * The type's sub-statements
+ *
+ * +------------------+---------+-------------+------------------------------------+
+ * | substatement | section | cardinality | mapped data type |
+ * +------------------+---------+-------------+------------------------------------+
+ * | bit | 9.7.4 | 0..n | - YangBit used in YangBits |
+ * | enum | 9.6.4 | 0..n | - YangEnum used in YangEnumeration |
+ * | length | 9.4.4 | 0..1 | - used for string |
+ * | path | 9.9.2 | 0..1 | - TODO leaf-ref |
+ * | pattern | 9.4.6 | 0..n | - used for string |
+ * | range | 9.2.4 | 0..1 | - used for integer data type |
+ * | require-instance | 9.13.2 | 0..1 | - TODO instance-identifier |
+ * | type | 7.4 | 0..n | - TODO union |
+ * +------------------+---------+-------------+------------------------------------+
+ */
+
+/**
+ * Represents the data type information.
+ *
+ * @param <T> YANG data type info
+ */
+public class YangType<T>
+ implements Parsable, Resolvable, Serializable {
+
+ private static final long serialVersionUID = 8062016054L;
+
+ /**
+ * YANG node identifier.
+ */
+ private YangNodeIdentifier nodeIdentifier;
+
+ /**
+ * Java package in which the Java type is defined.
+ */
+ private String javaPackage;
+
+ /**
+ * YANG data type.
+ */
+ private YangDataTypes dataType;
+
+ /**
+ * Additional information about data type, example restriction info, named
+ * values, etc. The extra information is based on the data type. Based on
+ * the data type, the extended info can vary.
+ */
+ private T dataTypeExtendedInfo;
+
+ /**
+ * Status of resolution. If completely resolved enum value is "RESOLVED",
+ * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
+ * is added to uses/type but it's not resolved value of enum should be
+ * "INTRA_FILE_RESOLVED".
+ */
+ private ResolvableStatus resolvableStatus;
+
+ /**
+ * Creates a YANG type object.
+ */
+ public YangType() {
+
+ nodeIdentifier = new YangNodeIdentifier();
+ resolvableStatus = ResolvableStatus.UNRESOLVED;
+ }
+
+ /**
+ * Returns prefix associated with data type name.
+ *
+ * @return prefix associated with data type name
+ */
+ public String getPrefix() {
+ return nodeIdentifier.getPrefix();
+ }
+
+ /**
+ * Sets prefix associated with data type name.
+ *
+ * @param prefix prefix associated with data type name
+ */
+ public void setPrefix(String prefix) {
+ nodeIdentifier.setPrefix(prefix);
+ }
+
+ /**
+ * Returns the name of data type.
+ *
+ * @return the name of data type
+ */
+ public String getDataTypeName() {
+ return nodeIdentifier.getName();
+ }
+
+ /**
+ * Sets the name of the data type.
+ *
+ * @param typeName the name to set
+ */
+ public void setDataTypeName(String typeName) {
+ nodeIdentifier.setName(typeName);
+ }
+
+ /**
+ * Returns the Java package where the type is defined.
+ *
+ * @return Java package where the type is defined
+ */
+ public String getJavaPackage() {
+ return javaPackage;
+ }
+
+ /**
+ * Sets Java package where the type is defined.
+ *
+ * @param javaPackage Java package where the type is defined
+ */
+ public void setJavaPackage(String javaPackage) {
+ this.javaPackage = javaPackage;
+ }
+
+ /**
+ * Returns the type of data.
+ *
+ * @return the data type
+ */
+ public YangDataTypes getDataType() {
+ return dataType;
+ }
+
+ /**
+ * Sets the type of data.
+ *
+ * @param dataType data type
+ */
+ public void setDataType(YangDataTypes dataType) {
+ this.dataType = dataType;
+ }
+
+ /**
+ * Returns the data type meta data.
+ *
+ * @return the data type meta data
+ */
+ public T getDataTypeExtendedInfo() {
+ return dataTypeExtendedInfo;
+ }
+
+ /**
+ * Sets the data type meta data.
+ *
+ * @param dataTypeInfo the meta data to set
+ */
+ public void setDataTypeExtendedInfo(T dataTypeInfo) {
+ this.dataTypeExtendedInfo = dataTypeInfo;
+ }
+
+ /**
+ * Returns node identifier.
+ *
+ * @return node identifier
+ */
+ public YangNodeIdentifier getNodeIdentifier() {
+ return nodeIdentifier;
+ }
+
+ /**
+ * Sets node identifier.
+ *
+ * @param nodeIdentifier the node identifier
+ */
+ public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
+ this.nodeIdentifier = nodeIdentifier;
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns TYPE_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.TYPE_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ @Override
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ @Override
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+ }
+
+ @Override
+ public void resolve()
+ throws DataModelException {
+ /*
+ * Check whether the data type is derived.
+ */
+ if (getDataType() != DERIVED) {
+ throw new DataModelException("Linker Error: Resolve should only be called for derived data types.");
+ }
+
+ // Check if the derived info is present.
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo();
+ if (derivedInfo == null) {
+ throw new DataModelException("Linker Error: Derived information is missing.");
+ }
+
+ // Initiate the resolution
+ try {
+ setResolvableStatus(derivedInfo.resolve());
+ } catch (DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
new file mode 100644
index 0000000..d0f69af
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
@@ -0,0 +1,294 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The "typedef" statement defines a new type that may be used locally in the
+ * module, in modules or submodules which include it, and by other modules that
+ * import from it. The new type is called the "derived type", and the type from
+ * which it was derived is called the "base type". All derived types can be
+ * traced back to a YANG built-in type.
+ *
+ * The "typedef" statement's argument is an identifier that is the name of the
+ * type to be defined, and MUST be followed by a block of sub-statements that
+ * holds detailed typedef information.
+ *
+ * The name of the type MUST NOT be one of the YANG built-in types. If the
+ * typedef is defined at the top level of a YANG module or submodule, the name
+ * of the type to be defined MUST be unique within the module.
+ * The typedef's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | default | 7.3.4 | 0..1 |-string |
+ * | description | 7.19.3 | 0..1 |-string |
+ * | reference | 7.19.4 | 0..1 |-string |
+ * | status | 7.19.2 | 0..1 |-YangStatus |
+ * | type | 7.3.2 | 1 |-yangType |
+ * | units | 7.3.3 | 0..1 |-string |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG typedef.
+ */
+public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder, CollisionDetector {
+
+ private static final long serialVersionUID = 806201615L;
+
+ /**
+ * Default value in string, needs to be converted to the target object,
+ * based on the type.
+ */
+ private String defaultValueInString;
+
+ /**
+ * Description of new type.
+ */
+ private String description;
+
+ /**
+ * reference string.
+ */
+ private String reference;
+
+ /**
+ * Status of the data type.
+ */
+ private YangStatusType status;
+
+ /**
+ * Name of the typedef.
+ */
+ private String name;
+
+ /**
+ * Units of the data type.
+ */
+ private String units;
+
+ /**
+ * List of YANG type, for typedef it will have single type.
+ * This is done to unify the code with union.
+ */
+ private List<YangType<?>> typeList;
+
+ /**
+ * Creates a typedef node.
+ */
+ public YangTypeDef() {
+ super(YangNodeType.TYPEDEF_NODE);
+ typeList = new LinkedList<>();
+ }
+
+ /**
+ * Returns the default value.
+ *
+ * @return the default value
+ */
+ public String getDefaultValueInString() {
+ return defaultValueInString;
+ }
+
+ /**
+ * Sets the default value.
+ *
+ * @param defaultValueInString the default value
+ */
+ public void setDefaultValueInString(String defaultValueInString) {
+ this.defaultValueInString = defaultValueInString;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the textual reference.
+ *
+ * @return the reference
+ */
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ /**
+ * Sets the textual reference.
+ *
+ * @param reference the reference to set
+ */
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ /**
+ * Returns the status.
+ *
+ * @return the status
+ */
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ /**
+ * Returns the data type.
+ *
+ * @return the data type
+ */
+ public YangType<?> getTypeDefBaseType() {
+ if (!getTypeList().isEmpty()) {
+ return getTypeList().get(0);
+ }
+ return null;
+ }
+
+ /**
+ * Sets the data type.
+ *
+ * @param dataType the data type
+ */
+ public void setDataType(YangType<?> dataType) {
+ getTypeList().add(0, dataType);
+ }
+
+ /**
+ * Returns the unit.
+ *
+ * @return the units
+ */
+ public String getUnits() {
+ return units;
+ }
+
+ /**
+ * Sets the unit.
+ *
+ * @param units the units to set
+ */
+ public void setUnits(String units) {
+ this.units = units;
+ }
+
+ /**
+ * Returns the type of the data.
+ *
+ * @return returns TYPEDEF_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.TYPEDEF_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Returns the YANG name of the typedef.
+ *
+ * @return YANG name of the typedef
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets YANG name of the typedef.
+ *
+ * @param name YANG name of the typedef
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public List<YangType<?>> getTypeList() {
+ return typeList;
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
+ // Asks helper to detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Duplicate input identifier detected, same as typedef \""
+ + getName() + "\"");
+ }
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangTypeHolder.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangTypeHolder.java
new file mode 100644
index 0000000..284f86a
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangTypeHolder.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.List;
+
+/**
+ * Represents the holder with type(s).
+ */
+public interface YangTypeHolder {
+
+ /**
+ * Returns type list.
+ *
+ * @return type list
+ */
+ List<YangType<?>> getTypeList();
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
new file mode 100644
index 0000000..d4c0306
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The union built-in type represents a value that corresponds to one of
+ * its member types.
+ *
+ * When the type is "union", the "type" statement (Section 7.4) MUST be
+ * present. It is used to repeatedly specify each member type of the
+ * union. It takes as an argument a string that is the name of a member
+ * type.
+ *
+ * A member type can be of any built-in or derived type, except it MUST
+ * NOT be one of the built-in types "empty" or "leafref".
+ *
+ * When a string representing a union data type is validated, the string
+ * is validated against each member type, in the order they are
+ * specified in the "type" statement, until a match is found.
+ *
+ * Any default value or "units" property defined in the member types is
+ * not inherited by the union type.
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG union.
+ */
+public class YangUnion extends YangNode implements Parsable, YangTypeHolder {
+
+ private static final long serialVersionUID = 806201616L;
+
+ // List of YANG type.
+ private List<YangType<?>> typeList;
+
+ // Name of union.
+ private String name;
+
+ // Current child union number.
+ private transient int childUnionNumber;
+
+ /**
+ * Creates a YANG union node.
+ */
+ public YangUnion() {
+ super(YangNodeType.UNION_NODE);
+ typeList = new LinkedList<>();
+ childUnionNumber = 1;
+ }
+
+ @Override
+ public List<YangType<?>> getTypeList() {
+ return typeList;
+ }
+
+ /**
+ * Sets the list of YANG type.
+ *
+ * @param typeList list of YANG type.
+ */
+ public void setTypeList(List<YangType<?>> typeList) {
+ this.typeList = typeList;
+ }
+
+ /**
+ * Returns running child union number.
+ *
+ * @return running child union number
+ */
+ public int getChildUnionNumber() {
+ return childUnionNumber;
+ }
+
+ /**
+ * Sets the running child union number.
+ *
+ * @param childUnionNumber running child union number
+ */
+ public void setChildUnionNumber(int childUnionNumber) {
+ this.childUnionNumber = childUnionNumber;
+ }
+
+ /**
+ * Adds YANG type to type list.
+ *
+ * @param yangType YANG type to be added to list
+ * @throws DataModelException union member type must not be one of the
+ * built-in types "empty" or "leafref"
+ */
+ public void addType(YangType<?> yangType) throws DataModelException {
+ if (yangType.getDataType() == YangDataTypes.EMPTY || yangType.getDataType() == YangDataTypes.LEAFREF) {
+ throw new DataModelException("Union member type must not be one of the built-in types \"empty\" or " +
+ "\"leafref\"");
+ }
+ getTypeList().add(yangType);
+ }
+
+ /**
+ * Returns union name.
+ *
+ * @return the union name
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the union name.
+ *
+ * @param name union name
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.UNION_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ //TODO: implement the method.
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ //TODO: implement the method.
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
new file mode 100644
index 0000000..b0d9ed9
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
@@ -0,0 +1,506 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The "uses" statement is used to reference a "grouping" definition. It takes
+ * one argument, which is the name of the grouping.
+ *
+ * The effect of a "uses" reference to a grouping is that the nodes defined by
+ * the grouping are copied into the current schema tree, and then updated
+ * according to the "refine" and "augment" statements.
+ *
+ * The identifiers defined in the grouping are not bound to a namespace until
+ * the contents of the grouping are added to the schema tree via a "uses"
+ * statement that does not appear inside a "grouping" statement, at which point
+ * they are bound to the namespace of the current module.
+ *
+ * The uses's sub-statements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | augment | 7.15 | 0..1 | -child nodes |
+ * | description | 7.19.3 | 0..1 | -string |
+ * | if-feature | 7.18.2 | 0..n | -TODO |
+ * | refine | 7.12.2 | 0..1 | -TODO |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * | when | 7.19.5 | 0..1 | -TODO |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG uses.
+ */
+public class YangUses
+ extends YangNode
+ implements YangCommonInfo, Parsable, Resolvable, CollisionDetector {
+
+ private static final long serialVersionUID = 806201617L;
+
+ /**
+ * YANG node identifier.
+ */
+ private YangNodeIdentifier nodeIdentifier;
+
+ /**
+ * Referred group.
+ */
+ private YangGrouping refGroup;
+
+ /**
+ * Description of YANG uses.
+ */
+ private String description;
+
+ /**
+ * YANG reference.
+ */
+ private String reference;
+
+ /**
+ * Status of YANG uses.
+ */
+ private YangStatusType status;
+
+ /**
+ * Status of resolution. If completely resolved enum value is "RESOLVED",
+ * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
+ * is added to uses/type but it's not resolved value of enum should be
+ * "INTRA_FILE_RESOLVED".
+ */
+ private ResolvableStatus resolvableStatus;
+
+ /**
+ * Effective list of nodes of grouping that needs to replicated at YANG uses.
+ */
+ private List<YangNode> resolvedGroupingNodes;
+
+ /**
+ * Effective list of leaves of grouping that needs to replicated at YANG uses.
+ */
+ private List<List<YangLeaf>> resolvedGroupingLeaves;
+
+ /**
+ * Effective list of leaf lists of grouping that needs to replicated at YANG uses.
+ */
+ private List<List<YangLeafList>> resolvedGroupingLeafLists;
+
+ /**
+ * Creates an YANG uses node.
+ */
+ public YangUses() {
+ super(YangNodeType.USES_NODE);
+ nodeIdentifier = new YangNodeIdentifier();
+ resolvableStatus = ResolvableStatus.UNRESOLVED;
+ resolvedGroupingNodes = new LinkedList<YangNode>();
+ resolvedGroupingLeaves = new LinkedList<List<YangLeaf>>();
+ resolvedGroupingLeafLists = new LinkedList<List<YangLeafList>>();
+ }
+
+ /**
+ * Returns the referred group.
+ *
+ * @return the referred group
+ */
+ public YangGrouping getRefGroup() {
+ return refGroup;
+ }
+
+ /**
+ * Sets the referred group.
+ *
+ * @param refGroup the referred group
+ */
+ public void setRefGroup(YangGrouping refGroup) {
+ this.refGroup = refGroup;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the textual reference.
+ *
+ * @return the reference
+ */
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ /**
+ * Sets the textual reference.
+ *
+ * @param reference the reference to set
+ */
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ /**
+ * Returns the status.
+ *
+ * @return the status
+ */
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status the status to set
+ */
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ /**
+ * Returns the type of the data.
+ *
+ * @return returns USES_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.USES_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ @Override
+ public String getName() {
+ return nodeIdentifier.getName();
+ }
+
+ @Override
+ public void setName(String name) {
+ nodeIdentifier.setName(name);
+ }
+
+ /**
+ * Returns node identifier.
+ *
+ * @return node identifier
+ */
+ public YangNodeIdentifier getNodeIdentifier() {
+ return nodeIdentifier;
+ }
+
+ /**
+ * Sets node identifier.
+ *
+ * @param nodeIdentifier the node identifier
+ */
+ public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
+ this.nodeIdentifier = nodeIdentifier;
+ }
+
+ /**
+ * Returns prefix associated with uses.
+ *
+ * @return prefix associated with uses
+ */
+ public String getPrefix() {
+ return nodeIdentifier.getPrefix();
+ }
+
+ /**
+ * Get prefix associated with uses.
+ *
+ * @param prefix prefix associated with uses
+ */
+ public void setPrefix(String prefix) {
+ nodeIdentifier.setPrefix(prefix);
+ }
+
+ @Override
+ public void resolve()
+ throws DataModelException {
+
+ YangGrouping referredGrouping = getRefGroup();
+
+ if (referredGrouping == null) {
+ throw new DataModelException("YANG uses linker error, cannot resolve uses");
+ }
+
+ YangNode usesParentNode = getParentNodeInGenCode(this);
+ if (!(usesParentNode instanceof YangLeavesHolder)
+ || !(usesParentNode instanceof CollisionDetector)) {
+ throw new DataModelException("YANG uses holder construct is wrong");
+ }
+
+ YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode;
+ if (referredGrouping.getListOfLeaf() != null
+ && referredGrouping.getListOfLeaf().size() != 0) {
+ addLeavesOfGrouping(
+ cloneLeavesList(referredGrouping.getListOfLeaf(),
+ usesParentLeavesHolder));
+ }
+
+ if (referredGrouping.getListOfLeafList() != null
+ && referredGrouping.getListOfLeafList().size() != 0) {
+ addListOfLeafListOfGrouping(
+ cloneListOfLeafList(referredGrouping.getListOfLeafList(),
+ usesParentLeavesHolder));
+ }
+
+ YangNode childInGrouping = referredGrouping.getChild();
+
+ while (childInGrouping != null) {
+ if (childInGrouping instanceof YangEnumeration
+ || childInGrouping instanceof YangUnion
+ || childInGrouping instanceof YangTypeDef) {
+
+ /*
+ * No need to copy the leaves, union / enum class, as these will
+ * be generated in the scope of grouping
+ */
+ childInGrouping = childInGrouping.getNextSibling();
+ continue;
+ } else if (childInGrouping instanceof YangUses) {
+ addResolvedUsesInfoOfGrouping((YangUses) childInGrouping,
+ usesParentLeavesHolder);
+ } else {
+ addNodeOfGrouping(childInGrouping);
+ }
+
+ childInGrouping = childInGrouping.getNextSibling();
+ }
+ }
+
+ /**
+ * Clone the resolved uses contained in grouping to the uses of grouping.
+ *
+ * @param usesInGrouping resolved uses in grouping
+ * @param usesHolder holder of uses
+ */
+ private void addResolvedUsesInfoOfGrouping(YangUses usesInGrouping,
+ YangLeavesHolder usesHolder) throws DataModelException {
+ for (YangNode usesResolvedNode : usesInGrouping.getUsesResolvedNodeList()) {
+ addNodeOfGrouping(usesResolvedNode);
+ }
+
+ for (List<YangLeaf> leavesList : usesInGrouping.getUsesResolvedLeavesList()) {
+ addLeavesOfGrouping(cloneLeavesList(leavesList, usesHolder));
+ }
+
+ for (List<YangLeafList> listOfLeafLists : usesInGrouping.getUsesResolvedListOfLeafList()) {
+ addListOfLeafListOfGrouping(
+ cloneListOfLeafList(listOfLeafLists, usesHolder));
+ }
+ }
+
+ /**
+ * Clone the list of leaves and return the cloned list leaves.
+ *
+ * @param listOfLeaves list of leaves to be cloned
+ * @param usesParentNode parent of the cloned location
+ * @return cloned list of leaves
+ * @throws DataModelException a violation in data model rule
+ */
+ private List<YangLeaf> cloneLeavesList(List<YangLeaf> listOfLeaves,
+ YangLeavesHolder usesParentNode) throws DataModelException {
+ if (listOfLeaves == null || listOfLeaves.size() == 0) {
+ throw new DataModelException("No leaves to clone");
+ }
+
+ List<YangLeaf> newLeavesList = new LinkedList<YangLeaf>();
+ for (YangLeaf leaf : listOfLeaves) {
+ YangLeaf clonedLeaf;
+ try {
+ ((CollisionDetector) usesParentNode).detectCollidingChild(leaf.getName(),
+ YangConstructType.LEAF_DATA);
+ clonedLeaf = leaf.clone();
+ } catch (CloneNotSupportedException | DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
+
+ clonedLeaf.setContainedIn(usesParentNode);
+ newLeavesList.add(clonedLeaf);
+ }
+
+ return newLeavesList;
+ }
+
+ /**
+ * Clone the list of leaf list.
+ *
+ * @param listOfLeafList list of leaf list that needs to be cloned
+ * @param usesParentNode parent of uses
+ * @return cloned list of leaf list
+ */
+ private List<YangLeafList> cloneListOfLeafList(List<YangLeafList> listOfLeafList,
+ YangLeavesHolder usesParentNode) throws DataModelException {
+ if (listOfLeafList == null || listOfLeafList.size() == 0) {
+ throw new DataModelException("No leaf lists to clone");
+ }
+
+ List<YangLeafList> newListOfLeafList = new LinkedList<YangLeafList>();
+ for (YangLeafList leafList : listOfLeafList) {
+ YangLeafList clonedLeafList;
+ try {
+ ((CollisionDetector) usesParentNode).detectCollidingChild(leafList.getName(),
+ YangConstructType.LEAF_LIST_DATA);
+ clonedLeafList = leafList.clone();
+ } catch (CloneNotSupportedException | DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
+
+ clonedLeafList.setContainedIn(usesParentNode);
+ newListOfLeafList.add(clonedLeafList);
+ }
+
+ return newListOfLeafList;
+ }
+
+ @Override
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ @Override
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+ }
+
+ @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 uses \""
+ + getName() + "\"");
+ }
+ }
+
+ /**
+ * Adds the node under grouping to the effective uses resolved info.
+ *
+ * @param nodeInGrouping node defined under grouping which needs to be copied in
+ * the context of uses
+ */
+ public void addNodeOfGrouping(YangNode nodeInGrouping) {
+ resolvedGroupingNodes.add(nodeInGrouping);
+ }
+
+ /**
+ * Returns the effective list of nodes added due to uses linking.
+ *
+ * @return effective list of nodes added due to uses linking
+ */
+ public List<YangNode> getUsesResolvedNodeList() {
+ return resolvedGroupingNodes;
+ }
+
+ /**
+ * Adds the leaves under grouping to the effective uses resolved info.
+ *
+ * @param leavesInGrouping Leaves defined under grouping which needs to be copied in
+ * the context of uses
+ */
+ public void addLeavesOfGrouping(List<YangLeaf> leavesInGrouping) {
+ resolvedGroupingLeaves.add(leavesInGrouping);
+ }
+
+ /**
+ * Returns the effective list of Leaves added due to uses linking.
+ *
+ * @return effective list of Leaves added due to uses linking
+ */
+ public List<List<YangLeaf>> getUsesResolvedLeavesList() {
+ return resolvedGroupingLeaves;
+ }
+
+ /**
+ * Adds the leaf-lists under grouping to the effective uses resolved info.
+ *
+ * @param leafListsInGrouping leaf-lists defined under grouping which needs to be copied in
+ * the context of uses
+ */
+ public void addListOfLeafListOfGrouping(List<YangLeafList> leafListsInGrouping) {
+ resolvedGroupingLeafLists.add(leafListsInGrouping);
+ }
+
+ /**
+ * Returns the effective list of Leaves added due to uses linking.
+ *
+ * @return effective list of Leaves added due to uses linking
+ */
+ public List<List<YangLeafList>> getUsesResolvedListOfLeafList() {
+ return resolvedGroupingLeafLists;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/exceptions/DataModelException.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/exceptions/DataModelException.java
new file mode 100644
index 0000000..b1375a7
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/exceptions/DataModelException.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel.exceptions;
+
+/**
+ * Represents base class for exceptions in data model operations.
+ */
+public class DataModelException extends Exception {
+
+ private static final long serialVersionUID = 201601270658L;
+ private int lineNumber;
+ private int charPositionInLine;
+
+ /**
+ * Creates a data model exception with message.
+ *
+ * @param message the detail of exception in string
+ */
+ public DataModelException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates exception from message and cause.
+ *
+ * @param message the detail of exception in string
+ * @param cause underlying cause of the error
+ */
+ public DataModelException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates exception from cause.
+ *
+ * @param cause underlying cause of the error
+ */
+ public DataModelException(final Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Returns line number of the exception.
+ *
+ * @return line number of the exception
+ */
+ public int getLineNumber() {
+ return this.lineNumber;
+ }
+
+ /**
+ * Returns position of the exception.
+ *
+ * @return position of the exception
+ */
+ public int getCharPositionInLine() {
+ return this.charPositionInLine;
+ }
+
+ /**
+ * Sets line number of YANG file.
+ *
+ * @param line line number of YANG file
+ */
+ public void setLine(int line) {
+ this.lineNumber = line;
+ }
+
+ /**
+ * Sets position of exception.
+ *
+ * @param charPosition position of exception
+ */
+ public void setCharPosition(int charPosition) {
+ this.charPositionInLine = charPosition;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/exceptions/package-info.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/exceptions/package-info.java
new file mode 100644
index 0000000..ec607f3
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/exceptions/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+/**
+ * Custom data model exceptions.
+ */
+package org.onosproject.yangutils.datamodel.exceptions;
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/package-info.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/package-info.java
new file mode 100644
index 0000000..d8e8901
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Maintains application's schema information.
+ */
+package org.onosproject.yangutils.datamodel;
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
new file mode 100644
index 0000000..f7ac5f2
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -0,0 +1,258 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils;
+
+import java.util.List;
+import java.util.Set;
+
+import org.onosproject.yangutils.datamodel.CollisionDetector;
+import org.onosproject.yangutils.datamodel.ResolvableType;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangLeafList;
+import org.onosproject.yangutils.datamodel.YangLeavesHolder;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangReferenceResolver;
+import org.onosproject.yangutils.datamodel.YangResolutionInfo;
+import org.onosproject.yangutils.datamodel.YangRpc;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+
+/**
+ * Represents utilities for data model tree.
+ */
+public final class DataModelUtils {
+
+ /**
+ * Creates a new data model tree utility.
+ */
+ private DataModelUtils() {
+ }
+
+ /**
+ * Detects the colliding identifier name in a given YANG node and its child.
+ *
+ * @param identifierName name for which collision detection is to be checked
+ * @param dataType type of YANG node asking for detecting collision
+ * @param node instance of calling node
+ * @throws DataModelException a violation of data model rules
+ */
+ public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node)
+ throws DataModelException {
+ if (dataType == YangConstructType.USES_DATA || dataType == YangConstructType.GROUPING_DATA) {
+ detectCollidingForUsesGrouping(identifierName, dataType, node);
+ } else {
+ if (node instanceof YangLeavesHolder) {
+ YangLeavesHolder leavesHolder = (YangLeavesHolder) node;
+ detectCollidingLeaf(leavesHolder.getListOfLeaf(), identifierName);
+ detectCollidingLeafList(leavesHolder.getListOfLeafList(), identifierName);
+ }
+ node = node.getChild();
+ while (node != null) {
+ Parsable parsable = (Parsable) node;
+ if (node instanceof CollisionDetector
+ && parsable.getYangConstructType() != YangConstructType.USES_DATA
+ && parsable.getYangConstructType() != YangConstructType.GROUPING_DATA) {
+ ((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
+ }
+ node = node.getNextSibling();
+ }
+ }
+ }
+
+ /**
+ * Detects colliding of uses and grouping only with uses and grouping respectively.
+ *
+ * @param identifierName name for which collision detection is to be checked
+ * @param dataType type of YANG node asking for detecting collision
+ * @param node node instance of calling node
+ * @throws DataModelException a violation of data model rules
+ */
+ public static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node)
+ throws DataModelException {
+
+ node = node.getChild();
+ while (node != null) {
+ Parsable parsable = (Parsable) node;
+ if (node instanceof CollisionDetector
+ && parsable.getYangConstructType() == dataType) {
+ ((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
+ }
+ node = node.getNextSibling();
+ }
+ }
+
+ /**
+ * Detects the colliding identifier name in a given leaf node.
+ *
+ * @param listOfLeaf List of leaves to detect collision
+ * @param identifierName name for which collision detection is to be checked
+ * @throws DataModelException a violation of data model rules
+ */
+ private static void detectCollidingLeaf(List<YangLeaf> listOfLeaf, String identifierName)
+ throws DataModelException {
+
+ if (listOfLeaf == null) {
+ return;
+ }
+ for (YangLeaf leaf : listOfLeaf) {
+ if (leaf.getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \""
+ + leaf.getName() + "\"");
+ }
+ }
+ }
+
+ /**
+ * Detects the colliding identifier name in a given leaf-list node.
+ *
+ * @param listOfLeafList list of leaf-lists to detect collision
+ * @param identifierName name for which collision detection is to be checked
+ * @throws DataModelException a violation of data model rules
+ */
+ private static void detectCollidingLeafList(List<YangLeafList> listOfLeafList, String identifierName)
+ throws DataModelException {
+
+ if (listOfLeafList == null) {
+ return;
+ }
+ for (YangLeafList leafList : listOfLeafList) {
+ if (leafList.getName().equals(identifierName)) {
+ throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " +
+ "list \"" + leafList.getName() + "\"");
+ }
+ }
+ }
+
+ /**
+ * Add a resolution information.
+ *
+ * @param resolutionInfo information about the YANG construct which has to be resolved
+ * @throws DataModelException a violation of data model rules
+ */
+ public static void addResolutionInfo(YangResolutionInfo resolutionInfo)
+ throws DataModelException {
+
+ /* get the module node to add maintain the list of nested reference */
+ YangNode curNode = resolutionInfo.getEntityToResolveInfo()
+ .getHolderOfEntityToResolve();
+ while (!(curNode instanceof YangReferenceResolver)) {
+ curNode = curNode.getParent();
+ if (curNode == null) {
+ throw new DataModelException("Internal datamodel error: Datamodel tree is not correct");
+ }
+ }
+ YangReferenceResolver resolutionNode = (YangReferenceResolver) curNode;
+
+ if (resolutionInfo.getEntityToResolveInfo()
+ .getEntityToResolve() instanceof YangType) {
+ resolutionNode.addToResolutionList(resolutionInfo,
+ ResolvableType.YANG_DERIVED_DATA_TYPE);
+ } else {
+ resolutionNode.addToResolutionList(resolutionInfo,
+ ResolvableType.YANG_USES);
+ }
+
+ }
+
+ /**
+ * Resolve linking for a resolution list.
+ *
+ * @param resolutionList resolution list for which linking to be done
+ * @param dataModelRootNode module/sub-module node
+ * @throws DataModelException a violation of data model rules
+ */
+ public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList,
+ YangReferenceResolver dataModelRootNode)
+ throws DataModelException {
+
+ for (YangResolutionInfo resolutionInfo : resolutionList) {
+ resolutionInfo.resolveLinkingForResolutionInfo(dataModelRootNode);
+ }
+ }
+
+ /**
+ * Links type/uses referring to typedef/uses of inter YANG file.
+ *
+ * @param resolutionList resolution list for which linking to be done
+ * @param dataModelRootNode module/sub-module node
+ * @throws DataModelException a violation of data model rules
+ */
+ public static void linkInterFileReferences(List<YangResolutionInfo> resolutionList,
+ YangReferenceResolver dataModelRootNode)
+ throws DataModelException {
+ /*
+ * Run through the resolution list, find type/uses referring to inter
+ * file typedef/grouping, ask for linking.
+ */
+ for (YangResolutionInfo resolutionInfo : resolutionList) {
+ resolutionInfo.linkInterFile(dataModelRootNode);
+ }
+ }
+
+ /**
+ * Checks if there is any rpc defined in the module or sub-module.
+ *
+ * @param rootNode root node of the data model
+ * @return status of rpc's existence
+ */
+ public static boolean isRpcChildNodePresent(YangNode rootNode) {
+ YangNode childNode = rootNode.getChild();
+ while (childNode != null) {
+ if (childNode instanceof YangRpc) {
+ return true;
+ }
+ childNode = childNode.getNextSibling();
+ }
+ return false;
+ }
+
+ /**
+ * Returns referred node in a given set.
+ *
+ * @param yangNodeSet YANG node set
+ * @param refNodeName name of the node which is referred
+ * @return referred node's reference
+ */
+ public static YangNode findReferredNode(Set<YangNode> yangNodeSet, String refNodeName) {
+ /*
+ * Run through the YANG files to see which YANG file matches the
+ * referred node name.
+ */
+ for (YangNode yangNode : yangNodeSet) {
+ if (yangNode.getName().equals(refNodeName)) {
+ return yangNode;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the contained data model parent node.
+ *
+ * @param currentNode current node which parent contained node is required
+ * @return parent node in which the current node is an attribute
+ */
+ public static YangNode getParentNodeInGenCode(YangNode currentNode) {
+
+ /*
+ * TODO: recursive parent lookup to support choice/augment/uses. TODO:
+ * need to check if this needs to be updated for
+ * choice/case/augment/grouping
+ */
+ return currentNode.getParent();
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/GeneratedLanguage.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/GeneratedLanguage.java
new file mode 100644
index 0000000..37d2161
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/GeneratedLanguage.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel.utils;
+
+/**
+ * Represents the target language in which the YANG information is modeled.
+ */
+public enum GeneratedLanguage {
+ /**
+ * Target language is java.
+ */
+ JAVA_GENERATION
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/Parsable.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/Parsable.java
new file mode 100644
index 0000000..eb32bc8
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/Parsable.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.yangutils.datamodel.utils;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+
+/**
+ * Abstraction of an entity which process the data of lexer's parse tree.
+ */
+public interface Parsable {
+
+ /**
+ * Returns the type of YANG construct data.
+ *
+ * @return the type of YANG construct data.
+ */
+ YangConstructType getYangConstructType();
+
+ /**
+ * Checks if the node is valid as per YANG grammar's syntax and semantics.
+ * This validation will be performed on entering the node in traversal
+ *
+ * @throws DataModelException if there is any violation of the YANG rules
+ * in parsed data, corresponding exception should be thrown
+ */
+ void validateDataOnEntry() throws DataModelException;
+
+ /**
+ * Checks if the node is valid as per YANG grammar's syntax and semantics.
+ * This validation will be performed on exiting the node in traversal
+ *
+ * @throws DataModelException if there is any violation of the YANG rules
+ * in parsed data, corresponding exception should be thrown
+ */
+ void validateDataOnExit() throws DataModelException;
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/ResolvableStatus.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/ResolvableStatus.java
new file mode 100644
index 0000000..d476c8b
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/ResolvableStatus.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils;
+
+/**
+ * Represents the status of resolvable entity.
+ */
+public enum ResolvableStatus {
+
+ /**
+ * Identifies that resolvable entity is unresolved.
+ */
+ UNRESOLVED,
+
+ /**
+ * Identifies that resolvable entity's reference is linked.
+ */
+ LINKED,
+
+ /**
+ * Identifies that resolvable entity is IntraFile resolved (i.e. complete
+ * linking with in the intra file).
+ */
+ INTRA_FILE_RESOLVED,
+
+ /**
+ * Identifies that resolvable entity is resolved.
+ */
+ RESOLVED,
+
+ /**
+ * Identifies that resolvable entity is inter file linked (i.e. complete
+ * linking with external files).
+ */
+ INTER_FILE_LINKED
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java
new file mode 100644
index 0000000..c9863c0
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java
@@ -0,0 +1,268 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils;
+
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DECIMAL64;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT16;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT64;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT8;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT16;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT32;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT64;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT8;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.LENGTH_DATA;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.RANGE_DATA;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString;
+
+import java.util.regex.Pattern;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangRangeInterval;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
+
+/**
+ * Represents restriction resolver which provide common utility used by parser
+ * and during linking for restriction resolution.
+ */
+public final class RestrictionResolver {
+
+ private static final String PIPE = "|";
+ private static final String ADD = "+";
+ private static final String EMPTY_STRING = "";
+ private static final String INTERVAL = "..";
+ private static final int MAX_RANGE_BOUNDARY = 2;
+ private static final int MIN_RANGE_BOUNDARY = 1;
+ private static final String MIN_KEYWORD = "min";
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Creates a restriction resolver.
+ */
+ private RestrictionResolver() {
+ }
+
+ /**
+ * Processes the range restriction for parser and linker.
+ *
+ * @param refRangeRestriction range restriction of referred typedef
+ * @param lineNumber error line number
+ * @param charPositionInLine error character position in line
+ * @param hasReferredRestriction whether has referred restriction
+ * @param curRangeString caller type's range string
+ * @param effectiveType effective type, when called from linker
+ * @return YANG range restriction
+ * @throws DataModelException a violation in data model rule
+ */
+ public static YangRangeRestriction processRangeRestriction(YangRangeRestriction refRangeRestriction,
+ int lineNumber, int charPositionInLine,
+ boolean hasReferredRestriction,
+ String curRangeString, YangDataTypes effectiveType)
+ throws DataModelException {
+ YangBuiltInDataTypeInfo<?> startValue;
+ YangBuiltInDataTypeInfo<?> endValue;
+ YangRangeRestriction rangeRestriction = new YangRangeRestriction();
+
+ String rangeArgument = removeQuotesAndHandleConcat(curRangeString);
+ String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
+
+ for (String rangePart : rangeArguments) {
+ String startInterval;
+ String endInterval;
+ YangRangeInterval rangeInterval = new YangRangeInterval();
+ String[] rangeBoundary = rangePart.trim().split(Pattern.quote(INTERVAL));
+
+ if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
+ DataModelException dataModelException = new DataModelException("YANG file error : " +
+ YangConstructType.getYangConstructType(RANGE_DATA) + " " + rangeArgument +
+ " is not valid.");
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
+ startInterval = rangeBoundary[0].trim();
+ endInterval = rangeBoundary[0].trim();
+ } else {
+ startInterval = rangeBoundary[0].trim();
+ endInterval = rangeBoundary[1].trim();
+ }
+
+ try {
+ if (hasReferredRestriction && startInterval.equals(MIN_KEYWORD)
+ && refRangeRestriction.getMinRestrictedvalue() != null) {
+ startValue = refRangeRestriction.getMinRestrictedvalue();
+ } else if (hasReferredRestriction && startInterval.equals(MAX_KEYWORD)
+ && refRangeRestriction.getMaxRestrictedvalue() != null) {
+ startValue = refRangeRestriction.getMaxRestrictedvalue();
+ } else {
+ startValue = getDataObjectFromString(startInterval, effectiveType);
+ }
+ if (hasReferredRestriction && endInterval.equals(MIN_KEYWORD)
+ && refRangeRestriction.getMinRestrictedvalue() != null) {
+ endValue = refRangeRestriction.getMinRestrictedvalue();
+ } else if (hasReferredRestriction && endInterval.equals(MAX_KEYWORD)
+ && refRangeRestriction.getMaxRestrictedvalue() != null) {
+ endValue = refRangeRestriction.getMaxRestrictedvalue();
+ } else {
+ endValue = getDataObjectFromString(endInterval, effectiveType);
+ }
+ } catch (Exception e) {
+ DataModelException dataModelException = new DataModelException(e.getMessage());
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ rangeInterval.setStartValue(startValue);
+ rangeInterval.setEndValue(endValue);
+
+ try {
+ rangeRestriction.addRangeRestrictionInterval(rangeInterval);
+ } catch (DataModelException dataModelException) {
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+ }
+ return rangeRestriction;
+ }
+
+ /**
+ * Processes the length restriction for parser and linker.
+ *
+ * @param refLengthRestriction length restriction of referred typedef
+ * @param lineNumber error line number
+ * @param charPositionInLine error character position in line
+ * @param hasReferredRestriction whether has referred restriction
+ * @param curLengthString caller type's length string
+ * @return YANG range restriction
+ * @throws DataModelException a violation in data model rule
+ */
+ public static YangRangeRestriction processLengthRestriction(YangRangeRestriction refLengthRestriction,
+ int lineNumber, int charPositionInLine,
+ boolean hasReferredRestriction,
+ String curLengthString) throws DataModelException {
+
+ YangBuiltInDataTypeInfo<?> startValue;
+ YangBuiltInDataTypeInfo<?> endValue;
+ YangRangeRestriction lengthRestriction = new YangRangeRestriction<>();
+
+ String rangeArgument = removeQuotesAndHandleConcat(curLengthString);
+ String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
+
+ for (String rangePart : rangeArguments) {
+ String startInterval;
+ String endInterval;
+ YangRangeInterval rangeInterval = new YangRangeInterval<>();
+ String[] rangeBoundary = rangePart.trim().split(Pattern.quote(INTERVAL));
+
+ if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
+ DataModelException dataModelException = new DataModelException("YANG file error : " +
+ YangConstructType.getYangConstructType(LENGTH_DATA) + " " + rangeArgument +
+ " is not valid.");
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
+ startInterval = rangeBoundary[0].trim();
+ endInterval = rangeBoundary[0].trim();
+ } else {
+ startInterval = rangeBoundary[0].trim();
+ endInterval = rangeBoundary[1].trim();
+ }
+
+ try {
+ if (hasReferredRestriction && startInterval.equals(MIN_KEYWORD)
+ && refLengthRestriction.getMinRestrictedvalue() != null) {
+ startValue = refLengthRestriction.getMinRestrictedvalue();
+ } else if (hasReferredRestriction && startInterval.equals(MAX_KEYWORD)
+ && refLengthRestriction.getMaxRestrictedvalue() != null) {
+ startValue = refLengthRestriction.getMaxRestrictedvalue();
+ } else {
+ startValue = getDataObjectFromString(startInterval, YangDataTypes.UINT64);
+ }
+ if (hasReferredRestriction && endInterval.equals(MIN_KEYWORD)
+ && refLengthRestriction.getMinRestrictedvalue() != null) {
+ endValue = refLengthRestriction.getMinRestrictedvalue();
+ } else if (hasReferredRestriction && endInterval.equals(MAX_KEYWORD)
+ && refLengthRestriction.getMaxRestrictedvalue() != null) {
+ endValue = refLengthRestriction.getMaxRestrictedvalue();
+ } else {
+ endValue = getDataObjectFromString(endInterval, YangDataTypes.UINT64);
+ }
+ } catch (Exception e) {
+ DataModelException dataModelException = new DataModelException(e.getMessage());
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ rangeInterval.setStartValue(startValue);
+ rangeInterval.setEndValue(endValue);
+
+ try {
+ lengthRestriction.addRangeRestrictionInterval(rangeInterval);
+ } catch (DataModelException dataModelException) {
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+ }
+ return lengthRestriction;
+ }
+
+ /**
+ * Returns whether the data type is of range restricted type.
+ *
+ * @param dataType data type to be checked
+ * @return true, if data type can have range restrictions, false otherwise
+ */
+ public static boolean isOfRangeRestrictedType(YangDataTypes dataType) {
+ return dataType == INT8
+ || dataType == INT16
+ || dataType == INT32
+ || dataType == INT64
+ || dataType == UINT8
+ || dataType == UINT16
+ || dataType == UINT32
+ || dataType == UINT64
+ || dataType == DECIMAL64;
+ }
+
+ /**
+ * Removes doubles quotes and concatenates if string has plus symbol.
+ *
+ * @param yangStringData string from yang file
+ * @return concatenated string after removing double quotes
+ */
+ private static String removeQuotesAndHandleConcat(String yangStringData) {
+
+ yangStringData = yangStringData.replace("\"", EMPTY_STRING);
+ String[] tmpData = yangStringData.split(Pattern.quote(ADD));
+ StringBuilder builder = new StringBuilder();
+ for (String yangString : tmpData) {
+ builder.append(yangString);
+ }
+ return builder.toString();
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/YangConstructType.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/YangConstructType.java
new file mode 100644
index 0000000..715fb76
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/YangConstructType.java
@@ -0,0 +1,532 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel.utils;
+
+/**
+ * Represents ENUM to represent the type of data in parse tree.
+ */
+public enum YangConstructType {
+ /**
+ * Identifies the module parsed data.
+ */
+ MODULE_DATA,
+
+ /**
+ * Identifies the sub module parsed data.
+ */
+ SUB_MODULE_DATA,
+
+ /**
+ * Identifies the typedef parsed data.
+ */
+ TYPEDEF_DATA,
+
+ /**
+ * Identifies the type parsed data.
+ */
+ TYPE_DATA,
+
+ /**
+ * Identifies the choice parsed data.
+ */
+ CHOICE_DATA,
+
+ /**
+ * Identifies the case parsed data.
+ */
+ CASE_DATA,
+
+ /**
+ * Identifies the YANG enumeration parsed data.
+ */
+ ENUMERATION_DATA,
+
+ /**
+ * Identifies the grouping parsed data.
+ */
+ GROUPING_DATA,
+
+ /**
+ * Identifies the uses parsed data.
+ */
+ USES_DATA,
+
+ /**
+ * Identifies the augment parsed data.
+ */
+ AUGMENT_DATA,
+
+ /**
+ * Identifies the container parsed data.
+ */
+ CONTAINER_DATA,
+
+ /**
+ * Identifies the YANG list parsed data.
+ */
+ LIST_DATA,
+
+ /**
+ * Identifies the YANG belongs-to parsed data.
+ */
+ BELONGS_TO_DATA,
+
+ /**
+ * Identifies the YANG bit parsed data.
+ */
+ BIT_DATA,
+
+ /**
+ * Identifies the YANG bits parsed data.
+ */
+ BITS_DATA,
+
+ /**
+ * Identifies the YANG enum parsed data.
+ */
+ ENUM_DATA,
+
+ /**
+ * Identifies the YANG import parsed data.
+ */
+ IMPORT_DATA,
+
+ /**
+ * Identifies the YANG include parsed data.
+ */
+ INCLUDE_DATA,
+
+ /**
+ * Identifies the YANG leaf parsed data.
+ */
+ LEAF_DATA,
+
+ /**
+ * Identifies the YANG leaf list parsed data.
+ */
+ LEAF_LIST_DATA,
+
+ /**
+ * Identifies the YANG must parsed data.
+ */
+ MUST_DATA,
+
+ /**
+ * Identifies the YANG revision parsed data.
+ */
+ REVISION_DATA,
+
+ /**
+ * Identifies the YANG revision date parsed data.
+ */
+ REVISION_DATE_DATA,
+
+ /**
+ * Identifies the YANG namespace parsed data.
+ */
+ NAMESPACE_DATA,
+
+ /**
+ * Identifies the YANG contact parsed data.
+ */
+ CONTACT_DATA,
+
+ /**
+ * Identifies the YANG config parsed data.
+ */
+ CONFIG_DATA,
+
+ /**
+ * Identifies the YANG description parsed data.
+ */
+ DESCRIPTION_DATA,
+
+ /**
+ * Identifies the YANG key parsed data.
+ */
+ KEY_DATA,
+
+ /**
+ * Identifies the YANG mandatory parsed data.
+ */
+ MANDATORY_DATA,
+
+ /**
+ * Identifies the YANG max element parsed data.
+ */
+ MAX_ELEMENT_DATA,
+
+ /**
+ * Identifies the YANG min element parsed data.
+ */
+ MIN_ELEMENT_DATA,
+
+ /**
+ * Identifies the YANG presence element parsed data.
+ */
+ PRESENCE_DATA,
+
+ /**
+ * Identifies the YANG reference element parsed data.
+ */
+ REFERENCE_DATA,
+
+ /**
+ * Identifies the YANG status element parsed data.
+ */
+ STATUS_DATA,
+
+ /**
+ * Identifies the YANG units element parsed data.
+ */
+ UNITS_DATA,
+
+ /**
+ * Identifies the YANG version element parsed data.
+ */
+ VERSION_DATA,
+
+ /**
+ * Identifies the YANG base element parsed data.
+ */
+ YANGBASE_DATA,
+
+ /**
+ * Identifies the YANG prefix element parsed data.
+ */
+ PREFIX_DATA,
+
+ /**
+ * Identifies the YANG default element parsed data.
+ */
+ DEFAULT_DATA,
+
+ /**
+ * Identifies the YANG value element parsed data.
+ */
+ VALUE_DATA,
+
+ /**
+ * Identifies the YANG organization parsed data.
+ */
+ ORGANIZATION_DATA,
+
+ /**
+ * Identifies the YANG position element parsed data.
+ */
+ POSITION_DATA,
+
+ /**
+ * Identifies the YANG data definition statements.
+ */
+ DATA_DEF_DATA,
+
+ /**
+ * Identifies the YANG union element parsed data.
+ */
+ UNION_DATA,
+
+ /**
+ * Identifies the YANG notification element parsed data.
+ */
+ NOTIFICATION_DATA,
+
+ /**
+ * Identifies the YANG when element parsed data.
+ */
+ WHEN_DATA,
+
+ /**
+ * Identifies the YANG input element parsed data.
+ */
+ INPUT_DATA,
+
+ /**
+ * Identifies the YANG output element parsed data.
+ */
+ OUTPUT_DATA,
+
+ /**
+ * Identifies the YANG rpc element parsed data.
+ */
+ RPC_DATA,
+
+ /**
+ * Identifies the YANG short case element parsed data.
+ */
+ SHORT_CASE_DATA,
+
+ /**
+ * Identifies the derived data type.
+ */
+ DERIVED,
+
+ /**
+ * Identifies the YANG range element parsed data.
+ */
+ RANGE_DATA,
+
+ /**
+ * Identifies the YANG length element parsed data.
+ */
+ LENGTH_DATA,
+
+ /**
+ * Identifies the YANG pattern element parsed data.
+ */
+ PATTERN_DATA,
+
+ /**
+ * Identifies the YANG extension element parsed data.
+ */
+ EXTENSION_DATA,
+
+ /**
+ * Identifies the YANG identity element parsed data.
+ */
+ IDENTITY_DATA,
+
+ /**
+ * Identifies the YANG base element parsed data.
+ */
+ BASE_DATA,
+
+ /**
+ * Identifies the YANG feature element parsed data.
+ */
+ FEATURE_DATA,
+
+ /**
+ * Identifies the YANG if-feature element parsed data.
+ */
+ IF_FEATURE_DATA,
+
+ /**
+ * Identifies the YANG path element parsed data.
+ */
+ PATH_DATA,
+
+ /**
+ * Identifies the YANG require-instance element parsed data.
+ */
+ REQUIRE_INSTANCE_DATA,
+
+ /**
+ * Identifies the YANG ordered-by element parsed data.
+ */
+ ORDERED_BY_DATA,
+
+ /**
+ * Identifies the YANG error-message element parsed data.
+ */
+ ERROR_MESSAGE_DATA,
+
+ /**
+ * Identifies the YANG error-app-tag element parsed data.
+ */
+ ERROR_APP_TAG_DATA,
+
+ /**
+ * Identifies the YANG unique element parsed data.
+ */
+ UNIQUE_DATA,
+
+ /**
+ * Identifies the YANG refine element parsed data.
+ */
+ REFINE_DATA,
+
+ /**
+ * Identifies the YANG leafref element parsed data.
+ */
+ LEAFREF_DATA,
+
+ /**
+ * Identifies the YANG identityref element parsed data.
+ */
+ IDENTITYREF_DATA,
+
+ /**
+ * Identifies the YANG instance identifier element parsed data.
+ */
+ INSTANCE_IDENTIFIER_DATA,
+
+ /**
+ * Identifies the YANG deviation element parsed data.
+ */
+ DEVIATION_DATA,
+
+ /**
+ * Identifies the YANG anyxml element parsed data.
+ */
+ ANYXML_DATA;
+
+ /**
+ * Returns the YANG construct keyword corresponding to enum values.
+ *
+ * @param yangConstructType enum value for parsable data type.
+ * @return YANG construct keyword.
+ */
+ public static String getYangConstructType(YangConstructType yangConstructType) {
+
+ switch (yangConstructType) {
+ case MODULE_DATA:
+ return "module";
+ case SUB_MODULE_DATA:
+ return "submodule";
+ case TYPEDEF_DATA:
+ return "typedef";
+ case TYPE_DATA:
+ return "type";
+ case CHOICE_DATA:
+ return "choice";
+ case CASE_DATA:
+ return "case";
+ case ENUMERATION_DATA:
+ return "enumeration";
+ case GROUPING_DATA:
+ return "grouping";
+ case USES_DATA:
+ return "uses";
+ case AUGMENT_DATA:
+ return "augment";
+ case CONTAINER_DATA:
+ return "container";
+ case LIST_DATA:
+ return "list";
+ case BELONGS_TO_DATA:
+ return "belongs-to";
+ case BIT_DATA:
+ return "bit";
+ case BITS_DATA:
+ return "bits";
+ case ENUM_DATA:
+ return "enum";
+ case IMPORT_DATA:
+ return "import";
+ case INCLUDE_DATA:
+ return "include";
+ case LEAF_DATA:
+ return "leaf";
+ case LEAF_LIST_DATA:
+ return "leaf-list";
+ case MUST_DATA:
+ return "must";
+ case REVISION_DATA:
+ return "revision";
+ case REVISION_DATE_DATA:
+ return "revision-date";
+ case NAMESPACE_DATA:
+ return "namespace";
+ case CONTACT_DATA:
+ return "contact";
+ case CONFIG_DATA:
+ return "config";
+ case DESCRIPTION_DATA:
+ return "description";
+ case KEY_DATA:
+ return "key";
+ case MANDATORY_DATA:
+ return "mandatory";
+ case MAX_ELEMENT_DATA:
+ return "max-elements";
+ case MIN_ELEMENT_DATA:
+ return "min-elements";
+ case PRESENCE_DATA:
+ return "presence";
+ case REFERENCE_DATA:
+ return "reference";
+ case STATUS_DATA:
+ return "status";
+ case UNITS_DATA:
+ return "units";
+ case VERSION_DATA:
+ return "version";
+ case YANGBASE_DATA:
+ return "yangbase";
+ case PREFIX_DATA:
+ return "prefix";
+ case ORGANIZATION_DATA:
+ return "organization";
+ case VALUE_DATA:
+ return "value";
+ case POSITION_DATA:
+ return "position";
+ case DEFAULT_DATA:
+ return "default";
+ case DATA_DEF_DATA:
+ return "data-def-substatements";
+ case WHEN_DATA:
+ return "when";
+ case INPUT_DATA:
+ return "input";
+ case OUTPUT_DATA:
+ return "ouput";
+ case RPC_DATA:
+ return "rpc";
+ case SHORT_CASE_DATA:
+ return "short-case";
+ case DERIVED:
+ return "derived";
+ case NOTIFICATION_DATA:
+ return "notification";
+ case UNION_DATA:
+ return "union";
+ case RANGE_DATA:
+ return "range";
+ case LENGTH_DATA:
+ return "length";
+ case PATTERN_DATA:
+ return "pattern";
+ case EXTENSION_DATA:
+ return "extension";
+ case IDENTITY_DATA:
+ return "identity";
+ case BASE_DATA:
+ return "base";
+ case FEATURE_DATA:
+ return "feature";
+ case IF_FEATURE_DATA:
+ return "if-feature";
+ case PATH_DATA:
+ return "path";
+ case REQUIRE_INSTANCE_DATA:
+ return "require-instance";
+ case ORDERED_BY_DATA:
+ return "ordered-by";
+ case ERROR_MESSAGE_DATA:
+ return "error-message";
+ case ERROR_APP_TAG_DATA:
+ return "error-app-tag";
+ case UNIQUE_DATA:
+ return "unique";
+ case REFINE_DATA:
+ return "refine";
+ case LEAFREF_DATA:
+ return "leafref";
+ case IDENTITYREF_DATA:
+ return "identityref";
+ case INSTANCE_IDENTIFIER_DATA:
+ return "instance-identifier";
+ case DEVIATION_DATA:
+ return "deviation";
+ case ANYXML_DATA:
+ return "anyxml";
+ default:
+ return "yang";
+ }
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/BuiltInTypeObjectFactory.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/BuiltInTypeObjectFactory.java
new file mode 100644
index 0000000..1f28565
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/BuiltInTypeObjectFactory.java
@@ -0,0 +1,79 @@
+/*-
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Factory to create an object of required type.
+ */
+public final class BuiltInTypeObjectFactory implements Serializable {
+
+ private static final long serialVersionUID = 8006201671L;
+
+ /**
+ * Utility factory class, hence the object creation is forbidden.
+ */
+ private BuiltInTypeObjectFactory() {
+ }
+
+ /**
+ * Given the value represented in string return the corresponding types
+ * object with the value initialized.
+ *
+ * @param valueInStr value represented in string
+ * @param builtInType built in data type
+ * @param <T> the data type of the target object
+ * @return the target data type object with the value initialized
+ */
+ public static <T extends YangBuiltInDataTypeInfo<?>> T getDataObjectFromString(String valueInStr,
+ YangDataTypes builtInType) {
+
+ switch (builtInType) {
+ case INT8: {
+ return (T) new YangInt8(valueInStr);
+ }
+ case INT16: {
+ return (T) new YangInt16(valueInStr);
+ }
+ case INT32: {
+ return (T) new YangInt32(valueInStr);
+ }
+ case INT64: {
+ return (T) new YangInt64(valueInStr);
+ }
+ case UINT8: {
+ return (T) new YangUint8(valueInStr);
+ }
+ case UINT16: {
+ return (T) new YangUint16(valueInStr);
+ }
+ case UINT32: {
+ return (T) new YangUint32(valueInStr);
+ }
+ case UINT64: {
+ return (T) new YangUint64(valueInStr);
+ }
+ default: {
+ throw new DataTypeException("YANG file error : Unsupported data type");
+ }
+ }
+
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/DataTypeException.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/DataTypeException.java
new file mode 100644
index 0000000..8c24d6c
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/DataTypeException.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+/**
+ * Base class for exceptions in data type.
+ */
+public class DataTypeException extends RuntimeException {
+
+ private static final long serialVersionUID = 20160211L;
+
+ /**
+ * Create a new data type exception.
+ */
+ public DataTypeException() {
+ super();
+ }
+
+ /**
+ * Creates a new data type exception with given message.
+ *
+ * @param message the detail of exception in string
+ */
+ public DataTypeException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new data type exception from given message and cause.
+ *
+ * @param message the detail of exception in string
+ * @param cause underlying cause of the error
+ */
+ public DataTypeException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new data type exception from cause.
+ *
+ * @param cause underlying cause of the error
+ */
+ public DataTypeException(final Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBinary.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBinary.java
new file mode 100644
index 0000000..663ddc5
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBinary.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents binary data type.
+ */
+public final class YangBinary implements Serializable {
+
+ private static final long serialVersionUID = 8006201670L;
+
+ private byte[] byteArray;
+
+ /**
+ * Creates an instance of YANG binary.
+ */
+ private YangBinary() {
+ }
+
+ /**
+ * Creates an instance of YANG binary.
+ *
+ * @param bytes byte array
+ */
+ public YangBinary(byte[] bytes) {
+ byteArray = bytes;
+ }
+
+ /**
+ * Returns object of YANG binary.
+ *
+ * @param bytes byte array
+ * @return object of YANG binary
+ */
+ public static YangBinary of(byte[] bytes) {
+ return new YangBinary(bytes);
+ }
+
+ /**
+ * Returns byte array.
+ *
+ * @return byte array
+ */
+ public byte[] byteArray() {
+ return byteArray;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(byteArray);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangBinary) {
+ YangBinary other = (YangBinary) obj;
+ return Objects.equals(byteArray, other.byteArray);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("byteArray", byteArray)
+ .toString();
+ }
+
+ /**
+ * Returns the object of YANG binary fromString input String.
+ *
+ * @param valInString input String
+ * @return Object of YANG binary
+ */
+ public static YangBinary fromString(String valInString) {
+ try {
+ byte[] tmpVal = valInString.getBytes();
+ return of(tmpVal);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBits.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBits.java
new file mode 100644
index 0000000..1e1d325
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBits.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents bits data type.
+ */
+public class YangBits implements Serializable {
+
+ private static final long serialVersionUID = 8006201669L;
+
+ private byte[] byteArray;
+
+ /**
+ * Creates an instance of YANG bits.
+ */
+ private YangBits() {
+ }
+
+ /**
+ * Creates an instance of YANG bits.
+ *
+ * @param bytes byte array
+ */
+ public YangBits(byte[] bytes) {
+ byteArray = bytes;
+ }
+
+ /**
+ * Returns object of YANG bits.
+ *
+ * @param bytes byte array
+ * @return object of YANG bits
+ */
+ public static YangBits of(byte[] bytes) {
+ return new YangBits(bytes);
+ }
+
+ /**
+ * Returns byte array.
+ *
+ * @return byte array
+ */
+ public byte[] byteArray() {
+ return byteArray;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(byteArray);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangBits) {
+ YangBits other = (YangBits) obj;
+ return Objects.equals(byteArray, other.byteArray);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("byteArray", byteArray)
+ .toString();
+ }
+
+ /**
+ * Returns the object of YANG bits fromString input String.
+ *
+ * @param valInString input String
+ * @return Object of YANG bits
+ */
+ public static YangBits fromString(String valInString) {
+ try {
+ byte[] tmpVal = valInString.getBytes();
+ return of(tmpVal);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBuiltInDataTypeInfo.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBuiltInDataTypeInfo.java
new file mode 100644
index 0000000..b082c16
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBuiltInDataTypeInfo.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Represents the list of utility functions to be supported by YANG built in
+ * data type implementations.
+ *
+ * @param <T> The target data type
+ */
+public interface YangBuiltInDataTypeInfo<T> extends Comparable<T> {
+
+ /**
+ * Returns the YANG built in type.
+ *
+ * @return the YANG built in type
+ */
+ YangDataTypes getYangType();
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDecimal64.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDecimal64.java
new file mode 100644
index 0000000..74c657b
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDecimal64.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents YANG decimal 64.
+ */
+public class YangDecimal64 implements Serializable {
+
+ private static final long serialVersionUID = 8006201668L;
+
+ private int fractionDigit;
+
+ /**
+ * Creates an instance of YANG decimal64.
+ */
+ public YangDecimal64() {
+ }
+
+ /**
+ * Creates an instance of of YANG decimal64.
+ *
+ * @param fractionDigit fraction digit
+ */
+ public YangDecimal64(int fractionDigit) {
+ setFractionDigit(fractionDigit);
+ }
+
+ /**
+ * Returns fraction digit.
+ *
+ * @return the fractionDigit
+ */
+ public int getFractionDigit() {
+ return fractionDigit;
+ }
+
+ /**
+ * Sets fraction digit.
+ *
+ * @param fractionDigit fraction digits.
+ */
+ public void setFractionDigit(int fractionDigit) {
+ this.fractionDigit = fractionDigit;
+ }
+
+ /**
+ * Returns object of YANG decimal64.
+ *
+ * @param value fraction digit
+ * @return YANG decimal64
+ */
+ public static YangDecimal64 of(int value) {
+ return new YangDecimal64(value);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fractionDigit);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangDecimal64) {
+ YangDecimal64 other = (YangDecimal64) obj;
+ return Objects.equals(fractionDigit, other.fractionDigit);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("fractionDigit", fractionDigit)
+ .toString();
+ }
+
+ /**
+ * Returns the object of YANG decimal64 fromString input String.
+ *
+ * @param valInString input String
+ * @return Object of YANG decimal64
+ */
+ public static YangDecimal64 fromString(String valInString) {
+ try {
+ int tmpVal = Integer.parseInt(valInString);
+ return of(tmpVal);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt16.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt16.java
new file mode 100644
index 0000000..c005b8d
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt16.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's int16 data type processing.
+ *
+ * int16 represents integer values between -32768 and 32767, inclusively.
+ */
+public class YangInt16 implements YangBuiltInDataTypeInfo<YangInt16>, Serializable {
+
+ private static final long serialVersionUID = 8006201667L;
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's int16.
+ */
+ public static final short MIN_VALUE = -32768;
+
+ /**
+ * Valid maximum value of YANG's int16.
+ */
+ public static final short MAX_VALUE = 32767;
+
+ /**
+ * The value of YANG's int16.
+ */
+ private final short value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ public YangInt16(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Short.parseShort(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "int16.");
+ }
+ }
+ }
+
+ /**
+ * Returns YANG's int16 value.
+ *
+ * @return value of YANG's int16
+ */
+ public short getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangInt16 anotherYangInt16) {
+ return Short.compare(value, anotherYangInt16.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT16;
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt32.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt32.java
new file mode 100644
index 0000000..45ae3d1
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt32.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's int32 data type processing.
+ *
+ * int32 represents integer values between -2147483648 and 2147483647, inclusively.
+ */
+public class YangInt32 implements YangBuiltInDataTypeInfo<YangInt32>, Serializable {
+
+ private static final long serialVersionUID = 8006201666L;
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's int32.
+ */
+ public static final int MIN_VALUE = -2147483648;
+
+ /**
+ * Valid maximum value of YANG's int32.
+ */
+ public static final int MAX_VALUE = 2147483647;
+
+ /**
+ * The value of YANG's int32.
+ */
+ private final int value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ public YangInt32(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Integer.parseInt(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "int32.");
+ }
+ }
+ }
+
+ /**
+ * Returns YANG's int32 value.
+ *
+ * @return value of YANG's int32
+ */
+ public int getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangInt32 anotherYangInt32) {
+ return Integer.compare(value, anotherYangInt32.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT32;
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt64.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt64.java
new file mode 100644
index 0000000..9f97bf8
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt64.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's int8 data type processing.
+ *
+ * int8 represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.
+ */
+public class YangInt64 implements YangBuiltInDataTypeInfo<YangInt64>, Serializable {
+
+ private static final long serialVersionUID = 8006201665L;
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's int64.
+ */
+ public static final Long MIN_VALUE = 0x8000000000000000L;
+
+ /**
+ * Valid maximum value of YANG's int64.
+ */
+ public static final long MAX_VALUE = 0x7fffffffffffffffL;
+
+ /**
+ * The value of YANG's int64.
+ */
+ private final long value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ public YangInt64(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Long.parseLong(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "int64.");
+ }
+ }
+ }
+
+ /**
+ * Returns YANG's int64 value.
+ *
+ * @return value of YANG's int64
+ */
+ public long getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangInt64 anotherYangInt64) {
+ return Long.compare(value, anotherYangInt64.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT64;
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt8.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt8.java
new file mode 100644
index 0000000..aad8c0b
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt8.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's int8 data type processing.
+ *
+ * int8 represents integer values between -128 and 127, inclusively.
+ */
+public class YangInt8 implements YangBuiltInDataTypeInfo<YangInt8>, Serializable {
+
+ private static final long serialVersionUID = 8006201664L;
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's int8.
+ */
+ public static final byte MIN_VALUE = -128;
+
+ /**
+ * Valid maximum value of YANG's int8.
+ */
+ public static final byte MAX_VALUE = 127;
+
+ /**
+ * The value of YANG's int8.
+ */
+ private final byte value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ public YangInt8(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Byte.parseByte(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "int8.");
+ }
+ }
+ }
+
+ /**
+ * Returns YANG's int8 value.
+ *
+ * @return value of YANG's int8
+ */
+ public byte getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangInt8 anotherYangInt8) {
+ return Byte.compare(value, anotherYangInt8.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT8;
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint16.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint16.java
new file mode 100644
index 0000000..c5a1ff3
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint16.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's Uint16 data type processing.
+ *
+ * Uint16 represents integer values between 0 and 65535, inclusively.
+ */
+public class YangUint16 implements YangBuiltInDataTypeInfo<YangUint16>, Serializable {
+
+ private static final long serialVersionUID = 8006201663L;
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's Uint16.
+ */
+ public static final int MIN_VALUE = 0;
+
+ /**
+ * Valid maximum value of YANG's Uint16.
+ */
+ public static final int MAX_VALUE = 65535;
+
+ /**
+ * Value of the object.
+ */
+ private int value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ YangUint16(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Integer.parseInt(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "uint16.");
+ }
+ }
+
+ if (value < MIN_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value > MAX_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns YANG's uint16 value.
+ *
+ * @return value of YANG's uint16
+ */
+ public int getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangUint16 another) {
+ return Integer.compare(value, another.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.UINT16;
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint32.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint32.java
new file mode 100644
index 0000000..031f45a
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint32.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's Uint32 data type processing.
+ *
+ * Uint32 represents integer values between 0 and 4294967295, inclusively.
+ */
+public class YangUint32 implements YangBuiltInDataTypeInfo<YangUint32>, Serializable {
+
+ private static final long serialVersionUID = 8006201662L;
+
+ private static final String MIN_KEYWORD = "min";
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's Uint32.
+ */
+ public static final long MIN_VALUE = 0;
+
+ /**
+ * Valid maximum value of YANG's Uint32.
+ */
+ public static final long MAX_VALUE = 4294967295L;
+
+ /**
+ * Value of the object.
+ */
+ private long value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ YangUint32(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Long.parseLong(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "uint32.");
+ }
+ }
+
+ if (value < MIN_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value > MAX_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns YANG's uint32 value.
+ *
+ * @return value of YANG's uint32
+ */
+ public long getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangUint32 another) {
+ return Long.compare(value, another.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.UINT32;
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint64.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint64.java
new file mode 100644
index 0000000..3a0a71f
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint64.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.regex.Pattern;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's Uint16 data type processing.
+ *
+ * Uint64 represents integer values between 0 and 18446744073709551615, inclusively.
+ */
+public class YangUint64 implements YangBuiltInDataTypeInfo<YangUint64>, Serializable {
+
+ private static final long serialVersionUID = 8006201661L;
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * YANG's Integer value pattern.
+ */
+ private static final Pattern NON_NEGATIVE_INTEGER_PATTERN = Pattern.compile("[0-9]+");
+
+ /**
+ * Valid minimum value of YANG's Uint64.
+ */
+ public static final BigInteger MIN_VALUE = BigInteger.valueOf(0);
+
+ /**
+ * Valid maximum value of YANG's Uint64.
+ */
+ public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
+
+ /**
+ * Value of the object.
+ */
+ private BigInteger value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ YangUint64(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else if (NON_NEGATIVE_INTEGER_PATTERN.matcher(valueInString).matches()) {
+ value = new BigInteger(valueInString);
+ } else {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "uint64.");
+ }
+
+ if (value.compareTo(MIN_VALUE) < 0) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value.compareTo(MAX_VALUE) > 0) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns YANG's uint64 value.
+ *
+ * @return value of YANG's uint64
+ */
+ public BigInteger getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangUint64 another) {
+ return value.compareTo(another.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.UINT64;
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint8.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint8.java
new file mode 100644
index 0000000..8de263a
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint8.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.io.Serializable;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's Uint8 data type processing.
+ *
+ * Uint8 represents integer values between 0 and 255, inclusively.
+ */
+public class YangUint8 implements YangBuiltInDataTypeInfo<YangUint8>, Serializable {
+
+ private static final long serialVersionUID = 8006201660L;
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's Uint8.
+ */
+ public static final short MIN_VALUE = 0;
+
+ /**
+ * Valid maximum value of YANG's Uint8.
+ */
+ public static final short MAX_VALUE = 255;
+
+ /**
+ * Value of the object.
+ */
+ private short value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ YangUint8(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Short.parseShort(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "uint8.");
+ }
+ }
+
+ if (value < MIN_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value > MAX_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns YANG's uint8 value.
+ *
+ * @return value of YANG's uint8
+ */
+ public short getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangUint8 another) {
+ return Short.compare(value, another.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.UINT8;
+ }
+
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/package-info.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/package-info.java
new file mode 100644
index 0000000..d1ceae5
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Utilities for YANG built in data types.
+ */
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/package-info.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/package-info.java
new file mode 100644
index 0000000..5d2a683
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Utilities for checking data model tree collisions.
+ */
+package org.onosproject.yangutils.datamodel.utils;
\ No newline at end of file