01: /*
02: * $Header: /cvsroot/jvalidate/jvalidate-framework/jvalidate/src/main/java/nl/knowlogy/validation/validators/IsRequiredValidator.java,v 1.7 2007/06/20 16:24:57 roberthofstra Exp $
03: * $Revision: 1.7 $
04: * $Date: 2007/06/20 16:24:57 $
05: *
06: *
07: * Created on Oct 6, 2004
08: *
09: * All right reserved(c) 2004, Knowlogy
10: *
11: * Copyright 2004 - 2005 Knowlogy, the Netherlands. All rights reserved.
12: * All Knowlogy brand and product names are trademarks or registered trademarks
13: * of Knowlogy in the Netherlands and other countries.
14: *
15: * No part of this publication may be reproduced, transmitted, stored in a retrieval system,
16: * or translated into any human or computer language, in any form, or by any means, electronic,
17: * mechanical, magnetic, optical, chemical, manual, or otherwise,
18: * without the prior written permission of the copyright owner, Knowlogy.
19: *
20: */
21: package nl.knowlogy.validation.validators;
22:
23: import nl.knowlogy.validation.ErrorCodes;
24: import nl.knowlogy.validation.MessageType;
25: import nl.knowlogy.validation.Messages;
26: import nl.knowlogy.validation.PropertyMetadataSuplier;
27: import nl.knowlogy.validation.metadata.PropertyMetadata;
28:
29: /**
30: *
31: * @author Robert
32: */
33: public class IsRequiredValidator extends BasePropertyValidator
34: implements PropertyMetadataSuplier {
35:
36: /**
37: *
38: */
39: public IsRequiredValidator(String propertyName) {
40: super (propertyName);
41: }
42:
43: public IsRequiredValidator(String propertyName, String errorCode) {
44: this (propertyName);
45: setErrorCode(errorCode);
46: }
47:
48: /*
49: * (non-Javadoc)
50: *
51: * @see nl.knowlogy.validation.validators.BasePropertyValidator#getDefaultErrorCode()
52: */
53: public String getDefaultErrorCode() {
54: return ErrorCodes.ISREQUIRED_VALUE;
55: }
56:
57: /*
58: * (non-Javadoc)
59: *
60: * @see nl.knowlogy.validation.metadata.PropertyValidation#doValidatePropertyValue(java.lang.Object,
61: * nl.knowlogy.validation.errors.Errors)
62: */
63: public void doValidatePropertyValue(Object toValidate,
64: Object propertyValue, Messages errors) {
65: if (propertyValue == null) {
66: errors.addPropertyMessage(MessageType.ERROR, toValidate,
67: getPropertyName(), getErrorCode());
68: }
69:
70: }
71:
72: public void supplyMetaData(PropertyMetadata propertyMetadata) {
73: propertyMetadata.setRequired(Boolean.TRUE);
74: }
75:
76: public String toString() {
77: return "IsRequiredValidator, " + super.toString();
78: }
79: }
|