ffda86541f1a07e965647e8a98b5553cf925c436
[platform/upstream/iotivity.git] / service / simulator / java / sdk / src / org / oic / simulator / ResourceAttribute.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
19  * getting the information associated with a particular attribute.
20  */
21 package org.oic.simulator;
22
23 /**
24  * This class represents an attribute of a resource. It has a set of native
25  * methods for getting the attribute's information.
26  */
27 public class ResourceAttribute {
28     /**
29      * Type of attribute value.
30      */
31     public enum Type {
32         INT, DOUBLE, BOOL, STRING;
33
34         private static Type[] m_cvalues = Type.values();
35
36         @SuppressWarnings("unused")
37         private static Type getType(int x) {
38             return m_cvalues[x];
39         }
40     };
41
42     /**
43      * Class contains range property in min and max value.
44      */
45     public class Range {
46         public int getMin() {
47             return m_min;
48         }
49
50         public int getMax() {
51             return m_max;
52         }
53
54         private Range(int min, int max) {
55             m_min = min;
56             m_max = max;
57         }
58
59         private int m_min;
60         private int m_max;
61     }
62
63     @SuppressWarnings("unused")
64     private void setRange(int min, int max) {
65         m_range = new Range(min, max);
66     }
67
68     /**
69      * This generic API is used to get the value of an attribute whose type is
70      * given by the caller of the method.
71      *
72      * @param <T>
73      *            This specifies the type in which the value has to be returned.
74      *
75      * @return The attribute's value in a specified type.
76      */
77     public <T> T getValue() {
78         @SuppressWarnings("unchecked")
79         T t = (T) m_value;
80         return t;
81     }
82
83     /**
84      * Method for getting the attribute's name.
85      *
86      * @return Attribute's name
87      */
88     public String getName() {
89         return m_name;
90     }
91
92     /**
93      * Method for getting the attribute's value type.
94      *
95      * @return Attribute's value type as {@link Type}
96      */
97     public Type getType() {
98         return m_type;
99     }
100
101     /**
102      * Method for getting the attribute's value base type. For example If the
103      * attribute value object is of type Vector of {@link Integer} then its type
104      * is Vector and base type is INT.
105      *
106      * @return Attribute's value type as {@link Type}
107      */
108     public Type getBaseType() {
109         return m_type;
110     }
111
112     /**
113      * Method for getting the attribute's range property. Range will be valid
114      * only for Integer type.
115      *
116      * @return Attribute's value range as {@link Range}.
117      */
118     public Range getRange() {
119         return m_range;
120     }
121
122     /**
123      * Method for getting the attribute's allowed values property. Allowed
124      * values property will be valid only for Integer, Double, String types.
125      *
126      * @param <T>
127      *            Attribute's allowed values whose type is given by the caller
128      *            of the method.
129      *
130      * @return Attribute's value range as {@link Range}.
131      */
132     public <T> T getAllowedValues() {
133         @SuppressWarnings("unchecked")
134         T t = (T) m_AllowedValues;
135         return t;
136     }
137
138     private String m_name          = null;
139     private Object m_value         = null;
140     private Type   m_type          = Type.STRING;
141     private Range  m_range         = null;
142     private Object m_AllowedValues = null;
143 }