01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: CmfPropertyValidationRule.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.cmf.validation;
09:
10: import com.uwyn.rife.site.Constrained;
11: import com.uwyn.rife.site.ConstrainedProperty;
12: import com.uwyn.rife.site.ConstrainedUtils;
13: import com.uwyn.rife.site.PropertyValidationRule;
14:
15: /**
16: * This abstract class extends the <code>PropertyValidationRule</code> class
17: * to provide common functionality that is useful for all concrete CMF
18: * validation rules.
19: *
20: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
21: * @version $Revision: 3634 $
22: * @since 1.0
23: */
24: public abstract class CmfPropertyValidationRule extends
25: PropertyValidationRule {
26: private boolean mFragment = false;
27:
28: /**
29: * Instantiates a new <code>CmfPropertyValidationRule</code> instance.
30: *
31: * @param propertyName the name of the property
32: * @param fragment <code>true</code> if the property is a fragment; or
33: * <p><code>false</code> if it's a complete document
34: * @since 1.0
35: */
36: public CmfPropertyValidationRule(String propertyName,
37: boolean fragment) {
38: super (propertyName);
39:
40: mFragment = fragment;
41: }
42:
43: /**
44: * Indicates whether the property that is validated is a fragment.
45: *
46: * @return <code>true</code> if the property is a fragment; or
47: * <p><code>false</code> if it's a complete document
48: * @since 1.0
49: */
50: public boolean getFragment() {
51: return mFragment;
52: }
53:
54: /**
55: * Sets the cached loaded data to a {@link com.uwyn.rife.site.ConstrainedProperty
56: * ConstrainedProperty} if the content data has been successfully loaded during
57: * validation. This prevents the data of having to be loaded again
58: * elsewhere.
59: * <p>If the validation rule's bean is not {@link
60: * com.uwyn.rife.site.Constrained Constrained} or if it doesn't contain a
61: * corresponding <code>ConstrainedProperty</code>, this method does nothing.
62: *
63: * @param data the loaded data
64: * @see com.uwyn.rife.site.ConstrainedProperty#setCachedLoadedData(Object)
65: * @since 1.0
66: */
67: protected void setCachedLoadedData(Object data) {
68: // if the bean is constrained and a CmfProperty exists that corresponds to
69: // the property name that's being checked, store the loaded data
70: // and prevent it from loading twice
71: Constrained constrained = ConstrainedUtils
72: .makeConstrainedInstance(getBean());
73: if (constrained != null) {
74: ConstrainedProperty property = constrained
75: .getConstrainedProperty(getPropertyName());
76: property.setCachedLoadedData(data);
77: }
78: }
79: }
|