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.ValueType;
26 import org.oic.simulator.SimulatorResourceAttribute;
29 * This class represents an attribute in the remote resource.
31 public class RemoteResourceAttribute {
33 // Native object reference
34 private SimulatorResourceAttribute resourceAttributeRef;
36 private String attributeName;
37 private Object attributeValue;
39 private ValueType attValType;
40 private ValueType attValBaseType;
43 private Type valuesType;
44 private List<Object> allowedValues;
45 private Object minValue;
46 private Object maxValue;
48 public SimulatorResourceAttribute getResourceAttributeRef() {
49 return resourceAttributeRef;
52 public void setResourceAttributeRef(
53 SimulatorResourceAttribute resourceAttribute) {
54 this.resourceAttributeRef = resourceAttribute;
57 public String getAttributeName() {
61 public void setAttributeName(String attributeName) {
62 this.attributeName = attributeName;
65 public Object getAttributeValue() {
66 return attributeValue;
69 public void setAttributeValue(Object attributeValue) {
70 this.attributeValue = attributeValue;
73 public List<Object> getAllowedValues() {
77 public void setAllowedValues(List<Object> allowedValues) {
78 this.allowedValues = allowedValues;
81 public void setAllowedValues(String[] allowedValues) {
82 List<Object> allowedValueList = null;
83 if (null != allowedValues && allowedValues.length > 0) {
84 allowedValueList = new ArrayList<Object>();
85 for (String value : allowedValues) {
86 allowedValueList.add(value);
89 this.allowedValues = allowedValueList;
92 public Object getMinValue() {
96 public void setMinValue(Object minValue) {
97 this.minValue = minValue;
100 public Object getMaxValue() {
104 public void setMaxValue(Object maxValue) {
105 this.maxValue = maxValue;
108 public static RemoteResourceAttribute clone(
109 RemoteResourceAttribute attribute) {
110 RemoteResourceAttribute clone = null;
111 if (null != attribute) {
112 clone = new RemoteResourceAttribute();
113 clone.setAttributeName(attribute.getAttributeName());
114 clone.setAttributeValue(attribute.getAttributeValue());
115 clone.setAllowedValues(attribute.getAllowedValues());
116 clone.setAttValBaseType(attribute.getAttValBaseType());
117 clone.setAttValType(attribute.getAttValType());
118 clone.setMinValue(attribute.getMinValue());
119 clone.setMaxValue(attribute.getMaxValue());
120 clone.setResourceAttributeRef(null);
125 // This method gives all known possible values of the attribute in string
127 // It takes allowed values or range of values whichever is available
128 public List<String> getAllValues() {
129 List<String> valueList = new ArrayList<String>();
130 if (null != allowedValues) {
131 Iterator<Object> values = allowedValues.iterator();
133 while (values.hasNext()) {
134 value = values.next();
136 valueList.add(String.valueOf(value));
139 } else if (null != minValue && null != maxValue) {
140 double min = (Double) minValue;
141 double max = (Double) maxValue;
142 for (double value = min; value <= max; value++) {
143 valueList.add(String.valueOf(value));
146 if (valueList.size() < 1 && null != attributeValue) {
147 valueList.add(String.valueOf(attributeValue));
152 // Method added for debugging purpose
153 public static void printAttributes(
154 Map<String, RemoteResourceAttribute> attributeMap) {
155 Iterator<String> itr = attributeMap.keySet().iterator();
157 RemoteResourceAttribute att;
158 while (itr.hasNext()) {
159 attName = itr.next();
160 att = attributeMap.get(attName);
161 System.out.println("AttributeName:" + attName);
162 System.out.println("AttributeValue:"
163 + att.getAttributeValue().toString());
164 System.out.println("Allowed Values:" + att.getAllValues());
168 public ValueType getAttValType() {
172 public void setAttValType(ValueType attValType) {
173 this.attValType = attValType;
176 public ValueType getAttValBaseType() {
177 return attValBaseType;
180 public void setAttValBaseType(ValueType attValBaseType) {
181 this.attValBaseType = attValBaseType;
184 public Type getValuesType() {
188 public void setValuesType(Type valuesType) {
189 this.valuesType = valuesType;
192 public int getDepth() {
196 public void setDepth(int depth) {