01: /*
02: * $Header: /cvsroot/jvalidate/jvalidate-framework/jvalidate/src/main/java/nl/knowlogy/validation/validators/BasePropertyValidator.java,v 1.7 2007/11/13 15:35:45 roberthofstra Exp $
03: * $Revision: 1.7 $
04: * $Date: 2007/11/13 15:35:45 $
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.PropertyValidation;
24:
25: import org.apache.log4j.Logger;
26:
27: /**
28: * <p>
29: * <tt>BasePropertyValidator</tt> is a base class for property validators.
30: * Subclass this class for building specific validators.
31: * </p>
32: *
33: *
34: *
35: * @author Robert
36: */
37: public abstract class BasePropertyValidator implements
38: PropertyValidation {
39:
40: private String propertyName;
41:
42: private String errorCode;
43:
44: protected static final Logger logger = Logger
45: .getLogger(BasePropertyValidator.class);
46:
47: public BasePropertyValidator(String propertyName) {
48: this .propertyName = propertyName;
49: }
50:
51: /*
52: * (non-Javadoc)
53: *
54: * @see nl.knowlogy.validation.metadata.PropertyValidation#getPropertyName()
55: */
56: public String getPropertyName() {
57:
58: return propertyName;
59: }
60:
61: public void setPropertyName(String value) {
62: propertyName = value;
63: }
64:
65: /**
66: * Returns a specific errorcode, if setted, otherwise the defaulterrorcode.
67: *
68: * Each subclass must specify the defaultErrorCode.
69: *
70: * @return a specific errorcode, if setted, otherwise the defaulterrorcode.
71: */
72: public String getErrorCode() {
73: if (errorCode != null) {
74: return errorCode;
75: } else {
76: return getDefaultErrorCode();
77: }
78: }
79:
80: public void setErrorCode(String value) {
81: if (value != null) {
82: errorCode = value;
83: }
84: }
85:
86: public abstract String getDefaultErrorCode();
87:
88: public String toString() {
89: return " propertyName = [" + propertyName + "],errorCode = ["
90: + errorCode + "], defaultErrorCode = ["
91: + getDefaultErrorCode() + "]";
92: }
93: }
|