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.ResourceAttribute;
25 import org.oic.simulator.ResourceAttribute.Type;
28 * This class represents an attribute in the remote resource.
30 public class RemoteResourceAttribute {
32 // Native object reference
33 private ResourceAttribute resourceAttribute;
35 private String attributeName;
36 private Object attributeValue;
37 private Type attValType;
38 private Type attValBaseType;
39 private List<Object> allowedValues;
41 private Object minValue;
42 private Object maxValue;
44 public ResourceAttribute getResourceAttribute() {
45 return resourceAttribute;
48 public void setResourceAttribute(ResourceAttribute resourceAttribute) {
49 this.resourceAttribute = resourceAttribute;
52 public String getAttributeName() {
56 public void setAttributeName(String attributeName) {
57 this.attributeName = attributeName;
60 public Object getAttributeValue() {
61 return attributeValue;
64 public void setAttributeValue(Object attributeValue) {
65 this.attributeValue = attributeValue;
68 public List<Object> getAllowedValues() {
72 public void setAllowedValues(List<Object> allowedValues) {
73 this.allowedValues = allowedValues;
76 public void setAllowedValues(String[] allowedValues) {
77 List<Object> allowedValueList = null;
78 if (null != allowedValues && allowedValues.length > 0) {
79 allowedValueList = new ArrayList<Object>();
80 for (String value : allowedValues) {
81 allowedValueList.add(value);
84 this.allowedValues = allowedValueList;
87 public Object getMinValue() {
91 public void setMinValue(Object minValue) {
92 this.minValue = minValue;
95 public Object getMaxValue() {
99 public void setMaxValue(Object maxValue) {
100 this.maxValue = maxValue;
103 public static RemoteResourceAttribute clone(
104 RemoteResourceAttribute attribute) {
105 RemoteResourceAttribute clone = null;
106 if (null != attribute) {
107 clone = new RemoteResourceAttribute();
108 clone.setAttributeName(attribute.getAttributeName());
109 clone.setAttributeValue(attribute.getAttributeValue());
110 clone.setAllowedValues(attribute.getAllowedValues());
111 clone.setAttValBaseType(attribute.getAttValBaseType());
112 clone.setAttValType(attribute.getAttValType());
113 clone.setMinValue(attribute.getMinValue());
114 clone.setMaxValue(attribute.getMaxValue());
115 clone.setResourceAttribute(null);
120 // This method gives all known possible values of the attribute in string
122 // It takes allowed values or range of values whichever is available
123 public List<String> getAllValues() {
124 List<String> valueList = new ArrayList<String>();
125 if (null != allowedValues) {
126 Iterator<Object> values = allowedValues.iterator();
128 while (values.hasNext()) {
129 value = values.next();
131 valueList.add(String.valueOf(value));
134 } else if (null != minValue && null != maxValue) {
135 if (attributeValue.getClass() == Integer.class) {
136 int min = (Integer) minValue;
137 int max = (Integer) maxValue;
138 for (int value = min; value <= max; value++) {
139 valueList.add(String.valueOf(value));
141 } else if (attributeValue.getClass() == Double.class) {
142 double min = (Double) minValue;
143 double max = (Double) maxValue;
144 for (double value = min; value <= max; value++) {
145 valueList.add(String.valueOf(value));
149 if (valueList.size() < 1 && null != attributeValue) {
150 valueList.add(String.valueOf(attributeValue));
155 public static void printAttributes(
156 Map<String, RemoteResourceAttribute> attributeMap) {
157 Iterator<String> itr = attributeMap.keySet().iterator();
159 RemoteResourceAttribute att;
160 while (itr.hasNext()) {
161 attName = itr.next();
162 att = attributeMap.get(attName);
163 System.out.println("AttributeName:" + attName);
164 System.out.println("AttributeValue:"
165 + att.getAttributeValue().toString());
166 System.out.println("Allowed Values:" + att.getAllValues());
170 public Type getAttValType() {
174 public void setAttValType(Type attValType) {
175 this.attValType = attValType;
178 public Type getAttValBaseType() {
179 return attValBaseType;
182 public void setAttValBaseType(Type attValBaseType) {
183 this.attValBaseType = attValBaseType;