You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2007/02/02 01:20:00 UTC

svn commit: r502410 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/ main/java/org/apache/tapestry/beaneditor/ main/java/org/apache/tapestry/corelib/base/ main/java/org/apache/tapestry/corelib/components/ main/java/org/a...

Author: hlship
Date: Thu Feb  1 16:19:58 2007
New Revision: 502410

URL: http://svn.apache.org/viewvc?view=rev&rev=502410
Log:
Change Binding to extend interface AnnotationProvider and rework the "prop:" binding prefix to allow access to the target property annotations.
Reorganize how the BeanEditForm gains access to default FieldValidators so that the main form components (TextField, Select, etc.) can leverage the same services for their default "translate" bindings.

Added:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/AnnotationProvider.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/PropBindingAnnotationProvider.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorDefaultSourceImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/FieldValidatorDefaultSource.java
Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Binding.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResources.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/PropertyConduit.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/PasswordField.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Select.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/BeanEditorModelImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/PrimitiveFieldConstraintGenerator.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGenerator.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/AbstractBinding.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/BasePropBinding.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/PropBindingFactory.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ValidationConstraintGeneratorImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ClassTransformation.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ValidationConstraintGenerator.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
    tapestry/tapestry5/tapestry-core/trunk/src/site/apt/index.apt
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/data/IncidentData.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGeneratorTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/PropBindingFactoryTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/TargetBean.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanEditorModelSourceImplTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/ValidForm.html

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/AnnotationProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/AnnotationProvider.java?view=auto&rev=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/AnnotationProvider.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/AnnotationProvider.java Thu Feb  1 16:19:58 2007
@@ -0,0 +1,34 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * A source of annotations. This interface is used to mask where the annotations come from (for
+ * example, from a Method, a Class, or some other source).
+ */
+public interface AnnotationProvider
+{
+    /**
+     * Searches for the specified annotation, returning the matching annotation instance.
+     * 
+     * @param <T>
+     * @param annotationClass
+     *            used to select the annotation to return«
+     * @return the annotation, or null if not found
+     */
+    <T extends Annotation> T getAnnotation(Class<T> annotationClass);
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Binding.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Binding.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Binding.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Binding.java Thu Feb  1 16:19:58 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -20,8 +20,12 @@
  * can represent any kind of value that can be obtained from the parent component, but is often a
  * JavaBean property that can be read and updated. Different implementations of Binding as used to
  * access different kinds of resources of the container.
+ * <p>
+ * A binding ultimately must provide access to the underlying annotations. In most cases, there are
+ * no annotations, but bindings that ultimate invoke methods or read and update fields must provide
+ * access to those annotations.
  */
-public interface Binding
+public interface Binding extends AnnotationProvider
 {
     /**
      * Reads the current value of the property (or other resource). When reading properties of

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResources.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResources.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResources.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResources.java Thu Feb  1 16:19:58 2007
@@ -63,6 +63,8 @@
     /**
      * Returns an embedded component, given the component's id.
      * 
+     * @param embeddedId
+     *            selects the embedded component (case is ignored)
      * @throws IllegalArgumentException
      *             if this component does not contain a component with the given id
      */
@@ -77,6 +79,7 @@
      * attribute/value pair into the current element of the markup writer.
      * 
      * @param writer
+     *            to which {@link MarkupWriter#attributes(Object[]) attributes} will be written
      */
     void renderInformalParameters(MarkupWriter writer);
 
@@ -92,7 +95,17 @@
      * 
      * @see Binding#getBindingType()
      * @param parameterName
+     *            used to select the parameter (case is ignored)
      * @return the type of the bound parameter, or null if the parameter is not bound
      */
     Class getBoundType(String parameterName);
+
+    /**
+     * Returns an annotation provider, used to obtain annotations related to the parameter.
+     * 
+     * @param parameterName
+     *            used to select the parameter (case is ignored)
+     * @return the annotation provider, or null if the parameter is not bound
+     */
+    AnnotationProvider getAnnotationProvider(String parameterName);
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/PropertyConduit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/PropertyConduit.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/PropertyConduit.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/beaneditor/PropertyConduit.java Thu Feb  1 16:19:58 2007
@@ -14,12 +14,13 @@
 
 package org.apache.tapestry.beaneditor;
 
-import java.lang.annotation.Annotation;
+import org.apache.tapestry.AnnotationProvider;
 
 /**
- * Used to read or update the value associated with a property.
+ * Used to read or update the value associated with a property. A PropertyConduit provides access to
+ * the annotations on the underlying getter and/or setter methods.
  */
-public interface PropertyConduit
+public interface PropertyConduit extends AnnotationProvider
 {
     /**
      * Reads the property from the instance.
@@ -28,7 +29,7 @@
      *            object containing the property
      * @return the current value of the property
      */
-    Object read(Object instance);
+    Object get(Object instance);
 
     /**
      * Changes the current value of the property.
@@ -38,16 +39,5 @@
      * @param value
      *            to change the property to
      */
-    void write(Object instance, Object value);
-
-    /**
-     * Returns an annotation if present on the property. The annotation is checked for on both the
-     * getter method and the setter method.
-     * 
-     * @param <T>
-     * @param annotationClass
-     *            the type of annotation to return
-     * @return the annotation if present, or null if not available
-     */
-    <T extends Annotation> T getAnnotation(Class<T> annotationClass);
+    void set(Object instance, Object value);
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java Thu Feb  1 16:19:58 2007
@@ -30,6 +30,7 @@
 import org.apache.tapestry.annotations.Parameter;
 import org.apache.tapestry.internal.services.FormParameterLookup;
 import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.services.FieldValidatorDefaultSource;
 import org.apache.tapestry.services.TranslatorDefaultSource;
 import org.apache.tapestry.services.ValidationMessagesSource;
 
@@ -58,12 +59,18 @@
     @Inject("infrastructure:TranslatorDefaultSource")
     private TranslatorDefaultSource _translatorDefaultSource;
 
+    @Inject("infrastructure:FieldValidatorDefaultSource")
+    private FieldValidatorDefaultSource _fieldValidatorDefaultSource;
+
     @Inject
     private ComponentResources _resources;
 
     @Inject
     private Locale _locale;
 
+    /**
+     * Computes a default value for the "translate" parameter using {@link TranslatorDefaultSource}.
+     */
     final Translator defaultTranslate()
     {
         // Because the value parameter is a principal parameter, we know that it will be bound (even
@@ -75,6 +82,26 @@
             return null;
 
         return _translatorDefaultSource.find(type);
+    }
+
+    /**
+     * Computes a default value for the "validate" parameter using
+     * {@link FieldValidatorDefaultSource}.
+     */
+    final FieldValidator defaultValidate()
+    {
+        Class type = _resources.getBoundType("value");
+
+        if (type == null)
+            return null;
+
+        return _fieldValidatorDefaultSource.createDefaultValidator(
+                this,
+                _resources.getId(),
+                _resources.getContainerMessages(),
+                _locale,
+                type,
+                _resources.getAnnotationProvider("value"));
     }
 
     /**

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java Thu Feb  1 16:19:58 2007
@@ -14,9 +14,6 @@
 
 package org.apache.tapestry.corelib.components;
 
-import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
-
-import java.util.List;
 import java.util.Locale;
 
 import org.apache.tapestry.Block;
@@ -34,12 +31,10 @@
 import org.apache.tapestry.annotations.Parameter;
 import org.apache.tapestry.beaneditor.BeanEditorModel;
 import org.apache.tapestry.beaneditor.PropertyEditModel;
-import org.apache.tapestry.internal.services.CompositeFieldValidator;
 import org.apache.tapestry.ioc.Messages;
 import org.apache.tapestry.services.BeanEditorModelSource;
-import org.apache.tapestry.services.FieldValidatorSource;
+import org.apache.tapestry.services.FieldValidatorDefaultSource;
 import org.apache.tapestry.services.TranslatorDefaultSource;
-import org.apache.tapestry.services.ValidationConstraintGenerator;
 
 /**
  * A component that creates an entire form editting the properties of a particular bean. Inspired by
@@ -71,11 +66,8 @@
     @Inject("infrastructure:TranslatorDefaultSource")
     private TranslatorDefaultSource _translatorDefaultSource;
 
-    @Inject("infrastructure:FieldValidatorSource")
-    private FieldValidatorSource _fieldValidatorSource;
-
-    @Inject("infrastructure:ValidationConstraintGenerator")
-    private ValidationConstraintGenerator _validationConstraintGenerator;
+    @Inject("infrastructure:FieldValidatorDefaultSource")
+    private FieldValidatorDefaultSource _fieldValidatorDefaultSource;
 
     @Inject
     private Block _text;
@@ -193,32 +185,13 @@
 
     public FieldValidator getValidateForProperty()
     {
-        List<FieldValidator> validators = newList();
-
-        // Use the property name, not the field id, when locating
-        // validation message overrides.
-        Messages overrideMessages = _resources.getContainerMessages();
-
-        for (String constraint : _validationConstraintGenerator
-                .buildConstraints(_propertyEditModel))
-        {
-            int equalsx = constraint.indexOf('=');
-
-            String validatorType = equalsx > 0 ? constraint.substring(0, equalsx) : constraint;
-            String constraintValue = equalsx > 0 ? constraint.substring(equalsx + 1) : null;
-
-            FieldValidator validator = _fieldValidatorSource.createValidator(
-                    _fieldForProperty,
-                    validatorType,
-                    constraintValue,
-                    _propertyName,
-                    overrideMessages,
-                    _locale);
-
-            validators.add(validator);
-        }
-
-        return new CompositeFieldValidator(validators);
+        return _fieldValidatorDefaultSource.createDefaultValidator(
+                _fieldForProperty,
+                _propertyName,
+                _resources.getContainerMessages(),
+                _locale,
+                _propertyEditModel.getPropertyType(),
+                _propertyEditModel.getConduit());
     }
 
     public PropertyEditModel getPropertyEditModel()
@@ -238,12 +211,12 @@
 
     public Object getValueForProperty()
     {
-        return _propertyEditModel.getConduit().read(_object);
+        return _propertyEditModel.getConduit().get(_object);
     }
 
     public void setValueForProperty(Object value)
     {
-        _propertyEditModel.getConduit().write(_object, value);
+        _propertyEditModel.getConduit().set(_object, value);
     }
 
     /** Provide a value encoder for an enum type. */

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/PasswordField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/PasswordField.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/PasswordField.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/PasswordField.java Thu Feb  1 16:19:58 2007
@@ -14,8 +14,6 @@
 
 package org.apache.tapestry.corelib.components;
 
-import java.awt.TextField;
-
 import org.apache.tapestry.MarkupWriter;
 import org.apache.tapestry.corelib.base.AbstractTextField;
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Select.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Select.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Select.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Select.java Thu Feb  1 16:19:58 2007
@@ -15,6 +15,7 @@
 package org.apache.tapestry.corelib.components;
 
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import org.apache.tapestry.Binding;
@@ -36,6 +37,7 @@
 import org.apache.tapestry.annotations.Parameter;
 import org.apache.tapestry.corelib.base.AbstractField;
 import org.apache.tapestry.internal.services.FormParameterLookup;
+import org.apache.tapestry.services.FieldValidatorDefaultSource;
 
 /**
  * Select an item from a list of values, using an [X]HTML &lt;select&gt; element on the client side.
@@ -76,15 +78,41 @@
     @SuppressWarnings("unchecked")
     private FieldValidator<Object> _validate = NOOP_VALIDATOR;
 
+    @Inject("infrastructure:FieldValidatorDefaultSource")
+    private FieldValidatorDefaultSource _fieldValidatorDefaultSource;
+
     @Environmental
     private ValidationTracker _tracker;
 
     @Inject
     private ComponentResources _resources;
 
+    @Inject
+    private Locale _locale;
+
     Binding defaultValue()
     {
         return createDefaultParameterBinding("value");
+    }
+
+    /**
+     * Computes a default value for the "validate" parameter using
+     * {@link FieldValidatorDefaultSource}.
+     */
+    FieldValidator defaultValidate()
+    {
+        Class type = _resources.getBoundType("value");
+
+        if (type == null)
+            return null;
+
+        return _fieldValidatorDefaultSource.createDefaultValidator(
+                this,
+                _resources.getId(),
+                _resources.getContainerMessages(),
+                _locale,
+                type,
+                _resources.getAnnotationProvider("value"));
     }
 
     @SuppressWarnings("unchecked")

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/BeanEditorModelImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/BeanEditorModelImpl.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/BeanEditorModelImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/BeanEditorModelImpl.java Thu Feb  1 16:19:58 2007
@@ -99,13 +99,13 @@
 
         return new PropertyConduit()
         {
-            public Object read(Object instance)
+            public Object get(Object instance)
             {
                 return adapter.get(instance);
             }
 
             @SuppressWarnings("unchecked")
-            public void write(Object instance, Object value)
+            public void set(Object instance, Object value)
             {
                 // TODO: Wrap this to provide a more useful error if the coercion
                 // fails.

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/PrimitiveFieldConstraintGenerator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/PrimitiveFieldConstraintGenerator.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/PrimitiveFieldConstraintGenerator.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/PrimitiveFieldConstraintGenerator.java Thu Feb  1 16:19:58 2007
@@ -17,7 +17,7 @@
 import java.util.Arrays;
 import java.util.List;
 
-import org.apache.tapestry.beaneditor.PropertyEditModel;
+import org.apache.tapestry.AnnotationProvider;
 import org.apache.tapestry.services.ValidationConstraintGenerator;
 
 /**
@@ -28,11 +28,9 @@
 {
     private final List<String> REQUIRED = Arrays.asList("required");
 
-    public List<String> buildConstraints(PropertyEditModel propertyModel)
+    public List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider)
     {
-        Class type = propertyModel.getPropertyType();
-
-        return type.isPrimitive() ? REQUIRED : null;
+        return propertyType.isPrimitive() ? REQUIRED : null;
     }
 
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGenerator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGenerator.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGenerator.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGenerator.java Thu Feb  1 16:19:58 2007
@@ -17,7 +17,7 @@
 import java.util.Arrays;
 import java.util.List;
 
-import org.apache.tapestry.beaneditor.PropertyEditModel;
+import org.apache.tapestry.AnnotationProvider;
 import org.apache.tapestry.beaneditor.Validate;
 import org.apache.tapestry.services.ValidationConstraintGenerator;
 
@@ -27,9 +27,9 @@
 public class ValidateAnnotationConstraintGenerator implements ValidationConstraintGenerator
 {
 
-    public List<String> buildConstraints(PropertyEditModel propertyModel)
+    public List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider)
     {
-        Validate annotation = propertyModel.getConduit().getAnnotation(Validate.class);
+        Validate annotation = annotationProvider.getAnnotation(Validate.class);
 
         if (annotation == null)
             return null;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/AbstractBinding.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/AbstractBinding.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/AbstractBinding.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/AbstractBinding.java Thu Feb  1 16:19:58 2007
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry.internal.bindings;
 
+import java.lang.annotation.Annotation;
+
 import org.apache.tapestry.Binding;
 import org.apache.tapestry.ioc.BaseLocatable;
 import org.apache.tapestry.ioc.Location;
@@ -61,4 +63,14 @@
     {
         return get().getClass();
     }
+
+    /**
+     * Always returns null. Bindings that provide access to a method or field will override this
+     * method to return the appropriate annotation.
+     */
+    public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
+    {
+        return null;
+    }
+
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/BasePropBinding.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/BasePropBinding.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/BasePropBinding.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/BasePropBinding.java Thu Feb  1 16:19:58 2007
@@ -14,6 +14,9 @@
 
 package org.apache.tapestry.internal.bindings;
 
+import java.lang.annotation.Annotation;
+
+import org.apache.tapestry.AnnotationProvider;
 import org.apache.tapestry.ioc.Location;
 import org.apache.tapestry.ioc.internal.util.TapestryException;
 
@@ -28,12 +31,16 @@
 
     private final Class _bindingType;
 
-    public BasePropBinding(Class bindingType, String toString, Location location)
+    private final AnnotationProvider _annotationProvider;
+
+    public BasePropBinding(Class bindingType, String toString,
+            AnnotationProvider annotationProvider, Location location)
     {
         super(location);
 
         _bindingType = bindingType;
         _toString = toString;
+        _annotationProvider = annotationProvider;
     }
 
     /**
@@ -62,5 +69,11 @@
     public Class getBindingType()
     {
         return _bindingType;
+    }
+
+    @Override
+    public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
+    {
+        return _annotationProvider.getAnnotation(annotationClass);
     }
 }

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/PropBindingAnnotationProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/PropBindingAnnotationProvider.java?view=auto&rev=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/PropBindingAnnotationProvider.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/PropBindingAnnotationProvider.java Thu Feb  1 16:19:58 2007
@@ -0,0 +1,43 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.bindings;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import org.apache.tapestry.AnnotationProvider;
+
+public class PropBindingAnnotationProvider implements AnnotationProvider
+{
+    private final Method _readMethod;
+
+    private final Method _writeMethod;
+
+    public PropBindingAnnotationProvider(final Method readMethod, final Method writeMethod)
+    {
+        _readMethod = readMethod;
+        _writeMethod = writeMethod;
+    }
+
+    public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
+    {
+        T result = _readMethod == null ? null : _readMethod.getAnnotation(annotationClass);
+
+        if (result == null && _writeMethod != null)
+            result = _writeMethod.getAnnotation(annotationClass);
+
+        return result;
+    }
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/PropBindingFactory.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/PropBindingFactory.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/PropBindingFactory.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/PropBindingFactory.java Thu Feb  1 16:19:58 2007
@@ -21,8 +21,10 @@
 import java.lang.reflect.Modifier;
 import java.util.Map;
 
+import org.apache.tapestry.AnnotationProvider;
 import org.apache.tapestry.Binding;
 import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.corelib.components.BeanEditForm;
 import org.apache.tapestry.events.InvalidationListener;
 import org.apache.tapestry.ioc.Location;
 import org.apache.tapestry.ioc.internal.util.TapestryException;
@@ -33,6 +35,7 @@
 import org.apache.tapestry.ioc.services.PropertyAccess;
 import org.apache.tapestry.ioc.services.PropertyAdapter;
 import org.apache.tapestry.ioc.util.BodyBuilder;
+import org.apache.tapestry.services.BeanEditorModelSource;
 import org.apache.tapestry.services.BindingFactory;
 
 /**
@@ -59,6 +62,10 @@
  * <em>actual type</em>. This means that, for example, if a property is type Collection, you may
  * <em>not</em> reference the listIterator() method, even if the actual value returned is of type
  * List. This is only really bites you when a method's return type is Object.
+ * <p>
+ * TODO: Split most of this out into a new service that generates a PropertyConduit. This will allow
+ * the {@link BeanEditForm}/{@link BeanEditorModelSource} make use of the same expressions that
+ * are supported here.
  */
 public class PropBindingFactory implements BindingFactory, InvalidationListener
 {
@@ -77,16 +84,25 @@
 
         private final Constructor _constructor;
 
-        BindingConstructor(Class propertyType, Constructor constructor)
+        private final AnnotationProvider _annotationProvider;
+
+        BindingConstructor(Class propertyType, AnnotationProvider annotationProvider,
+                Constructor constructor)
         {
             _propertyType = propertyType;
             _constructor = constructor;
+            _annotationProvider = annotationProvider;
         }
 
         Binding newBindingInstance(Object target, String toString, Location location)
                 throws Exception
         {
-            return (Binding) _constructor.newInstance(target, _propertyType, toString, location);
+            return (Binding) _constructor.newInstance(
+                    target,
+                    _propertyType,
+                    toString,
+                    _annotationProvider,
+                    location);
         }
     }
 
@@ -212,7 +228,8 @@
         // The fabricated class is only going to have the one constructor. This is the easiest
         // way to access it.
 
-        return new BindingConstructor(bindingType, bindingClass.getConstructors()[0]);
+        return new BindingConstructor(bindingType, new PropBindingAnnotationProvider(readMethod,
+                writeMethod), bindingClass.getConstructors()[0]);
     }
 
     private Class extendWithMethodTerm(Class inClass, String term, String propertyExpression,
@@ -224,7 +241,6 @@
         builder.append(term);
 
         return method.getReturnType();
-
     }
 
     private Method validateMethodName(Class inClass, String term, String propertyExpression)
@@ -300,11 +316,13 @@
 
         classFab.addField("_target", targetClass);
 
-        classFab.addConstructor(
-                new Class[]
-                { targetClass, Class.class, String.class, Location.class },
-                null,
-                "{ super($2, $3, $4); _target = $1; }");
+        classFab
+                .addConstructor(
+                        new Class[]
+                        { targetClass, Class.class, String.class, AnnotationProvider.class,
+                                Location.class },
+                        null,
+                        "{ super($2, $3, $4, $5); _target = $1; }");
 
         if (readMethod != null)
         {

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorDefaultSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorDefaultSourceImpl.java?view=auto&rev=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorDefaultSourceImpl.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorDefaultSourceImpl.java Thu Feb  1 16:19:58 2007
@@ -0,0 +1,72 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.services;
+
+import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
+
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.tapestry.AnnotationProvider;
+import org.apache.tapestry.Field;
+import org.apache.tapestry.FieldValidator;
+import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.services.FieldValidatorDefaultSource;
+import org.apache.tapestry.services.FieldValidatorSource;
+import org.apache.tapestry.services.ValidationConstraintGenerator;
+
+public class FieldValidatorDefaultSourceImpl implements FieldValidatorDefaultSource
+{
+    private final ValidationConstraintGenerator _validationConstraintGenerator;
+
+    private final FieldValidatorSource _fieldValidatorSource;
+
+    public FieldValidatorDefaultSourceImpl(
+            ValidationConstraintGenerator validationConstraintGenerator,
+            FieldValidatorSource fieldValidatorSource)
+    {
+        _validationConstraintGenerator = validationConstraintGenerator;
+        _fieldValidatorSource = fieldValidatorSource;
+    }
+
+    public FieldValidator createDefaultValidator(Field field, String overrideId,
+            Messages overrideMessages, Locale locale, Class propertyType,
+            AnnotationProvider propertyAnnotations)
+    {
+        List<FieldValidator> validators = newList();
+
+        for (String constraint : _validationConstraintGenerator.buildConstraints(
+                propertyType,
+                propertyAnnotations))
+        {
+            int equalsx = constraint.indexOf('=');
+
+            String validatorType = equalsx > 0 ? constraint.substring(0, equalsx) : constraint;
+            String constraintValue = equalsx > 0 ? constraint.substring(equalsx + 1) : null;
+
+            FieldValidator validator = _fieldValidatorSource.createValidator(
+                    field,
+                    validatorType,
+                    constraintValue,
+                    overrideId,
+                    overrideMessages,
+                    locale);
+
+            validators.add(validator);
+        }
+
+        return new CompositeFieldValidator(validators);
+    }
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ValidationConstraintGeneratorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ValidationConstraintGeneratorImpl.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ValidationConstraintGeneratorImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ValidationConstraintGeneratorImpl.java Thu Feb  1 16:19:58 2007
@@ -14,9 +14,11 @@
 
 package org.apache.tapestry.internal.services;
 
+import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
+
 import java.util.List;
 
-import org.apache.tapestry.beaneditor.PropertyEditModel;
+import org.apache.tapestry.AnnotationProvider;
 import org.apache.tapestry.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry.services.ValidationConstraintGenerator;
 
@@ -29,13 +31,16 @@
         _configuration = configuration;
     }
 
-    public List<String> buildConstraints(PropertyEditModel propertyModel)
+    public List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider)
     {
+        notNull(propertyType, "propertyType");
+        notNull(annotationProvider, "annotationProvider");
+
         List<String> result = CollectionFactory.newList();
 
         for (ValidationConstraintGenerator g : _configuration)
         {
-            List<String> constraints = g.buildConstraints(propertyModel);
+            List<String> constraints = g.buildConstraints(propertyType, annotationProvider);
 
             if (constraints != null)
                 result.addAll(constraints);

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java Thu Feb  1 16:19:58 2007
@@ -20,6 +20,7 @@
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
+import org.apache.tapestry.AnnotationProvider;
 import org.apache.tapestry.Binding;
 import org.apache.tapestry.Block;
 import org.apache.tapestry.ComponentEventHandler;
@@ -229,6 +230,11 @@
     private Binding getBinding(String parameterName)
     {
         return _bindings == null ? null : _bindings.get(parameterName.toLowerCase());
+    }
+
+    public AnnotationProvider getAnnotationProvider(String parameterName)
+    {
+        return getBinding(parameterName);
     }
 
     public Log getLog()

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ClassTransformation.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ClassTransformation.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ClassTransformation.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ClassTransformation.java Thu Feb  1 16:19:58 2007
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import org.apache.commons.logging.Log;
+import org.apache.tapestry.AnnotationProvider;
 
 /**
  * Contains class-specific information used when transforming an raw class into an executable class.
@@ -38,7 +39,7 @@
  * The majority of methods concern the <em>declared</em> members (field and methods) of a specific
  * class, rather than any fields or methods inherited from a base class.
  */
-public interface ClassTransformation
+public interface ClassTransformation extends AnnotationProvider
 {
     /**
      * Returns the fully qualified class name of the class being transformed.
@@ -95,17 +96,6 @@
      * @return the names of all matched fields, in ascending order
      */
     List<String> findFields(FieldFilter filter);
-
-    /**
-     * Finds an annotation for the class itself, including any annotations inherited from parent
-     * classes.
-     * 
-     * @param <T>
-     * @param annotationClass
-     *            the type of annotation to access
-     * @return the annotation if present, or null otherwise
-     */
-    <T extends Annotation> T getAnnotation(Class<T> annotationClass);
 
     /**
      * Finds an annotation on a declared instance field.

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/FieldValidatorDefaultSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/FieldValidatorDefaultSource.java?view=auto&rev=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/FieldValidatorDefaultSource.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/FieldValidatorDefaultSource.java Thu Feb  1 16:19:58 2007
@@ -0,0 +1,33 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.services;
+
+import java.util.Locale;
+
+import org.apache.tapestry.AnnotationProvider;
+import org.apache.tapestry.Field;
+import org.apache.tapestry.FieldValidator;
+import org.apache.tapestry.ioc.Messages;
+
+/**
+ * For a particular field, geenerates the default validation for the field, in accordance with a
+ * number of factors and contributions.
+ */
+public interface FieldValidatorDefaultSource
+{
+    FieldValidator createDefaultValidator(Field field, String overrideId,
+            Messages overrideMessages, Locale locale, Class propertyType,
+            AnnotationProvider propertyAnnotations);
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java Thu Feb  1 16:19:58 2007
@@ -80,6 +80,7 @@
 import org.apache.tapestry.internal.services.CookieSink;
 import org.apache.tapestry.internal.services.CookieSource;
 import org.apache.tapestry.internal.services.CookiesImpl;
+import org.apache.tapestry.internal.services.FieldValidatorDefaultSourceImpl;
 import org.apache.tapestry.internal.services.DefaultInjectionProvider;
 import org.apache.tapestry.internal.services.DefaultValidationDelegateCommand;
 import org.apache.tapestry.internal.services.EnvironmentImpl;
@@ -465,7 +466,8 @@
     }
 
     /**
-     * Contributes properties: componentNameExpander, markupWriterFactory, request
+     * Contributes pretty much everything in the tapestry module, plus PropertyAccess and
+     * TypeCoercer.
      */
     public static void contributeInfrastructure(
             Configuration<InfrastructureContribution> configuration, ServiceLocator locator,
@@ -480,26 +482,27 @@
                 ApplicationGlobals.class,
                 ApplicationStateManager.class,
                 ApplicationStatePersistenceStrategySource.class,
+                AssetSource.class,
                 BeanEditorModelSource.class,
-                RequestGlobals.class,
-                MarkupWriterFactory.class,
-                PersistentFieldManager.class,
-                Environment.class,
-                ComponentSource.class,
                 BindingSource.class,
-                ComponentMessagesSource.class,
+                ClasspathAssetAliasManager.class,
                 ComponentClassResolver.class,
                 ComponentEventResultProcessor.class,
-                AssetSource.class,
-                ResourceDigestGenerator.class,
-                ClasspathAssetAliasManager.class,
+                ComponentMessagesSource.class,
+                ComponentSource.class,
+                Environment.class,
+                FieldValidatorDefaultSource.class,
+                FieldValidatorSource.class,
+                MarkupWriterFactory.class,
+                PersistentFieldManager.class,
                 Request.class,
+                RequestGlobals.class,
+                ResourceDigestGenerator.class,
                 Response.class,
-                ValidationMessagesSource.class,
-                TranslatorSource.class,
                 TranslatorDefaultSource.class,
-                FieldValidatorSource.class,
-                ValidationConstraintGenerator.class);
+                TranslatorSource.class,
+                ValidationConstraintGenerator.class,
+                ValidationMessagesSource.class);
 
         configuration.add(new InfrastructureContribution("TypeCoercer", typeCoercer));
         configuration.add(new InfrastructureContribution("PropertyAccess", propertyAccess));
@@ -1186,5 +1189,15 @@
     {
         configuration.add("PrimitiveField", new PrimitiveFieldConstraintGenerator());
         configuration.add("ValidateAnnotation", new ValidateAnnotationConstraintGenerator());
+    }
+
+    public static FieldValidatorDefaultSource buildFieldValidatorDefaultSource(
+            @Inject("infrastructure:ValidationConstraintGenerator")
+            ValidationConstraintGenerator validationConstraintGenerator,
+            @Inject("infrastructure:FieldValidatorSource")
+            FieldValidatorSource fieldValidatorSource)
+    {
+        return new FieldValidatorDefaultSourceImpl(validationConstraintGenerator,
+                fieldValidatorSource);
     }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ValidationConstraintGenerator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ValidationConstraintGenerator.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ValidationConstraintGenerator.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ValidationConstraintGenerator.java Thu Feb  1 16:19:58 2007
@@ -16,8 +16,8 @@
 
 import java.util.List;
 
+import org.apache.tapestry.AnnotationProvider;
 import org.apache.tapestry.FieldValidator;
-import org.apache.tapestry.beaneditor.PropertyEditModel;
 
 /**
  * Invoked to generate a list of validation constraint strings for a property. This typically
@@ -35,9 +35,12 @@
      * These will ultimately be used to create {@link FieldValidator}s for the field that edits the
      * property.
      * 
-     * @param propertyModel
-     * @return
+     * @param propertyType
+     *            the type of the property for which constraints are needed
+     * @param annotationProvider
+     *            provides access to any annotations conceerning the property
+     * @return a list of constraints
      * @see FieldValidatorSource
      */
-    List<String> buildConstraints(PropertyEditModel propertyModel);
+    List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider);
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java Thu Feb  1 16:19:58 2007
@@ -33,6 +33,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
+import org.apache.tapestry.AnnotationProvider;
 import org.apache.tapestry.Asset;
 import org.apache.tapestry.Binding;
 import org.apache.tapestry.Block;
@@ -351,12 +352,6 @@
         expect(response.encodeRedirectURL(URI)).andReturn(encoded);
     }
 
-    protected final <T extends Annotation> void train_getAnnotation(
-            ClassTransformation transformation, Class<T> annotationClass, T annotation)
-    {
-        expect(transformation.getAnnotation(annotationClass)).andReturn(annotation);
-    }
-
     protected final void train_getPage(ComponentResources resources, Component page)
     {
         expect(resources.getPage()).andReturn(page).atLeastOnce();
@@ -779,10 +774,10 @@
         expect(messages.contains(isA(String.class))).andStubReturn(contained);
     }
 
-    protected final <T extends Annotation> void train_getAnnotation(PropertyConduit conduit,
+    protected final <T extends Annotation> void train_getAnnotation(AnnotationProvider provider,
             Class<T> annotationClass, T annotation)
     {
-        expect(conduit.getAnnotation(annotationClass)).andReturn(annotation).atLeastOnce();
+        expect(provider.getAnnotation(annotationClass)).andReturn(annotation).atLeastOnce();
     }
 
     protected final void train_getConduit(PropertyEditModel model, PropertyConduit conduit)

Modified: tapestry/tapestry5/tapestry-core/trunk/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/site/apt/index.apt?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/site/apt/index.apt (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/site/apt/index.apt Thu Feb  1 16:19:58 2007
@@ -38,6 +38,8 @@
   Progress on Tapestry 5 is really taking off. This space lists some cool new features that have been added
   recently.
   
+  * Validating form components will use the same system as BeanEditForm to determine default validation for fields.
+  
   * Select component will automatically provide a ValueEncoder and SelectModel when the value parameter is bound to an Enum type.
   
   * BeanEditForm component that creates a form and related controls to edit the properties of any JavaBean, automatically.

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/data/IncidentData.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/data/IncidentData.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/data/IncidentData.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/data/IncidentData.java Thu Feb  1 16:19:58 2007
@@ -16,6 +16,8 @@
 
 import java.io.Serializable;
 
+import org.apache.tapestry.beaneditor.Validate;
+
 public class IncidentData implements Serializable
 {
     private static final long serialVersionUID = -321606932140181054L;
@@ -47,6 +49,7 @@
         return _message;
     }
 
+    @Validate("required")
     public void setMessage(String message)
     {
         _message = message;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGeneratorTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGeneratorTest.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGeneratorTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGeneratorTest.java Thu Feb  1 16:19:58 2007
@@ -17,7 +17,6 @@
 import java.util.Arrays;
 
 import org.apache.tapestry.beaneditor.PropertyConduit;
-import org.apache.tapestry.beaneditor.PropertyEditModel;
 import org.apache.tapestry.beaneditor.Validate;
 import org.apache.tapestry.internal.test.InternalBaseTestCase;
 import org.apache.tapestry.services.ValidationConstraintGenerator;
@@ -28,17 +27,15 @@
     @Test
     public void no_annotation()
     {
-        PropertyEditModel model = newPropertyEditModel();
         PropertyConduit conduit = newPropertyConduit();
 
-        train_getConduit(model, conduit);
         train_getAnnotation(conduit, Validate.class, null);
 
         replay();
 
         ValidationConstraintGenerator gen = new ValidateAnnotationConstraintGenerator();
 
-        assertNull(gen.buildConstraints(model));
+        assertNull(gen.buildConstraints(Object.class, conduit));
 
         verify();
     }
@@ -46,18 +43,16 @@
     @Test
     public void single_constraint()
     {
-        PropertyEditModel model = newPropertyEditModel();
         PropertyConduit conduit = newPropertyConduit();
         Validate validate = newValidate("required");
 
-        train_getConduit(model, conduit);
         train_getAnnotation(conduit, Validate.class, validate);
 
         replay();
 
         ValidationConstraintGenerator gen = new ValidateAnnotationConstraintGenerator();
 
-        assertEquals(gen.buildConstraints(model), Arrays.asList("required"));
+        assertEquals(gen.buildConstraints(Object.class, conduit), Arrays.asList("required"));
 
         verify();
     }
@@ -65,18 +60,16 @@
     @Test
     public void multiple_constraints()
     {
-        PropertyEditModel model = newPropertyEditModel();
         PropertyConduit conduit = newPropertyConduit();
         Validate validate = newValidate("required,minlength=3");
 
-        train_getConduit(model, conduit);
         train_getAnnotation(conduit, Validate.class, validate);
 
         replay();
 
         ValidationConstraintGenerator gen = new ValidateAnnotationConstraintGenerator();
 
-        assertEquals(gen.buildConstraints(model), Arrays.asList("required", "minlength=3"));
+        assertEquals(gen.buildConstraints(null, conduit), Arrays.asList("required", "minlength=3"));
 
         verify();
     }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/PropBindingFactoryTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/PropBindingFactoryTest.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/PropBindingFactoryTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/PropBindingFactoryTest.java Thu Feb  1 16:19:58 2007
@@ -16,6 +16,7 @@
 
 import org.apache.tapestry.Binding;
 import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.beaneditor.Order;
 import org.apache.tapestry.internal.test.InternalBaseTestCase;
 import org.apache.tapestry.internal.util.IntegerRange;
 import org.apache.tapestry.ioc.Location;
@@ -79,6 +80,91 @@
         assertEquals(InternalUtils.locationOf(binding), l);
 
         assertEquals(binding.toString(), "PropBinding[test binding foo.Bar:baz(objectValue)]");
+
+        verify();
+    }
+
+    @Test
+    public void annotation_from_read_only_property()
+    {
+        TargetBean bean = new TargetBean();
+        ComponentResources resources = newComponentResources(bean);
+        Location l = newLocation();
+
+        replay();
+
+        Binding binding = _factory.newBinding("test binding", resources, null, "readOnly", l);
+
+        assertEquals(binding.getAnnotation(Order.class).value(), 100);
+
+        verify();
+    }
+
+    @Test
+    public void annotation_from_write_only_property()
+    {
+        TargetBean bean = new TargetBean();
+        ComponentResources resources = newComponentResources(bean);
+        Location l = newLocation();
+
+        replay();
+
+        Binding binding = _factory.newBinding("test binding", resources, null, "writeOnly", l);
+
+        assertEquals(binding.getAnnotation(Order.class).value(), 200);
+
+        verify();
+    }
+
+    @Test
+    public void annotation_does_not_exist()
+    {
+        TargetBean bean = new TargetBean();
+        ComponentResources resources = newComponentResources(bean);
+        Location l = newLocation();
+
+        replay();
+
+        Binding binding = _factory.newBinding("test binding", resources, null, "intValue", l);
+
+        assertNull(binding.getAnnotation(Order.class));
+
+        verify();
+    }
+
+    @Test
+    public void annotation_on_named_method()
+    {
+        TargetBean bean = new TargetBean();
+        ComponentResources resources = newComponentResources(bean);
+        Location l = newLocation();
+
+        replay();
+
+        Binding binding = _factory.newBinding(
+                "test binding",
+                resources,
+                null,
+                "stringHolderMethod()",
+                l);
+
+        assertEquals(binding.getAnnotation(Order.class).value(), 300);
+
+        verify();
+    }
+
+    @Test
+    public void annnotation_on_read_method_takes_precedence_over_write_method()
+    {
+        TargetBean bean = new TargetBean();
+        ComponentResources resources = newComponentResources(bean);
+        Location l = newLocation();
+
+        replay();
+
+        Binding binding = _factory.newBinding("test binding", resources, null, "objectValue", l);
+
+        assertEquals(binding.getAnnotation(Order.class).value(), 1000);
 
         verify();
     }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/TargetBean.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/TargetBean.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/TargetBean.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/TargetBean.java Thu Feb  1 16:19:58 2007
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry.internal.bindings;
 
+import org.apache.tapestry.beaneditor.Order;
+
 public class TargetBean extends DefaultComponent
 {
     private String _objectValue;
@@ -29,6 +31,7 @@
         return _stringHolder;
     }
 
+    @Order(300)
     public StringHolder stringHolderMethod()
     {
         return _stringHolder;
@@ -49,21 +52,25 @@
         _intValue = intValue;
     }
 
+    @Order(1000)
     public String getObjectValue()
     {
         return _objectValue;
     }
 
+    @Order(2000)
     public void setObjectValue(String objectValue)
     {
         _objectValue = objectValue;
     }
 
+    @Order(200)
     public void setWriteOnly(String value)
     {
         _writeOnly = value;
     }
 
+    @Order(100)
     public String getReadOnly()
     {
         return "ReadOnly";

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanEditorModelSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanEditorModelSourceImplTest.java?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanEditorModelSourceImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/BeanEditorModelSourceImplTest.java Thu Feb  1 16:19:58 2007
@@ -80,15 +80,15 @@
 
         instance.setLastName("Lewis Ship");
 
-        assertEquals(conduit.read(instance), "Lewis Ship");
+        assertEquals(conduit.get(instance), "Lewis Ship");
 
-        conduit.write(instance, "TapestryDude");
+        conduit.set(instance, "TapestryDude");
 
         assertEquals(instance.getLastName(), "TapestryDude");
 
         // Now, one with some type coercion.
 
-        age.getConduit().write(instance, "40");
+        age.getConduit().set(instance, "40");
 
         assertEquals(instance.getAge(), 40);
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/ValidForm.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/ValidForm.html?view=diff&rev=502410&r1=502409&r2=502410
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/ValidForm.html (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/ValidForm.html Thu Feb  1 16:19:58 2007
@@ -11,7 +11,7 @@
             t:type="TextField" t:id="email" value="incident.email" size="50" t:validate="required"/>
         <br/>
         <label t:type="Label"  for="message"/>: <textarea t:type="TextArea" t:id="message" t:label="Incident Message"
-            value="incident.message" cols="50" rows="10" t:validate="required"> You can put text here, but it isn't used. </textarea>
+            value="incident.message" cols="50" rows="10"> You can put text here, but it isn't used. </textarea>
         <br/>
         <input t:type="Checkbox" t:id="urgent" value="incident.urgent"/>
         <label t:type="Label" for="urgent"/>