Adding utility to get module name from namespace

Change-Id: I24e1d14cba09a681d9d45668a65f82fa7718d7a8
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/SerializerHelper.java b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/SerializerHelper.java
index 0902630..57dad4e 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/SerializerHelper.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/helperutils/SerializerHelper.java
@@ -17,6 +17,7 @@
 package org.onosproject.yang.runtime.helperutils;
 
 import org.onosproject.yang.compiler.datamodel.YangLeaf;
+import org.onosproject.yang.compiler.datamodel.YangSchemaNode;
 import org.onosproject.yang.model.DataNode;
 import org.onosproject.yang.model.InnerNode;
 import org.onosproject.yang.model.LeafNode;
@@ -27,6 +28,7 @@
 import org.onosproject.yang.model.SchemaId;
 import org.onosproject.yang.model.SingleInstanceNodeContext;
 import org.onosproject.yang.runtime.YangSerializerContext;
+import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry;
 
 import java.util.Iterator;
 import java.util.List;
@@ -526,4 +528,22 @@
     public static String errorMsg(String fmt, Object... params) {
         return String.format(fmt, params);
     }
+
+    /**
+     * Returns the yang module name for given namespace.
+     *
+     * @param c  YANG serializer context
+     * @param ns namespace of the module
+     * @return namespace of the module
+     */
+    public static String getModuleNameFromNameSpace(YangSerializerContext c,
+                                                    String ns) {
+
+        YangSchemaNode schemaNode = ((DefaultYangModelRegistry) c.getContext())
+                .getForNameSpace(ns, false);
+        if (schemaNode != null) {
+            return schemaNode.getName();
+        }
+        return null;
+    }
 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
index 84d11a4..cc77a5f 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/serializerhelper/AddToDataNodeListTest.java
@@ -30,12 +30,14 @@
 import java.util.Iterator;
 import java.util.Map;
 
+import static org.junit.Assert.assertEquals;
 import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE;
 import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE;
 import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
 import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_NODE;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.exitDataNode;
+import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getModuleNameFromNameSpace;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.getResourceId;
 import static org.onosproject.yang.runtime.helperutils.SerializerHelper.initializeDataNode;
 import static org.onosproject.yang.runtime.impl.TestUtils.LNS;
@@ -105,6 +107,16 @@
     };
 
     /**
+     * Test get module name from namespace.
+     */
+    @Test
+    public void getModuleNameTest() {
+
+        String ns = getModuleNameFromNameSpace(context, LNS);
+        assertEquals(ns, "list");
+    }
+
+    /**
      * Test add to data node builder.
      */
     @Test