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 * Method to get the URI for this resource.
42 * @return Resource URI
44 public String getUri() {
49 * Method to get the observe capability of this resource.
51 * @return True if the resource is observable, otherwise false.
53 public boolean getIsObservable() {
58 * Method to get the connectivity type for this resource.
60 * @return Connectivity type.
62 public SimulatorConnectivityType getConnectivityType() {
63 return SimulatorConnectivityType.getConnectivityType(mConnType);
67 * Method to get the list of resource types.
69 * @return List of resource types.
71 public LinkedList<String> getResourceTypes() {
76 * Method to get the list of resource interfaces.
78 * @return List of resource interfaces.
80 public LinkedList<String> getResourceInterfaces() {
81 return mResInterfaces;
85 * Method to get a string representation of the host address of the remote
88 * @return Host address.
90 public String getHost() {
95 * Method to get a unique Id for the resource.
99 public String getId() {
104 * Method to set observation on the remote 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 observe(SimulatorObserveType observeType,
122 Map<String, String> queryParamsMap,
123 IObserveListener onObserveListener) throws InvalidArgsException,
127 * Method to cancel the observation on 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 cancelObserve() throws InvalidArgsException,
139 * Method to get the attributes of a resource.
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 * Method to get the attributes of a resource.
165 * @param resourceInterface
166 * Interface type of the resource to operate on.
167 * @param queryParamsMap
168 * Map which can have the query parameter name and value.
169 * @param onGetListener
170 * Event handler which will be invoked with the response for GET
171 * request with a map of attribute name and values.
173 * @throws InvalidArgsException
174 * This exception will be thrown if any parameter has invalid
176 * @throws NoSupportException
177 * This exception will be thrown if we cannot send GET request
178 * to the remote resource.
179 * @throws SimulatorException
180 * This exception will be thrown for other errors.
182 public native void get(String resourceInterface,
183 Map<String, String> queryParamsMap, IGetListener onGetListener)
184 throws InvalidArgsException, NoSupportException, SimulatorException;
187 * Method to set the representation of a resource (via PUT)
189 * @param representation
190 * {@link SimulatorResourceModel} holding the representation of
192 * @param queryParamsMap
193 * Map which can have the query parameter name and value.
194 * @param onPutListener
195 * Event handler which will be invoked with the response for PUT
196 * request with a map of attribute name and values.
198 * @throws InvalidArgsException
199 * This exception will be thrown if any parameter has invalid
201 * @throws NoSupportException
202 * This exception will be thrown if we cannot send PUT request
203 * to the remote resource.
204 * @throws SimulatorException
205 * This exception will be thrown for other errors.
207 public void put(SimulatorResourceModel representation,
208 Map<String, String> queryParamsMap, IPutListener onPutListener)
209 throws InvalidArgsException, NoSupportException, SimulatorException {
210 this.put(null, representation, queryParamsMap, onPutListener);
214 * Method to set the representation of a resource (via PUT).
216 * @param resourceInterface
217 * Interface type of the resource to operate on.
218 * @param representation
219 * {@link SimulatorResourceModel} holding the representation of
221 * @param queryParamsMap
222 * Map which can have the query parameter name and value.
223 * @param onPutListener
224 * Event handler which will be invoked with the response for PUT
225 * request with a map of attribute name and values.
227 * @throws InvalidArgsException
228 * This exception will be thrown if any parameter has invalid
230 * @throws NoSupportException
231 * This exception will be thrown if we cannot send PUT request
232 * to the remote resource.
233 * @throws SimulatorException
234 * This exception will be thrown for other errors.
236 private native void put(String resourceInterface,
237 SimulatorResourceModel representation,
238 Map<String, String> queryParamsMap, IPutListener onPutListener)
239 throws InvalidArgsException, NoSupportException, SimulatorException;
242 * Method to POST on a resource.
244 * @param representation
245 * {@link SimulatorResourceModel} holding the representation of
247 * @param queryParamsMap
248 * Map which can have the query parameter name and value
249 * @param onPostListener
250 * Event handler which will be invoked with the response for POST
251 * request with a map of attribute name and values.
253 * @throws InvalidArgsException
254 * This exception will be thrown if any parameter has invalid
256 * @throws NoSupportException
257 * This exception will be thrown if we cannot send POST request
258 * on the remote resource.
259 * @throws SimulatorException
260 * This exception will be thrown for other errors.
262 public void post(SimulatorResourceModel representation,
263 Map<String, String> queryParamsMap, IPostListener onPostListener)
264 throws InvalidArgsException, NoSupportException, SimulatorException {
265 this.post(null, representation, queryParamsMap, onPostListener);
269 * Method to POST on a resource.
271 * @param resourceInterface
272 * Interface type of the resource to operate on.
273 * @param representation
274 * {@link SimulatorResourceModel} holding the representation of
276 * @param queryParamsMap
277 * Map which can have the query parameter name and value.
278 * @param onPostListener
279 * Event handler which will be invoked with the response for POST
280 * request with a map of attribute name and values.
282 * @throws InvalidArgsException
283 * This exception will be thrown if any parameter has invalid
285 * @throws NoSupportException
286 * This exception will be thrown if we cannot send POST request
287 * on the remote resource.
288 * @throws SimulatorException
289 * This exception will be thrown for other errors.
291 public native void post(String resourceInterface,
292 SimulatorResourceModel representation,
293 Map<String, String> queryParamsMap, IPostListener onPostListener)
294 throws InvalidArgsException, NoSupportException, SimulatorException;
297 * Method to set the RAML file path from application
300 * RAML configuration file path
302 * @throws InvalidArgsException
303 * Thrown if the RAML configuration file path is invalid.
304 * @throws SimulatorException
305 * Thrown for other errors.
307 public native void configureRAMLPath(String ramlPath)
308 throws InvalidArgsException, SimulatorException;
311 * Method to start verification of a resource using automation.
314 * Request type to verify.
315 * @param onVerifyListener
316 * This event handler will be invoked with the current status of
319 * @return Automation ID.
321 * @throws InvalidArgsException
322 * This exception will be thrown if any parameter has invalid
324 * @throws NoSupportException
325 * Thrown either if the resource does not support the request
326 * type or the resource is not configured with RAML.
327 * @throws OperationInProgressException
328 * Thrown if another request generation session is already in
330 * @throws SimulatorException
331 * This exception will be thrown for other errors.
333 public int startVerification(SimulatorVerificationType requestType,
334 IVerificationListener onVerifyListener)
335 throws InvalidArgsException, NoSupportException,
336 OperationInProgressException, SimulatorException {
337 return startVerification(requestType.ordinal(), onVerifyListener);
340 private native int startVerification(int requestType,
341 IVerificationListener onVerifyListener)
342 throws InvalidArgsException, NoSupportException,
343 OperationInProgressException, SimulatorException;
346 * Method to stop verification of a resource previously started.
351 * @throws InvalidArgsException
352 * Thrown if the automation ID is invalid.
353 * @throws NoSupportException
354 * Thrown if the resource is not configured with RAML.
355 * @throws SimulatorException
356 * Thrown for other errors.
358 public native void stopVerification(int id) throws InvalidArgsException,
359 NoSupportException, SimulatorException;
362 protected void finalize() throws Throwable {
368 private native void dispose();
370 private long nativeHandle;
372 private int mConnType;
373 private String mHost;
375 private LinkedList<String> mResTypes;
376 private LinkedList<String> mResInterfaces;
377 private boolean mIsObservable;