tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From freem...@apache.org
Subject svn commit: r503415 [2/3] - in /tapestry/tapestry5/tapestry-core: branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/ branches/kt-20070204-IDE-support/src/test/java/org/apache/tapestry/corelib/base/ branches/kt-20070204-IDE-support/src/...
Date Sun, 04 Feb 2007 14:40:42 GMT
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=503415&r1=503414&r2=503415
==============================================================================
--- 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 Sun Feb  4 06:40:39 2007
@@ -14,16 +14,16 @@
 
 package org.apache.tapestry.corelib.components;
 
-import java.util.Locale;
+import java.util.List;
 
 import org.apache.tapestry.Block;
 import org.apache.tapestry.ComponentResources;
 import org.apache.tapestry.EnumSelectModel;
 import org.apache.tapestry.EnumValueEncoder;
 import org.apache.tapestry.Field;
-import org.apache.tapestry.FieldValidator;
 import org.apache.tapestry.SelectModel;
 import org.apache.tapestry.Translator;
+import org.apache.tapestry.Validator;
 import org.apache.tapestry.ValueEncoder;
 import org.apache.tapestry.annotations.Component;
 import org.apache.tapestry.annotations.ComponentClass;
@@ -33,8 +33,8 @@
 import org.apache.tapestry.beaneditor.PropertyEditModel;
 import org.apache.tapestry.ioc.Messages;
 import org.apache.tapestry.services.BeanEditorModelSource;
-import org.apache.tapestry.services.FieldValidatorDefaultSource;
 import org.apache.tapestry.services.TranslatorDefaultSource;
+import org.apache.tapestry.services.ValidatorGenerator;
 
 /**
  * A component that creates an entire form editting the properties of a particular bean. Inspired by
@@ -66,8 +66,8 @@
     @Inject("infrastructure:TranslatorDefaultSource")
     private TranslatorDefaultSource _translatorDefaultSource;
 
-    @Inject("infrastructure:FieldValidatorDefaultSource")
-    private FieldValidatorDefaultSource _fieldValidatorDefaultSource;
+    @Inject("infrastructure:ValidatorGenerator")
+    private ValidatorGenerator _validatorGenerator;
 
     @Inject
     private Block _text;
@@ -81,27 +81,56 @@
     @Component
     private Form _form;
 
-    @Component(parameters =
-    { "value=valueForProperty", "label=prop:propertyEditModel.label",
-            "encoder=valueEncoderForProperty", "model=selectModelForProperty",
-            "validate=prop:validateForProperty", "clientId=prop:propertyName" })
+    // @Component(parameters =
+    // { "value=valueForProperty", "label=prop:propertyEditModel.label",
+    // "encoder=valueEncoderForProperty", "model=selectModelForProperty",
+    // "validate=prop:validateForProperty", "clientId=prop:propertyName" })
+    @Component
     private Select _select;
 
-    @Component(parameters =
-    { "value=valueForProperty", "label=prop:propertyEditModel.label",
-            "translate=prop:translateForProperty", "validate=prop:validateForProperty",
-            "clientId=prop:propertyName" })
+    @SuppressWarnings("unchecked")
+    public void configureSelect()
+    {
+        _select.setValueBindingExpr("valueForProperty");
+        _select.setLabel(getPropertyEditModel().getLabel());
+        _select.setEncoder(getValueEncoderForProperty());
+        _select.setModel(getSelectModelForProperty());
+        _select.setValidators(getValidatorsForProperty());
+        _select.setClientId(getPropertyName());
+    }
+
+    // @Component(parameters =
+    // { "value=valueForProperty", "label=prop:propertyEditModel.label",
+    // "translate=prop:translateForProperty", "validate=prop:validateForProperty",
+    // "clientId=prop:propertyName" })
+    @Component
     private TextField _textField;
 
-    @Component(parameters =
-    { "value=valueForProperty", "label=prop:propertyEditModel.label", "clientId=prop:propertyName" })
+    @SuppressWarnings("unchecked")
+    public void configureTextField()
+    {
+        _textField.setValueBindingExpr("valueForProperty");
+        _textField.setLabel(getPropertyEditModel().getLabel());
+        _textField.setTranslator(getTranslateForProperty());
+        _textField.setValidators(getValidatorsForProperty());
+        _textField.setClientId(getPropertyName());
+    }
+
+    // @Component(parameters =
+    // { "value=valueForProperty", "label=prop:propertyEditModel.label",
+    // "clientId=prop:propertyName" })
+    @Component
     private Checkbox _checkboxField;
 
-    @Inject
-    private Messages _messages;
+    public void configureCheckboxField()
+    {
+        _checkboxField.setValueBindingExpr("valueForProperty");
+        _checkboxField.setLabel(getPropertyEditModel().getLabel());
+        _checkboxField.setClientId(getPropertyName());
+    }
 
     @Inject
-    private Locale _locale;
+    private Messages _messages;
 
     @Parameter
     private BeanEditorModel _model;
@@ -183,15 +212,12 @@
         return _translatorDefaultSource.find(_propertyEditModel.getPropertyType());
     }
 
-    public FieldValidator getValidateForProperty()
+    public Validator[] getValidatorsForProperty()
     {
-        return _fieldValidatorDefaultSource.createDefaultValidator(
-                _fieldForProperty,
-                _propertyName,
-                _resources.getContainerMessages(),
-                _locale,
+        List<? extends Validator> validators = _validatorGenerator.buildValidators(
                 _propertyEditModel.getPropertyType(),
                 _propertyEditModel.getConduit());
+        return validators == null ? null : validators.toArray(new Validator[0]);
     }
 
     public PropertyEditModel getPropertyEditModel()

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Checkbox.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Checkbox.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Checkbox.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Checkbox.java Sun Feb  4 06:40:39 2007
@@ -14,29 +14,34 @@
 
 package org.apache.tapestry.corelib.components;
 
-import org.apache.tapestry.Binding;
+import org.apache.tapestry.BindingExprValueConduit;
 import org.apache.tapestry.MarkupWriter;
+import org.apache.tapestry.ValueConduit;
 import org.apache.tapestry.annotations.AfterRender;
 import org.apache.tapestry.annotations.BeginRender;
-import org.apache.tapestry.annotations.Parameter;
+import org.apache.tapestry.annotations.FormPersist;
 import org.apache.tapestry.corelib.base.AbstractField;
 import org.apache.tapestry.internal.services.FormParameterLookup;
 
 /** A Checkbox component is simply a &lt;input type="checkbox"&gt;. */
 public class Checkbox extends AbstractField
 {
+    @FormPersist
+    private ValueConduit<Boolean> _valueConduit;
 
-    @Parameter(required = true)
-    private boolean _value;
-
-    Binding defaultValue()
+    @SuppressWarnings("unchecked")
+    public void setValueBindingExpr(String valueBindingExpr)
     {
-        return createDefaultParameterBinding("value");
+        _valueConduit = new BindingExprValueConduit(valueBindingExpr);
     }
 
     @BeginRender
     void begin(MarkupWriter writer)
     {
+        if (_valueConduit == null)
+        {
+            setValueBindingExpr(getIdBasedBindingExpression());
+        }
         writer.element(
                 "input",
                 "type",
@@ -46,7 +51,7 @@
                 "id",
                 getClientId(),
                 "checked",
-                _value ? "checked" : null);
+                _valueConduit.get(this) ? "checked" : null);
 
         getValidationDecorator().insideField(this);
     }
@@ -62,7 +67,16 @@
     {
         String postedValue = paramLookup.getParameter(elementName);
 
-        _value = postedValue != null;
+        _valueConduit.set(this, postedValue != null);
+    }
+
+    public ValueConduit<Boolean> getValueConduit()
+    {
+        return _valueConduit;
     }
 
+    public void setValueConduit(ValueConduit<Boolean> valueConduit)
+    {
+        _valueConduit = valueConduit;
+    }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Label.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Label.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Label.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Label.java Sun Feb  4 06:40:39 2007
@@ -80,6 +80,9 @@
                 element.forceAttributes("for", fieldId);
 
                 decorator.insideLabel(field, element);
+
+                element.text(field.getLabel());
+
             }
         };
 
@@ -97,8 +100,6 @@
     @AfterRender
     void after(MarkupWriter writer)
     {
-        writer.write(_field.getLabel());
-
         writer.end(); // label
     }
 }

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=503415&r1=503414&r2=503415
==============================================================================
--- 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 Sun Feb  4 06:40:39 2007
@@ -21,7 +21,7 @@
  * A version of {@link TextField}, but written out as a &lt;input type="password"&gt;. Further, the
  * output value for a PasswordField is always blank.
  */
-public class PasswordField extends AbstractTextField
+public class PasswordField<T> extends AbstractTextField<T>
 {
 
     @Override

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=503415&r1=503414&r2=503415
==============================================================================
--- 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 Sun Feb  4 06:40:39 2007
@@ -15,11 +15,11 @@
 package org.apache.tapestry.corelib.components;
 
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 
-import org.apache.tapestry.Binding;
+import org.apache.tapestry.BindingExprValueConduit;
 import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.DefaultValueEncoder;
 import org.apache.tapestry.EnumSelectModel;
 import org.apache.tapestry.EnumValueEncoder;
 import org.apache.tapestry.FieldValidator;
@@ -29,57 +29,45 @@
 import org.apache.tapestry.SelectModel;
 import org.apache.tapestry.ValidationException;
 import org.apache.tapestry.ValidationTracker;
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.ValueConduit;
 import org.apache.tapestry.ValueEncoder;
 import org.apache.tapestry.annotations.AfterRender;
 import org.apache.tapestry.annotations.BeforeRenderTemplate;
+import org.apache.tapestry.annotations.BeginRender;
 import org.apache.tapestry.annotations.Environmental;
+import org.apache.tapestry.annotations.FormPersist;
 import org.apache.tapestry.annotations.Inject;
-import org.apache.tapestry.annotations.Parameter;
 import org.apache.tapestry.corelib.base.AbstractField;
+import org.apache.tapestry.internal.services.FieldValidatorImpl;
+import org.apache.tapestry.internal.services.FieldValidatorMessages;
 import org.apache.tapestry.internal.services.FormParameterLookup;
-import org.apache.tapestry.services.FieldValidatorDefaultSource;
+import org.apache.tapestry.ioc.internal.util.Defense;
 
 /**
  * Select an item from a list of values, using an [X]HTML &lt;select&gt; element on the client side.
  * An validation decorations will go around the entire &lt;select&gt; element.
  */
-public final class Select extends AbstractField
+public final class Select<T> extends AbstractField
 {
-    @Parameter(required = true, principal = true)
-    private Object _value;
+    @FormPersist
+    private ValueConduit<T> _valueConduit;
 
     /**
      * The default encoder encodes strings, passing them to the client and back unchanged.
      */
-    @Parameter
-    private ValueEncoder _encoder = new ValueEncoder<String>()
-    {
-        public String toClient(String value)
-        {
-            return value;
-        }
-
-        public String toValue(String primaryKey)
-        {
-            // We don't do a conversion here, so it stays a String. When that String is assigned to
-            // _value, it will be coerced to the appropriate type (if possible) or an exception
-            // will be thrown.
-
-            return primaryKey;
-        }
-    };
+    @FormPersist
+    private ValueEncoder<T> _encoder;
 
     // Maybe this should default to property "<componentId>Model"?
 
-    @Parameter(required = true)
-    private SelectModel _model;
+    private SelectModel<T> _model;
 
-    @Parameter(defaultPrefix = "validate")
-    @SuppressWarnings("unchecked")
-    private FieldValidator<Object> _validate = NOOP_VALIDATOR;
+    @Inject("infrastructure:FieldValidatorMessages")
+    private FieldValidatorMessages _fieldValidatorMessages;
 
-    @Inject("infrastructure:FieldValidatorDefaultSource")
-    private FieldValidatorDefaultSource _fieldValidatorDefaultSource;
+    @FormPersist
+    private Validator<? super T>[] _validators;
 
     @Environmental
     private ValidationTracker _tracker;
@@ -87,64 +75,75 @@
     @Inject
     private ComponentResources _resources;
 
-    @Inject
-    private Locale _locale;
-
-    Binding defaultValue()
+    @SuppressWarnings("unchecked")
+    private ValueEncoder<T> getDefaultEncoder()
     {
-        return createDefaultParameterBinding("value");
+        T value = _valueConduit.get(this);
+        return value == null ? null : getDefaultEncoder((Class<T>) value.getClass());
     }
 
-    /**
-     * Computes a default value for the "validate" parameter using
-     * {@link FieldValidatorDefaultSource}.
-     */
-    FieldValidator defaultValidate()
+    @SuppressWarnings("unchecked")
+    private ValueEncoder<T> getDefaultEncoder(Class<T> valueType)
     {
-        Class type = _resources.getBoundType("value");
+        Defense.notNull(valueType, "valueType");
+        if (Enum.class.isAssignableFrom(valueType))
+            return (ValueEncoder<T>) new EnumValueEncoder(valueType);
+        ValueEncoder<T> defaultEncoder = (ValueEncoder<T>) new DefaultValueEncoder();
+        return defaultEncoder;
+    }
 
-        if (type == null)
-            return null;
+    public void useDefaultEncoder(Class<T> valueType)
+    {
+        _encoder = getDefaultEncoder(valueType);
+    }
 
-        return _fieldValidatorDefaultSource.createDefaultValidator(
-                this,
-                _resources.getId(),
-                _resources.getContainerMessages(),
-                _locale,
-                type,
-                _resources.getAnnotationProvider("value"));
+    private void useDefaultEncoder()
+    {
+        _encoder = getDefaultEncoder();
     }
 
     @SuppressWarnings("unchecked")
-    ValueEncoder defaultEncoder()
+    private SelectModel<T> getDefaultModel(Class<T> valueType)
     {
-        Class valueType = _resources.getBoundType("value");
-
-        if (valueType == null)
-            return null;
-
+        Defense.notNull(valueType, "valueType");
         if (Enum.class.isAssignableFrom(valueType))
-            return new EnumValueEncoder(valueType);
+            return new EnumSelectModel(valueType, _resources.getContainerMessages());
 
         return null;
     }
 
     @SuppressWarnings("unchecked")
-    SelectModel defaultModel()
+    private SelectModel<T> getDefaultModel()
     {
-        Class valueType = _resources.getBoundType("value");
-
-        if (valueType == null)
-            return null;
+        T value = _valueConduit.get(this);
+        return value == null ? null : getDefaultModel((Class<T>) value.getClass());
+    }
 
-        if (Enum.class.isAssignableFrom(valueType))
-            return new EnumSelectModel(valueType, _resources.getContainerMessages());
+    public void useDefaultModel(Class<T> valueType)
+    {
+        _model = getDefaultModel(valueType);
+    }
 
-        return null;
+    private void useDefaultModel()
+    {
+        _model = getDefaultModel();
     }
 
+    @BeginRender
     void beginRender(MarkupWriter writer)
     {
+        if (_valueConduit == null)
+        {
+            setValueBindingExpr(getIdBasedBindingExpression());
+        }
+        if (_encoder == null)
+        {
+            useDefaultEncoder();
+        }
+        if (_model == null)
+        {
+            useDefaultModel();
+        }
         writer.element("select", "name", getElementName(), "id", getClientId());
 
         // Disabled, informals via mixins
@@ -155,7 +154,7 @@
     {
         if (_model.getOptionGroups() != null)
         {
-            for (OptionGroupModel group : _model.getOptionGroups())
+            for (OptionGroupModel<T> group : _model.getOptionGroups())
             {
                 writeOptionGroup(writer, group);
             }
@@ -164,7 +163,7 @@
         writeOptions(writer, _model.getOptions());
     }
 
-    private void writeOptionGroup(MarkupWriter writer, OptionGroupModel model)
+    private void writeOptionGroup(MarkupWriter writer, OptionGroupModel<T> model)
     {
         writer.element("optgroup", "label", model.getLabel());
 
@@ -177,16 +176,16 @@
     }
 
     @SuppressWarnings("unchecked")
-    private void writeOptions(MarkupWriter writer, List<OptionModel> optionModels)
+    private void writeOptions(MarkupWriter writer, List<OptionModel<T>> optionModels)
     {
         if (optionModels == null)
             return;
 
-        for (OptionModel model : optionModels)
+        for (OptionModel<T> model : optionModels)
         {
-            Object optionValue = model.getValue();
+            T optionValue = model.getValue();
 
-            String clientValue = _encoder.toClient(optionValue);
+            String clientValue = _encoder.toClient(_resources, optionValue);
 
             writer.element("option", "value", clientValue);
 
@@ -204,7 +203,8 @@
 
     boolean isOptionValueSelected(Object optionValue)
     {
-        return _value == optionValue || (_value != null && _value.equals(optionValue));
+        Object value = _valueConduit.get(this);
+        return value == optionValue || (value != null && value.equals(optionValue));
     }
 
     private void writeDisabled(MarkupWriter writer, boolean disabled)
@@ -233,13 +233,16 @@
     {
         String primaryKey = paramLookup.getParameter(elementName);
 
-        Object selectedValue = _encoder.toValue(primaryKey);
+        T selectedValue = _encoder.toValue(_resources, primaryKey);
 
         try
         {
-            _validate.validate(selectedValue);
+            FieldValidator<T> fieldValidator = new FieldValidatorImpl<T>(this,
+                    _fieldValidatorMessages, _validators);
 
-            _value = selectedValue;
+            fieldValidator.validate(selectedValue);
+
+            _valueConduit.set(this, selectedValue);
         }
         catch (ValidationException ex)
         {
@@ -248,15 +251,55 @@
         }
     }
 
-    // For testing.
+    public void setModel(SelectModel<T> model)
+    {
+        _model = model;
+    }
+
+    public ValueConduit<T> getValueConduit()
+    {
+        return _valueConduit;
+    }
+
+    public void setValueConduit(ValueConduit<T> valueConduit)
+    {
+        _valueConduit = valueConduit;
+    }
 
-    void setValue(Object value)
+    @SuppressWarnings("unchecked")
+    public void setValueBindingExpr(String valueBindingExpr)
     {
-        _value = value;
+        _valueConduit = new BindingExprValueConduit(valueBindingExpr);
     }
 
-    void setModel(SelectModel model)
+    public ValueEncoder<T> getEncoder()
     {
-        _model = model;
+        return _encoder;
+    }
+
+    public void setEncoder(ValueEncoder<T> encoder)
+    {
+        _encoder = encoder;
+    }
+
+    public Validator<? super T>[] getValidators()
+    {
+        return _validators;
+    }
+
+    public void setValidators(Validator<? super T>... validators)
+    {
+        _validators = validators;
+    }
+
+    public SelectModel<T> getModel()
+    {
+        return _model;
+    }
+
+    public void useDefaultsFor(Class<T> valueType)
+    {
+        useDefaultEncoder(valueType);
+        useDefaultModel(valueType);
     }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextArea.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextArea.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextArea.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextArea.java Sun Feb  4 06:40:39 2007
@@ -22,7 +22,7 @@
  * TextArea component corresponds to a &lt;textarea&gt;. The value parameter is almost always bound
  * to a string, but this is not an absolute requirement.
  */
-public final class TextArea extends AbstractTextField
+public final class TextArea<T> extends AbstractTextField<T>
 {
     private String _value;
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextField.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextField.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/TextField.java Sun Feb  4 06:40:39 2007
@@ -22,7 +22,7 @@
  * editted. TextField is generally used with string values, but other values are acceptible, as long
  * as they can be freely converted back and forth to strings.
  */
-public final class TextField extends AbstractTextField
+public final class TextField<T> extends AbstractTextField<T>
 {
     @Override
     protected final void writeFieldTag(MarkupWriter writer, String value)

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/mixins/TypeSafeConfigurationEnabled.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/mixins/TypeSafeConfigurationEnabled.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/mixins/TypeSafeConfigurationEnabled.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/mixins/TypeSafeConfigurationEnabled.java Sun Feb  4 06:40:39 2007
@@ -0,0 +1,55 @@
+// 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.corelib.mixins;
+
+import java.lang.reflect.Method;
+
+import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.annotations.ComponentClass;
+import org.apache.tapestry.annotations.Inject;
+import org.apache.tapestry.annotations.SetupRender;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
+
+/**
+ * A mixin to enable type safe configuration. It is going to be removed once
+ * it's function is made built-in.
+ */
+@ComponentClass
+public class TypeSafeConfigurationEnabled
+{
+    @Inject
+    private ComponentResources _resources;
+
+    @SetupRender
+    public void invokeConfigurationMethod()
+    {
+        Object container = _resources.getContainer();
+        try
+        {
+            Method method = container.getClass().getMethod(
+                    "configure" + InternalUtils.capitalize(_resources.getId()));
+            method.invoke(container);
+        }
+        catch (NoSuchMethodException ex)
+        {
+
+        }
+        catch (Exception ex)
+        {
+            throw new RuntimeException(ex);
+        }
+    }
+
+}

Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/mixins/TypeSafeConfigurationEnabled.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/OptionGroupModelImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/OptionGroupModelImpl.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/OptionGroupModelImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/OptionGroupModelImpl.java Sun Feb  4 06:40:39 2007
@@ -14,30 +14,33 @@
 
 package org.apache.tapestry.internal;
 
+import java.io.Serializable;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.tapestry.OptionGroupModel;
 import org.apache.tapestry.OptionModel;
 
-public final class OptionGroupModelImpl implements OptionGroupModel
+public final class OptionGroupModelImpl<T> implements OptionGroupModel<T>, Serializable
 {
+    private static final long serialVersionUID = 1L;
+    
     private final String _label;
 
     private final boolean _disabled;
 
-    private final List<OptionModel> _options;
+    private final List<OptionModel<T>> _options;
 
     private final Map<String, String> _attributes;
 
-    public OptionGroupModelImpl(String label, boolean disabled, List<OptionModel> options,
+    public OptionGroupModelImpl(String label, boolean disabled, List<OptionModel<T>> options,
             String... attributeKeysAndValues)
     {
         this(label, disabled, options, attributeKeysAndValues.length == 0 ? null : TapestryUtils
                 .mapFromKeysAndValues(attributeKeysAndValues));
     }
 
-    public OptionGroupModelImpl(String label, boolean disabled, List<OptionModel> options,
+    public OptionGroupModelImpl(String label, boolean disabled, List<OptionModel<T>> options,
             Map<String, String> attributes)
     {
         _label = label;
@@ -56,7 +59,7 @@
         return _label;
     }
 
-    public List<OptionModel> getOptions()
+    public List<OptionModel<T>> getOptions()
     {
         return _options;
     }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/OptionModelImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/OptionModelImpl.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/OptionModelImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/OptionModelImpl.java Sun Feb  4 06:40:39 2007
@@ -14,27 +14,30 @@
 
 package org.apache.tapestry.internal;
 
+import java.io.Serializable;
 import java.util.Map;
 
 import org.apache.tapestry.OptionModel;
 
-public final class OptionModelImpl implements OptionModel
+public final class OptionModelImpl<T> implements OptionModel<T>, Serializable
 {
+    private static final long serialVersionUID = 1L;
+
     private final String _label;
 
     private final boolean _disabled;
 
-    private final Object _value;
+    private final T _value;
 
     private final Map<String, String> _attributes;
 
-    public OptionModelImpl(String label, boolean disabled, Object value, String... keysAndValues)
+    public OptionModelImpl(String label, boolean disabled, T value, String... keysAndValues)
     {
         this(label, disabled, value, keysAndValues.length > 0 ? TapestryUtils
                 .mapFromKeysAndValues(keysAndValues) : null);
     }
 
-    public OptionModelImpl(String label, boolean disabled, Object value,
+    public OptionModelImpl(String label, boolean disabled, T value,
             Map<String, String> attributes)
     {
         _label = label;
@@ -53,7 +56,7 @@
         return _label;
     }
 
-    public Object getValue()
+    public T getValue()
     {
         return _value;
     }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/SelectModelImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/SelectModelImpl.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/SelectModelImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/SelectModelImpl.java Sun Feb  4 06:40:39 2007
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry.internal;
 
+import java.io.Serializable;
 import java.util.Arrays;
 import java.util.List;
 
@@ -21,35 +22,37 @@
 import org.apache.tapestry.OptionModel;
 import org.apache.tapestry.SelectModel;
 
-public final class SelectModelImpl implements SelectModel
+public final class SelectModelImpl<T> implements SelectModel<T>, Serializable
 {
-    private final List<OptionGroupModel> _optionGroups;
+    private static final long serialVersionUID = 1L;
+    
+    private final List<OptionGroupModel<T>> _optionGroups;
 
-    private final List<OptionModel> _optionModels;
+    private final List<OptionModel<T>> _optionModels;
 
-    public SelectModelImpl(final List<OptionGroupModel> optionGroups,
-            final List<OptionModel> optionModels)
+    public SelectModelImpl(final List<OptionGroupModel<T>> optionGroups,
+            final List<OptionModel<T>> optionModels)
     {
         _optionGroups = optionGroups;
         _optionModels = optionModels;
     }
 
-    public SelectModelImpl(OptionModel... optionModels)
+    public SelectModelImpl(OptionModel<T>... optionModels)
     {
         this(null, Arrays.asList(optionModels));
     }
 
-    public SelectModelImpl(OptionGroupModel... groupModels)
+    public SelectModelImpl(OptionGroupModel<T>... groupModels)
     {
         this(Arrays.asList(groupModels), null);
     }
 
-    public List<OptionGroupModel> getOptionGroups()
+    public List<OptionGroupModel<T>> getOptionGroups()
     {
         return _optionGroups;
     }
 
-    public List<OptionModel> getOptions()
+    public List<OptionModel<T>> getOptions()
     {
         return _optionModels;
     }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/TapestryUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/TapestryUtils.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/TapestryUtils.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/TapestryUtils.java Sun Feb  4 06:40:39 2007
@@ -126,19 +126,19 @@
      * @param input
      * @return
      */
-    public static OptionModel toOptionModel(String input)
+    public static OptionModel<String> toOptionModel(String input)
     {
         Defense.notNull(input, "input");
 
         int equalsx = input.indexOf('=');
 
         if (equalsx < 0)
-            return new OptionModelImpl(input, false, input);
+            return new OptionModelImpl<String>(input, false, input);
 
         String value = input.substring(0, equalsx);
         String label = input.substring(equalsx + 1);
 
-        return new OptionModelImpl(label, false, value);
+        return new OptionModelImpl<String>(label, false, value);
     }
 
     /**
@@ -149,11 +149,11 @@
      *            comma seperated list of terms
      * @return list of option models
      */
-    public static List<OptionModel> toOptionModels(String input)
+    public static List<OptionModel<String>> toOptionModels(String input)
     {
         Defense.notNull(input, "input");
 
-        List<OptionModel> result = newList();
+        List<OptionModel<String>> result = newList();
 
         for (String term : input.split(","))
             result.add(toOptionModel(term.trim()));
@@ -168,11 +168,11 @@
      * @param input
      * @return
      */
-    public static SelectModel toSelectModel(String input)
+    public static SelectModel<String> toSelectModel(String input)
     {
-        List<OptionModel> options = toOptionModels(input);
+        List<OptionModel<String>> options = toOptionModels(input);
 
-        return new SelectModelImpl(null, options);
+        return new SelectModelImpl<String>(null, options);
     }
 
     /**

Copied: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/AnnotationValidatorGenerator.java (from r503165, 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/AnnotationValidatorGenerator.java?view=diff&rev=503415&p1=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationConstraintGenerator.java&r1=503165&p2=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/AnnotationValidatorGenerator.java&r2=503415
==============================================================================
--- 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/AnnotationValidatorGenerator.java Sun Feb  4 06:40:39 2007
@@ -14,27 +14,48 @@
 
 package org.apache.tapestry.internal.beaneditor;
 
-import java.util.Arrays;
+import java.lang.annotation.Annotation;
 import java.util.List;
 
 import org.apache.tapestry.AnnotationProvider;
-import org.apache.tapestry.beaneditor.Validate;
-import org.apache.tapestry.services.ValidationConstraintGenerator;
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry.services.ValidatorGenerator;
 
 /**
- * Checks for the {@link Validate} annotation, and extracts its value to form the result.
+ * Checks for the various validate annotations, and use the data in the annotations to create
+ * {@link org.apache.tapestry.Validator}s.
  */
-public class ValidateAnnotationConstraintGenerator implements ValidationConstraintGenerator
+public class AnnotationValidatorGenerator implements ValidatorGenerator
 {
+    /**
+     * It will delegate this chain of commands.
+     */
+    private List<ValidateAnnotationWorker> _annotationWorkers;
 
-    public List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider)
+    public AnnotationValidatorGenerator(List<ValidateAnnotationWorker> annotationWorkers)
     {
-        Validate annotation = annotationProvider.getAnnotation(Validate.class);
+        this._annotationWorkers = annotationWorkers;
+    }
 
-        if (annotation == null)
-            return null;
-
-        return Arrays.asList(annotation.value().split(","));
+    /**
+     * For each {@link ValidateAnnotationWorker}, see if the {@link AnnotationProvider} contains
+     * the annotation the worker handles. If so, let the worker inspect the data in that annotation
+     * to create {@link Validator}s.
+     * 
+     * @return the list of validators. If none, it will return null.
+     */
+    public List<? extends Validator> buildValidators(Class propertyType,
+            AnnotationProvider annotationProvider)
+    {
+        List<Validator> result = CollectionFactory.newList();
+        for (ValidateAnnotationWorker worker : _annotationWorkers)
+        {
+            Annotation annotation = annotationProvider.getAnnotation(worker.getAnnotationClass());
+            if (annotation != null)
+                worker.addValidators(annotation, result);
+        }
+        return result;
     }
 
 }

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/LengthRangeValidateAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/LengthRangeValidateAnnotationWorker.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/LengthRangeValidateAnnotationWorker.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/LengthRangeValidateAnnotationWorker.java Sun Feb  4 06:40:39 2007
@@ -0,0 +1,44 @@
+// 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.beaneditor;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.beaneditor.LengthRange;
+import org.apache.tapestry.validator.MaxLength;
+import org.apache.tapestry.validator.MinLength;
+
+/**
+ * An {@link org.apache.tapestry.internal.beaneditor.ValidateAnnotationWorker} that handles the
+ * {@link org.apache.tapestry.beaneditor.LengthRange} annotation.
+ */
+public class LengthRangeValidateAnnotationWorker implements ValidateAnnotationWorker
+{
+
+    public Class<? extends Annotation> getAnnotationClass()
+    {
+        return LengthRange.class;
+    }
+
+    public void addValidators(Annotation annotation, List<? super Validator> result)
+    {
+        LengthRange lengthRange = (LengthRange) annotation;
+        result.add(new MinLength(lengthRange.minLength()));
+        result.add(new MaxLength(lengthRange.maxLength()));
+    }
+
+}

Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/LengthRangeValidateAnnotationWorker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/MaxValidateAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/MaxValidateAnnotationWorker.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/MaxValidateAnnotationWorker.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/MaxValidateAnnotationWorker.java Sun Feb  4 06:40:39 2007
@@ -0,0 +1,42 @@
+// 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.beaneditor;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.beaneditor.Max;
+
+/**
+ * An {@link org.apache.tapestry.internal.beaneditor.ValidateAnnotationWorker} that handles the
+ * {@link org.apache.tapestry.beaneditor.Max} annotation.
+ */
+public class MaxValidateAnnotationWorker implements ValidateAnnotationWorker
+{
+
+    public Class<? extends Annotation> getAnnotationClass()
+    {
+        return Max.class;
+    }
+
+    public void addValidators(Annotation annotation, List<? super Validator> result)
+    {
+        Max max = (Max) annotation;
+        result.add(new org.apache.tapestry.validator.Max(max.value()));
+
+    }
+
+}

Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/MaxValidateAnnotationWorker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/MinValidateAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/MinValidateAnnotationWorker.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/MinValidateAnnotationWorker.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/MinValidateAnnotationWorker.java Sun Feb  4 06:40:39 2007
@@ -0,0 +1,42 @@
+// 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.beaneditor;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.beaneditor.Min;
+
+/**
+ * An {@link org.apache.tapestry.internal.beaneditor.ValidateAnnotationWorker} that handles the
+ * {@link org.apache.tapestry.beaneditor.Min} annotation.
+ */
+public class MinValidateAnnotationWorker implements ValidateAnnotationWorker
+{
+
+    public Class<? extends Annotation> getAnnotationClass()
+    {
+        return Min.class;
+    }
+
+    public void addValidators(Annotation annotation, List<? super Validator> result)
+    {
+        Min min = (Min) annotation;
+        result.add(new org.apache.tapestry.validator.Min(min.value()));
+
+    }
+
+}

Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/MinValidateAnnotationWorker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/PrimitiveFieldValidatorGenerator.java (from r503165, 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/PrimitiveFieldValidatorGenerator.java?view=diff&rev=503415&p1=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/PrimitiveFieldConstraintGenerator.java&r1=503165&p2=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/PrimitiveFieldValidatorGenerator.java&r2=503415
==============================================================================
--- 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/PrimitiveFieldValidatorGenerator.java Sun Feb  4 06:40:39 2007
@@ -18,17 +18,21 @@
 import java.util.List;
 
 import org.apache.tapestry.AnnotationProvider;
-import org.apache.tapestry.services.ValidationConstraintGenerator;
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.services.ValidatorGenerator;
+import org.apache.tapestry.validator.Required;
 
 /**
- * Adds a "required" constraint for any property of whose type is a primitive (not a wrapper or
- * reference) type.
+ * A {@link org.apache.tapestry.services.ValidatorGenerator} that creates a
+ * {@link org.apache.tapestry.validator.Required} validator for the property if its type is a
+ * primitive (not a wrapper or reference) type.
  */
-public class PrimitiveFieldConstraintGenerator implements ValidationConstraintGenerator
+public class PrimitiveFieldValidatorGenerator implements ValidatorGenerator
 {
-    private final List<String> REQUIRED = Arrays.asList("required");
+    private final List<? extends Validator> REQUIRED = Arrays.asList(new Required());
 
-    public List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider)
+    public List<? extends Validator> buildValidators(Class propertyType,
+            AnnotationProvider annotationProvider)
     {
         return propertyType.isPrimitive() ? REQUIRED : null;
     }

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/RequiredValidateAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/RequiredValidateAnnotationWorker.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/RequiredValidateAnnotationWorker.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/RequiredValidateAnnotationWorker.java Sun Feb  4 06:40:39 2007
@@ -0,0 +1,41 @@
+// 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.beaneditor;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.beaneditor.Required;
+
+/**
+ * An {@link org.apache.tapestry.internal.beaneditor.ValidateAnnotationWorker} that handles the
+ * {@link org.apache.tapestry.beaneditor.Required} annotation.
+ */
+public class RequiredValidateAnnotationWorker implements ValidateAnnotationWorker
+{
+
+    public Class<? extends Annotation> getAnnotationClass()
+    {
+        return Required.class;
+    }
+
+    public void addValidators(Annotation annotation, List<? super Validator> result)
+    {
+        result.add(new org.apache.tapestry.validator.Required());
+        
+    }
+
+}

Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/RequiredValidateAnnotationWorker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationWorker.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationWorker.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationWorker.java Sun Feb  4 06:40:39 2007
@@ -0,0 +1,42 @@
+// 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.beaneditor;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import org.apache.tapestry.Validator;
+
+/**
+ * It handles a particular validate annotation and can create {@link org.apache.tapestry.Validator}'s
+ * according to the annotation instance.
+ */
+public interface ValidateAnnotationWorker
+{
+    /**
+     * @return the annotation class that it can handle
+     */
+    Class<? extends Annotation> getAnnotationClass();
+
+    /**
+     * Creates validators from the data in the given annotation instance and store them into the
+     * list.
+     * 
+     * @param annotation
+     * @param validators
+     */
+    void addValidators(Annotation annotation, List<? super Validator> validators);
+
+}

Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/beaneditor/ValidateAnnotationWorker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CompoundalidatorGenerator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CompoundalidatorGenerator.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CompoundalidatorGenerator.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CompoundalidatorGenerator.java Sun Feb  4 06:40:39 2007
@@ -0,0 +1,62 @@
+// 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.Defense.notNull;
+
+import java.util.List;
+
+import org.apache.tapestry.AnnotationProvider;
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry.services.ValidatorGenerator;
+
+/**
+ * A {@link org.apache.tapestry.services.ValidatorGenerator} that combines the results from on other
+ * {@link org.apache.tapestry.services.ValidatorGenerator}'s.
+ */
+public class CompoundalidatorGenerator implements ValidatorGenerator
+{
+    private final List<ValidatorGenerator> _configuration;
+
+    public CompoundalidatorGenerator(final List<ValidatorGenerator> configuration)
+    {
+        _configuration = configuration;
+    }
+
+    public List<? extends Validator> buildValidators(Class propertyType,
+            AnnotationProvider annotationProvider)
+    {
+        notNull(propertyType, "propertyType");
+        notNull(annotationProvider, "annotationProvider");
+
+        List<Validator> result = CollectionFactory.newList();
+
+        for (ValidatorGenerator g : _configuration)
+        {
+            List<? extends Validator> validators = g.buildValidators(
+                    propertyType,
+                    annotationProvider);
+
+            if (validators != null)
+                result.addAll(validators);
+        }
+
+        // TODO: How to handle duplicate or conflicting constraints from different generators?
+
+        return result.isEmpty() ? null : result;
+    }
+
+}

Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CompoundalidatorGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorImpl.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorImpl.java Sun Feb  4 06:40:39 2007
@@ -20,35 +20,33 @@
 import org.apache.tapestry.Validator;
 import org.apache.tapestry.ioc.MessageFormatter;
 
-public class FieldValidatorImpl implements FieldValidator
+public class FieldValidatorImpl<T> implements FieldValidator<T>
 {
     private final Field _field;
 
-    private final Object _constraintValue;
+    private final Validator<? super T>[] _validators;
 
-    private final MessageFormatter _messageFormatter;
+    private FieldValidatorMessages _fieldValidatorMessages;
 
-    private final Validator _validator;
-
-    public FieldValidatorImpl(Field field, Object constraintValue,
-            MessageFormatter messageFormatter, Validator validator)
+    public FieldValidatorImpl(Field field, FieldValidatorMessages fieldValidatorMessages,
+            Validator<? super T>... validators)
     {
         _field = field;
-        _constraintValue = constraintValue;
-        _messageFormatter = messageFormatter;
-        _validator = validator;
+        _fieldValidatorMessages = fieldValidatorMessages;
+        _validators = validators;
     }
 
-    @SuppressWarnings("unchecked")
-    public void validate(Object value) throws ValidationException
+    public void validate(T value) throws ValidationException
     {
-        if (! _validator.invokeIfBlank() && isBlank(value))
-            return;
-
-        if (value != null && !_validator.getValueType().isInstance(value))
+        if (_validators == null)
             return;
-
-        _validator.validate(_field, _constraintValue, _messageFormatter, value);
+        for (Validator<? super T> validator : _validators)
+        {
+            if (!validator.invokeIfBlank() && isBlank(value))
+                return;
+            MessageFormatter messageFormatter = _fieldValidatorMessages.get(_field, validator);
+            validator.validate(_field, messageFormatter, value);
+        }
     }
 
     private boolean isBlank(Object value)

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorMessages.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorMessages.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorMessages.java Sun Feb  4 06:40:39 2007
@@ -0,0 +1,29 @@
+// 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 org.apache.tapestry.Field;
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.ioc.MessageFormatter;
+
+/**
+ * Given a {@link org.apache.tapestry.Field} and a {@link org.apache.tapestry.Validator}, return a
+ * {@link org.apache.tapestry.ioc.MessageFormatter} to be used by the Validator to output error
+ * messages.
+ */
+public interface FieldValidatorMessages
+{
+    MessageFormatter get(Field field, Validator validator);
+}

Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorMessages.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorMessagesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorMessagesImpl.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorMessagesImpl.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorMessagesImpl.java Sun Feb  4 06:40:39 2007
@@ -0,0 +1,62 @@
+// 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.Defense.cast;
+
+import java.util.Locale;
+
+import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.Field;
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.ioc.MessageFormatter;
+import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.runtime.Component;
+import org.apache.tapestry.services.ValidationMessagesSource;
+
+/**
+ * A {@link org.apache.tapestry.internal.services.FieldValidatorMessages} that uses the message key
+ * of the {@link org.apache.tapestry.Validator} to look up a global
+ * {@link org.apache.tapestry.services.ValidationMessagesSource}. It will also uses
+ * <em>componentId</em>-<em>messageKey</em> to look up the messages of the container of the
+ * given field.
+ */
+public class FieldValidatorMessagesImpl implements FieldValidatorMessages
+{
+    private ValidationMessagesSource _messagesSource;
+
+    public FieldValidatorMessagesImpl(ValidationMessagesSource messagesSource)
+    {
+        _messagesSource = messagesSource;
+    }
+
+    public MessageFormatter get(Field field, Validator validator)
+    {
+        Component component = cast(field, Component.class, "field");
+        ComponentResources componentResources = component.getComponentResources();
+        String overrideId = componentResources.getId();
+        Locale locale = componentResources.getLocale();
+        Messages overrideMessages = componentResources.getContainerMessages();
+        String key = validator.getMessageKey();
+        String overrideKey = overrideId + "-" + key;
+
+        if (overrideMessages.contains(overrideKey))
+            return overrideMessages.getFormatter(overrideKey);
+
+        Messages messages = _messagesSource.getValidationMessages(locale);
+        return messages.getFormatter(key);
+    }
+
+}

Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorMessagesImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FormPersistWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FormPersistWorker.java?view=auto&rev=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FormPersistWorker.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FormPersistWorker.java Sun Feb  4 06:40:39 2007
@@ -0,0 +1,55 @@
+// Copyright 2006 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 java.lang.reflect.Modifier;
+import java.util.List;
+
+import org.apache.tapestry.annotations.FormPersist;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
+import org.apache.tapestry.model.MutableComponentModel;
+import org.apache.tapestry.services.ClassTransformation;
+import org.apache.tapestry.services.ComponentClassTransformWorker;
+import org.apache.tapestry.services.MethodSignature;
+
+/**
+ * Identifies fields with the {@link org.apache.tapestry.annotations.FormPersist} annotation, and
+ * implements the
+ * {@link org.apache.tapestry.corelib.base.AbstractField#collectFormPersistPropNames()} method
+ * to add the names of such fields.
+ */
+public final class FormPersistWorker implements ComponentClassTransformWorker
+{
+    /**
+     * Identifies fields with the {@link org.apache.tapestry.annotations.FormPersist} annotation,
+     * and implements the
+     * {@link org.apache.tapestry.corelib.base.AbstractField#collectFormPersistPropNames()}
+     * method to add the names of such fields.
+     */
+    public void transform(ClassTransformation transformation, MutableComponentModel model)
+    {
+        List<String> fieldNames = transformation.findFieldsWithAnnotation(FormPersist.class);
+        if (fieldNames.isEmpty())
+            return;
+        String body = "";
+        for (String fieldName : fieldNames)
+        {
+            body += String.format("$1.add(\"%s\");", InternalUtils.stripMemberPrefix(fieldName));
+        }
+        transformation.extendMethod(new MethodSignature(Modifier.PROTECTED, "void",
+                "collectFormPersistPropNames", new String[]
+                { List.class.getName() }, null), body);
+    }
+}

Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FormPersistWorker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java Sun Feb  4 06:40:39 2007
@@ -786,6 +786,12 @@
 
     public List<String> findFieldsWithAnnotation(final Class<? extends Annotation> annotationClass)
     {
+        return findFieldsWithAnnotation(annotationClass, false);
+    }
+
+    public List<String> findFieldsWithAnnotation(final Class<? extends Annotation> annotationClass,
+            boolean searchAncestors)
+    {
         FieldFilter filter = new FieldFilter()
         {
             public boolean accept(String fieldName, String fieldType)
@@ -824,7 +830,6 @@
         {
             throw new RuntimeException(ex);
         }
-
         Collections.sort(result);
 
         return result;

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=503415&r1=503414&r2=503415
==============================================================================
--- 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 Sun Feb  4 06:40:39 2007
@@ -30,7 +30,6 @@
 import org.apache.tapestry.MarkupWriter;
 import org.apache.tapestry.SelectModel;
 import org.apache.tapestry.Translator;
-import org.apache.tapestry.Validator;
 import org.apache.tapestry.annotations.AfterRender;
 import org.apache.tapestry.annotations.AfterRenderBody;
 import org.apache.tapestry.annotations.AfterRenderTemplate;
@@ -40,18 +39,21 @@
 import org.apache.tapestry.annotations.CleanupRender;
 import org.apache.tapestry.annotations.InjectPage;
 import org.apache.tapestry.annotations.SetupRender;
-import org.apache.tapestry.beaneditor.Validate;
 import org.apache.tapestry.dom.DefaultMarkupModel;
 import org.apache.tapestry.dom.Document;
 import org.apache.tapestry.internal.InternalConstants;
 import org.apache.tapestry.internal.TapestryUtils;
-import org.apache.tapestry.internal.beaneditor.PrimitiveFieldConstraintGenerator;
-import org.apache.tapestry.internal.beaneditor.ValidateAnnotationConstraintGenerator;
+import org.apache.tapestry.internal.beaneditor.AnnotationValidatorGenerator;
+import org.apache.tapestry.internal.beaneditor.LengthRangeValidateAnnotationWorker;
+import org.apache.tapestry.internal.beaneditor.MaxValidateAnnotationWorker;
+import org.apache.tapestry.internal.beaneditor.MinValidateAnnotationWorker;
+import org.apache.tapestry.internal.beaneditor.PrimitiveFieldValidatorGenerator;
+import org.apache.tapestry.internal.beaneditor.RequiredValidateAnnotationWorker;
+import org.apache.tapestry.internal.beaneditor.ValidateAnnotationWorker;
 import org.apache.tapestry.internal.bindings.ComponentBindingFactory;
 import org.apache.tapestry.internal.bindings.LiteralBindingFactory;
 import org.apache.tapestry.internal.bindings.MessageBindingFactory;
 import org.apache.tapestry.internal.bindings.TranslateBindingFactory;
-import org.apache.tapestry.internal.bindings.ValidateBindingFactory;
 import org.apache.tapestry.internal.services.ActionLinkHandler;
 import org.apache.tapestry.internal.services.ActionLinkHandlerImpl;
 import org.apache.tapestry.internal.services.ApplicationGlobalsImpl;
@@ -80,13 +82,14 @@
 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;
 import org.apache.tapestry.internal.services.EnvironmentalWorker;
-import org.apache.tapestry.internal.services.FieldValidatorSourceImpl;
+import org.apache.tapestry.internal.services.FieldValidatorMessages;
+import org.apache.tapestry.internal.services.FieldValidatorMessagesImpl;
 import org.apache.tapestry.internal.services.FlashPersistentFieldStrategy;
+import org.apache.tapestry.internal.services.FormPersistWorker;
 import org.apache.tapestry.internal.services.HeartbeatImpl;
 import org.apache.tapestry.internal.services.InfrastructureImpl;
 import org.apache.tapestry.internal.services.InfrastructureManagerImpl;
@@ -133,8 +136,8 @@
 import org.apache.tapestry.internal.services.TranslatorSourceImpl;
 import org.apache.tapestry.internal.services.UnclaimedFieldWorker;
 import org.apache.tapestry.internal.services.UpdateListenerHub;
-import org.apache.tapestry.internal.services.ValidationConstraintGeneratorImpl;
 import org.apache.tapestry.internal.services.ValidationMessagesSourceImpl;
+import org.apache.tapestry.internal.services.CompoundalidatorGenerator;
 import org.apache.tapestry.ioc.Configuration;
 import org.apache.tapestry.ioc.IOCUtilities;
 import org.apache.tapestry.ioc.MappedConfiguration;
@@ -166,11 +169,6 @@
 import org.apache.tapestry.translator.IntegerTranslator;
 import org.apache.tapestry.translator.LongTranslator;
 import org.apache.tapestry.translator.StringTranslator;
-import org.apache.tapestry.validator.Max;
-import org.apache.tapestry.validator.MaxLength;
-import org.apache.tapestry.validator.Min;
-import org.apache.tapestry.validator.MinLength;
-import org.apache.tapestry.validator.Required;
 
 /**
  * The root module for Tapestry.
@@ -471,7 +469,8 @@
      */
     public static void contributeInfrastructure(
             Configuration<InfrastructureContribution> configuration, ServiceLocator locator,
-            @InjectService("tapestry.ioc.TypeCoercer")
+            @InjectService("ValidatorGenerator")
+            ValidatorGenerator validatorGenerator, @InjectService("tapestry.ioc.TypeCoercer")
             TypeCoercer typeCoercer, @InjectService("tapestry.ioc.PropertyAccess")
             PropertyAccess propertyAccess)
 
@@ -491,8 +490,6 @@
                 ComponentMessagesSource.class,
                 ComponentSource.class,
                 Environment.class,
-                FieldValidatorDefaultSource.class,
-                FieldValidatorSource.class,
                 MarkupWriterFactory.class,
                 PersistentFieldManager.class,
                 Request.class,
@@ -501,9 +498,10 @@
                 Response.class,
                 TranslatorDefaultSource.class,
                 TranslatorSource.class,
-                ValidationConstraintGenerator.class,
-                ValidationMessagesSource.class);
+                ValidationMessagesSource.class,
+                FieldValidatorMessages.class);
 
+        configuration.add(new InfrastructureContribution("ValidatorGenerator", validatorGenerator));
         configuration.add(new InfrastructureContribution("TypeCoercer", typeCoercer));
         configuration.add(new InfrastructureContribution("PropertyAccess", propertyAccess));
     }
@@ -590,15 +588,13 @@
     public static void contributeBindingSource(
             MappedConfiguration<String, BindingFactory> configuration,
             @InjectService("tapestry.internal.PropBindingFactory")
-            BindingFactory propBindingFactory, @Inject("infrastructure:FieldValidatorSource")
-            FieldValidatorSource fieldValidatorSource, @Inject("infrastructure:TranslatorSource")
+            BindingFactory propBindingFactory, @Inject("infrastructure:TranslatorSource")
             TranslatorSource translatorSource)
     {
         configuration.add(InternalConstants.LITERAL_BINDING_PREFIX, new LiteralBindingFactory());
         configuration.add(InternalConstants.PROP_BINDING_PREFIX, propBindingFactory);
         configuration.add("component", new ComponentBindingFactory());
         configuration.add("message", new MessageBindingFactory());
-        configuration.add("validate", new ValidateBindingFactory(fieldValidatorSource));
         configuration.add("translate", new TranslateBindingFactory(translatorSource));
     }
 
@@ -741,6 +737,7 @@
 
         configuration.add("Retain", new RetainWorker());
         configuration.add("Persist", new PersistWorker());
+        configuration.add("RestoreOnSubmit", new FormPersistWorker());
         configuration.add("UnclaimedField", new UnclaimedFieldWorker(), "after:*.*");
     }
 
@@ -927,32 +924,11 @@
         configuration.add("tapestry/", "org/apache/tapestry/");
     }
 
-    public static FieldValidatorSource buildFieldValidatorSource(
+    public static FieldValidatorMessages buildFieldValidatorMessages(
             @Inject("infrastructure:ValidationMessagesSource")
-            ValidationMessagesSource messagesSource, @Inject("infrastructure:TypeCoercer")
-            TypeCoercer typeCoercer, Map<String, Validator> configuration)
+            ValidationMessagesSource messagesSource)
     {
-        return new FieldValidatorSourceImpl(messagesSource, typeCoercer, configuration);
-    }
-
-    /**
-     * Contributes the basic set of validators:
-     * <ul>
-     * <li>required</li>
-     * <li>minlength</li>
-     * <li>maxlength</li>
-     * <li>min</li>
-     * <li>max</li>
-     * </ul>
-     */
-    public static void contributeFieldValidatorSource(
-            MappedConfiguration<String, Validator> configuration)
-    {
-        configuration.add("required", new Required());
-        configuration.add("minlength", new MinLength());
-        configuration.add("maxlength", new MaxLength());
-        configuration.add("min", new Min());
-        configuration.add("max", new Max());
+        return new FieldValidatorMessagesImpl(messagesSource);
     }
 
     public static TranslatorSource buildTranslatorSource(Map<String, Translator> configuration)
@@ -1171,33 +1147,40 @@
         configuration.add(Boolean.class, "checkbox");
     }
 
-    public static ValidationConstraintGenerator buildValidationConstraintGenerator(
-            List<ValidationConstraintGenerator> configuration)
+    public static ValidatorGenerator buildValidatorGenerator(List<ValidatorGenerator> configuration)
     {
-        return new ValidationConstraintGeneratorImpl(configuration);
+        return new CompoundalidatorGenerator(configuration);
     }
 
     /**
-     * Adds built-in constraint generators:
+     * Adds built-in validator generators:
      * <ul>
      * <li>PrimtiveField -- primitive fields are always required
-     * <li>ValidateAnnotation -- adds constraints from a {@link Validate} annotation
+     * <li>Annotation -- adds constraints from a various annotations
      * </ul>
      */
-    public static void contributeValidationConstraintGenerator(
-            OrderedConfiguration<ValidationConstraintGenerator> configuration)
+    public static void contributeValidatorGenerator(
+            OrderedConfiguration<ValidatorGenerator> configuration,
+            @InjectService("AnnotationValidatorGenerator")
+            ValidatorGenerator annotationValidatorGenerator)
     {
-        configuration.add("PrimitiveField", new PrimitiveFieldConstraintGenerator());
-        configuration.add("ValidateAnnotation", new ValidateAnnotationConstraintGenerator());
+        configuration.add("PrimitiveField", new PrimitiveFieldValidatorGenerator());
+        configuration.add("Annotation", annotationValidatorGenerator);
     }
 
-    public static FieldValidatorDefaultSource buildFieldValidatorDefaultSource(
-            @Inject("infrastructure:ValidationConstraintGenerator")
-            ValidationConstraintGenerator validationConstraintGenerator,
-            @Inject("infrastructure:FieldValidatorSource")
-            FieldValidatorSource fieldValidatorSource)
+    public static ValidatorGenerator buildAnnotationValidatorGenerator(
+            List<ValidateAnnotationWorker> configuration)
     {
-        return new FieldValidatorDefaultSourceImpl(validationConstraintGenerator,
-                fieldValidatorSource);
+        return new AnnotationValidatorGenerator(configuration);
     }
+
+    public static void contributeAnnotationValidatorGenerator(
+            OrderedConfiguration<ValidateAnnotationWorker> configuration)
+    {
+        configuration.add("required", new RequiredValidateAnnotationWorker());
+        configuration.add("min", new MinValidateAnnotationWorker());
+        configuration.add("max", new MaxValidateAnnotationWorker());
+        configuration.add("lengthRange", new LengthRangeValidateAnnotationWorker());
+    }
+
 }

Copied: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ValidatorGenerator.java (from r503165, 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/ValidatorGenerator.java?view=diff&rev=503415&p1=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ValidationConstraintGenerator.java&r1=503165&p2=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/ValidatorGenerator.java&r2=503415
==============================================================================
--- 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/ValidatorGenerator.java Sun Feb  4 06:40:39 2007
@@ -17,30 +17,25 @@
 import java.util.List;
 
 import org.apache.tapestry.AnnotationProvider;
-import org.apache.tapestry.FieldValidator;
+import org.apache.tapestry.Validator;
 
 /**
- * Invoked to generate a list of validation constraint strings for a property. This typically
- * involves scanning the property for annotations or naming conventions that confer the desired
- * validation. The constraint strings are ultimately handed to
- * {@link FieldValidatorSource#createValidator(org.apache.tapestry.Field, String, String, String, org.apache.tapestry.ioc.Messages, java.util.Locale)}.
+ * Invoked to generate a list of {@link org.apache.tapestry.Validator} for a property. This
+ * typically involves scanning the property for annotations or naming conventions that confer the
+ * desired validation.
  */
-public interface ValidationConstraintGenerator
+public interface ValidatorGenerator
 {
     /**
-     * For a given property, identify all the approprite validation constraints. Each returned value
-     * is the name of a validator (i.e., "required") or a validator name and configuration (i.e.,
-     * "minlength=5"). These contraints are exactly the individual terms in a
-     * {@link FieldValidatorSource#createValidators(org.apache.tapestry.Field, String) validate specification}.
-     * These will ultimately be used to create {@link FieldValidator}s for the field that edits the
-     * property.
+     * For a given property, identify all the approprite validators. Each returned value is a
+     * {@link Validator} (i.e., {@link org.apache.tapestry.validator.Required}).
      * 
      * @param propertyType
-     *            the type of the property for which constraints are needed
+     *            the type of the property for which validators are needed
      * @param annotationProvider
      *            provides access to any annotations conceerning the property
-     * @return a list of constraints
-     * @see FieldValidatorSource
+     * @return a list of validators
      */
-    List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider);
+    List<? extends Validator> buildValidators(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=503415&r1=503414&r2=503415
==============================================================================
--- 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 Sun Feb  4 06:40:39 2007
@@ -72,7 +72,6 @@
 import org.apache.tapestry.services.ComponentClassResolver;
 import org.apache.tapestry.services.Context;
 import org.apache.tapestry.services.Environment;
-import org.apache.tapestry.services.FieldValidatorSource;
 import org.apache.tapestry.services.Heartbeat;
 import org.apache.tapestry.services.InjectionProvider;
 import org.apache.tapestry.services.MethodFilter;
@@ -82,7 +81,6 @@
 import org.apache.tapestry.services.ResourceDigestGenerator;
 import org.apache.tapestry.services.Response;
 import org.apache.tapestry.services.Session;
-import org.apache.tapestry.services.ValidationConstraintGenerator;
 import org.apache.tapestry.services.ValidationMessagesSource;
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
@@ -532,11 +530,6 @@
         expect(resources.getLocale()).andReturn(locale).atLeastOnce();
     }
 
-    protected <C, T> void train_getConstraintType(Validator<C, T> validator, Class<C> constraintType)
-    {
-        expect(validator.getConstraintType()).andReturn(constraintType);
-    }
-
     protected final Validator newValidator()
     {
         return newMock(Validator.class);
@@ -552,11 +545,6 @@
         return newMock(FieldValidator.class);
     }
 
-    protected FieldValidatorSource newFieldValidatorSource()
-    {
-        return newMock(FieldValidatorSource.class);
-    }
-
     protected final Component newComponent()
     {
         return newMock(Component.class);
@@ -717,11 +705,6 @@
         expect(resources.getMessages()).andReturn(messages).atLeastOnce();
     }
 
-    protected final void train_getValueType(Validator validator, Class valueType)
-    {
-        expect(validator.getValueType()).andReturn(valueType).atLeastOnce();
-    }
-
     protected final void train_invokeIfBlank(Validator validator, boolean invokeIfBlank)
     {
         expect(validator.invokeIfBlank()).andReturn(invokeIfBlank).atLeastOnce();
@@ -801,26 +784,4 @@
         return newMock(AnnotationProvider.class);
     }
 
-    protected final void train_createValidator(FieldValidatorSource source, Field field, String validatorType, String constraintValue, String overrideId, Messages overrideMessages, Locale locale, FieldValidator result)
-    {
-        expect(
-                source.createValidator(
-                        field,
-                        validatorType,
-                        constraintValue,
-                        overrideId,
-                        overrideMessages,
-                        locale)).andReturn(result);
-    }
-
-    protected final void train_buildConstraints(ValidationConstraintGenerator generator, Class propertyType, AnnotationProvider provider, String... constraints)
-    {
-        expect(generator.buildConstraints(propertyType, provider)).andReturn(
-                Arrays.asList(constraints));
-    }
-
-    protected final ValidationConstraintGenerator newValidationConstraintGenerator()
-    {
-        return newMock(ValidationConstraintGenerator.class);
-    }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java Sun Feb  4 06:40:39 2007
@@ -14,13 +14,17 @@
 
 package org.apache.tapestry.translator;
 
+import java.io.Serializable;
+
 import org.apache.tapestry.Translator;
 import org.apache.tapestry.ValidationException;
 import org.apache.tapestry.ioc.Messages;
 import org.apache.tapestry.ioc.internal.util.InternalUtils;
 
-public class DoubleTranslator implements Translator<Double>
+public class DoubleTranslator implements Translator<Double>, Serializable
 {
+    private static final long serialVersionUID = 1L;
+
     /**
      * Parses blank values to null, otherwise parses the client value to a long
      * 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/IntegerTranslator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/IntegerTranslator.java?view=diff&rev=503415&r1=503414&r2=503415
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/IntegerTranslator.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/IntegerTranslator.java Sun Feb  4 06:40:39 2007
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry.translator;
 
+import java.io.Serializable;
+
 import org.apache.tapestry.Translator;
 import org.apache.tapestry.ValidationException;
 import org.apache.tapestry.ioc.Messages;
@@ -22,8 +24,10 @@
 /**
  * A translator for type integer.
  */
-public final class IntegerTranslator implements Translator<Integer>
+public final class IntegerTranslator implements Translator<Integer>, Serializable
 {
+    private static final long serialVersionUID = 1L;
+
     /**
      * Parses blank values to null, otherwise parses the client value to an integer.
      * 



Mime
View raw message