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.
18 * This file contains a class which has a set of native methods for
19 * communicating with a remote resource.
21 package org.oic.simulator.clientcontroller;
23 import java.util.LinkedList;
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 String getConnectivityType() {
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 interface
80 public LinkedList<String> getResourceInterfaces() {
81 return mResInterfaces;
85 * Method to get a string representation of the resource's server ID. This
86 * is unique per-server independent on how it was discovered.
90 public String getServerId() {
95 * Method to get a unique Id of the resource.
99 public String getUid() {
104 * Method to set observation on the resource
107 * allows the client to specify how it wants to observe
108 * @param queryParamsMap
109 * map which can have the query parameter name and value
110 * @param onObserveListener
111 * event handler The handler method will be invoked with a map of
112 * attribute name and values.
115 public native void observe(SimulatorObserveType observeType,
116 Map<String, String> queryParamsMap,
117 IObserveListener onObserveListener);
120 * Method to cancel the observation on the resource
122 public native void cancelObserve();
125 * Method to get the attributes of a resource.
127 * @param queryParamsMap
128 * map which can have the query parameter name and value
129 * @param onGetListener
130 * The event handler will be invoked with a map of attribute name
131 * and values. The event handler will also have the result from
132 * this Get operation This will have error codes
134 public void get(Map<String, String> queryParamsMap,
135 IGetListener onGetListener) {
136 this.get(null, queryParamsMap, onGetListener);
140 * Method to get the attributes of a resource.
142 * @param resourceInterface
143 * interface type of the resource to operate on
144 * @param queryParamsMap
145 * map which can have the query parameter name and value
146 * @param onGetListener
147 * The event handler will be invoked with a map of attribute name
148 * and values. The event handler will also have the result from
149 * this Get operation This will have error codes
151 public native void get(String resourceInterface,
152 Map<String, String> queryParamsMap, IGetListener onGetListener);
155 * Method to set the representation of a resource (via PUT)
157 * @param representation
158 * representation of the resource
159 * @param queryParamsMap
160 * Map which can have the query parameter name and value
161 * @param onPutListener
162 * event handler The event handler will be invoked with a map of
163 * attribute name and values.
165 public void put(SimulatorResourceModel representation,
166 Map<String, String> queryParamsMap, IPutListener onPutListener) {
167 this.put(null, representation, queryParamsMap, onPutListener);
171 * Method to set the representation of a resource (via PUT)
173 * @param resourceInterface
174 * interface type of the resource to operate on
175 * @param representation
176 * representation of the resource
177 * @param queryParamsMap
178 * Map which can have the query parameter name and value
179 * @param onPutListener
180 * event handler The event handler will be invoked with a map of
181 * attribute name and values.
183 private native int put(String resourceInterface,
184 SimulatorResourceModel representation,
185 Map<String, String> queryParamsMap, IPutListener onPutListener);
188 * Method to POST on a resource
190 * @param representation
191 * representation of the resource
192 * @param queryParamsMap
193 * Map which can have the query parameter name and value
194 * @param onPostListener
195 * event handler The event handler will be invoked with a map of
196 * attribute name and values.
198 public void post(SimulatorResourceModel representation,
199 Map<String, String> queryParamsMap, IPostListener onPostListener) {
200 this.post(null, representation, queryParamsMap, onPostListener);
204 * Method to POST on a resource
206 * @param resourceInterface
207 * interface type of the resource to operate on
208 * @param representation
209 * representation of the resource
210 * @param queryParamsMap
211 * Map which can have the query parameter name and value
212 * @param onPostListener
213 * event handler The event handler will be invoked with a map of
214 * attribute name and values.
216 private native int post(String resourceInterface,
217 SimulatorResourceModel representation,
218 Map<String, String> queryParamsMap, IPostListener onPostListener);
221 * Method to set the RAML file path from application
224 * RAML configuration file path
226 public native void configureRAMLPath(String ramlPath);
229 * Method to start verification of a resource using automation
232 * request type to verify
234 * @param onVerifyListener
235 * event handler The event handler will be invoked with the
238 * @return Automation ID.
241 public native int startVerification(int requestType,
242 IVerificationListener onVerifyListener);
245 * Method to stop verification of a resource previously started.
251 public native void stopVerification(int id);
254 protected void finalize() throws Throwable {
260 private native void dispose();
262 private long nativeHandle;
264 private String mConnType;
267 private boolean mIsObservable;
268 private LinkedList<String> mResTypes;
269 private LinkedList<String> mResInterfaces;