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;
27 import org.oic.simulator.SimulatorResult;
30 * SimulatorRemoteResource represents a Resource running in the remote Simulator
31 * Server. It comes with a well-defined contract or interface onto which you can
32 * perform different operations or subscribe for event notifications.
34 public class SimulatorRemoteResource {
36 private SimulatorRemoteResource(long nativeHandle) {
37 this.nativeHandle = nativeHandle;
41 * API to get the URI for this resource.
43 * @return Resource URI
45 public String getUri() {
50 * API to get the observe policy of this resource.
52 * @return True if the resource is observable, otherwise false.
54 public boolean getIsObservable() {
59 * API to get the connectivity type for this resource.
61 * @return Connectivity type.
63 public SimulatorConnectivityType getConnectivityType() {
64 return SimulatorConnectivityType.getConnectivityType(mConnType);
68 * API to get the list of resource types.
70 * @return List of resource types.
72 public LinkedList<String> getResourceTypes() {
77 * API to get the list of resource interfaces.
79 * @return List of resource interfaces.
81 public LinkedList<String> getResourceInterfaces() {
82 return mResInterfaces;
86 * API to get host address and port information of the resource.
88 * @return Host address.
90 public String getHost() {
95 * API to get a unique Id of the resource .
99 public String getId() {
104 * API to start observing the resource.
107 * Allows the client to specify how it wants to observe.
108 * @param queryParamsMap
109 * Map which can have the query parameter names and values.
110 * @param onObserveListener
111 * The handler method which will be invoked with a map of
112 * attribute names and values whenever there is a change in
113 * resource model of the remote resource.
115 * @throws InvalidArgsException
116 * This exception will be thrown if any parameter has invalid
118 * @throws SimulatorException
119 * This exception will be thrown for other errors.
121 public native void startObserve(SimulatorObserveType observeType,
122 Map<String, String> queryParamsMap,
123 IObserveListener onObserveListener) throws InvalidArgsException,
127 * API to stop observing the resource.
129 * @throws InvalidArgsException
130 * This exception will be thrown if the native remote resource
131 * object is unavailable.
132 * @throws SimulatorException
133 * This exception will be thrown for other errors.
135 public native void stopObserve() throws InvalidArgsException,
139 * API to send GET request to the resource. Response will be notified
140 * asynchronously via callback set for {@link IGetListener}.
142 * @param queryParamsMap
143 * Map which can have the query parameter name and value.
144 * @param onGetListener
145 * Event handler which will be invoked with the response for GET
146 * request with a map of attribute name and values.
148 * @throws InvalidArgsException
149 * This exception will be thrown if any parameter has invalid
151 * @throws NoSupportException
152 * This exception will be thrown if we cannot send GET request
153 * to the remote resource.
154 * @throws SimulatorException
155 * This exception will be thrown for other errors.
157 public void get(Map<String, String> queryParamsMap,
158 IGetListener onGetListener) throws InvalidArgsException,
159 NoSupportException, SimulatorException {
160 if (null == onGetListener)
161 throw new InvalidArgsException(
162 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
163 "Parameter passed in invalid");
164 this.get(null, queryParamsMap, onGetListener);
168 * API to send GET request to the resource. Response will be notified
169 * asynchronously via callback set for {@link IGetListener}.
171 * @param resourceInterface
172 * Interface type of the resource to operate on.
173 * @param queryParamsMap
174 * Map which can have the query parameter name and value.
175 * @param onGetListener
176 * Event handler which will be invoked with the response for GET
177 * request with a map of attribute name and values.
179 * @throws InvalidArgsException
180 * This exception will be thrown if any parameter has invalid
182 * @throws NoSupportException
183 * This exception will be thrown if we cannot send GET request
184 * to the remote resource.
185 * @throws SimulatorException
186 * This exception will be thrown for other errors.
188 public void get(String resourceInterface,
189 Map<String, String> queryParamsMap, IGetListener onGetListener)
190 throws InvalidArgsException, NoSupportException, SimulatorException {
191 if (resourceInterface.isEmpty() || null == onGetListener)
192 throw new InvalidArgsException(
193 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
194 "Parameter passed in invalid");
195 this.get(resourceInterface, queryParamsMap, onGetListener);
198 private native void nativeGet(String resourceInterface,
199 Map<String, String> queryParamsMap, IGetListener onGetListener)
200 throws InvalidArgsException, NoSupportException, SimulatorException;
203 * API to send PUT request to the resource. Response will be notified
204 * asynchronously via callback set for {@link IPutListener}.
206 * @param representation
207 * {@link SimulatorResourceModel} holding the representation of
209 * @param queryParamsMap
210 * Map which can have the query parameter name and value.
211 * @param onPutListener
212 * Event handler which will be invoked with the response for PUT
213 * request with a map of attribute name and values.
215 * @throws InvalidArgsException
216 * This exception will be thrown if any parameter has invalid
218 * @throws NoSupportException
219 * This exception will be thrown if we cannot send PUT request
220 * to the remote resource.
221 * @throws SimulatorException
222 * This exception will be thrown for other errors.
224 public void put(SimulatorResourceModel representation,
225 Map<String, String> queryParamsMap, IPutListener onPutListener)
226 throws InvalidArgsException, NoSupportException, SimulatorException {
227 if (null == representation || null == onPutListener)
228 throw new InvalidArgsException(
229 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
230 "Parameter passed in invalid");
231 this.put(null, representation, queryParamsMap, onPutListener);
235 * API to send PUT request to the resource. Response will be notified
236 * asynchronously via callback set for {@link IPutListener}.
238 * @param resourceInterface
239 * Interface type of the resource to operate on.
240 * @param representation
241 * {@link SimulatorResourceModel} holding the representation of
243 * @param queryParamsMap
244 * Map which can have the query parameter name and value.
245 * @param onPutListener
246 * Event handler which will be invoked with the response for PUT
247 * request with a map of attribute name and values.
249 * @throws InvalidArgsException
250 * This exception will be thrown if any parameter has invalid
252 * @throws NoSupportException
253 * This exception will be thrown if we cannot send PUT request
254 * to the remote resource.
255 * @throws SimulatorException
256 * This exception will be thrown for other errors.
258 public void put(String resourceInterface,
259 SimulatorResourceModel representation,
260 Map<String, String> queryParamsMap, IPutListener onPutListener)
261 throws InvalidArgsException, NoSupportException, SimulatorException {
262 if (resourceInterface.isEmpty() || null == representation || null == onPutListener)
263 throw new InvalidArgsException(
264 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
265 "Parameter passed in invalid");
266 this.put(resourceInterface, representation, queryParamsMap, onPutListener);
269 private native void nativePut(String resourceInterface,
270 SimulatorResourceModel representation,
271 Map<String, String> queryParamsMap, IPutListener onPutListener)
272 throws InvalidArgsException, NoSupportException, SimulatorException;
275 * API to send POST request to the resource. Response will be notified
276 * asynchronously via callback set for {@link IPostListener}.
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 void post(SimulatorResourceModel representation,
297 Map<String, String> queryParamsMap, IPostListener onPostListener)
298 throws InvalidArgsException, NoSupportException, SimulatorException {
299 if (null == representation || null == onPostListener)
300 throw new InvalidArgsException(
301 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
302 "Parameter passed in invalid");
303 this.post(null, representation, queryParamsMap, onPostListener);
307 * API to send POST request to the resource. Response will be notified
308 * asynchronously via callback set for {@link IPostListener}.
310 * @param resourceInterface
311 * Interface type of the resource to operate on.
312 * @param representation
313 * {@link SimulatorResourceModel} holding the representation of
315 * @param queryParamsMap
316 * Map which can have the query parameter name and value.
317 * @param onPostListener
318 * Event handler which will be invoked with the response for POST
319 * request with a map of attribute name and values.
321 * @throws InvalidArgsException
322 * This exception will be thrown if any parameter has invalid
324 * @throws NoSupportException
325 * This exception will be thrown if we cannot send POST request
326 * on the remote resource.
327 * @throws SimulatorException
328 * This exception will be thrown for other errors.
330 public void post(String resourceInterface,
331 SimulatorResourceModel representation,
332 Map<String, String> queryParamsMap, IPostListener onPostListener)
333 throws InvalidArgsException, NoSupportException, SimulatorException {
334 if (resourceInterface.isEmpty() || null == representation || null == onPostListener)
335 throw new InvalidArgsException(
336 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
337 "Parameter passed in invalid");
338 this.post(resourceInterface, representation, queryParamsMap, onPostListener);
341 private native void nativePost(String resourceInterface,
342 SimulatorResourceModel representation,
343 Map<String, String> queryParamsMap, IPostListener onPostListener)
344 throws InvalidArgsException, NoSupportException, SimulatorException;
347 * API to provide remote resource configure information,
348 * which is required for using automation feature.
353 * @throws InvalidArgsException
354 * Thrown if the RAML configuration file path is invalid.
355 * @throws SimulatorException
356 * Thrown for other errors.
358 public native void setConfigInfo(String path)
359 throws InvalidArgsException, SimulatorException;
362 * API to send multiple requests for the resource, based on
363 * the configure file provided from {@link setConfigInfo}.
364 * This verifies response received as well.
367 * Request type to verify.
368 * @param onVerifyListener
369 * This event handler will be invoked with the current status of
372 * @return Automation ID.
374 * @throws InvalidArgsException
375 * This exception will be thrown if any parameter has invalid
377 * @throws NoSupportException
378 * Thrown either if the resource does not support the request
379 * type or the resource is not configured with RAML.
380 * @throws OperationInProgressException
381 * Thrown if another request generation session is already in
383 * @throws SimulatorException
384 * This exception will be thrown for other errors.
386 public int startVerification(SimulatorVerificationType requestType,
387 IVerificationListener onVerifyListener)
388 throws InvalidArgsException, NoSupportException,
389 OperationInProgressException, SimulatorException {
390 return startVerification(requestType.ordinal(), onVerifyListener);
394 * API to stop sending requests which has been started using {@link setConfigInfo}.
399 * @throws InvalidArgsException
400 * Thrown if the automation ID is invalid.
401 * @throws NoSupportException
402 * Thrown if the resource is not configured with RAML.
403 * @throws SimulatorException
404 * Thrown for other errors.
406 public native void stopVerification(int id) throws InvalidArgsException,
407 NoSupportException, SimulatorException;
409 private native int startVerification(int requestType,
410 IVerificationListener onVerifyListener)
411 throws InvalidArgsException, NoSupportException,
412 OperationInProgressException, SimulatorException;
415 protected void finalize() throws Throwable {
418 } catch(Throwable t){
425 private native void dispose();
427 private long nativeHandle;
429 private int mConnType;
430 private String mHost;
432 private LinkedList<String> mResTypes;
433 private LinkedList<String> mResInterfaces;
434 private boolean mIsObservable;