2 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.oic.simulator.clientcontroller;
19 import java.util.LinkedList;
22 import org.oic.simulator.InvalidArgsException;
23 import org.oic.simulator.NoSupportException;
24 import org.oic.simulator.OperationInProgressException;
25 import org.oic.simulator.SimulatorException;
26 import org.oic.simulator.SimulatorResourceModel;
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.
33 public class SimulatorRemoteResource {
35 private SimulatorRemoteResource(long nativeHandle) {
36 this.nativeHandle = nativeHandle;
40 * API to get the URI for this resource.
42 * @return Resource URI
44 public String getUri() {
49 * API to get the observe policy of this resource.
51 * @return True if the resource is observable, otherwise false.
53 public boolean getIsObservable() {
58 * API to get the connectivity type for this resource.
60 * @return Connectivity type.
62 public SimulatorConnectivityType getConnectivityType() {
63 return SimulatorConnectivityType.getConnectivityType(mConnType);
67 * API to get the list of resource types.
69 * @return List of resource types.
71 public LinkedList<String> getResourceTypes() {
76 * API to get the list of resource interfaces.
78 * @return List of resource interfaces.
80 public LinkedList<String> getResourceInterfaces() {
81 return mResInterfaces;
85 * API to get host address and port information of the resource.
87 * @return Host address.
89 public String getHost() {
94 * API to get a unique Id of the resource .
98 public String getId() {
103 * API to start observing the resource.
106 * Allows the client to specify how it wants to observe.
107 * @param queryParamsMap
108 * Map which can have the query parameter names and values.
109 * @param onObserveListener
110 * The handler method which will be invoked with a map of
111 * attribute names and values whenever there is a change in
112 * resource model of the remote resource.
114 * @throws InvalidArgsException
115 * This exception will be thrown if any parameter has invalid
117 * @throws SimulatorException
118 * This exception will be thrown for other errors.
120 public native void startObserve(SimulatorObserveType observeType,
121 Map<String, String> queryParamsMap,
122 IObserveListener onObserveListener) throws InvalidArgsException,
126 * API to stop observing the resource.
128 * @throws InvalidArgsException
129 * This exception will be thrown if the native remote resource
130 * object is unavailable.
131 * @throws SimulatorException
132 * This exception will be thrown for other errors.
134 public native void stopObserve() throws InvalidArgsException,
138 * API to send GET request to the resource. Response will be notified
139 * asynchronously via callback set for {@link IGetListener}.
141 * @param queryParamsMap
142 * Map which can have the query parameter name and value.
143 * @param onGetListener
144 * Event handler which will be invoked with the response for GET
145 * request with a map of attribute name and values.
147 * @throws InvalidArgsException
148 * This exception will be thrown if any parameter has invalid
150 * @throws NoSupportException
151 * This exception will be thrown if we cannot send GET request
152 * to the remote resource.
153 * @throws SimulatorException
154 * This exception will be thrown for other errors.
156 public void get(Map<String, String> queryParamsMap,
157 IGetListener onGetListener) throws InvalidArgsException,
158 NoSupportException, SimulatorException {
159 this.get(null, queryParamsMap, onGetListener);
163 * API to send GET request to the resource. Response will be notified
164 * asynchronously via callback set for {@link IGetListener}.
166 * @param resourceInterface
167 * Interface type of the resource to operate on.
168 * @param queryParamsMap
169 * Map which can have the query parameter name and value.
170 * @param onGetListener
171 * Event handler which will be invoked with the response for GET
172 * request with a map of attribute name and values.
174 * @throws InvalidArgsException
175 * This exception will be thrown if any parameter has invalid
177 * @throws NoSupportException
178 * This exception will be thrown if we cannot send GET request
179 * to the remote resource.
180 * @throws SimulatorException
181 * This exception will be thrown for other errors.
183 public native void get(String resourceInterface,
184 Map<String, String> queryParamsMap, IGetListener onGetListener)
185 throws InvalidArgsException, NoSupportException, SimulatorException;
188 * API to send PUT request to the resource. Response will be notified
189 * asynchronously via callback set for {@link IPutListener}.
191 * @param representation
192 * {@link SimulatorResourceModel} holding the representation of
194 * @param queryParamsMap
195 * Map which can have the query parameter name and value.
196 * @param onPutListener
197 * Event handler which will be invoked with the response for PUT
198 * request with a map of attribute name and values.
200 * @throws InvalidArgsException
201 * This exception will be thrown if any parameter has invalid
203 * @throws NoSupportException
204 * This exception will be thrown if we cannot send PUT request
205 * to the remote resource.
206 * @throws SimulatorException
207 * This exception will be thrown for other errors.
209 public void put(SimulatorResourceModel representation,
210 Map<String, String> queryParamsMap, IPutListener onPutListener)
211 throws InvalidArgsException, NoSupportException, SimulatorException {
212 this.put(null, representation, queryParamsMap, onPutListener);
216 * API to send PUT request to the resource. Response will be notified
217 * asynchronously via callback set for {@link IPutListener}.
219 * @param resourceInterface
220 * Interface type of the resource to operate on.
221 * @param representation
222 * {@link SimulatorResourceModel} holding the representation of
224 * @param queryParamsMap
225 * Map which can have the query parameter name and value.
226 * @param onPutListener
227 * Event handler which will be invoked with the response for PUT
228 * request with a map of attribute name and values.
230 * @throws InvalidArgsException
231 * This exception will be thrown if any parameter has invalid
233 * @throws NoSupportException
234 * This exception will be thrown if we cannot send PUT request
235 * to the remote resource.
236 * @throws SimulatorException
237 * This exception will be thrown for other errors.
239 private native void put(String resourceInterface,
240 SimulatorResourceModel representation,
241 Map<String, String> queryParamsMap, IPutListener onPutListener)
242 throws InvalidArgsException, NoSupportException, SimulatorException;
245 * API to send POST request to the resource. Response will be notified
246 * asynchronously via callback set for {@link IPostListener}.
248 * @param representation
249 * {@link SimulatorResourceModel} holding the representation of
251 * @param queryParamsMap
252 * Map which can have the query parameter name and value
253 * @param onPostListener
254 * Event handler which will be invoked with the response for POST
255 * request with a map of attribute name and values.
257 * @throws InvalidArgsException
258 * This exception will be thrown if any parameter has invalid
260 * @throws NoSupportException
261 * This exception will be thrown if we cannot send POST request
262 * on the remote resource.
263 * @throws SimulatorException
264 * This exception will be thrown for other errors.
266 public void post(SimulatorResourceModel representation,
267 Map<String, String> queryParamsMap, IPostListener onPostListener)
268 throws InvalidArgsException, NoSupportException, SimulatorException {
269 this.post(null, representation, queryParamsMap, onPostListener);
273 * API to send POST request to the resource. Response will be notified
274 * asynchronously via callback set for {@link IPostListener}.
276 * @param resourceInterface
277 * Interface type of the resource to operate on.
278 * @param representation
279 * {@link SimulatorResourceModel} holding the representation of
281 * @param queryParamsMap
282 * Map which can have the query parameter name and value.
283 * @param onPostListener
284 * Event handler which will be invoked with the response for POST
285 * request with a map of attribute name and values.
287 * @throws InvalidArgsException
288 * This exception will be thrown if any parameter has invalid
290 * @throws NoSupportException
291 * This exception will be thrown if we cannot send POST request
292 * on the remote resource.
293 * @throws SimulatorException
294 * This exception will be thrown for other errors.
296 public native void post(String resourceInterface,
297 SimulatorResourceModel representation,
298 Map<String, String> queryParamsMap, IPostListener onPostListener)
299 throws InvalidArgsException, NoSupportException, SimulatorException;
302 * API to provide remote resource configure information,
303 * which is required for using automation feature.
308 * @throws InvalidArgsException
309 * Thrown if the RAML configuration file path is invalid.
310 * @throws SimulatorException
311 * Thrown for other errors.
313 public native void setConfigInfo(String path)
314 throws InvalidArgsException, SimulatorException;
317 * API to send multiple requests for the resource, based on
318 * the configure file provided from {@link setConfigInfo}.
319 * This verifies response received as well.
322 * Request type to verify.
323 * @param onVerifyListener
324 * This event handler will be invoked with the current status of
327 * @return Automation ID.
329 * @throws InvalidArgsException
330 * This exception will be thrown if any parameter has invalid
332 * @throws NoSupportException
333 * Thrown either if the resource does not support the request
334 * type or the resource is not configured with RAML.
335 * @throws OperationInProgressException
336 * Thrown if another request generation session is already in
338 * @throws SimulatorException
339 * This exception will be thrown for other errors.
341 public int startVerification(SimulatorVerificationType requestType,
342 IVerificationListener onVerifyListener)
343 throws InvalidArgsException, NoSupportException,
344 OperationInProgressException, SimulatorException {
345 return startVerification(requestType.ordinal(), onVerifyListener);
349 * API to stop sending requests which has been started using {@link setConfigInfo}.
354 * @throws InvalidArgsException
355 * Thrown if the automation ID is invalid.
356 * @throws NoSupportException
357 * Thrown if the resource is not configured with RAML.
358 * @throws SimulatorException
359 * Thrown for other errors.
361 public native void stopVerification(int id) throws InvalidArgsException,
362 NoSupportException, SimulatorException;
364 private native int startVerification(int requestType,
365 IVerificationListener onVerifyListener)
366 throws InvalidArgsException, NoSupportException,
367 OperationInProgressException, SimulatorException;
370 protected void finalize() throws Throwable {
373 } catch(Throwable t){
380 private native void dispose();
382 private long nativeHandle;
384 private int mConnType;
385 private String mHost;
387 private LinkedList<String> mResTypes;
388 private LinkedList<String> mResInterfaces;
389 private boolean mIsObservable;