Imported Upstream version 1.0.1
[platform/upstream/iotivity.git] / service / simulator / java / sdk / src / org / oic / simulator / SimulatorResourceModel.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.oic.simulator;
18
19 import org.oic.simulator.ResourceAttribute;
20 import java.util.Map;
21
22 /**
23  * This class represents the resource model of a resource and it provides a set
24  * of native methods for accessing the resource model.
25  */
26 public class SimulatorResourceModel {
27
28     /**
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
31      * resource model.
32      */
33     public SimulatorResourceModel() {
34         create();
35     }
36
37     /**
38      * API to add an attribute of type integer.
39      *
40      * @param name
41      *            Name of the attribute
42      * @param value
43      *            Value of the attribute
44      *
45      * @throws InvalidArgsException
46      *             This exception will be thrown if the attribute name is
47      *             invalid.
48      * @throws SimulatorException
49      *             This exception will be thrown either if the resource model is
50      *             not found or for some general errors.
51      */
52     public native void addAttributeInt(String name, int value)
53             throws InvalidArgsException, SimulatorException;
54
55     /**
56      * API to add an attribute of type double.
57      *
58      * @param name
59      *            Name of the attribute
60      * @param value
61      *            Value of the attribute
62      *
63      * @throws InvalidArgsException
64      *             This exception will be thrown if the attribute name is
65      *             invalid.
66      * @throws SimulatorException
67      *             This exception will be thrown either if the resource model is
68      *             not found or for some general errors.
69      */
70     public native void addAttributeDouble(String name, double value)
71             throws InvalidArgsException, SimulatorException;
72
73     /**
74      * API to add an attribute of type boolean.
75      *
76      * @param name
77      *            Name of the attribute
78      * @param value
79      *            Value of the attribute
80      *
81      * @throws InvalidArgsException
82      *             This exception will be thrown if the attribute name is
83      *             invalid.
84      * @throws SimulatorException
85      *             This exception will be thrown either if the resource model is
86      *             not found or for some general errors.
87      */
88     public native void addAttributeBoolean(String name, boolean value)
89             throws InvalidArgsException, SimulatorException;
90
91     /**
92      * API to add an attribute of type string.
93      *
94      * @param name
95      *            Name of the attribute
96      * @param value
97      *            Value of the attribute
98      *
99      * @throws InvalidArgsException
100      *             This exception will be thrown if the attribute name is
101      *             invalid.
102      * @throws SimulatorException
103      *             This exception will be thrown either if the resource model is
104      *             not found or for some general errors.
105      */
106     public native void addAttributeString(String name, String value)
107             throws InvalidArgsException, SimulatorException;
108
109     /**
110      * API to get number of attributes for this model.
111      *
112      * @return Number of attributes.
113      *
114      * @throws SimulatorException
115      *             This exception will be thrown either if the resource model is
116      *             not found or for some general errors.
117      */
118     public native int size() throws SimulatorException;
119
120     /**
121      * API for getting all attributes.
122      *
123      * @return Map of attributes with attribute name as the key and its
124      *         corresponding {@link ResourceAttribute} object as the value.
125      *
126      * @throws SimulatorException
127      *             This exception will be thrown either if the resource model is
128      *             not found or for some general errors.
129      */
130     public native Map<String, ResourceAttribute> getAttributes()
131             throws SimulatorException;
132
133     /**
134      * API to get attribute by its name.
135      *
136      * @param name
137      *            Name of the attribute
138      *
139      * @return An object of {@link ResourceAttribute}.
140      *
141      * @throws InvalidArgsException
142      *             This exception will be thrown if the attribute does not
143      *             exist.
144      *
145      * @throws SimulatorException
146      *             This exception will be thrown either if the resource model is
147      *             not found or for some general errors.
148      */
149     public native ResourceAttribute getAttribute(String name)
150             throws InvalidArgsException, SimulatorException;
151
152     private SimulatorResourceModel(long nativeHandle) {
153         this.nativeHandle = nativeHandle;
154     }
155
156     @Override
157     protected void finalize() throws Throwable {
158         try {
159             dispose();
160         } finally {
161             super.finalize();
162         }
163     }
164
165     private native void create();
166
167     private native void dispose();
168
169     private long nativeHandle;
170 }