Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / OcResourceResponse.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.List;
26
27 /**
28  * OcResourceResponse provides APIs to set the response details
29  */
30 public class OcResourceResponse {
31
32     static {
33         System.loadLibrary("oc");
34         System.loadLibrary("ocstack-jni");
35     }
36
37     public OcResourceResponse() {
38         super();
39
40         create();
41     }
42
43     private OcResourceResponse(long nativeHandle) {
44         this.mNativeHandle = nativeHandle;
45     }
46
47     /**
48      * This API sets the error code for this response
49      *
50      * @param eCode error code to set
51      */
52     public native void setErrorCode(int eCode);
53
54     /**
55      * Gets new resource uri
56      *
57      * @return new resource uri
58      */
59     public native String getNewResourceUri();
60
61     /**
62      * Sets new resource uri
63      *
64      * @param newResourceUri new resource uri
65      */
66     public native void setNewResourceUri(String newResourceUri);
67
68     /**
69      * This API allows to set headerOptions in the response
70      *
71      * @param headerOptionList List of HeaderOption entries
72      */
73     public void setHeaderOptions(List<OcHeaderOption> headerOptionList) {
74         this.setHeaderOptions(headerOptionList.toArray(
75                         new OcHeaderOption[headerOptionList.size()])
76         );
77     }
78
79     private native void setHeaderOptions(OcHeaderOption[] headerOptionList);
80
81     /**
82      * This API allows to set request handle
83      *
84      * @param ocRequestHandle request handle
85      */
86     public native void setRequestHandle(OcRequestHandle ocRequestHandle);
87
88     /**
89      * This API allows to set the resource handle
90      *
91      * @param ocResourceHandle resource handle
92      */
93     public native void setResourceHandle(OcResourceHandle ocResourceHandle);
94
95     /**
96      * This API allows to set the EntityHandler response result
97      *
98      * @param responseResult OcEntityHandlerResult type to set the result value
99      */
100     public void setResponseResult(EntityHandlerResult responseResult) {
101         this.setResponseResult(responseResult.getValue());
102     }
103
104     private native void setResponseResult(int responseResult);
105
106     /**
107      * API to set the entire resource attribute representation
108      *
109      * @param ocRepresentation the name value pairs representing the resource's attributes
110      * @param interfaceStr     specifies the interface
111      */
112     public native void setResourceRepresentation(OcRepresentation ocRepresentation,
113                                                  String interfaceStr);
114
115     /**
116      * API to set the entire resource attribute representation
117      *
118      * @param representation object containing the name value pairs representing the
119      *                       resource's attributes
120      */
121     public void setResourceRepresentation(OcRepresentation representation) {
122         this.setResourceRepresentation1(representation);
123     }
124
125     private native void setResourceRepresentation1(OcRepresentation representation);
126
127     @Override
128     protected void finalize() throws Throwable {
129         super.finalize();
130
131         dispose();
132     }
133
134     private native void create();
135
136     private native void dispose();
137
138     private long mNativeHandle;
139 }