199f8192ccbc2e70e2c2e8524d6e1df0dcb56311
[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 /**
18  * This file contains a class which has a set of native methods for accessing
19  * the resource model.
20  */
21 package org.oic.simulator;
22
23 import org.oic.simulator.ResourceAttribute;
24 import java.util.Map;
25
26 /**
27  * This class represents the resource model of a resource and it provides a set
28  * of native methods for accessing the resource model.
29  */
30 public class SimulatorResourceModel {
31
32     /**
33      * Constructor.
34      */
35     public SimulatorResourceModel() {
36         create();
37     }
38
39     /**
40      * Method for adding an attribute whose value is of type int.
41      * 
42      * @param name
43      *            Name of the attribute
44      * @param value
45      *            Value of the attribute
46      */
47     public void addAttribute(String name, int value) {
48         addAttributeInt(name, value);
49     }
50
51     /**
52      * Method for adding an attribute whose value is of type double.
53      * 
54      * @param name
55      *            Name of the attribute
56      * @param value
57      *            Value of the attribute
58      */
59     public void addAttribute(String name, double value) {
60         addAttributeDouble(name, value);
61     }
62
63     /**
64      * Method for adding an attribute whose value is of type boolean.
65      * 
66      * @param name
67      *            Name of the attribute
68      * @param value
69      *            Value of the attribute
70      */
71     public void addAttribute(String name, boolean value) {
72         addAttributeBoolean(name, value);
73     }
74
75     /**
76      * Method for adding an attribute whose value is of type string.
77      * 
78      * @param name
79      *            Name of the attribute
80      * @param value
81      *            Value of the attribute
82      */
83     public void addAttribute(String name, String value) {
84         addAttributeString(name, value);
85     }
86
87     /**
88      * Method for getting the number of attributes this model comprised of.
89      *
90      * @return Number of attributes.
91      */
92     public native int size();
93
94     /**
95      * Method for getting all attributes.
96      *
97      * @return Map of attributes with attribute name as the key and its
98      *         corresponding {@link ResourceAttribute} object as the value.
99      */
100     public native Map<String, ResourceAttribute> getAttributes();
101
102     /**
103      * Method for getting a specific attribute by its name.
104      *
105      * @param attrName
106      *            Name of the attribute
107      *
108      * @return An object of {@link ResourceAttribute}.
109      */
110     public native ResourceAttribute getAttribute(String attrName);
111
112     private native void addAttributeInt(String name, int value);
113
114     private native void addAttributeDouble(String name, double value);
115
116     private native void addAttributeBoolean(String name, boolean value);
117
118     private native void addAttributeString(String name, String value);
119
120     private SimulatorResourceModel(long nativeHandle) {
121         this.nativeHandle = nativeHandle;
122     }
123
124     @Override
125     protected void finalize() throws Throwable {
126         dispose();
127     }
128
129     private native void create();
130
131     private native void dispose();
132
133     private long nativeHandle;
134 }