3486d2265bb6bc17aad501d50cf338e01f9af0cf
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / rest / impl / AbstractIdentifierAwareJaxRsProvider.java
1 package org.opendaylight.controller.sal.rest.impl;
2
3 import javax.ws.rs.core.Context;
4 import javax.ws.rs.core.Request;
5 import javax.ws.rs.core.UriInfo;
6 import org.opendaylight.controller.sal.rest.api.RestconfConstants;
7 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
8 import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
9
10 public class AbstractIdentifierAwareJaxRsProvider {
11
12     private static final String POST = "POST";
13
14     @Context
15     private UriInfo uriInfo;
16
17     @Context
18     private Request request;
19
20     protected final String getIdentifier() {
21         return uriInfo.getPathParameters(false).getFirst(RestconfConstants.IDENTIFIER);
22     }
23
24     protected InstanceIdentifierContext<?> getInstanceIdentifierContext() {
25         return ControllerContext.getInstance().toInstanceIdentifier(getIdentifier());
26     }
27
28     protected UriInfo getUriInfo() {
29         return uriInfo;
30     }
31
32     protected boolean isPost() {
33         return POST.equals(request.getMethod());
34     }
35 }