[ONOS-5785] Refactor code into new folder structure
Change-Id: I115d5af1cd7bfbde71a3092973fe160ec1d9bae5
diff --git a/compiler/base/datamodel/pom.xml b/compiler/base/datamodel/pom.xml
new file mode 100644
index 0000000..28618a0
--- /dev/null
+++ b/compiler/base/datamodel/pom.xml
@@ -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.
+ -->
+<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-yang-compiler-base</artifactId>
+ <version>1.12-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>onos-yang-compiler-datamodel</artifactId>
+ <packaging>jar</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.0.2</version>
+ <configuration>
+ <skipIfEmpty>true</skipIfEmpty>
+ </configuration>
+ <executions>
+ <execution>
+ <id>default</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/BuiltInTypeObjectFactory.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/BuiltInTypeObjectFactory.java
new file mode 100644
index 0000000..f2bfb8c
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/BuiltInTypeObjectFactory.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.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.DataTypeException;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangInt16;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangInt32;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangInt64;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangInt8;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangUint16;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangUint32;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangUint64;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangUint8;
+
+import java.io.Serializable;
+
+/**
+ * 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);
+ }
+ case DECIMAL64: {
+ return (T) new YangDecimal64(valueInStr);
+ }
+ default: {
+ throw new DataTypeException("YANG file error : Unsupported data type");
+ }
+ }
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/CollisionDetector.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/CollisionDetector.java
new file mode 100644
index 0000000..728a513
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/DefaultLocationInfo.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/DefaultLocationInfo.java
new file mode 100644
index 0000000..985542b
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/DefaultLocationInfo.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Represents the implementation of location info.
+ */
+public class DefaultLocationInfo implements LocationInfo {
+
+ private transient int lineNumber;
+ private transient int charPosition;
+ private String fileName;
+
+ @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;
+ }
+
+ @Override
+ public String getFileName() {
+ return fileName;
+ }
+
+ @Override
+ public void setFileName(String name) {
+ fileName = name;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/InvalidOpTypeHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/InvalidOpTypeHolder.java
new file mode 100644
index 0000000..f8659cd
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/InvalidOpTypeHolder.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.yang.compiler.datamodel;
+
+/**
+ * Represents non data nodes which will not have operation api's ex: operation
+ * type, value leaf flag, select leaf flag and process sub tree filter in
+ * their generated code.
+ */
+public interface InvalidOpTypeHolder {
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/LeafRefInvalidHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/LeafRefInvalidHolder.java
new file mode 100644
index 0000000..d9f23f0
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/LeafRefInvalidHolder.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Represents YANG nodes which linking of leaf ref should be avoided.
+ */
+public interface LeafRefInvalidHolder {
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/LocationInfo.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/LocationInfo.java
new file mode 100644
index 0000000..0e1f4c1
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/LocationInfo.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Abstraction of 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);
+
+ /**
+ * Returns YANG file name.
+ *
+ * @return YANG file name
+ */
+ String getFileName();
+
+ /**
+ * Sets YANG file name
+ *
+ * @param name YANG file name
+ */
+ void setFileName(String name);
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/Resolvable.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/Resolvable.java
new file mode 100644
index 0000000..ec25c55
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/Resolvable.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
+
+/**
+ * Abstraction of YANG resolvable information. Abstracted to obtain the
+ * information required for linking resolution.
+ *
+ * @param <T> YANG resolvable info
+ */
+public interface Resolvable<T> {
+
+ /**
+ * 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.
+ *
+ * @return list of entities to be added for resolution
+ * @throws DataModelException data model exception
+ */
+ T resolve()
+ throws DataModelException;
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/ResolvableType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/ResolvableType.java
new file mode 100644
index 0000000..367c811
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/ResolvableType.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Type of the resolvable info.
+ */
+public enum ResolvableType {
+
+ /**
+ * Identifies the derived data type.
+ */
+ YANG_DERIVED_DATA_TYPE,
+
+ /**
+ * Identifies the uses.
+ */
+ YANG_USES,
+
+ /**
+ * Identifies the if-feature.
+ */
+ YANG_IF_FEATURE,
+
+ /**
+ * Identifies the leafref.
+ */
+ YANG_LEAFREF,
+
+ /**
+ * Identifies the base.
+ */
+ YANG_BASE,
+
+ /**
+ * Identifies the identityref.
+ */
+ YANG_IDENTITYREF,
+
+ /**
+ * Identifies the augment.
+ */
+ YANG_AUGMENT,
+
+ /**
+ * Identifies the compiler annotations.
+ */
+ YANG_COMPILER_ANNOTATION
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/RpcNotificationContainer.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/RpcNotificationContainer.java
new file mode 100644
index 0000000..4f709b3
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/RpcNotificationContainer.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import java.util.List;
+
+/**
+ * Represents class having rpc and notification.
+ */
+public interface RpcNotificationContainer {
+
+ /**
+ * Sets notification presence flag.
+ *
+ * @param notificationPresent notification presence flag
+ */
+ void setNotificationPresenceFlag(boolean notificationPresent);
+
+ /**
+ * Adds to notification enumeration map.
+ *
+ * @param enumName name of notification in enum
+ * @param schemaNode schema node of notification
+ */
+ void addToNotificationEnumMap(String enumName, YangSchemaNode schemaNode);
+
+ /**
+ * Adds augment which is augmenting input node to augment list.
+ *
+ * @param augment augment which is augmenting input
+ */
+ void addToAugmentList(YangAugment augment);
+
+ /**
+ * Returns augment list.
+ *
+ * @return augment list
+ */
+ List<YangAugment> getAugmentList();
+
+ /**
+ * Returns prefix.
+ *
+ * @return prefix
+ */
+ String getPrefix();
+
+ /**
+ * Returns list of notification nodes.
+ *
+ * @return list of notification nodes
+ */
+ List<YangNode> getNotificationNodes();
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/TraversalType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/TraversalType.java
new file mode 100644
index 0000000..4b7162d
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/TraversalType.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Represents data model tree traversal types.
+ */
+public enum TraversalType {
+
+ /**
+ * Start of traversal at the tree root.
+ */
+ ROOT,
+
+ /**
+ * Child node traversal.
+ */
+ CHILD,
+
+ /**
+ * Sibling node traversal.
+ */
+ SIBILING,
+
+ /**
+ * Parent node traversal.
+ */
+ PARENT
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAppDataStructure.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAppDataStructure.java
new file mode 100644
index 0000000..d750d9e
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAppDataStructure.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.APP_DATA_STRUCTURE;
+
+/**
+ * Represents data model node to maintain information defined in YANG app-data-structure.
+ */
+public class YangAppDataStructure extends DefaultLocationInfo
+ implements Parsable, Serializable {
+
+ private static final long serialVersionUID = 806201602L;
+
+ /**
+ * Data structure information.
+ */
+ private YangDataStructure dataStructure;
+
+ /**
+ * List of key names.
+ */
+ private List<String> keyList;
+
+ /**
+ * Prefix of app-data-structure.
+ */
+ private String prefix;
+
+ /**
+ * Returns the YANG data structure information.
+ *
+ * @return the YANG data structure information
+ */
+ public YangDataStructure getDataStructure() {
+ return dataStructure;
+ }
+
+ /**
+ * Sets the YANG data structure information.
+ *
+ * @param dataStructure the YANG data structure to set
+ */
+ public void setDataStructure(YangDataStructure dataStructure) {
+ this.dataStructure = dataStructure;
+ }
+
+ /**
+ * Returns the list of key field names.
+ *
+ * @return the list of key field names
+ */
+ public List<String> getKeyList() {
+ return unmodifiableList(keyList);
+ }
+
+ /**
+ * Adds a key field name.
+ *
+ * @param key key field name
+ */
+ public void addKey(String key) {
+ if (keyList == null) {
+ keyList = new LinkedList<>();
+ }
+ keyList.add(key);
+ }
+
+ /**
+ * Returns the prefix.
+ *
+ * @return the prefix
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * Sets the prefix information.
+ *
+ * @param prefix the prefix to set
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return APP_DATA_STRUCTURE;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO : to be implemented
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO : to be implemented
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAppErrorHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAppErrorHolder.java
new file mode 100644
index 0000000..113a143
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAppErrorHolder.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Represents data model node to maintain YANG app error message information.
+ */
+public interface YangAppErrorHolder {
+
+ /**
+ * Sets the application's error information.
+ *
+ * @param yangAppErrorInfo the application's error information
+ */
+ void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo);
+
+ /**
+ * Returns application's error information.
+ *
+ * @return application's error information
+ */
+ YangAppErrorInfo getAppErrorInfo();
+
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAppErrorInfo.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAppErrorInfo.java
new file mode 100644
index 0000000..f82c7e6
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAppErrorInfo.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import java.io.Serializable;
+
+/**
+ * Represents data model to maintain yang app error information.
+ */
+public class YangAppErrorInfo extends DefaultLocationInfo implements Serializable {
+
+ private static final long serialVersionUID = 807201693L;
+
+ /**
+ * Application's error message, to be used for data error.
+ */
+ private String errorMessage;
+
+ /**
+ * Error tag, to be filled in data validation error response.
+ */
+ private String errorTag;
+
+ /**
+ * Application's error tag, to be filled in data validation error response.
+ */
+ private String errorAppTag;
+
+ /**
+ * Application's error path, to be filled in data validation error response.
+ */
+ private String errorAppPath;
+
+ /**
+ * Application's error info, to be filled in data validation error response.
+ */
+ private String errorAppInfo;
+
+ /**
+ * Creates a YANG app error info object.
+ */
+ @SuppressWarnings("unused")
+ public YangAppErrorInfo() {
+ }
+
+ /**
+ * Returns application's error message, to be used for data error.
+ *
+ * @return Application's error message, to be used for data error
+ */
+ 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
+ */
+ public void setErrorMessage(String errMsg) {
+ errorMessage = errMsg;
+ }
+
+ /**
+ * Returns error tag, to be used for data error.
+ *
+ * @return error tag, to be used for data error
+ */
+ public String getGetErrorTag() {
+ return errorTag;
+ }
+
+ /**
+ * Sets error tag, to be used for data error.
+ *
+ * @param errTag error tag, to be used for data error
+ */
+ public void setErrorTag(String errTag) {
+ errorTag = errTag;
+ }
+
+ /**
+ * Returns application's error tag, to be used for data error.
+ *
+ * @return application's error tag, to be used for data error
+ */
+ 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
+ */
+ public void setErrorAppTag(String errTag) {
+ errorAppTag = errTag;
+ }
+
+ /**
+ * Returns application's error path, to be used for data error.
+ *
+ * @return application's error path, to be used for data error
+ */
+ public String getGetErrorAppPath() {
+ return errorAppPath;
+ }
+
+ /**
+ * Sets application's error path, to be used for data error.
+ *
+ * @param errPath application's error path, to be used for data error
+ */
+ public void setErrorAppPath(String errPath) {
+ errorAppPath = errPath;
+ }
+
+ /**
+ * Returns application's error info, to be used for data error.
+ *
+ * @return application's error info, to be used for data error
+ */
+ public String getGetErrorAppInfo() {
+ return errorAppInfo;
+ }
+
+ /**
+ * Sets application's error info, to be used for data error.
+ *
+ * @param errInfo application's error info, to be used for data error
+ */
+ public void setErrorAppInfo(String errInfo) {
+ errorAppInfo = errInfo;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAppExtended.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAppExtended.java
new file mode 100644
index 0000000..b96b4cb
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAppExtended.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+
+/**
+ * Represents data model node to maintain information defined in YANG extended name.
+ */
+public class YangAppExtended extends DefaultLocationInfo
+ implements Parsable, Serializable {
+
+ private static final long serialVersionUID = 806201602L;
+ /**
+ * App extended name information.
+ */
+ private String yangAppExtendedName;
+
+ /**
+ * Prefix of extended name.
+ */
+ private String prefix;
+
+ /**
+ * Returns the YANG app extended name information.
+ *
+ * @return the YANG app extended name information
+ */
+ public String getYangAppExtendedName() {
+ return yangAppExtendedName;
+ }
+
+ /**
+ * Sets the YANG app extended name information.
+ *
+ * @param yangAppExtendedName the YANG app extended name to set
+ */
+ public void setYangAppExtendedName(String yangAppExtendedName) {
+ this.yangAppExtendedName = yangAppExtendedName;
+ }
+
+ /**
+ * Returns the prefix.
+ *
+ * @return the prefix
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * Sets the prefix information.
+ *
+ * @param prefix the prefix to set
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.APP_EXTENDED_NAME_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO : to be implemented
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO : to be implemented
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAtomicPath.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAtomicPath.java
new file mode 100644
index 0000000..411aca3
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAtomicPath.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Representation of data model node to maintain absolute path defined in YANG path-arg.
+ */
+public class YangAtomicPath extends DefaultLocationInfo implements Serializable {
+
+ private static final long serialVersionUID = 806201688L;
+
+ // YANG node identifier.
+ private YangNodeIdentifier nodeIdentifier;
+
+ // List of path predicates expression.
+ private List<YangPathPredicate> pathPredicatesList;
+
+ /**
+ * Resolved node for the absolute path.
+ */
+ private YangNode resolvedNode;
+
+ /**
+ * Returns the node identifier.
+ *
+ * @return the node identifier
+ */
+ public YangNodeIdentifier getNodeIdentifier() {
+ return nodeIdentifier;
+ }
+
+ /**
+ * Sets the node identifier.
+ *
+ * @param nodeIdentifier Sets the node identifier
+ */
+ public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
+ this.nodeIdentifier = nodeIdentifier;
+ }
+
+ /**
+ * Returns the path predicate expression.
+ *
+ * @return the path predicate expression
+ */
+ public List<YangPathPredicate> getPathPredicatesList() {
+ return pathPredicatesList;
+ }
+
+ /**
+ * Sets the path predicate expression.
+ *
+ * @param pathPredicatesList Sets the path predicate expression
+ */
+ public void setPathPredicatesList(List<YangPathPredicate> pathPredicatesList) {
+ this.pathPredicatesList = pathPredicatesList;
+ }
+
+ /**
+ * Adds predicate expression in data holder.
+ *
+ * @param predicatesExp the predicate expression to be added
+ */
+ public void addLeavesPredicate(YangPathPredicate predicatesExp) {
+ getPathPredicatesList().add(predicatesExp);
+ }
+
+
+ /**
+ * Returns resolved node.
+ *
+ * @return resolved node
+ */
+ public YangNode getResolvedNode() {
+ return resolvedNode;
+ }
+
+ /**
+ * Sets resolved node.
+ *
+ * @param resolvedNode resolved node
+ */
+ public void setResolvedNode(YangNode resolvedNode) {
+ this.resolvedNode = resolvedNode;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAugment.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAugment.java
new file mode 100644
index 0000000..4ea139d
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAugment.java
@@ -0,0 +1,535 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.onosproject.yang.compiler.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 |-YangIfFeature |
+ * | leaf | 7.6 | 0..n |-YangLeaf |
+ * | leaf-list | 7.7 | 0..n |-YangLeafList |
+ * | list | 7.8 | 0..n |-child nodes |
+ * | reference | 7.19.4 | 0..1 |-String |
+ * | status | 7.19.2 | 0..1 |-YangStatus |
+ * | uses | 7.12 | 0..n |-child nodes |
+ * | when | 7.19.5 | 0..1 |-YangWhen |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Representation of data model node to maintain information defined in YANG
+ * augment.
+ */
+public abstract class YangAugment
+ extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable,
+ CollisionDetector, Resolvable,
+ YangXPathResolver, YangWhenHolder, YangIfFeatureHolder {
+
+ private static final long serialVersionUID = 806201602L;
+
+ /**
+ * 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<YangAtomicPath> targetNode;
+
+ /**
+ * Reference of the YANG augment.
+ */
+ private String reference;
+
+ /**
+ * Status of the node.
+ */
+ private YangStatusType status;
+
+ /**
+ * Resolved augmented node.
+ */
+ private YangNode augmentedNode;
+
+ /**
+ * 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;
+
+ /**
+ * When data of the node.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
+ * Name of augment when prefix is removed if it is in the same file. For
+ * linking purpose the name with same prefix of the file is removed and
+ * maintained.
+ */
+ private String prefixRemovedName;
+
+ /**
+ * Name of augment's setter method.
+ */
+ private String setterMethodName;
+
+ /**
+ * Create a YANG augment node.
+ */
+ public YangAugment() {
+ super(YangNodeType.AUGMENT_NODE, new HashMap<>());
+ listOfLeaf = new LinkedList<>();
+ listOfLeafList = new LinkedList<>();
+ targetNode = new LinkedList<>();
+ ifFeatureList = new LinkedList<>();
+ resolvableStatus = ResolvableStatus.UNRESOLVED;
+ }
+
+ @Override
+ public void addToChildSchemaMap(
+ YangSchemaNodeIdentifier schemaNodeIdentifier,
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+ throws DataModelException {
+ getYsnContextInfoMap()
+ .put(schemaNodeIdentifier, yangSchemaNodeContextInfo);
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo1 =
+ new YangSchemaNodeContextInfo();
+ yangSchemaNodeContextInfo1
+ .setSchemaNode(yangSchemaNodeContextInfo.getSchemaNode());
+ yangSchemaNodeContextInfo1.setContextSwitchedNode(this);
+ getAugmentedNode().addToChildSchemaMap(schemaNodeIdentifier,
+ yangSchemaNodeContextInfo1);
+ }
+
+ @Override
+ public void setNameSpaceAndAddToParentSchemaMap() {
+ // Get parent namespace and set namespace for self node.
+ setNameSpace(getParent().getNameSpace());
+ /*
+ * Check if node contains leaf/leaf-list, if yes add namespace for leaf
+ * and leaf list.
+ */
+ setLeafNameSpaceAndAddToParentSchemaMap();
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(
+ YangSchemaNodeIdentifier yangSchemaNodeIdentifier,
+ YangSchemaNode yangSchemaNode) {
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ /*
+ * Augment node to switch the name space in YMS
+ */
+ return YangSchemaNodeType.YANG_AUGMENT_NODE;
+ }
+
+ /**
+ * Returns the augmented node.
+ *
+ * @return the augmented node
+ */
+ public List<YangAtomicPath> getTargetNode() {
+ return targetNode;
+ }
+
+ /**
+ * Sets the augmented node.
+ *
+ * @param nodeIdentifiers the augmented node
+ */
+ public void setTargetNode(List<YangAtomicPath> nodeIdentifiers) {
+ targetNode = nodeIdentifiers;
+ }
+
+ /**
+ * Returns the name of augment after removing the prefix, in each atomic
+ * content, which is equal to the root prefix.
+ *
+ * @return prefix removed augment name
+ */
+ public String getPrefixRemovedName() {
+ return prefixRemovedName;
+ }
+
+ /**
+ * Sets the name of augment after removing the prefix, in each atomic
+ * content, which is equal to the root prefix.
+ *
+ * @param prefixRemovedName augment name
+ */
+ public void setPrefixRemovedName(String prefixRemovedName) {
+ this.prefixRemovedName = prefixRemovedName;
+ }
+
+ /**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @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() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+
+ /**
+ * 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);
+ }
+
+ @Override
+ public void setLeafNameSpaceAndAddToParentSchemaMap() {
+ // Add namespace for all leafs.
+ for (YangLeaf yangLeaf : getListOfLeaf()) {
+ yangLeaf.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ // Add namespace for all leaf list.
+ for (YangLeafList yangLeafList : getListOfLeafList()) {
+ yangLeafList
+ .setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ }
+
+ /**
+ * 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 augmented node.
+ *
+ * @return augmented node
+ */
+ public YangNode getAugmentedNode() {
+ return augmentedNode;
+ }
+
+ /**
+ * Sets augmented node.
+ *
+ * @param augmentedNode augmented node
+ */
+ public void setAugmentedNode(YangNode augmentedNode) {
+ this.augmentedNode = augmentedNode;
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ @Override
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+
+ }
+
+ @Override
+ public Object resolve()
+ throws DataModelException {
+ // Resolving of target node is being done in XPathLinker.
+ return null;
+ }
+
+ /**
+ * Returns setter method name for augment in application.
+ *
+ * @return setter method name for augment in application
+ */
+ public String getSetterMethodName() {
+ return setterMethodName;
+ }
+
+ /**
+ * Sets setter method name for augment in application.
+ *
+ * @param name setter method name for augment in application
+ */
+ public void setSetterMethodName(String name) {
+ setterMethodName = name;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAugmentableNode.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAugmentableNode.java
new file mode 100644
index 0000000..5d24723
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangAugmentableNode.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.yang.compiler.datamodel;
+
+import java.util.List;
+
+/**
+ * Represents YANG constructs which can be augmented.
+ */
+public interface YangAugmentableNode {
+
+ /**
+ * Adds augment info to the augment info list.
+ *
+ * @param augmentInfo augment info of node
+ */
+ void addAugmentation(YangAugment augmentInfo);
+
+ /**
+ * Removes augment info from the node.
+ *
+ * @param augmentInfo augment info of node
+ */
+ void removeAugmentation(YangAugment augmentInfo);
+
+ /**
+ * Returns list of augment info.
+ *
+ * @return list of augment info
+ */
+ List<YangAugment> getAugmentedInfoList();
+
+ /**
+ * Clones augment info.
+ */
+ void cloneAugmentInfo();
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBase.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBase.java
new file mode 100644
index 0000000..a0194bb
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBase.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
+
+import java.io.Serializable;
+
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.UNRESOLVED;
+
+/**
+ * Reference RFC 6020.
+ * <p>
+ * Represents data model node to maintain information defined in YANG base.
+ * The "base" statement, which is optional, takes as an argument a
+ * string that is the name of an existing identity, from which the new
+ * identity is derived. If no "base" statement is present, the identity
+ * is defined from scratch.
+ * <p>
+ * If a prefix is present on the base name, it refers to an identity
+ * defined in the module that was imported with that prefix, or the
+ * local module if the prefix matches the local module's prefix.
+ * Otherwise, an identity with the matching name MUST be defined in the
+ * current module or an included submodule.
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG base.
+ */
+public class YangBase extends DefaultLocationInfo implements Resolvable, Serializable {
+
+ private static final long serialVersionUID = 806201693L;
+
+ // YANG node identifier.
+ private YangNodeIdentifier baseIdentifier;
+
+ // Referred identity parent information.
+ private YangIdentity referredIdentity;
+
+ /**
+ * Status of resolution. If completely resolved enum value is "RESOLVED",
+ * if not enum value is "UNRESOLVED", in case reference of grouping/typedef/base/identityref
+ * is added to uses/type/base/identityref but it's not resolved value of enum should be
+ * "INTRA_FILE_RESOLVED".
+ */
+ private ResolvableStatus resolvableStatus;
+
+ // Creates a base type of node.
+ public YangBase() {
+ resolvableStatus = UNRESOLVED;
+ }
+
+ /**
+ * Returns the YANG node identifier.
+ *
+ * @return the YANG node identifier
+ */
+ public YangNodeIdentifier getBaseIdentifier() {
+ return baseIdentifier;
+ }
+
+ /**
+ * Sets the YANG node identifier.
+ *
+ * @param baseIdentifier the YANG node identifier to set
+ */
+ public void setBaseIdentifier(YangNodeIdentifier baseIdentifier) {
+ this.baseIdentifier = baseIdentifier;
+ }
+
+ /**
+ * Returns the parent identity node.
+ *
+ * @return the parent identity node
+ */
+ public YangIdentity getReferredIdentity() {
+ return referredIdentity;
+ }
+
+ /**
+ * Sets the parent identity node.
+ *
+ * @param referredIdentity the parent identity node to set
+ */
+ public void setReferredIdentity(YangIdentity referredIdentity) {
+ this.referredIdentity = referredIdentity;
+ }
+
+ @Override
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ @Override
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+ }
+
+ @Override
+ public Object resolve() throws DataModelException {
+ return null;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBelongsTo.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBelongsTo.java
new file mode 100644
index 0000000..74b6338
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBelongsTo.java
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.Set;
+
+import static org.onosproject.yang.compiler.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 extends DefaultLocationInfo implements Parsable, Serializable {
+
+ private static final long serialVersionUID = 806201639L;
+
+ /**
+ * Reference RFC 6020.
+ * <p>
+ * 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.
+ * <p>
+ * 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;
+
+ /**
+ * 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
+ }
+
+ /**
+ * 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. " + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName());
+ exception.setLine(getLineNumber());
+ exception.setCharPosition(getCharPosition());
+ throw exception;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBinary.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBinary.java
new file mode 100644
index 0000000..22f6e82
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBinary.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
+
+import java.io.Serializable;
+import java.util.Base64;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The binary built-in type represents any binary data,
+ * i.e., a sequence of octets.
+ */
+public class YangBinary extends DefaultLocationInfo implements YangBuiltInDataTypeInfo<YangBinary>,
+ Serializable, Comparable<YangBinary> {
+
+ private static final long serialVersionUID = 2106201608L;
+
+ // Binary data is a decoded value by base64 decoding scheme from data input (jason)
+ private byte[] binaryData;
+
+ /**
+ * Creates a binary object corresponding to the base 64 encoding value.
+ *
+ * @param strValue base64 encoded value
+ */
+ public YangBinary(String strValue) {
+ setBinaryData(Base64.getDecoder().decode(strValue));
+ }
+
+ /**
+ * Retrieves decoded binary data.
+ *
+ * @return binary data
+ */
+ public byte[] getBinaryData() {
+ return binaryData;
+ }
+
+ /**
+ * Sets binary data.
+ *
+ * @param binaryData binary data
+ */
+ public void setBinaryData(byte[] binaryData) {
+ this.binaryData = binaryData;
+ }
+
+ /**
+ * Encodes binary data by base64 encoding scheme.
+ *
+ * @return encoded binary data
+ */
+ public String toString() {
+ return Base64.getEncoder()
+ .encodeToString(binaryData);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.BINARY;
+ }
+
+ @Override
+ public int compareTo(YangBinary o) {
+ for (int i = 0, j = 0; i < this.binaryData.length && j < o.binaryData.length; i++, j++) {
+ int a = (this.binaryData[i] & 0xff);
+ int b = (o.binaryData[j] & 0xff);
+ if (a != b) {
+ return a - b;
+ }
+ }
+ return this.binaryData.length - o.binaryData.length;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBit.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBit.java
new file mode 100644
index 0000000..8482905
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/*-
+ * 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 extends DefaultLocationInfo 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBits.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBits.java
new file mode 100644
index 0000000..fd97e38
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangBits.java
@@ -0,0 +1,260 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.BitSet;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+/*
+ * 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 extends DefaultLocationInfo implements Parsable, Serializable {
+
+ private static final long serialVersionUID = 806201641L;
+ private static final String SPACE = " ";
+
+ // Bits name
+ private String bitsName;
+ // Bits data contains bit-positions will be used to send to ONOS application
+ private BitSet bitDataSet;
+ /**
+ * Mapping bit name to YangBit. In data input (jason), only bit name will be received.
+ * By using the bit name corresponding (yang) bit-position will be retrieved from bitNameMap map.
+ */
+ private Map<String, YangBit> bitNameMap;
+ /**
+ * Mapping bit position to YangBit. The bit-position received from ONOS application
+ * will be converted into bit-name by using bitPositionMap map to send (jason) output data as response.
+ */
+ private Map<Integer, YangBit> bitPositionMap;
+
+ /**
+ * Creates a YANG bits type object.
+ */
+ public YangBits() {
+ bitDataSet = new BitSet();
+ setBitNameMap(new HashMap<>());
+ setBitPositionMap(new HashMap<>());
+ }
+
+ /**
+ * Returns the bits name.
+ *
+ * @return the bits name
+ */
+ public String getBitsName() {
+ return bitsName;
+ }
+
+ /**
+ * Sets the bits name.
+ *
+ * @param bitsName the bits name
+ */
+ public void setBitsName(String bitsName) {
+ this.bitsName = bitsName;
+ }
+
+ /**
+ * Returns the bit data set.
+ *
+ * @return the bit data set
+ */
+ public BitSet getBitDataSet() {
+ return bitDataSet;
+ }
+
+ /**
+ * Sets the bit data set.
+ *
+ * @param bitNames the set of bit names
+ * @throws DataModelException due to violation in data model rules
+ */
+ public void setBitDataSet(String[] bitNames) throws DataModelException {
+ YangBit bit;
+ for (String bitName : bitNames) {
+ bit = bitNameMap.get(bitName);
+ if (bit == null) {
+ throw new DataModelException("YANG file error: Unable to find " +
+ "corresponding bit position for bit name: " + bitName +
+ " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName());
+ }
+ bitDataSet.set(bit.getPosition());
+ }
+ }
+
+ /**
+ * Returns the bit name map.
+ *
+ * @return the bit name map
+ */
+ public Map<String, YangBit> getBitNameMap() {
+ return bitNameMap;
+ }
+
+ /**
+ * Sets the bit name map.
+ *
+ * @param bitNameMap the bit name map
+ */
+ public void setBitNameMap(Map<String, YangBit> bitNameMap) {
+ this.bitNameMap = bitNameMap;
+ }
+
+ /**
+ * Checks whether bit name already available.
+ *
+ * @param bitName bit name
+ * @return true if bit name already available otherwise returns false
+ */
+ public boolean isBitNameExists(String bitName) {
+ return bitNameMap.containsKey(bitName);
+ }
+
+ /**
+ * Returns the bit position map.
+ *
+ * @return the bit position map
+ */
+ public Map<Integer, YangBit> getBitPositionMap() {
+ return bitPositionMap;
+ }
+
+ /**
+ * Sets the bit position map.
+ *
+ * @param bitPositionMap the bit position map
+ */
+ public void setBitPositionMap(Map<Integer, YangBit> bitPositionMap) {
+ this.bitPositionMap = bitPositionMap;
+ }
+
+ /**
+ * Checks whether bit position already available.
+ *
+ * @param bitPosition bit position
+ * @return true if bit position already available otherwise returns false
+ */
+ public boolean isBitPositionExists(Integer bitPosition) {
+ return bitPositionMap.containsKey(bitPosition);
+ }
+
+ /**
+ * 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 (bitNameMap.put(bitInfo.getBitName(), bitInfo) != null) {
+ throw new DataModelException("YANG file error: Duplicate bit name detected, same as bit name \""
+ + bitInfo.getBitName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ if (bitPositionMap.put(bitInfo.getPosition(), bitInfo) != null) {
+ throw new DataModelException("YANG file error: Duplicate bit position detected, same as bit position \""
+ + bitInfo.getPosition() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+
+ /**
+ * Returns the type of the data.
+ *
+ * @return ParsedDataType returns BITS_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.BITS_DATA;
+ }
+
+ @Override
+ public String toString() {
+ YangBit bit;
+ String bits = new String();
+ for (int i = bitDataSet.nextSetBit(0); i >= 0; i = bitDataSet.nextSetBit(i + 1)) {
+ bit = bitPositionMap.get(i);
+ if (bit == null) {
+ return null;
+ }
+ if (bits.isEmpty()) {
+ bits = bit.getBitName();
+ } else {
+ bits += " " + bit.getBitName();
+ }
+ }
+ return bits.trim();
+ }
+
+ /**
+ * Returns the object of YANG bits based on specific set of bit names.
+ *
+ * @param bits set of bit names
+ * @return Object of YANG bits
+ */
+ public YangBits fromString(String bits) {
+ try {
+ String[] bitNames = bits.trim().split(Pattern.quote(SPACE));
+ setBitDataSet(bitNames);
+ return this;
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+ /**
+ * 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangCase.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangCase.java
new file mode 100644
index 0000000..8c1f491
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangCase.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.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.CASE_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_NON_DATA_NODE;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.CASE;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.INVALID_CASE_HOLDER;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsg;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yang.compiler.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 |-YangIfFeature |
+ * | leaf | 7.6 | 0..n |-YangLeaf |
+ * | leaf-list | 7.7 | 0..n |-YangLeafList |
+ * | list | 7.8 | 0..n |-child nodes |
+ * | reference | 7.19.4 | 0..1 |-string |
+ * | status | 7.19.2 | 0..1 |-YangStatus |
+ * | uses | 7.12 | 0..n |-child node |
+ * | when | 7.19.5 | 0..1 |-YangWhen |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG case.
+ */
+public abstract class YangCase
+ extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
+ YangAugmentableNode, YangWhenHolder, YangIfFeatureHolder, YangIsFilterContentNodes {
+
+ private static final long serialVersionUID = 806201603L;
+
+ /**
+ * 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;
+
+ /**
+ * When data of the node.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ private List<YangAugment> yangAugmentedInfo;
+
+ /**
+ * Creates a choice node.
+ */
+ public YangCase() {
+ super(CASE_NODE, new HashMap<>());
+ listOfLeaf = new LinkedList<>();
+ listOfLeafList = new LinkedList<>();
+ ifFeatureList = new LinkedList<>();
+ yangAugmentedInfo = new ArrayList<>();
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo context)
+ throws DataModelException {
+ getYsnContextInfoMap().put(id, context);
+ YangSchemaNodeContextInfo contextInfo = new YangSchemaNodeContextInfo();
+ contextInfo.setSchemaNode(context.getSchemaNode());
+ contextInfo.setContextSwitchedNode(this);
+ getParent().addToChildSchemaMap(id, contextInfo);
+ }
+
+ @Override
+ public void setNameSpaceAndAddToParentSchemaMap() {
+ // Get parent namespace and set namespace for self node.
+ setNameSpace(getParent().getNameSpace());
+ /*
+ * Check if node contains leaf/leaf-list, if yes add namespace for leaf
+ * and leaf list.
+ */
+ setLeafNameSpaceAndAddToParentSchemaMap();
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ //For non data nodes, mandatory child to be added to parent node.
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier id,
+ YangSchemaNode node) {
+ //For non data nodes, default child to be added to parent node.
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_NON_DATA_NODE;
+ }
+
+ /**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @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 unmodifiableList(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) {
+ listOfLeaf.add(leaf);
+ }
+
+ /**
+ * Returns the list of leaf-list.
+ *
+ * @return the list of leaf-list
+ */
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return unmodifiableList(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) {
+ listOfLeafList.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 ||
+ getParent() instanceof YangAugment)) {
+ throw new DataModelException(getErrorMsg(
+ INVALID_CASE_HOLDER, getName(), getLineNumber(),
+ getCharPosition(), getFileName()));
+ }
+ // 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(getErrorMsgCollision(
+ COLLISION_DETECTION, getName(), getLineNumber(),
+ getCharPosition(), CASE, getFileName()));
+ }
+ return;
+ }
+
+ // Asks helper to detect colliding child.
+ detectCollidingChildUtil(identifierName, dataType, this);
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return unmodifiableList(ifFeatureList);
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ ifFeatureList.add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
+ public void addAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.add(augmentInfo);
+ }
+
+ @Override
+ public void removeAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.remove(augmentInfo);
+ }
+
+ @Override
+ public List<YangAugment> getAugmentedInfoList() {
+ return unmodifiableList(yangAugmentedInfo);
+ }
+
+ @Override
+ public void setLeafNameSpaceAndAddToParentSchemaMap() {
+ // Add namespace for all leafs.
+ for (YangLeaf yangLeaf : listOfLeaf) {
+ yangLeaf.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ // Add namespace for all leaf list.
+ for (YangLeafList yangLeafList : listOfLeafList) {
+ yangLeafList.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ }
+
+
+ public void cloneAugmentInfo() {
+ yangAugmentedInfo = new ArrayList<>();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangChoice.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangChoice.java
new file mode 100644
index 0000000..8e54d48
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangChoice.java
@@ -0,0 +1,493 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.CHOICE_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_CHOICE_NODE;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.CHOICE;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.CASE_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.CHOICE_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.YangErrMsgConstants.DATA_MISSING_ERROR_TAG;
+import static org.onosproject.yang.compiler.datamodel.utils.YangErrMsgConstants.ERROR_PATH_MISSING_CHOICE;
+import static org.onosproject.yang.compiler.datamodel.utils.YangErrMsgConstants.MISSING_CHOICE_ERROR_APP_TAG;
+
+/*-
+ * 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 |-YangIfFeature |
+ * | leaf | 7.6 | 0..n |-child case nodes |
+ * | leaf-list | 7.7 | 0..n |-child case nodes |
+ * | list | 7.8 | 0..n |-child case nodes |
+ * | mandatory | 7.9.4 | 0..1 |-string |
+ * | reference | 7.19.4 | 0..1 |-string |
+ * | status | 7.19.2 | 0..1 |-string |
+ * | when | 7.19.5 | 0..1 |-YangWhen |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG choice.
+ */
+public abstract class YangChoice
+ extends YangNode
+ implements YangCommonInfo, Parsable, CollisionDetector,
+ YangAugmentableNode, YangWhenHolder, YangIfFeatureHolder,
+ YangAppErrorHolder, YangIsFilterContentNodes, YangConfig {
+
+ private static final long serialVersionUID = 806201604L;
+
+ /**
+ * If the choice represents config data.
+ */
+ private boolean isConfig;
+
+ /**
+ * Description of choice.
+ */
+ private String description;
+
+ /**
+ * Reference RFC 6020.
+ * <p>
+ * 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.
+ * <p>
+ * If not specified, the default is "false".
+ * <p>
+ * 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:
+ * <p>
+ * o If this ancestor is a case node, the constraint is enforced if any
+ * other node from the case exists.
+ * <p>
+ * 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;
+
+ /**
+ * Reference RFC 6020.
+ * <p>
+ * 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.
+ * <p>
+ * The "default" statement MUST NOT be present on choices where "mandatory"
+ * is true.
+ * <p>
+ * 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.
+ * <p>
+ * There MUST NOT be any mandatory nodes directly under the default case.
+ * <p>
+ * 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.
+ * <p>
+ * the default case to be used if no case members is present.
+ */
+ private String defaultValueInString;
+
+ /**
+ * When data of the node.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ private List<YangAugment> yangAugmentedInfo;
+
+ /**
+ * YANG application error information.
+ */
+ private YangAppErrorInfo yangAppErrorInfo;
+
+ /**
+ * Create a choice node.
+ */
+ public YangChoice() {
+ super(CHOICE_NODE, new HashMap<>());
+ yangAppErrorInfo = new YangAppErrorInfo();
+ ifFeatureList = new LinkedList<>();
+ yangAugmentedInfo = new ArrayList<>();
+ yangAppErrorInfo.setErrorTag(DATA_MISSING_ERROR_TAG);
+ yangAppErrorInfo.setErrorAppTag(MISSING_CHOICE_ERROR_APP_TAG);
+ yangAppErrorInfo.setErrorAppPath(ERROR_PATH_MISSING_CHOICE);
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo context)
+ throws DataModelException {
+ getYsnContextInfoMap().put(id, context);
+ YangSchemaNodeContextInfo contextInfo =
+ new YangSchemaNodeContextInfo();
+ contextInfo.setSchemaNode(context.getSchemaNode());
+ contextInfo.setContextSwitchedNode(this);
+ getParent().addToChildSchemaMap(id, contextInfo);
+ }
+
+ @Override
+ public void setNameSpaceAndAddToParentSchemaMap() {
+ // Get parent namespace and set namespace for self node.
+ setNameSpace(getParent().getNameSpace());
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ //For non data nodes, mandatory child to be added to parent node.
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(
+ YangSchemaNodeIdentifier yangSchemaNodeIdentifier,
+ YangSchemaNode yangSchemaNode) {
+ //For non data nodes, default child to be added to parent node.
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ /*Choice node to be skipped in YANG data tree preparation*/
+ return YANG_CHOICE_NODE;
+ }
+
+ /**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
+ * Returns config flag.
+ *
+ * @return the config flag
+ */
+ @Override
+ public boolean isConfig() {
+ return isConfig;
+ }
+
+ /**
+ * Sets config flag.
+ *
+ * @param isConfig the config flag
+ */
+ @Override
+ public void setConfig(boolean isConfig) {
+ this.isConfig = isConfig;
+ }
+
+ /**
+ * 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 {
+ if (defaultValueInString != null && !defaultValueInString.isEmpty()) {
+ YangNode node = getChild();
+ boolean matched = false;
+ // Check whether default string matches the case
+ while (node != null) {
+ if (node instanceof YangCase) {
+ if (defaultValueInString.equals(node.getName())) {
+ matched = true;
+ break;
+ }
+ }
+ node = node.getNextSibling();
+ }
+
+ if (!matched) {
+ throw new DataModelException(
+ "YANG file error: default string \"" +
+ defaultValueInString + "\" not matching choice \"" +
+ getName() + "\" case.");
+ }
+ }
+ }
+
+ @Override
+ public void detectCollidingChild(String idName, YangConstructType type)
+ throws DataModelException {
+
+ if (getParent() instanceof YangCase && type != CASE_DATA) {
+ ((CollisionDetector) getParent()).detectCollidingChild(idName, type);
+ }
+ YangNode node = getChild();
+ while (node != null) {
+ if (node instanceof CollisionDetector) {
+ ((CollisionDetector) node).detectSelfCollision(idName, type);
+ }
+ node = node.getNextSibling();
+ }
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName,
+ YangConstructType dataType)
+ throws DataModelException {
+
+ if (dataType == CHOICE_DATA) {
+ if (getName().equals(identifierName)) {
+ throw new DataModelException(
+ getErrorMsgCollision(COLLISION_DETECTION, getName(),
+ getLineNumber(), getCharPosition(),
+ CHOICE, getFileName()));
+ }
+ return;
+ }
+
+ YangNode node = getChild();
+ while (node != null) {
+ if (node instanceof CollisionDetector) {
+ ((CollisionDetector) node)
+ .detectSelfCollision(identifierName, dataType);
+ }
+ node = node.getNextSibling();
+ }
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return unmodifiableList(ifFeatureList);
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ ifFeatureList.add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
+ public void addAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.add(augmentInfo);
+ }
+
+ @Override
+ public void removeAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.remove(augmentInfo);
+ }
+
+ @Override
+ public List<YangAugment> getAugmentedInfoList() {
+ return unmodifiableList(yangAugmentedInfo);
+ }
+
+ @Override
+ public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
+ this.yangAppErrorInfo = yangAppErrorInfo;
+ }
+
+ @Override
+ public YangAppErrorInfo getAppErrorInfo() {
+ return yangAppErrorInfo;
+ }
+
+ public void cloneAugmentInfo() {
+ yangAugmentedInfo = new ArrayList<>();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangCommonInfo.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangCommonInfo.java
new file mode 100644
index 0000000..82872f0
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangCompilerAnnotation.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangCompilerAnnotation.java
new file mode 100644
index 0000000..f106689
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangCompilerAnnotation.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.COMPILER_ANNOTATION_DATA;
+
+/**
+ * Represents data model node to maintain information defined in YANG compiler-annotation.
+ */
+public class YangCompilerAnnotation extends DefaultLocationInfo
+ implements Parsable, YangXPathResolver, Resolvable, Serializable {
+
+ private static final long serialVersionUID = 806201602L;
+
+ /**
+ * App data structure information.
+ */
+ private YangAppDataStructure yangAppDataStructure;
+
+ /**
+ * App extended name information.
+ */
+ private YangAppExtended yangAppExtended;
+
+ /**
+ * Prefix of compiler-annotation.
+ */
+ private String prefix;
+
+ /**
+ * Path of compiler-annotation.
+ */
+ private String path;
+
+ /**
+ * Path of compiler-annotation.
+ */
+ private List<YangAtomicPath> atomicPathList = new LinkedList<>();
+
+ /**
+ * Resolution status.
+ */
+ private ResolvableStatus resolvableStatus;
+
+ /**
+ * Returns the YANG app data structure information.
+ *
+ * @return the YANG app data structure information
+ */
+ public YangAppDataStructure getYangAppDataStructure() {
+ return yangAppDataStructure;
+ }
+
+ /**
+ * Sets the YANG app data structure information.
+ *
+ * @param yangAppDataStructure the YANG app data structure to set
+ */
+ public void setYangAppDataStructure(YangAppDataStructure yangAppDataStructure) {
+ this.yangAppDataStructure = yangAppDataStructure;
+ }
+
+ /**
+ * Returns the prefix.
+ *
+ * @return the prefix
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * Sets the prefix information.
+ *
+ * @param prefix the prefix to set
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ /**
+ * Returns the path.
+ *
+ * @return the path
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * Sets the path.
+ *
+ * @param path the path to set
+ */
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ /**
+ * Returns the YANG app extended name information.
+ *
+ * @return the YANG app extended name information
+ */
+ public YangAppExtended getYangAppExtendedName() {
+ return yangAppExtended;
+ }
+
+ /**
+ * Sets the YANG app extended name information.
+ *
+ * @param yangAppExtendedName the YANG app extended name to set
+ */
+ public void setYangAppExtendedName(YangAppExtended yangAppExtendedName) {
+ yangAppExtended = yangAppExtendedName;
+ }
+
+ /**
+ * Returns the list of atomic path.
+ *
+ * @return the list of atomic path
+ */
+ public List<YangAtomicPath> getAtomicPathList() {
+ return unmodifiableList(atomicPathList);
+ }
+
+ /**
+ * Sets the atomic path.
+ *
+ * @param atomicPathList the atomic path list to set
+ */
+ public void setAtomicPathList(List<YangAtomicPath> atomicPathList) {
+ this.atomicPathList = atomicPathList;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return COMPILER_ANNOTATION_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO : to be implemented
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO : to be implemented
+ }
+
+ @Override
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ @Override
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+ }
+
+ @Override
+ public Object resolve()
+ throws DataModelException {
+ return null;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangConfig.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangConfig.java
new file mode 100644
index 0000000..3659396
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangConfig.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Abstraction of config entity. It is used to abstract the data holders of config statement.
+ */
+public interface YangConfig {
+
+ /**
+ * Returns the config flag.
+ *
+ * @return if config flag
+ */
+ boolean isConfig();
+
+ /**
+ * Sets the config flag.
+ *
+ * @param isConfig the flag value to set
+ */
+ void setConfig(boolean isConfig);
+
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangContainer.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangContainer.java
new file mode 100644
index 0000000..04d99a4
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangContainer.java
@@ -0,0 +1,523 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.onosproject.yang.compiler.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 | -YangIfFeature |
+ * | leaf | 7.6 | 0..n | -YangLeaf |
+ * | leaf-list | 7.7 | 0..n | -YangLeafList |
+ * | list | 7.8 | 0..n | -child nodes |
+ * | must | 7.5.3 | 0..n | -YangMust |
+ * | presence | 7.5.5 | 0..1 | -boolean |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * | typedef | 7.3 | 0..n | -child nodes |
+ * | uses | 7.12 | 0..n | -child nodes |
+ * | when | 7.19.5 | 0..1 | -YangWhen |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG container.
+ */
+public abstract class YangContainer
+ extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
+ YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangIsFilterContentNodes,
+ YangConfig {
+
+ private static final long serialVersionUID = 806201605L;
+
+ /**
+ * 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;
+
+ private List<YangAugment> yangAugmentedInfo = new ArrayList<>();
+
+ /**
+ * Status of the node.
+ */
+ private YangStatusType status = YangStatusType.CURRENT;
+
+ /**
+ * List of must statement constraints.
+ */
+ private List<YangMust> mustConstraintList;
+
+ /**
+ * When data of the node.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
+ * Create a container node.
+ */
+ public YangContainer() {
+ super(YangNodeType.CONTAINER_NODE, new HashMap<>());
+ listOfLeaf = new LinkedList<>();
+ listOfLeafList = new LinkedList<>();
+ mustConstraintList = new LinkedList<>();
+ ifFeatureList = new LinkedList<>();
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier schemaNodeIdentifier,
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo) {
+ getYsnContextInfoMap().put(schemaNodeIdentifier, yangSchemaNodeContextInfo);
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier, YangSchemaNode yangSchemaNode) {
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YangSchemaNodeType.YANG_SINGLE_INSTANCE_NODE;
+ }
+
+ /**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
+ * Returns the config flag.
+ *
+ * @return the isConfig
+ */
+ @Override
+ public boolean isConfig() {
+ return isConfig;
+ }
+
+ /**
+ * Sets the config flag.
+ *
+ * @param isConfig the config flag
+ */
+ @Override
+ public void setConfig(boolean isConfig) {
+ this.isConfig = isConfig;
+ }
+
+ /**
+ * 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 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();
+ validateConfig(leaves, leafLists);
+ }
+
+ /**
+ * 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\"." + getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+ }
+
+ 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\"." +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+ }
+ }
+
+ @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() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
+ public List<YangMust> getListOfMust() {
+ return mustConstraintList;
+ }
+
+ @Override
+ public void setListOfMust(List<YangMust> mustConstraintList) {
+ this.mustConstraintList = mustConstraintList;
+ }
+
+ @Override
+ public void addMust(YangMust must) {
+ if (getListOfMust() == null) {
+ setListOfMust(new LinkedList<>());
+ }
+ getListOfMust().add(must);
+ }
+
+ @Override
+ public void addAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.add(augmentInfo);
+ }
+
+ @Override
+ public void removeAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.remove(augmentInfo);
+ }
+
+ @Override
+ public List<YangAugment> getAugmentedInfoList() {
+ return yangAugmentedInfo;
+ }
+
+ @Override
+ public void setLeafNameSpaceAndAddToParentSchemaMap() {
+ // Add namespace for all leafs.
+ for (YangLeaf yangLeaf : getListOfLeaf()) {
+ yangLeaf.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ // Add namespace for all leaf list.
+ for (YangLeafList yangLeafList : getListOfLeafList()) {
+ yangLeafList.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ }
+
+ public void cloneAugmentInfo() {
+ yangAugmentedInfo = new ArrayList<>();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDataStructure.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDataStructure.java
new file mode 100644
index 0000000..0896a48
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDataStructure.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Represents ENUM to identify the YANG data type.
+ */
+public enum YangDataStructure {
+
+ QUEUE,
+
+ LIST,
+
+ MAP,
+
+ SET;
+
+ /**
+ * Returns YANG data structure type for corresponding data structure name.
+ *
+ * @param name data structure name from YANG file.
+ * @return YANG data structure for corresponding data structure name.
+ */
+ public static YangDataStructure getDataStructureType(String name) {
+ name = name.replace("\"", "");
+ for (YangDataStructure dataStructure : values()) {
+ if (dataStructure.name().toLowerCase().equals(name.toLowerCase())) {
+ return dataStructure;
+ }
+ }
+ return null;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDecimal64.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDecimal64.java
new file mode 100644
index 0000000..56ae4f3
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDecimal64.java
@@ -0,0 +1,360 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.FractionDigits;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.DataTypeException;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.ListIterator;
+
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsg;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.DECIMAL64_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
+
+/**
+ * Represents YANG decimal 64.
+ */
+public class YangDecimal64<T> extends DefaultLocationInfo
+ implements YangBuiltInDataTypeInfo<YangDecimal64>, Parsable, Serializable,
+ Comparable<YangDecimal64> {
+
+ private static final long serialVersionUID = 8006201668L;
+
+ /**
+ * 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 fraction-digits.
+ */
+ public static final int MIN_FRACTION_DIGITS_VALUE = 1;
+
+ /**
+ * Valid maximum value of YANG's fraction-digits.
+ */
+ public static final int MAX_FRACTION_DIGITS_VALUE = 18;
+
+ /**
+ * Valid minimum value of YANG's decimal64.
+ */
+ private static final BigDecimal MIN_VALUE =
+ BigDecimal.valueOf(-922337203685477580.8);
+
+ /**
+ * Valid maximum value of YANG's decimal64.
+ */
+ private static final BigDecimal MAX_VALUE =
+ BigDecimal.valueOf(922337203685477580.7);
+
+ private static final int MIN_FRACTION_DIGIT_RANGE = 1;
+ private static final int MAX_FRACTION_DIGIT_RANGE = 18;
+ private static final int ZERO = 0;
+
+
+ // Decimal64 value
+ private BigDecimal value;
+
+ // fraction-digits
+ private int fractionDigit;
+
+ /**
+ * Additional information about range restriction.
+ */
+ private T rangeRestrictedExtendedInfo;
+
+ /**
+ * Creates an instance of YANG decimal64.
+ */
+ public YangDecimal64() {
+ }
+
+ /**
+ * Creates an instance of YANG decimal64.
+ *
+ * @param value of decimal64
+ */
+ public YangDecimal64(BigDecimal value) {
+ setValue(value);
+ }
+
+ /**
+ * Creates an instance of YANG decimal64.
+ *
+ * @param valueInString of decimal64 in string
+ */
+ YangDecimal64(String valueInString) {
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = new BigDecimal(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException(
+ "YANG file error : Input value \"" + valueInString + "\"" +
+ " is not a valid decimal64.");
+ }
+ }
+
+ if (value.doubleValue() < MIN_VALUE.doubleValue()) {
+ throw new DataTypeException("YANG file error : " + valueInString +
+ " is less than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value.doubleValue() > MAX_VALUE.doubleValue()) {
+ throw new DataTypeException("YANG file error : " + valueInString +
+ " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns decimal64 value.
+ *
+ * @return value
+ */
+ public BigDecimal getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the decimal64 value.
+ *
+ * @param value of decimal64
+ */
+ public void setValue(BigDecimal value) {
+ this.value = value;
+ }
+
+ /**
+ * 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 additional information about range restriction.
+ *
+ * @return resolved range restricted extended information
+ */
+ public T getRangeRestrictedExtendedInfo() {
+ return rangeRestrictedExtendedInfo;
+ }
+
+ /**
+ * Sets additional information about range restriction.
+ *
+ * @param resolvedExtendedInfo resolved range restricted extended information
+ */
+ public void setRangeRestrictedExtendedInfo(T resolvedExtendedInfo) {
+ rangeRestrictedExtendedInfo = resolvedExtendedInfo;
+ }
+
+ /**
+ * Returns object of YANG decimal64.
+ *
+ * @param value of decimal64
+ * @return YANG decimal64 object
+ */
+ public static YangDecimal64 of(BigDecimal value) {
+ return new YangDecimal64(value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return DECIMAL64;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return DECIMAL64_DATA;
+ }
+
+ @Override
+ public String toString() {
+ return value.toString();
+ }
+
+ /**
+ * Returns the object of YANG decimal64 from input string.
+ *
+ * @param valInString input String
+ * @return Object of YANG decimal64
+ */
+ static YangDecimal64 fromString(String valInString) {
+ return new YangDecimal64(valInString);
+ }
+
+ /**
+ * Checks whether specific fraction-digit in its range.
+ *
+ * @return true if fraction-digit is in its range otherwise false
+ */
+ public boolean isValidFractionDigit() {
+ return fractionDigit >= MIN_FRACTION_DIGIT_RANGE &&
+ fractionDigit <= MAX_FRACTION_DIGIT_RANGE;
+ }
+
+
+ /**
+ * Checks whether value is in correct decimal64 value range.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ public void validateDecimal64() throws DataModelException {
+ YangRangeRestriction rangeRestriction =
+ (YangRangeRestriction) getRangeRestrictedExtendedInfo();
+ if (rangeRestriction != null) {
+ // Check whether value is within provided range value
+ ListIterator<YangRangeInterval> rangeListIterator =
+ rangeRestriction.getAscendingRangeIntervals().listIterator();
+
+ boolean isMatched = false;
+ while (rangeListIterator.hasNext()) {
+ YangRangeInterval rangeInterval = rangeListIterator.next();
+ rangeInterval.setCharPosition(getCharPosition());
+ rangeInterval.setLineNumber(getLineNumber());
+ rangeInterval.setFileName(getFileName());
+ BigDecimal startValue = ((YangDecimal64) rangeInterval.getStartValue()).getValue();
+ BigDecimal endValue = ((YangDecimal64) rangeInterval.getEndValue()).getValue();
+ if (value.compareTo(startValue) >= ZERO &&
+ value.compareTo(endValue) <= ZERO) {
+ isMatched = true;
+ break;
+ }
+ }
+ // If range is not matched then throw error
+ if (!isMatched) {
+ throw new DataModelException(getErrorMsg(
+ "YANG file error : decimal64 validation failed.", "decimal64",
+ getLineNumber(), getCharPosition(), getFileName() + "\""));
+ }
+ } else {
+ // Check value is in fraction-digits decimal64 value range
+ if (!FractionDigits.isValueInDecimal64Range(value, getFractionDigit())) {
+ throw new DataModelException(
+ "YANG file error : value is not in decimal64 range.");
+ }
+ }
+ }
+
+ /**
+ * Validate range restriction values based on fraction-digits decimal64 range value.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ public void validateRange() throws DataModelException {
+ YangRangeRestriction rangeRestriction =
+ (YangRangeRestriction) getRangeRestrictedExtendedInfo();
+ if (rangeRestriction == null) {
+ // No need to validate. Range is optional.
+ return;
+ }
+ ListIterator<YangRangeInterval> rangeListIterator =
+ rangeRestriction.getAscendingRangeIntervals().listIterator();
+ while (rangeListIterator.hasNext()) {
+ YangRangeInterval rangeInterval = rangeListIterator.next();
+ rangeInterval.setCharPosition(getCharPosition());
+ rangeInterval.setLineNumber(getLineNumber());
+ rangeInterval.setFileName(getFileName());
+ if (!FractionDigits.isValueInDecimal64Range(
+ ((YangDecimal64) rangeInterval.getStartValue()).getValue(),
+ getFractionDigit())) {
+ throw new DataModelException(getErrorMsg(
+ "YANG file error : decimal64 validation failed.", "decimal64",
+ getLineNumber(), getCharPosition(), getFileName() + "\""));
+ }
+ if (!FractionDigits.isValueInDecimal64Range(
+ ((YangDecimal64) rangeInterval.getEndValue()).getValue(),
+ getFractionDigit())) {
+ throw new DataModelException(getErrorMsg(
+ "YANG file error : decimal64 validation failed.", "decimal64",
+ getLineNumber(), getCharPosition(), getFileName() + "\""));
+ }
+ }
+ }
+
+ @Override
+ public int compareTo(YangDecimal64 o) {
+ return Double.compare(value.doubleValue(), o.value.doubleValue());
+ }
+
+ /**
+ * Returns decimal64 default range restriction based on fraction-digits.
+ * If range restriction is not provided then this default range value will be applicable.
+ *
+ * @return range restriction
+ * @throws DataModelException a violation of data model rules
+ */
+ public YangRangeRestriction getDefaultRangeRestriction() throws DataModelException {
+ YangRangeRestriction refRangeRestriction = new YangRangeRestriction();
+ YangRangeInterval rangeInterval = new YangRangeInterval<>();
+ rangeInterval.setCharPosition(getCharPosition());
+ rangeInterval.setLineNumber(getLineNumber());
+ rangeInterval.setFileName(getFileName());
+ FractionDigits.Range range = FractionDigits.getRange(fractionDigit);
+ rangeInterval.setStartValue(new YangDecimal64(new BigDecimal((range.getMin()))));
+ rangeInterval.setEndValue(new YangDecimal64(new BigDecimal((range.getMax()))));
+ refRangeRestriction.addRangeRestrictionInterval(rangeInterval);
+ return refRangeRestriction;
+ }
+
+ /**
+ * 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDerivedInfo.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDerivedInfo.java
new file mode 100644
index 0000000..88adac0
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDerivedInfo.java
@@ -0,0 +1,684 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
+
+import java.io.Serializable;
+
+import static com.google.common.base.Strings.isNullOrEmpty;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsg;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.RESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.RestrictionResolver.processLengthRestriction;
+import static org.onosproject.yang.compiler.datamodel.utils.RestrictionResolver.processRangeRestriction;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.STRING;
+
+/**
+ * Represents the derived information.
+ *
+ * @param <T> extended information.
+ */
+public class YangDerivedInfo<T> extends DefaultLocationInfo
+ implements 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;
+
+ /**
+ * Effective built-in type, required 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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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();
+ YangDataTypes type = baseType.getDataType();
+ T extended = (T) baseType.getDataTypeExtendedInfo();
+
+ /*
+ * 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 (type == DERIVED) {
+ ResolvableStatus resolvableStatus = resolveTypeDerivedInfo(baseType);
+ if (resolvableStatus != null) {
+ return resolvableStatus;
+ }
+ } else if (type == LEAFREF || type == IDENTITYREF) {
+ effectiveBuiltInType = type;
+ return RESOLVED;
+ } else {
+ effectiveBuiltInType = type;
+ /*
+ * Check whether the effective built-in type can have range
+ * restrictions, if yes call resolution of range.
+ */
+ if (isOfRangeRestrictedType(effectiveBuiltInType)) {
+ return getResolveStatusForRangeRestrictionType(extended);
+ } else if (effectiveBuiltInType == STRING) {
+ return getResolveStatusForString(extended);
+ } else if (effectiveBuiltInType == BINARY) {
+ return getResolveStatusForBinary(extended);
+ } else if (effectiveBuiltInType == DECIMAL64) {
+ return getResolveStatusForDecimal64(extended);
+ }
+ }
+
+ /*
+ * 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 (effectiveBuiltInType.isNonRestrictedType()) {
+ if (isNullOrEmpty(getLengthRestrictionString()) &&
+ isNullOrEmpty(getRangeRestrictionString()) &&
+ getPatternRestriction() == null) {
+ return RESOLVED;
+ } else {
+ throw new DataModelException(getErrorMsg(
+ "YANG file error: Restrictions can't be applied to a " +
+ "given type ", "type.", getLineNumber(),
+ getCharPosition(), getFileName() + "\""));
+ }
+ }
+ // Throw exception for unsupported types
+ throw new DataModelException(getErrorMsg(
+ "Linker error: Unable to process the derived type. ", "type.",
+ getLineNumber(), getCharPosition(), getFileName() + "\""));
+ }
+
+ //Returns resolve status for range restrictions.
+ private ResolvableStatus getResolveStatusForRangeRestrictionType(T extended)
+ throws DataModelException {
+ if (extended == 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 (!(extended instanceof YangRangeRestriction)) {
+ throwError();
+ }
+ resolveRangeRestriction((YangRangeRestriction) extended);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ }
+
+ //Returns resolve status for string.
+ private ResolvableStatus getResolveStatusForString(T extended)
+ throws DataModelException {
+ if (extended == 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 (!(extended instanceof YangStringRestriction)) {
+ throwError();
+ }
+ resolveStringRestriction((YangStringRestriction) extended);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ }
+
+ //Returns resolve status for binary type.
+ private ResolvableStatus getResolveStatusForBinary(T extended)
+ throws DataModelException {
+ if (extended == null) {
+ resolveBinaryRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve length restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(extended instanceof YangRangeRestriction)) {
+ throwError();
+ }
+ resolveBinaryRestriction((YangRangeRestriction) extended);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve length restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ }
+
+ //Returns resolve status for decimal64 type.
+ private ResolvableStatus getResolveStatusForDecimal64(T extended)
+ throws DataModelException {
+ if (extended != null) {
+ if (((YangDecimal64) extended).getRangeRestrictedExtendedInfo() == null) {
+ resolveRangeRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not;
+ * resolve range restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(((YangDecimal64) extended)
+ .getRangeRestrictedExtendedInfo() instanceof YangRangeRestriction)) {
+ throwError();
+ }
+ resolveRangeRestriction((YangRangeRestriction) (
+ (YangDecimal64) extended).getRangeRestrictedExtendedInfo());
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+
+ } else {
+ throw new DataModelException(getErrorMsg(
+ "Linker error: Unable to find type extended info " +
+ "for decimal64.", "type.", getLineNumber(),
+ getCharPosition(), getFileName() + "\""));
+ }
+ }
+
+ private void throwError() throws DataModelException {
+ throw new DataModelException(getErrorMsg(
+ "Linker error: Referred typedef restriction info is of invalid ",
+ "type.", getLineNumber(), getCharPosition(), getFileName() + "\""));
+ }
+
+ /**
+ * Resolves the type derived info, by obtaining the effective built-in type
+ * and resolving the restrictions.
+ *
+ * @param baseType base type of typedef
+ * @return resolution status
+ * @throws DataModelException a violation in data mode rule
+ */
+ private ResolvableStatus resolveTypeDerivedInfo(YangType<?> baseType)
+ throws DataModelException {
+
+ //Check whether the referred typedef is resolved.
+ if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED &&
+ baseType.getResolvableStatus() != RESOLVED) {
+ throwError();
+ }
+
+ /*
+ * 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;
+ }
+ effectiveBuiltInType = ((YangDerivedInfo<?>) baseType
+ .getDataTypeExtendedInfo()).getEffectiveBuiltInType();
+ YangDerivedInfo refDerivedInfo = (YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo();
+ T extendedInfo = (T) refDerivedInfo.getResolvedExtendedInfo();
+ /*
+ * Check whether the effective built-in type can have range
+ * restrictions, if yes call resolution of range.
+ */
+ if (isOfRangeRestrictedType(effectiveBuiltInType)) {
+ return getResolveStatusForRangeRestrictionType(extendedInfo);
+ } else if (effectiveBuiltInType == STRING) {
+ return getResolveStatusForString(extendedInfo);
+ } else if (effectiveBuiltInType == BINARY) {
+ return getResolveStatusForBinary(extendedInfo);
+ } else if (effectiveBuiltInType == DECIMAL64) {
+ if (extendedInfo == null) {
+ resolveRangeRestriction(null);
+ /*
+ * Return the resolution status as resolved, if it's not;
+ * resolve range restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ } else {
+ if (!(extendedInfo instanceof YangRangeRestriction)) {
+ throwError();
+ }
+ resolveRangeRestriction((YangRangeRestriction) extendedInfo);
+ /*
+ * Return the resolution status as resolved, if it's not
+ * resolve range/string restriction will throw exception in
+ * previous function.
+ */
+ return RESOLVED;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Resolves the string restrictions.
+ *
+ * @param refSr referred string restriction of typedef
+ * @throws DataModelException a violation in data model rule
+ */
+ private void resolveStringRestriction(YangStringRestriction refSr)
+ throws DataModelException {
+ YangStringRestriction curSr = null;
+ YangRangeRestriction refRr = null;
+ YangPatternRestriction refPr = null;
+
+ /*
+ * Check that range restriction should be null when built-in type is
+ * string.
+ */
+ if (!isNullOrEmpty(getRangeRestrictionString())) {
+ throw new DataModelException(getErrorMsg(
+ "YANG file error: Range restriction should't be present for" +
+ " string data type.", ".", getLineNumber(),
+ getCharPosition(), getFileName()));
+ }
+
+ /*
+ * If referred restriction and self restriction both are null, no
+ * resolution is required.
+ */
+ if (refSr == null && isNullOrEmpty(getLengthRestrictionString()) &&
+ getPatternRestriction() == null) {
+ return;
+ }
+
+ /*
+ * If referred string restriction is not null, take value of length and
+ * pattern restriction and assign.
+ */
+ if (refSr != null) {
+ refRr = refSr.getLengthRestriction();
+ refPr = refSr.getPatternRestriction();
+ }
+
+ YangRangeRestriction lr = resolveLengthRestriction(refRr);
+ YangPatternRestriction pr = resolvePatternRestriction(refPr);
+
+ /*
+ * Check if either of length or pattern restriction is present, if yes
+ * create string restriction and assign value.
+ */
+ if (lr != null || pr != null) {
+ curSr = new YangStringRestriction();
+ curSr.setCharPosition(getCharPosition());
+ curSr.setFileName(getFileName());
+ curSr.setLineNumber(getLineNumber());
+ curSr.setLengthRestriction(lr);
+ curSr.setPatternRestriction(pr);
+ }
+ resolvedExtendedInfo = (T) curSr;
+ }
+
+ /**
+ * Resolves the binary restrictions.
+ *
+ * @param refLr referred length restriction of typedef
+ * @throws DataModelException a violation in data model rule
+ */
+ private void resolveBinaryRestriction(YangRangeRestriction refLr)
+ throws DataModelException {
+
+ if (rangeRestrictionString != null || patternRestriction != null) {
+ throw new DataModelException(getErrorMsg(
+ "YANG file error: for binary range restriction or pattern " +
+ "restriction is not allowed.", "type.",
+ getLineNumber(), getCharPosition(), getFileName()));
+ }
+
+ // Get the final resolved length restriction
+ YangRangeRestriction lr = resolveLengthRestriction(refLr);
+ // Set the length restriction.
+ resolvedExtendedInfo = (T) lr;
+ }
+
+ /**
+ * Resolves pattern restriction.
+ *
+ * @param refPr referred pattern restriction of typedef
+ * @return resolved pattern restriction
+ */
+ private YangPatternRestriction resolvePatternRestriction(YangPatternRestriction refPr) {
+ /*
+ * If referred restriction and self restriction both are null, no
+ * resolution is required.
+ */
+ if (refPr == 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 refPr;
+ }
+
+ /*
+ * If referred restriction is null, and self restriction is present
+ * carry out self resolution.
+ */
+ if (refPr == null) {
+ return getPatternRestriction();
+ }
+
+ /*
+ * Get patterns of referred type and add it to current pattern
+ * restrictions.
+ */
+ for (String pattern : refPr.getPatternList()) {
+ getPatternRestriction().addPattern(pattern);
+ }
+ return getPatternRestriction();
+ }
+
+ /**
+ * Resolves the length restrictions.
+ *
+ * @param refLenRestriction referred length restriction of typedef
+ * @return resolved length restriction
+ * @throws DataModelException a violation in data model rule
+ */
+ private YangRangeRestriction resolveLengthRestriction(
+ YangRangeRestriction refLenRestriction) throws DataModelException {
+
+ /*
+ * If referred restriction and self restriction both are null, no
+ * resolution is required.
+ */
+ if (refLenRestriction == null && isNullOrEmpty(getLengthRestrictionString())) {
+ return null;
+ }
+
+ /*
+ * If self restriction is null, and referred restriction is present
+ * shallow copy the referred to self.
+ */
+ if (isNullOrEmpty(getLengthRestrictionString())) {
+ return refLenRestriction;
+ }
+
+ /*
+ * If referred restriction is null, and self restriction is present
+ * carry out self resolution.
+ */
+ if (refLenRestriction == null) {
+ return processLengthRestriction(
+ null, getLineNumber(), getCharPosition(), false,
+ getLengthRestrictionString(), getFileName());
+ }
+
+ /*
+ * 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(refLenRestriction, getLineNumber(),
+ getCharPosition(), true,
+ getLengthRestrictionString(), getFileName());
+
+ // Resolve the range with referred typedef's restriction.
+ resolveLengthAndRangeRestriction(refLenRestriction, 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(getErrorMsg(
+ "Linker error: Current range intervals not processed correctly.",
+ "type.", getLineNumber(), getCharPosition(), getFileName()));
+ }
+ try {
+ refRestriction.isValidInterval((YangRangeInterval)
+ curInterval, getFileName());
+ } catch (DataModelException e) {
+ throw new DataModelException(getErrorMsg(
+ e.getMessage(), "type.", getLineNumber(), getCharPosition(),
+ getFileName()));
+ }
+ }
+ }
+
+ /**
+ * 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 (!isNullOrEmpty(getLengthRestrictionString())
+ || getPatternRestriction() != null) {
+ throw new DataModelException(getErrorMsg(
+ "YANG file error: Length/Pattern restriction should't be present" +
+ " for int/uint/decimal data type.", "type.", getLineNumber(),
+ getCharPosition(), getFileName()));
+ }
+
+ /*
+ * If referred restriction and self restriction both are null, no
+ * resolution is required.
+ */
+ if (refRangeRestriction == null && isNullOrEmpty(getRangeRestrictionString())) {
+ return;
+ }
+
+ /*
+ * If self restriction is null, and referred restriction is present
+ * shallow copy the referred to self.
+ */
+ if (isNullOrEmpty(getRangeRestrictionString())) {
+ resolvedExtendedInfo = (T) refRangeRestriction;
+ return;
+ }
+
+ /*
+ * If referred restriction is null, and self restriction is present
+ * carry out self resolution.
+ */
+ if (refRangeRestriction == null) {
+ YangRangeRestriction curRangeRestriction =
+ processRangeRestriction(null, getLineNumber(),
+ getCharPosition(), false, getRangeRestrictionString(),
+ effectiveBuiltInType, getFileName());
+ resolvedExtendedInfo = (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, getLineNumber(),
+ getCharPosition(), true,
+ getRangeRestrictionString(),
+ effectiveBuiltInType, getFileName());
+
+ // Resolve the range with referred typedef's restriction.
+ resolveLengthAndRangeRestriction(refRangeRestriction, curRangeRestriction);
+ resolvedExtendedInfo = (T) curRangeRestriction;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDesc.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangDesc.java
new file mode 100644
index 0000000..7bfbf38
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangEntityToResolveInfo.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangEntityToResolveInfo.java
new file mode 100644
index 0000000..f4efa8b
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangEntityToResolveInfoImpl.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangEntityToResolveInfoImpl.java
new file mode 100644
index 0000000..14cced0
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangEntityToResolveInfoImpl.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import java.io.Serializable;
+
+/**
+ * Represents implementation of information about entity being resolved.
+ *
+ * @param <T> type of entity being resolved, uses / grouping
+ */
+public class YangEntityToResolveInfoImpl<T> extends DefaultLocationInfo
+ implements YangEntityToResolveInfo<T>, Serializable {
+
+ private static final long serialVersionUID = 806201659L;
+
+ /**
+ * Parsable node for which resolution is to be performed.
+ */
+ private T entityToResolve;
+
+ /**
+ * Holder of the YANG construct for which resolution has to be carried out.
+ */
+ private YangNode holderOfEntityToResolve;
+
+ @Override
+ public T getEntityToResolve() {
+ return entityToResolve;
+ }
+
+ @Override
+ public void setEntityToResolve(T entityToResolve) {
+ this.entityToResolve = entityToResolve;
+ }
+
+ @Override
+ public YangNode getHolderOfEntityToResolve() {
+ return holderOfEntityToResolve;
+ }
+
+ @Override
+ public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
+ this.holderOfEntityToResolve = holderOfEntityToResolve;
+ }
+
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangEnum.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangEnum.java
new file mode 100644
index 0000000..cc8da44
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangEnum.java
@@ -0,0 +1,243 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.ENUM_DATA;
+
+/*-
+ * 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 extends DefaultLocationInfo 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 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangEnumeration.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangEnumeration.java
new file mode 100644
index 0000000..37e747c
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangEnumeration.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_NON_DATA_NODE;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.ENUMERATION_DATA;
+
+/*
+ * The enumeration built-in type represents values from a set of
+ * assigned names.
+ */
+
+/**
+ * Represents the enumeration data type information.
+ */
+public abstract class YangEnumeration
+ extends YangNode
+ implements Parsable, CollisionDetector {
+
+ private static final long serialVersionUID = 806201606L;
+
+ // Enumeration info set.
+ private SortedSet<YangEnum> enumSet;
+
+ /**
+ * Creates an enumeration object.
+ */
+ public YangEnumeration() {
+ super(YangNodeType.ENUMERATION_NODE, null);
+ setEnumSet(new TreeSet<>());
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier schemaNodeIdentifier,
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+ throws DataModelException {
+ // Do nothing.
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier, YangSchemaNode yangSchemaNode) {
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_NON_DATA_NODE;
+ }
+
+ /**
+ * 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 " +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+
+ /**
+ * Returns the type of the data.
+ *
+ * @return returns ENUMERATION_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangExtension.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangExtension.java
new file mode 100644
index 0000000..b6e469e
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangExtension.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The "extension" statement allows the definition of new statements
+ * within the YANG language. This new statement definition can be
+ * imported and used by other modules.
+ *
+ * The statement's argument is an identifier that is the new keyword for
+ * the extension and must be followed by a block of sub-statements that
+ * holds detailed extension information. The purpose of the "extension"
+ * statement is to define a keyword, so that it can be imported and used
+ * by other modules.
+ *
+ * The extension can be used like a normal YANG statement, with the
+ * statement name followed by an argument if one is defined by the
+ * extension, and an optional block of sub-statements. The statement's
+ * name is created by combining the prefix of the module in which the
+ * extension was defined, a colon (":"), and the extension's keyword,
+ * with no interleaving whitespace. The sub-statements of an extension
+ * are defined by the extension, using some mechanism outside the scope
+ * of this specification. Syntactically, the sub-statements MUST be YANG
+ * statements, or also defined using "extension" statements.
+ *
+ * The extension'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 |
+ * | argument | 7.17.2 | 0..1 | -string |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG extension.
+ */
+public class YangExtension extends DefaultLocationInfo
+ implements YangCommonInfo, Serializable, Parsable {
+
+ private static final long serialVersionUID = 806201605L;
+
+ /**
+ * Name of the extension.
+ */
+ private String name;
+
+ /**
+ * Name of the argument.
+ */
+ private String argumentName;
+
+ /**
+ * Description of extension.
+ */
+ private String description;
+
+ /**
+ * Reference of the extension.
+ */
+ private String reference;
+
+ /**
+ * Status of the extension.
+ */
+ private YangStatusType status = YangStatusType.CURRENT;
+
+ /**
+ * Returns the YANG name of extension.
+ *
+ * @return the name of extension as defined in YANG file
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the YANG name of extension.
+ *
+ * @param name the name of extension as defined in YANG file
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the YANG argument name of extension.
+ *
+ * @return the name of argument as defined in YANG file
+ */
+ public String getArgumentName() {
+ return argumentName;
+ }
+
+ /**
+ * Sets the YANG argument name of extension.
+ *
+ * @param argumentName the name of argument as defined in YANG file
+ */
+ public void setArgumentName(String argumentName) {
+ this.argumentName = argumentName;
+ }
+
+ /**
+ * 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 EXTENSION_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.EXTENSION_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 : to be implemented
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangFeature.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangFeature.java
new file mode 100644
index 0000000..76a3515
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangFeature.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The "feature" statement is used to define a mechanism by which
+ * portions of the schema are marked as conditional. A feature name is
+ * defined that can later be referenced using the "if-feature" statement.
+ * Schema nodes tagged with a feature are ignored by the device unless
+ * the device supports the given feature. This allows portions of the
+ * YANG module to be conditional based on conditions on the device.
+ * The model can represent the abilities of the device within the model,
+ * giving a richer model that allows for differing device abilities and roles.
+ *
+ * The argument to the "feature" statement is the name of the new
+ * feature, and follows the rules for identifiers. This name is used by the
+ * "if-feature" statement to tie the schema nodes to the feature.
+ *
+ * The feature's Substatements
+ *
+ * +--------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +--------------+---------+-------------+------------------+
+ * | description | 7.19.3 | 0..1 | -string |
+ * | if-feature | 7.18.2 | 0..n | -YangIfFeature |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG feature.
+ */
+public class YangFeature extends DefaultLocationInfo
+ implements YangCommonInfo, Parsable, YangIfFeatureHolder, Serializable {
+
+ private static final long serialVersionUID = 806201635L;
+
+ /**
+ * Name of the feature.
+ */
+ private String name;
+
+ /**
+ * Description of feature.
+ */
+ private String description;
+
+ /**
+ * Reference of the feature.
+ */
+ private String reference;
+
+ /**
+ * Status of feature.
+ */
+ private YangStatusType statusType;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ @Override
+ public YangStatusType getStatus() {
+ return statusType;
+ }
+
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.statusType = status;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.FEATURE_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ //TODO : To be implemented
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ //TODO : To be implemented
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangFeatureHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangFeatureHolder.java
new file mode 100644
index 0000000..d6f588d
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangFeatureHolder.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import java.util.List;
+
+/**
+ * Abstraction of feature entity. It is used to abstract the data holders of feature.
+ */
+public interface YangFeatureHolder {
+
+ /**
+ * Returns the list of feature from data holder like container / list.
+ *
+ * @return the list of feature
+ */
+ List<YangFeature> getFeatureList();
+
+ /**
+ * Adds feature in feature list.
+ *
+ * @param feature the feature to be added
+ */
+ void addFeatureList(YangFeature feature);
+
+ /**
+ * Sets the list of feature.
+ *
+ * @param listOfFeature the list of feature to set
+ */
+ void setListOfFeature(List<YangFeature> listOfFeature);
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangGrouping.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangGrouping.java
new file mode 100644
index 0000000..da87a1d
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangGrouping.java
@@ -0,0 +1,367 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.GROUPING_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_NON_DATA_NODE;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.GROUPING;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.GROUPING_DATA;
+
+/*-
+ * 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 abstract class YangGrouping
+ extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
+ YangTranslatorOperatorNode {
+
+ private static final long serialVersionUID = 806201607L;
+
+ /**
+ * 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;
+
+ /**
+ * Grouping depth.
+ */
+ private int groupingDepth;
+
+ /**
+ * Creates the grouping node.
+ */
+ public YangGrouping() {
+ super(GROUPING_NODE, null);
+ listOfLeaf = new LinkedList<>();
+ listOfLeafList = new LinkedList<>();
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo context)
+ throws DataModelException {
+ // Do nothing, to be handled during linking.
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // Do nothing, to be handled during linking.
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier id,
+ YangSchemaNode node) {
+ // Do nothing, to be handled during linking.
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_NON_DATA_NODE;
+ }
+
+ /**
+ * 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 unmodifiableList(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) {
+ listOfLeaf.add(leaf);
+ }
+
+ /**
+ * Returns the list of leaf-list.
+ *
+ * @return the list of leaf-list
+ */
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return unmodifiableList(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) {
+ listOfLeafList.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 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(
+ getErrorMsgCollision(COLLISION_DETECTION, getName(),
+ getLineNumber(), getCharPosition(),
+ GROUPING, getFileName()));
+ }
+ }
+
+ @Override
+ public void setLeafNameSpaceAndAddToParentSchemaMap() {
+ // Add namespace for all leafs.
+ for (YangLeaf yangLeaf : listOfLeaf) {
+ yangLeaf.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ // Add namespace for all leaf list.
+ for (YangLeafList yangLeafList : listOfLeafList) {
+ yangLeafList.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ }
+ // TODO A grouping MUST NOT reference itself, neither directly nor indirectly through a chain of other groupings.
+
+ /**
+ * Returns grouping depth.
+ *
+ * @return grouping depth
+ */
+ public int getGroupingDepth() {
+ return groupingDepth;
+ }
+
+ /**
+ * Sets grouping depth.
+ *
+ * @param groupingDepth grouping depth
+ */
+ public void setGroupingDepth(int groupingDepth) {
+ this.groupingDepth = groupingDepth;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentity.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentity.java
new file mode 100644
index 0000000..94732a9
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentity.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The "identity" statement is used to define a new globally unique,
+ * abstract, and untyped identity. Its only purpose is to denote its
+ * name, semantics, and existence. An identity can either be defined
+ * from scratch or derived from a base identity. The identity's
+ * argument is an identifier that is the name of the identity. It is
+ * followed by a block of substatements that holds detailed identity
+ * information.
+ *
+ * The identity's Substatements
+ *
+ * +--------------+---------+-------------+-----------------------+
+ * | substatement | section | cardinality | data model mapping |
+ * +--------------+---------+-------------+-----------------------+
+ * | base | 7.16.2 | 0..1 | -YangNodeIdentifier |
+ * | description | 7.19.3 | 0..1 | -string |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * +--------------+---------+-------------+-----------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG identity.
+ */
+public abstract class YangIdentity
+ extends YangNode
+ implements YangCommonInfo, Parsable, Serializable, YangTranslatorOperatorNode {
+
+ private static final long serialVersionUID = 806201691L;
+
+ //Base node of identity.
+ private YangBase baseNode;
+
+ //Status of YANG identity.
+ private YangStatusType status;
+
+ //Description of YANG identity.
+ private String description;
+
+ //YANG reference of the identity.
+ private String reference;
+
+ //Creates a identity type of node.
+ public YangIdentity() {
+ super(YangNodeType.IDENTITY_NODE, null);
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier schemaNodeIdentifier,
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+ throws DataModelException {
+ // Do nothing.
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier, YangSchemaNode yangSchemaNode) {
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YangSchemaNodeType.YANG_NON_DATA_NODE;
+ }
+
+ @Override
+ public YangStatusType getStatus() {
+ return status;
+ }
+
+ @Override
+ public void setStatus(YangStatusType status) {
+ this.status = status;
+ }
+
+ @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 YangConstructType getYangConstructType() {
+ return YangConstructType.IDENTITY_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ }
+
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ }
+
+ /**
+ * Returns base node of identity.
+ *
+ * @return the base node of identity
+ */
+ public YangBase getBaseNode() {
+ return baseNode;
+ }
+
+ /**
+ * Sets the base node.
+ *
+ * @param baseNode the base node to set
+ */
+ public void setBaseNode(YangBase baseNode) {
+ this.baseNode = baseNode;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentityRef.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentityRef.java
new file mode 100644
index 0000000..6c5817f
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIdentityRef.java
@@ -0,0 +1,299 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.RESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.UNRESOLVED;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * The identityref type is used to reference an existing identity.
+ *
+ * The identityref's base Statement :
+ * The "base" statement, which is a substatement to the "type"
+ * statement, MUST be present if the type is "identityref". The
+ * argument is the name of an identity, as defined by an "identity"
+ * statement. If a prefix is present on the identity name, it refers to
+ * an identity defined in the module that was imported with that prefix.
+ * Otherwise, an identity with the matching name MUST be defined in the
+ * current module or an included submodule.
+ * Valid values for an identityref are any identities derived from the
+ * identityref's base identity. On a particular server, the valid
+ * values are further restricted to the set of identities defined in the
+ * modules supported by the server.
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG identityref.
+ */
+public class YangIdentityRef
+ extends YangNode
+ implements Cloneable, Parsable, Resolvable, Serializable {
+
+ private static final long serialVersionUID = 806201692L;
+
+ // Get referred identity parent information.
+ private YangIdentity referredIdentity;
+
+ // YANG node identifier.
+ private YangNodeIdentifier baseIdentity;
+
+ /**
+ * Status of resolution. If completely resolved enum value is "RESOLVED",
+ * if not enum value is "UNRESOLVED", in case reference of grouping/typedef/identityref/base
+ * is added to uses/type/identityref/base but it's not resolved value of enum should be
+ * "INTRA_FILE_RESOLVED".
+ */
+ private ResolvableStatus resolvableStatus;
+
+ /**
+ * Resolution for interfile grouping.
+ */
+ private boolean isIdentityForInterFileGroupingResolution;
+
+ /**
+ * Flag to indicate whether the leaf ref is inside grouping.
+ */
+ private boolean inGrouping;
+
+ // Creates a specific identityref of node.
+ public YangIdentityRef() {
+ super(YangNodeType.IDENTITYREF_NODE, null);
+ baseIdentity = new YangNodeIdentifier();
+ resolvableStatus = UNRESOLVED;
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier schemaNodeIdentifier,
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+ throws DataModelException {
+ // Do nothing.
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier, YangSchemaNode yangSchemaNode) {
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YangSchemaNodeType.YANG_NON_DATA_NODE;
+ }
+
+ @Override
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ @Override
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+ }
+
+ @Override
+ public Object resolve()
+ throws DataModelException {
+
+ // Check if the derived info is present.
+ YangIdentity identity = getReferredIdentity();
+
+ if (identity == null) {
+ throw new DataModelException("Linker Error: Identity information is missing. " +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+
+ while (identity.getBaseNode() != null) {
+ if (identity.getBaseNode().getResolvableStatus() != RESOLVED) {
+ setResolvableStatus(INTRA_FILE_RESOLVED);
+ return null;
+ }
+ identity = identity.getBaseNode().getReferredIdentity();
+ }
+ return null;
+ }
+
+ /**
+ * Returns the YANG base node identifier.
+ *
+ * @return the YANG base node identifier
+ */
+ public YangNodeIdentifier getBaseIdentity() {
+ return baseIdentity;
+ }
+
+ /**
+ * Sets the YANG node identifier.
+ *
+ * @param baseIdentity the YANG node identifier to set
+ */
+ public void setBaseIdentity(YangNodeIdentifier baseIdentity) {
+ this.baseIdentity = baseIdentity;
+ }
+
+ /**
+ * Returns the name of identity.
+ *
+ * @return the identity name
+ */
+ @Override
+ public String getName() {
+ return baseIdentity.getName();
+ }
+
+ /**
+ * Sets the name of identity.
+ *
+ * @param name the identity name to set
+ */
+ @Override
+ public void setName(String name) {
+ baseIdentity.setName(name);
+ }
+
+ /**
+ * Sets node identifier.
+ *
+ * @param nodeIdentifier the node identifier
+ */
+ public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
+ this.baseIdentity = nodeIdentifier;
+ }
+
+ /**
+ * Returns prefix associated with base.
+ *
+ * @return prefix associated with base
+ */
+ public String getPrefix() {
+ return baseIdentity.getPrefix();
+ }
+
+ /**
+ * Sets prefix associated with base.
+ *
+ * @param prefix prefix associated with base
+ */
+ public void setPrefix(String prefix) {
+ baseIdentity.setPrefix(prefix);
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.IDENTITYREF_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ }
+
+ @Override
+ public void validateDataOnExit()
+ throws DataModelException {
+ }
+
+ /**
+ * Returns the parent identity node.
+ *
+ * @return the parent identity node
+ */
+ public YangIdentity getReferredIdentity() {
+ return referredIdentity;
+ }
+
+ /**
+ * Sets the parent identity node.
+ *
+ * @param referredIdentity the parent identity node to set
+ */
+ public void setReferredIdentity(YangIdentity referredIdentity) {
+ this.referredIdentity = referredIdentity;
+ }
+
+ public boolean isIdentityForInterFileGroupingResolution() {
+ return isIdentityForInterFileGroupingResolution;
+ }
+
+ public void setIdentityForInterFileGroupingResolution(
+ boolean identityForInterFileGroupingResolution) {
+ isIdentityForInterFileGroupingResolution =
+ identityForInterFileGroupingResolution;
+ }
+
+ @Override
+ public YangIdentityRef clone()
+ throws CloneNotSupportedException {
+ YangIdentityRef identityRef = (YangIdentityRef) super.clone();
+ return identityRef;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ //TODO: throw exception
+ return null;
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ //TODO: throw exception
+ return null;
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ throw new RuntimeException("Attribute name is not applicable ");
+ }
+
+ /**
+ * Returns flag value indicating whether leafref is inside grouping.
+ *
+ * @return true if leafref is in grouping, false otherwise
+ */
+ public boolean isInGrouping() {
+ return inGrouping;
+ }
+
+ /**
+ * Sets in grouping flag.
+ *
+ * @param inGrouping flag
+ */
+ public void setInGrouping(boolean inGrouping) {
+ this.inGrouping = inGrouping;
+ }
+
+ @Override
+ public YangNode clone(YangUses yangUses) throws CloneNotSupportedException {
+ return (YangNode) super.clone();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIfFeature.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIfFeature.java
new file mode 100644
index 0000000..a4e50c4
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIfFeature.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The "if-feature" statement makes its parent statement conditional.
+ * The argument is the name of a feature, as defined by a "feature"
+ * statement. The parent statement is implemented by servers that
+ * support this feature. If a prefix is present on the feature name, it
+ * refers to a feature defined in the module that was imported with that
+ * prefix, or the local module if the prefix matches the local module's
+ * prefix. Otherwise, a feature with the matching name MUST be defined
+ * in the current module or an included submodule.
+ *
+ * Since submodules cannot include the parent module, any features in
+ * the module that need to be exposed to submodules MUST be defined in a
+ * submodule. Submodules can then include this submodule to find the
+ * definition of the feature.
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG if-feature.
+ */
+public class YangIfFeature extends DefaultLocationInfo
+ implements Parsable, Resolvable, Serializable {
+
+ private static final long serialVersionUID = 806201635L;
+
+ /**
+ * if-feature argument.
+ */
+ private YangNodeIdentifier name;
+
+ /**
+ * Referred feature information.
+ */
+ private YangFeature referredFeature;
+
+ /**
+ * Referred feature parent information.
+ */
+ private YangNode referredFeatureHolder;
+
+ /**
+ * Status of resolution. If completely resolved enum value is "RESOLVED",
+ * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
+ * is added to uses/type but it's not resolved value of enum should be
+ * "INTRA_FILE_RESOLVED".
+ */
+ private ResolvableStatus resolvableStatus;
+
+ /**
+ * Returns referred feature holder.
+ *
+ * @return referred feature holder
+ */
+ public YangNode getReferredFeatureHolder() {
+ return referredFeatureHolder;
+ }
+
+ /**
+ * Sets the referred feature holder.
+ *
+ * @param referredFeatureHolder referred feature holder
+ */
+ public void setReferredFeatureHolder(YangNode referredFeatureHolder) {
+ this.referredFeatureHolder = referredFeatureHolder;
+ }
+
+ /**
+ * Returns prefix associated with identifier.
+ *
+ * @return prefix associated with identifier
+ */
+ public String getPrefix() {
+ return name.getPrefix();
+ }
+
+ /**
+ * Sets prefix associated with identifier.
+ *
+ * @param prefix prefix associated with identifier
+ */
+ public void setPrefix(String prefix) {
+ name.setPrefix(prefix);
+ }
+
+ /**
+ * Returns referred feature associated with if-feature.
+ *
+ * @return referred feature associated with if-feature
+ */
+ public YangFeature getReferredFeature() {
+ return referredFeature;
+ }
+
+ /**
+ * Sets referred feature associated with if-feature.
+ *
+ * @param referredFeature referred feature associated with if-feature
+ */
+ public void setReferredFeature(YangFeature referredFeature) {
+ this.referredFeature = referredFeature;
+ }
+
+ /**
+ * Returns the YANG name of if-feature.
+ *
+ * @return the name of if-feature as defined in YANG file
+ */
+ public YangNodeIdentifier getName() {
+ return name;
+ }
+
+ /**
+ * Sets the YANG name of if-feature.
+ *
+ * @param name the name of if-feature as defined in YANG file
+ */
+ public void setName(YangNodeIdentifier name) {
+ this.name = name;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.IF_FEATURE_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // do nothing, no validation required for if-feature
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // do nothing, no validation required for if-feature
+ }
+
+ @Override
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ @Override
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+ }
+
+ @Override
+ public Object resolve() throws DataModelException {
+ YangFeature feature = getReferredFeature();
+
+ // check whether feature has if-feature
+ List<YangIfFeature> ifFeatureList = feature.getIfFeatureList();
+ if (ifFeatureList != null && !ifFeatureList.isEmpty()) {
+ Iterator<YangIfFeature> ifFeatureIterator = ifFeatureList.iterator();
+ while (ifFeatureIterator.hasNext()) {
+ YangIfFeature ifFeature = ifFeatureIterator.next();
+ if (ifFeature.getResolvableStatus() != ResolvableStatus.RESOLVED) {
+ setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
+ return null;
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIfFeatureHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIfFeatureHolder.java
new file mode 100644
index 0000000..a7eda66
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIfFeatureHolder.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import java.util.List;
+
+/**
+ * Abstraction of if-feature entity. It is used to abstract the data holders of if-feature.
+ */
+public interface YangIfFeatureHolder {
+
+ /**
+ * Returns the list of if-feature from data holder like container / list.
+ *
+ * @return the list of if-feature
+ */
+ List<YangIfFeature> getIfFeatureList();
+
+ /**
+ * Adds if-feature in if-feature list.
+ *
+ * @param ifFeature the if-feature to be added
+ */
+ void addIfFeatureList(YangIfFeature ifFeature);
+
+ /**
+ * Sets the list of if-feature.
+ *
+ * @param ifFeatureList the list of if-feature to set
+ */
+ void setIfFeatureList(List<YangIfFeature> ifFeatureList);
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangImport.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangImport.java
new file mode 100644
index 0000000..bef36ab
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangImport.java
@@ -0,0 +1,266 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.Set;
+
+import static org.onosproject.yang.compiler.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 | Date |
+ * +---------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents the information about the imported modules.
+ */
+public class YangImport extends DefaultLocationInfo
+ implements Parsable, 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 Date revision;
+
+ /**
+ * Reference to node which is imported.
+ */
+ private YangNode importedNode;
+
+ /**
+ * 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 Date getRevision() {
+ return revision;
+ }
+
+ /**
+ * Sets the revision of the imported module.
+ *
+ * @param rev set the revision of the imported module
+ */
+ public void setRevision(Date 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;
+ }
+
+ /**
+ * 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();
+ Date 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) {
+ setImportedNode(moduleNode);
+ return;
+ }
+ // Match revision if import is with revision.
+ if (moduleNode.getRevision() != null && (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());
+ exception.setFileName(getFileName());
+ throw exception;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangInclude.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangInclude.java
new file mode 100644
index 0000000..83c6bbe
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangInclude.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.Set;
+
+import static org.onosproject.yang.compiler.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 extends DefaultLocationInfo
+ implements Parsable, 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 Date revision;
+
+ /**
+ * Reference to node which is included.
+ */
+ private YangNode includedNode;
+
+ /**
+ * 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 Date getRevision() {
+ return revision;
+ }
+
+ /**
+ * Sets the revision.
+ *
+ * @param revision the revision to set
+ */
+ public void setRevision(Date 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;
+ }
+
+ /**
+ * 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();
+ Date 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) {
+ setIncludedNode(subModuleNode);
+ return (YangSubModule) subModuleNode;
+ }
+
+ // Match revision if inclusion is with revision.
+ if (subModuleNode.getRevision() != null && 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());
+ exception.setFileName(getFileName());
+ 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());
+ exception.setFileName(getFileName());
+ throw exception;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangInput.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangInput.java
new file mode 100644
index 0000000..10d7188
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangInput.java
@@ -0,0 +1,231 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.INPUT_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_SINGLE_INSTANCE_NODE;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.INPUT;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.INPUT_DATA;
+
+/*
+ * 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 abstract class YangInput
+ extends YangNode
+ implements YangLeavesHolder, Parsable, CollisionDetector,
+ YangAugmentableNode, YangIsFilterContentNodes, InvalidOpTypeHolder {
+
+ private static final long serialVersionUID = 806201608L;
+
+ /**
+ * List of leaves contained.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf-lists contained.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ private List<YangAugment> yangAugmentedInfo;
+
+ /**
+ * Create a rpc input node.
+ */
+ public YangInput() {
+ super(INPUT_NODE, new HashMap<>());
+ listOfLeaf = new LinkedList<>();
+ listOfLeafList = new LinkedList<>();
+ yangAugmentedInfo = new ArrayList<>();
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo context)
+ throws DataModelException {
+ getYsnContextInfoMap().put(id, context);
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ //For non data nodes, mandatory child to be added to parent node.
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier id,
+ YangSchemaNode yangSchemaNode) {
+ //For non data nodes, default child to be added to parent node.
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_SINGLE_INSTANCE_NODE;
+ }
+
+ @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(
+ getErrorMsgCollision(COLLISION_DETECTION, getName(),
+ getLineNumber(), getCharPosition(),
+ INPUT, getFileName()));
+ }
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return 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 unmodifiableList(listOfLeaf);
+ }
+
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+ listOfLeaf.add(leaf);
+ }
+
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return unmodifiableList(listOfLeafList);
+ }
+
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+ listOfLeafList.add(leafList);
+ }
+
+ @Override
+ public void addAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.add(augmentInfo);
+ }
+
+ @Override
+ public void removeAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.remove(augmentInfo);
+ }
+
+ @Override
+ public List<YangAugment> getAugmentedInfoList() {
+ return unmodifiableList(yangAugmentedInfo);
+ }
+
+ @Override
+ public void setLeafNameSpaceAndAddToParentSchemaMap() {
+ // Add namespace for all leafs.
+ for (YangLeaf yangLeaf : listOfLeaf) {
+ yangLeaf.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ // Add namespace for all leaf list.
+ for (YangLeafList yangLeafList : listOfLeafList) {
+ yangLeafList.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ }
+
+ public void cloneAugmentInfo() {
+ yangAugmentedInfo = new ArrayList<>();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIsFilterContentNodes.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIsFilterContentNodes.java
new file mode 100644
index 0000000..ec097c1
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangIsFilterContentNodes.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.yang.compiler.datamodel;
+
+/**
+ * Represent the YANG nodes which can contain is filter content match.
+ */
+public interface YangIsFilterContentNodes {
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java
new file mode 100644
index 0000000..a1cf665
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeaf.java
@@ -0,0 +1,577 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import static org.onosproject.yang.compiler.datamodel.YangStatusType.CURRENT;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.validateEmptyDataType;
+
+/*
+ * 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 | - string |
+ * | description | 7.19.3 | 0..1 | - string |
+ * | if-feature | 7.18.2 | 0..n | - YangIfFeature |
+ * | mandatory | 7.6.5 | 0..1 | - boolean |
+ * | must | 7.5.3 | 0..n | - YangMust |
+ * | reference | 7.19.4 | 0..1 | - string |
+ * | status | 7.19.2 | 0..1 | - YangStatus |
+ * | type | 7.6.3 | 1 | - YangType |
+ * | units | 7.3.3 | 0..1 | - String |
+ * | when | 7.19.5 | 0..1 | - YangWhen |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents leaf data represented in YANG.
+ */
+public abstract class YangLeaf extends DefaultLocationInfo
+ implements YangCommonInfo, Parsable, Cloneable, Serializable,
+ YangMustHolder, YangIfFeatureHolder, YangWhenHolder, YangSchemaNode,
+ YangConfig {
+
+ private static final long serialVersionUID = 806201635L;
+
+ /**
+ * YANG schema node identifier.
+ */
+ private YangSchemaNodeIdentifier yangSchemaNodeIdentifier;
+
+ /**
+ * 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 = 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;
+
+ /**
+ * When data of the leaf.
+ */
+ private YangWhen when;
+
+ /**
+ * YANG Node in which the leaf is contained.
+ */
+ private YangLeavesHolder containedIn;
+
+ /**
+ * List of must statement constraints.
+ */
+ private List<YangMust> mustConstraintList;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
+ * Referred schema leaf.
+ */
+ private YangLeaf referredLeaf;
+
+ private boolean isKeyLeaf;
+ /**
+ * Creates a YANG leaf.
+ */
+ public YangLeaf() {
+ mustConstraintList = new LinkedList<>();
+ ifFeatureList = new LinkedList<>();
+ }
+
+ /**
+ * Returns the config flag.
+ *
+ * @return if config flag
+ */
+ @Override
+ public boolean isConfig() {
+ return isConfig;
+ }
+
+ /**
+ * Sets the config flag.
+ *
+ * @param isConfig the flag value to set
+ */
+ @Override
+ public void setConfig(boolean isConfig) {
+ this.isConfig = isConfig;
+ }
+
+ /**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @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;
+ }
+
+ @Override
+ public boolean isEmptyDataType() {
+ return validateEmptyDataType(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 {
+ YangLeaf cl = (YangLeaf) super.clone();
+ cl.yangSchemaNodeIdentifier = yangSchemaNodeIdentifier.clone();
+ return cl;
+ }
+
+ /**
+ * 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 {
+ if (defaultValueInString != null && !defaultValueInString.isEmpty()
+ && dataType != null) {
+ dataType.isValidValue(defaultValueInString);
+ }
+ }
+
+ @Override
+ public List<YangMust> getListOfMust() {
+ return mustConstraintList;
+ }
+
+ @Override
+ public void setListOfMust(List<YangMust> mustConstraintList) {
+ this.mustConstraintList = mustConstraintList;
+ }
+
+ @Override
+ public void addMust(YangMust must) {
+ if (getListOfMust() == null) {
+ setListOfMust(new LinkedList<>());
+ }
+ getListOfMust().add(must);
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
+ public YangSchemaNodeContextInfo getChildSchema(
+ YangSchemaNodeIdentifier dataNodeIdentifier)
+ throws DataModelException {
+ throw new DataModelException("leaf cannot have any child schema nodes " +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+
+ @Override
+ public void isValueValid(String value)
+ throws DataModelException {
+ getDataType().isValidValue(value);
+ }
+
+ @Override
+ public int getMandatoryChildCount()
+ throws DataModelException {
+ throw new DataModelException("Leaf can't have child. " +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+
+ @Override
+ public Map<YangSchemaNodeIdentifier, YangSchemaNode> getDefaultChild(YangSchemaNodeIdentifier dataNodeIdentifier) {
+ // Returns null as there is no child to leaf.
+ return null;
+ }
+
+ @Override
+ public boolean isNotificationPresent() throws DataModelException {
+ throw new DataModelException("Method is called for node other than module/sub-module.");
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YangSchemaNodeType.YANG_SINGLE_INSTANCE_LEAF_NODE;
+ }
+
+ /**
+ * Sets leaf namespace and add itself to parent child schema map.
+ *
+ * @param nameSpace namespace
+ */
+ public void setLeafNameSpaceAndAddToParentSchemaMap(YangNamespace nameSpace) {
+ setNameSpace(nameSpace);
+ // Process addition of leaf to schema node map.
+ ((YangNode) getContainedIn()).processAdditionOfSchemaNodeToCurNodeMap(getName(), getNameSpace(), this);
+ }
+
+ @Override
+ public YangSchemaNodeIdentifier getYangSchemaNodeIdentifier() {
+ return yangSchemaNodeIdentifier;
+ }
+
+ /**
+ * Sets YANG schema node identifier.
+ *
+ * @param yangSchemaNodeIdentifier YANG schema node identifier
+ */
+ public void setYangSchemaNodeIdentifier(YangSchemaNodeIdentifier
+ yangSchemaNodeIdentifier) {
+ if (this.yangSchemaNodeIdentifier == null) {
+ this.yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
+ }
+ this.yangSchemaNodeIdentifier = yangSchemaNodeIdentifier;
+ }
+
+ /**
+ * Retrieve the name of leaf.
+ *
+ * @return leaf name
+ */
+ public String getName() {
+ return yangSchemaNodeIdentifier.getName();
+ }
+
+ /**
+ * Sets name of node.
+ *
+ * @param name name of the node
+ */
+ public void setName(String name) {
+ if (yangSchemaNodeIdentifier == null) {
+ yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
+ }
+ yangSchemaNodeIdentifier.setName(name);
+ }
+
+ @Override
+ public YangNamespace getNameSpace() {
+ return yangSchemaNodeIdentifier.getNameSpace();
+ }
+
+ /**
+ * Sets namespace of node.
+ *
+ * @param namespace namespace of the node
+ */
+ public void setNameSpace(YangNamespace namespace) {
+ if (yangSchemaNodeIdentifier == null) {
+ yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
+ }
+ yangSchemaNodeIdentifier.setNameSpace(namespace);
+ }
+
+ @Override
+ public YangSchemaNode getNotificationSchemaNode(String notificationNameInEnum)
+ throws DataModelException {
+ throw new DataModelException("Method called for schema node other " +
+ "then module/sub-module");
+ }
+
+ @Override
+ public YangLeaf getReferredSchema() {
+ return referredLeaf;
+ }
+
+ /**
+ * Sets referred schema leaf. This is only applicable for grouping.
+ *
+ * @param leaf referred schema leaf
+ */
+ public void setReferredLeaf(YangLeaf leaf) {
+ referredLeaf = leaf;
+ }
+ /**
+ * Returns true if its a key leaf.
+ *
+ * @return true if its a key leaf
+ */
+ public boolean isKeyLeaf() {
+ return isKeyLeaf;
+ }
+
+ /**
+ * Sets true if its a key leaf.
+ *
+ * @param keyLeaf true if its a key leaf
+ */
+ public void setKeyLeaf(boolean keyLeaf) {
+ isKeyLeaf = keyLeaf;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java
new file mode 100644
index 0000000..2477d1a
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafList.java
@@ -0,0 +1,574 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import static org.onosproject.yang.compiler.datamodel.YangStatusType.CURRENT;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.validateEmptyDataType;
+
+/*
+ * 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 | -YangIfFeature |
+ * | max-elements | 7.7.4 | 0..1 | -int |
+ * | min-elements | 7.7.3 | 0..1 | -int |
+ * | must | 7.5.3 | 0..n | -YangMust |
+ * | ordered-by | 7.7.5 | 0..1 | -TODO |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * | type | 7.4 | 1 | -YangType |
+ * | units | 7.3.3 | 0..1 | -string |
+ * | when | 7.19.5 | 0..1 | -YangWhen |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents leaf-list data represented in YANG.
+ */
+public abstract class YangLeafList extends DefaultLocationInfo
+ implements YangCommonInfo, Parsable, Cloneable, Serializable,
+ YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangSchemaNode,
+ YangConfig {
+
+ private static final long serialVersionUID = 806201637L;
+
+ /**
+ * Name of leaf-list.
+ */
+ private YangSchemaNodeIdentifier yangSchemaNodeIdentifier;
+
+ /**
+ * If the leaf-list is a config parameter.
+ */
+ private boolean isConfig;
+
+ /**
+ * Description of leaf-list.
+ */
+ private String description;
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * 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.
+ * <p>
+ * If no "max-elements" statement is present, it defaults to "unbounded".
+ */
+ private YangMaxElement maxElement;
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * 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.
+ * <p>
+ * If no "min-elements" statement is present, it defaults to zero.
+ * <p>
+ * 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:
+ * <p>
+ * o If this ancestor is a case node, the constraint is enforced if any
+ * other node from the case exists.
+ * <p>
+ * o Otherwise, it is enforced if the ancestor node exists.
+ */
+ private YangMinElement minElements;
+
+ /**
+ * The textual reference to this leaf-list.
+ */
+ private String reference;
+
+ /**
+ * Status of the leaf-list in the YANG definition.
+ */
+ private YangStatusType status = CURRENT;
+
+ /**
+ * Textual units.
+ */
+ private String units;
+
+ /**
+ * Data type of leaf-list.
+ */
+ private YangType<?> dataType;
+
+ /**
+ * YANG Node in which the leaf is contained.
+ */
+ private YangLeavesHolder containedIn;
+
+ /**
+ * List of must statement constraints.
+ */
+ private List<YangMust> mustConstraintList;
+
+ /**
+ * When data of the leaf.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
+ * Referred schema leaf list.
+ */
+ private YangLeafList referredLeafList;
+
+ /**
+ * Creates a YANG leaf-list.
+ */
+ public YangLeafList() {
+ mustConstraintList = new LinkedList<>();
+ ifFeatureList = new LinkedList<>();
+ setMinElements(new YangMinElement());
+ setMaxElements(new YangMaxElement());
+ }
+
+ /**
+ * Returns the config flag.
+ *
+ * @return the config flag
+ */
+ @Override
+ public boolean isConfig() {
+ return isConfig;
+ }
+
+ /**
+ * Sets the config flag.
+ *
+ * @param isConfig the config flag
+ */
+ @Override
+ public void setConfig(boolean isConfig) {
+ this.isConfig = isConfig;
+ }
+
+ /**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @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 maximum elements number.
+ *
+ * @return the maximum elements number
+ */
+ public YangMaxElement getMaxElements() {
+ return maxElement;
+ }
+
+ /**
+ * Sets the maximum elements number.
+ *
+ * @param maxElement maximum elements number
+ */
+ public void setMaxElements(YangMaxElement maxElement) {
+ this.maxElement = maxElement;
+ }
+
+ /**
+ * Returns the minimum elements number.
+ *
+ * @return the minimum elements number
+ */
+ public YangMinElement getMinElements() {
+ return minElements;
+ }
+
+ /**
+ * Sets the minimum elements number.
+ *
+ * @param minElements the minimum elements number
+ */
+ public void setMinElements(YangMinElement 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;
+ }
+
+ @Override
+ public boolean isEmptyDataType() {
+ return validateEmptyDataType(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 {
+ YangLeafList cll = (YangLeafList) super.clone();
+ cll.yangSchemaNodeIdentifier = yangSchemaNodeIdentifier.clone();
+ return cll;
+ }
+
+ /**
+ * 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
+
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
+ public List<YangMust> getListOfMust() {
+ return mustConstraintList;
+ }
+
+ @Override
+ public void setListOfMust(List<YangMust> mustConstraintList) {
+ this.mustConstraintList = mustConstraintList;
+ }
+
+ @Override
+ public void addMust(YangMust must) {
+ if (getListOfMust() == null) {
+ setListOfMust(new LinkedList<>());
+ }
+ getListOfMust().add(must);
+ }
+
+ @Override
+ public YangSchemaNodeContextInfo getChildSchema(
+ YangSchemaNodeIdentifier dataNodeIdentifier)
+ throws DataModelException {
+ throw new DataModelException("leaf cannot have any child schema nodes" +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+
+ @Override
+ public void isValueValid(String value)
+ throws DataModelException {
+ getDataType().isValidValue(value);
+ }
+
+ @Override
+ public int getMandatoryChildCount()
+ throws DataModelException {
+ throw new DataModelException("leaf list can't have child " + getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+
+ @Override
+ public Map<YangSchemaNodeIdentifier, YangSchemaNode> getDefaultChild(YangSchemaNodeIdentifier dataNodeIdentifier) {
+ // Returns null as there is no child to leaf list.
+ return null;
+ }
+
+ @Override
+ public boolean isNotificationPresent() throws DataModelException {
+ throw new DataModelException("Method is called for node other than module/sub-module.");
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YangSchemaNodeType.YANG_MULTI_INSTANCE_LEAF_NODE;
+ }
+
+ /**
+ * Sets leaf namespace and add itself to parent child schema map.
+ *
+ * @param nameSpace namespace
+ */
+ public void setLeafNameSpaceAndAddToParentSchemaMap(YangNamespace nameSpace) {
+ setNameSpace(nameSpace);
+ // Process addition of leaf to schema node map.
+ ((YangNode) getContainedIn()).processAdditionOfSchemaNodeToCurNodeMap(getName(), getNameSpace(), this);
+ }
+
+ @Override
+ public YangSchemaNodeIdentifier getYangSchemaNodeIdentifier() {
+ return yangSchemaNodeIdentifier;
+ }
+
+ /**
+ * Sets YANG schema node identifier.
+ *
+ * @param yangSchemaNodeIdentifier YANG schema node identifier
+ */
+ public void setYangSchemaNodeIdentifier(YangSchemaNodeIdentifier
+ yangSchemaNodeIdentifier) {
+ if (this.yangSchemaNodeIdentifier == null) {
+ this.yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
+ }
+ this.yangSchemaNodeIdentifier = yangSchemaNodeIdentifier;
+ }
+
+ /**
+ * Retrieve the name of leaf list
+ *
+ * @return leaf list name
+ */
+ public String getName() {
+ return yangSchemaNodeIdentifier.getName();
+ }
+
+ /**
+ * Sets name of node.
+ *
+ * @param name name of the node
+ */
+ public void setName(String name) {
+ if (yangSchemaNodeIdentifier == null) {
+ yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
+ }
+ yangSchemaNodeIdentifier.setName(name);
+ }
+
+ @Override
+ public YangNamespace getNameSpace() {
+ return yangSchemaNodeIdentifier.getNameSpace();
+ }
+
+ /**
+ * Sets namespace of node.
+ *
+ * @param namespace namespace of the node
+ */
+ public void setNameSpace(YangNamespace namespace) {
+ if (yangSchemaNodeIdentifier == null) {
+ yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
+ }
+ yangSchemaNodeIdentifier.setNameSpace(namespace);
+ }
+
+ @Override
+ public YangSchemaNode getNotificationSchemaNode(String notificationNameInEnum)
+ throws DataModelException {
+ throw new DataModelException("Method called for schema node other then module/sub-module");
+ }
+
+ @Override
+ public YangLeafList getReferredSchema() {
+ return referredLeafList;
+ }
+
+ /**
+ * Sets referred schema leaf-list. This is only applicable for grouping.
+ *
+ * @param leafList referred schema leaf-list
+ */
+ public void setReferredSchemaLeafList(YangLeafList leafList) {
+ referredLeafList = leafList;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafRef.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafRef.java
new file mode 100644
index 0000000..cdefeda
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeafRef.java
@@ -0,0 +1,553 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.RESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.LEAFREF_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.YangErrMsgConstants.DATA_MISSING_ERROR_TAG;
+import static org.onosproject.yang.compiler.datamodel.utils.YangErrMsgConstants.ERROR_PATH_LEAFREF_LEAF;
+import static org.onosproject.yang.compiler.datamodel.utils.YangErrMsgConstants.INSTANCE_REQUIRED_ERROR_APP_TAG;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
+
+/*
+ * Reference:RFC 6020.
+ * The leafref type is used to reference a particular leaf instance in
+ * the data tree. The "path" substatement (Section 9.9.2) selects a set
+ * of leaf instances, and the leafref value space is the set of values
+ * of these leaf instances.
+ */
+
+/**
+ * Represents the leafref information.
+ *
+ * @param <T> YANG leafref info
+ */
+public class YangLeafRef<T> extends DefaultLocationInfo
+ implements Cloneable, Parsable, Resolvable, Serializable, YangIfFeatureHolder,
+ YangXPathResolver, YangAppErrorHolder {
+
+ private static final long serialVersionUID = 286201644L;
+
+ /**
+ * YANG data type.
+ */
+ private YangType effectiveDataType;
+
+ /**
+ * Referred leaf/leaf-list for the path specified in the leafref type.
+ */
+ private T referredLeafOrLeafList;
+
+ /**
+ * Path of the leafref.
+ */
+ private String path;
+
+ /**
+ * Leafref path type. Either absolute or relative path.
+ */
+ private YangPathArgType pathType;
+
+ /**
+ * List of atomic paths in absolute Path.
+ */
+ private List<YangAtomicPath> atomicPath;
+
+ /**
+ * YANG relative path.
+ */
+ private YangRelativePath relativePath;
+
+ /**
+ * Status of resolution. If completely resolved enum value is "RESOLVED",
+ * if not enum value is "UNRESOLVED", in case reference of grouping/typedef/leafref
+ * is added to uses/type/leafref but it's not resolved value of enum should be
+ * "INTRA_FILE_RESOLVED".
+ */
+ private ResolvableStatus resolvableStatus;
+
+ /**
+ * Require instance status in leafref type.
+ */
+ private boolean requireInstance;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
+ * Parent node of the leafref's leaf.
+ */
+ private YangNode parentNode;
+
+ /**
+ * Prefix in the nodes of the leafref path and its imported node name.
+ */
+ private Map<String, String> prefixAndNode;
+
+ /**
+ * Flag to indicate whether the leaf ref is inside grouping.
+ */
+ private boolean inGrouping;
+
+ /**
+ * Returns the prefix in the leafref path and its imported node name.
+ *
+ * @return map of prefix with node
+ */
+ public Map<String, String> getPrefixAndNode() {
+ return prefixAndNode;
+ }
+
+ /**
+ * Sets the prefix in the leaf-ref path and its imported node name.
+ *
+ * @param prefixAndNode prefix with node map
+ */
+ public void setPrefixAndNode(Map<String, String> prefixAndNode) {
+ this.prefixAndNode = prefixAndNode;
+ }
+
+ /**
+ * Returns the parent node from the leafref's leaf.
+ *
+ * @return parent node of the leafref
+ */
+ public YangNode getParentNode() {
+ return parentNode;
+ }
+
+ /**
+ * Sets the parent node from the leafref's leaf.
+ *
+ * @param parentNode parent node
+ */
+ public void setParentNode(YangNode parentNode) {
+ this.parentNode = parentNode;
+ }
+
+ /**
+ * YANG application error information.
+ */
+ private YangAppErrorInfo yangAppErrorInfo;
+
+ /**
+ * Creates a YANG leaf ref.
+ */
+ public YangLeafRef() {
+ yangAppErrorInfo = new YangAppErrorInfo();
+ prefixAndNode = new HashMap<>();
+ atomicPath = new ArrayList<>();
+ ifFeatureList = new ArrayList<>();
+ yangAppErrorInfo.setErrorTag(DATA_MISSING_ERROR_TAG);
+ yangAppErrorInfo.setErrorAppTag(INSTANCE_REQUIRED_ERROR_APP_TAG);
+ yangAppErrorInfo.setErrorAppPath(ERROR_PATH_LEAFREF_LEAF);
+ }
+
+ /**
+ * Returns the status of the require instance in leafref.
+ *
+ * @return status of the require instance
+ */
+ public boolean getRequireInstance() {
+ return requireInstance;
+ }
+
+ /**
+ * Sets the status of the require instance in leafref.
+ *
+ * @param requireInstance status of the require instance
+ */
+ public void setRequireInstance(boolean requireInstance) {
+ this.requireInstance = requireInstance;
+ }
+
+ /**
+ * Returns the type of data.
+ *
+ * @return the data type
+ */
+ public YangType getEffectiveDataType() {
+ return effectiveDataType;
+ }
+
+ /**
+ * Sets the type of data.
+ *
+ * @param effectiveDataType data type
+ */
+ public void setEffectiveDataType(YangType effectiveDataType) {
+ this.effectiveDataType = effectiveDataType;
+ }
+
+ /**
+ * Returns the path of the leafref.
+ *
+ * @return path of the leafref
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * Sets the path of the leafref.
+ *
+ * @param path leafref path
+ */
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ /**
+ * Returns the type of path in the leafref.
+ *
+ * @return type of path
+ */
+ public YangPathArgType getPathType() {
+ return pathType;
+ }
+
+ /**
+ * Sets the type of path in the leafref. It can be either absolute or relative type.
+ *
+ * @param pathType type of path
+ */
+ public void setPathType(YangPathArgType pathType) {
+ this.pathType = pathType;
+ }
+
+ /**
+ * Returns the list of atomic path.
+ *
+ * @return list of atomic path
+ */
+ public List<YangAtomicPath> getAtomicPath() {
+ return unmodifiableList(atomicPath);
+ }
+
+ /**
+ * Sets the list of atomic path.
+ *
+ * @param atomicPath list of atomic path.
+ */
+ public void setAtomicPath(List<YangAtomicPath> atomicPath) {
+ this.atomicPath = atomicPath;
+ }
+
+ /**
+ * Returns the object of relative path.
+ *
+ * @return object of relative path
+ */
+ public YangRelativePath getRelativePath() {
+ return relativePath;
+ }
+
+ /**
+ * Sets the object of relative path.
+ *
+ * @param relativePath object of relative path.
+ */
+ public void setRelativePath(YangRelativePath relativePath) {
+ this.relativePath = relativePath;
+ }
+
+ /**
+ * Returns the object of referred leaf/leaf-list.
+ *
+ * @return object of referred leaf/leaf-list
+ */
+ public T getReferredLeafOrLeafList() {
+ return referredLeafOrLeafList;
+ }
+
+ /**
+ * Sets the object of referred leaf/leaf-list.
+ *
+ * @param targetExtendedInfo object of referred leaf/leaf-list
+ */
+ public void setReferredLeafOrLeafList(T targetExtendedInfo) {
+ this.referredLeafOrLeafList = targetExtendedInfo;
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return unmodifiableList(ifFeatureList);
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ ifFeatureList.add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return LEAFREF_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry()
+ throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ @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 setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
+ this.yangAppErrorInfo = yangAppErrorInfo;
+ }
+
+ @Override
+ public YangAppErrorInfo getAppErrorInfo() {
+ return yangAppErrorInfo;
+ }
+
+ @Override
+ public Object resolve()
+ throws DataModelException {
+
+ if (getReferredLeafOrLeafList() == null) {
+ throw new DataModelException("Linker Error: The leafref does not refer to any leaf/leaf-list." +
+ " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+
+ // Initiate the resolution
+ try {
+ setResolvableStatus(getResolution());
+ } catch (DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
+ return null;
+ }
+
+ /**
+ * Returns the resolution status by getting the effective built-in type.
+ *
+ * @return status of resolution
+ * @throws DataModelException a violation of data model rules
+ */
+ private ResolvableStatus getResolution()
+ throws DataModelException {
+
+ if (getReferredLeafOrLeafList() instanceof YangLeaf) {
+ YangLeaf yangLeaf = ((YangLeaf) getReferredLeafOrLeafList());
+ YangType baseType = yangLeaf.getDataType();
+
+ if (baseType.getDataType() == LEAFREF) {
+ YangLeafRef referredLeafRefInfo = (YangLeafRef) (yangLeaf.getDataType().getDataTypeExtendedInfo());
+
+ //Check whether the referred typedef is resolved.
+ if (referredLeafRefInfo.getResolvableStatus() != INTRA_FILE_RESOLVED
+ && referredLeafRefInfo.getResolvableStatus() != RESOLVED) {
+ throw new DataModelException("Linker Error: Referred typedef is not resolved for type." +
+ " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+
+ /*
+ * Check if the referred typedef is intra file resolved, if yes
+ * sets current status also to intra file resolved .
+ */
+ if ((referredLeafRefInfo.getResolvableStatus() == INTRA_FILE_RESOLVED)) {
+ return INTRA_FILE_RESOLVED;
+ }
+
+ // Add the if-feature list from referred leafref to current leafref.
+ List<YangIfFeature> referredLeafIfFeatureListFromLeafref = referredLeafRefInfo.getIfFeatureList();
+ if (referredLeafIfFeatureListFromLeafref != null && !referredLeafIfFeatureListFromLeafref.isEmpty()) {
+ Iterator<YangIfFeature> referredLeafIfFeature = referredLeafIfFeatureListFromLeafref.iterator();
+ while (referredLeafIfFeature.hasNext()) {
+ YangIfFeature ifFeature = referredLeafIfFeature.next();
+ addIfFeatureList(ifFeature);
+ }
+ }
+ setEffectiveDataType(referredLeafRefInfo.getEffectiveDataType());
+ } else if (baseType.getDataType() == YangDataTypes.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." +
+ " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ /*
+ * Check if the referred typedef is intra file resolved, if yes
+ * sets current status also to intra file resolved .
+ */
+ if ((baseType.getResolvableStatus() == INTRA_FILE_RESOLVED)) {
+ return INTRA_FILE_RESOLVED;
+ }
+ setEffectiveDataType(baseType);
+ } else {
+ setEffectiveDataType(baseType);
+ }
+
+ // Add the if-feature list from referred leaf to current leafref.
+ List<YangIfFeature> referredLeafIfFeatureList = yangLeaf.getIfFeatureList();
+ if (referredLeafIfFeatureList != null && !referredLeafIfFeatureList.isEmpty()) {
+ Iterator<YangIfFeature> referredLeafIfFeature = referredLeafIfFeatureList.iterator();
+ while (referredLeafIfFeature.hasNext()) {
+ YangIfFeature ifFeature = referredLeafIfFeature.next();
+ addIfFeatureList(ifFeature);
+ }
+ }
+ return RESOLVED;
+ } else if (getReferredLeafOrLeafList() instanceof YangLeafList) {
+ YangLeafList yangLeafList = ((YangLeafList) getReferredLeafOrLeafList());
+ YangType baseType = yangLeafList.getDataType();
+
+ if (baseType.getDataType() == LEAFREF) {
+ YangLeafRef referredLeafRefInfo = (YangLeafRef) yangLeafList.getDataType().getDataTypeExtendedInfo();
+
+ //Check whether the referred typedef is resolved.
+ if (referredLeafRefInfo.getResolvableStatus() != INTRA_FILE_RESOLVED
+ && referredLeafRefInfo.getResolvableStatus() != RESOLVED) {
+ throw new DataModelException("Linker Error: Referred typedef is not resolved for type." +
+ " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ /*
+ * Check if the referred typedef is intra file resolved, if yes
+ * sets current status also to intra file resolved .
+ */
+ if ((referredLeafRefInfo.getResolvableStatus() == INTRA_FILE_RESOLVED)) {
+ return INTRA_FILE_RESOLVED;
+ }
+ // Add the if-feature list from referred leafref to current leafref.
+ List<YangIfFeature> referredLeafListIfFeatureListFromLeafref = referredLeafRefInfo.getIfFeatureList();
+ if (referredLeafListIfFeatureListFromLeafref != null
+ && !referredLeafListIfFeatureListFromLeafref.isEmpty()) {
+ Iterator<YangIfFeature> referredLeafListIfFeature = referredLeafListIfFeatureListFromLeafref
+ .iterator();
+ while (referredLeafListIfFeature.hasNext()) {
+ YangIfFeature ifFeature = referredLeafListIfFeature.next();
+ addIfFeatureList(ifFeature);
+ }
+ }
+ setEffectiveDataType(referredLeafRefInfo.getEffectiveDataType());
+ } else if (baseType.getDataType() == YangDataTypes.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." +
+ " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ /*
+ * Check if the referred typedef is intra file resolved, if yes
+ * sets current status also to intra file resolved .
+ */
+ if ((baseType.getResolvableStatus() == INTRA_FILE_RESOLVED)) {
+ return INTRA_FILE_RESOLVED;
+ }
+ setEffectiveDataType(baseType);
+ } else {
+ setEffectiveDataType(baseType);
+ }
+ // Add the if-feature list from referred leaf-list to current leafref.
+ List<YangIfFeature> referredLeafListIfFeatureList = yangLeafList.getIfFeatureList();
+ if (referredLeafListIfFeatureList != null && !referredLeafListIfFeatureList.isEmpty()) {
+ Iterator<YangIfFeature> referredLeafListIfFeature = referredLeafListIfFeatureList.iterator();
+ while (referredLeafListIfFeature.hasNext()) {
+ YangIfFeature ifFeature = referredLeafListIfFeature.next();
+ addIfFeatureList(ifFeature);
+ }
+ }
+ return RESOLVED;
+ } else {
+ throw new DataModelException("Linker Error: The leafref must refer only to leaf/leaf-list." +
+ " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+
+ @Override
+ public YangLeafRef<T> clone()
+ throws CloneNotSupportedException {
+ YangLeafRef<T> clonedLeafRef = (YangLeafRef<T>) super.clone();
+ return clonedLeafRef;
+ }
+
+ /**
+ * Returns flag value indicating whether leafref is inside grouping.
+ *
+ * @return true if leafref is in grouping, false otherwise
+ */
+ public boolean isInGrouping() {
+ return inGrouping;
+ }
+
+ /**
+ * Sets in grouping flag.
+ *
+ * @param inGrouping flag
+ */
+ public void setInGrouping(boolean inGrouping) {
+ this.inGrouping = inGrouping;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeavesHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeavesHolder.java
new file mode 100644
index 0000000..ad39253
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLeavesHolder.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.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 extends LocationInfo {
+
+ /**
+ * 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);
+
+ /**
+ * Adds namespace for leafs and leaf-list, this is used in case of
+ * submodule.
+ *
+ */
+ void setLeafNameSpaceAndAddToParentSchemaMap();
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLengthRestriction.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLengthRestriction.java
new file mode 100644
index 0000000..797d1a3
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangLengthRestriction.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangUint64;
+
+import java.io.Serializable;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.PATTERN_DATA;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * Binary can be restricted with "length" statements alone.
+ *
+ */
+
+/**
+ * Represents the restriction for length data type.
+ */
+public class YangLengthRestriction extends DefaultLocationInfo
+ implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder {
+
+ /*-
+ * 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;
+
+ /**
+ * Textual description.
+ */
+ private String description;
+
+ /**
+ * YANG application error information.
+ */
+ private YangAppErrorInfo yangAppErrorInfo;
+
+ /**
+ * Creates a YANG length restriction object.
+ */
+ public YangLengthRestriction() {
+ setLengthRestriction(new YangRangeRestriction<>());
+ yangAppErrorInfo = new YangAppErrorInfo();
+ }
+
+ /**
+ * 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;
+
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return PATTERN_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO: implement the method.
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO: implement the method.
+ }
+
+ /**
+ * Sets the application's error information.
+ *
+ * @param yangAppErrorInfo the application's error information
+ */
+ @Override
+ public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
+ this.yangAppErrorInfo = yangAppErrorInfo;
+ }
+
+ /**
+ * Returns application's error information.
+ *
+ * @return application's error information
+ */
+ @Override
+ public YangAppErrorInfo getAppErrorInfo() {
+ return yangAppErrorInfo;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangList.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangList.java
new file mode 100644
index 0000000..343a8f2
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangList.java
@@ -0,0 +1,804 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.DataModelUtils;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.LIST_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_MULTI_INSTANCE_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangStatusType.CURRENT;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.LIST_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
+
+/*
+ * 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 |-YangIfFeature |
+ * | key | 7.8.2 | 0..1 |-String list |
+ * | leaf | 7.6 | 0..n |-YangLeaf |
+ * | leaf-list | 7.7 | 0..n |-YangLeafList |
+ * | list | 7.8 | 0..n |-child nodes |
+ * | max-elements | 7.7.4 | 0..1 |-int |
+ * | min-elements | 7.7.3 | 0..1 |-int |
+ * | must | 7.5.3 | 0..n |-YangMust |
+ * | ordered-by | 7.7.5 | 0..1 |-TODO |
+ * | reference | 7.19.4 | 0..1 |-string |
+ * | status | 7.19.2 | 0..1 |-YangStatus |
+ * | typedef | 7.3 | 0..n |-child nodes |
+ * | unique | 7.8.3 | 0..n |-TODO |
+ * | uses | 7.12 | 0..n |-child nodes |
+ * | when | 7.19.5 | 0..1 |-YangWhen |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents list data represented in YANG.
+ */
+public abstract class YangList
+ extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
+ YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangSchemaNode,
+ YangIsFilterContentNodes, YangConfig {
+
+ private static final long serialVersionUID = 806201609L;
+
+ /**
+ * If list maintains config data.
+ */
+ private boolean isConfig;
+
+ /**
+ * Description of list.
+ */
+ private String description;
+
+ /**
+ * Reference RFC 6020.
+ * <p>
+ * 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.
+ * <p>
+ * 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.
+ * <p>
+ * 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".
+ * <p>
+ * All key leafs in a list MUST have the same value for their "config" as
+ * the list itself.
+ * <p>
+ * List of key leaf names.
+ */
+ private List<String> keyList;
+
+ /**
+ * Reference RFC 6020.
+ * <p>
+ * The "unique" statement is used to put constraints on valid list
+ * entries. It takes as an argument a string that contains a space-
+ * separated list of schema node identifiers, which MUST be given in the
+ * descendant form. Each such schema node identifier MUST refer to a leaf.
+ * <p>
+ * If one of the referenced leafs represents configuration data, then
+ * all of the referenced leafs MUST represent configuration data.
+ * <p>
+ * The "unique" constraint specifies that the combined values of all the
+ * leaf instances specified in the argument string, including leafs with
+ * default values, MUST be unique within all list entry instances in
+ * which all referenced leafs exist.
+ * <p>
+ * List of unique leaf/leaf-list names
+ */
+ private List<String> uniqueList;
+
+ /**
+ * List of leaves.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf-lists.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ private List<YangAugment> yangAugmentedInfo = new ArrayList<>();
+
+ /**
+ * Reference RFC 6020.
+ * <p>
+ * 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.
+ * <p>
+ * If no "max-elements" statement is present, it defaults to "unbounded".
+ */
+ private YangMaxElement maxElements;
+
+ /**
+ * Reference RFC 6020.
+ * <p>
+ * 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.
+ * <p>
+ * If no "min-elements" statement is present, it defaults to zero.
+ * <p>
+ * 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:
+ * <p>
+ * o If this ancestor is a case node, the constraint is enforced if any
+ * other node from the case exists.
+ * <p>
+ * o Otherwise, it is enforced if the ancestor node exists.
+ */
+ private YangMinElement minElements;
+
+ /**
+ * reference.
+ */
+ private String reference;
+
+ /**
+ * Status of the node.
+ */
+ private YangStatusType status = CURRENT;
+
+ /**
+ * List of must statement constraints.
+ */
+ private List<YangMust> mustConstraintList;
+
+ /**
+ * When data of the node.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
+ * Compiler Annotation.
+ */
+ private transient YangCompilerAnnotation compilerAnnotation;
+
+ /**
+ * Creates a YANG list object.
+ */
+ public YangList() {
+ super(LIST_NODE, new HashMap<>());
+ listOfLeaf = new LinkedList<>();
+ listOfLeafList = new LinkedList<>();
+ mustConstraintList = new LinkedList<>();
+ ifFeatureList = new LinkedList<>();
+ uniqueList = new LinkedList<>();
+ keyList = new LinkedList<>();
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier schemaNodeIdentifier,
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo) {
+ getYsnContextInfoMap().put(schemaNodeIdentifier, yangSchemaNodeContextInfo);
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier, YangSchemaNode yangSchemaNode) {
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_MULTI_INSTANCE_NODE;
+ }
+
+ /**
+ * Returns the compiler annotation.
+ *
+ * @return the compiler annotation
+ */
+ public YangCompilerAnnotation getCompilerAnnotation() {
+ return compilerAnnotation;
+ }
+
+ /**
+ * Sets the compiler annotation.
+ *
+ * @param compilerAnnotation the compiler annotation to set
+ */
+ public void setCompilerAnnotation(YangCompilerAnnotation compilerAnnotation) {
+ this.compilerAnnotation = compilerAnnotation;
+ }
+
+ /**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
+ * Returns the config flag.
+ *
+ * @return the isConfig
+ */
+ @Override
+ public boolean isConfig() {
+ return isConfig;
+ }
+
+ /**
+ * Sets the config flag.
+ *
+ * @param isConfig the config flag
+ */
+ @Override
+ public void setConfig(boolean isConfig) {
+ this.isConfig = isConfig;
+ }
+
+ /**
+ * 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 unique field names.
+ *
+ * @return the list of unique field names
+ */
+ public List<String> getUniqueList() {
+ return uniqueList;
+ }
+
+ /**
+ * Sets the list of unique field names.
+ *
+ * @param uniqueList the list of unique field names
+ */
+ private void setUniqueList(List<String> uniqueList) {
+ this.uniqueList = uniqueList;
+ }
+
+ /**
+ * 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<>());
+ }
+
+ if (getKeyList().contains(key)) {
+ throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
+ " key" +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+
+ getKeyList().add(key);
+ }
+
+ /**
+ * Adds a unique field name.
+ *
+ * @param unique unique field name.
+ * @throws DataModelException a violation of data model rules
+ */
+ public void addUnique(String unique)
+ throws DataModelException {
+ if (getUniqueList() == null) {
+ setUniqueList(new LinkedList<>());
+ }
+ if (getUniqueList().contains(unique)) {
+ throw new DataModelException("A leaf identifier must not appear more than once in the\n" +
+ " unique" +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ getUniqueList().add(unique);
+ }
+
+ /**
+ * 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 max elements.
+ *
+ * @return the max elements
+ */
+ public YangMaxElement getMaxElements() {
+ return maxElements;
+ }
+
+ /**
+ * Sets the max elements.
+ *
+ * @param max the max elements
+ */
+ public void setMaxElements(YangMaxElement max) {
+ this.maxElements = max;
+ }
+
+ /**
+ * Returns the minimum elements.
+ *
+ * @return the minimum elements
+ */
+ public YangMinElement getMinElements() {
+ return minElements;
+ }
+
+ /**
+ * Sets the minimum elements.
+ *
+ * @param minElements the minimum elements
+ */
+ public void setMinElements(YangMinElement 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 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();
+
+ validateConfig(leaves, leafLists);
+
+ //A list must have atleast one key leaf if config is true
+ if (isConfig && (keys.isEmpty() || leaves.isEmpty()) && !isUsesPresentInList()
+ && !isListPresentInGrouping()) {
+ throw new DataModelException("A list must have atleast one key leaf if config is true; " +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ } else if (keys != null) {
+ validateKey(leaves, keys);
+ }
+ }
+
+ /**
+ * 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\"." +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+ }
+
+ 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\"." + getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+ }
+ }
+
+ /**
+ * Validates key statement of list.
+ *
+ * @param leaves list of leaf 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<String> keys)
+ throws DataModelException {
+ boolean leafFound = false;
+ List<YangLeaf> keyLeaves = 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() == EMPTY) {
+ throw new DataModelException(" A leaf that is part of the key must not be the built-in " +
+ "type \"empty\"." +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ leafFound = true;
+ keyLeaves.add(leaf);
+ break;
+ }
+ }
+ }
+
+ if (!leafFound && !isUsesPresentInList() && !isListPresentInGrouping()) {
+ throw new DataModelException("An identifier, in key, must refer to a child leaf of the list" +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ 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." +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Asks helper to detect colliding child.
+ DataModelUtils.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() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+
+ 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.
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return ifFeatureList;
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (getIfFeatureList() == null) {
+ setIfFeatureList(new LinkedList<>());
+ }
+ getIfFeatureList().add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
+ public List<YangMust> getListOfMust() {
+ return mustConstraintList;
+ }
+
+ @Override
+ public void setListOfMust(List<YangMust> mustConstraintList) {
+ this.mustConstraintList = mustConstraintList;
+ }
+
+ @Override
+ public void addMust(YangMust must) {
+ if (getListOfMust() == null) {
+ setListOfMust(new LinkedList<>());
+ }
+ getListOfMust().add(must);
+ }
+
+ @Override
+ public void addAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.add(augmentInfo);
+ }
+
+ @Override
+ public void removeAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.remove(augmentInfo);
+ }
+
+ @Override
+ public List<YangAugment> getAugmentedInfoList() {
+ return yangAugmentedInfo;
+ }
+
+ @Override
+ public void setLeafNameSpaceAndAddToParentSchemaMap() {
+ // Add namespace for all leafs.
+ for (YangLeaf yangLeaf : getListOfLeaf()) {
+ yangLeaf.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ // Add namespace for all leaf list.
+ for (YangLeafList yangLeafList : getListOfLeafList()) {
+ yangLeafList.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ }
+
+ public void cloneAugmentInfo() {
+ yangAugmentedInfo = new ArrayList<>();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMaxElement.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMaxElement.java
new file mode 100644
index 0000000..5ccd572
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMaxElement.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import java.io.Serializable;
+
+import static java.lang.Integer.MAX_VALUE;
+import static org.onosproject.yang.compiler.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
+import static org.onosproject.yang.compiler.datamodel.utils.YangErrMsgConstants.TOO_MANY_ELEMENTS_ERROR_APP_TAG;
+
+/**
+ * Represents max element data represented in YANG.
+ */
+public class YangMaxElement extends DefaultLocationInfo
+ implements YangAppErrorHolder, Serializable {
+
+ private static final long serialVersionUID = 807201694L;
+
+ /**
+ * YANG application error information.
+ */
+ private YangAppErrorInfo yangAppErrorInfo;
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * 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.
+ * <p>
+ * If no "max-elements" statement is present, it defaults to "unbounded".
+ */
+ private int maxElement = MAX_VALUE;
+
+ /**
+ * Creates a YANG maximum element.
+ */
+ public YangMaxElement() {
+ yangAppErrorInfo = new YangAppErrorInfo();
+ yangAppErrorInfo.setErrorTag(OPERATION_FAILED_ERROR_TAG);
+ yangAppErrorInfo.setErrorAppTag(TOO_MANY_ELEMENTS_ERROR_APP_TAG);
+ }
+
+ /**
+ * Returns the maximum element value.
+ *
+ * @return the maximum element value
+ */
+ public int getMaxElement() {
+ return maxElement;
+ }
+
+ /**
+ * Sets the maximum element value.
+ *
+ * @param maxElement the maximum element value
+ */
+ public void setMaxElement(int maxElement) {
+ this.maxElement = maxElement;
+ }
+
+ @Override
+ public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
+ this.yangAppErrorInfo = yangAppErrorInfo;
+ }
+
+ @Override
+ public YangAppErrorInfo getAppErrorInfo() {
+ return yangAppErrorInfo;
+ }
+}
\ No newline at end of file
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMinElement.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMinElement.java
new file mode 100644
index 0000000..0c04837
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMinElement.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import java.io.Serializable;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
+import static org.onosproject.yang.compiler.datamodel.utils.YangErrMsgConstants.TOO_FEW_ELEMENTS_ERROR_APP_TAG;
+
+/**
+ * Represents minimum element data represented in YANG.
+ */
+public class YangMinElement extends DefaultLocationInfo
+ implements YangAppErrorHolder, Serializable {
+
+ private static final long serialVersionUID = 807201695L;
+
+ /**
+ * YANG application error information.
+ */
+ private YangAppErrorInfo yangAppErrorInfo;
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * 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.
+ * <p>
+ * If no "min-elements" statement is present, it defaults to zero.
+ * <p>
+ * 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:
+ * <p>
+ * If this ancestor is a case node, the constraint is enforced if any
+ * other node from the case exists.
+ * <p>
+ * Otherwise, it is enforced if the ancestor node exists.
+ */
+ private int minElement;
+
+ /**
+ * Creates a YANG minimum element.
+ */
+ public YangMinElement() {
+ yangAppErrorInfo = new YangAppErrorInfo();
+ yangAppErrorInfo.setErrorTag(OPERATION_FAILED_ERROR_TAG);
+ yangAppErrorInfo.setErrorAppTag(TOO_FEW_ELEMENTS_ERROR_APP_TAG);
+ }
+
+ /**
+ * Returns the minimum element value.
+ *
+ * @return the minimum element value
+ */
+ public int getMinElement() {
+ return minElement;
+ }
+
+ /**
+ * Sets the minimum element value.
+ *
+ * @param minElement the minimum element value
+ */
+ public void setMinElement(int minElement) {
+ this.minElement = minElement;
+ }
+
+ @Override
+ public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
+ this.yangAppErrorInfo = yangAppErrorInfo;
+ }
+
+ @Override
+ public YangAppErrorInfo getAppErrorInfo() {
+ return yangAppErrorInfo;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangModule.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangModule.java
new file mode 100644
index 0000000..360b192
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangModule.java
@@ -0,0 +1,820 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_AUGMENT;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_BASE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_COMPILER_ANNOTATION;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_DERIVED_DATA_TYPE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IDENTITYREF;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IF_FEATURE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_LEAFREF;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_USES;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_SINGLE_INSTANCE_NODE;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.linkInterFileReferences;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.MODULE_DATA;
+
+/*-
+ * 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 abstract class YangModule
+ extends YangNode
+ implements YangLeavesHolder, YangDesc, YangReference, Parsable,
+ CollisionDetector, YangReferenceResolver, RpcNotificationContainer,
+ YangFeatureHolder, YangIsFilterContentNodes, YangNamespace {
+
+ private static final long serialVersionUID = 806201610L;
+
+ /**
+ * 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;
+
+ /**
+ * List of feature at root level in the module.
+ */
+ private List<YangFeature> listOfFeature;
+
+ /**
+ * 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 un-prefixed 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;
+
+ /**
+ * If-feature resolution list.
+ */
+ private List<YangResolutionInfo> ifFeatureResolutionList;
+
+ /**
+ * LeafRef resolution list.
+ */
+ private List<YangResolutionInfo> leafRefResolutionList;
+
+ /**
+ * Base resolution list.
+ */
+ private List<YangResolutionInfo> baseResolutionList;
+
+ /**
+ * IdentityRef resolution list.
+ */
+ private List<YangResolutionInfo> identityRefResolutionList;
+
+ /**
+ * Augment resolution list.
+ */
+ private List<YangResolutionInfo> augmentResolutionList;
+
+ /**
+ * Compiler annotation list.
+ */
+ private List<YangResolutionInfo> compilerAnnotationList;
+
+ /**
+ * Extension list.
+ */
+ private List<YangExtension> extensionList;
+
+ /**
+ * Flag to indicate the presence of notification.
+ */
+ private boolean isNotificationPresent;
+
+ /**
+ * Map of notification enum.
+ */
+ private final Map<String, YangSchemaNode> notificationEnumMap;
+
+ /**
+ * List of augments which augmenting to an input in rpc.
+ */
+ private final List<YangAugment> augments;
+
+ /**
+ * YANG defined namespace.
+ */
+ private String namespace;
+
+ /**
+ * Creates a YANG node of module type.
+ */
+ public YangModule() {
+
+ super(YangNodeType.MODULE_NODE, new HashMap<>());
+ derivedTypeResolutionList = new LinkedList<>();
+ augmentResolutionList = new LinkedList<>();
+ usesResolutionList = new LinkedList<>();
+ ifFeatureResolutionList = new LinkedList<>();
+ leafRefResolutionList = new LinkedList<>();
+ baseResolutionList = new LinkedList<>();
+ identityRefResolutionList = new LinkedList<>();
+ compilerAnnotationList = new LinkedList<>();
+ importList = new LinkedList<>();
+ includeList = new LinkedList<>();
+ listOfLeaf = new LinkedList<>();
+ listOfLeafList = new LinkedList<>();
+ extensionList = new LinkedList<>();
+ listOfFeature = new LinkedList<>();
+ notificationEnumMap = new HashMap<>();
+ augments = new LinkedList<>();
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo context) {
+ getYsnContextInfoMap().put(id, context);
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier id,
+ YangSchemaNode node) {
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_SINGLE_INSTANCE_NODE;
+ }
+
+ /**
+ * 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 unmodifiableList(importList);
+ }
+
+ /**
+ * Adds the imported module information to the import list.
+ *
+ * @param importedModule module being imported
+ */
+ @Override
+ public void addToImportList(YangImport importedModule) {
+ importList.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 unmodifiableList(includeList);
+ }
+
+ /**
+ * Adds the included sub module information to the include list.
+ *
+ * @param includeModule submodule being included
+ */
+ @Override
+ public void addToIncludeList(YangInclude includeModule) {
+ includeList.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 unmodifiableList(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) {
+ listOfLeaf.add(leaf);
+ }
+
+ /**
+ * Returns the list of leaf-list from module.
+ *
+ * @return the list of leaf-list
+ */
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return unmodifiableList(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) {
+ listOfLeafList.add(leafList);
+ }
+
+ @Override
+ public List<YangFeature> getFeatureList() {
+ return unmodifiableList(listOfFeature);
+ }
+
+ @Override
+ public void addFeatureList(YangFeature feature) {
+ listOfFeature.add(feature);
+ }
+
+ @Override
+ public void setListOfFeature(List<YangFeature> listOfFeature) {
+ this.listOfFeature = listOfFeature;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Adds extension in extension list.
+ *
+ * @param extension the extension to be added
+ */
+ public void addExtension(YangExtension extension) {
+ extensionList.add(extension);
+ }
+
+ /**
+ * Returns the extension list.
+ *
+ * @return the extension list
+ */
+ public List<YangExtension> getExtensionList() {
+ return unmodifiableList(extensionList);
+ }
+
+ /**
+ * Sets the extension list.
+ *
+ * @param extensionList the list of extension
+ */
+ protected void setExtensionList(List<YangExtension> extensionList) {
+ this.extensionList = extensionList;
+ }
+
+ /**
+ * Adds to extension list.
+ *
+ * @param extension YANG extension
+ */
+ public void addToExtensionList(YangExtension extension) {
+ extensionList.add(extension);
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns MODULE_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return 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 == YANG_DERIVED_DATA_TYPE) {
+ return unmodifiableList(derivedTypeResolutionList);
+ } else if (type == YANG_USES) {
+ return unmodifiableList(usesResolutionList);
+ } else if (type == YANG_AUGMENT) {
+ return unmodifiableList(augmentResolutionList);
+ } else if (type == YANG_IF_FEATURE) {
+ return unmodifiableList(ifFeatureResolutionList);
+ } else if (type == YANG_LEAFREF) {
+ return unmodifiableList(leafRefResolutionList);
+ } else if (type == YANG_BASE) {
+ return unmodifiableList(baseResolutionList);
+ } else if (type == YANG_IDENTITYREF) {
+ return unmodifiableList(identityRefResolutionList);
+ } else {
+ return unmodifiableList(compilerAnnotationList);
+ }
+ }
+
+ @Override
+ public void addToResolutionList(YangResolutionInfo info,
+ ResolvableType type) {
+ if (type == YANG_DERIVED_DATA_TYPE) {
+ derivedTypeResolutionList.add(info);
+ } else if (type == YANG_USES) {
+ usesResolutionList.add(info);
+ } else if (type == YANG_IF_FEATURE) {
+ ifFeatureResolutionList.add(info);
+ } else if (type == YANG_LEAFREF) {
+ leafRefResolutionList.add(info);
+ } else if (type == YANG_BASE) {
+ baseResolutionList.add(info);
+ } else if (type == YANG_AUGMENT) {
+ augmentResolutionList.add(info);
+ } else if (type == YANG_IDENTITYREF) {
+ identityRefResolutionList.add(info);
+ } else if (type == YANG_COMPILER_ANNOTATION) {
+ compilerAnnotationList.add(info);
+ }
+ }
+
+ @Override
+ public void setResolutionList(List<YangResolutionInfo> resolutionList,
+ ResolvableType type) {
+ if (type == YANG_DERIVED_DATA_TYPE) {
+ derivedTypeResolutionList = resolutionList;
+ } else if (type == YANG_USES) {
+ usesResolutionList = resolutionList;
+ } else if (type == YANG_IF_FEATURE) {
+ ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
+ } else if (type == YANG_LEAFREF) {
+ leafRefResolutionList = resolutionList;
+ } else if (type == YANG_BASE) {
+ baseResolutionList = resolutionList;
+ } else if (type == YANG_AUGMENT) {
+ augmentResolutionList = resolutionList;
+ } else if (type == YANG_IDENTITYREF) {
+ identityRefResolutionList = resolutionList;
+ } else if (type == YANG_COMPILER_ANNOTATION) {
+ compilerAnnotationList = resolutionList;
+ }
+ }
+
+ @Override
+ public void addReferencesToImportList(Set<YangNode> yangNodeSet)
+ throws DataModelException {
+ // Run through the imported list to add references.
+ for (YangImport yangImport : getImportList()) {
+ yangImport.addReferenceToImport(yangNodeSet);
+ }
+ }
+
+ @Override
+ public void addReferencesToIncludeList(Set<YangNode> yangNodeSet)
+ throws DataModelException {
+ // Run through the included list to add references.
+ for (YangInclude yangInclude : getIncludeList()) {
+ YangSubModule subModule = yangInclude
+ .addReferenceToInclude(yangNodeSet);
+
+ // Check if the referred sub-modules parent is self
+ if (!subModule.getBelongsTo().getModuleNode().equals(this)) {
+ yangInclude.reportIncludeError();
+ }
+ }
+ }
+
+ @Override
+ public void setLeafNameSpaceAndAddToParentSchemaMap() {
+ // Add namespace for all leafs.
+ for (YangLeaf yangLeaf : getListOfLeaf()) {
+ yangLeaf.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ // Add namespace for all leaf list.
+ for (YangLeafList yangLeafList : getListOfLeafList()) {
+ yangLeafList.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ }
+
+ @Override
+ public boolean isNotificationPresent() {
+ return isNotificationPresent;
+ }
+
+ @Override
+ public void setNotificationPresenceFlag(boolean notificationPresent) {
+ isNotificationPresent = notificationPresent;
+ }
+
+ @Override
+ public void addToNotificationEnumMap(String enumName,
+ YangSchemaNode notification) {
+ notificationEnumMap.put(enumName, notification);
+ }
+
+ @Override
+ public YangSchemaNode getNotificationSchemaNode(String enumName) {
+ return notificationEnumMap.get(enumName);
+ }
+
+ /**
+ * Adds to augment list.
+ *
+ * @param augment augment which is augmenting input
+ */
+ public void addToAugmentList(YangAugment augment) {
+ augments.add(augment);
+ }
+
+ /**
+ * Returns augmented list.
+ *
+ * @return augmented list
+ */
+ public List<YangAugment> getAugmentList() {
+ return unmodifiableList(augments);
+ }
+
+ @Override
+ public String getModuleNamespace() {
+ return namespace;
+ }
+
+ @Override
+ public String getModuleName() {
+ return getName();
+ }
+
+ public void setModuleNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMust.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMust.java
new file mode 100644
index 0000000..45c349f
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMust.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.MUST_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.YangErrMsgConstants.MUST_VIOLATION_ERROR_APP_TAG;
+import static org.onosproject.yang.compiler.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
+
+/*-
+ * 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 extends DefaultLocationInfo
+ implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder {
+
+ private static final long serialVersionUID = 806201646L;
+
+ /**
+ * Constraint info.
+ */
+ private String constraint;
+
+ /**
+ * Description string.
+ */
+ private String description;
+
+ /**
+ * Reference string.
+ */
+ private String reference;
+
+ /**
+ * YANG application error information.
+ */
+ private YangAppErrorInfo yangAppErrorInfo;
+
+ /**
+ * Creates a YANG must restriction.
+ */
+ public YangMust() {
+ yangAppErrorInfo = new YangAppErrorInfo();
+ yangAppErrorInfo.setErrorTag(OPERATION_FAILED_ERROR_TAG);
+ yangAppErrorInfo.setErrorAppTag(MUST_VIOLATION_ERROR_APP_TAG);
+ }
+
+ /**
+ * Returns the constraint.
+ *
+ * @return the constraint
+ */
+ public String getConstraint() {
+ return constraint;
+ }
+
+ /**
+ * Sets the constraint.
+ *
+ * @param constraint the constraint to set
+ */
+ public void setConstraint(String constraint) {
+ this.constraint = constraint;
+ }
+
+ /**
+ * 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 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
+ }
+
+ @Override
+ public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
+ this.yangAppErrorInfo = yangAppErrorInfo;
+ }
+
+ @Override
+ public YangAppErrorInfo getAppErrorInfo() {
+ return yangAppErrorInfo;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMustHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMustHolder.java
new file mode 100644
index 0000000..8a9b39a
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangMustHolder.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import java.util.List;
+
+/**
+ * Abstraction of must entity. It is used to abstract the data holders of must.
+ */
+public interface YangMustHolder {
+
+ /**
+ * Returns the list of must from data holder like container / list.
+ *
+ * @return the list of must
+ */
+ List<YangMust> getListOfMust();
+
+ /**
+ * Sets the list of must.
+ *
+ * @param mustConstraintList the list of must to set
+ */
+ void setListOfMust(List<YangMust> mustConstraintList);
+
+ /**
+ * Adds must in data holder like container / list.
+ *
+ * @param must the must to be added
+ */
+ void addMust(YangMust must);
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNamespace.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNamespace.java
new file mode 100644
index 0000000..5131c2c
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNamespace.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Representation of YANG namespace.
+ */
+public interface YangNamespace {
+
+ /**
+ * Returns module's namespace.
+ *
+ * @return module namespace
+ */
+ String getModuleNamespace();
+
+ /**
+ * Returns module name.
+ *
+ * @return module name
+ */
+ String getModuleName();
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java
new file mode 100644
index 0000000..d962a39
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNode.java
@@ -0,0 +1,930 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.onosproject.yang.compiler.datamodel.TraversalType.CHILD;
+import static org.onosproject.yang.compiler.datamodel.TraversalType.PARENT;
+import static org.onosproject.yang.compiler.datamodel.TraversalType.SIBILING;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.cloneListOfLeaf;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.cloneListOfLeafList;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef;
+
+/**
+ * Represents base class of a node in data model tree.
+ */
+public abstract class YangNode
+ implements Cloneable, Serializable, YangSchemaNode,
+ Comparable<YangNode> {
+
+ private static final long serialVersionUID = 806201601L;
+
+ /**
+ * YANG schema node identifier.
+ */
+ private YangSchemaNodeIdentifier yangSchemaNodeIdentifier;
+
+ /**
+ * 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;
+
+ /**
+ * Priority of the node.
+ */
+ private int priority;
+
+ /**
+ * Flag if the node is for translation.
+ */
+ private boolean isToTranslate = true;
+
+ private transient int lineNumber;
+ private transient int charPosition;
+ private String fileName;
+
+ /**
+ * Map of YANG context information. It is to be consumed by YMS.
+ */
+ private Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> ysnContextInfoMap;
+
+ /**
+ * Count of mandatory YANG schema nodes.
+ */
+ private int mandatoryChildCount;
+
+ /**
+ * Yang revision.
+ */
+ private YangRevision revision;
+
+ /**
+ * Map of default schema nodes.
+ */
+ private Map<YangSchemaNodeIdentifier, YangSchemaNode> defaultChildMap;
+
+ /**
+ * Flag to check whether any descendant node is augmented.
+ */
+ private boolean isDescendantNodeAugmented;
+
+ /**
+ * Referred schema node, only applicable during grouping.
+ */
+ private YangNode referredSchemaNode;
+
+ /**
+ * Returns the priority of the node.
+ *
+ * @return priority of the node
+ */
+ public int getPriority() {
+ return priority;
+ }
+
+ /**
+ * Sets the priority of the node.
+ *
+ * @param priority of the node
+ */
+ public void setPriority(int priority) {
+ this.priority = priority;
+ }
+
+ /**
+ * Creates a YANG node object.
+ */
+ @SuppressWarnings("unused")
+ private YangNode() {
+ }
+
+ /**
+ * Creates a specific type of node.
+ *
+ * @param type of YANG node
+ * @param ysnContextInfoMap YSN context info map
+ */
+ protected YangNode(YangNodeType type,
+ Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> ysnContextInfoMap) {
+ nodeType = type;
+ this.ysnContextInfoMap = ysnContextInfoMap;
+ }
+
+ /**
+ * Returns true if descendant node is augmented.
+ *
+ * @return true if descendant node is augmented
+ */
+ public boolean isDescendantNodeAugmented() {
+ return isDescendantNodeAugmented;
+ }
+
+ /**
+ * Sets true if descendant node is augmented.
+ *
+ * @param descendantNodeAugmented true if descendant node is augmented.
+ */
+ public void setDescendantNodeAugmented(boolean descendantNodeAugmented) {
+ isDescendantNodeAugmented = descendantNodeAugmented;
+ }
+
+ /**
+ * 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
+ */
+ public 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
+ */
+ public 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 " + getName() +
+ " in " + getLineNumber() +
+ " at " + getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+
+ if (newChild.getParent() == null) {
+ newChild.setParent(this);
+ } else if (newChild.getParent() != this) {
+ throw new DataModelException("Node is already part of a tree " +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() + " in " +
+ getFileName() + "\"");
+ }
+
+ if (newChild.getChild() != null) {
+ throw new DataModelException("Child to be added is not atomic, " +
+ "it already has a child " +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() + " in " +
+ getFileName() + "\"");
+ }
+
+ if (newChild.getNextSibling() != null) {
+ throw new DataModelException("Child to be added is not atomic, " +
+ "it already has a next " +
+ "sibling " + getName() +
+ " in " + getLineNumber() +
+ " at " + getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+
+ if (newChild.getPreviousSibling() != null) {
+ throw new DataModelException("Child to be added is not atomic, " +
+ "it already has a previous " +
+ "sibling " + getName() +
+ " in " + getLineNumber() +
+ " at " + getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+
+ /* First child to be added */
+ if (getChild() == null) {
+ setChild(newChild);
+ } else {
+
+ 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);
+ }
+ }
+ }
+
+ /**
+ * Processes addition of schema node child to parent map.
+ *
+ * @param name name of the node
+ * @param namespace namespace of the node
+ */
+ protected void processAdditionOfSchemaNodeToParentMap(String name,
+ YangNamespace namespace) {
+ processAdditionOfSchemaNodeToMap(name, namespace, this, getParent());
+ }
+
+ /**
+ * Processes addition of schema node child to parent map.
+ *
+ * @param name name of the node
+ * @param namespace namespace of the node
+ * @param yangSchemaNode YANG schema node
+ */
+ public void processAdditionOfSchemaNodeToCurNodeMap(String name,
+ YangNamespace namespace,
+ YangSchemaNode yangSchemaNode) {
+ processAdditionOfSchemaNodeToMap(name, namespace, yangSchemaNode, this);
+ }
+
+ /**
+ * Processes addition of schema node child to map.
+ *
+ * @param name name of the node
+ * @param namespace namespace of the node
+ * @param yangSchemaNode YANG schema node
+ * @param childSchemaMapHolder child schema map holder
+ */
+ private void processAdditionOfSchemaNodeToMap(String name,
+ YangNamespace namespace,
+ YangSchemaNode yangSchemaNode,
+ YangNode childSchemaMapHolder) {
+ // Addition of node to schema node map.
+ // Create YANG schema node identifier with child node name.
+ YangSchemaNodeIdentifier yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
+ yangSchemaNodeIdentifier.setName(name);
+ yangSchemaNodeIdentifier.setNameSpace(namespace);
+ // Create YANG schema node context info and set child node.
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo = new YangSchemaNodeContextInfo();
+ yangSchemaNodeContextInfo.setSchemaNode(yangSchemaNode);
+ // Invoke parent method to add the created entry.
+ try {
+ childSchemaMapHolder.addToChildSchemaMap(yangSchemaNodeIdentifier,
+ yangSchemaNodeContextInfo);
+ } catch (DataModelException e) {
+ //TODO
+ }
+ }
+
+ @Override
+ public int compareTo(YangNode otherNode) {
+ if (priority == otherNode.getPriority()) {
+ return 0;
+ }
+ return ((Integer) otherNode.getPriority()).compareTo(priority);
+ }
+
+ /**
+ * Clones the current node contents and create a new node.
+ *
+ * @param yangUses YANG uses
+ * @return cloned node
+ * @throws CloneNotSupportedException clone is not supported by the referred
+ * node
+ */
+ public YangNode clone(YangUses yangUses)
+ throws CloneNotSupportedException {
+ YangNode clonedNode = (YangNode) super.clone();
+ clonedNode.referredSchemaNode = this;
+ if (clonedNode instanceof YangLeavesHolder) {
+ try {
+ cloneListOfLeaf((YangLeavesHolder) clonedNode, yangUses);
+ cloneListOfLeafList((YangLeavesHolder) clonedNode, yangUses);
+ } catch (DataModelException e) {
+ throw new CloneNotSupportedException(e.getMessage());
+ }
+ }
+
+ clonedNode.setParent(null);
+ clonedNode.setChild(null);
+ clonedNode.setNextSibling(null);
+ clonedNode.setPreviousSibling(null);
+ clonedNode.yangSchemaNodeIdentifier =
+ clonedNode.yangSchemaNodeIdentifier.clone();
+ clonedNode.ysnContextInfoMap = new HashMap<>();
+ if (clonedNode instanceof YangAugmentableNode) {
+ ((YangAugmentableNode) clonedNode).cloneAugmentInfo();
+ }
+ return clonedNode;
+ }
+
+ /**
+ * Clones the subtree from the specified source node to the mentioned target
+ * node. The source and target root node cloning is carried out by the
+ * caller.
+ *
+ * @param srcRootNode source node for sub tree cloning
+ * @param dstRootNode destination node where the sub tree needs to be cloned
+ * @param yangUses YANG uses
+ * @throws DataModelException data model error
+ */
+ public static void cloneSubTree(YangNode srcRootNode, YangNode dstRootNode,
+ YangUses yangUses)
+ throws DataModelException {
+
+ YangNode nextNodeToClone = srcRootNode;
+ TraversalType curTraversal;
+
+ YangNode clonedTreeCurNode = dstRootNode;
+ YangNode newNode = null;
+
+ nextNodeToClone = nextNodeToClone.getChild();
+ if (nextNodeToClone == null) {
+ return;
+ } else {
+ /*
+ * Root level cloning is taken care in the caller.
+ */
+ curTraversal = CHILD;
+ }
+
+ /*
+ * Caller ensures the cloning of the root nodes
+ */
+ try {
+ while (nextNodeToClone != srcRootNode) {
+ if (nextNodeToClone == null) {
+ throw new DataModelException("Internal error: Cloning " +
+ "failed, source " +
+ "tree null pointer " +
+ "reached " +
+ nextNodeToClone.getName() +
+ " in " + nextNodeToClone.getLineNumber() +
+ " at " + nextNodeToClone.getCharPosition() +
+ " in " + nextNodeToClone.getFileName() + "\"");
+ }
+ if (curTraversal != PARENT) {
+ newNode = nextNodeToClone.clone(yangUses);
+ detectCollisionWhileCloning(clonedTreeCurNode, newNode,
+ curTraversal);
+ }
+
+ if (curTraversal == CHILD) {
+
+ /*
+ * add the new node to the cloned tree.
+ */
+ clonedTreeCurNode.addChild(newNode);
+
+ /*
+ * update the cloned tree's traversal current node as the
+ * new node.
+ */
+ clonedTreeCurNode = newNode;
+ } else if (curTraversal == SIBILING) {
+
+ clonedTreeCurNode.addNextSibling(newNode);
+ clonedTreeCurNode = newNode;
+ } else {
+ if (clonedTreeCurNode instanceof YangLeavesHolder) {
+ updateClonedLeavesUnionEnumRef((YangLeavesHolder) clonedTreeCurNode);
+ }
+ clonedTreeCurNode = clonedTreeCurNode.getParent();
+ }
+
+ if (curTraversal != PARENT && nextNodeToClone.getChild() != null) {
+ curTraversal = CHILD;
+
+ /*
+ * update the traversal's current node.
+ */
+ nextNodeToClone = nextNodeToClone.getChild();
+ } else if (nextNodeToClone.getNextSibling() != null) {
+
+ curTraversal = SIBILING;
+
+ nextNodeToClone = nextNodeToClone.getNextSibling();
+ } else {
+ curTraversal = PARENT;
+ nextNodeToClone = nextNodeToClone.getParent();
+ }
+ }
+ } catch (CloneNotSupportedException e) {
+ throw new DataModelException("Failed to clone the tree " +
+ nextNodeToClone.getName() +
+ " in " + nextNodeToClone.getLineNumber() +
+ " at " + nextNodeToClone.getCharPosition() +
+ " in " + nextNodeToClone.getFileName() + "\"");
+ }
+ }
+
+ /**
+ * Detects collision when the grouping is deep copied to the uses's parent.
+ *
+ * @param currentNode parent/previous sibling node for the new node
+ * @param newNode node which has to be added
+ * @param addAs traversal type of the node
+ * @throws DataModelException data model error
+ */
+ private static void detectCollisionWhileCloning(YangNode currentNode,
+ YangNode newNode,
+ TraversalType addAs)
+ throws DataModelException {
+ if (!(currentNode instanceof CollisionDetector)
+ || !(newNode instanceof Parsable)) {
+ throw new DataModelException("Node in data model tree does not " +
+ "support collision detection " +
+ newNode.getName() + " in " +
+ newNode.getLineNumber() + " at " +
+ newNode.getCharPosition() +
+ " in " + newNode.getFileName() + "\"");
+ }
+
+ CollisionDetector collisionDetector = (CollisionDetector) currentNode;
+ Parsable parsable = (Parsable) newNode;
+ if (addAs == CHILD) {
+ collisionDetector.detectCollidingChild(newNode.getName(),
+ parsable.getYangConstructType());
+ } else if (addAs == SIBILING) {
+ currentNode = currentNode.getParent();
+ if (!(currentNode instanceof CollisionDetector)) {
+ throw new DataModelException("Node in data model tree does " +
+ "not support collision " +
+ "detection" + currentNode.getName() +
+ " in " + currentNode.getLineNumber() +
+ " at " + currentNode.getCharPosition() +
+ " in " + currentNode.getFileName() + "\"");
+ }
+ collisionDetector = (CollisionDetector) currentNode;
+ collisionDetector.detectCollidingChild(newNode.getName(),
+ parsable.getYangConstructType());
+ } else {
+ throw new DataModelException("Error tree cloning " +
+ currentNode.getName() + " in" +
+ " " + currentNode.getLineNumber() +
+ " at " + currentNode.getCharPosition() +
+ " in " + currentNode.getFileName() + "\"");
+ }
+ }
+
+ /**
+ * /** Returns true if translation required.
+ *
+ * @return true if translation required
+ */
+ public boolean isToTranslate() {
+ return isToTranslate;
+ }
+
+ /**
+ * Sest true if translation required.
+ *
+ * @param toTranslate true if translation required.
+ */
+ public void setToTranslate(boolean toTranslate) {
+ isToTranslate = toTranslate;
+ }
+
+ /**
+ * Adds a new next sibling.
+ *
+ * @param newSibling new sibling to be added
+ * @throws DataModelException data model error
+ */
+ private void addNextSibling(YangNode newSibling)
+ throws DataModelException {
+
+ if (newSibling.getNodeType() == null) {
+ throw new DataModelException("Cloned abstract node cannot be " +
+ "inserted into a tree "
+ + getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
+ }
+
+ if (newSibling.getParent() == null) {
+ /**
+ * Since the siblings needs to have a common parent, set the parent
+ * as the current node's parent
+ */
+ newSibling.setParent(getParent());
+ } else {
+ throw new DataModelException("Node is already part of a tree, " +
+ "and cannot be added as a " +
+ "sibling " + getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() + " in " +
+ getFileName() + "\"");
+ }
+
+ if (newSibling.getPreviousSibling() == null) {
+ newSibling.setPreviousSibling(this);
+ setNextSibling(newSibling);
+ } else {
+ throw new DataModelException("New sibling to be added is not " +
+ "atomic, it already has a " +
+ "previous sibling " +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() + " in " +
+ getFileName() + "\"");
+ }
+
+ if (newSibling.getChild() != null) {
+ throw new DataModelException("Sibling to be added is not atomic, " +
+ "it already has a child " +
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() + " in " +
+ getFileName() + "\"");
+ }
+
+ if (newSibling.getNextSibling() != null) {
+ throw new DataModelException("Sibling to be added is not atomic, " +
+ "it already has a next " +
+ "sibling " + getName() +
+ " in " + getLineNumber() +
+ " at " + getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+ }
+
+ @Override
+ public YangSchemaNodeContextInfo getChildSchema(YangSchemaNodeIdentifier dataNodeIdentifier)
+ throws DataModelException {
+ YangSchemaNodeContextInfo childSchemaContext =
+ ysnContextInfoMap.get(dataNodeIdentifier);
+ if (childSchemaContext == null) {
+ throw new DataModelException("Requested " +
+ dataNodeIdentifier.getName() +
+ " is not child in " +
+ getName());
+ }
+ return childSchemaContext;
+ }
+
+ @Override
+ public int getMandatoryChildCount()
+ throws DataModelException {
+ return mandatoryChildCount;
+ }
+
+ @Override
+ public Map<YangSchemaNodeIdentifier, YangSchemaNode> getDefaultChild(YangSchemaNodeIdentifier dataNodeIdentifier) {
+ return defaultChildMap;
+ }
+
+ @Override
+ public boolean isNotificationPresent() throws DataModelException {
+ throw new DataModelException("Method is called for node other than module/sub-module.");
+ }
+
+ @Override
+ public boolean isEmptyDataType() throws DataModelException {
+ throw new DataModelException("Method is called for node other than " +
+ "leaf/leaf-list.");
+ }
+
+ /**
+ * Adds child schema in child schema map, this is used to add the schema
+ * to the map in case of leaf as a child.
+ *
+ * @param schemaNodeIdentifier YANG schema node identifier
+ * @param yangSchemaNodeContextInfo YANG data node context information
+ * @throws DataModelException a violation in data model rule
+ */
+ public abstract void addToChildSchemaMap(YangSchemaNodeIdentifier schemaNodeIdentifier,
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+ throws DataModelException;
+
+ /**
+ * Increments mandatory child count.
+ */
+ public abstract void incrementMandatoryChildCount();
+
+ /**
+ * Sets mandatory child count.
+ *
+ * @param mandatoryChildCount value of mandatory child count
+ */
+ public void setMandatoryChildCount(int mandatoryChildCount) {
+ this.mandatoryChildCount = mandatoryChildCount;
+ }
+
+ /**
+ * Adds default child information to map.
+ *
+ * @param yangSchemaNodeIdentifier YANG schema node identifier
+ * @param yangSchemaNode YANG schema node
+ */
+ public abstract void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier,
+ YangSchemaNode yangSchemaNode);
+
+ /**
+ * Returns default child map.
+ *
+ * @return default child map
+ */
+ public Map<YangSchemaNodeIdentifier, YangSchemaNode> getDefaultChildMap() {
+ return defaultChildMap;
+ }
+
+ /**
+ * Returns YANG schema node context info map.
+ *
+ * @return YANG schema node context info map
+ */
+ public Map<YangSchemaNodeIdentifier,
+ YangSchemaNodeContextInfo> getYsnContextInfoMap() {
+ return ysnContextInfoMap;
+ }
+
+ /**
+ * Adds namespace for self, next sibling and first child. This is used
+ * after obtaining namespace in case of submodule after performing
+ * linking.
+ */
+ public void setNameSpaceAndAddToParentSchemaMap() {
+ // Get parent namespace.
+ if (getParent() != null) {
+ // Get parent namespace and set namespace for self node.
+ setNameSpace(getParent().getNameSpace());
+ // Process addition of leaf to the child schema map of parent.
+ processAdditionOfSchemaNodeToParentMap(getName(), getNameSpace());
+ } else {
+ // Module/Sub-module
+ setNameSpace((YangNamespace) this);
+ }
+ /*
+ * Check if node contains leaf/leaf-list, if yes add namespace for leaf
+ * and leaf list.
+ */
+ if (this instanceof YangLeavesHolder) {
+ ((YangLeavesHolder) this).setLeafNameSpaceAndAddToParentSchemaMap();
+ }
+ }
+
+ /**
+ * Sets YSN context info map.
+ *
+ * @param ysnContextInfoMap YSN context info map
+ */
+ public void setYsnContextInfoMap(Map<YangSchemaNodeIdentifier,
+ YangSchemaNodeContextInfo> ysnContextInfoMap) {
+ this.ysnContextInfoMap = ysnContextInfoMap;
+ }
+
+ /**
+ * Adds to YSN context info map.
+ *
+ * @param yangSchemaNodeIdentifier YANG schema node identifier
+ * @param yangSchemaNodeContextInfo YANG schema node context info
+ */
+ public void addToYsnContextInfoMap(YangSchemaNodeIdentifier
+ yangSchemaNodeIdentifier, YangSchemaNodeContextInfo
+ yangSchemaNodeContextInfo) {
+ getYsnContextInfoMap().put(yangSchemaNodeIdentifier, yangSchemaNodeContextInfo);
+ }
+
+ @Override
+ public void isValueValid(String value)
+ throws DataModelException {
+ throw new DataModelException("Value validation asked for YANG node. "
+ + getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
+ }
+
+ @Override
+ public YangSchemaNodeIdentifier getYangSchemaNodeIdentifier() {
+ return yangSchemaNodeIdentifier;
+ }
+
+ /**
+ * Sets YANG schema node identifier.
+ *
+ * @param yangSchemaNodeIdentifier YANG schema node identifier
+ */
+ public void setYangSchemaNodeIdentifier(YangSchemaNodeIdentifier yangSchemaNodeIdentifier) {
+ if (this.yangSchemaNodeIdentifier == null) {
+ this.yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
+ }
+ this.yangSchemaNodeIdentifier = yangSchemaNodeIdentifier;
+ }
+
+ @Override
+ public String getName() {
+ return yangSchemaNodeIdentifier.getName();
+ }
+
+ /**
+ * Sets name of node.
+ *
+ * @param name name of the node
+ */
+ public void setName(String name) {
+ if (yangSchemaNodeIdentifier == null) {
+ yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
+ }
+ yangSchemaNodeIdentifier.setName(name);
+ }
+
+ @Override
+ public YangNamespace getNameSpace() {
+ return yangSchemaNodeIdentifier.getNameSpace();
+ }
+
+ /**
+ * Sets namespace of node.
+ *
+ * @param namespace namespace of the node
+ */
+ public void setNameSpace(YangNamespace namespace) {
+ if (yangSchemaNodeIdentifier == null) {
+ yangSchemaNodeIdentifier = new YangSchemaNodeIdentifier();
+ }
+ yangSchemaNodeIdentifier.setNameSpace(namespace);
+ }
+
+ /**
+ * Returns YANG revision.
+ *
+ * @return YANG revision
+ */
+ public YangRevision getRevision() {
+ return revision;
+ }
+
+ /**
+ * Sets YANG revision.
+ *
+ * @param revision YANG revision
+ */
+ public void setRevision(YangRevision revision) {
+ this.revision = revision;
+ }
+
+ @Override
+ public YangSchemaNode getNotificationSchemaNode(String notificationNameInEnum)
+ throws DataModelException {
+ throw new DataModelException("Method called for schema node other " +
+ "then module/sub-module");
+ }
+
+ @Override
+ public YangSchemaNode getReferredSchema() {
+ return referredSchemaNode;
+ }
+
+ /**
+ * Returns true if op type info required for node.
+ *
+ * @return true if op type info required for node
+ */
+ public boolean isOpTypeReq() {
+ return this instanceof RpcNotificationContainer ||
+ !(this instanceof InvalidOpTypeHolder) &&
+ getParent().isOpTypeReq();
+ }
+
+ @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;
+ }
+
+ @Override
+ public String getFileName() {
+ return fileName;
+ }
+
+ @Override
+ public void setFileName(String name) {
+ fileName = name;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNodeIdentifier.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNodeIdentifier.java
new file mode 100644
index 0000000..f18633a
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNodeIdentifier.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import java.io.Serializable;
+
+/**
+ * Represents YANG node identifier which is a combination of prefix and name.
+ */
+public class YangNodeIdentifier extends DefaultLocationInfo
+ 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNodeType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNodeType.java
new file mode 100644
index 0000000..1b178d3
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNodeType.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * 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,
+
+ /**
+ * Identity node.
+ */
+ IDENTITY_NODE,
+
+ /**
+ * Identityref node.
+ */
+ IDENTITYREF_NODE
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNotification.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNotification.java
new file mode 100644
index 0000000..096b3dc
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangNotification.java
@@ -0,0 +1,299 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.NOTIFICATION_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_SINGLE_INSTANCE_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangStatusType.CURRENT;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.NOTIFICATION;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.NOTIFICATION_DATA;
+
+/*
+ * 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 | -YangIfFeature |
+ * | leaf | 7.6 | 0..n | -YangLeaf |
+ * | leaf-list | 7.7 | 0..n | -YangLeafList |
+ * | list | 7.8 | 0..n | -child nodes |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * | 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 abstract class YangNotification
+ extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
+ YangAugmentableNode, YangIfFeatureHolder, InvalidOpTypeHolder {
+
+ private static final long serialVersionUID = 806201611L;
+
+ /**
+ * 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 = CURRENT;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ private List<YangAugment> yangAugmentedInfo;
+
+ /**
+ * Create a notification node.
+ */
+ public YangNotification() {
+ super(NOTIFICATION_NODE, new HashMap<>());
+ listOfLeaf = new LinkedList<>();
+ listOfLeafList = new LinkedList<>();
+ ifFeatureList = new LinkedList<>();
+ yangAugmentedInfo = new LinkedList<>();
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo context)
+ throws DataModelException {
+ getYsnContextInfoMap().put(id, context);
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier id,
+ YangSchemaNode yangSchemaNode) {
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_SINGLE_INSTANCE_NODE;
+ }
+
+ @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(getErrorMsgCollision(
+ COLLISION_DETECTION, getName(), getLineNumber(),
+ getCharPosition(), NOTIFICATION, getFileName()));
+ }
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return 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 unmodifiableList(listOfLeaf);
+ }
+
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+ listOfLeaf.add(leaf);
+ }
+
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return unmodifiableList(listOfLeafList);
+ }
+
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+ listOfLeafList.add(leafList);
+ }
+
+ @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;
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return unmodifiableList(ifFeatureList);
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ ifFeatureList.add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
+ public void addAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.add(augmentInfo);
+ }
+
+ @Override
+ public void removeAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.remove(augmentInfo);
+ }
+
+ @Override
+ public List<YangAugment> getAugmentedInfoList() {
+ return unmodifiableList(yangAugmentedInfo);
+ }
+
+ @Override
+ public void setLeafNameSpaceAndAddToParentSchemaMap() {
+ // Add namespace for all leafs.
+ for (YangLeaf yangLeaf : listOfLeaf) {
+ yangLeaf.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ // Add namespace for all leaf list.
+ for (YangLeafList yangLeafList : listOfLeafList) {
+ yangLeafList.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ }
+
+ public void cloneAugmentInfo() {
+ yangAugmentedInfo = new ArrayList<>();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangOutput.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangOutput.java
new file mode 100644
index 0000000..2c206f0
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangOutput.java
@@ -0,0 +1,227 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_SINGLE_INSTANCE_NODE;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.OUTPUT;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.OUTPUT_DATA;
+
+/*
+ * 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 abstract class YangOutput
+ extends YangNode
+ implements YangLeavesHolder, Parsable, CollisionDetector,
+ YangAugmentableNode, YangIsFilterContentNodes, InvalidOpTypeHolder {
+
+ private static final long serialVersionUID = 806201612L;
+
+ /**
+ * List of leaves contained.
+ */
+ private List<YangLeaf> listOfLeaf;
+
+ /**
+ * List of leaf-lists contained.
+ */
+ private List<YangLeafList> listOfLeafList;
+
+ private List<YangAugment> yangAugmentedInfo;
+
+ /**
+ * Create a rpc output node.
+ */
+ public YangOutput() {
+ super(YangNodeType.OUTPUT_NODE, new HashMap<>());
+ listOfLeaf = new LinkedList<>();
+ listOfLeafList = new LinkedList<>();
+ yangAugmentedInfo = new ArrayList<>();
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo context)
+ throws DataModelException {
+ getYsnContextInfoMap().put(id, context);
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // For non data nodes, mandatory child to be added to parent node.
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier id,
+ YangSchemaNode yangSchemaNode) {
+ // For non data nodes, default child to be added to parent node.
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_SINGLE_INSTANCE_NODE;
+ }
+
+ @Override
+ public void detectCollidingChild(String idName, YangConstructType dataType)
+ throws DataModelException {
+ // Detect colliding child.
+ detectCollidingChildUtil(idName, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName,
+ YangConstructType dataType)
+ throws DataModelException {
+ if (getName().equals(identifierName)) {
+ getErrorMsgCollision(COLLISION_DETECTION, getName(),
+ getLineNumber(), getCharPosition(),
+ OUTPUT, getFileName());
+ }
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return 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 unmodifiableList(listOfLeaf);
+ }
+
+ @Override
+ public void addLeaf(YangLeaf leaf) {
+ listOfLeaf.add(leaf);
+ }
+
+ @Override
+ public void setListOfLeaf(List<YangLeaf> leafsList) {
+ listOfLeaf = leafsList;
+ }
+
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return unmodifiableList(listOfLeafList);
+ }
+
+ @Override
+ public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
+ this.listOfLeafList = listOfLeafList;
+ }
+
+ @Override
+ public void addLeafList(YangLeafList leafList) {
+ listOfLeafList.add(leafList);
+ }
+
+ @Override
+ public void addAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.add(augmentInfo);
+ }
+
+ @Override
+ public void removeAugmentation(YangAugment augmentInfo) {
+ yangAugmentedInfo.remove(augmentInfo);
+ }
+
+ @Override
+ public List<YangAugment> getAugmentedInfoList() {
+ return unmodifiableList(yangAugmentedInfo);
+ }
+
+ @Override
+ public void setLeafNameSpaceAndAddToParentSchemaMap() {
+ // Add namespace for all leafs.
+ for (YangLeaf yangLeaf : listOfLeaf) {
+ yangLeaf.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ // Add namespace for all leaf list.
+ for (YangLeafList yangLeafList : listOfLeafList) {
+ yangLeafList.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ }
+
+ public void cloneAugmentInfo() {
+ yangAugmentedInfo = new ArrayList<>();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangPathArgType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangPathArgType.java
new file mode 100644
index 0000000..2f4fd79
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangPathArgType.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.yang.compiler.datamodel;
+
+/**
+ * Represents path argument type in data model tree.
+ */
+public enum YangPathArgType {
+
+ /**
+ * Absolute path.
+ */
+ ABSOLUTE_PATH,
+
+ /**
+ * Relative path.
+ */
+ RELATIVE_PATH
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangPathOperator.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangPathOperator.java
new file mode 100644
index 0000000..b911384
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangPathOperator.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Represents path-expr in data model tree.
+ */
+public enum YangPathOperator {
+
+ /**
+ * Path expression contains equal-to.
+ */
+ EQUALTO
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangPathPredicate.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangPathPredicate.java
new file mode 100644
index 0000000..c308d0a
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangPathPredicate.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import java.io.Serializable;
+
+/**
+ * Representation of data model node to maintain path predicate in YANG
+ * absolute-path or relative-path.
+ */
+public class YangPathPredicate extends DefaultLocationInfo
+ implements Serializable {
+
+ private static final long serialVersionUID = 806201689L;
+
+ /**
+ * YANG node id.
+ */
+ private YangNodeIdentifier nodeId;
+
+ /**
+ * Left axis represents node-id before equality sign.
+ */
+ private Object leftAxisNode;
+
+ /**
+ * YANG path operator.
+ */
+ private YangPathOperator pathOp;
+
+ /**
+ * YANG right relative path in path-predicate.
+ */
+ private YangRelativePath relPath;
+
+ /**
+ * Right axis node represents the node-id after the equality sign.
+ */
+ private Object rightAxisNode;
+
+ /**
+ * Returns the path expression operator.
+ *
+ * @return path operator
+ */
+ public YangPathOperator getPathOp() {
+ return pathOp;
+ }
+
+ /**
+ * Sets the path expression operator.
+ *
+ * @param pathOp path operator
+ */
+ public void setPathOp(YangPathOperator pathOp) {
+ this.pathOp = pathOp;
+ }
+
+ /**
+ * Returns the right relative path expression.
+ *
+ * @return relative path
+ */
+ public YangRelativePath getRelPath() {
+ return relPath;
+ }
+
+ /**
+ * Sets the right relative path expression.
+ *
+ * @param relPath relative path
+ */
+ public void setRelPath(YangRelativePath relPath) {
+ this.relPath = relPath;
+ }
+
+ /**
+ * Returns the node identifier.
+ *
+ * @return node id
+ */
+ public YangNodeIdentifier getNodeId() {
+ return nodeId;
+ }
+
+ /**
+ * Sets the YANG node identifier.
+ *
+ * @param nodeId node id
+ */
+ public void setNodeId(YangNodeIdentifier nodeId) {
+ this.nodeId = nodeId;
+ }
+
+ /**
+ * Returns the left axis node.
+ *
+ * @return left axis node
+ */
+ public Object getLeftAxisNode() {
+ return leftAxisNode;
+ }
+
+ /**
+ * Sets the left axis node.
+ *
+ * @param leftAxisNode left axis node
+ */
+ public void setLeftAxisNode(Object leftAxisNode) {
+ this.leftAxisNode = leftAxisNode;
+ }
+
+ /**
+ * Returns the right axis node.
+ *
+ * @return right axis node
+ */
+ public Object getRightAxisNode() {
+ return rightAxisNode;
+ }
+
+ /**
+ * Sets the right axis node.
+ *
+ * @param rightAxisNode right axis node
+ */
+ public void setRightAxisNode(Object rightAxisNode) {
+ this.rightAxisNode = rightAxisNode;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangPatternRestriction.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangPatternRestriction.java
new file mode 100644
index 0000000..3e0363b
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangPatternRestriction.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.yang.compiler.datamodel;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+
+/*-
+ * 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 extends DefaultLocationInfo
+ implements Serializable, YangAppErrorHolder {
+
+ private static final long serialVersionUID = 806201649L;
+
+ /**
+ * Pattern restriction defined for the current type.
+ */
+ private final List<String> patternList;
+
+ /**
+ * YANG application error information.
+ */
+ private YangAppErrorInfo yangAppErrorInfo;
+
+ /**
+ * Creates a YANG pattern restriction object.
+ */
+ public YangPatternRestriction() {
+ patternList = new LinkedList<>();
+ yangAppErrorInfo = new YangAppErrorInfo();
+ }
+
+ /**
+ * Returns the pattern restriction defined for the current type.
+ *
+ * @return pattern restriction defined for the current type.
+ */
+ public List<String> getPatternList() {
+ return unmodifiableList(patternList);
+ }
+
+ /**
+ * Adds a new pattern to the list of pattern restriction.
+ *
+ * @param newPattern pattern restriction.
+ */
+ public void addPattern(String newPattern) {
+ patternList.add(newPattern);
+ }
+
+ @Override
+ public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
+ this.yangAppErrorInfo = yangAppErrorInfo;
+ }
+
+ @Override
+ public YangAppErrorInfo getAppErrorInfo() {
+ return yangAppErrorInfo;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRangeInterval.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRangeInterval.java
new file mode 100644
index 0000000..a298d20
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRangeInterval.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
+
+import java.io.Serializable;
+
+/**
+ * Represents single interval information of a range.
+ *
+ * @param <T> range type based on the data type
+ */
+public class YangRangeInterval<T extends YangBuiltInDataTypeInfo<T>> extends DefaultLocationInfo
+ 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRangeRestriction.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRangeRestriction.java
new file mode 100644
index 0000000..f9f0da7
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRangeRestriction.java
@@ -0,0 +1,308 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.yang.compiler.datamodel.BuiltInTypeObjectFactory.getDataObjectFromString;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsg;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.RANGE_DATA;
+
+/*-
+ * 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>>
+ extends DefaultLocationInfo
+ implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder {
+
+ 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;
+
+ /**
+ * Textual description.
+ */
+ private String description;
+
+ /**
+ * YANG application error information.
+ */
+ private YangAppErrorInfo yangAppErrorInfo;
+
+ /**
+ * Creates YANG range restriction object.
+ */
+ public YangRangeRestriction() {
+ yangAppErrorInfo = new YangAppErrorInfo();
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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(getErrorMsg(
+ "No range restriction info ",
+ "", getLineNumber(), getCharPosition(), getFileName() + "\""));
+ }
+ if (getAscendingRangeIntervals().isEmpty()) {
+ throw new DataModelException(getErrorMsg(
+ "No range interval info ",
+ "", getLineNumber(), getCharPosition(), getFileName() + "\""));
+ }
+ 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(getErrorMsg(
+ "No range restriction info ",
+ "", getLineNumber(), getCharPosition(), getFileName() + "\""));
+ }
+ if (getAscendingRangeIntervals().isEmpty()) {
+ throw new DataModelException(getErrorMsg(
+ "No range interval info ",
+ "", getLineNumber(), getCharPosition(), getFileName() + "\""));
+ }
+ 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 (ascendingRangeIntervals == null) {
+ /*
+ * First interval that is being added, and it must be the smallest
+ * interval.
+ */
+ ascendingRangeIntervals = new LinkedList<>();
+ ascendingRangeIntervals.add(newInterval);
+ return;
+ }
+
+ T curMaxvalue = getMaxRestrictedValue();
+ if (newInterval.getStartValue().compareTo(curMaxvalue) < 1) {
+ throw new DataModelException(getErrorMsg(
+ "New added range interval is lesser than the old interval(s) ",
+ "", getLineNumber(), getCharPosition(), getFileName() + "\""));
+ }
+ 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
+ */
+ 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(getErrorMsg(
+ "Range interval missing in range restriction. ",
+ "", getLineNumber(), getCharPosition(), getFileName() + "\""));
+ }
+
+ 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
+ * @param fileName file name
+ * @return true, if the interval is confirming to restriction, false otherwise
+ * @throws DataModelException data model error
+ */
+ boolean isValidInterval(YangRangeInterval rangeInterval, String fileName)
+ 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(getErrorMsg(
+ "Range interval missing in range restriction. ",
+ "restriction ranges.", getLineNumber(), getCharPosition(), fileName + "\""));
+ }
+
+ 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(getErrorMsg(
+ "Range interval doesn't fall within the referred restriction ranges ",
+ "restriction ranges.", getLineNumber(), getCharPosition(), fileName + "\""));
+ }
+
+ /**
+ * 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;
+
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return RANGE_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO: implement the method.
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO: implement the method.
+ }
+
+ @Override
+ public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
+ this.yangAppErrorInfo = yangAppErrorInfo;
+ }
+
+ @Override
+ public YangAppErrorInfo getAppErrorInfo() {
+ return yangAppErrorInfo;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangReference.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangReference.java
new file mode 100644
index 0000000..74ec1f4
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangReferenceResolver.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangReferenceResolver.java
new file mode 100644
index 0000000..d47387e
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangReferenceResolver.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRelativePath.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRelativePath.java
new file mode 100644
index 0000000..007b914
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRelativePath.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Representation of data model node to maintain relative path defined in YANG path-arg.
+ */
+public class YangRelativePath extends DefaultLocationInfo
+ implements Serializable {
+
+ private static final long serialVersionUID = 806201690L;
+
+ // Relative path ancestor node count the number of node exist between current node to parent node.
+ private int ancestorNodeCount;
+
+ // Absolute path expression.
+ private List<YangAtomicPath> atomicPathList;
+
+ /**
+ * Returns the absolute path.
+ *
+ * @return the absolute path
+ */
+ public List<YangAtomicPath> getAtomicPathList() {
+ return atomicPathList;
+ }
+
+ /**
+ * Sets the absolute path.
+ *
+ * @param atomicPathList Sets the absolute path
+ */
+ public void setAtomicPathList(List<YangAtomicPath> atomicPathList) {
+ this.atomicPathList = atomicPathList;
+ }
+
+ /**
+ * Returns the relative path ancestor count.
+ *
+ * @return the relative path ancestor count
+ */
+ public int getAncestorNodeCount() {
+ return ancestorNodeCount;
+ }
+
+ /**
+ * Sets the relative path ancestor count.
+ *
+ * @param ancestorNodeCount Sets the relative path ancestor count
+ */
+ public void setAncestorNodeCount(int ancestorNodeCount) {
+ this.ancestorNodeCount = ancestorNodeCount;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangResolutionInfo.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangResolutionInfo.java
new file mode 100644
index 0000000..b5ad97d
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.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> {
+
+ /**
+ * 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRevision.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRevision.java
new file mode 100644
index 0000000..9e13144
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRevision.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/*
+ * 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
+ extends DefaultLocationInfo
+ implements YangDesc, YangReference, Parsable, Serializable, Comparable<YangRevision> {
+
+ private static final long serialVersionUID = 8062016052L;
+
+ /**
+ * Revision date. Date string in the format "YYYY-MM-DD"
+ */
+ private Date 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 Date getRevDate() {
+ return revDate;
+ }
+
+ /**
+ * Sets the revision date.
+ *
+ * @param revDate the revision date to set
+ */
+ public void setRevDate(Date 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
+
+ }
+
+ @Override
+ public int compareTo(YangRevision obj) {
+ if (this == obj) {
+ return 0;
+ }
+ return getRevDate().compareTo(obj.getRevDate());
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRpc.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRpc.java
new file mode 100644
index 0000000..cd3f30e
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangRpc.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.RPC_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_SINGLE_INSTANCE_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangStatusType.CURRENT;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.RPC;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.RPC_DATA;
+
+/*
+ * 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 | -YangIfFeature |
+ * | 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 abstract class YangRpc
+ extends YangNode
+ implements YangCommonInfo, Parsable,
+ CollisionDetector, YangIfFeatureHolder, InvalidOpTypeHolder {
+
+ private static final long serialVersionUID = 806201613L;
+
+ /**
+ * Description of rpc.
+ */
+ private String description;
+
+ /**
+ * Reference of the module.
+ */
+ private String reference;
+
+ /**
+ * Status of the node.
+ */
+ private YangStatusType status = CURRENT;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
+ * Creates a rpc node.
+ */
+ public YangRpc() {
+ super(RPC_NODE, new HashMap<>());
+ ifFeatureList = new LinkedList<>();
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo context)
+ throws DataModelException {
+ getYsnContextInfoMap().put(id, context);
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ /*
+ * This will maintain all mandatory child which are there inside
+ * input and
+ * output as input/output is non data node.
+ */
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier id,
+ YangSchemaNode yangSchemaNode) {
+ /*
+ * This will maintain all default child which are there inside input and
+ * output as input/output is non data node.
+ */
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_SINGLE_INSTANCE_NODE;
+ }
+
+ @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(getErrorMsgCollision(
+ COLLISION_DETECTION, getName(), getLineNumber(),
+ getCharPosition(), RPC, getFileName()));
+ }
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return 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;
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return unmodifiableList(ifFeatureList);
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ ifFeatureList.add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNode.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNode.java
new file mode 100644
index 0000000..155f522
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNode.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.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+
+import java.util.Map;
+
+/**
+ * Abstraction of YANG data node, used by YMS to abstractly refer the data
+ * nodes in YANG data tree.
+ */
+public interface YangSchemaNode extends LocationInfo {
+
+ /**
+ * Returns type of YANG schema node.
+ *
+ * @return type of YANG schema node
+ */
+ YangSchemaNodeType getYangSchemaNodeType();
+
+ /**
+ * Returns child schema information. It is used by YMS to obtain the child
+ * schema corresponding to data node identifier.
+ *
+ * @param dataNodeIdentifier YANG data node identifier
+ * @return YANG data node context information
+ * @throws DataModelException data model exception in searching the child
+ */
+ YangSchemaNodeContextInfo getChildSchema(YangSchemaNodeIdentifier dataNodeIdentifier)
+ throws DataModelException;
+
+ /**
+ * Validates whether the leaf/leaf-list value is valid as per YANG. It is
+ * used by YMS to validate input value.
+ *
+ * @param value value of leaf/leaf-list
+ * @throws DataModelException a violation in data model rule
+ */
+ void isValueValid(String value)
+ throws DataModelException;
+
+ /**
+ * Returns count of mandatory child nodes, this is used by YMS to identify
+ * whether in request all mandatory child nodes are available.
+ *
+ * @return count of YANG schema nodes
+ * @throws DataModelException a violation in data model rule
+ */
+ int getMandatoryChildCount()
+ throws DataModelException;
+
+ /**
+ * Returns map of default child nodes, this is used by YMS to identify
+ * whether
+ * in request all default child nodes are available.
+ *
+ * @param dataNodeIdentifier YANG data node identifier
+ * @return map of default child nodes
+ */
+ Map<YangSchemaNodeIdentifier, YangSchemaNode> getDefaultChild(
+ YangSchemaNodeIdentifier dataNodeIdentifier);
+
+ /**
+ * Get Java class's package corresponding to the schema node.
+ *
+ * @return java package, it is null, if the Java type is a built in data
+ * type
+ */
+ String getJavaPackage();
+
+ /**
+ * Get Java class or built in data type corresponding to the schema node.
+ *
+ * @return Java class or built in data type corresponding to the schema node
+ */
+ String getJavaClassNameOrBuiltInType();
+
+ /**
+ * Returns schema node identifier.
+ *
+ * @return schema node identifier
+ */
+ YangSchemaNodeIdentifier getYangSchemaNodeIdentifier();
+
+ /**
+ * Returns name of the node.
+ *
+ * @return name of the node
+ */
+ String getName();
+
+ /**
+ * Returns Java attribute name.
+ *
+ * @return Java attribute name
+ */
+ String getJavaAttributeName();
+
+ /**
+ * Returns namespace of the node.
+ *
+ * @return namespace of the node
+ */
+ YangNamespace getNameSpace();
+
+ /**
+ * Checks for the presence of notification in module/sub-module. Exception
+ * will be thrown if this is called for any other node type.
+ *
+ * @return true if notification is present, false otherwise
+ * @throws DataModelException a violation in data model rule
+ */
+ boolean isNotificationPresent()
+ throws DataModelException;
+
+ /**
+ * Returns notification schema node corresponding to the name of
+ * notification as per the generated code enumeration. This is to be used
+ * for notification processing in YMS.
+ *
+ * @param notificationNameInEnum notification name in enum
+ * @return notification schema node
+ * @throws DataModelException a violation in data model rule
+ */
+ YangSchemaNode getNotificationSchemaNode(String notificationNameInEnum)
+ throws DataModelException;
+
+ /**
+ * Returns referred schema node in case of grouping.
+ *
+ * @return referred schema node
+ */
+ YangSchemaNode getReferredSchema();
+
+ /**
+ * Checks for the presence of empty data-type in requested schema node.
+ * Exception will be thrown if this is called for other then leaf/leaf-list
+ * node type.
+ *
+ * @return true if empty data-type is present, false otherwise
+ * @throws DataModelException when fails to do data model operations
+ */
+ boolean isEmptyDataType() throws DataModelException;
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeContextInfo.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeContextInfo.java
new file mode 100644
index 0000000..3b42112
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeContextInfo.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import java.io.Serializable;
+
+/**
+ * Abstraction of YANG data node context information, used by YMS to abstractly
+ * refer the YANG data nodes schema context information.
+ */
+public class YangSchemaNodeContextInfo extends DefaultLocationInfo
+ implements Serializable {
+
+ private static final long serialVersionUID = 806201613L;
+
+ // Current schema node
+ private YangSchemaNode schemaNode;
+
+ /*
+ * Context switched schema node, it will be non null only for the scenarios
+ * in which context switch is there like augment, choice etc, in this case
+ * this node will point to context switched node like YangAugmentInfo.
+ */
+ private YangSchemaNode contextSwitchedNode;
+
+ // Default instance of YangSchemaNodeContextInfo.
+ public YangSchemaNodeContextInfo() {
+ }
+
+ /**
+ * Returns the YANG schema node.
+ *
+ * @return YANG schema node
+ */
+ public YangSchemaNode getSchemaNode() {
+ return schemaNode;
+ }
+
+ /**
+ * Sets YANG schema node.
+ *
+ * @param schemaNode YANG schema node
+ */
+ void setSchemaNode(YangSchemaNode schemaNode) {
+ this.schemaNode = schemaNode;
+ }
+
+ /**
+ * Returns context switched node.
+ *
+ * @return context switched node
+ */
+ public YangSchemaNode getContextSwitchedNode() {
+ return contextSwitchedNode;
+ }
+
+ /**
+ * Set context switched node.
+ *
+ * @param contextSwitchedNode context switched node
+ */
+ void setContextSwitchedNode(YangSchemaNode contextSwitchedNode) {
+ this.contextSwitchedNode = contextSwitchedNode;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeIdentifier.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeIdentifier.java
new file mode 100644
index 0000000..4ee96fd
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeIdentifier.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * Represents YANG data node identifier which is a combination of name and namespace.
+ * Namespace will be present only if node is module/sub-module or augmented node.
+ */
+public class YangSchemaNodeIdentifier extends DefaultLocationInfo
+ implements Serializable, Cloneable {
+
+ private static final long serialVersionUID = 806201648L;
+
+ // Name of YANG data node.
+ private String name;
+
+ // Namespace of YANG data node.
+ private YangNamespace namespace;
+
+ /**
+ * Creates an instance of YANG data node identifier.
+ */
+ public YangSchemaNodeIdentifier() {
+ }
+
+ /**
+ * Returns the name of the node.
+ *
+ * @return name of the node
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets name of the node.
+ *
+ * @param name name of the node
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns namespace of the node.
+ *
+ * @return namespace of the node
+ */
+ public YangNamespace getNameSpace() {
+ return namespace;
+ }
+
+ /**
+ * Sets namespace of the node.
+ *
+ * @param namespace namespace of the node
+ */
+ public void setNameSpace(YangNamespace namespace) {
+ this.namespace = namespace;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangSchemaNodeIdentifier) {
+ YangSchemaNodeIdentifier other = (YangSchemaNodeIdentifier) obj;
+
+ if (!Objects.equals(name, other.name)) {
+ return false;
+ }
+ String name = namespace.getModuleName();
+ String otherName = other.getNameSpace().getModuleName();
+ if (name != null && otherName != null) {
+ if (namespace.getModuleName()
+ .equals(other.getNameSpace().getModuleName())) {
+ return true;
+ }
+
+ }
+ String nSpace = namespace.getModuleNamespace();
+ String otherNspace = other.getNameSpace().getModuleNamespace();
+ if (nSpace != null && otherNspace != null) {
+ if (nSpace.equals(otherNspace)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public YangSchemaNodeIdentifier clone() throws CloneNotSupportedException {
+ return (YangSchemaNodeIdentifier) super.clone();
+ }
+
+ @Override
+ public int hashCode() {
+ return 0;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeType.java
new file mode 100644
index 0000000..ebcfd0a
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSchemaNodeType.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Represents the nature of YANG node, it is used by YMS to abstractly
+ * understand the nature of node without knowing details of the YANG
+ * construct.
+ */
+public enum YangSchemaNodeType {
+
+ /**
+ * Represents single instance of YANG node like YANG container, YANG module,
+ * YANG sub-module. This is used by YMS to abstractly understand the nature
+ * of node.
+ */
+ YANG_SINGLE_INSTANCE_NODE,
+
+ /**
+ * Represents multi instance of YANG node i.e. YANG list.
+ * This is used by YMS to abstractly understand the nature of node.
+ */
+ YANG_MULTI_INSTANCE_NODE,
+
+ /**
+ * Represents single instance of YANG leaf node i.e. YANG leaf
+ * This is used by YMS to abstractly understand the nature of node.
+ */
+ YANG_SINGLE_INSTANCE_LEAF_NODE,
+
+ /**
+ * Represents multi instance of YANG leaf node i.e. YANG leaflist
+ * This is used by YMS to abstractly understand the nature of node.
+ */
+ YANG_MULTI_INSTANCE_LEAF_NODE,
+
+ /**
+ * Represents node which is not a data node.
+ */
+ YANG_NON_DATA_NODE,
+
+ /**
+ * Represents node which cannot be instantiated.
+ */
+ YANG_CHOICE_NODE,
+
+ /**
+ * Represents the Augmented Node.
+ */
+ YANG_AUGMENT_NODE
+
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangStatus.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangStatus.java
new file mode 100644
index 0000000..044ba5a
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangStatus.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangStatusType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangStatusType.java
new file mode 100644
index 0000000..6de81fd
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangStringRestriction.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangStringRestriction.java
new file mode 100644
index 0000000..1934e8d
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangStringRestriction.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.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangUint64;
+
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.ListIterator;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.PATTERN_DATA;
+
+/*-
+ * Reference RFC 6020.
+ *
+ * A string can be restricted with the "length" and "pattern" statements.
+ *
+ */
+
+/**
+ * Represents the restriction for string data type.
+ */
+public class YangStringRestriction extends DefaultLocationInfo
+ implements YangDesc, YangReference, 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;
+
+ /**
+ * 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 rest length restriction on the string data
+ */
+ public void setLengthRestriction(YangRangeRestriction<YangUint64> rest) {
+ lengthRestriction = rest;
+ }
+
+ /**
+ * 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 rest pattern restriction for the type
+ */
+ void setPatternRestriction(YangPatternRestriction rest) {
+ patternRestriction = rest;
+ }
+
+ /**
+ * Adds a new pattern restriction for the type.
+ *
+ * @param newPattern new pattern restriction for the type
+ */
+ public void addPattern(String newPattern) {
+ if (patternRestriction == null) {
+ patternRestriction = new YangPatternRestriction();
+ }
+ patternRestriction.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;
+
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return PATTERN_DATA;
+ }
+
+ /**
+ * Validates if the given value is correct as per the length restriction.
+ *
+ * @param valueInString value
+ * @return true, if the value is confirming to length restriction, false otherwise
+ */
+ boolean isValidStringOnLengthRestriction(String valueInString) {
+ if (lengthRestriction == null || lengthRestriction.getAscendingRangeIntervals() == null
+ || lengthRestriction.getAscendingRangeIntervals().isEmpty()) {
+ // Length restriction is optional
+ return true;
+ }
+
+ ListIterator<YangRangeInterval<YangUint64>> rangeListIterator =
+ lengthRestriction.getAscendingRangeIntervals().listIterator();
+ boolean isMatched = false;
+ while (rangeListIterator.hasNext()) {
+ YangRangeInterval rangeInterval = rangeListIterator.next();
+ rangeInterval.setCharPosition(getCharPosition());
+ rangeInterval.setLineNumber(getLineNumber());
+ rangeInterval.setFileName(getFileName());
+ BigInteger startValue = ((YangUint64) rangeInterval.getStartValue()).getValue();
+ BigInteger endValue = ((YangUint64) rangeInterval.getEndValue()).getValue();
+ if (valueInString.length() >= startValue.intValue() &&
+ valueInString.length() <= endValue.intValue()) {
+ isMatched = true;
+ break;
+ }
+ }
+
+ return isMatched;
+ }
+
+ /**
+ * Validates if the given value is correct as per the pattern restriction.
+ *
+ * @param valueInString value
+ * @return true, if the value is confirming to pattern restriction, false otherwise
+ */
+ boolean isValidStringOnPatternRestriction(String valueInString) {
+ if (patternRestriction == null
+ || patternRestriction.getPatternList().isEmpty()) {
+ // Pattern restriction is optional
+ return true;
+ }
+
+ ListIterator<String> patternListIterator =
+ patternRestriction.getPatternList().listIterator();
+ boolean isMatched = false;
+ while (patternListIterator.hasNext()) {
+ if (valueInString.matches(patternListIterator.next())) {
+ isMatched = true;
+ break;
+ }
+ }
+ return isMatched;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO: implement the method.
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO: implement the method.
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSubModule.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSubModule.java
new file mode 100644
index 0000000..d67b15f
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangSubModule.java
@@ -0,0 +1,827 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_AUGMENT;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_BASE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_COMPILER_ANNOTATION;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_DERIVED_DATA_TYPE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IDENTITYREF;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IF_FEATURE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_LEAFREF;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_USES;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_SINGLE_INSTANCE_NODE;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.linkInterFileReferences;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.resolveLinkingForResolutionList;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.SUB_MODULE_DATA;
+
+/*
+ * 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 | - YangFeature |
+ * | 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 abstract class YangSubModule
+ extends YangNode
+ implements YangLeavesHolder, YangDesc, YangReference, Parsable,
+ CollisionDetector, YangReferenceResolver, RpcNotificationContainer,
+ YangFeatureHolder, YangIsFilterContentNodes, YangNamespace {
+
+ private static final long serialVersionUID = 806201614L;
+
+ /**
+ * 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;
+
+ /**
+ * List of feature at root level in the module.
+ */
+ private List<YangFeature> listOfFeature;
+
+ /**
+ * 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 un-prefixed 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;
+
+ /**
+ * If-feature resolution list.
+ */
+ private List<YangResolutionInfo> ifFeatureResolutionList;
+
+ /**
+ * LeafRef resolution list.
+ */
+ private List<YangResolutionInfo> leafRefResolutionList;
+
+ /**
+ * Base resolution list.
+ */
+ private List<YangResolutionInfo> baseResolutionList;
+
+ /**
+ * IdentityRef resolution list.
+ */
+ private List<YangResolutionInfo> identityRefResolutionList;
+
+ /**
+ * Compiler annotation list.
+ */
+ private List<YangResolutionInfo> compilerAnnotationList;
+
+ /**
+ * extension list.
+ */
+ private List<YangExtension> extensionList;
+
+ /**
+ * Augment resolution list.
+ */
+ private List<YangResolutionInfo> augmentResolutionList;
+
+ /**
+ * Flag to indicate the presence of notification.
+ */
+ private boolean isNotificationPresent;
+
+ /**
+ * Map of notification enum.
+ */
+ private final Map<String, YangSchemaNode> notificationEnumMap;
+
+ /**
+ * List of augments which are augmenting input.
+ */
+ private final List<YangAugment> augments;
+
+ /**
+ * YANG defined namespace.
+ */
+ private String namespace;
+
+ /**
+ * Creates a sub module node.
+ */
+ public YangSubModule() {
+ super(YangNodeType.SUB_MODULE_NODE, new HashMap<>());
+ derivedTypeResolutionList = new LinkedList<>();
+ augmentResolutionList = new LinkedList<>();
+ usesResolutionList = new LinkedList<>();
+ ifFeatureResolutionList = new LinkedList<>();
+ leafRefResolutionList = new LinkedList<>();
+ baseResolutionList = new LinkedList<>();
+ identityRefResolutionList = new LinkedList<>();
+ compilerAnnotationList = new LinkedList<>();
+ importList = new LinkedList<>();
+ includeList = new LinkedList<>();
+ listOfLeaf = new LinkedList<>();
+ listOfLeafList = new LinkedList<>();
+ extensionList = new LinkedList<>();
+ compilerAnnotationList = new LinkedList<>();
+ listOfFeature = new LinkedList<>();
+ notificationEnumMap = new HashMap<>();
+ augments = new LinkedList<>();
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo context) {
+ getYsnContextInfoMap().put(id, context);
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier id,
+ YangSchemaNode yangSchemaNode) {
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_SINGLE_INSTANCE_NODE;
+ }
+
+ /**
+ * 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 unmodifiableList(importList);
+ }
+
+ /**
+ * Adds the imported module information to the import list.
+ *
+ * @param importedModule module being imported
+ */
+ @Override
+ public void addToImportList(YangImport importedModule) {
+ importList.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 unmodifiableList(includeList);
+ }
+
+ /**
+ * Returns the included sub module information to the include list.
+ *
+ * @param includeModule submodule being included
+ */
+ @Override
+ public void addToIncludeList(YangInclude includeModule) {
+ includeList.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 unmodifiableList(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) {
+ listOfLeaf.add(leaf);
+ }
+
+ /**
+ * Returns the list of leaf-list.
+ *
+ * @return the list of leaf-list
+ */
+ @Override
+ public List<YangLeafList> getListOfLeafList() {
+ return unmodifiableList(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) {
+ listOfLeafList.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 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 id, YangConstructType dataType)
+ throws DataModelException {
+ // Asks helper to detect colliding child.
+ detectCollidingChildUtil(id, dataType, this);
+ }
+
+ @Override
+ public void detectSelfCollision(String id, YangConstructType dataType)
+ throws DataModelException {
+ // Not required as module doesn't have any parent.
+ }
+
+ @Override
+ public List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type) {
+ if (type == YANG_DERIVED_DATA_TYPE) {
+ return unmodifiableList(derivedTypeResolutionList);
+ } else if (type == YANG_USES) {
+ return unmodifiableList(usesResolutionList);
+ } else if (type == YANG_AUGMENT) {
+ return unmodifiableList(augmentResolutionList);
+ } else if (type == YANG_IF_FEATURE) {
+ return unmodifiableList(ifFeatureResolutionList);
+ } else if (type == YANG_LEAFREF) {
+ return unmodifiableList(leafRefResolutionList);
+ } else if (type == YANG_BASE) {
+ return unmodifiableList(baseResolutionList);
+ } else if (type == YANG_IDENTITYREF) {
+ return unmodifiableList(identityRefResolutionList);
+ } else {
+ return unmodifiableList(compilerAnnotationList);
+ }
+ }
+
+ @Override
+ public void addToResolutionList(YangResolutionInfo resolutionInfo,
+ ResolvableType type) {
+ if (type == YANG_DERIVED_DATA_TYPE) {
+ derivedTypeResolutionList.add(resolutionInfo);
+ } else if (type == YANG_USES) {
+ usesResolutionList.add(resolutionInfo);
+ } else if (type == YANG_IF_FEATURE) {
+ ifFeatureResolutionList.add(resolutionInfo);
+ } else if (type == YANG_LEAFREF) {
+ leafRefResolutionList.add(resolutionInfo);
+ } else if (type == YANG_BASE) {
+ baseResolutionList.add(resolutionInfo);
+ } else if (type == YANG_AUGMENT) {
+ augmentResolutionList.add(resolutionInfo);
+ } else if (type == YANG_IDENTITYREF) {
+ identityRefResolutionList.add(resolutionInfo);
+ } else if (type == YANG_COMPILER_ANNOTATION) {
+ compilerAnnotationList.add(resolutionInfo);
+ }
+ }
+
+ @Override
+ public void setResolutionList(List<YangResolutionInfo> resolutionList,
+ ResolvableType type) {
+ if (type == YANG_DERIVED_DATA_TYPE) {
+ derivedTypeResolutionList = resolutionList;
+ } else if (type == YANG_USES) {
+ usesResolutionList = resolutionList;
+ } else if (type == YANG_IF_FEATURE) {
+ ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
+ } else if (type == YANG_LEAFREF) {
+ leafRefResolutionList = resolutionList;
+ } else if (type == YANG_BASE) {
+ baseResolutionList = resolutionList;
+ } else if (type == YANG_AUGMENT) {
+ augmentResolutionList = resolutionList;
+ } else if (type == YANG_IDENTITYREF) {
+ identityRefResolutionList = resolutionList;
+ } else if (type == YANG_COMPILER_ANNOTATION) {
+ compilerAnnotationList = 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 {
+ belongsTo.linkWithModule(yangNodeSet);
+ namespace = ((YangNamespace) belongsTo.getModuleNode())
+ .getModuleNamespace();
+ }
+
+ @Override
+ public void addReferencesToIncludeList(Set<YangNode> yangNodeSet)
+ throws DataModelException {
+ // Run through the included list to add references.
+ for (YangInclude yangInclude : getIncludeList()) {
+ YangSubModule subModule = yangInclude.addReferenceToInclude(yangNodeSet);
+ // Check if the referred sub-modules parent is self
+ if (!Objects.equals(subModule.getBelongsTo().getModuleNode(), getBelongsTo()
+ .getModuleNode())) {
+ yangInclude.reportIncludeError();
+ }
+ }
+ }
+
+ @Override
+ public void addReferencesToImportList(Set<YangNode> yangNodeSet)
+ throws DataModelException {
+ // Run through the imported list to add references.
+ for (YangImport yangImport : getImportList()) {
+ yangImport.addReferenceToImport(yangNodeSet);
+ }
+ }
+
+ @Override
+ public List<YangFeature> getFeatureList() {
+ return unmodifiableList(listOfFeature);
+ }
+
+ @Override
+ public void addFeatureList(YangFeature feature) {
+ listOfFeature.add(feature);
+ }
+
+ @Override
+ public void setListOfFeature(List<YangFeature> listOfFeature) {
+ this.listOfFeature = listOfFeature;
+ }
+
+ /**
+ * Adds extension in extension list.
+ *
+ * @param extension the extension to be added
+ */
+ public void addExtension(YangExtension extension) {
+ extensionList.add(extension);
+ }
+
+ /**
+ * Returns the extension list.
+ *
+ * @return the extension list
+ */
+ public List<YangExtension> getExtensionList() {
+ return unmodifiableList(extensionList);
+ }
+
+ /**
+ * Sets the extension list.
+ *
+ * @param extensionList the list of extension
+ */
+ public void setExtensionList(List<YangExtension> extensionList) {
+ this.extensionList = extensionList;
+ }
+
+ @Override
+ public void setLeafNameSpaceAndAddToParentSchemaMap() {
+ // Add namespace for all leafs.
+ for (YangLeaf yangLeaf : getListOfLeaf()) {
+ yangLeaf.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ // Add namespace for all leaf list.
+ for (YangLeafList yangLeafList : getListOfLeafList()) {
+ yangLeafList.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
+ }
+ }
+
+
+ @Override
+ public boolean isNotificationPresent() {
+ return isNotificationPresent;
+ }
+
+ @Override
+ public void setNotificationPresenceFlag(boolean notificationPresent) {
+ isNotificationPresent = notificationPresent;
+ }
+
+ @Override
+ public void addToNotificationEnumMap(String enumName,
+ YangSchemaNode notification) {
+ notificationEnumMap.put(enumName, notification);
+ }
+
+ @Override
+ public YangSchemaNode getNotificationSchemaNode(String enumName) {
+ return notificationEnumMap.get(enumName);
+ }
+
+ /**
+ * Adds to augment list.
+ *
+ * @param augment augment which is augmenting input
+ */
+ public void addToAugmentList(YangAugment augment) {
+ augments.add(augment);
+ }
+
+ /**
+ * Returns augmented list.
+ *
+ * @return augmented list
+ */
+ public List<YangAugment> getAugmentList() {
+ return unmodifiableList(augments);
+ }
+
+ @Override
+ public String getModuleNamespace() {
+ return namespace;
+ }
+
+ @Override
+ public String getModuleName() {
+ return getName();
+ }
+
+ public void setModuleNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangTranslatorOperatorNode.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangTranslatorOperatorNode.java
new file mode 100644
index 0000000..7045109
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangTranslatorOperatorNode.java
@@ -0,0 +1,25 @@
+
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Abstraction of an entity which provides info about whether to translate module/submodule in manager and service
+ * classes.
+ */
+public interface YangTranslatorOperatorNode {
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangType.java
new file mode 100644
index 0000000..8105d37
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangType.java
@@ -0,0 +1,557 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.DataModelUtils;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.DataTypeException;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangUint64;
+
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.Iterator;
+import java.util.ListIterator;
+
+import static org.onosproject.yang.compiler.datamodel.BuiltInTypeObjectFactory.getDataObjectFromString;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.UNRESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.TYPE_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.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 | - path for referred leaf/leaf-list |
+ * | 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> extends DefaultLocationInfo
+ implements Cloneable, Parsable, Resolvable, Serializable {
+
+ private static final long serialVersionUID = 8062016054L;
+
+ /**
+ * YANG node identifier.
+ */
+ private YangNodeIdentifier nodeId;
+
+ /**
+ * 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;
+
+
+ /**
+ * Resolution for interfile grouping.
+ */
+ private boolean isTypeForInterFileGroupingResolution;
+
+ /**
+ * Resolved within the grouping where the type is used.
+ */
+ private boolean isTypeNotResolvedTillRootNode;
+
+ /**
+ * Creates a YANG type object.
+ */
+ public YangType() {
+
+ nodeId = new YangNodeIdentifier();
+ resolvableStatus = UNRESOLVED;
+ }
+
+ /**
+ * Returns prefix associated with data type name.
+ *
+ * @return prefix associated with data type name
+ */
+ public String getPrefix() {
+ return nodeId.getPrefix();
+ }
+
+ /**
+ * Sets prefix associated with data type name.
+ *
+ * @param prefix prefix associated with data type name
+ */
+ public void setPrefix(String prefix) {
+ nodeId.setPrefix(prefix);
+ }
+
+ /**
+ * Returns the name of data type.
+ *
+ * @return the name of data type
+ */
+ public String getDataTypeName() {
+ return nodeId.getName();
+ }
+
+ /**
+ * Sets the name of the data type.
+ *
+ * @param typeName the name to set
+ */
+ public void setDataTypeName(String typeName) {
+ nodeId.setName(typeName);
+ }
+
+ /**
+ * 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 getNodeId() {
+ return nodeId;
+ }
+
+ /**
+ * Sets node identifier.
+ *
+ * @param nodeId the node identifier
+ */
+ public void setNodeId(YangNodeIdentifier nodeId) {
+ this.nodeId = nodeId;
+ }
+
+ /**
+ * Resets the class attributes to its default value.
+ */
+ public void resetYangType() {
+ nodeId = new YangNodeIdentifier();
+ resolvableStatus = UNRESOLVED;
+ dataType = null;
+ dataTypeExtendedInfo = null;
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns TYPE_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return 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 Object 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. "
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
+ }
+
+ // Check if the derived info is present.
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo();
+ if (derivedInfo == null) {
+ throw new DataModelException("Linker Error: Derived information is missing. " + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
+ }
+
+ // Initiate the resolution
+ try {
+ setResolvableStatus(derivedInfo.resolve());
+ } catch (DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
+ return null;
+ }
+
+ /**
+ * Validates the input data value against the permissible value for the
+ * type as per the YANG file.
+ *
+ * @param value input data value
+ * @throws DataModelException a violation of data model rules
+ */
+ void isValidValue(String value)
+ throws DataModelException {
+ switch (getDataType()) {
+ case INT8:
+ case INT16:
+ case INT32:
+ case INT64:
+ case UINT8:
+ case UINT16:
+ case UINT32:
+ case UINT64: {
+ if (getDataTypeExtendedInfo() == null) {
+ getDataObjectFromString(value, getDataType());
+ } else {
+ if (!((YangRangeRestriction) getDataTypeExtendedInfo()).isValidValueString(value)) {
+ throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
+ getDataType());
+ }
+ }
+ break;
+ }
+ case DECIMAL64: {
+ // Fraction-Digits and range needs to get it from yang
+ YangDecimal64<YangRangeRestriction> decimal64 =
+ (YangDecimal64<YangRangeRestriction>) getDataTypeExtendedInfo();
+ validateDecimal64(value, decimal64.getFractionDigit(),
+ decimal64.getRangeRestrictedExtendedInfo());
+ break;
+ }
+ case STRING: {
+ if (getDataTypeExtendedInfo() == null) {
+ break;
+ } else if (!(((YangStringRestriction) getDataTypeExtendedInfo()).isValidStringOnLengthRestriction(value)
+ && ((YangStringRestriction) getDataTypeExtendedInfo())
+ .isValidStringOnPatternRestriction(value))) {
+ throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
+ getDataType());
+ }
+ break;
+ }
+ case BOOLEAN:
+ if (!(value.equals(DataModelUtils.TRUE) || value.equals(DataModelUtils.FALSE))) {
+ throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
+ getDataType());
+ }
+ break;
+ case ENUMERATION: {
+ Iterator<YangEnum> iterator = ((YangEnumeration) getDataTypeExtendedInfo()).getEnumSet().iterator();
+ boolean isValidated = false;
+ while (iterator.hasNext()) {
+ YangEnum enumTemp = iterator.next();
+ if (enumTemp.getNamedValue().equals(value)) {
+ isValidated = true;
+ break;
+ }
+ }
+
+ if (!isValidated) {
+ throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
+ getDataType());
+ }
+ break;
+ }
+ case BITS: {
+ YangBits bits = (YangBits) getDataTypeExtendedInfo();
+ if (bits.fromString(value) == null) {
+ throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
+ getDataType());
+ }
+ break;
+ }
+ case BINARY: {
+ if (!isValidBinary(value, (YangRangeRestriction) getDataTypeExtendedInfo())) {
+ throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
+ getDataType());
+ }
+ break;
+ }
+ case LEAFREF: {
+ YangLeafRef<?> leafRef = (YangLeafRef<?>) getDataTypeExtendedInfo();
+ leafRef.validateDataOnExit();
+ break;
+ }
+ case IDENTITYREF: {
+ // TODO TBD
+ break;
+ }
+ case EMPTY: {
+ if (value.length() > 0) {
+ throw new DataTypeException("YANG file error : Input value \"" + value
+ + "\" is not allowed for a data type " + getDataType());
+ }
+ break;
+ }
+ case UNION: {
+ ListIterator<YangType<?>> listIterator = ((YangUnion) getDataTypeExtendedInfo()).getTypeList()
+ .listIterator();
+ boolean isValidated = false;
+ while (listIterator.hasNext()) {
+ YangType<?> type = (YangType<?>) listIterator.next();
+ try {
+ type.isValidValue(value);
+ // If it is not thrown exception then validation is success
+ isValidated = true;
+ break;
+ } catch (Exception e) {
+ }
+ }
+
+ if (!isValidated) {
+ throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
+ getDataType());
+ }
+ break;
+ }
+ case INSTANCE_IDENTIFIER: {
+ // TODO TBD
+ break;
+ }
+ case DERIVED: {
+ YangDataTypes dataType = ((YangDerivedInfo) getDataTypeExtendedInfo()).getEffectiveBuiltInType();
+ if (isOfRangeRestrictedType(dataType)) {
+ if (((YangDerivedInfo) getDataTypeExtendedInfo()).getResolvedExtendedInfo() == null) {
+ getDataObjectFromString(value,
+ ((YangDerivedInfo) getDataTypeExtendedInfo())
+ .getEffectiveBuiltInType());
+ } else {
+ if (!((YangRangeRestriction) ((YangDerivedInfo) getDataTypeExtendedInfo())
+ .getResolvedExtendedInfo()).isValidValueString(value)) {
+ throw new DataTypeException("YANG file error : Input value \"" + value
+ + "\" is not a valid " + dataType);
+ }
+ }
+ } else if (dataType == YangDataTypes.STRING) {
+ Object info = ((YangDerivedInfo) getDataTypeExtendedInfo())
+ .getResolvedExtendedInfo();
+ if (info != null) {
+ if (info instanceof YangStringRestriction) {
+ YangStringRestriction stringRestriction =
+ (YangStringRestriction) info;
+ if (!(stringRestriction.isValidStringOnLengthRestriction(value) &&
+ stringRestriction.isValidStringOnPatternRestriction(value))) {
+ throw new DataTypeException("YANG file error : Input value \"" + value
+ + "\" is not a valid " + dataType);
+ }
+ }
+ }
+ } else if (dataType == YangDataTypes.BITS) {
+ YangTypeDef prevTypedef = ((YangDerivedInfo) getDataTypeExtendedInfo())
+ .getReferredTypeDef();
+ YangType type = prevTypedef.getTypeList().iterator().next();
+ YangBits bits = (YangBits) type.getDataTypeExtendedInfo();
+ if (bits.fromString(value) == null) {
+ throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
+ dataType);
+ }
+ } else if (dataType == YangDataTypes.BINARY) {
+ if (!isValidBinary(value, (YangRangeRestriction) ((YangDerivedInfo)
+ getDataTypeExtendedInfo()).getResolvedExtendedInfo())) {
+ throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
+ dataType);
+ }
+ } else if (dataType == YangDataTypes.DECIMAL64) {
+ YangDerivedInfo derivedInfo = (YangDerivedInfo) getDataTypeExtendedInfo();
+ YangTypeDef typedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
+ YangType<YangDecimal64> decimal64Type =
+ (YangType<YangDecimal64>) typedef.getTypeList().iterator().next();
+ YangDecimal64<YangRangeRestriction> decimal64 = decimal64Type.getDataTypeExtendedInfo();
+ // Fraction-Digits and range needs to get it from yang
+ validateDecimal64(value, decimal64.getFractionDigit(),
+ decimal64.getRangeRestrictedExtendedInfo());
+ }
+ break;
+ }
+ default: {
+ throw new DataTypeException("YANG file error : Input value \"" + value + "\" received for " +
+ "unsupported data type " + getDataType());
+ }
+ }
+ }
+
+
+ /**
+ * Checks whether specific string is valid decimal64 value.
+ *
+ * @param value decimal64 value
+ */
+ private void validateDecimal64(String value, int fractionDigit, YangRangeRestriction rangeRestriction)
+ throws DataModelException {
+ YangDecimal64<YangRangeRestriction> decimal64 = YangDecimal64.fromString(value);
+ decimal64.setFractionDigit(fractionDigit);
+ decimal64.setRangeRestrictedExtendedInfo(rangeRestriction);
+ decimal64.validateDecimal64();
+ }
+
+ /**
+ * Checks whether specific string is valid binary.
+ *
+ * @param value binary value
+ * @return true if validation success otherwise false
+ */
+ private boolean isValidBinary(String value, YangRangeRestriction lengthRestriction) {
+ YangBinary binary = new YangBinary(value);
+
+ // After decoding binary, its length should not be zero
+ if (binary.getBinaryData().length == 0) {
+ return false;
+ }
+
+ if (lengthRestriction == null || lengthRestriction.getAscendingRangeIntervals() == null
+ || lengthRestriction.getAscendingRangeIntervals().isEmpty()) {
+ // Length restriction is optional
+ return true;
+ }
+
+ ListIterator<YangRangeInterval<YangUint64>> rangeListIterator = lengthRestriction.getAscendingRangeIntervals()
+ .listIterator();
+ boolean isMatched = false;
+ while (rangeListIterator.hasNext()) {
+ YangRangeInterval rangeInterval = rangeListIterator.next();
+ rangeInterval.setFileName(getFileName());
+ rangeInterval.setLineNumber(getLineNumber());
+ rangeInterval.setCharPosition(getCharPosition());
+ BigInteger startValue = ((YangUint64) rangeInterval.getStartValue()).getValue();
+ BigInteger endValue = ((YangUint64) rangeInterval.getEndValue()).getValue();
+ // convert (encode) back and check length
+ if ((binary.toString().length() >= startValue.intValue()) &&
+ (binary.toString().length() <= endValue.intValue())) {
+ isMatched = true;
+ break;
+ }
+ }
+
+ return isMatched;
+ }
+
+ public boolean isTypeForInterFileGroupingResolution() {
+ return isTypeForInterFileGroupingResolution;
+ }
+
+ public void setTypeForInterFileGroupingResolution(boolean typeForInterFileGroupingResolution) {
+ isTypeForInterFileGroupingResolution = typeForInterFileGroupingResolution;
+ }
+
+ public boolean isTypeNotResolvedTillRootNode() {
+ return isTypeNotResolvedTillRootNode;
+ }
+
+ public void setTypeNotResolvedTillRootNode(boolean typeNotResolvedTillRootNode) {
+ isTypeNotResolvedTillRootNode = typeNotResolvedTillRootNode;
+ }
+
+ @Override
+ public YangType<T> clone()
+ throws CloneNotSupportedException {
+ YangType<T> clonedNode = (YangType<T>) super.clone();
+ return clonedNode;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangTypeDef.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangTypeDef.java
new file mode 100644
index 0000000..499269d
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangTypeDef.java
@@ -0,0 +1,313 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.TYPEDEF_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_NON_DATA_NODE;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.TYPEDEF;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.TYPEDEF_DATA;
+
+/*-
+ * 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 abstract class YangTypeDef
+ extends YangNode
+ implements YangCommonInfo, Parsable, YangTypeHolder, CollisionDetector,
+ YangTranslatorOperatorNode {
+
+ 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;
+
+ /**
+ * 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 final List<YangType<?>> typeList;
+
+ /**
+ * Creates a typedef node.
+ */
+ public YangTypeDef() {
+ super(TYPEDEF_NODE, null);
+ typeList = new LinkedList<>();
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+ throws DataModelException {
+ // Do nothing.
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // Do nothing, to be handled during linking.
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier id,
+ YangSchemaNode node) {
+ // Do nothing, to be handled during linking.
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_NON_DATA_NODE;
+ }
+
+ /**
+ * 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 (!typeList.isEmpty()) {
+ return typeList.get(0);
+ }
+ return null;
+ }
+
+ /**
+ * Sets the data type.
+ *
+ * @param dataType the data type
+ */
+ public void setDataType(YangType<?> dataType) {
+ typeList.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 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 {
+ if (defaultValueInString != null && !defaultValueInString.isEmpty() &&
+ getTypeDefBaseType() != null) {
+ getTypeDefBaseType().isValidValue(defaultValueInString);
+ }
+ }
+
+ @Override
+ public List<YangType<?>> getTypeList() {
+ return unmodifiableList(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(
+ getErrorMsgCollision(COLLISION_DETECTION, getName(),
+ getLineNumber(), getCharPosition(),
+ TYPEDEF, getFileName()));
+ }
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangTypeHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangTypeHolder.java
new file mode 100644
index 0000000..443ec08
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUnion.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUnion.java
new file mode 100644
index 0000000..7dd545a
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUnion.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_NON_DATA_NODE;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsg;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.UNION_DATA;
+
+/*
+ * 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 abstract class YangUnion
+ extends YangNode
+ implements Parsable, YangTypeHolder, CollisionDetector {
+
+ private static final long serialVersionUID = 806201616L;
+
+ // List of YANG type.
+ private List<YangType<?>> typeList;
+
+ // Current child union number.
+ private transient int childUnionNumber;
+
+ /**
+ * Creates a YANG union node.
+ */
+ public YangUnion() {
+ super(YangNodeType.UNION_NODE, null);
+ typeList = new LinkedList<>();
+ childUnionNumber = 1;
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier schemaNodeIdentifier,
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+ throws DataModelException {
+ // Do nothing.
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // Do nothing, as leaf can't come directly or indirectly below this construct.
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier, YangSchemaNode yangSchemaNode) {
+ // Do nothing, as leaf can't come directly or indirectly below this construct.
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_NON_DATA_NODE;
+ }
+
+ @Override
+ public List<YangType<?>> getTypeList() {
+ return 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 {
+ YangDataTypes type = yangType.getDataType();
+ String msg = "Union member type must not be one of the built-in types" +
+ " \"empty\" or \"leafref\"";
+ switch (type) {
+ case EMPTY:
+ case LEAFREF:
+ throw new DataModelException(getErrorMsg(
+ msg, getName(), getLineNumber(), getCharPosition(),
+ getFileName()));
+
+ default:
+ typeList.add(yangType);
+ }
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return 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.
+ }
+
+ @Override
+ public void detectCollidingChild(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Do nothing
+ }
+
+ @Override
+ public void detectSelfCollision(String identifierName, YangConstructType dataType)
+ throws DataModelException {
+ // Do nothing
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUses.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUses.java
new file mode 100644
index 0000000..b622e28
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangUses.java
@@ -0,0 +1,562 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yang.compiler.datamodel.TraversalType.CHILD;
+import static org.onosproject.yang.compiler.datamodel.TraversalType.PARENT;
+import static org.onosproject.yang.compiler.datamodel.TraversalType.ROOT;
+import static org.onosproject.yang.compiler.datamodel.TraversalType.SIBILING;
+import static org.onosproject.yang.compiler.datamodel.YangNodeType.USES_NODE;
+import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_NON_DATA_NODE;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.USES;
+import static org.onosproject.yang.compiler.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.addUnresolvedType;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.RESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.UNRESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.LEAF_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.LEAF_LIST_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.USES_DATA;
+
+/*-
+ * 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 | -YangIfFeature |
+ * | refine | 7.12.2 | 0..1 | -TODO |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * | status | 7.19.2 | 0..1 | -YangStatus |
+ * | when | 7.19.5 | 0..1 | -YangWhen |
+ * +--------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents data model node to maintain information defined in YANG uses.
+ */
+public abstract class YangUses
+ extends YangNode
+ implements YangCommonInfo, Parsable, Resolvable, CollisionDetector,
+ YangWhenHolder, YangIfFeatureHolder, YangTranslatorOperatorNode,
+ LeafRefInvalidHolder {
+
+ 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;
+
+ /**
+ * When data of the node.
+ */
+ private YangWhen when;
+
+ /**
+ * List of if-feature.
+ */
+ private List<YangIfFeature> ifFeatureList;
+
+ /**
+ * Status of resolution. If completely resolved enum value is "RESOLVED",
+ * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
+ * is added to uses/type but it's not resolved value of enum should be
+ * "INTRA_FILE_RESOLVED".
+ */
+ private ResolvableStatus resolvableStatus;
+
+ /**
+ * Effective list of leaf lists of grouping that needs to replicated at YANG uses.
+ */
+ private List<YangEntityToResolveInfoImpl> entityToResolveInfoList;
+
+ /**
+ * Current grouping depth for uses.
+ */
+ private int currentGroupingDepth;
+
+ /**
+ * Creates an YANG uses node.
+ */
+ public YangUses() {
+ super(USES_NODE, null);
+ nodeIdentifier = new YangNodeIdentifier();
+ resolvableStatus = UNRESOLVED;
+ ifFeatureList = new LinkedList<>();
+ entityToResolveInfoList = new LinkedList<>();
+ }
+
+ @Override
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo context)
+ throws DataModelException {
+ // Do nothing.
+ }
+
+ @Override
+ public void incrementMandatoryChildCount() {
+ // Do nothing.
+ // TODO
+ }
+
+ @Override
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier id,
+ YangSchemaNode yangSchemaNode) {
+ // Do nothing.
+ // TODO
+ }
+
+ @Override
+ public YangSchemaNodeType getYangSchemaNodeType() {
+ return YANG_NON_DATA_NODE;
+ }
+
+ /**
+ * Adds an entity to resolve in list.
+ *
+ * @param entityToResolve entity to resolved
+ * @throws DataModelException a violation of data model rules
+ */
+ public void addEntityToResolve(
+ List<YangEntityToResolveInfoImpl> entityToResolve)
+ throws DataModelException {
+ if (entityToResolveInfoList == null) {
+ entityToResolveInfoList = new
+ LinkedList<>();
+ }
+ entityToResolveInfoList.addAll(entityToResolve);
+ }
+
+ /**
+ * 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 when.
+ *
+ * @return the when
+ */
+ @Override
+ public YangWhen getWhen() {
+ return when;
+ }
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ @Override
+ public void setWhen(YangWhen when) {
+ this.when = when;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @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 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
+ }
+
+ /**
+ * 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 Object resolve()
+ throws DataModelException {
+
+ YangGrouping referredGrouping = getRefGroup();
+
+ if (referredGrouping == null) {
+ throw new DataModelException("YANG uses linker error, cannot resolve" +
+ " uses " + getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition() + " in " +
+ getFileName() + "\"");
+ } else {
+ /*
+ * if referredGrouping has uses which is not resolved then set the status
+ * as Intra file resolved and return
+ */
+ if (checkIsUnresolvedRecursiveUsesInGrouping(referredGrouping)) {
+ return null;
+ }
+ }
+
+ YangNode usesParentNode = getParentNodeInGenCode(this);
+ if (!(usesParentNode instanceof YangLeavesHolder)
+ || !(usesParentNode instanceof CollisionDetector)) {
+ throw new DataModelException(
+ "YANG uses holder construct is wrong " + getName() + " in " +
+ getLineNumber() + " at " + getCharPosition() +
+ " in " + getFileName() + "\"");
+ }
+
+ YangLeavesHolder usesParent = (YangLeavesHolder) usesParentNode;
+ if (referredGrouping.getListOfLeaf() != null) {
+ for (YangLeaf leaf : referredGrouping.getListOfLeaf()) {
+ YangLeaf clonedLeaf;
+ try {
+ ((CollisionDetector) usesParent)
+ .detectCollidingChild(leaf.getName(), LEAF_DATA);
+ clonedLeaf = leaf.clone();
+ clonedLeaf.setReferredLeaf(leaf);
+ addUnresolvedType(this, clonedLeaf, (YangNode) usesParent);
+ } catch (CloneNotSupportedException | DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
+
+ clonedLeaf.setContainedIn(usesParent);
+ usesParent.addLeaf(clonedLeaf);
+ }
+ }
+ if (referredGrouping.getListOfLeafList() != null) {
+ for (YangLeafList leafList : referredGrouping.getListOfLeafList()) {
+ YangLeafList clonedLeafList;
+ try {
+ ((CollisionDetector) usesParent)
+ .detectCollidingChild(leafList.getName(), LEAF_LIST_DATA);
+ clonedLeafList = leafList.clone();
+ clonedLeafList.setReferredSchemaLeafList(leafList);
+ addUnresolvedType(this, clonedLeafList,
+ (YangNode) usesParent);
+ } catch (CloneNotSupportedException | DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
+ clonedLeafList.setContainedIn(usesParent);
+ usesParent.addLeafList(clonedLeafList);
+ }
+ }
+
+ try {
+ cloneSubTree(referredGrouping, usesParentNode, this);
+ } catch (DataModelException e) {
+ throw new DataModelException(e.getMessage());
+ }
+ updateClonedLeavesUnionEnumRef(usesParent);
+ return unmodifiableList(entityToResolveInfoList);
+ }
+
+ /**
+ * Checks if referred grouping has uses which is not resolved then it set the
+ * status of current uses as intra file resolved and returns true.
+ *
+ * @param referredGrouping referred grouping node of uses
+ * @return true if referred grouping has unresolved uses
+ */
+ private boolean checkIsUnresolvedRecursiveUsesInGrouping(YangGrouping referredGrouping) {
+
+ /*
+ * Search the grouping node's children for presence of uses node.
+ */
+ TraversalType curTraversal = ROOT;
+ YangNode curNode = referredGrouping.getChild();
+ while (curNode != null) {
+ if (curNode == referredGrouping || (curNode instanceof YangUses &&
+ curNode.getName().equals(referredGrouping.getName()))) {
+ // if we have traversed all the child nodes, then exit from loop
+ return false;
+ }
+
+ // if child nodes has uses, then add it to resolution stack
+ if (curNode instanceof YangUses) {
+ if (((YangUses) curNode).getResolvableStatus() != RESOLVED) {
+ setResolvableStatus(INTRA_FILE_RESOLVED);
+ return true;
+ }
+ }
+
+ // Traversing all the child nodes of grouping
+ if (curTraversal != PARENT && curNode.getChild() != null) {
+ curTraversal = CHILD;
+ curNode = curNode.getChild();
+ } else if (curNode.getNextSibling() != null) {
+ curTraversal = SIBILING;
+ curNode = curNode.getNextSibling();
+ } else {
+ curTraversal = PARENT;
+ curNode = curNode.getParent();
+ }
+ }
+ return false;
+ }
+
+ @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(
+ getErrorMsgCollision(COLLISION_DETECTION, getName(),
+ getLineNumber(), getCharPosition(),
+ USES, getFileName()));
+ }
+ }
+
+ @Override
+ public List<YangIfFeature> getIfFeatureList() {
+ return unmodifiableList(ifFeatureList);
+ }
+
+ @Override
+ public void addIfFeatureList(YangIfFeature ifFeature) {
+ if (ifFeatureList == null) {
+ ifFeatureList = new LinkedList<>();
+ }
+ ifFeatureList.add(ifFeature);
+ }
+
+ @Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ /**
+ * Sets the current grouping depth.
+ *
+ * @param currentGroupingDepth current grouping depth
+ */
+ public void setCurrentGroupingDepth(int currentGroupingDepth) {
+ this.currentGroupingDepth = currentGroupingDepth;
+ }
+
+ /**
+ * Returns the current grouping depth.
+ *
+ * @return current grouping depth
+ */
+ public int getCurrentGroupingDepth() {
+ return currentGroupingDepth;
+ }
+
+ @Override
+ public String getName() {
+ return nodeIdentifier.getName();
+ }
+
+ @Override
+ public void setName(String name) {
+ nodeIdentifier.setName(name);
+ }
+
+ @Override
+ public YangNode clone(YangUses node) throws CloneNotSupportedException {
+ YangNode clnNode = (YangNode) super.clone();
+ clnNode.setParent(null);
+ clnNode.setChild(null);
+ clnNode.setNextSibling(null);
+ clnNode.setPreviousSibling(null);
+ return clnNode;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangWhen.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangWhen.java
new file mode 100644
index 0000000..68b6160
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangWhen.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel;
+
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.Parsable;
+import org.onosproject.yang.compiler.datamodel.utils.YangConstructType;
+
+import java.io.Serializable;
+
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.WHEN_DATA;
+
+/*
+ * Reference RFC 6020.
+ *
+ * The "when" statement makes its parent data definition statement
+ * conditional. The node defined by the parent data definition
+ * statement is only valid when the condition specified by the "when"
+ * statement is satisfied.
+ *
+ * The statement's argument is an XPath expression, which is used to formally
+ * specify this condition. If the XPath expression conceptually evaluates to
+ * "true" for a particular instance, then the node defined by the parent data
+ * definition statement is valid; otherwise, it is not.
+ *
+ * The when's sub-statements
+ *
+ * +---------------+---------+-------------+------------------+
+ * | substatement | section | cardinality |data model mapping|
+ * +---------------+---------+-------------+------------------+
+ * | description | 7.19.3 | 0..1 | -string |
+ * | reference | 7.19.4 | 0..1 | -string |
+ * +---------------+---------+-------------+------------------+
+ */
+
+/**
+ * Represents information defined in YANG when.
+ */
+public class YangWhen extends DefaultLocationInfo
+ implements YangDesc, YangReference, Parsable, Serializable {
+
+ private static final long serialVersionUID = 806201646L;
+
+ /**
+ * When condition info.
+ */
+ private String condition;
+
+ /**
+ * Description string.
+ */
+ private String description;
+
+ /**
+ * Reference string.
+ */
+ private String reference;
+
+ /**
+ * Creates a YANG when restriction.
+ */
+ public YangWhen() {
+ }
+
+ /**
+ * Returns the condition.
+ *
+ * @return the condition
+ */
+ public String getCondition() {
+ return condition;
+ }
+
+ /**
+ * Sets the condition.
+ *
+ * @param condition the condition to set
+ */
+ public void setCondition(String condition) {
+ this.condition = condition;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description set the description
+ */
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the textual reference.
+ *
+ * @return the reference
+ */
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ /**
+ * Sets the textual reference.
+ *
+ * @param reference the reference to set
+ */
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ /**
+ * Returns the type of the parsed data.
+ *
+ * @return returns WHEN_DATA
+ */
+ @Override
+ public YangConstructType getYangConstructType() {
+ return WHEN_DATA;
+ }
+
+ /**
+ * Validates the data on entering the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+
+ /**
+ * Validates the data on exiting the corresponding parse tree node.
+ *
+ * @throws DataModelException a violation of data model rules
+ */
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO auto-generated method stub, to be implemented by parser
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangWhenHolder.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangWhenHolder.java
new file mode 100644
index 0000000..08a4ee7
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangWhenHolder.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel;
+
+/**
+ * Abstraction of when entity. It is used to abstract the data holders of when.
+ */
+public interface YangWhenHolder {
+
+ /**
+ * Returns the when.
+ *
+ * @return the when
+ */
+ YangWhen getWhen();
+
+ /**
+ * Sets the when.
+ *
+ * @param when the when to set
+ */
+ void setWhen(YangWhen when);
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangXPathResolver.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangXPathResolver.java
new file mode 100644
index 0000000..075241c
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/YangXPathResolver.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.yang.compiler.datamodel;
+
+/**
+ * Abstraction of an entity which can be resolved with x-path linker.
+ */
+public interface YangXPathResolver {
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/exceptions/DataModelException.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/exceptions/DataModelException.java
new file mode 100644
index 0000000..054b6e4
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/exceptions/DataModelException.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel.exceptions;
+
+/**
+ * Represents base class for exceptions in data model operations.
+ */
+public class DataModelException extends Exception {
+
+ private static final long serialVersionUID = 201601270658L;
+ private transient int lineNumber;
+ private transient int charPositionInLine;
+ private transient String fileName;
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Returns YANG file name of the exception.
+ *
+ * @return YANG file name of the exception
+ */
+ public String getFileName() {
+ return this.fileName;
+ }
+
+ /**
+ * Sets file name in datamodel exception.
+ *
+ * @param fileName YANG file name
+ */
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/exceptions/ErrorMessages.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/exceptions/ErrorMessages.java
new file mode 100644
index 0000000..26f813e
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/exceptions/ErrorMessages.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel.exceptions;
+
+/**
+ * Represents error messages thrown by data model exception.
+ */
+public final class ErrorMessages {
+
+ private ErrorMessages() {
+ }
+
+ private static final String IN = " in ";
+ private static final String AT = " at ";
+ private static final String AS = "as ";
+ public static final String QUOTES = "\"";
+ public static final String CASE = " case ";
+ public static final String NOTIFICATION = " notificaiton ";
+ public static final String RPC = " rpc ";
+ public static final String INPUT = " input ";
+ public static final String OUTPUT = " output ";
+ public static final String CHOICE = " choice ";
+ public static final String GROUPING = " grouping ";
+ public static final String TYPEDEF = " typedef ";
+ public static final String USES = " uses ";
+ public static final String INVALID_CASE_HOLDER
+ = "\"Internal Data Model Tree Error: Invalid/Missing \"" +
+ " \"holder in case \"";
+ public static final String TARGET_NODE_LEAF_INFO = "target node leaf/leaf-list";
+ public static final String TARGET_NODE = "target node ";
+ public static final String COLLISION_DETECTION = "YANG File Error: " +
+ "Identifier collision detected in";
+ public static final String FAILED_TO_ADD_CASE = "Failed to add child " +
+ "nodes to case node of augment ";
+
+ /**
+ * Returns error message for datamodel exception for collision detection.
+ *
+ * @param msg message
+ * @param name name of construct
+ * @param line line number
+ * @param position character position
+ * @param fileName file name
+ * @return error message for datamodel exception for collision detection
+ */
+ public static String getErrorMsg(String msg, String name, int line,
+ int position, String fileName) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(msg)
+ .append(name)
+ .append(IN)
+ .append(line)
+ .append(AT)
+ .append(position)
+ .append(IN)
+ .append(fileName);
+ return builder.toString();
+ }
+
+ /**
+ * Returns error message for datamodel exception for collision detection.
+ *
+ * @param msg message
+ * @param name name of construct
+ * @param line line number
+ * @param position character position
+ * @param construct construct name
+ * @param fileName file name
+ * @return error message for datamodel exception for collision detection
+ */
+ public static String getErrorMsgCollision(String msg, String name, int line,
+ int position, String construct,
+ String fileName) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(msg)
+ .append(construct)
+ .append(AS)
+ .append(QUOTES)
+ .append(name)
+ .append(IN)
+ .append(line)
+ .append(AT)
+ .append(position)
+ .append(IN)
+ .append(fileName)
+ .append(QUOTES);
+ return builder.toString();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/exceptions/package-info.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/exceptions/package-info.java
new file mode 100644
index 0000000..e22c2af
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.datamodel.exceptions;
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/JavaFileInfo.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/JavaFileInfo.java
new file mode 100644
index 0000000..284378b
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/JavaFileInfo.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.yang.compiler.datamodel.javadatamodel;
+
+import java.io.Serializable;
+
+/**
+ * Represents cached java file handle, which supports the addition of member attributes and
+ * methods.
+ */
+public class JavaFileInfo
+ implements Serializable {
+
+ private static final long serialVersionUID = 806102633L;
+
+ /**
+ * Name of the module.
+ */
+ protected String javaName;
+
+ /**
+ * Java package of the mapped java class.
+ */
+ protected String pkg;
+
+ /**
+ * Java attribute name;
+ */
+ protected String javaAttributeName;
+
+ /**
+ * Returns the java name of the node.
+ *
+ * @return the java name of node
+ */
+ public String getJavaName() {
+ return javaName;
+ }
+
+ /**
+ * Sets the java name of the node.
+ *
+ * @param name the java name of node
+ */
+ public void setJavaName(String name) {
+ javaName = name;
+ }
+
+ /**
+ * Returns the mapped java package.
+ *
+ * @return the java package
+ */
+ public String getPackage() {
+ return pkg;
+ }
+
+ /**
+ * Sets the node's package.
+ *
+ * @param nodePackage node's package
+ */
+ public void setPackage(String nodePackage) {
+ pkg = nodePackage;
+ }
+
+ /**
+ * Retrieve Java attribute name.
+ *
+ * @return Java attribute name
+ */
+ public String getJavaAttributeName() {
+ return javaAttributeName;
+ }
+
+ /**
+ * Assign the Java attribute Name.
+ *
+ * @param javaAttributeName Java attribute name
+ */
+ public void setJavaAttributeName(String javaAttributeName) {
+ this.javaAttributeName = javaAttributeName;
+ }
+
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/JavaQualifiedTypeInfo.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/JavaQualifiedTypeInfo.java
new file mode 100644
index 0000000..fcf0da0
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/JavaQualifiedTypeInfo.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.yang.compiler.datamodel.javadatamodel;
+
+import java.io.Serializable;
+
+/**
+ * Represents the information about individual imports in the generated file.
+ */
+public class JavaQualifiedTypeInfo
+ implements Serializable {
+
+ private static final long serialVersionUID = 806201634L;
+
+ /**
+ * Package location where the imported class/interface is defined.
+ */
+ protected String pkgInfo;
+
+ /**
+ * Class/interface being referenced.
+ */
+ protected String classInfo;
+
+ /**
+ * attribute name being used.
+ */
+ protected String javaAttributeName;
+ /**
+ * Returns the imported package info.
+ *
+ * @return the imported package info
+ */
+ public String getPkgInfo() {
+ return pkgInfo;
+ }
+
+ /**
+ * Sets the imported package info.
+ *
+ * @param pkgInfo the imported package info
+ */
+ public void setPkgInfo(String pkgInfo) {
+ this.pkgInfo = pkgInfo;
+ }
+
+ /**
+ * Returns the imported class/interface info.
+ *
+ * @return the imported class/interface info
+ */
+ public String getClassInfo() {
+ return classInfo;
+ }
+
+ /**
+ * Sets the imported class/interface info.
+ *
+ * @param classInfo the imported class/interface info
+ */
+ public void setClassInfo(String classInfo) {
+ this.classInfo = classInfo;
+ }
+
+ /**
+ * Retrieve Java attribute name.
+ *
+ * @return Java attribute name
+ */
+ public String getJavaAttributeName() {
+ return javaAttributeName;
+ }
+
+ /**
+ * Assign Java attribute name.
+ *
+ * @param javaAttributeName Java attribute name
+ */
+ public void setJavaAttributeName(String javaAttributeName) {
+ this.javaAttributeName = javaAttributeName;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/JavaQualifiedTypeInfoContainer.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/JavaQualifiedTypeInfoContainer.java
new file mode 100644
index 0000000..dc14455
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/JavaQualifiedTypeInfoContainer.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+/**
+ * Maintain the java qualified access details for an attribute or a class.
+ */
+public interface JavaQualifiedTypeInfoContainer {
+
+ /**
+ * Obtain the java qualified details.
+ *
+ * @return java qualified type details
+ */
+ JavaQualifiedTypeInfo getJavaQualifiedInfo();
+
+ /**
+ * Assign the qualified type info.
+ *
+ * @param typeInfo qualified type information
+ */
+ void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo);
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaAugment.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaAugment.java
new file mode 100644
index 0000000..c358326
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaAugment.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangAugment;
+
+/**
+ * Represents YANG java augment.
+ */
+public class YangJavaAugment
+ extends YangAugment {
+
+ private static final long serialVersionUID = 208201601L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ return getJavaFileInfo().getJavaAttributeName();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaCase.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaCase.java
new file mode 100644
index 0000000..bc5bd70
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaCase.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangCase;
+import org.onosproject.yang.compiler.datamodel.YangNode;
+
+/**
+ * Represents YANG java case.
+ */
+public class YangJavaCase
+ extends YangCase {
+
+ private static final long serialVersionUID = 208201602L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ YangNode parent = getParent();
+ if (parent instanceof YangJavaChoice) {
+ return ((YangJavaChoice) parent).getJavaFileInfo()
+ .getJavaAttributeName();
+ }
+ throw new RuntimeException("Attribute name is not applicable ");
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaChoice.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaChoice.java
new file mode 100644
index 0000000..406b442
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaChoice.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangChoice;
+
+/**
+ * Represents YANG java choice.
+ */
+public class YangJavaChoice
+ extends YangChoice {
+
+ private static final long serialVersionUID = 208201603L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ return getJavaFileInfo().getJavaAttributeName();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaContainer.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaContainer.java
new file mode 100644
index 0000000..68dc622
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaContainer.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangContainer;
+
+/**
+ * Represents YANG java container.
+ */
+public class YangJavaContainer
+ extends YangContainer {
+
+ private static final long serialVersionUID = 208201604L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ return getJavaFileInfo().getJavaAttributeName();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaEnumeration.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaEnumeration.java
new file mode 100644
index 0000000..9f41d3a
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaEnumeration.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangEnumeration;
+
+/**
+ * Represents YANG java enumeration.
+ */
+public class YangJavaEnumeration
+ extends YangEnumeration {
+
+ private static final long serialVersionUID = 208201605L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ throw new RuntimeException("Attribute name is not applicable ");
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaGrouping.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaGrouping.java
new file mode 100644
index 0000000..7fc247c
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaGrouping.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangGrouping;
+
+/**
+ * Represents YANG java grouping.
+ */
+public class YangJavaGrouping
+ extends YangGrouping {
+
+ private static final long serialVersionUID = 208201606L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ throw new RuntimeException("Attribute name is not applicable ");
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaIdentity.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaIdentity.java
new file mode 100644
index 0000000..bd447e4
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaIdentity.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangIdentity;
+
+/**
+ * Represents YANG java identity.
+ */
+public class YangJavaIdentity
+ extends YangIdentity {
+
+ private static final long serialVersionUID = 208201616L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ return getJavaFileInfo().getJavaAttributeName();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaInput.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaInput.java
new file mode 100644
index 0000000..c83cec2
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaInput.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangInput;
+
+/**
+ * Represents YANG java input.
+ */
+public class YangJavaInput
+ extends YangInput {
+
+ private static final long serialVersionUID = 208201607L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ return getJavaFileInfo().getJavaAttributeName();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaLeaf.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaLeaf.java
new file mode 100644
index 0000000..7549862
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaLeaf.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangLeaf;
+
+/**
+ * Represent YANG java leaf.
+ */
+public class YangJavaLeaf
+ extends YangLeaf
+ implements JavaQualifiedTypeInfoContainer {
+
+ private static final long serialVersionUID = 208201617L;
+
+ protected JavaQualifiedTypeInfo javaQualifiedTypeInfo;
+
+ /**
+ * Sets java qualified type info.
+ *
+ * @param javaQualifiedTypeInfo java qualified type info
+ */
+ public void setJavaQualifiedInfo(JavaQualifiedTypeInfo javaQualifiedTypeInfo) {
+ this.javaQualifiedTypeInfo = javaQualifiedTypeInfo;
+ }
+
+ /**
+ * Returns java qualified type info.
+ *
+ * @return java qualified type info
+ */
+ public JavaQualifiedTypeInfo getJavaQualifiedInfo() {
+ return javaQualifiedTypeInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaQualifiedInfo().getPkgInfo();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaQualifiedInfo().getClassInfo();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ return getJavaQualifiedInfo().getJavaAttributeName();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaLeafList.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaLeafList.java
new file mode 100644
index 0000000..8825fa7
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaLeafList.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangLeafList;
+
+/**
+ * Represents YANG java leaf list.
+ */
+public class YangJavaLeafList
+ extends YangLeafList
+ implements JavaQualifiedTypeInfoContainer {
+
+ private static final long serialVersionUID = 208201618L;
+
+ protected JavaQualifiedTypeInfo javaQualifiedTypeInfo;
+
+ /**
+ * Returns java qualified type info.
+ *
+ * @return java qualified type info
+ */
+ public JavaQualifiedTypeInfo getJavaQualifiedInfo() {
+ return javaQualifiedTypeInfo;
+ }
+
+ /**
+ * Sets java qualified type info.
+ *
+ * @param javaQualifiedTypeInfo java qualified type info
+ */
+ public void setJavaQualifiedInfo(JavaQualifiedTypeInfo javaQualifiedTypeInfo) {
+ this.javaQualifiedTypeInfo = javaQualifiedTypeInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaQualifiedInfo().getPkgInfo();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaQualifiedInfo().getClassInfo();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ return getJavaQualifiedInfo().getJavaAttributeName();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaList.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaList.java
new file mode 100644
index 0000000..72ee3b5
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaList.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangList;
+
+/**
+ * Represent YANG java list.
+ */
+public class YangJavaList
+ extends YangList {
+
+ private static final long serialVersionUID = 208201608L;
+
+ /**
+ * Contains the information of the java file being generated.
+ */
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ return getJavaFileInfo().getJavaAttributeName();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaModule.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaModule.java
new file mode 100644
index 0000000..fb98261
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaModule.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangModule;
+import org.onosproject.yang.compiler.datamodel.YangNode;
+
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+
+/**
+ * Represents YANG java module.
+ */
+public class YangJavaModule
+ extends YangModule {
+
+ private static final long serialVersionUID = 208201609L;
+
+ protected JavaFileInfo javaFileInfo;
+ protected List<YangNode> notificationNodes;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ throw new RuntimeException("Attribute name is not applicable ");
+ }
+
+ @Override
+ public List<YangNode> getNotificationNodes() {
+ return unmodifiableList(notificationNodes);
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaNotification.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaNotification.java
new file mode 100644
index 0000000..a774327
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaNotification.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangNotification;
+
+/**
+ * Represents YANG java notification.
+ */
+public class YangJavaNotification
+ extends YangNotification {
+
+ private static final long serialVersionUID = 208201610L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ return getJavaFileInfo().getJavaAttributeName();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaOutput.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaOutput.java
new file mode 100644
index 0000000..2fc9983
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaOutput.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangOutput;
+
+/**
+ * Represents YANG java output.
+ */
+public class YangJavaOutput
+ extends YangOutput {
+
+ private static final long serialVersionUID = 208201611L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ return getJavaFileInfo().getJavaAttributeName();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaRpc.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaRpc.java
new file mode 100644
index 0000000..e88c624
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaRpc.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangRpc;
+
+/**
+ * Represents YANG java rpc.
+ */
+public class YangJavaRpc
+ extends YangRpc {
+
+ private static final long serialVersionUID = 208201612L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ return getJavaFileInfo().getJavaAttributeName();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaSubModule.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaSubModule.java
new file mode 100644
index 0000000..00ee10c
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaSubModule.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangNode;
+import org.onosproject.yang.compiler.datamodel.YangSubModule;
+
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+
+/**
+ * Represents YANG java submodule.
+ */
+public class YangJavaSubModule
+ extends YangSubModule {
+
+ private static final long serialVersionUID = 208201612L;
+
+ protected JavaFileInfo javaFileInfo;
+ protected List<YangNode> notificationNodes;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ throw new RuntimeException("Attribute name is not applicable ");
+ }
+
+ @Override
+ public List<YangNode> getNotificationNodes() {
+ return unmodifiableList(notificationNodes);
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaType.java
new file mode 100644
index 0000000..9eaf4b0
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaType.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangType;
+
+/**
+ * Represents YANG java type.
+ */
+public class YangJavaType extends YangType implements JavaQualifiedTypeInfoContainer {
+
+ private static final long serialVersionUID = 19082016001L;
+ protected JavaQualifiedTypeInfo javaQualifiedTypeInfo;
+
+ /**
+ * Returns java qualified type info.
+ *
+ * @return java qualified type info
+ */
+
+ @Override
+ public JavaQualifiedTypeInfo getJavaQualifiedInfo() {
+ return javaQualifiedTypeInfo;
+ }
+
+ @Override
+ public void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo) {
+ this.javaQualifiedTypeInfo = typeInfo;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaTypeDef.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaTypeDef.java
new file mode 100644
index 0000000..c97719a
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaTypeDef.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangTypeDef;
+
+/**
+ * Represents YANG java typedef.
+ */
+public class YangJavaTypeDef
+ extends YangTypeDef {
+
+ private static final long serialVersionUID = 208201613L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ throw new RuntimeException("Attribute name is not applicable ");
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaUnion.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaUnion.java
new file mode 100644
index 0000000..858bd58
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaUnion.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.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangUnion;
+
+/**
+ * Represent YANG java union.
+ */
+public class YangJavaUnion
+ extends YangUnion {
+
+ private static final long serialVersionUID = 208201614L;
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ throw new RuntimeException("Attribute name is not applicable ");
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaUses.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaUses.java
new file mode 100644
index 0000000..466fd3c
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/YangJavaUses.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
+
+import org.onosproject.yang.compiler.datamodel.YangUses;
+
+/**
+ * Represent YANG java uses.
+ */
+public class YangJavaUses
+ extends YangUses {
+
+ private static final long serialVersionUID = 208201615L;
+
+ protected JavaFileInfo javaFileInfo;
+
+ /**
+ * Returns java file info.
+ *
+ * @return java file info
+ */
+ public JavaFileInfo getJavaFileInfo() {
+ return javaFileInfo;
+ }
+
+ @Override
+ public String getJavaPackage() {
+ return getJavaFileInfo().getPackage();
+ }
+
+ @Override
+ public String getJavaClassNameOrBuiltInType() {
+ return getJavaFileInfo().getJavaName();
+ }
+
+ @Override
+ public String getJavaAttributeName() {
+ throw new RuntimeException("Attribute name is not applicable ");
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/package-info.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/package-info.java
new file mode 100644
index 0000000..45da407
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/javadatamodel/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.
+ */
+
+/**
+ * Representation of YANG java data model.
+ */
+package org.onosproject.yang.compiler.datamodel.javadatamodel;
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/package-info.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/package-info.java
new file mode 100644
index 0000000..f02b899
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.datamodel;
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
new file mode 100644
index 0000000..bfb5b8d
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
@@ -0,0 +1,847 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.utils;
+
+import org.onosproject.yang.compiler.datamodel.CollisionDetector;
+import org.onosproject.yang.compiler.datamodel.ResolvableType;
+import org.onosproject.yang.compiler.datamodel.YangAtomicPath;
+import org.onosproject.yang.compiler.datamodel.YangAugment;
+import org.onosproject.yang.compiler.datamodel.YangBase;
+import org.onosproject.yang.compiler.datamodel.YangCompilerAnnotation;
+import org.onosproject.yang.compiler.datamodel.YangDerivedInfo;
+import org.onosproject.yang.compiler.datamodel.YangEntityToResolveInfoImpl;
+import org.onosproject.yang.compiler.datamodel.YangEnumeration;
+import org.onosproject.yang.compiler.datamodel.YangIdentityRef;
+import org.onosproject.yang.compiler.datamodel.YangIfFeature;
+import org.onosproject.yang.compiler.datamodel.YangImport;
+import org.onosproject.yang.compiler.datamodel.YangLeaf;
+import org.onosproject.yang.compiler.datamodel.YangLeafList;
+import org.onosproject.yang.compiler.datamodel.YangLeafRef;
+import org.onosproject.yang.compiler.datamodel.YangLeavesHolder;
+import org.onosproject.yang.compiler.datamodel.YangModule;
+import org.onosproject.yang.compiler.datamodel.YangNode;
+import org.onosproject.yang.compiler.datamodel.YangReferenceResolver;
+import org.onosproject.yang.compiler.datamodel.YangResolutionInfo;
+import org.onosproject.yang.compiler.datamodel.YangRpc;
+import org.onosproject.yang.compiler.datamodel.YangType;
+import org.onosproject.yang.compiler.datamodel.YangUnion;
+import org.onosproject.yang.compiler.datamodel.YangUses;
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.ENUMERATION;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UNION;
+
+
+/**
+ * Represents utilities for data model tree.
+ */
+public final class DataModelUtils {
+ public static final String TRUE = "true";
+ public static final String FALSE = "false";
+ private static final String SLASH = File.separator;
+
+ /**
+ * 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
+ */
+ private 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() + " in " +
+ leaf.getLineNumber() + " at " +
+ leaf.getCharPosition() +
+ " in " + leaf.getFileName() + "\"");
+ }
+ }
+ }
+
+ /**
+ * 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() + " in " +
+ leafList.getLineNumber() + " at " +
+ leafList.getCharPosition() +
+ " in " + leafList.getFileName() + "\"");
+ }
+ }
+ }
+
+ /**
+ * 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 if (resolutionInfo.getEntityToResolveInfo()
+ .getEntityToResolve() instanceof YangUses) {
+ resolutionNode.addToResolutionList(resolutionInfo,
+ ResolvableType.YANG_USES);
+ } else if (resolutionInfo.getEntityToResolveInfo()
+ .getEntityToResolve() instanceof YangAugment) {
+ resolutionNode.addToResolutionList(resolutionInfo,
+ ResolvableType.YANG_AUGMENT);
+ } else if (resolutionInfo.getEntityToResolveInfo()
+ .getEntityToResolve() instanceof YangIfFeature) {
+ resolutionNode.addToResolutionList(resolutionInfo,
+ ResolvableType.YANG_IF_FEATURE);
+ } else if (resolutionInfo.getEntityToResolveInfo()
+ .getEntityToResolve() instanceof YangLeafRef) {
+ resolutionNode.addToResolutionList(resolutionInfo,
+ ResolvableType.YANG_LEAFREF);
+ } else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangBase) {
+ resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_BASE);
+ } else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangIdentityRef) {
+ resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_IDENTITYREF);
+ } else if (resolutionInfo.getEntityToResolveInfo()
+ .getEntityToResolve() instanceof YangCompilerAnnotation) {
+ resolutionNode.addToResolutionList(resolutionInfo,
+ ResolvableType.YANG_COMPILER_ANNOTATION);
+ }
+ }
+
+ /**
+ * 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.
+ */
+ if (resolutionList != null) {
+ 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();
+ }
+
+ /**
+ * Returns de-serializes YANG data-model nodes.
+ *
+ * @param serializedFileInfo serialized File Info
+ * @return de-serializes YANG data-model nodes
+ * @throws IOException when fails do IO operations
+ */
+ public static Set<YangNode> deSerializeDataModel(String serializedFileInfo)
+ throws IOException {
+
+ Set<YangNode> nodes;
+ try {
+ FileInputStream fileInputStream = new FileInputStream(serializedFileInfo);
+ ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
+ nodes = (Set<YangNode>) objectInputStream.readObject();
+ objectInputStream.close();
+ fileInputStream.close();
+ } catch (IOException | ClassNotFoundException e) {
+ throw new IOException(serializedFileInfo + " not found.");
+ }
+ return nodes;
+ }
+
+ /**
+ * Adds the list of leaf present under a node to resolution list, after
+ * cloning. Under the cloned node, with cloned leaf, attributes are set
+ * and added to resolution list.
+ *
+ * @param clonedNode holder node
+ * @param yangUses YANG uses
+ * @throws CloneNotSupportedException clone not supported error
+ * @throws DataModelException data model error
+ */
+ public static void cloneListOfLeaf(
+ YangLeavesHolder clonedNode, YangUses yangUses)
+ throws CloneNotSupportedException, DataModelException {
+
+ List<YangLeaf> leaves = clonedNode.getListOfLeaf();
+ if (nonEmpty(leaves)) {
+ List<YangLeaf> clonedLeaves = new LinkedList<>();
+ for (YangLeaf leaf : leaves) {
+ YangLeaf clonedLeaf = leaf.clone();
+ clonedLeaf.setReferredLeaf(leaf);
+ addUnresolvedType(yangUses, clonedLeaf, (YangNode) clonedNode);
+ clonedLeaf.setContainedIn(clonedNode);
+ clonedLeaves.add(clonedLeaf);
+ }
+ clonedNode.setListOfLeaf(clonedLeaves);
+ }
+ }
+
+ /**
+ * Adds all the unresolved type under leaf/leaf-list to the resolution
+ * list, after cloning. This makes the resolution to happen after cloning
+ * of the grouping. Adds resolution with cloned node holder under which
+ * cloned type is present.
+ *
+ * @param yangUses YANG uses
+ * @param clonedObj cloned type object
+ * @param clonedNode holder node
+ * @throws DataModelException data model error
+ */
+ public static void addUnresolvedType(
+ YangUses yangUses, Object clonedObj,
+ YangNode clonedNode) throws DataModelException {
+
+ List<YangEntityToResolveInfoImpl> infoList;
+ if (yangUses != null && yangUses.getCurrentGroupingDepth() == 0) {
+ infoList = getTypesToBeResolved(clonedObj, clonedNode, yangUses);
+ if (nonEmpty(infoList)) {
+ yangUses.addEntityToResolve(infoList);
+ }
+ }
+ }
+
+ /**
+ * Returns true if collection object is non-null and non-empty; false
+ * otherwise.
+ *
+ * @param c collection object
+ * @return true if object is non-null and non-empty; false otherwise
+ */
+ public static boolean nonEmpty(Collection<?> c) {
+ return c != null && !c.isEmpty();
+ }
+
+ /**
+ * Adds the list of leaf-list present under a node to resolution list,
+ * after cloning. Under the cloned node, with cloned leaf-list,
+ * attributes are set and added to resolution list.
+ *
+ * @param clonedNode cloned holder
+ * @param yangUses YANG uses
+ * @throws CloneNotSupportedException clone not supported error
+ * @throws DataModelException data model error
+ */
+ public static void cloneListOfLeafList(
+ YangLeavesHolder clonedNode, YangUses yangUses)
+ throws CloneNotSupportedException, DataModelException {
+
+ List<YangLeafList> listOfLeafList = clonedNode.getListOfLeafList();
+ if (nonEmpty(listOfLeafList)) {
+ List<YangLeafList> clonedList = new LinkedList<>();
+ for (YangLeafList leafList : listOfLeafList) {
+ YangLeafList clonedLeafList = leafList.clone();
+ clonedLeafList.setReferredSchemaLeafList(leafList);
+ addUnresolvedType(yangUses, clonedLeafList,
+ (YangNode) clonedNode);
+ clonedLeafList.setContainedIn(clonedNode);
+ clonedList.add(clonedLeafList);
+ }
+ clonedNode.setListOfLeafList(clonedList);
+ }
+ }
+
+ /**
+ * Returns types that has to be resolved for a single leaf/leaf-list.
+ * Identifies the object to be leaf/leaf-list and assigns respective
+ * parameters to resolve the types under leaf/leaf-list.
+ *
+ * @param clonedObj leaf/leaf-list object
+ * @param holderNode holder node
+ * @param yangUses YANG uses
+ * @return list of resolvable entities in a leaf/leaf-list
+ * @throws DataModelException data model error
+ */
+ private static List<YangEntityToResolveInfoImpl> getTypesToBeResolved(
+ Object clonedObj, YangNode holderNode,
+ YangUses yangUses) throws DataModelException {
+
+ YangType type;
+ if (clonedObj instanceof YangLeaf) {
+ YangLeaf clonedLeaf = (YangLeaf) clonedObj;
+ type = clonedLeaf.getDataType();
+ return getUnresolvedTypeList(type.getDataType(), type, holderNode,
+ yangUses, true);
+ }
+ YangLeafList clonedLeafList = (YangLeafList) clonedObj;
+ type = clonedLeafList.getDataType();
+ return getUnresolvedTypeList(type.getDataType(), type, holderNode,
+ yangUses, false);
+ }
+
+ /**
+ * Returns list of resolvable entities from the type of leaf/leaf-list.
+ * If the type is leaf-ref, derived or union with type resolution
+ * required, it has to be resolved from the place where it is cloned. So,
+ * the resolution list added with these entities. When a type require no
+ * resolution then null is returned, so it will never be added to
+ * resolution list.
+ *
+ * @param dataTypes data type of type
+ * @param type type of leaf/leaf-list
+ * @param holder holder node of type
+ * @param yangUses YANG uses
+ * @param isLeaf leaf or leaf-list
+ * @return list of resolvable entities for a leaf/leaf-list.
+ * @throws DataModelException data model error
+ */
+ private static List<YangEntityToResolveInfoImpl> getUnresolvedTypeList(
+ YangDataTypes dataTypes, YangType type, YangNode holder,
+ YangUses yangUses, boolean isLeaf) throws DataModelException {
+
+ List<YangEntityToResolveInfoImpl> infoList = new ArrayList<>();
+ YangEntityToResolveInfoImpl entity = null;
+ List<YangEntityToResolveInfoImpl> entityList = null;
+
+ switch (dataTypes) {
+ case LEAFREF:
+ entity = getLeafRefResolvableEntity(type, yangUses, holder);
+ break;
+
+ case DERIVED:
+ entity = getDerivedResolvableEntity(type, holder, isLeaf);
+ break;
+
+ case UNION:
+ entityList = getUnionResolvableEntity(type, isLeaf);
+ break;
+
+ default:
+ return null;
+ }
+ infoList.add(entity);
+ if (nonEmpty(entityList)) {
+ infoList.addAll(entityList);
+ }
+ return infoList;
+ }
+
+ /**
+ * Returns resolvable entity when the type is leaf-ref. It changes the
+ * prefixes from grouping to uses, then changes the parent node to the
+ * cloned node, sets needed information to entity such as line number,
+ * position number and holder.
+ *
+ * @param type YANG type of leaf-ref
+ * @param yangUses YANG uses
+ * @param holder cloned holder
+ * @return entity to resolve for leaf-ref
+ * @throws DataModelException data model error
+ */
+ private static YangEntityToResolveInfoImpl getLeafRefResolvableEntity(
+ YangType type, YangUses yangUses, YangNode holder)
+ throws DataModelException {
+
+ YangEntityToResolveInfoImpl<YangLeafRef> leafRefInfo =
+ new YangEntityToResolveInfoImpl<>();
+ YangLeafRef leafRef = (YangLeafRef) type.getDataTypeExtendedInfo();
+
+ // Conversion of prefixes in absolute path while cloning them.
+ convertThePrefixesDuringChange(leafRef, yangUses);
+ leafRef.setParentNode(holder);
+ leafRefInfo.setEntityToResolve(leafRef);
+
+ return setInformationInEntity(
+ leafRefInfo, holder, leafRef.getCharPosition(),
+ leafRef.getLineNumber());
+ }
+
+ /**
+ * Returns resolvable entity when the type is derived. It sets needed
+ * information to entity such as line number,position number and holder.
+ * Returns null when identity is for inter grouping.
+ *
+ * @param type derived YANG type
+ * @param holder holder node
+ * @param isLeaf leaf or leaf-list
+ * @return entity to resolve for derived type
+ */
+ private static YangEntityToResolveInfoImpl getDerivedResolvableEntity(
+ YangType<?> type, YangNode holder, boolean isLeaf) {
+
+ YangEntityToResolveInfoImpl<YangType<?>> derivedInfo =
+ new YangEntityToResolveInfoImpl<>();
+ if (type.isTypeForInterFileGroupingResolution()) {
+ return null;
+ }
+ if (!isLeaf && type.isTypeNotResolvedTillRootNode()) {
+ return null;
+ }
+
+ derivedInfo.setEntityToResolve(type);
+ return setInformationInEntity(
+ derivedInfo, holder, type.getCharPosition(),
+ type.getLineNumber());
+ }
+
+ /**
+ * Sets the information needed for adding the entity into resolution
+ * list, such as line number, position number and cloned holder node.
+ *
+ * @param entity resolvable entity
+ * @param holder cloned holder node
+ * @param charPos character position
+ * @param lineNum line number
+ * @return resolvable entity after setting info
+ */
+ private static YangEntityToResolveInfoImpl<?> setInformationInEntity(
+ YangEntityToResolveInfoImpl<?> entity, YangNode holder,
+ int charPos, int lineNum) {
+
+ entity.setHolderOfEntityToResolve(holder);
+ entity.setCharPosition(charPos);
+ entity.setLineNumber(lineNum);
+ return entity;
+ }
+
+ /**
+ * Returns resolvable entity under union. When types under union have
+ * identity-ref, derived and union, the function call is done recursively
+ * to get resolvable entity and adds it to list.
+ *
+ * @param type union YANG type
+ * @param isLeaf leaf or leaf-list
+ * @return resolvable entity list after setting info
+ * @throws DataModelException data model error
+ */
+ private static List<YangEntityToResolveInfoImpl> getUnionResolvableEntity(
+ YangType type, boolean isLeaf) throws DataModelException {
+
+ YangUnion union = (YangUnion) type.getDataTypeExtendedInfo();
+ List<YangType<?>> typeList = union.getTypeList();
+ List<YangEntityToResolveInfoImpl> unionList = new ArrayList<>();
+ List<YangEntityToResolveInfoImpl> entity;
+
+ for (YangType unionType : typeList) {
+ entity = getUnresolvedTypeList(unionType.getDataType(),
+ unionType, union, null, isLeaf);
+ if (nonEmpty(entity)) {
+ unionList.addAll(entity);
+ }
+ }
+ return unionList;
+ }
+
+ /**
+ * Converts the prefixes in all the nodes of the leafref with respect to the uses node.
+ *
+ * @param leafrefForCloning leafref that is to be cloned
+ * @param yangUses instance of YANG uses where cloning is done
+ * @throws DataModelException data model error
+ */
+ private static void convertThePrefixesDuringChange(YangLeafRef leafrefForCloning, YangUses yangUses)
+ throws DataModelException {
+ List<YangAtomicPath> atomicPathList = leafrefForCloning.getAtomicPath();
+ if (atomicPathList != null && !atomicPathList.isEmpty()) {
+ Iterator<YangAtomicPath> atomicPathIterator = atomicPathList.listIterator();
+ while (atomicPathIterator.hasNext()) {
+ YangAtomicPath atomicPath = atomicPathIterator.next();
+ Map<String, String> prefixesAndItsImportNameNode = leafrefForCloning.getPrefixAndNode();
+ String prefixInPath = atomicPath.getNodeIdentifier().getPrefix();
+ String importedNodeName = prefixesAndItsImportNameNode.get(prefixInPath);
+ assignCurrentLeafedWithNewPrefixes(importedNodeName, atomicPath, yangUses);
+ }
+ }
+ }
+
+ /**
+ * Assigns leafref with new prefixes while cloning.
+ *
+ * @param importedNodeName imported node name from grouping
+ * @param atomicPath atomic path in leafref
+ * @param node instance of YANG uses where cloning is done
+ * @throws DataModelException data model error
+ */
+ private static void assignCurrentLeafedWithNewPrefixes(String importedNodeName, YangAtomicPath atomicPath,
+ YangNode node)
+ throws DataModelException {
+ while (!(node instanceof YangReferenceResolver)) {
+ node = node.getParent();
+ if (node == null) {
+ throw new DataModelException("Internal datamodel error: Datamodel tree is not correct");
+ }
+ }
+ if (node instanceof YangModule) {
+ List<YangImport> importInUsesList = ((YangModule) node).getImportList();
+ if (importInUsesList != null && !importInUsesList.isEmpty()) {
+ Iterator<YangImport> importInUsesListIterator = importInUsesList.listIterator();
+ while (importInUsesListIterator.hasNext()) {
+ YangImport importInUsesNode = importInUsesListIterator.next();
+ if (importInUsesNode.getModuleName().equals(importedNodeName)) {
+ atomicPath.getNodeIdentifier().setPrefix(importInUsesNode.getPrefixId());
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Clones the union or enum leaves. If there is any cloned leaves whose type is union/enum then the corresponding
+ * type info needs to be updated to the cloned new type node.
+ *
+ * @param leavesHolder cloned leaves holder, for whom the leaves reference needs to be updated
+ * @throws DataModelException when fails to do data model operations
+ */
+ public static void updateClonedLeavesUnionEnumRef(YangLeavesHolder leavesHolder)
+ throws DataModelException {
+ List<YangLeaf> currentListOfLeaves = leavesHolder.getListOfLeaf();
+ if (currentListOfLeaves != null) {
+ for (YangLeaf leaf : currentListOfLeaves) {
+ if (leaf.getDataType().getDataType() == ENUMERATION
+ || leaf.getDataType().getDataType() == UNION) {
+ try {
+ YangType<?> clonedType = leaf.getDataType().clone();
+ updateClonedTypeRef(clonedType, leavesHolder);
+ leaf.setDataType(clonedType);
+ } catch (DataModelException e) {
+ throw e;
+ } catch (CloneNotSupportedException e) {
+ e.printStackTrace();
+ throw new DataModelException("Could not clone Type node " +
+ leaf.getDataType().getDataTypeName() + " in " +
+ leaf.getDataType().getLineNumber() + " at " +
+ leaf.getDataType().getCharPosition() +
+ " in " + leaf.getDataType().getFileName() + "\"");
+ }
+ }
+ }
+ }
+
+ List<YangLeafList> currentListOfLeafList = leavesHolder.getListOfLeafList();
+ if (currentListOfLeafList != null) {
+ for (YangLeafList leafList : currentListOfLeafList) {
+ if (leafList.getDataType().getDataType() == ENUMERATION
+ || leafList.getDataType().getDataType() == UNION) {
+ try {
+ YangType<?> clonedType = leafList.getDataType().clone();
+ updateClonedTypeRef(clonedType, leavesHolder);
+ leafList.setDataType(clonedType);
+ } catch (DataModelException e) {
+ throw e;
+ } catch (CloneNotSupportedException e) {
+ e.printStackTrace();
+ throw new DataModelException("Could not clone Type node " +
+ leafList.getDataType().getDataTypeName() + " in " +
+ leafList.getDataType().getLineNumber() + " at " +
+ leafList.getDataType().getCharPosition() +
+ " in " + leafList.getDataType().getFileName() + "\"");
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Updates the types extended info pointer to point to the cloned type node.
+ *
+ * @param dataType data type, whose extended info needs to be pointed to the cloned type
+ * @param leavesHolder the leaves holder having the cloned type
+ */
+ private static void updateClonedTypeRef(YangType dataType, YangLeavesHolder leavesHolder)
+ throws DataModelException {
+ if (!(leavesHolder instanceof YangNode)) {
+ throw new DataModelException("Data model error: cloned leaves holder is not a node " +
+ " in " +
+ leavesHolder.getLineNumber() + " at " +
+ leavesHolder.getCharPosition() +
+ " in " + leavesHolder.getFileName() + "\"");
+ }
+ YangNode potentialTypeNode = ((YangNode) leavesHolder).getChild();
+ while (potentialTypeNode != null) {
+ String dataTypeName = null;
+ if (dataType.getDataType() == ENUMERATION) {
+ YangEnumeration enumNode = (YangEnumeration) dataType.getDataTypeExtendedInfo();
+ dataTypeName = enumNode.getName();
+ } else if (dataType.getDataType() == UNION) {
+ YangUnion unionNode = (YangUnion) dataType.getDataTypeExtendedInfo();
+ dataTypeName = unionNode.getName();
+ }
+ if (potentialTypeNode.getName().contentEquals(dataTypeName)) {
+ dataType.setDataTypeExtendedInfo(potentialTypeNode);
+ return;
+ }
+ potentialTypeNode = potentialTypeNode.getNextSibling();
+ }
+
+ throw new DataModelException("Data model error: cloned leaves type is not found " +
+ dataType.getDataTypeName() + " in " +
+ dataType.getLineNumber() + " at " +
+ dataType.getCharPosition() +
+ " in " + dataType.getFileName() + "\"");
+ }
+
+ /**
+ * Parses jar file and returns list of serialized file names.
+ *
+ * @param jarFile jar file to be parsed
+ * @param directory directory where to search
+ * @return list of serialized files
+ * @throws IOException when fails to do IO operations
+ */
+ public static List<YangNode> parseJarFile(String jarFile, String directory)
+ throws IOException {
+
+ List<YangNode> nodes = new ArrayList<>();
+ JarFile jar = new JarFile(jarFile);
+ Enumeration<?> enumEntries = jar.entries();
+
+ while (enumEntries.hasMoreElements()) {
+ JarEntry file = (JarEntry) enumEntries.nextElement();
+ if (file.getName().endsWith(".ser")) {
+
+ if (file.getName().contains(SLASH)) {
+ String[] strArray = file.getName().split(SLASH);
+ String tempPath = "";
+ for (int i = 0; i < strArray.length - 1; i++) {
+ tempPath = SLASH + tempPath + SLASH + strArray[i];
+ }
+ File dir = new File(directory + tempPath);
+ dir.mkdirs();
+ }
+ File serializedFile = new File(directory + SLASH + file.getName());
+ if (file.isDirectory()) {
+ serializedFile.mkdirs();
+ continue;
+ }
+ InputStream inputStream = jar.getInputStream(file);
+
+ FileOutputStream fileOutputStream = new FileOutputStream(serializedFile);
+ while (inputStream.available() > 0) {
+ fileOutputStream.write(inputStream.read());
+ }
+ fileOutputStream.close();
+ inputStream.close();
+ nodes.addAll(deSerializeDataModel(serializedFile.toString()));
+ }
+ }
+ jar.close();
+ return nodes;
+ }
+
+ /**
+ * Validates the requested data-type resolve type in empty or not.
+ *
+ * @param dataType the data type
+ * @return true, for empty resolved data-type; false otherwise
+ */
+ public static boolean validateEmptyDataType(YangType dataType) {
+ switch (dataType.getDataType()) {
+ case DERIVED:
+ return ((YangDerivedInfo) dataType.getDataTypeExtendedInfo())
+ .getEffectiveBuiltInType().equals(EMPTY);
+
+ case LEAFREF:
+ YangType type = ((YangLeafRef) dataType
+ .getDataTypeExtendedInfo())
+ .getEffectiveDataType();
+ if (type.getDataType() == DERIVED) {
+ return ((YangDerivedInfo) type.getDataTypeExtendedInfo())
+ .getEffectiveBuiltInType().equals(EMPTY);
+ }
+ return ((YangLeafRef) dataType.getDataTypeExtendedInfo())
+ .getEffectiveDataType().getDataType().equals(EMPTY);
+
+ case UNION:
+ return ((YangUnion) dataType.getDataTypeExtendedInfo())
+ .getTypeList().contains(EMPTY);
+ default:
+ return dataType.getDataType().equals(EMPTY);
+ }
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/FractionDigits.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/FractionDigits.java
new file mode 100644
index 0000000..b64c548
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/FractionDigits.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.utils;
+
+import org.onosproject.yang.compiler.datamodel.DefaultLocationInfo;
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+
+/**
+ * The "fraction-digits" statement, which is a substatement to the
+ * "type" statement, MUST be present if the type is "decimal64". It
+ * takes as an argument an integer between 1 and 18, inclusively. It
+ * controls the size of the minimum difference between values of a
+ * decimal64 type, by restricting the value space to numbers that are
+ * expressible as "i x 10^-n" where n is the fraction-digits argument.
+ *
+ * +----------------+-----------------------+----------------------+
+ * | fraction-digit | min | max |
+ * +----------------+-----------------------+----------------------+
+ * | 1 | -922337203685477580.8 | 922337203685477580.7 |
+ * | 2 | -92233720368547758.08 | 92233720368547758.07 |
+ * | 3 | -9223372036854775.808 | 9223372036854775.807 |
+ * | 4 | -922337203685477.5808 | 922337203685477.5807 |
+ * | 5 | -92233720368547.75808 | 92233720368547.75807 |
+ * | 6 | -9223372036854.775808 | 9223372036854.775807 |
+ * | 7 | -922337203685.4775808 | 922337203685.4775807 |
+ * | 8 | -92233720368.54775808 | 92233720368.54775807 |
+ * | 9 | -9223372036.854775808 | 9223372036.854775807 |
+ * | 10 | -922337203.6854775808 | 922337203.6854775807 |
+ * | 11 | -92233720.36854775808 | 92233720.36854775807 |
+ * | 12 | -9223372.036854775808 | 9223372.036854775807 |
+ * | 13 | -922337.2036854775808 | 922337.2036854775807 |
+ * | 14 | -92233.72036854775808 | 92233.72036854775807 |
+ * | 15 | -9223.372036854775808 | 9223.372036854775807 |
+ * | 16 | -922.3372036854775808 | 922.3372036854775807 |
+ * | 17 | -92.23372036854775808 | 92.23372036854775807 |
+ * | 18 | -9.223372036854775808 | 9.223372036854775807 |
+ * +----------------+-----------------------+----------------------+
+ */
+
+/**
+ * Represents the decimal64 value range based on fraction-digits.
+ */
+public final class FractionDigits extends DefaultLocationInfo {
+
+ public static class Range {
+ private double min;
+ private double max;
+
+ /**
+ * Creates an instance of range.
+ *
+ * @param min minimum value of decimal64
+ * @param max maximum value of decimal64
+ */
+ protected Range(double min, double max) {
+ this.min = min;
+ this.max = max;
+ }
+
+ /**
+ * Retrieve minimum value range.
+ *
+ * @return minimum value range
+ */
+ public double getMin() {
+ return min;
+ }
+
+ /**
+ * Retrieve maximum value range.
+ *
+ * @return maximum value range
+ */
+ public double getMax() {
+ return max;
+ }
+ }
+
+ private static ArrayList<Range> decimal64ValueRange = null;
+
+ /**
+ * Creates a fraction-digits instance.
+ */
+ private FractionDigits() {
+ }
+
+ /**
+ * Generates decimal64 value range based on fraction-digits.
+ *
+ * @return decimal64 value range by fraction-digits as index
+ */
+ public static ArrayList<Range> getDecimal64ValueRange() {
+ if (decimal64ValueRange == null) {
+ decimal64ValueRange = new ArrayList<>();
+ decimal64ValueRange.add(new Range(-922337203685477580.8, 922337203685477580.7)); // fraction-digit: 1
+ decimal64ValueRange.add(new Range(-92233720368547758.08, 92233720368547758.07)); // fraction-digit: 2
+ decimal64ValueRange.add(new Range(-9223372036854775.808, 9223372036854775.807)); // fraction-digit: 3
+ decimal64ValueRange.add(new Range(-922337203685477.5808, 922337203685477.5807)); // fraction-digit: 4
+ decimal64ValueRange.add(new Range(-92233720368547.75808, 92233720368547.75807)); // fraction-digit: 5
+ decimal64ValueRange.add(new Range(-9223372036854.775808, 9223372036854.775807)); // fraction-digit: 6
+ decimal64ValueRange.add(new Range(-922337203685.4775808, 922337203685.4775807)); // fraction-digit: 7
+ decimal64ValueRange.add(new Range(-92233720368.54775808, 92233720368.54775807)); // fraction-digit: 8
+ decimal64ValueRange.add(new Range(-9223372036.854775808, 9223372036.854775807)); // fraction-digit: 9
+ decimal64ValueRange.add(new Range(-922337203.6854775808, 922337203.6854775807)); // fraction-digit: 10
+ decimal64ValueRange.add(new Range(-92233720.36854775808, 92233720.36854775807)); // fraction-digit: 11
+ decimal64ValueRange.add(new Range(-9223372.036854775808, 9223372.036854775807)); // fraction-digit: 12
+ decimal64ValueRange.add(new Range(-922337.2036854775808, 922337.2036854775807)); // fraction-digit: 13
+ decimal64ValueRange.add(new Range(-92233.72036854775808, 92233.72036854775807)); // fraction-digit: 14
+ decimal64ValueRange.add(new Range(-9223.372036854775808, 9223.372036854775807)); // fraction-digit: 15
+ decimal64ValueRange.add(new Range(-922.3372036854775808, 922.3372036854775807)); // fraction-digit: 16
+ decimal64ValueRange.add(new Range(-92.23372036854775808, 92.23372036854775807)); // fraction-digit: 17
+ decimal64ValueRange.add(new Range(-9.223372036854775808, 9.223372036854775807)); // fraction-digit: 18
+ }
+ return decimal64ValueRange;
+ }
+
+ /**
+ * Retrieve range based on fraction-digits.
+ *
+ * @param fractionDigit fraction-digits
+ * @return range
+ * @throws DataModelException a violation of data model rules
+ */
+ public static Range getRange(int fractionDigit) throws DataModelException {
+ if (!((fractionDigit >= 1) && (fractionDigit <= 18))) {
+ throw new DataModelException("YANG file error : given fraction-digit is not in its range (1..18).");
+ }
+
+ return getDecimal64ValueRange().get(fractionDigit - 1);
+ }
+
+ /**
+ * Checks whether specific decimal64 value is in correct range based fraction-digit.
+ *
+ * @param value decimal64 value
+ * @param fractionDigit fraction-digits
+ * @return true when it is in correct range otherwise false
+ */
+ public static boolean isValueInDecimal64Range(BigDecimal value, int fractionDigit) {
+ // Fraction-digits should be in correct its own range.
+ if (!((fractionDigit >= 1) && (fractionDigit <= 18))) {
+ return false;
+ }
+
+ // ArrayList index starts from 0.
+ FractionDigits.Range range = FractionDigits.getDecimal64ValueRange().get(fractionDigit - 1);
+ if ((value.doubleValue() >= range.getMin()) && (value.doubleValue() <= range.getMax())) {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/GeneratedLanguage.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/GeneratedLanguage.java
new file mode 100644
index 0000000..ff1253b
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/Parsable.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/Parsable.java
new file mode 100644
index 0000000..3ca59ce
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.datamodel.utils;
+
+import org.onosproject.yang.compiler.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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/ResolvableStatus.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/ResolvableStatus.java
new file mode 100644
index 0000000..f822d0b
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/ResolvableStatus.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.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,
+
+ /**
+ * Identifies that resolvable entity is referred node is not defined.
+ */
+ UNDEFINED
+
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/RestrictionResolver.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/RestrictionResolver.java
new file mode 100644
index 0000000..bed39cd
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/RestrictionResolver.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.utils;
+
+import org.onosproject.yang.compiler.datamodel.YangRangeInterval;
+import org.onosproject.yang.compiler.datamodel.YangRangeRestriction;
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
+import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
+
+import static java.util.regex.Pattern.quote;
+import static org.onosproject.yang.compiler.datamodel.BuiltInTypeObjectFactory.getDataObjectFromString;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.LENGTH_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.RANGE_DATA;
+import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.getYangConstructType;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
+
+/**
+ * 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";
+ private static final String SPACE = " ";
+ private static final String QUOTE = "\"";
+
+ /**
+ * Creates a restriction resolver.
+ */
+ private RestrictionResolver() {
+ }
+
+ /**
+ * Processes the range restriction for parser and linker.
+ *
+ * @param refRr range restriction of referred typedef
+ * @param line error line number
+ * @param position error character position in line
+ * @param hasRefR whether has referred restriction
+ * @param curRange caller type's range string
+ * @param type effective type, when called from linker
+ * @param fileName file name
+ * @return YANG range restriction
+ * @throws DataModelException a violation in data model rule
+ */
+ public static YangRangeRestriction processRangeRestriction(
+ YangRangeRestriction refRr, int line, int position,
+ boolean hasRefR, String curRange, YangDataTypes type, String fileName)
+ throws DataModelException {
+ return getRestriction(refRr, line, position, hasRefR, curRange, fileName,
+ type, RANGE_DATA);
+ }
+
+ /**
+ * Processes the length restriction for parser and linker.
+ *
+ * @param refLr length restriction of referred typedef
+ * @param line error line number
+ * @param position error character position in line
+ * @param hasRefR whether has referred restriction
+ * @param curLenStr caller type's length string
+ * @param fileName file name
+ * @return YANG range restriction
+ * @throws DataModelException a violation in data model rule
+ */
+ public static YangRangeRestriction processLengthRestriction(
+ YangRangeRestriction refLr, int line, int position, boolean hasRefR,
+ String curLenStr, String fileName) throws DataModelException {
+ return getRestriction(refLr, line, position, hasRefR, curLenStr, fileName,
+ UINT64, LENGTH_DATA);
+ }
+
+ /**
+ * Processes the range/length restriction for parser and linker.
+ *
+ * @param refR range/length restriction of referred typedef
+ * @param line error line number
+ * @param position error character position in line
+ * @param hasRefR whether has referred restriction
+ * @param curRange caller type's range string
+ * @param type effective type, when called from linker
+ * @param fileName file name
+ * @param conType construct type
+ * @return YANG range restriction
+ * @throws DataModelException a violation in data model rule
+ */
+ private static YangRangeRestriction getRestriction(
+ YangRangeRestriction refR, int line, int position, boolean hasRefR,
+ String curRange, String fileName, YangDataTypes type,
+ YangConstructType conType) throws
+ DataModelException {
+ YangBuiltInDataTypeInfo<?> startValue;
+ YangBuiltInDataTypeInfo<?> endValue;
+ YangRangeRestriction rr = new YangRangeRestriction();
+
+ String rangeArg = removeQuotesAndHandleConcat(curRange);
+ String[] rangeArguments = rangeArg.trim().split(quote(PIPE));
+
+ for (String rangePart : rangeArguments) {
+ String startInterval;
+ String endInterval;
+ YangRangeInterval rangeInterval = new YangRangeInterval();
+ rangeInterval.setCharPosition(position);
+ rangeInterval.setLineNumber(line);
+ rangeInterval.setFileName(fileName);
+ String[] rangeBoundary = rangePart.trim().split(quote(INTERVAL));
+
+ if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
+ DataModelException ex = new DataModelException(
+ "YANG file error : " + getYangConstructType(conType) +
+ SPACE + rangeArg + " is not valid.");
+ ex.setLine(line);
+ ex.setCharPosition(position);
+ ex.setFileName(fileName);
+ throw ex;
+ }
+
+ 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 (hasRefR && startInterval.equals(MIN_KEYWORD) &&
+ refR.getMinRestrictedValue() != null) {
+ startValue = refR.getMinRestrictedValue();
+ } else if (hasRefR && startInterval.equals(MAX_KEYWORD) &&
+ refR.getMaxRestrictedValue() != null) {
+ startValue = refR.getMaxRestrictedValue();
+ } else {
+ startValue = getDataObjectFromString(startInterval, type);
+ }
+ if (hasRefR && endInterval.equals(MIN_KEYWORD) &&
+ refR.getMinRestrictedValue() != null) {
+ endValue = refR.getMinRestrictedValue();
+ } else if (hasRefR && endInterval.equals(MAX_KEYWORD) &&
+ refR.getMaxRestrictedValue() != null) {
+ endValue = refR.getMaxRestrictedValue();
+ } else {
+ endValue = getDataObjectFromString(endInterval, type);
+ }
+ } catch (Exception e) {
+ DataModelException ex = new DataModelException(e.getMessage());
+ ex.setLine(line);
+ ex.setCharPosition(position);
+ ex.setFileName(fileName);
+ throw ex;
+ }
+ rangeInterval.setStartValue(startValue);
+ rangeInterval.setEndValue(endValue);
+ try {
+ rr.addRangeRestrictionInterval(rangeInterval);
+ } catch (DataModelException ex) {
+ ex.setLine(line);
+ ex.setCharPosition(position);
+ ex.setFileName(fileName);
+ throw ex;
+ }
+ }
+ return rr;
+ }
+
+ /**
+ * 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(QUOTE, EMPTY_STRING);
+ String[] tmpData = yangStringData.split(quote(ADD));
+ StringBuilder builder = new StringBuilder();
+ for (String yangString : tmpData) {
+ builder.append(yangString);
+ }
+ return builder.toString();
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/YangConstructType.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/YangConstructType.java
new file mode 100644
index 0000000..9c9aedf
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/YangConstructType.java
@@ -0,0 +1,574 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yang.compiler.datamodel.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 decimal64 parsed data.
+ */
+ DECIMAL64_DATA,
+
+ /**
+ * Identifies the YANG fraction-digits parsed data.
+ */
+ FRACTION_DIGITS_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,
+
+ /**
+ * Identifies the YANG compiler annotation element parsed data.
+ */
+ COMPILER_ANNOTATION_DATA,
+
+ /**
+ * Identifies the YANG app data structure element parsed data.
+ */
+ APP_DATA_STRUCTURE,
+
+ /**
+ * Identifies the YANG app extended element parsed data.
+ */
+ APP_EXTENDED_NAME_DATA,
+
+ /**
+ * Identifies the YANG argument element parsed data.
+ */
+ ARGUMENT_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 DECIMAL64_DATA:
+ return "decimal64";
+ case FRACTION_DIGITS_DATA:
+ return "fraction-digits";
+ 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";
+ case COMPILER_ANNOTATION_DATA:
+ return "compiler-annotation";
+ case APP_DATA_STRUCTURE:
+ return "app-data-structure";
+ case APP_EXTENDED_NAME_DATA:
+ return "app-extended-name";
+ case ARGUMENT_DATA:
+ return "argument";
+ default:
+ return "yang";
+ }
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/YangErrMsgConstants.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/YangErrMsgConstants.java
new file mode 100644
index 0000000..48f0bb8
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/YangErrMsgConstants.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.utils;
+
+/**
+ * Represents default YANG error message types.
+ */
+public final class YangErrMsgConstants {
+
+ /**
+ * Static attribute for operation failed error tag.
+ */
+ public static final String OPERATION_FAILED_ERROR_TAG = "operation-failed";
+
+ /**
+ * Static attribute for data missing error tag.
+ */
+ public static final String DATA_MISSING_ERROR_TAG = "data-missing";
+
+ /**
+ * Static attribute for bad attribute error tag.
+ */
+ public static final String BAD_ATTRIBUTE_ERROR_TAG = "bad-attribute";
+
+ /**
+ * Static attribute for data not unique error app tag.
+ */
+ public static final String DATA_NOT_UNIQUE_ERROR_APP_TAG = "data-not-unique";
+
+ /**
+ * Static attribute for too many elements error app tag.
+ */
+ public static final String TOO_MANY_ELEMENTS_ERROR_APP_TAG = "too-many-elements";
+
+ /**
+ * Static attribute for too few elements error app tag.
+ */
+ public static final String TOO_FEW_ELEMENTS_ERROR_APP_TAG = "too-few-elements";
+
+ /**
+ * Static attribute for must violation error app tag.
+ */
+ public static final String MUST_VIOLATION_ERROR_APP_TAG = "must-violation";
+
+ /**
+ * Static attribute for instance required error app tag.
+ */
+ public static final String INSTANCE_REQUIRED_ERROR_APP_TAG = "instance-required";
+
+ /**
+ * Static attribute for missing choice error app tag.
+ */
+ public static final String MISSING_CHOICE_ERROR_APP_TAG = "missing-choice";
+
+ /**
+ * Static attribute for missing instance error app tag.
+ */
+ public static final String MISSING_INSTANCE_ERROR_APP_TAG = "missing-instance";
+
+ /**
+ * TODO: Static attribute for error path to the instance-identifier leaf.
+ */
+ public static final String ERROR_PATH_INSTANCE_IDENTIFIER_LEAF = "Path to the instance-identifier leaf.";
+
+ /**
+ * Static attribute for error path to the missing choice.
+ */
+ public static final String ERROR_PATH_MISSING_CHOICE = "Path to the element with the missing choice.";
+
+ /**
+ * Static attribute for error path to the leafref leaf.
+ */
+ public static final String ERROR_PATH_LEAFREF_LEAF = "Path to the leafref leaf.";
+
+ /**
+ * Creates an instance of yang error message constants.
+ */
+ private YangErrMsgConstants() {
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/DataTypeException.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/DataTypeException.java
new file mode 100644
index 0000000..115f611
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/DataTypeException.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangBuiltInDataTypeInfo.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangBuiltInDataTypeInfo.java
new file mode 100644
index 0000000..56b7a01
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangBuiltInDataTypeInfo.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.yang.compiler.datamodel.utils.builtindatatype;
+
+/**
+ * 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangDataTypeUtils.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangDataTypeUtils.java
new file mode 100644
index 0000000..75fb807
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangDataTypeUtils.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.utils.builtindatatype;
+
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.INT16;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.INT32;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.INT64;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.INT8;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UINT32;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
+
+/**
+ * Represents YANG data type utilities.
+ */
+public final class YangDataTypeUtils {
+
+ /**
+ * Restricts creation of YANG data type utils instance.
+ */
+ private YangDataTypeUtils() {
+ }
+
+ /**
+ * 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;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangDataTypes.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangDataTypes.java
new file mode 100644
index 0000000..8221627
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangDataTypes.java
@@ -0,0 +1,285 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.utils.builtindatatype;
+
+/**
+ * Represents ENUM to identify the YANG data type.
+ */
+public enum YangDataTypes {
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * int8 represents integer values between -128 and 127, inclusively.
+ */
+ INT8("int8"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * int16 represents integer values between -32768 and 32767, inclusively.
+ */
+ INT16("int16"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * int32 represents integer values between -2147483648 and 2147483647,
+ * inclusively.
+ */
+ INT32("int32"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * int64 represents integer values between -9223372036854775808 and
+ * 9223372036854775807, inclusively.
+ */
+ INT64("int64"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * uint8 represents integer values between 0 and 255, inclusively.
+ */
+ UINT8("uint8"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * uint16 represents integer values between 0 and 65535, inclusively.
+ */
+ UINT16("uint16"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * uint32 represents integer values between 0 and 4294967295, inclusively.
+ */
+ UINT32("uint32"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * uint64 represents integer values between 0 and 18446744073709551615,
+ * inclusively.
+ */
+ UINT64("uint64"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * 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("decimal64"), // TODO: need to implement in type.
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * 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("string"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * The boolean built-in type represents a boolean value.
+ */
+ BOOLEAN("boolean"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * The enumeration built-in type represents values from a set of assigned
+ * names.
+ */
+ ENUMERATION("enumeration"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * 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("bits"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * The binary built-in type represents any binary data, i.e., a sequence of
+ * octets.
+ */
+ BINARY("binary"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * 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.
+ * <p>
+ * 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.
+ * <p>
+ * There MUST NOT be any circular chains of leafrefs.
+ * <p>
+ * 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("leafref"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * The identityref type is used to reference an existing identity.
+ */
+ IDENTITYREF("identityref"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * The empty built-in type represents a leaf that does not have any value,
+ * it conveys information by its presence or absence.
+ * <p>
+ * An empty type cannot have a default value.
+ */
+ EMPTY("empty"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * The union built-in type represents a value that corresponds to one of its
+ * member types.
+ * <p>
+ * 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.
+ * <p>
+ * 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".
+ * <p>
+ * 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.
+ * <p>
+ * Any default value or "units" property defined in the member types is not
+ * inherited by the union type.
+ */
+ UNION("union"),
+
+ /**
+ * Reference:RFC 6020.
+ * <p>
+ * The instance-identifier built-in type is used to uniquely identify a
+ * particular instance node in the data tree.
+ * <p>
+ * 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.
+ * <p>
+ * 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("instance-identifier"),
+
+ /**
+ * Derived data type.
+ */
+ DERIVED("derived");
+
+ /**
+ * Defined type from the enum value.
+ */
+ private final String definedType;
+
+ /**
+ * Constructs type value from enum.
+ *
+ * @param definedType value of enum
+ */
+ YangDataTypes(String definedType) {
+ this.definedType = definedType;
+ }
+
+ /**
+ * 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.definedType.toLowerCase().equals(name)) {
+ return yangDataType;
+ }
+ }
+ return YangDataTypes.DERIVED;
+ }
+
+ /**
+ * Returns whether the data type is of primitive data type.
+ *
+ * @return true, if data type can have primitive data type, false otherwise
+ */
+ public boolean isPrimitiveDataType() {
+ return this == INT8 ||
+ this == INT16 ||
+ this == INT32 ||
+ this == INT64 ||
+ this == UINT8 ||
+ this == UINT16 ||
+ this == UINT32 ||
+ this == UINT64 ||
+ this == DECIMAL64 ||
+ this == BOOLEAN ||
+ this == EMPTY;
+ }
+
+ /**
+ * Returns whether the data type is of non restricted type.
+ *
+ * @return true, if data type can't be restricted, false otherwise
+ */
+ public boolean isNonRestrictedType() {
+ return this == BOOLEAN ||
+ this == ENUMERATION ||
+ this == BITS ||
+ this == EMPTY ||
+ this == UNION ||
+ this == IDENTITYREF ||
+ this == LEAFREF;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangInt16.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangInt16.java
new file mode 100644
index 0000000..679196f
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangInt16.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.utils.builtindatatype;
+
+import org.onosproject.yang.compiler.datamodel.DefaultLocationInfo;
+
+import java.io.Serializable;
+
+import static java.lang.Short.compare;
+import static java.lang.Short.parseShort;
+
+/**
+ * Handles the YANG's int16 data type processing.
+ *
+ * int16 represents integer values between -32768 and 32767, inclusively.
+ */
+public class YangInt16 extends DefaultLocationInfo
+ 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 = 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 compare(value, anotherYangInt16.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT16;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangInt32.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangInt32.java
new file mode 100644
index 0000000..6beac4c
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangInt32.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.utils.builtindatatype;
+
+import org.onosproject.yang.compiler.datamodel.DefaultLocationInfo;
+
+import java.io.Serializable;
+
+import static java.lang.Integer.compare;
+import static java.lang.Integer.parseInt;
+
+/**
+ * Handles the YANG's int32 data type processing.
+ *
+ * int32 represents integer values between -2147483648 and 2147483647, inclusively.
+ */
+public class YangInt32 extends DefaultLocationInfo
+ 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 = 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 compare(value, anotherYangInt32.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT32;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangInt64.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangInt64.java
new file mode 100644
index 0000000..4bfe8b0
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangInt64.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.datamodel.utils.builtindatatype;
+
+import org.onosproject.yang.compiler.datamodel.DefaultLocationInfo;
+
+import java.io.Serializable;
+
+import static java.lang.Long.compare;
+import static java.lang.Long.parseLong;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.INT64;
+
+/**
+ * Handles the YANG's int8 data type processing.
+ *
+ * int8 represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.
+ */
+public class YangInt64 extends DefaultLocationInfo
+ 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 = 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 compare(value, anotherYangInt64.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return INT64;
+ }
+}
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangInt8.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangInt8.java
new file mode 100644
index 0000000..e1474a9
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.datamodel.utils.builtindatatype;
+
+import org.onosproject.yang.compiler.datamodel.DefaultLocationInfo;
+
+import java.io.Serializable;
+
+/**
+ * Handles the YANG's int8 data type processing.
+ *
+ * int8 represents integer values between -128 and 127, inclusively.
+ */
+public class YangInt8 extends DefaultLocationInfo
+ 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangUint16.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangUint16.java
new file mode 100644
index 0000000..defa218
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.datamodel.utils.builtindatatype;
+
+import org.onosproject.yang.compiler.datamodel.DefaultLocationInfo;
+
+import java.io.Serializable;
+
+/**
+ * Handles the YANG's Uint16 data type processing.
+ *
+ * Uint16 represents integer values between 0 and 65535, inclusively.
+ */
+public class YangUint16 extends DefaultLocationInfo
+ 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
+ */
+ public 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangUint32.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangUint32.java
new file mode 100644
index 0000000..dd5176f
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.datamodel.utils.builtindatatype;
+
+import org.onosproject.yang.compiler.datamodel.DefaultLocationInfo;
+
+import java.io.Serializable;
+
+/**
+ * Handles the YANG's Uint32 data type processing.
+ *
+ * Uint32 represents integer values between 0 and 4294967295, inclusively.
+ */
+public class YangUint32 extends DefaultLocationInfo
+ 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
+ */
+ public 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangUint64.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangUint64.java
new file mode 100644
index 0000000..5568f85
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangUint64.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.yang.compiler.datamodel.utils.builtindatatype;
+
+import org.onosproject.yang.compiler.datamodel.DefaultLocationInfo;
+
+import java.io.Serializable;
+import java.math.BigInteger;
+
+/**
+ * Handles the YANG's Uint16 data type processing.
+ *
+ * Uint64 represents integer values between 0 and 18446744073709551615, inclusively.
+ */
+public class YangUint64 extends DefaultLocationInfo
+ 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";
+
+ /**
+ * 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
+ */
+ public YangUint64(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = new BigInteger(valueInString);
+ } catch (Exception e) {
+ 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangUint8.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/YangUint8.java
new file mode 100644
index 0000000..93df40f
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.datamodel.utils.builtindatatype;
+
+import org.onosproject.yang.compiler.datamodel.DefaultLocationInfo;
+
+import java.io.Serializable;
+
+/**
+ * Handles the YANG's Uint8 data type processing.
+ *
+ * Uint8 represents integer values between 0 and 255, inclusively.
+ */
+public class YangUint8 extends DefaultLocationInfo
+ 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
+ */
+ public 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/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/package-info.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/package-info.java
new file mode 100644
index 0000000..e2a8a94
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/builtindatatype/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 YANG built in data types.
+ */
+package org.onosproject.yang.compiler.datamodel.utils.builtindatatype;
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/package-info.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/package-info.java
new file mode 100644
index 0000000..563ea68
--- /dev/null
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/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.yang.compiler.datamodel.utils;
\ No newline at end of file