[ONOS-5885] ModelConverter API updation to handle resourceId and leaf

Change-Id: I8b5f49d905e5068c96ff330e771c4a20850c540e
diff --git a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
index dc36d1c..215cac8 100644
--- a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
+++ b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
@@ -1750,7 +1750,7 @@
     /**
      * Static param for model object.
      */
-    public static final String MODEL_OBJECT = "ModelObject";
+    public static final String MODEL_OBJECT = "InnerModelObject";
 
     /**
      * Static param for add augmentation.
diff --git a/model/src/main/java/org/onosproject/yang/model/DefaultModelObjectData.java b/model/src/main/java/org/onosproject/yang/model/DefaultModelObjectData.java
new file mode 100644
index 0000000..0503069
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/DefaultModelObjectData.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Representation of an entity that is composition of model objects identifier
+ * and its data.
+ */
+public class DefaultModelObjectData implements ModelObjectData {
+
+    private List<ModelObject> objects;
+    private ModelObjectId identifier;
+
+    /**
+     * Creates an instance of model object data.
+     *
+     * @param b model object data builder
+     */
+    protected DefaultModelObjectData(Builder b) {
+        objects = b.objects;
+        identifier = b.identifier;
+    }
+
+    @Override
+    public List<ModelObject> modelObjects() {
+        return objects;
+    }
+
+    @Override
+    public ModelObjectId identifier() {
+        return identifier;
+    }
+
+    /**
+     * Retrieves a new model object data builder.
+     *
+     * @return model object data builder
+     */
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    /**
+     * Represents composite model data builder.
+     */
+    public static class Builder implements ModelObjectData.Builder {
+
+        private List<ModelObject> objects;
+        private ModelObjectId identifier;
+
+        /**
+         * Creates an instance of composite model data builder.
+         */
+        public Builder() {
+            objects = new LinkedList<>();
+        }
+
+        @Override
+        public Builder addModelObject(ModelObject o) {
+            objects.add(o);
+            return this;
+        }
+
+        @Override
+        public Builder identifer(ModelObjectId id) {
+            identifier = id;
+            return this;
+        }
+
+        @Override
+        public ModelObjectData build() {
+            return new DefaultModelObjectData(this);
+        }
+    }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/InnerModelObject.java b/model/src/main/java/org/onosproject/yang/model/InnerModelObject.java
new file mode 100644
index 0000000..03488f6
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/InnerModelObject.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+import com.google.common.collect.ImmutableMap;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * Abstraction of an entity that provides common basis for all POJOs which are
+ * generated from a YANG model.
+ */
+public abstract class InnerModelObject extends ModelObject {
+
+    private ConcurrentMap<Class<? extends InnerModelObject>, InnerModelObject> augments =
+            new ConcurrentHashMap<>();
+
+    /**
+     * Creates an instance of Inner model object.
+     */
+    protected InnerModelObject() {
+        super(ModelObjectType.NON_ATOMIC);
+    }
+
+    /**
+     * Adds the specified augmentation to this model object.
+     *
+     * @param obj model object of augmentation
+     */
+    public void addAugmentation(InnerModelObject obj) {
+        augments.put(obj.getClass(), obj);
+    }
+
+    /**
+     * Removes the specified augmentation to this model object.
+     *
+     * @param obj model object of augmentation
+     */
+    public void removeAugmentation(InnerModelObject obj) {
+        augments.remove(obj.getClass());
+    }
+
+    /**
+     * Returns the map of augmentations available to this model object.
+     *
+     * @return map of augmentations
+     */
+    public Map<Class<? extends InnerModelObject>, InnerModelObject> augmentations() {
+        return ImmutableMap.copyOf(augments);
+    }
+
+    /**
+     * Returns the augmentation for to a given augmentation class.
+     *
+     * @param c   augmentation class
+     * @param <T> augmentation class type
+     * @return augmentation object if available, null otherwise
+     */
+    public <T extends InnerModelObject> T augmentation(Class<T> c) {
+        return (T) augments.get(c);
+    }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafModelObject.java b/model/src/main/java/org/onosproject/yang/model/LeafModelObject.java
new file mode 100644
index 0000000..162fc54
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/LeafModelObject.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Representation of an entity that provides common basis to specify atomic
+ * model.
+ */
+public final class LeafModelObject extends ModelObject {
+
+    private LeafIdentifier leafIdentifier;
+    private List<Object> values;
+
+    /**
+     * Creates an instance of leaf model object.
+     */
+    public LeafModelObject() {
+        super(ModelObjectType.ATOMIC);
+        values = new LinkedList<>();
+    }
+
+    /**
+     * Returns leaf identifier.
+     *
+     * @return leaf identifier
+     */
+    public LeafIdentifier leafIdentifier() {
+        return leafIdentifier;
+    }
+
+    /**
+     * Sets leaf identifier.
+     *
+     * @param id leaf identifier
+     */
+    public void leafIdentifier(LeafIdentifier id) {
+        leafIdentifier = id;
+    }
+
+    /**
+     * Returns value of leaf, it will be single value for leaf and can be
+     * single or list for leaf-list.
+     *
+     * @return value(s)
+     */
+    public List<Object> values() {
+        return values;
+    }
+
+    /**
+     * Sets list of values. For leaf it will always be single value.
+     *
+     * @param v value(s)
+     */
+    public void values(List<Object> v) {
+        values = v;
+    }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelConverter.java b/model/src/main/java/org/onosproject/yang/model/ModelConverter.java
index cdae6c6..32fd08f 100644
--- a/model/src/main/java/org/onosproject/yang/model/ModelConverter.java
+++ b/model/src/main/java/org/onosproject/yang/model/ModelConverter.java
@@ -23,21 +23,25 @@
 public interface ModelConverter {
 
     /**
-     * Produces a POJO of the specified type, initialized and backed by
-     * the specified data node.
+     * Produces a POJO of the specified type.
+     * <p>
+     * Resource identifier will be converted to model object identifier and
+     * list of data nodes will be converted to list of model objects.
      *
-     * @param node data node
-     * @param <T>  type of model object
-     * @return POJO of specified data node
+     * @param data resource data
+     * @return model object data of specified resource data
      */
-    <T extends ModelObject> T createModel(DataNode node);
+    ModelObjectData createModel(ResourceData data);
 
     /**
      * Produces an immutable tree structure rooted at the returned DataNode
      * using the supplied model POJO object.
+     * <p>
+     * Model object identifier will be converted to resource identfier and
+     * list of model objects will be converted to list of data nodes.
      *
-     * @param obj model object
-     * @return data node corresponds to model object
+     * @param modelData model object data
+     * @return resource data corresponds to model object
      */
-    DataNode createDataNode(ModelObject obj);
+    ResourceData createDataNode(ModelObjectData modelData);
 }
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelObject.java b/model/src/main/java/org/onosproject/yang/model/ModelObject.java
index d6688f1..b91618a 100644
--- a/model/src/main/java/org/onosproject/yang/model/ModelObject.java
+++ b/model/src/main/java/org/onosproject/yang/model/ModelObject.java
@@ -16,59 +16,45 @@
 
 package org.onosproject.yang.model;
 
-import com.google.common.collect.ImmutableMap;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
 /**
- * Abstraction of an entity that provides common basis for all POJOs which are
- * generated from a YANG model.
+ * Abstraction of an entity that provides common basis to specify atomic and
+ * non atomic model.
  */
 public abstract class ModelObject {
 
-    private ConcurrentMap<Class<? extends ModelObject>, ModelObject> augments =
-            new ConcurrentHashMap<>();
+    /*
+ * Represents type of node in data store.
+ */
+    public enum ModelObjectType {
+
+        /**
+         * Atomic node.
+         */
+        ATOMIC,
+
+        /**
+         * Non atomic node.
+         */
+        NON_ATOMIC
+    }
+
+    private ModelObjectType modelObjectType;
 
     /**
-     * Adds the specified augmentation to this model object.
+     * Creates an instance of model object.
      *
-     * @param obj model object of augmentation
+     * @param t type of model object
      */
-    public void addAugmentation(ModelObject obj) {
-        augments.put(obj.getClass(), obj);
+    protected ModelObject(ModelObjectType t) {
+        modelObjectType = t;
     }
 
     /**
-     * Removes the specified augmentation to this model object.
+     * Returns type of model object.
      *
-     * @param obj model object of augmentation
+     * @return type
      */
-    public void removeAugmentation(ModelObject obj) {
-        augments.remove(obj.getClass());
+    ModelObjectType getModelObjectType() {
+        return modelObjectType;
     }
-
-    /**
-     * Returns the map of augmentations available to this model object.
-     *
-     * @return map of augmentations
-     */
-    public Map<Class<? extends ModelObject>, ModelObject> augmentations() {
-        return ImmutableMap.copyOf(augments);
-    }
-
-    /**
-     * Returns the augmentation for to a given augmentation class.
-     *
-     * @param c   augmentation class
-     * @param <T> augmentation class type
-     * @return augmentation object if available, null otherwise
-     */
-    public <T extends ModelObject> T augmentation(Class<T> c) {
-        return (T) augments.get(c);
-    }
-
-    // TODO analyze if some more common information of generated code like
-    // augment which needs to be moved to base ModelObject.
 }
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelObjectData.java b/model/src/main/java/org/onosproject/yang/model/ModelObjectData.java
new file mode 100644
index 0000000..02f6b6b
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ModelObjectData.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+import java.util.List;
+
+/**
+ * Abstraction of an entity that is composition of model object identifier
+ * and its data.
+ */
+public interface ModelObjectData {
+
+    /**
+     * Returns model objects.
+     *
+     * @return model objects
+     */
+    List<ModelObject> modelObjects();
+
+    /**
+     * Returns module object identifier.
+     *
+     * @return identifier
+     */
+    ModelObjectId identifier();
+
+    /**
+     * Represents builder of composite model data.
+     */
+    interface Builder {
+
+        /**
+         * Adds a model object.
+         *
+         * @param o model object to be added
+         * @return builder
+         */
+        Builder addModelObject(ModelObject o);
+
+        /**
+         * Sets module object identifier.
+         *
+         * @param id identifier
+         * @return builder
+         */
+        Builder identifer(ModelObjectId id);
+
+        /**
+         * Builds an instance of model object data.
+         *
+         * @return model object data
+         */
+        ModelObjectData build();
+    }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelObjectId.java b/model/src/main/java/org/onosproject/yang/model/ModelObjectId.java
index b0a522f..b82cdf6 100644
--- a/model/src/main/java/org/onosproject/yang/model/ModelObjectId.java
+++ b/model/src/main/java/org/onosproject/yang/model/ModelObjectId.java
@@ -98,7 +98,7 @@
          * @param <T>       generated java class which extends model object
          * @return updated builder pointing to the specified schema location
          */
-        public <T extends ModelObject> Builder addChild(Class<T> container) {
+        public <T extends InnerModelObject> Builder addChild(Class<T> container) {
             atomicPathList.add(new SingleInstanceNode<>(container));
             return this;
         }
@@ -113,7 +113,7 @@
          *             identify the list
          * @return updated builder pointing to the specified schema location
          */
-        public <T extends ModelObject & MultiInstanceObject<K>,
+        public <T extends InnerModelObject & MultiInstanceObject<K>,
                 K extends KeyInfo<T>> Builder addChild(Class<T> list, K key) {
             atomicPathList.add(new MultiInstanceNode<>(list, key));
             return this;
diff --git a/model/src/main/java/org/onosproject/yang/model/MultiInstanceNode.java b/model/src/main/java/org/onosproject/yang/model/MultiInstanceNode.java
index 72182e5..cfd7330 100644
--- a/model/src/main/java/org/onosproject/yang/model/MultiInstanceNode.java
+++ b/model/src/main/java/org/onosproject/yang/model/MultiInstanceNode.java
@@ -21,7 +21,7 @@
 /**
  * Represents a multi instance object.
  */
-public class MultiInstanceNode<T extends ModelObject, K extends KeyInfo>
+public class MultiInstanceNode<T extends InnerModelObject, K extends KeyInfo>
         extends AtomicPath {
 
     private Class<T> listClass;
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/ResourceData.java b/model/src/main/java/org/onosproject/yang/model/ResourceData.java
similarity index 92%
rename from runtime/src/main/java/org/onosproject/yang/runtime/ResourceData.java
rename to model/src/main/java/org/onosproject/yang/model/ResourceData.java
index b4af900..d087ad6 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/ResourceData.java
+++ b/model/src/main/java/org/onosproject/yang/model/ResourceData.java
@@ -14,10 +14,7 @@
  * limitations under the License.
  */
 
-package org.onosproject.yang.runtime;
-
-import org.onosproject.yang.model.DataNode;
-import org.onosproject.yang.model.ResourceId;
+package org.onosproject.yang.model;
 
 import java.util.List;
 
diff --git a/model/src/main/java/org/onosproject/yang/model/SingleInstanceNode.java b/model/src/main/java/org/onosproject/yang/model/SingleInstanceNode.java
index 40c5076..de42f5b 100644
--- a/model/src/main/java/org/onosproject/yang/model/SingleInstanceNode.java
+++ b/model/src/main/java/org/onosproject/yang/model/SingleInstanceNode.java
@@ -21,7 +21,7 @@
 /**
  * Represents a single instance object.
  */
-public class SingleInstanceNode<T extends ModelObject> extends AtomicPath {
+public class SingleInstanceNode<T extends InnerModelObject> extends AtomicPath {
 
     private Class<T> containerClass;
 
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/CompositeData.java b/runtime/src/main/java/org/onosproject/yang/runtime/CompositeData.java
index 33653b3..b1d4bb8 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/CompositeData.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/CompositeData.java
@@ -16,6 +16,8 @@
 
 package org.onosproject.yang.runtime;
 
+import org.onosproject.yang.model.ResourceData;
+
 import java.util.List;
 
 /**
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/DefaultCompositeData.java b/runtime/src/main/java/org/onosproject/yang/runtime/DefaultCompositeData.java
index b2e9f72..b3386bf 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/DefaultCompositeData.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/DefaultCompositeData.java
@@ -16,6 +16,8 @@
 
 package org.onosproject.yang.runtime;
 
+import org.onosproject.yang.model.ResourceData;
+
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/DefaultResourceData.java b/runtime/src/main/java/org/onosproject/yang/runtime/DefaultResourceData.java
index dfdf5e2..ecf7971 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/DefaultResourceData.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/DefaultResourceData.java
@@ -17,6 +17,7 @@
 package org.onosproject.yang.runtime;
 
 import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceData;
 import org.onosproject.yang.model.ResourceId;
 
 import java.util.LinkedList;
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSerializer.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSerializer.java
index bf63dc6..2f4fab5 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSerializer.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/TestSerializer.java
@@ -17,11 +17,11 @@
 package org.onosproject.yang.runtime.impl;
 
 import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceData;
 import org.onosproject.yang.model.ResourceId;
 import org.onosproject.yang.runtime.AnnotatedNodeInfo;
 import org.onosproject.yang.runtime.CompositeData;
 import org.onosproject.yang.runtime.CompositeStream;
-import org.onosproject.yang.runtime.ResourceData;
 import org.onosproject.yang.runtime.YangSerializer;
 import org.onosproject.yang.runtime.YangSerializerContext;