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;
25 public class SimulatorResource {
27 private native void dispose();
29 protected long mNativeHandle;
31 protected SimulatorResource() {
35 protected void finalize() throws Throwable {
38 } catch (Throwable t) {
49 public enum AutoUpdateType {
54 * API to get the name of the resource.
56 * @return Name of the resource.
58 * @throws SimulatorException
59 * This exception will be thrown if the native resource object
60 * does not exist or for some general errors.
62 public native String getName() throws SimulatorException;
65 * API to get the type which indicates whether resource is single or
66 * collection resource.
68 * @return Type of resource.
70 * @throws SimulatorException
71 * This exception will be thrown if the native resource object
72 * does not exist or for some general errors.
74 public native Type getType() throws SimulatorException;
77 * API to get the resource URI.
79 * @return Resource URI.
81 * @throws SimulatorException
82 * This exception will be thrown if the native resource object
83 * does not exist or for some general errors.
85 public native String getURI() throws SimulatorException;
88 * API to get the resource type.
90 * @return Resource type.
92 * @throws SimulatorException
93 * This exception will be thrown if the native resource object
94 * does not exist or for some general errors.
96 public native String getResourceType() throws SimulatorException;
99 * API to get the interfaces resource is bound with.
101 * @return Interface type.
103 * @throws SimulatorException
104 * This exception will be thrown if the native resource object
105 * does not exist or for some general errors.
107 public native Vector<String> getInterface() throws SimulatorException;
110 * API to get the observable state of resource.
112 * @return Observable state - true if resource is observable, otherwise
115 * @throws SimulatorException
116 * This exception will be thrown if the native resource object
117 * does not exist or for some general errors.
119 public native boolean isObservable() throws SimulatorException;
122 * API to get the start state of resource.
124 * @return Start state - true if resource is started, otherwise false.
126 * @throws SimulatorException
127 * This exception will be thrown if the native resource object
128 * does not exist or for some general errors.
130 public native boolean isStarted() throws SimulatorException;
133 * API to get the {@link SimulatorResourceModel} of the simulated resource.
135 * @return {@link SimulatorResourceModel} object on success, otherwise null.
137 * @throws SimulatorException
138 * This exception will be thrown if simulated resource is not
141 public native SimulatorResourceModel getResourceModel()
142 throws SimulatorException;
145 * API to set the name of the resource.
150 * @throws InvalidArgsException
151 * This exception will be thrown if the resource name is
153 * @throws SimulatorException
154 * This exception will be thrown if the native resource object
155 * does not exist or for some general errors.
157 public native void setName(String name) throws InvalidArgsException,
161 * API to set the resource URI.
166 * @throws InvalidArgsException
167 * This exception will be thrown if the resource URI is invalid.
168 * @throws SimulatorException
169 * This exception will be thrown if the native resource object
170 * does not exist or for some general errors.
172 public native void setURI(String uri) throws InvalidArgsException,
176 * API to set the resource type.
178 * @param resourceType
179 * - resource type string.
181 * @throws InvalidArgsException
182 * This exception will be thrown if the resource type is
184 * @throws SimulatorException
185 * This exception will be thrown if the native resource object
186 * does not exist or for some general errors.
188 public native void setResourceType(String resourceType)
189 throws InvalidArgsException, SimulatorException;
192 * API to add interface type for resource.
194 * @param interfaceType
195 * - interface to be added for resource.
197 * @throws InvalidArgsException
198 * This exception will be thrown if the interface type is
200 * @throws SimulatorException
201 * This exception will be thrown if the native resource object
202 * does not exist or for some general errors.
204 public native void addInterface(String interfaceType)
205 throws InvalidArgsException, SimulatorException;
208 * API to make the resource observable or not.
211 * - true make the resource observable, otherwise non-observable.
213 * @throws SimulatorException
214 * This exception will be thrown if the native resource object
215 * does not exist or for some general errors.
217 public native void setObservable(boolean state) throws SimulatorException;
220 * API to set the listener for receiving the notifications when observer is
221 * registered or unregistered with resource.
224 * - Callback to be set for receiving the notifications.
226 * @throws InvalidArgsException
227 * This exception will be thrown if the listener is invalid.
228 * @throws SimulatorException
229 * This exception will be thrown if the native resource object
230 * does not exist or for some general errors.
232 public native void setObserverListener(ObserverListener listener)
233 throws InvalidArgsException, SimulatorException;
236 * API to set listener for receiving notifications when resource's model
240 * {@link ResourceModelChangeListener}.
242 * @throws InvalidArgsException
243 * This exception will be thrown on invalid input.
244 * @throws SimulatorException
245 * This exception will be thrown for other errors.
247 public native void setResourceModelChangeListener(
248 ResourceModelChangeListener listener) throws InvalidArgsException,
252 * API to start the resource.
254 * @throws SimulatorException
255 * This exception will be thrown if the native resource object
256 * does not exist or for some general errors.
258 public native void start() throws SimulatorException;
261 * API to stop the resource.
263 * @throws SimulatorException
264 * This exception will be thrown if the native resource object
265 * does not exist or for some general errors.
267 public native void stop() throws SimulatorException;
270 * API to get observers which are registered with resource.
272 * @return observers as an array of {@link Observer}.
274 * @throws SimulatorException
275 * This exception will be thrown if the native resource object
276 * does not exist or for some general errors.
278 public native Vector<Observer> getObservers() throws SimulatorException;
281 * API to notify current resource model to specific observer.
284 * - Observer ID to notify.
286 * @throws SimulatorException
287 * This exception will be thrown if the native resource object
288 * does not exist or for some general errors.
290 public native void notifyObserver(int observerId) throws SimulatorException;
293 * API to notify all registered observers.
295 * @throws SimulatorException
296 * This exception will be thrown if the native resource object
297 * does not exist or for some general errors.
299 public native void notifyAllObservers() throws SimulatorException;
302 * Listener for receiving notification when observer is registered or
303 * unregistered with the resource.
305 public interface ObserverListener {
307 * Method will be invoked when a observer is registered with resource.
310 * URI of the resource.
312 * {@link ObserverInfo} object containing the details of
315 public void onObserverAdded(String resourceURI, Observer observer);
318 * Method will be invoked when a observer is Unregistered with resource.
321 * URI of the resource.
323 * {@link ObserverInfo} object containing the details of
326 public void onObserverRemoved(String resourceURI, Observer observer);
330 * Listener for receiving notification on completion of automatically
331 * updating attribute value from its range or value set property.
333 public interface AutoUpdateListener {
335 * Method for receiving automation complete notifications.
340 * Identifier for auto resource/attribute update session.
342 public void onUpdateComplete(String uri, int id);
346 * Listener for receiving notifications whenever there is a change in the
349 public interface ResourceModelChangeListener {
351 * Method will be invoked to notify about the changes in the resource
356 * @param resourceModel
357 * {@link SimulatorResourceModel} of the resource.
359 public void onResourceModelChanged(String uri,
360 SimulatorResourceModel resourceModel);