fix of Bug 314
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / restconf / impl / ControllerContext.xtend
index 61237f01a16933ef742041c787874ec9ee8fc957..b26810347c160c1114057e3819263cfa2ee2890e 100644 (file)
@@ -45,7 +45,7 @@ class ControllerContext implements SchemaServiceListener {
     val static NULL_VALUE = "null"
     val static MOUNT_MODULE = "yang-ext"
     val static MOUNT_NODE = "mount"
-    val static MOUNT = "yang-ext:mount"
+    public val static MOUNT = "yang-ext:mount"
 
     @Property
     var SchemaContext globalSchema;
@@ -129,6 +129,7 @@ class ControllerContext implements SchemaServiceListener {
     
     def findModuleByNamespace(URI namespace) {
         checkPreconditions
+        checkArgument(namespace !== null)
         val moduleSchemas = globalSchema.findModuleByNamespace(namespace)
         return moduleSchemas?.filterLatestModule
     }
@@ -170,28 +171,36 @@ class ControllerContext implements SchemaServiceListener {
 
     def findModuleNameByNamespace(URI namespace) {
         checkPreconditions
-        var module = uriToModuleName.get(namespace)
-        if (module === null) {
-            val moduleSchemas = globalSchema.findModuleByNamespace(namespace);
-            if(moduleSchemas === null) return null
-            var latestModule = moduleSchemas.filterLatestModule
-            if(latestModule === null) return null
-            uriToModuleName.put(namespace, latestModule.name)
-            module = latestModule.name;
+        var moduleName = uriToModuleName.get(namespace)
+        if (moduleName === null) {
+            val module = findModuleByNamespace(namespace)
+            if (module === null) return null
+            moduleName = module.name
+            uriToModuleName.put(namespace, moduleName)
         }
-        return module
+        return moduleName
+    }
+    
+    def findModuleNameByNamespace(MountInstance mountPoint, URI namespace) {
+        val module = mountPoint.findModuleByNamespace(namespace);
+        return module?.name
     }
 
-    def findNamespaceByModuleName(String module) {
-        var namespace = moduleNameToUri.get(module)
+    def findNamespaceByModuleName(String moduleName) {
+        var namespace = moduleNameToUri.get(moduleName)
         if (namespace === null) {
-            var latestModule = globalSchema.getLatestModule(module)
-            if(latestModule === null) return null
-            namespace = latestModule.namespace
-            uriToModuleName.put(namespace, latestModule.name)
+            var module = findModuleByName(moduleName)
+            if(module === null) return null
+            namespace = module.namespace
+            uriToModuleName.put(namespace, moduleName)
         }
         return namespace
     }
+    
+    def findNamespaceByModuleName(MountInstance mountPoint, String moduleName) {
+        val module = mountPoint.findModuleByName(moduleName)
+        return module?.namespace
+    }
 
     def CharSequence toRestconfIdentifier(QName qname) {
         checkPreconditions