Merge branch 'master' into simulator
[contrib/iotivity.git] / service / simulator / java / sdk / src / org / oic / simulator / clientcontroller / SimulatorRemoteResource.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * This file contains a class which has a set of native methods for 
19  * communicating with a remote resource.  
20  */
21 package org.oic.simulator.clientcontroller;
22
23 import java.util.List;
24 import java.util.Map;
25
26 import org.oic.simulator.serviceprovider.SimulatorResourceModel;
27
28 /**
29  * SimulatorRemoteResource represents a Resource running in the remote Simulator
30  * Server. It comes with a well-defined contract or interface onto which you can
31  * perform different operations or subscribe for event notifications.
32  */
33 public class SimulatorRemoteResource {
34
35     private SimulatorRemoteResource(long nativeHandle) {
36         this.mNativeHandle = nativeHandle;
37     }
38
39     /**
40      * Method to get the URI for this resource
41      *
42      * @return resource URI
43      */
44     public native String getUri();
45
46     /**
47      * Method to get the list of resource types
48      *
49      * @return List of resource types
50      */
51     public native List<String> getResourceTypes();
52
53     /**
54      * Method to get the list of resource interfaces
55      *
56      * @return List of resource interface
57      */
58     public native List<String> getResourceInterfaces();
59
60     /**
61      * Method to get a string representation of the resource's server ID. This
62      * is unique per-server independent on how it was discovered.
63      *
64      * @return server ID
65      */
66     public native String getServerId();
67
68     /**
69      * Method to set observation on the resource
70      *
71      * @param observeType
72      *            allows the client to specify how it wants to observe
73      * @param queryParamsMap
74      *            map which can have the query parameter name and value
75      * @param onObserveListener
76      *            event handler The handler method will be invoked with a map of
77      *            attribute name and values.
78      *
79      */
80     public native void observe(SimulatorObserveType observeType,
81             Map<String, String> queryParamsMap,
82             IObserveListener onObserveListener);
83
84     /**
85      * Method to cancel the observation on the resource
86      *
87      */
88     public native void cancelObserve();
89
90     /**
91      * Method to get the attributes of a resource.
92      *
93      * @param queryParamsMap
94      *            map which can have the query parameter name and value
95      * @param onGetListener
96      *            The event handler will be invoked with a map of attribute name
97      *            and values. The event handler will also have the result from
98      *            this Get operation This will have error codes
99      */
100     public native void get(Map<String, String> queryParamsMap,
101             IGetListener onGetListener);
102
103     /**
104      * Method to get the attributes of a resource.
105      *
106      * @param resourceType
107      *            resourceType of the resource to operate on
108      * @param resourceInterface
109      *            interface type of the resource to operate on
110      * @param queryParamsMap
111      *            map which can have the query parameter name and value
112      * @param onGetListener
113      *            The event handler will be invoked with a map of attribute name
114      *            and values. The event handler will also have the result from
115      *            this Get operation This will have error codes
116      */
117     public void get(String resourceType, String resourceInterface,
118             Map<String, String> queryParamsMap, IGetListener onGetListener) {
119         this.get2(resourceType, resourceInterface, queryParamsMap,
120                 onGetListener);
121     }
122
123     private native void get2(String resourceType, String resourceInterface,
124             Map<String, String> queryParamsMap, IGetListener onGetListener);
125
126     /**
127      * Method to set the representation of a resource (via PUT)
128      *
129      * @param representation
130      *            representation of the resource
131      * @param queryParamsMap
132      *            Map which can have the query parameter name and value
133      * @param onPutListener
134      *            event handler The event handler will be invoked with a map of
135      *            attribute name and values.
136      */
137     public native void put(SimulatorResourceModel representation,
138             Map<String, String> queryParamsMap, IPutListener onPutListener);
139
140     /**
141      * Method to set the representation of a resource (via PUT)
142      *
143      * @param resourceType
144      *            resource type of the resource to operate on
145      * @param resourceInterface
146      *            interface type of the resource to operate on
147      * @param representation
148      *            representation of the resource
149      * @param queryParamsMap
150      *            Map which can have the query parameter name and value
151      * @param onPutListener
152      *            event handler The event handler will be invoked with a map of
153      *            attribute name and values.
154      */
155     public void put(String resourceType, String resourceInterface,
156             SimulatorResourceModel representation,
157             Map<String, String> queryParamsMap, IPutListener onPutListener) {
158         this.put2(resourceType, resourceInterface, representation,
159                 queryParamsMap, onPutListener);
160     }
161
162     private native void put2(String resourceType, String resourceInterface,
163             SimulatorResourceModel representation,
164             Map<String, String> queryParamsMap, IPutListener onPutListener);
165
166     /**
167      * Method to POST on a resource
168      *
169      * @param representation
170      *            representation of the resource
171      * @param queryParamsMap
172      *            Map which can have the query parameter name and value
173      * @param onPostListener
174      *            event handler The event handler will be invoked with a map of
175      *            attribute name and values.
176      */
177     public native void post(SimulatorResourceModel representation,
178             Map<String, String> queryParamsMap, IPostListener onPostListener);
179
180     /**
181      * Method to POST on a resource
182      *
183      * @param resourceType
184      *            resource type of the resource to operate on
185      * @param resourceInterface
186      *            interface type of the resource to operate on
187      * @param representation
188      *            representation of the resource
189      * @param queryParamsMap
190      *            Map which can have the query parameter name and value
191      * @param onPostListener
192      *            event handler The event handler will be invoked with a map of
193      *            attribute name and values.
194      */
195     public void post(String resourceType, String resourceInterface,
196             SimulatorResourceModel representation,
197             Map<String, String> queryParamsMap, IPostListener onPostListener) {
198         this.post2(resourceType, resourceInterface, representation,
199                 queryParamsMap, onPostListener);
200     }
201
202     private native void post2(String resourceType, String resourceInterface,
203             SimulatorResourceModel representation,
204             Map<String, String> queryParamsMap, IPostListener onPostListener);
205
206     @Override
207     protected void finalize() throws Throwable {
208         super.finalize();
209
210         dispose();
211     }
212
213     private native void dispose();
214
215     private long mNativeHandle;
216 }