2 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package oic.simulator.clientcontroller.remoteresource;
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
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;
30 * This class represents an attribute in the remote resource.
32 public class RemoteResourceAttribute {
34 // Native object reference
35 private SimulatorResourceAttribute resourceAttributeRef;
37 private String attributeName;
38 private Object attributeValue;
40 private ValueType attValType;
41 private ValueType attValBaseType;
44 private Type valuesType;
45 private List<Object> allowedValues;
46 private Object minValue;
47 private Object maxValue;
49 public SimulatorResourceAttribute getResourceAttributeRef() {
50 return resourceAttributeRef;
53 public void setResourceAttributeRef(
54 SimulatorResourceAttribute resourceAttribute) {
55 this.resourceAttributeRef = resourceAttribute;
58 public String getAttributeName() {
62 public void setAttributeName(String attributeName) {
63 this.attributeName = attributeName;
66 public Object getAttributeValue() {
67 return attributeValue;
70 public void setAttributeValue(Object attributeValue) {
71 this.attributeValue = attributeValue;
74 public List<Object> getAllowedValues() {
78 public void setAllowedValues(List<Object> allowedValues) {
79 this.allowedValues = allowedValues;
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);
90 this.allowedValues = allowedValueList;
93 public Object getMinValue() {
97 public void setMinValue(Object minValue) {
98 this.minValue = minValue;
101 public Object getMaxValue() {
105 public void setMaxValue(Object maxValue) {
106 this.maxValue = maxValue;
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);
126 // This method gives all known possible values of the attribute in string
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();
134 while (values.hasNext()) {
135 value = values.next();
137 valueList.add(String.valueOf(value));
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));
147 if (valueList.size() < 1 && null != attributeValue) {
148 valueList.add(String.valueOf(attributeValue));
153 // Method added for debugging purpose
154 public static void printAttributes(
155 Map<String, RemoteResourceAttribute> attributeMap) {
156 Iterator<String> itr = attributeMap.keySet().iterator();
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());
169 public ValueType getAttValType() {
173 public void setAttValType(ValueType attValType) {
174 this.attValType = attValType;
177 public ValueType getAttValBaseType() {
178 return attValBaseType;
181 public void setAttValBaseType(ValueType attValBaseType) {
182 this.attValBaseType = attValBaseType;
185 public Type getValuesType() {
189 public void setValuesType(Type valuesType) {
190 this.valuesType = valuesType;
193 public int getDepth() {
197 public void setDepth(int depth) {