[IOT-1089] Change Android build system to accomodate both Android and Generic Java...
[contrib/iotivity.git] / java / common / src / main / java / org / iotivity / base / OcResourceRequest.java
1 /*
2  *******************************************************************
3  *
4  * Copyright 2015 Intel Corporation.
5  *
6  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22
23 package org.iotivity.base;
24
25 import java.util.EnumSet;
26 import java.util.List;
27 import java.util.Map;
28
29 /**
30  * OcResourceRequest provides APIs to extract details from a request
31  */
32 public class OcResourceRequest {
33
34     private OcResourceRequest(long nativeHandle) {
35         this.mNativeHandle = nativeHandle;
36     }
37
38     /**
39      * Retrieves the type of request for the entity handler function to operate
40      *
41      * @return request type. This could be 'GET'/'PUT'/'POST'/'DELETE'
42      */
43     public RequestType getRequestType() {
44         return RequestType.get(getRequestTypeNative());
45     }
46
47     private native String getRequestTypeNative();
48
49     /**
50      * Retrieves the query parameters from the request
51      *
52      * @return parameters in the request
53      */
54     public native Map<String, String> getQueryParameters();
55
56     /**
57      * Retrieves the request handler flag set. This can be INIT flag and/or REQUEST flag and/or
58      * OBSERVE flag.
59      * NOTE:
60      * INIT indicates that the vendor's entity handler should go and perform
61      * initialization operations
62      * REQUEST indicates that it is a request of certain type (GET/PUT/POST/DELETE) and entity
63      * handler needs to perform corresponding operations
64      * OBSERVE indicates that the request is of type Observe and entity handler needs to perform
65      * corresponding operations
66      *
67      * @return Set of handler flags
68      */
69     public EnumSet<RequestHandlerFlag> getRequestHandlerFlagSet() {
70         return RequestHandlerFlag.convertToEnumSet(getRequestHandlerFlagNative());
71     }
72
73     private native int getRequestHandlerFlagNative();
74
75     /**
76      * Provides the entire resource attribute representation
77      *
78      * @return OcRepresentation object containing the name value pairs representing
79      * the resource's attributes
80      */
81     public native OcRepresentation getResourceRepresentation();
82
83     /**
84      * Object provides observation information
85      *
86      * @return observation information
87      */
88     public native ObservationInfo getObservationInfo();
89
90     /**
91      * Specifies the resource uri
92      *
93      * @param resourceUri resource uri
94      */
95     public native void setResourceUri(String resourceUri);
96
97     /**
98      * Gets the resource URI
99      *
100      * @return resource URI
101      */
102     public native String getResourceUri();
103
104     /**
105      * This API retrieves a list of headerOptions which was sent from a client
106      *
107      * @return List of header options
108      */
109     public native List<OcHeaderOption> getHeaderOptions();
110
111     /**
112      * This API retrieves the request handle
113      *
114      * @return request handle
115      */
116     public native OcRequestHandle getRequestHandle();
117
118     /**
119      * This API retrieves the resource handle
120      *
121      * @return resource handle
122      */
123     public native OcResourceHandle getResourceHandle();
124
125     @Override
126     protected void finalize() throws Throwable {
127         super.finalize();
128
129         dispose();
130     }
131
132     private native void dispose();
133
134     private long mNativeHandle;
135 }