X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FControllerContext.xtend;h=c2b0ae8bdbb716580b1197108d0e91168b3d6ef0;hp=624178569d4e71551507f7733cec7c93bf4b032c;hb=312e38ea16a563e630b59f12c8459bce8b743eb5;hpb=41af542c09b1bda7a1618d3d92be529c9573288f 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 624178569d..c2b0ae8bdb 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 @@ -8,6 +8,11 @@ import java.net.URLEncoder import java.util.HashMap import java.util.List import java.util.Map +import java.util.concurrent.ConcurrentHashMap +import javax.ws.rs.WebApplicationException +import javax.ws.rs.core.Response +import org.opendaylight.controller.sal.core.api.model.SchemaServiceListener +import org.opendaylight.controller.sal.rest.impl.RestconfProvider import org.opendaylight.yangtools.yang.common.QName import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.InstanceIdentifierBuilder @@ -21,12 +26,10 @@ import org.opendaylight.yangtools.yang.model.api.DataNodeContainer import org.opendaylight.yangtools.yang.model.api.DataSchemaNode import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode import org.opendaylight.yangtools.yang.model.api.ListSchemaNode +import org.opendaylight.yangtools.yang.model.api.RpcDefinition import org.opendaylight.yangtools.yang.model.api.SchemaContext import static com.google.common.base.Preconditions.* -import org.opendaylight.controller.sal.core.api.model.SchemaServiceListener -import org.opendaylight.yangtools.yang.model.api.RpcDefinition -import java.util.concurrent.ConcurrentHashMap class ControllerContext implements SchemaServiceListener { @@ -43,7 +46,7 @@ class ControllerContext implements SchemaServiceListener { private new() { - if (INSTANCE != null) { + if (INSTANCE !== null) { throw new IllegalStateException("Already instantiated"); } } @@ -51,6 +54,13 @@ class ControllerContext implements SchemaServiceListener { static def getInstance() { return INSTANCE } + + private def void checkPreconditions() { + if (schemas === null) { + throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE) + .entity(RestconfProvider::NOT_INITALIZED_MSG).build()) + } + } public def InstanceIdWithSchemaNode toInstanceIdentifier(String restconfInstance) { val ret = InstanceIdentifier.builder(); @@ -62,13 +72,14 @@ class ControllerContext implements SchemaServiceListener { pathArgs.remove(0) } val schemaNode = ret.collectPathArguments(pathArgs, restconfInstance.findModule); - if (schemaNode == null) { + if (schemaNode === null) { return null } new InstanceIdWithSchemaNode(ret.toInstance, schemaNode) } private def findModule(String restconfInstance) { + checkPreconditions checkNotNull(restconfInstance); val pathArgs = restconfInstance.split("/"); if (pathArgs.empty) { @@ -81,7 +92,7 @@ class ControllerContext implements SchemaServiceListener { private def getLatestModule(SchemaContext schema, String moduleName) { checkNotNull(schema) - checkArgument(moduleName != null && !moduleName.empty) + checkArgument(moduleName !== null && !moduleName.empty) val modules = schema.modules.filter[m|m.name == moduleName] var latestModule = modules.head for (module : modules) { @@ -93,6 +104,7 @@ class ControllerContext implements SchemaServiceListener { } def String toFullRestconfIdentifier(InstanceIdentifier path) { + checkPreconditions val elements = path.path; val ret = new StringBuilder(); val startQName = elements.get(0).nodeType; @@ -120,10 +132,11 @@ class ControllerContext implements SchemaServiceListener { } def CharSequence toRestconfIdentifier(QName qname) { + checkPreconditions var module = uriToModuleName.get(qname.namespace) - if (module == null) { + if (module === null) { val moduleSchema = schemas.findModuleByNamespaceAndRevision(qname.namespace, qname.revision); - if(moduleSchema == null) throw new IllegalArgumentException() + if(moduleSchema === null) throw new IllegalArgumentException() uriToModuleName.put(qname.namespace, moduleSchema.name) module = moduleSchema.name; } @@ -176,7 +189,7 @@ class ControllerContext implements SchemaServiceListener { } private def toUriString(Object object) { - if(object == null) return ""; + if(object === null) return ""; return URLEncoder.encode(object.toString) } @@ -190,14 +203,14 @@ class ControllerContext implements SchemaServiceListener { val nodeName = nodeRef.toNodeName(); val targetNode = parentNode.getDataChildByName(nodeName); - if (targetNode == null) { + if (targetNode === null) { val children = parentNode.childNodes for (child : children) { if (child instanceof ChoiceNode) { val choice = child as ChoiceNode for (caze : choice.cases) { val result = builder.collectPathArguments(strings, caze as DataNodeContainer); - if (result != null) + if (result !== null) return result } }