01: package nl.knowlogy.validation.validators;
02:
03: import nl.knowlogy.validation.ErrorCodes;
04: import nl.knowlogy.validation.MessageType;
05: import nl.knowlogy.validation.Messages;
06:
07: public class DoubleMaximumValidator extends NumberValidator {
08:
09: public Double maximum;
10:
11: public DoubleMaximumValidator(String propertyName, Double maximum) {
12: super (propertyName);
13: this .maximum = maximum;
14: }
15:
16: private Object[] createMessageArg(double actualValue) {
17: Object[] messageArg = new Object[2];
18: messageArg[0] = new Double(maximum.doubleValue());
19: messageArg[1] = new Double(actualValue);
20: return messageArg;
21: }
22:
23: protected void doValidateNumber(Object toValidate, Number value,
24: Messages messages) {
25: if (value.doubleValue() > maximum.doubleValue()) {
26: Object[] messageArgs = createMessageArg(value.doubleValue());
27: messages.addPropertyMessage(MessageType.ERROR, toValidate,
28: getPropertyName(), getErrorCode(), messageArgs,
29: null);
30: }
31:
32: }
33:
34: public String getDefaultErrorCode() {
35: return ErrorCodes.INVALID_MAX_SIZE;
36: }
37:
38: }
|