001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: PropertyValidationRule.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.site;
009:
010: import java.util.Collection;
011:
012: /**
013: * This abstract class extends the <code>AbstractValidationRule</code> class
014: * to provide common functionality that is useful for all bean property
015: * validation rules.
016: *
017: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
018: * @version $Revision: 3634 $
019: * @since 1.0
020: */
021: public abstract class PropertyValidationRule extends
022: AbstractValidationRule {
023: private String mPropertyName = null;
024: private String mSubject = null;
025: private Collection<String> mLoadingErrors = null;
026: private ConstrainedProperty mConstrainedProperty = null;
027:
028: /**
029: * Instantiates a new <code>PropertyValidationRule</code> instance.
030: *
031: * @param propertyName the name of the property
032: * @since 1.0
033: */
034: protected PropertyValidationRule(String propertyName) {
035: setPropertyName(propertyName);
036: }
037:
038: /**
039: * Set the name of the property.
040: *
041: * @param propertyName the name of the property
042: * @see #getPropertyName
043: * @since 1.0
044: */
045: public <T extends PropertyValidationRule> T setPropertyName(
046: String propertyName) {
047: mPropertyName = propertyName;
048: if (null == mSubject) {
049: mSubject = propertyName;
050: }
051:
052: return (T) this ;
053: }
054:
055: /**
056: * Retrieves the name of the property.
057: *
058: * @return the name of the property
059: * @see #setPropertyName
060: * @since 1.0
061: */
062: public String getPropertyName() {
063: return mPropertyName;
064: }
065:
066: /**
067: * Set the subject that the property refers to.
068: *
069: * @param subjectName the subject name of the property
070: * @see #getSubject
071: * @since 1.0
072: */
073: public PropertyValidationRule setSubject(String subjectName) {
074: if (null == subjectName) {
075: mSubject = mPropertyName;
076: } else {
077: mSubject = subjectName;
078: }
079:
080: return this ;
081: }
082:
083: /**
084: * Retrieves the subject name of the property.
085: *
086: * @return the subject name of the property
087: * @see #setSubject
088: * @since 1.0
089: */
090: public String getSubject() {
091: return mSubject;
092: }
093:
094: /**
095: * Set the list of error messages that occurred during the loading of
096: * content data.
097: *
098: * @param errors the collection of errors messages
099: * @since 1.0
100: */
101: protected void setLoadingErrors(Collection<String> errors) {
102: mLoadingErrors = errors;
103: }
104:
105: /**
106: * Retrieves the list of error messages that occurred during the loading
107: * of content data.
108: *
109: * @return the collection of errors messages; or
110: * <p><code>null</code> if the data was <code>null</code> or the property
111: * didn't exist
112: * @since 1.0
113: */
114: public Collection<String> getLoadingErrors() {
115: return mLoadingErrors;
116: }
117:
118: void setConstrainedProperty(ConstrainedProperty constrainedProperty) {
119: mConstrainedProperty = constrainedProperty;
120: }
121:
122: ConstrainedProperty getConstrainedProperty() {
123: return mConstrainedProperty;
124: }
125: }
|