tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r492715 - in /tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry: corelib/base/ internal/bindings/
Date Thu, 04 Jan 2007 20:14:50 GMT
Author: hlship
Date: Thu Jan  4 12:14:49 2007
New Revision: 492715

URL: http://svn.apache.org/viewvc?view=rev&rev=492715
Log:
Simplify and better document AbstractBinding, to make it easier to create one-off subclasses.

Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.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/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/ComponentBinding.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/LiteralBinding.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java?view=diff&rev=492715&r1=492714&r2=492715
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java
Thu Jan  4 12:14:49 2007
@@ -70,7 +70,7 @@
     @Mixin
     private DiscardBody _discardBody;
 
-    private static final FieldValidator NOOP_VALIDATOR = new FieldValidator()
+    protected static final FieldValidator NOOP_VALIDATOR = new FieldValidator()
     {
         public void check(Object value) throws ValidationException
         {
@@ -208,7 +208,7 @@
         // Only provide a default binding if the container actually contains the property.
         // This sets up an error condition for when the value parameter is not bound, and
         // the binding can't be deduced.
-        
+
         if (_propertyAccess.getAdapter(container).getPropertyAdapter(componentId) == null)
             return null;
 
@@ -234,13 +234,4 @@
      *            the name of the element (used to find the correct parameter in the request)
      */
     protected abstract void processSubmission(FormParameterLookup paramLookup, String elementName);
-
-    /**
-     * A field validator that does nothing. This is used as the default for subclasses' validate
-     * parameter.
-     */
-    public final FieldValidator getNoopValidator()
-    {
-        return NOOP_VALIDATOR;
-    }
 }

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=492715&r1=492714&r2=492715
==============================================================================
--- 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 Jan  4 12:14:49 2007
@@ -42,8 +42,9 @@
     @Parameter
     private Translator<Object> _translate;
 
-    @Parameter("noopValidator")
-    private FieldValidator<Object> _validate;
+    @Parameter
+    @SuppressWarnings("unchecked")
+    private FieldValidator<Object> _validate = NOOP_VALIDATOR;
 
     @Environmental
     private ValidationTracker _tracker;
@@ -78,11 +79,6 @@
                     _translator = _translatorDefaultSource.find(_resources.getBoundType("value"));
 
                 return _translator;
-            }
-
-            public Class getBindingType()
-            {
-                return get().getClass();
             }
         };
     }

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=492715&r1=492714&r2=492715
==============================================================================
--- 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 Jan  4 12:14:49 2007
@@ -20,7 +20,8 @@
 import org.apache.tapestry.services.Binding;
 
 /**
- * Abstract base class for bindings.
+ * Abstract base class for bindings. Assumes that the binding is read only and invariant.
Subclasses
+ * must provide an implementation of {@link Binding#get()}.
  */
 public abstract class AbstractBinding extends BaseLocatable implements Binding
 {
@@ -43,10 +44,21 @@
         throw new TapestryException(BindingsMessages.bindingIsReadOnly(this), this, null);
     }
 
-    /** Returns true. */
+    /**
+     * Returns true. Subclasses that do not supply a fixed, read-only value should override
this
+     * method to return false.
+     */
     public boolean isInvariant()
     {
         return true;
     }
 
+    /**
+     * Returns the actual class, by invoking {@link Binding#get()}. Subclasses may override
this
+     * method to work more efficiently (say, when the binding type is known statically).
+     */
+    public Class getBindingType()
+    {
+        return get().getClass();
+    }
 }

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=492715&r1=492714&r2=492715
==============================================================================
--- 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 Jan  4 12:14:49 2007
@@ -12,51 +12,55 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.internal.bindings;
-
+package org.apache.tapestry.internal.bindings;
+
 import org.apache.tapestry.ioc.Location;
 import org.apache.tapestry.ioc.internal.util.TapestryException;
-
-/**
- * Base class for bindings created by the
- * {@link org.apache.tapestry.internal.bindings.PropBindingFactory}. A subclass of this is
created
- * at runtime.
- */
-public abstract class BasePropBinding extends AbstractBinding
-{
-    private final String _toString;
-
-    private final Class _bindingType;
-
-    public BasePropBinding(Class bindingType, String toString, Location location)
-    {
-        super(location);
-
-        _bindingType = bindingType;
-        _toString = toString;
-    }
-
-    /** The default implementation of get() will throw a TapestryException (binding is write
only). */
-    public Object get()
-    {
-        throw new TapestryException(BindingsMessages.bindingIsWriteOnly(this), this, null);
-    }
-
-    @Override
-    public String toString()
-    {
-        return _toString;
-    }
-
-    /** Returns false; these properties are always dynamic. */
-    @Override
-    public boolean isInvariant()
-    {
-        return false;
-    }
-
-    public Class getBindingType()
-    {
-        return _bindingType;
-    }
+
+/**
+ * Base class for bindings created by the
+ * {@link org.apache.tapestry.internal.bindings.PropBindingFactory}. A subclass of this is
created
+ * at runtime.
+ */
+public abstract class BasePropBinding extends AbstractBinding
+{
+    private final String _toString;
+
+    private final Class _bindingType;
+
+    public BasePropBinding(Class bindingType, String toString, Location location)
+    {
+        super(location);
+
+        _bindingType = bindingType;
+        _toString = toString;
+    }
+
+    /**
+     * The default implementation of get() will throw a TapestryException (binding is write
only).
+     * The fabricated subclass <em>may</em> override this method (as well as
set()).
+     */
+    public Object get()
+    {
+        throw new TapestryException(BindingsMessages.bindingIsWriteOnly(this), this, null);
+    }
+
+    @Override
+    public String toString()
+    {
+        return _toString;
+    }
+
+    /** Returns false; these properties are always dynamic. */
+    @Override
+    public boolean isInvariant()
+    {
+        return false;
+    }
+
+    @Override
+    public Class getBindingType()
+    {
+        return _bindingType;
+    }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/ComponentBinding.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/ComponentBinding.java?view=diff&rev=492715&r1=492714&r2=492715
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/ComponentBinding.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/ComponentBinding.java
Thu Jan  4 12:14:49 2007
@@ -40,11 +40,6 @@
         return _resources.getEmbeddedComponent(_componentId);
     }
 
-    public Class getBindingType()
-    {
-        return get().getClass();
-    }
-
     @Override
     public String toString()
     {

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/LiteralBinding.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/LiteralBinding.java?view=diff&rev=492715&r1=492714&r2=492715
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/LiteralBinding.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/LiteralBinding.java
Thu Jan  4 12:14:49 2007
@@ -44,11 +44,4 @@
     {
         return String.format("LiteralBinding[%s: %s]", _description, _value);
     }
-
-    public Class getBindingType()
-    {
-        // Could be a problem for a LiteralBinding of null but that will certainly be read-only.
-        return _value.getClass();
-    }
-
 }



Mime
View raw message