001: /*
002: * $Header: /cvsroot/jvalidate/jvalidate-framework/jvalidate/src/main/java/nl/knowlogy/validation/validators/MinSizeValidator.java,v 1.8 2007/10/31 16:34:58 roberthofstra Exp $
003: * $Revision: 1.8 $
004: * $Date: 2007/10/31 16:34:58 $
005: *
006: *
007: * Created on Oct 6, 2004
008: *
009: * All right reserved(c) 2004, Knowlogy
010: *
011: * Copyright 2004 - 2005 Knowlogy, the Netherlands. All rights reserved.
012: * All Knowlogy brand and product names are trademarks or registered trademarks
013: * of Knowlogy in the Netherlands and other countries.
014: *
015: * No part of this publication may be reproduced, transmitted, stored in a retrieval system,
016: * or translated into any human or computer language, in any form, or by any means, electronic,
017: * mechanical, magnetic, optical, chemical, manual, or otherwise,
018: * without the prior written permission of the copyright owner, Knowlogy.
019: *
020: */
021: package nl.knowlogy.validation.validators;
022:
023: import nl.knowlogy.validation.ErrorCodes;
024: import nl.knowlogy.validation.MessageType;
025: import nl.knowlogy.validation.Messages;
026: import nl.knowlogy.validation.PropertyMetadataSuplier;
027: import nl.knowlogy.validation.metadata.PropertyMetadata;
028:
029: /**
030: *
031: * @author Robert
032: */
033: public class MinSizeValidator extends NumberValidator implements
034: PropertyMetadataSuplier {
035:
036: private Long minSize;
037:
038: /**
039: *
040: */
041: public MinSizeValidator(String propertyName, Long minValue) {
042: super (propertyName);
043: this .minSize = minValue;
044: }
045:
046: public MinSizeValidator(String propertyName, Long minValue,
047: String errorCode) {
048: this (propertyName, minValue);
049: setErrorCode(errorCode);
050: }
051:
052: /*
053: * (non-Javadoc)
054: *
055: * @see nl.knowlogy.validation.validators.BasePropertyValidator#getDefaultErrorCode()
056: */
057: public String getDefaultErrorCode() {
058: return ErrorCodes.INVALID_MIN_SIZE;
059: }
060:
061: /*
062: * (non-Javadoc)
063: *
064: * @see nl.knowlogy.validation.metadata.PropertyValidation#doValidatePropertyValue(java.lang.Object,
065: * nl.knowlogy.validation.errors.Errors)
066: */
067: // public void doValidatePropertyValue(Object toValidate, Object propertyValue, Messages errors) {
068: // Integer integerValue = (Integer) propertyValue;
069: //
070: // if ((integerValue != null) && (integerValue.longValue() < minSize.longValue())) {
071: // Object[] errorArg = new Object[2];
072: // errorArg[0] = new Long(minSize.longValue());
073: // errorArg[1] = new Long(minSize.longValue());
074: //
075: // errors.addPropertyMessage(MessageType.ERROR, toValidate, getPropertyName(), getErrorCode(), errorArg,
076: // null);
077: //
078: // }
079: // }
080: protected void doValidateNumber(Object toValidate, Number value,
081: Messages messages) {
082:
083: if ((value.longValue() < minSize.longValue())) {
084: Object[] errorArg = new Object[2];
085: errorArg[0] = new Long(minSize.longValue());
086: errorArg[1] = new Long(minSize.longValue());
087:
088: messages.addPropertyMessage(MessageType.ERROR, toValidate,
089: getPropertyName(), getErrorCode(), errorArg, null);
090:
091: }
092:
093: }
094:
095: public void supplyMetaData(PropertyMetadata propertyMetadata) {
096:
097: propertyMetadata.setMinSize(minSize);
098: }
099:
100: public String toString() {
101: return "MinSizeValidator, minSize=[" + minSize + "]"
102: + super.toString();
103: }
104:
105: }
|