InstanceIdentifierContext does not take generics
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / jersey / providers / spi / AbstractIdentifierAwareJaxRsProvider.java
index a3398aa7b2af47f56f815a62eaf69b752e02436b..ebf27749669a14508a6e97fe235fa289bc6881a7 100644 (file)
@@ -5,15 +5,14 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi;
 
-import com.google.common.base.Optional;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.Optional;
 import javax.ws.rs.HttpMethod;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
@@ -22,12 +21,11 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.MessageBodyReader;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 public abstract class AbstractIdentifierAwareJaxRsProvider<T> implements MessageBodyReader<T> {
 
@@ -38,9 +36,12 @@ public abstract class AbstractIdentifierAwareJaxRsProvider<T> implements Message
     private Request request;
 
     private final SchemaContextHandler schemaContextHandler;
+    private final DOMMountPointService mountPointService;
 
-    protected AbstractIdentifierAwareJaxRsProvider(SchemaContextHandler schemaContextHandler) {
+    protected AbstractIdentifierAwareJaxRsProvider(final SchemaContextHandler schemaContextHandler,
+            final DOMMountPointService mountPointService) {
         this.schemaContextHandler = schemaContextHandler;
+        this.mountPointService = mountPointService;
     }
 
     @Override
@@ -54,7 +55,7 @@ public abstract class AbstractIdentifierAwareJaxRsProvider<T> implements Message
             final Annotation[] annotations, final MediaType mediaType,
             final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException,
             WebApplicationException {
-        final InstanceIdentifierContext<?> path = getInstanceIdentifierContext();
+        final InstanceIdentifierContext path = getInstanceIdentifierContext();
 
         final PushbackInputStream pushbackInputStream = new PushbackInputStream(entityStream);
 
@@ -74,29 +75,32 @@ public abstract class AbstractIdentifierAwareJaxRsProvider<T> implements Message
      * @param path Request path
      * @return empty body type
      */
-    protected abstract T emptyBody(InstanceIdentifierContext<?> path);
-
-    protected abstract T readBody(InstanceIdentifierContext<?> path, InputStream entityStream)
-            throws IOException, WebApplicationException;
+    protected abstract T emptyBody(InstanceIdentifierContext path);
 
+    protected abstract T readBody(InstanceIdentifierContext path, InputStream entityStream)
+            throws WebApplicationException;
 
     private String getIdentifier() {
-        return this.uriInfo.getPathParameters(false).getFirst(RestconfConstants.IDENTIFIER);
+        return this.uriInfo.getPathParameters(false).getFirst("identifier");
     }
 
-    private InstanceIdentifierContext<?> getInstanceIdentifierContext() {
+    private InstanceIdentifierContext getInstanceIdentifierContext() {
         return ParserIdentifier.toInstanceIdentifier(getIdentifier(), getSchemaContext(),
-                Optional.of(RestConnectorProvider.getMountPointService()));
+                Optional.ofNullable(getMountPointService()));
     }
 
     protected UriInfo getUriInfo() {
         return this.uriInfo;
     }
 
-    protected SchemaContext getSchemaContext() {
+    protected EffectiveModelContext getSchemaContext() {
         return schemaContextHandler.get();
     }
 
+    protected DOMMountPointService getMountPointService() {
+        return mountPointService;
+    }
+
     protected boolean isPost() {
         return HttpMethod.POST.equals(this.request.getMethod());
     }