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.server;
19 import java.util.Vector;
21 import org.oic.simulator.InvalidArgsException;
22 import org.oic.simulator.SimulatorException;
23 import org.oic.simulator.SimulatorResourceModel;
26 * This class serves as a base class type for all the resources in the
27 * simulator. It provides APIs to get and update the resource details, and
28 * register listeners to get notifications for resource model changes and
29 * observe requests from clients, and APIs to register/ unregister the resource
32 public class SimulatorResource {
34 private native void dispose();
36 protected long mNativeHandle;
38 protected SimulatorResource() {
42 protected void finalize() throws Throwable {
45 } catch (Throwable t) {
53 * Enum to represent the type of resource.
60 * Enum to represent the update type of automation.
62 public enum AutoUpdateType {
67 * API to get the name of the resource.
69 * @return Name of the resource.
71 * @throws SimulatorException
72 * This exception will be thrown if the native resource object
73 * does not exist or for some general errors.
75 public native String getName() throws SimulatorException;
78 * API to get the type which indicates whether resource is single or
79 * collection resource.
81 * @return Type of resource.
83 * @throws SimulatorException
84 * This exception will be thrown if the native resource object
85 * does not exist or for some general errors.
87 public native Type getType() throws SimulatorException;
90 * API to get the resource URI.
92 * @return Resource URI.
94 * @throws SimulatorException
95 * This exception will be thrown if the native resource object
96 * does not exist or for some general errors.
98 public native String getURI() throws SimulatorException;
101 * API to get the resource type.
103 * @return Resource type.
105 * @throws SimulatorException
106 * This exception will be thrown if the native resource object
107 * does not exist or for some general errors.
109 public native String getResourceType() throws SimulatorException;
112 * API to get the interfaces resource is bound with.
114 * @return Interface types.
116 * @throws SimulatorException
117 * This exception will be thrown if the native resource object
118 * does not exist or for some general errors.
120 public native Vector<String> getInterface() throws SimulatorException;
123 * API to get the observable state of resource.
125 * @return Observable state - true if resource is observable, otherwise
128 * @throws SimulatorException
129 * This exception will be thrown if the native resource object
130 * does not exist or for some general errors.
132 public native boolean isObservable() throws SimulatorException;
135 * API to get the start state of resource.
137 * @return Start state - true if resource is started, otherwise false.
139 * @throws SimulatorException
140 * This exception will be thrown if the native resource object
141 * does not exist or for some general errors.
143 public native boolean isStarted() throws SimulatorException;
146 * API to get the {@link SimulatorResourceModel} of the simulated resource.
148 * @return {@link SimulatorResourceModel} object on success, otherwise null.
150 * @throws SimulatorException
151 * This exception will be thrown if simulated resource is not
154 public native SimulatorResourceModel getResourceModel()
155 throws SimulatorException;
158 * API to set the name of the resource.
163 * @throws InvalidArgsException
164 * This exception will be thrown if the resource name is
166 * @throws SimulatorException
167 * This exception will be thrown if the native resource object
168 * does not exist or for some general errors.
170 public native void setName(String name) throws InvalidArgsException,
174 * API to set the resource URI.
179 * @throws InvalidArgsException
180 * This exception will be thrown if the resource URI is invalid.
181 * @throws SimulatorException
182 * A resource needs to be stopped by calling the stop() before
183 * calling this API. This exception will be thrown if the native
184 * resource object has not yet been stopped.
186 public native void setURI(String uri) throws InvalidArgsException,
190 * API to set the resource type.
192 * @param resourceType
193 * Resource type string.
195 * @throws InvalidArgsException
196 * This exception will be thrown if the resource type is
198 * @throws SimulatorException
199 * This exception will be thrown if the native resource object
200 * does not exist or for some general errors.
202 public native void setResourceType(String resourceType)
203 throws InvalidArgsException, SimulatorException;
206 * API to add interface type for resource.
208 * @param interfaceType
209 * Interface to be added for resource.
211 * @throws InvalidArgsException
212 * This exception will be thrown if the interface type is
214 * @throws SimulatorException
215 * This exception will be thrown if the native resource object
216 * does not exist or for some general errors.
218 public native void addInterface(String interfaceType)
219 throws InvalidArgsException, SimulatorException;
222 * API to remove interface type for resource.
224 * @param interfaceType
225 * Interface to be remove for resource.
226 * @throws InvalidArgsException
227 * This exception will be thrown if the interface type is
229 * @throws SimulatorException
230 * This exception will be thrown if the native resource object
231 * does not exist or for some general errors.
233 public native void removeInterface(String interfaceType)
234 throws InvalidArgsException, SimulatorException;
237 * API to add a list of interfaces for resource.
239 * @param interfaceType
240 * List of interfaces to be added to the resource.
242 * @throws InvalidArgsException
243 * This exception will be thrown if the interface type is
245 * @throws SimulatorException
246 * This exception will be thrown if the native resource object
247 * does not exist or for some general errors.
249 public native void addInterfaces(Vector<String> interfaceType)
250 throws InvalidArgsException, SimulatorException;
253 * API to remove interface type for resource.
255 * @param interfaceType
256 * List of interfaces to be removed from the resource.
257 * @throws InvalidArgsException
258 * This exception will be thrown if the interface type is
260 * @throws SimulatorException
261 * This exception will be thrown if the native resource object
262 * does not exist or for some general errors.
264 public native void removeInterfaces(Vector<String> interfaceType)
265 throws InvalidArgsException, SimulatorException;
268 * API to make the resource observable or not.
271 * True makes the resource observable, otherwise non-observable.
273 * @throws SimulatorException
274 * This exception will be thrown if the native resource object
275 * does not exist or for some general errors.
277 public native void setObservable(boolean state) throws SimulatorException;
280 * API to set the listener for receiving the notifications when observer is
281 * registered or unregistered with resource.
284 * Callback to be set for receiving the notifications.
286 * @throws InvalidArgsException
287 * This exception will be thrown if the listener is invalid.
288 * @throws SimulatorException
289 * This exception will be thrown if the native resource object
290 * does not exist or for some general errors.
292 public native void setObserverListener(ObserverListener listener)
293 throws InvalidArgsException, SimulatorException;
296 * API to set listener for receiving notifications when resource's model
300 * {@link ResourceModelChangeListener}.
302 * @throws InvalidArgsException
303 * This exception will be thrown on invalid input.
304 * @throws SimulatorException
305 * This exception will be thrown for other errors.
307 public native void setResourceModelChangeListener(
308 ResourceModelChangeListener listener) throws InvalidArgsException,
312 * API to start(register) the resource.
314 * @throws SimulatorException
315 * This exception will be thrown if the native resource object
316 * does not exist or for some general errors.
318 public native void start() throws SimulatorException;
321 * API to stop(unregister) the resource.
323 * @throws SimulatorException
324 * This exception will be thrown if the native resource object
325 * does not exist or for some general errors.
327 public native void stop() throws SimulatorException;
330 * API to get observers which are registered with resource.
332 * @return observers as an array of {@link Observer}.
334 * @throws SimulatorException
335 * This exception will be thrown if the native resource object
336 * does not exist or for some general errors.
338 public native Vector<Observer> getObservers() throws SimulatorException;
341 * API to notify current resource model to a specific observer.
344 * Observer ID to notify.
346 * @throws SimulatorException
347 * This exception will be thrown if the native resource object
348 * does not exist or for some general errors.
350 public native void notifyObserver(int observerId) throws SimulatorException;
353 * API to notify current resource model to all registered observers.
355 * @throws SimulatorException
356 * This exception will be thrown if the native resource object
357 * does not exist or for some general errors.
359 public native void notifyAllObservers() throws SimulatorException;
362 * Listener for receiving notification when observer is registered or
363 * unregistered with the resource.
365 public interface ObserverListener {
367 * Method will be invoked when an observer is registered with resource.
370 * URI of the resource.
372 * {@link Observer} object containing the details of
375 public void onObserverAdded(String resourceURI, Observer observer);
378 * Method will be invoked when an observer is unregistered from the
382 * URI of the resource.
384 * {@link Observer} object containing the details of
387 public void onObserverRemoved(String resourceURI, Observer observer);
391 * Listener for receiving notification on completion of automatically
392 * updating attribute value from its range or value set property.
394 public interface AutoUpdateListener {
396 * Method for receiving automation complete notifications.
401 * Identifier for auto resource/attribute update session.
403 public void onUpdateComplete(String uri, int id);
407 * Listener for receiving notifications whenever there is a change in the
410 public interface ResourceModelChangeListener {
412 * Method will be invoked to notify about the changes in the resource
417 * @param resourceModel
418 * {@link SimulatorResourceModel} of the resource.
420 public void onResourceModelChanged(String uri,
421 SimulatorResourceModel resourceModel);