2 * //******************************************************************
\r
4 * // Copyright 2015 Intel Corporation.
\r
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
8 * // Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * // you may not use this file except in compliance with the License.
\r
10 * // You may obtain a copy of the License at
\r
12 * // http://www.apache.org/licenses/LICENSE-2.0
\r
14 * // Unless required by applicable law or agreed to in writing, software
\r
15 * // distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * // See the License for the specific language governing permissions and
\r
18 * // limitations under the License.
\r
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
23 package org.iotivity.base;
\r
25 import java.security.InvalidParameterException;
\r
26 import java.util.Arrays;
\r
27 import java.util.List;
\r
32 public class OcRepresentation {
\r
35 System.loadLibrary("oc");
\r
36 System.loadLibrary("ocstack-jni");
\r
39 public OcRepresentation() {
\r
41 //Native OCRepresentation object was created using "new" and needs to be deleted
\r
42 this.mNativeNeedsDelete = true;
\r
45 private OcRepresentation(long nativeHandle) {
\r
46 this.mNativeHandle = nativeHandle;
\r
47 this.mNativeNeedsDelete = false;
\r
50 private OcRepresentation(long nativeHandle, boolean nativeNeedsDelete) {
\r
51 this.mNativeHandle = nativeHandle;
\r
52 this.mNativeNeedsDelete = nativeNeedsDelete;
\r
55 public <T> T getValue(String key) throws OcException {
\r
56 Object obj = this.getValueN(key);
\r
57 @SuppressWarnings("unchecked")
\r
62 private native Object getValueN(String key);
\r
64 public void setValue(String key, int value) throws OcException {
\r
65 this.setValueInteger(key, value);
\r
68 public void setValue(String key, double value) throws OcException {
\r
69 this.setValueDouble(key, value);
\r
72 public void setValue(String key, boolean value) throws OcException {
\r
73 this.setValueBoolean(key, value);
\r
76 public void setValue(String key, String value) throws OcException {
\r
77 this.setValueStringN(key, value);
\r
80 public void setValue(String key, OcRepresentation value) throws OcException {
\r
81 this.setValueRepresentation(key, value);
\r
84 public void setValue(String key, int[] value) throws OcException {
\r
85 this.setValueIntegerArray(key, value);
\r
88 public void setValue(String key, int[][] value) throws OcException {
\r
89 this.setValueInteger2DArray(key, value);
\r
92 public void setValue(String key, int[][][] value) throws OcException {
\r
93 this.setValueInteger3DArray(key, value);
\r
96 public void setValue(String key, double[] value) throws OcException {
\r
97 this.setValueDoubleArray(key, value);
\r
100 public void setValue(String key, double[][] value) throws OcException {
\r
101 this.setValueDouble2DArray(key, value);
\r
104 public void setValue(String key, double[][][] value) throws OcException {
\r
105 this.setValueDouble3DArray(key, value);
\r
108 public void setValue(String key, boolean[] value) throws OcException {
\r
109 this.setValueBooleanArray(key, value);
\r
112 public void setValue(String key, boolean[][] value) throws OcException {
\r
113 this.setValueBoolean2DArray(key, value);
\r
116 public void setValue(String key, boolean[][][] value) throws OcException {
\r
117 this.setValueBoolean3DArray(key, value);
\r
120 public void setValue(String key, String[] value) throws OcException {
\r
121 this.setValueStringArray(key, value);
\r
124 public void setValue(String key, String[][] value) throws OcException {
\r
125 this.setValueString2DArray(key, value);
\r
128 public void setValue(String key, String[][][] value) throws OcException {
\r
129 this.setValueString3DArray(key, value);
\r
132 public void setValue(String key, OcRepresentation[] value) throws OcException {
\r
133 this.setValueRepresentationArray(key, value);
\r
136 public void setValue(String key, OcRepresentation[][] value) throws OcException {
\r
137 this.setValueRepresentation2DArray(key, value);
\r
140 public void setValue(String key, OcRepresentation[][][] value) throws OcException {
\r
141 this.setValueRepresentation3DArray(key, value);
\r
144 private native void setValueInteger(String key, int value) throws OcException;
\r
146 private native void setValueDouble(String key, double value) throws OcException;
\r
148 private native void setValueBoolean(String key, boolean value) throws OcException;
\r
150 private native void setValueStringN(String key, String value) throws OcException;
\r
152 private native void setValueRepresentation(String key, OcRepresentation value) throws OcException;
\r
154 private native void setValueIntegerArray(String key, int[] value) throws OcException;
\r
156 private native void setValueInteger2DArray(String key, int[][] value) throws OcException;
\r
158 private native void setValueInteger3DArray(String key, int[][][] value) throws OcException;
\r
160 private native void setValueDoubleArray(String key, double[] value) throws OcException;
\r
162 private native void setValueDouble2DArray(String key, double[][] value) throws OcException;
\r
164 private native void setValueDouble3DArray(String key, double[][][] value) throws OcException;
\r
166 private native void setValueBooleanArray(String key, boolean[] value) throws OcException;
\r
168 private native void setValueBoolean2DArray(String key, boolean[][] value) throws OcException;
\r
170 private native void setValueBoolean3DArray(String key, boolean[][][] value) throws OcException;
\r
172 private native void setValueStringArray(String key, String[] value) throws OcException;
\r
174 private native void setValueString2DArray(String key, String[][] value) throws OcException;
\r
176 private native void setValueString3DArray(String key, String[][][] value) throws OcException;
\r
178 private native void setValueRepresentationArray(String key, OcRepresentation[] value) throws OcException;
\r
180 private native void setValueRepresentation2DArray(String key, OcRepresentation[][] value) throws OcException;
\r
182 private native void setValueRepresentation3DArray(String key, OcRepresentation[][][] value) throws OcException;
\r
185 * @deprecated use {@link #getValue(String key)} instead.
\r
188 public int getValueInt(String key) {
\r
191 value = this.getValue(key);
\r
192 } catch (OcException e) {
\r
193 //simply catching here for the deprecated APIs, so the older usages don't have to handle
\r
200 * @deprecated use {@link #getValue(String key)} instead.
\r
203 public boolean getValueBool(String key) {
\r
204 boolean value = false;
\r
206 value = this.getValue(key);
\r
207 } catch (OcException e) {
\r
208 //simply catching here for the deprecated APIs, so the older usages don't have to handle
\r
215 * @deprecated use {@link #getValue(String key)} instead.
\r
218 public String getValueString(String key) {
\r
221 value = this.getValue(key);
\r
222 } catch (OcException e) {
\r
223 //simply catching here for the deprecated APIs, so the older usages don't have to handle
\r
230 * @deprecated use {@link #setValue(String key, int value)} instead.
\r
233 public void setValueInt(String key, int value) {
\r
235 this.setValue(key, value);
\r
236 } catch (OcException e) {
\r
237 //simply catching here for the deprecated APIs, so the older usages don't have to handle
\r
243 * @deprecated use {@link #setValue(String key, boolean value)} instead.
\r
246 public void setValueBool(String key, boolean value) {
\r
248 this.setValue(key, value);
\r
249 } catch (OcException e) {
\r
250 //simply catching here for the deprecated APIs, so the older usages don't have to handle
\r
256 * @deprecated use {@link #setValue(String key, String value)} instead.
\r
259 public void setValueString(String key, String value) {
\r
261 this.setValue(key, value);
\r
262 } catch (OcException e) {
\r
263 //simply catching here for the deprecated APIs, so the older usages don't have to handle
\r
268 public native String getJSONRepresentation();
\r
270 public native void addChild(OcRepresentation representation);
\r
272 public native void clearChildren();
\r
274 public List<OcRepresentation> getChildren() {
\r
275 return Arrays.asList(
\r
276 getChildrenArray());
\r
279 private native OcRepresentation[] getChildrenArray();
\r
281 public native String getUri();
\r
283 public native void setUri(String uri);
\r
286 * Method to get the list of resource types
\r
288 * @return List of resource types
\r
290 public native List<String> getResourceTypes();
\r
293 * Method to set the list of resource types
\r
295 * @param resourceTypeList list of resources
\r
297 public void setResourceTypes(List<String> resourceTypeList) {
\r
298 if (null == resourceTypeList) {
\r
299 throw new InvalidParameterException("resourceTypeList cannot be null");
\r
302 this.setResourceTypeArray(
\r
303 resourceTypeList.toArray(
\r
304 new String[resourceTypeList.size()]));
\r
307 private native void setResourceTypeArray(String[] resourceTypeArray);
\r
310 * Method to get the list of resource interfaces
\r
312 * @return List of resource interface
\r
314 public native List<String> getResourceInterfaces();
\r
317 * Method to set the list of resource interfaces
\r
319 * @param resourceInterfaceList list of interfaces
\r
321 public void setResourceInterfaces(List<String> resourceInterfaceList) {
\r
322 if (null == resourceInterfaceList) {
\r
323 throw new InvalidParameterException("resourceInterfaceList cannot be null");
\r
326 this.setResourceInterfaceArray(
\r
327 resourceInterfaceList.toArray(
\r
328 new String[resourceInterfaceList.size()]));
\r
331 private native void setResourceInterfaceArray(String[] resourceInterfaceArray);
\r
333 public native boolean isEmpty();
\r
335 public native int size();
\r
337 public native boolean remove(String key);
\r
339 public native boolean hasAttribute(String key);
\r
341 public native void setNull(String key);
\r
343 public native boolean isNull(String key);
\r
346 protected void finalize() throws Throwable {
\r
349 dispose(this.mNativeNeedsDelete);
\r
352 private native void create();
\r
354 private native void dispose(boolean needsDelete);
\r
356 private long mNativeHandle;
\r
357 private boolean mNativeNeedsDelete;
\r