X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FControllerContext.xtend;h=eca4bd257298b78706cbd10321e8484ea06cab87;hb=0618d4956aba2a765a932bc3690db9db120244da;hp=065d01e8e9405058f563189e6f5117d30eed4857;hpb=638093908ccb9f2824e264ab68c789d18b5e93ac;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend index 065d01e8e9..eca4bd2572 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend @@ -36,8 +36,7 @@ class ControllerContext implements SchemaServiceListener { val static NULL_VALUE = "null" - @Property - SchemaContext schemas; + var SchemaContext schemas; private val BiMap uriToModuleName = HashBiMap.create(); private val Map moduleNameToUri = uriToModuleName.inverse(); @@ -60,6 +59,10 @@ class ControllerContext implements SchemaServiceListener { } } + def setSchemas(SchemaContext schemas) { + onGlobalContextUpdated(schemas) + } + public def InstanceIdWithSchemaNode toInstanceIdentifier(String restconfInstance) { val ret = InstanceIdentifier.builder(); val pathArgs = restconfInstance.split("/"); @@ -73,7 +76,7 @@ class ControllerContext implements SchemaServiceListener { if (schemaNode === null) { return null } - new InstanceIdWithSchemaNode(ret.toInstance, schemaNode) + return new InstanceIdWithSchemaNode(ret.toInstance, schemaNode) } private def findModule(String restconfInstance) { @@ -85,13 +88,13 @@ class ControllerContext implements SchemaServiceListener { } val modulWithFirstYangStatement = pathArgs.filter[s|s.contains(":")].head val startModule = modulWithFirstYangStatement.toModuleName(); - schemas.getLatestModule(startModule) + return getLatestModule(startModule) } - private def getLatestModule(SchemaContext schema, String moduleName) { - checkNotNull(schema) + private def getLatestModule(String moduleName) { + checkPreconditions checkArgument(moduleName !== null && !moduleName.empty) - val modules = schema.modules.filter[m|m.name == moduleName] + val modules = schemas.modules.filter[m|m.name == moduleName] var latestModule = modules.head for (module : modules) { if (module.revision.after(latestModule.revision)) { @@ -128,6 +131,25 @@ class ControllerContext implements SchemaServiceListener { private def dispatch CharSequence toRestconfIdentifier(PathArgument argument, DataSchemaNode node) { throw new IllegalArgumentException("Conversion of generic path argument is not supported"); } + + def findModuleByNamespace(URI namespace) { + checkPreconditions + var module = uriToModuleName.get(namespace) + if (module === null) { + val moduleSchemas = schemas.findModuleByNamespace(namespace); + if(moduleSchemas === null) throw new IllegalArgumentException() + var latestModule = moduleSchemas.head + for (m : moduleSchemas) { + if (m.revision.after(latestModule.revision)) { + latestModule = m + } + } + if(latestModule === null) throw new IllegalArgumentException() + uriToModuleName.put(namespace, latestModule.name) + module = latestModule.name; + } + return module + } def CharSequence toRestconfIdentifier(QName qname) { checkPreconditions @@ -289,13 +311,17 @@ class ControllerContext implements SchemaServiceListener { return str; } } - - public def QName toQName(String name) { + + private def QName toQName(String name) { val module = name.toModuleName; val node = name.toNodeName; val namespace = moduleNameToUri.get(module); return new QName(namespace,null,node); } + + def getRpcDefinition(String name) { + return qnameToRpc.get(name.toQName) + } override onGlobalContextUpdated(SchemaContext context) { this.schemas = context; @@ -305,12 +331,4 @@ class ControllerContext implements SchemaServiceListener { } } - def ContainerSchemaNode getRpcOutputSchema(QName name) { - qnameToRpc.get(name)?.output; - } - - def ContainerSchemaNode getRpcInputSchema(QName name) { - qnameToRpc.get(name)?.input; - } - }