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;
19 import org.oic.simulator.ResourceAttribute;
23 * This class represents the resource model of a resource and it provides a set
24 * of native methods for accessing the resource model.
26 public class SimulatorResourceModel {
29 * Constructor for creating a native resource model object. Client requests
30 * such as PUT and POST uses this method for passing the new/updated
33 public SimulatorResourceModel() {
38 * API to add an attribute of type integer.
41 * Name of the attribute
43 * Value of the attribute
45 * @throws InvalidArgsException
46 * This exception will be thrown if the attribute name is
48 * @throws SimulatorException
49 * This exception will be thrown either if the resource model is
50 * not found or for some general errors.
52 public native void addAttributeInt(String name, int value)
53 throws InvalidArgsException, SimulatorException;
56 * API to add an attribute of type double.
59 * Name of the attribute
61 * Value of the attribute
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 void addAttributeDouble(String name, double value)
71 throws InvalidArgsException, SimulatorException;
74 * API to add an attribute of type boolean.
77 * Name of the attribute
79 * Value of the attribute
81 * @throws InvalidArgsException
82 * This exception will be thrown if the attribute name is
84 * @throws SimulatorException
85 * This exception will be thrown either if the resource model is
86 * not found or for some general errors.
88 public native void addAttributeBoolean(String name, boolean value)
89 throws InvalidArgsException, SimulatorException;
92 * API to add an attribute of type string.
95 * Name of the attribute
97 * Value of the attribute
99 * @throws InvalidArgsException
100 * This exception will be thrown if the attribute name is
102 * @throws SimulatorException
103 * This exception will be thrown either if the resource model is
104 * not found or for some general errors.
106 public native void addAttributeString(String name, String value)
107 throws InvalidArgsException, SimulatorException;
110 * API to get number of attributes for this model.
112 * @return Number of attributes.
114 * @throws SimulatorException
115 * This exception will be thrown either if the resource model is
116 * not found or for some general errors.
118 public native int size() throws SimulatorException;
121 * API for getting all attributes.
123 * @return Map of attributes with attribute name as the key and its
124 * corresponding {@link ResourceAttribute} object as the value.
126 * @throws SimulatorException
127 * This exception will be thrown either if the resource model is
128 * not found or for some general errors.
130 public native Map<String, ResourceAttribute> getAttributes()
131 throws SimulatorException;
134 * API to get attribute by its name.
137 * Name of the attribute
139 * @return An object of {@link ResourceAttribute}.
141 * @throws InvalidArgsException
142 * This exception will be thrown if the attribute does not
145 * @throws SimulatorException
146 * This exception will be thrown either if the resource model is
147 * not found or for some general errors.
149 public native ResourceAttribute getAttribute(String name)
150 throws InvalidArgsException, SimulatorException;
152 private SimulatorResourceModel(long nativeHandle) {
153 this.nativeHandle = nativeHandle;
157 protected void finalize() throws Throwable {
160 } catch(Throwable t){
163 System.out.println("Calling finalize of Super Class");
168 private native void create();
170 private native void dispose();
172 private long nativeHandle;