1 package org.oic.simulator;
3 public class AttributeValueValidation implements
4 AttributeValueVisitor.VisitingMethods<Boolean> {
5 private AttributeProperty mProperty = null;
7 public AttributeValueValidation(AttributeProperty property) {
11 public boolean validate(AttributeValue value) {
12 AttributeValueVisitor visitor = new AttributeValueVisitor(value, this);
13 Boolean result = (Boolean) visitor.visit();
14 return result.booleanValue();
18 public Boolean visitingValue(Integer value) {
19 if (mProperty == null)
22 if (checkRange(value.doubleValue()) || checkValueSet(value))
28 public Boolean visitingValue(Double value) {
29 if (mProperty == null)
32 if (checkRange(value.doubleValue()) || checkValueSet(value))
38 public Boolean visitingValue(Boolean value) {
39 if (mProperty == null)
42 if (checkValueSet(value))
48 public Boolean visitingValue(String value) {
49 if (mProperty == null)
52 if (checkRange(value.length()) || checkValueSet(value))
58 public Boolean visitingValue(SimulatorResourceModel value) {
63 public Boolean visitingValue(Integer[] values) {
64 if (mProperty == null)
67 if (!checkRange(values.length))
70 if (mProperty.getChildProperty() != null) {
71 AttributeValueValidation rangeValidation = new AttributeValueValidation(
72 mProperty.getChildProperty());
73 for (Integer value : values) {
74 if (rangeValidation.visitingValue(value) == false)
83 public Boolean visitingValue(Double[] values) {
84 if (mProperty == null)
87 if (!checkRange(values.length))
90 if (mProperty.getChildProperty() != null) {
91 AttributeValueValidation rangeValidation = new AttributeValueValidation(
92 mProperty.getChildProperty());
93 for (Double value : values) {
94 if (rangeValidation.visitingValue(value) == false)
103 public Boolean visitingValue(Boolean[] values) {
104 if (mProperty == null)
107 if (!checkRange(values.length))
110 if (mProperty.getChildProperty() != null) {
111 AttributeValueValidation rangeValidation = new AttributeValueValidation(
112 mProperty.getChildProperty());
113 for (Boolean value : values) {
114 if (rangeValidation.visitingValue(value) == false)
123 public Boolean visitingValue(String[] values) {
124 if (mProperty == null)
127 if (!checkRange(values.length))
130 if (mProperty.getChildProperty() != null) {
131 AttributeValueValidation rangeValidation = new AttributeValueValidation(
132 mProperty.getChildProperty());
133 for (String value : values) {
134 if (rangeValidation.visitingValue(value) == false)
143 public Boolean visitingValue(SimulatorResourceModel[] value) {
148 public Boolean visitingValue(Integer[][] values) {
149 if (mProperty == null)
152 if (!checkRange(values.length))
155 if (mProperty.getChildProperty() != null) {
156 AttributeValueValidation rangeValidation = new AttributeValueValidation(
157 mProperty.getChildProperty());
158 for (Integer[] value : values) {
159 if (rangeValidation.visitingValue(value) == false)
168 public Boolean visitingValue(Double[][] values) {
169 if (mProperty == null)
172 if (!checkRange(values.length))
175 if (mProperty.getChildProperty() != null) {
176 AttributeValueValidation rangeValidation = new AttributeValueValidation(
177 mProperty.getChildProperty());
178 for (Double[] value : values) {
179 if (rangeValidation.visitingValue(value) == false)
188 public Boolean visitingValue(Boolean[][] values) {
189 if (mProperty == null)
192 if (!checkRange(values.length))
195 if (mProperty.getChildProperty() != null) {
196 AttributeValueValidation rangeValidation = new AttributeValueValidation(
197 mProperty.getChildProperty());
198 for (Boolean[] value : values) {
199 if (rangeValidation.visitingValue(value) == false)
208 public Boolean visitingValue(String[][] values) {
209 if (mProperty == null)
212 if (!checkRange(values.length))
215 if (mProperty.getChildProperty() != null) {
216 AttributeValueValidation rangeValidation = new AttributeValueValidation(
217 mProperty.getChildProperty());
218 for (String[] value : values) {
219 if (rangeValidation.visitingValue(value) == false)
228 public Boolean visitingValue(SimulatorResourceModel[][] value) {
233 public Boolean visitingValue(Integer[][][] values) {
234 if (mProperty == null)
237 if (!checkRange(values.length))
240 if (mProperty.getChildProperty() != null) {
241 AttributeValueValidation rangeValidation = new AttributeValueValidation(
242 mProperty.getChildProperty());
243 for (Integer[][] value : values) {
244 if (rangeValidation.visitingValue(value) == false)
253 public Boolean visitingValue(Double[][][] values) {
254 if (mProperty == null)
257 if (!checkRange(values.length))
260 if (mProperty.getChildProperty() != null) {
261 AttributeValueValidation rangeValidation = new AttributeValueValidation(
262 mProperty.getChildProperty());
263 for (Double[][] value : values) {
264 if (rangeValidation.visitingValue(value) == false)
273 public Boolean visitingValue(Boolean[][][] values) {
274 if (mProperty == null)
277 if (!checkRange(values.length))
280 if (mProperty.getChildProperty() != null) {
281 AttributeValueValidation rangeValidation = new AttributeValueValidation(
282 mProperty.getChildProperty());
283 for (Boolean[][] value : values) {
284 if (rangeValidation.visitingValue(value) == false)
293 public Boolean visitingValue(String[][][] values) {
294 if (mProperty == null)
297 if (!checkRange(values.length))
300 if (mProperty.getChildProperty() != null) {
301 AttributeValueValidation rangeValidation = new AttributeValueValidation(
302 mProperty.getChildProperty());
303 for (String[][] value : values) {
304 if (rangeValidation.visitingValue(value) == false)
313 public Boolean visitingValue(SimulatorResourceModel[][][] value) {
317 private boolean checkRange(double value) {
318 if (AttributeProperty.Type.RANGE == mProperty.type()
319 && (value >= mProperty.min() && value <= mProperty.max())) {
326 private <T> boolean checkValueSet(T value) {
327 if (AttributeProperty.Type.VALUESET == mProperty.type()
328 && null != mProperty.valueSet()) {
329 for (AttributeValue allowedValue : mProperty.valueSet()) {
330 if (allowedValue.get().equals(value))