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;
21 import org.oic.simulator.AttributeValue;
22 import org.oic.simulator.InvalidArgsException;
23 import org.oic.simulator.SimulatorException;
24 import org.oic.simulator.SimulatorResourceAttribute;
27 * This class represents a single type resource(Non-collection resource). It
28 * provides APIs specific to single resource for manipulating the resource model
29 * by adding/removing the attributes, and updating the attribute values manually
32 public final class SimulatorSingleResource extends SimulatorResource {
34 private SimulatorSingleResource(long nativeHandle) {
35 mNativeHandle = nativeHandle;
39 * API to get attribute of resource.
42 * Name of the attribute
44 * @return An object of {@link SimulatorResourceAttribute}, or null if
45 * resource does not have attribute of this name.
47 * @throws InvalidArgsException
48 * This exception will be thrown if the attribute name is
50 * @throws SimulatorException
51 * This exception will be thrown either if the resource model is
52 * not found or for some general errors.
54 public native SimulatorResourceAttribute getAttribute(String attrName)
55 throws InvalidArgsException, SimulatorException;
58 * API to get all the attributes of the resource.
60 * @return Map of attributes with attribute name as key and its
61 * corresponding {@link SimulatorResourceAttribute} as value.
63 * @throws InvalidArgsException
64 * This exception will be thrown if the attribute name is
66 * @throws SimulatorException
67 * This exception will be thrown either if the resource model is
68 * not found or for some general errors.
70 public native Map<String, SimulatorResourceAttribute> getAttributes()
71 throws InvalidArgsException, SimulatorException;
74 * API to add an attribute to resource's representation model. Observers
75 * will be notified on success.
78 * Attribute to be added to resource's representation model.
80 * @throws InvalidArgsException
81 * This exception will be thrown on invalid input.
82 * @throws SimulatorException
83 * This exception will be thrown for other errors.
85 public native boolean addAttribute(SimulatorResourceAttribute attribute)
86 throws InvalidArgsException, SimulatorException;
89 * API to remove an attribute from the simulated resource. Observers will be
90 * notified on success.
93 * Name of the attribute to be deleted.
95 * @throws InvalidArgsException
96 * This exception will be thrown on invalid input.
97 * @throws SimulatorException
98 * This exception will be thrown for other errors.
100 public native boolean removeAttribute(String attrName)
101 throws InvalidArgsException, SimulatorException;
104 * API to update the value of an attribute. Observers will be notified on
108 * Name of the attribute.
110 * New value of the attribute.
112 * @throws InvalidArgsException
113 * This exception will be thrown on invalid input.
114 * @throws SimulatorException
115 * This exception will be thrown for other errors.
117 public native boolean updateAttribute(String attrName, AttributeValue value)
118 throws InvalidArgsException, SimulatorException;
121 * API to start the resource level automation. This automation involves
122 * automatically updating all the possible values for all the attributes
126 * {@link AutoUpdateType} indicating whether the automation is
127 * one-time or recursive.
129 * Interval time in milliseconds.
131 * Listener to be notified when automation ends.
133 * @return Automation ID using which the automation can be stopped.
135 * @throws InvalidArgsException
136 * This exception will be thrown on invalid input.
137 * @throws SimulatorException
138 * This exception will be thrown for other errors.
140 public native int startResourceUpdation(AutoUpdateType type, int interval,
141 AutoUpdateListener listener) throws InvalidArgsException,
145 * API to start the attribute level automation. This automation involves
146 * automatically updating all the possible values for a given attribute
150 * Name of the attribute to be automated.
152 * {@link AutoUpdateType} indicating whether the automation is
153 * one-time or recursive.
155 * Interval time in milliseconds.
157 * Listener to be notified when automation ends.
159 * @return Automation ID using which the automation can be stopped.
161 * @throws InvalidArgsException
162 * This exception will be thrown on invalid input.
163 * @throws SimulatorException
164 * This exception will be thrown for other errors.
166 public native int startAttributeUpdation(String attrName,
167 AutoUpdateType type, int interval, AutoUpdateListener listener)
168 throws InvalidArgsException, SimulatorException;
171 * API to stop the automation based on automation id.
174 * Using which a specific automation can be stopped.
176 * @throws SimulatorException
177 * This exception will be thrown for general errors.
179 public native void stopUpdation(int id) throws SimulatorException;