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