e014bdcd21139c1de873783180ffcd781ec780d1
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / remoteresource / RemoteResourceAttribute.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 oic.simulator.clientcontroller.remoteresource;
18
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.oic.simulator.AttributeProperty.Type;
25 import org.oic.simulator.AttributeValue;
26 import org.oic.simulator.AttributeValue.ValueType;
27 import org.oic.simulator.SimulatorResourceAttribute;
28
29 /**
30  * This class represents an attribute in the remote resource.
31  */
32 public class RemoteResourceAttribute {
33
34     // Native object reference
35     private SimulatorResourceAttribute resourceAttributeRef;
36
37     private String                     attributeName;
38     private Object                     attributeValue;
39
40     private ValueType                  attValType;
41     private ValueType                  attValBaseType;
42     private int                        depth;
43
44     private Type                       valuesType;
45     private List<Object>               allowedValues;
46     private Object                     minValue;
47     private Object                     maxValue;
48
49     public SimulatorResourceAttribute getResourceAttributeRef() {
50         return resourceAttributeRef;
51     }
52
53     public void setResourceAttributeRef(
54             SimulatorResourceAttribute resourceAttribute) {
55         this.resourceAttributeRef = resourceAttribute;
56     }
57
58     public String getAttributeName() {
59         return attributeName;
60     }
61
62     public void setAttributeName(String attributeName) {
63         this.attributeName = attributeName;
64     }
65
66     public Object getAttributeValue() {
67         return attributeValue;
68     }
69
70     public void setAttributeValue(Object attributeValue) {
71         this.attributeValue = attributeValue;
72     }
73
74     public List<Object> getAllowedValues() {
75         return allowedValues;
76     }
77
78     public void setAllowedValues(List<Object> allowedValues) {
79         this.allowedValues = allowedValues;
80     }
81
82     public void setAllowedValues(String[] allowedValues) {
83         List<Object> allowedValueList = null;
84         if (null != allowedValues && allowedValues.length > 0) {
85             allowedValueList = new ArrayList<Object>();
86             for (String value : allowedValues) {
87                 allowedValueList.add(value);
88             }
89         }
90         this.allowedValues = allowedValueList;
91     }
92
93     public Object getMinValue() {
94         return minValue;
95     }
96
97     public void setMinValue(Object minValue) {
98         this.minValue = minValue;
99     }
100
101     public Object getMaxValue() {
102         return maxValue;
103     }
104
105     public void setMaxValue(Object maxValue) {
106         this.maxValue = maxValue;
107     }
108
109     public static RemoteResourceAttribute clone(
110             RemoteResourceAttribute attribute) {
111         RemoteResourceAttribute clone = null;
112         if (null != attribute) {
113             clone = new RemoteResourceAttribute();
114             clone.setAttributeName(attribute.getAttributeName());
115             clone.setAttributeValue(attribute.getAttributeValue());
116             clone.setAllowedValues(attribute.getAllowedValues());
117             clone.setAttValBaseType(attribute.getAttValBaseType());
118             clone.setAttValType(attribute.getAttValType());
119             clone.setMinValue(attribute.getMinValue());
120             clone.setMaxValue(attribute.getMaxValue());
121             clone.setResourceAttributeRef(null);
122         }
123         return clone;
124     }
125
126     // This method gives all known possible values of the attribute in string
127     // format.
128     // It takes allowed values or range of values whichever is available
129     public List<String> getAllValues() {
130         List<String> valueList = new ArrayList<String>();
131         if (null != allowedValues) {
132             Iterator<Object> values = allowedValues.iterator();
133             Object value;
134             while (values.hasNext()) {
135                 value = values.next();
136                 if (null != value) {
137                     valueList.add(String.valueOf(value));
138                 }
139             }
140         } else if (null != minValue && null != maxValue) {
141             double min = (Double) minValue;
142             double max = (Double) maxValue;
143             for (double value = min; value <= max; value++) {
144                 valueList.add(String.valueOf(value));
145             }
146         }
147         if (valueList.size() < 1 && null != attributeValue) {
148             valueList.add(String.valueOf(attributeValue));
149         }
150         return valueList;
151     }
152
153     // Method added for debugging purpose
154     public static void printAttributes(
155             Map<String, RemoteResourceAttribute> attributeMap) {
156         Iterator<String> itr = attributeMap.keySet().iterator();
157         String attName;
158         RemoteResourceAttribute att;
159         while (itr.hasNext()) {
160             attName = itr.next();
161             att = attributeMap.get(attName);
162             System.out.println("AttributeName:" + attName);
163             System.out.println("AttributeValue:"
164                     + att.getAttributeValue().toString());
165             System.out.println("Allowed Values:" + att.getAllValues());
166         }
167     }
168
169     public ValueType getAttValType() {
170         return attValType;
171     }
172
173     public void setAttValType(ValueType attValType) {
174         this.attValType = attValType;
175     }
176
177     public ValueType getAttValBaseType() {
178         return attValBaseType;
179     }
180
181     public void setAttValBaseType(ValueType attValBaseType) {
182         this.attValBaseType = attValBaseType;
183     }
184
185     public Type getValuesType() {
186         return valuesType;
187     }
188
189     public void setValuesType(Type valuesType) {
190         this.valuesType = valuesType;
191     }
192
193     public int getDepth() {
194         return depth;
195     }
196
197     public void setDepth(int depth) {
198         this.depth = depth;
199     }
200 }