Merge branch 'master' into simulator
[platform/upstream/iotivity.git] / service / simulator / java / sdk / src / org / oic / simulator / serviceprovider / 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.serviceprovider;
22
23 import org.oic.simulator.SimulatorResourceAttribute;
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      * Handle to the native object of the simulator resource model.
34      */
35     private long nativeHandle;
36
37     /**
38      * Constructor for SimulatorResourceModel.
39      *
40      * @param nativeHandle
41      *            Handle to the native SimulatorResourceModel object.
42      */
43     private SimulatorResourceModel(long nativeHandle) {
44         this.nativeHandle = nativeHandle;
45     }
46
47     @Override
48     protected void finalize() throws Throwable {
49         dispose();
50     }
51
52     /**
53      * Native function for getting the total count of attributes in the resource
54      * model.
55      *
56      * @return Total number of attributes.
57      */
58     public native int size();
59
60     /**
61      * Native function for getting all attributes of a resource.
62      *
63      * @return Map of attributes with attribute name as the key and its
64      *         corresponding {@link SimulatorResourceAttribute} object as the
65      *         value.
66      */
67     public native Map<String, SimulatorResourceAttribute> getAttributes();
68
69     /**
70      * Native function to get a specific attribute of a resource. It takes the
71      * attribute name and returns an object of
72      * {@link SimulatorResourceAttribute}.
73      *
74      * @param attrName
75      *            Name of the attribute
76      *
77      * @return An object of SimulatorResourceAttribute.
78      */
79     public native SimulatorResourceAttribute getAttribute(String attrName);
80
81     /**
82      * Native function to get all the allowed values of a particular attribute.
83      *
84      * @param key
85      *            Name of the attribute
86      *
87      * @return An array of all possible values as strings.
88      */
89     public native String[] getAllowedValues(String key);
90
91     /**
92      * Native function to release the memory allocated to the native object for
93      * SimulatorResourceModel.
94      */
95     public native void dispose();
96 }