Resourse Identifier builder

Change-Id: I31ebaa6fa4450d405a5f9ec82f629233e568390e
diff --git a/model/pom.xml b/model/pom.xml
index 73403f1..36c2f69 100644
--- a/model/pom.xml
+++ b/model/pom.xml
@@ -39,6 +39,12 @@
             <artifactId>slf4j-api</artifactId>
             <version>1.7.21</version>
         </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/model/src/main/java/org/onosproject/yang/model/DataNode.java b/model/src/main/java/org/onosproject/yang/model/DataNode.java
index 257b5de..d927455 100644
--- a/model/src/main/java/org/onosproject/yang/model/DataNode.java
+++ b/model/src/main/java/org/onosproject/yang/model/DataNode.java
@@ -28,7 +28,7 @@
      *
      * @return node schema identifier
      */
-    SchemaIdentifier identifier();
+    SchemaId identifier();
 
     /**
      * Returns the type of node.
diff --git a/model/src/main/java/org/onosproject/yang/model/KeyLeaf.java b/model/src/main/java/org/onosproject/yang/model/KeyLeaf.java
new file mode 100644
index 0000000..6d782e4
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/KeyLeaf.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+/**
+ * Represents the List's key leaf value.
+ */
+public class KeyLeaf {
+    private SchemaId leafSchema;
+    private Object leafVal;
+
+    private KeyLeaf() {
+
+    }
+
+    /**
+     * Constructs a key leaf with all the identifier and value initialized.
+     *
+     * @param name      name of the leaf
+     * @param nameSpace namespace of leaf
+     * @param leafVal   value of leaf
+     */
+    public KeyLeaf(String name, String nameSpace, Object leafVal) {
+        leafSchema = new SchemaId(name, nameSpace);
+        this.leafVal = leafVal;
+    }
+
+    /**
+     * Returns the node schema schemaId.
+     *
+     * @return node schema schemaId
+     */
+    public SchemaId leafSchema() {
+        return leafSchema;
+    }
+
+    /**
+     * Returns value contained in leaf node.
+     *
+     * @return value contained in leaf node
+     */
+    public Object leafValue() {
+        return leafVal;
+    }
+
+    /**
+     * Returns value as string, for usage in serializers.
+     *
+     * @return string representation of value
+     */
+    public String leafValAsString() {
+        return leafVal.toString();
+    }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafListKey.java b/model/src/main/java/org/onosproject/yang/model/LeafListKey.java
new file mode 100644
index 0000000..904d6bd
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/LeafListKey.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+/**
+ * Representation of an entity which identifies a uniquely branching
+ * leaf-list entry corresponding to a multi instance leaf schema.
+ */
+public class LeafListKey extends NodeKey<LeafListKey>
+        implements Comparable<LeafListKey> {
+    private Object val;
+
+    /**
+     * Create object from builder.
+     *
+     * @param builder initialized builder
+     */
+    private LeafListKey(LeafListKeyBuilder builder) {
+        super(builder);
+        val = builder.val;
+    }
+
+    /**
+     * Returns value of node, this is only valid for multi-instance leaf, node.
+     *
+     * @return value maintained in the node
+     */
+    Object value() {
+        return val;
+    }
+
+    /**
+     * Returns value as string, for usage in serializers.
+     *
+     * @return string representation of value
+     */
+    String asString() {
+        return val.toString();
+    }
+
+    public static class LeafListKeyBuilder
+            extends NodeKeyBuilder<LeafListKeyBuilder> {
+
+        private Object val;
+
+        /**
+         * constructor used while constructing the key from scratch.
+         */
+        public LeafListKeyBuilder() {
+
+        }
+
+        /**
+         * Adds the value for for the leaf list node identifier.
+         *
+         * @param val leaf list value
+         */
+        LeafListKeyBuilder value(Object val) {
+            this.val = val;
+            return this;
+        }
+
+        /**
+         * Creates a leaf list entry identifier.
+         *
+         * @return leaf list entry identifier
+         */
+        public LeafListKey build() {
+            return new LeafListKey(this);
+        }
+    }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ListKey.java b/model/src/main/java/org/onosproject/yang/model/ListKey.java
new file mode 100644
index 0000000..87107fc
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ListKey.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.onosproject.yang.model;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Represents an entity which identifies a unique branching node
+ * corresponding to a multi instance schema definition.
+ */
+public class ListKey extends NodeKey<ListKey> implements Comparable<ListKey> {
+
+    private List<KeyLeaf> keyLeafs;
+
+    /**
+     * Create object from builder.
+     *
+     * @param builder initialized builder
+     */
+    private ListKey(ListKeyBuilder builder) {
+        super(builder);
+        keyLeafs = builder.keyLeafs;
+    }
+
+    /**
+     * Returns the list of key leaf nodes of a multi instance node, which
+     * uniquely identifies the branching node entry corresponding to a multi
+     * instance schema definition.
+     *
+     * @return List of key leaf nodes
+     */
+    List<KeyLeaf> keyLeafs() {
+        return keyLeafs;
+    }
+
+    public int compareTo(ListKey o) {
+        //TODO: implement me
+        return 0;
+    }
+
+    public static class ListKeyBuilder extends NodeKeyBuilder<ListKeyBuilder> {
+        private List<KeyLeaf> keyLeafs = new LinkedList<>();
+
+        /**
+         * used to construct the key from scratch.
+         */
+        public ListKeyBuilder() {
+
+        }
+
+        /**
+         * used to construct a key from an existing node key.
+         *
+         * @param base existing node key
+         */
+        public ListKeyBuilder(NodeKeyBuilder base) {
+            super(base);
+        }
+
+        /**
+         * Adds the key leaf for the list resource.
+         *
+         * @param name      key leaf name
+         * @param nameSpace key laef namespace
+         * @param val       value of key
+         */
+        void addKeyLeaf(String name, String nameSpace, Object val) {
+            KeyLeaf keyLeaf = new KeyLeaf(name, nameSpace, val);
+            keyLeafs.add(keyLeaf);
+        }
+
+        /**
+         * Creates the list key object.
+         *
+         * @return list key
+         */
+        public ListKey build() {
+            return new ListKey(this);
+        }
+    }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelConstants.java b/model/src/main/java/org/onosproject/yang/model/ModelConstants.java
new file mode 100644
index 0000000..4c24cdd
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ModelConstants.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+/**
+ * Constants used in model package.
+ */
+final class ModelConstants {
+    static final String INCOMPLETE_SCHEMA_INFO = "Schema info is not complete";
+    static final String LEAF_IS_TERMINAL = "Leaf must be the terminal node";
+    static final String NON_KEY_LEAF = "Leaf list is not a key of list";
+    static final String NO_KEY_SET = "Resource Identifier is empty";
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelException.java b/model/src/main/java/org/onosproject/yang/model/ModelException.java
new file mode 100644
index 0000000..460991c
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ModelException.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+/**
+ * Represents the Model Exception.
+ */
+public class ModelException extends RuntimeException {
+
+    private static final long serialVersionUID = 20161223L;
+
+    /**
+     * Creates a new YANG tool exception with given message.
+     *
+     * @param message the detail of exception in string
+     */
+    public ModelException(String message) {
+        super(message);
+    }
+
+    /**
+     * Creates a new tool exception from given message and cause.
+     *
+     * @param message the detail of exception in string
+     * @param cause   underlying cause of the error
+     */
+    public ModelException(final String message, final Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Creates a new tool exception from cause.
+     *
+     * @param cause underlying cause of the error
+     */
+    public ModelException(final Throwable cause) {
+        super(cause);
+    }
+
+}
+
diff --git a/model/src/main/java/org/onosproject/yang/model/MultiInstanceLeafKey.java b/model/src/main/java/org/onosproject/yang/model/MultiInstanceLeafKey.java
deleted file mode 100644
index 8be8bbe..0000000
--- a/model/src/main/java/org/onosproject/yang/model/MultiInstanceLeafKey.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yang.model;
-
-/**
- * Abstraction of an entity which identifies a uniquely branching leaf
- * corresponding to a multi instance leaf schema.
- */
-public interface MultiInstanceLeafKey extends NodeKey {
-
-    /**
-     * Returns value of node, this is only valid for multi-instance leaf, node.
-     *
-     * @return value maintained in the node
-     */
-    Object value();
-
-    /**
-     * Returns value as string, for usage in serializers.
-     *
-     * @return string representation of value
-     */
-    String asString();
-}
diff --git a/model/src/main/java/org/onosproject/yang/model/MultiInstanceNodeKey.java b/model/src/main/java/org/onosproject/yang/model/MultiInstanceNodeKey.java
deleted file mode 100644
index 5677891..0000000
--- a/model/src/main/java/org/onosproject/yang/model/MultiInstanceNodeKey.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.onosproject.yang.model;
-
-import java.util.List;
-
-/**
- * Abstraction of an entity which identifies a unique branching node
- * corresponding to a multi instance schema definition.
- */
-public interface MultiInstanceNodeKey extends NodeKey {
-
-    /**
-     * Returns the list of key leaf nodes of a multi instance node, which
-     * uniquely identifies the branching node entry corresponding to a multi
-     * instance schema definition.
-     *
-     * @return List of key leaf nodes
-     */
-    List<LeafNode> keyLeafs();
-}
diff --git a/model/src/main/java/org/onosproject/yang/model/NodeKey.java b/model/src/main/java/org/onosproject/yang/model/NodeKey.java
index 1f6dbfe..8e83e49 100644
--- a/model/src/main/java/org/onosproject/yang/model/NodeKey.java
+++ b/model/src/main/java/org/onosproject/yang/model/NodeKey.java
@@ -17,11 +17,25 @@
 
 package org.onosproject.yang.model;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.yang.model.ModelConstants.INCOMPLETE_SCHEMA_INFO;
+
 /**
  * Abstraction of an entity which identifies a node uniquely among its
  * siblings.
  */
-public interface NodeKey extends Comparable<NodeKey> {
+public class NodeKey<E extends NodeKey> implements Comparable<E> {
+
+    private SchemaId schemaId;
+
+    /**
+     * Create object from builder.
+     *
+     * @param builder initialized builder
+     */
+    protected NodeKey(NodeKeyBuilder builder) {
+        schemaId = builder.schemaId;
+    }
 
     /**
      * Returns the schema identifier as minimal key required to identify a
@@ -29,5 +43,68 @@
      *
      * @return schema identifier of a key
      */
-    SchemaIdentifier identifier();
+    public SchemaId schemaId() {
+        return schemaId;
+    }
+
+    @Override
+    public int compareTo(NodeKey o) {
+        //TODO: implement me
+        return 0;
+    }
+
+    public static class NodeKeyBuilder<B extends NodeKeyBuilder<B>> {
+        private SchemaId schemaId;
+
+        /**
+         * Create the node key from scratch.
+         */
+        public NodeKeyBuilder() {
+
+        }
+
+        /**
+         * Support the derived object to inherit from existing node key builder.
+         *
+         * @param base existing node key builder
+         */
+        protected NodeKeyBuilder(NodeKeyBuilder base) {
+            checkNotNull(base.schemaId, INCOMPLETE_SCHEMA_INFO);
+            schemaId = base.schemaId;
+        }
+
+        /**
+         * set the schema identifier.
+         *
+         * @param schema schema identifier
+         * @return current builder
+         */
+        public B schemaId(SchemaId schema) {
+            schemaId = schema;
+            return (B) this;
+        }
+
+        /**
+         * set the schema identifier.
+         *
+         * @param name      name of the node
+         * @param nameSpace name space of the node
+         * @return current builder
+         */
+        public B schemaId(String name, String nameSpace) {
+            schemaId = new SchemaId(name, nameSpace);
+            return (B) this;
+        }
+
+        /**
+         * construct the node key.
+         *
+         * @return node key
+         */
+        public NodeKey build() {
+            checkNotNull(schemaId.name(), INCOMPLETE_SCHEMA_INFO);
+            checkNotNull(schemaId.namespace(), INCOMPLETE_SCHEMA_INFO);
+            return new NodeKey(this);
+        }
+    }
 }
diff --git a/model/src/main/java/org/onosproject/yang/model/ResourceId.java b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
new file mode 100644
index 0000000..7f99c8c
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.onosproject.yang.model.ModelConstants.LEAF_IS_TERMINAL;
+import static org.onosproject.yang.model.ModelConstants.NON_KEY_LEAF;
+import static org.onosproject.yang.model.ModelConstants.NO_KEY_SET;
+
+/**
+ * Representation of an entity which identifies a resource in the logical tree
+ * data store. It is a list of node keys to identify the branch point
+ * hierarchy to reach a resource in the instance tree.
+ */
+
+public class ResourceId {
+    private List<NodeKey> nodeKeyList;
+
+    /**
+     * Create object from builder.
+     *
+     * @param builder initialized builder
+     */
+    private ResourceId(Builder builder) {
+        nodeKeyList = builder.nodeKeyList;
+    }
+
+    /**
+     * Returns the list of node key used to uniquely identify the branch in the
+     * logical tree starting from root.
+     *
+     * @return node key uniquely identifying the branch
+     */
+    public List<NodeKey> nodeKeys() {
+        return nodeKeyList;
+    }
+
+    /**
+     * Retrieves a new resource builder.
+     *
+     * @return resource builder
+     */
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    /**
+     * Builder to construct resource identifier.
+     */
+    public static class Builder {
+
+        private List<NodeKey> nodeKeyList = new LinkedList<>();
+        private NodeKey.NodeKeyBuilder curKeyBuilder = null;
+
+        /**
+         * Adds the descendent node's schema identity.
+         *
+         * @param name      name of descendent node
+         * @param nameSpace name space pf descendent node
+         * @return updated builder pointing to the specified schema location
+         */
+        public Builder addBranchPointSchema(String name, String nameSpace) {
+            if (curKeyBuilder != null) {
+                if (curKeyBuilder instanceof LeafListKey.LeafListKeyBuilder) {
+                    throw new ModelException(LEAF_IS_TERMINAL);
+                }
+                nodeKeyList.add(curKeyBuilder.build());
+            }
+
+            curKeyBuilder = new NodeKey.NodeKeyBuilder();
+            curKeyBuilder.schemaId(name, nameSpace);
+
+            return this;
+        }
+
+        /**
+         * Adds a multi instance attribute's node identity.
+         *
+         * @param name      name of the leaf list
+         * @param nameSpace name space of leaf list
+         * @param val       value of attribute to identify the instance
+         * @return updated builder pointing to the specific attribute
+         * value instance
+         */
+        public Builder addLeafListBranchPoint(String name, String nameSpace,
+                                              Object val) {
+            LeafListKey.LeafListKeyBuilder leafListKeyBuilder;
+            if (curKeyBuilder instanceof LeafListKey.LeafListKeyBuilder) {
+                throw new ModelException(NON_KEY_LEAF);
+            }
+            leafListKeyBuilder = new LeafListKey.LeafListKeyBuilder()
+                    .schemaId(name, nameSpace).value(val);
+
+            curKeyBuilder = leafListKeyBuilder;
+            return this;
+        }
+
+        /**
+         * Adds a multi instance nodes key attribute value to identify
+         * the branch point of instance tree.
+         *
+         * @param name      name of the key attribute
+         * @param nameSpace name space of key attribute
+         * @param val       value of the key leaf, to match in the list entry
+         * @return updated builder with list branching information
+         */
+        public Builder addKeyLeaf(String name, String nameSpace, Object val) {
+            ListKey.ListKeyBuilder listKeyBuilder;
+            if (!(curKeyBuilder instanceof ListKey.ListKeyBuilder)) {
+                if (curKeyBuilder instanceof LeafListKey.LeafListKeyBuilder) {
+                    throw new ModelException(LEAF_IS_TERMINAL);
+                }
+
+                listKeyBuilder = new ListKey.ListKeyBuilder(curKeyBuilder);
+            } else {
+                listKeyBuilder = (ListKey.ListKeyBuilder) curKeyBuilder;
+            }
+
+            listKeyBuilder.addKeyLeaf(name, nameSpace, val);
+            curKeyBuilder = listKeyBuilder;
+            return this;
+        }
+
+        /**
+         * Builds a resource identifier to based on set path information of
+         * the resource.
+         *
+         * @return built resource identifier
+         */
+        public ResourceId build() {
+            if (curKeyBuilder == null) {
+                throw new ModelException(NO_KEY_SET);
+            }
+            nodeKeyList.add(curKeyBuilder.build());
+            return new ResourceId(this);
+        }
+    }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ResourceIdentifier.java b/model/src/main/java/org/onosproject/yang/model/ResourceIdentifier.java
deleted file mode 100644
index fb40c48..0000000
--- a/model/src/main/java/org/onosproject/yang/model/ResourceIdentifier.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yang.model;
-
-/**
- * Abstraction of an entity which identifies a resource in the logical tree
- * data store. It is a recursive approach to locate a resource in the
- * instance tree.
- */
-
- /*-- Assume the below schema
- * container node1{
- *     list node2{
- *         key node3;
- *         leaf node3{
- *             type string;
- *         }
- *         leaf-list node4{
- *             type string
- *         }
- *     }
- * }
- * Assume an instance tree as below
- * node1
- * |----node2
- * |    |----node3
- * |    |    |----"val1"
- * |    |----node4
- * |    |    |----"val2"
- * |    |    |----"val3"
- * |----node2
- * |    |----node3
- * |    |    |----"val4"
- * |    |----node4
- * |    |    |----"val5"
- * |    |    |----"val6"
- * <p>
- *
- * Assume a resource identifier variable a is pointing to node4 with val3,
- * then its value is as follows
- *
- *      //identifies node1
- *      NodeKey containerKey = a.nodeKey();
- *      SchemaIdentifier schemaId = containerKey.identifier();//"node1"
- *
- *      //identifies a specific entry of list node2
- *      MultiInstanceNodeKey listKey;
- *      listKey = (MultiInstanceNodeKey) a.descendentIdentifier().nodeKey();
- *      schemaId = listKey.identifier();//"node2"
- *      List<LeafNode> keyLeaves = listKey.keyLeafs();
- *      LeafNode key = keyLeaves.get(0);
- *      schemaId = key.identifier();//"node3"
- *      String keyVal = key.asString();//"val1"
- *
- *      //identifiers a specific entry of leaf-list node4
- *      MultiInstanceLeafKey leafKey;
- *      leafKey = (MultiInstanceLeafKey) a.descendentIdentifier().
- *              descendentIdentifier().nodeKey();
- *      schemaId = leafKey.identifier();//"node4"
- *      keyVal = leafKey.asString();//val3
- *
- *      ResourceIdentifier termination = a.descendentIdentifier().descendentIdentifier().
- *              descendentIdentifier(); //null
- *
- */
-public interface ResourceIdentifier {
-    /**
-     * Returns the node key used to uniquely identify the branch in the
-     * logical tree.
-     *
-     * @return node key uniquely identifying the branch
-     */
-    NodeKey nodeKey();
-
-    /**
-     * Returns the descendent resource identifier.
-     *
-     * @return descendent resource identifier
-     */
-    ResourceIdentifier descendentIdentifier();
-}
diff --git a/model/src/main/java/org/onosproject/yang/model/SchemaIdentifier.java b/model/src/main/java/org/onosproject/yang/model/SchemaId.java
similarity index 61%
rename from model/src/main/java/org/onosproject/yang/model/SchemaIdentifier.java
rename to model/src/main/java/org/onosproject/yang/model/SchemaId.java
index a180afb..e25f8b4 100644
--- a/model/src/main/java/org/onosproject/yang/model/SchemaIdentifier.java
+++ b/model/src/main/java/org/onosproject/yang/model/SchemaId.java
@@ -16,18 +16,38 @@
 
 package org.onosproject.yang.model;
 
+import static org.onosproject.yang.model.ModelConstants.INCOMPLETE_SCHEMA_INFO;
+
 /**
- * Abstraction of an entity which identifies a schema node in the schema / data
- * tree.
+ * Representation of an entity which identifies a schema node in the schema /
+ * data tree.
  */
-public interface SchemaIdentifier {
+public class SchemaId {
+
+    private String name;
+    private String nameSpace;
+
+    private SchemaId() {
+
+    }
+
+    public SchemaId(String name, String nameSpace) {
+        if (name == null || nameSpace == null) {
+            throw new ModelException(INCOMPLETE_SCHEMA_INFO);
+        }
+        this.name = name;
+        this.nameSpace = nameSpace;
+    }
+
     /**
      * Returns node schema name. This is mandatory to identify node according
      * to schema.
      *
      * @return node name
      */
-    String name();
+    String name() {
+        return name;
+    }
 
     /**
      * Returns node's namespace. This is mandatory serializers must translate
@@ -35,5 +55,7 @@
      *
      * @return node's namespace
      */
-    String namespace();
+    String namespace() {
+        return nameSpace;
+    }
 }
diff --git a/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java b/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
new file mode 100644
index 0000000..7a4bb62
--- /dev/null
+++ b/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2016. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+ * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
+ * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
+ * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
+ * Vestibulum commodo. Ut rhoncus gravida arcu.
+ */
+
+package org.onosproject.yang.model;
+
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test resource id
+ */
+
+public class ResourceIdTest {
+
+    @Test
+    public void resourceIdConstruction() {
+        String sampleResId = "/card=8/port=5,eth/stats";
+        String[] resourcePath = sampleResId.split("/");
+
+        ResourceId.Builder resBldr = new ResourceId.Builder();
+
+        int i = 0;
+        int j;
+        while (i < resourcePath.length) {
+            if (resourcePath[i].equals("")) {
+                i++;
+                continue;
+            }
+
+            String[] nameValue = resourcePath[i].split("=");
+            resBldr.addBranchPointSchema(nameValue[0], "testNameSpace");
+            if (nameValue.length == 1) {
+                i++;
+                continue;
+            }
+
+            String[] keys = nameValue[1].split(",");
+
+            j = 0;
+            while (j < keys.length) {
+                //TODO: get schema name of key using YANG runtime
+                String keyName = getKeyName(nameValue[0], j);
+                resBldr.addKeyLeaf(keyName, "testNameSpace", keys[j]);
+                j++;
+            }
+            i++;
+        }
+
+        ResourceId res = resBldr.build();
+        List<NodeKey> keys = res.nodeKeys();
+        assertEquals("invalid augmented node created", "card",
+                     keys.get(0).schemaId().name());
+        assertEquals("invalid augmented node created", ListKey.class,
+                     keys.get(0).getClass());
+        ListKey listKey = (ListKey) keys.get(0);
+        assertEquals("invalid augmented node created", "slot",
+                     listKey.keyLeafs().get(0).leafSchema().name());
+    }
+
+    private String getKeyName(String s, int j) {
+        if (s.equals("card")) {
+            return "slot";
+        }
+        if (s.equals("port")) {
+            if (j == 0) {
+                return "portno";
+            }
+        }
+        return "type";
+    }
+
+}