1 package oic.simulator.serviceprovider.resource;
3 import java.util.ArrayList;
4 import java.util.HashSet;
5 import java.util.Iterator;
9 import org.oic.simulator.AutomationType;
10 import org.oic.simulator.SimulatorResourceAttribute;
12 public class ResourceAttribute {
14 // Native object reference
15 private SimulatorResourceAttribute resourceAttribute;
17 private String attributeName;
18 private Object attributeValue;
19 private AttributeValueType attributeType;
20 private List<Object> allowedValues;
22 private Object minValue;
23 private Object maxValue;
25 private int automationId;
27 private boolean automationInProgress;
29 private int automationUpdateInterval;
31 private AutomationType automationType;
33 public SimulatorResourceAttribute getResourceAttribute() {
34 return resourceAttribute;
37 public void setResourceAttribute(
38 SimulatorResourceAttribute resourceAttribute) {
39 this.resourceAttribute = resourceAttribute;
42 public String getAttributeName() {
46 public void setAttributeName(String attributeName) {
47 this.attributeName = attributeName;
50 public Object getAttributeValue() {
51 return attributeValue;
54 public void setAttributeValue(Object attributeValue) {
55 this.attributeValue = attributeValue;
58 public AttributeValueType getAttributeType() {
62 public void setAttributeType(AttributeValueType attributeType) {
63 this.attributeType = attributeType;
66 public List<Object> getAllowedValues() {
70 public void setAllowedValues(List<Object> allowedValues) {
71 this.allowedValues = allowedValues;
74 public void setAllowedValues(String[] allowedValues) {
75 List<Object> allowedValueList = null;
76 if (null != allowedValues && allowedValues.length > 0) {
77 allowedValueList = new ArrayList<Object>();
78 for (String value : allowedValues) {
79 allowedValueList.add(value);
82 this.allowedValues = allowedValueList;
85 public Object getMinValue() {
89 public void setMinValue(Object minValue) {
90 this.minValue = minValue;
93 public Object getMaxValue() {
97 public void setMaxValue(Object maxValue) {
98 this.maxValue = maxValue;
101 public boolean isAutomationInProgress() {
102 return automationInProgress;
105 public void setAutomationInProgress(boolean automationInProgress) {
106 this.automationInProgress = automationInProgress;
109 public int getAutomationUpdateInterval() {
110 return automationUpdateInterval;
113 public void setAutomationUpdateInterval(int automationUpdateInterval) {
114 this.automationUpdateInterval = automationUpdateInterval;
117 public AutomationType getAutomationType() {
118 return automationType;
121 public void setAutomationType(AutomationType automationType) {
122 this.automationType = automationType;
125 public int getAutomationId() {
129 public void setAutomationId(int automationId) {
130 this.automationId = automationId;
133 public static ResourceAttribute clone(ResourceAttribute attribute) {
134 ResourceAttribute clone = null;
135 if (null != attribute) {
136 clone = new ResourceAttribute();
137 clone.setAttributeName(attribute.getAttributeName());
138 clone.setAttributeValue(attribute.getAttributeValue());
139 clone.setAllowedValues(attribute.getAllowedValues());
140 clone.setAttributeType(attribute.getAttributeType());
141 clone.setMinValue(attribute.getMinValue());
142 clone.setMaxValue(attribute.getMaxValue());
143 clone.setAutomationInProgress(attribute.isAutomationInProgress());
144 clone.setAutomationType(attribute.getAutomationType());
145 clone.setAutomationUpdateInterval(attribute
146 .getAutomationUpdateInterval());
147 clone.setResourceAttribute(null);
152 // This method gives all known possible values of the attribute
153 // It takes allowed values or range of values whichever is available
154 public Set<Object> getValues() {
155 Set<Object> valueList = new HashSet<Object>();
156 if (null != allowedValues) {
157 Iterator<Object> values = allowedValues.iterator();
158 while (values.hasNext()) {
159 valueList.add(values.next());
161 } else if (null != minValue && null != maxValue) {
162 if (attributeValue.getClass() == Integer.class) {
163 int min = (Integer) minValue;
164 int max = (Integer) maxValue;
165 for (int value = min; value <= max; value++) {
166 valueList.add(value);
168 } else if (attributeValue.getClass() == Double.class) {
169 double min = (Double) minValue;
170 double max = (Double) maxValue;
171 for (double value = min; value <= max; value++) {
172 valueList.add(value);
176 if (valueList.size() < 1) {
177 valueList.add(attributeValue);