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

svn commit: r508289 - in /tapestry/tapestry4/trunk: src/site/xdoc/usersguide/ tapestry-examples/TimeTracker/src/context/WEB-INF/ tapestry-framework/src/descriptor/META-INF/ tapestry-framework/src/java/org/apache/tapestry/binding/ tapestry-framework/src...

Author: jkuhnert
Date: Thu Feb 15 18:58:15 2007
New Revision: 508289

URL: http://svn.apache.org/viewvc?view=rev&rev=508289
Log:
Resolves TAPESTRY-1253.

First was that injections of type meta with no previous "java property" equivalent will have a default type of Object, but this property is read only since you're using the very basic meta property type. (ie read only)

Added a new "meta:" binding that will hopefully be used in 97% of the cases like yours. It works in any sort of property syntax expression so it would be easy to specify it as the intitial-value to a normal property.

Updated documentation.

Added:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/MetaBinding.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/MetaBindingFactory.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestMetaBinding.java
Modified:
    tapestry/tapestry4/trunk/src/site/xdoc/usersguide/bindings.xml
    tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Home.page
    tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/log4j.properties
    tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.bindings.xml
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhanceUtils.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/InjectMetaWorker.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/ParameterPropertyWorker.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/SpecifiedPropertyWorker.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/ComponentPropertySource.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestClientIdBinding.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestMessageBinding.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestInjectMetaWorker.java

Modified: tapestry/tapestry4/trunk/src/site/xdoc/usersguide/bindings.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/src/site/xdoc/usersguide/bindings.xml?view=diff&rev=508289&r1=508288&r2=508289
==============================================================================
--- tapestry/tapestry4/trunk/src/site/xdoc/usersguide/bindings.xml (original)
+++ tapestry/tapestry4/trunk/src/site/xdoc/usersguide/bindings.xml Thu Feb 15 18:58:15 2007
@@ -116,7 +116,14 @@
                 <td>message:page-title</td>
                 <td>ognl:messages.getMessage("page-title")</td>
             </tr>
-
+            
+            <tr>
+                <td>meta</td>
+                <td>References a meta configured value for a specific component/page or global configuration file. (such as APPNAME.application or FooComponent.jwc)</td>
+                <td>meta:renderIfTags</td>
+                <td>n/a</td>
+            </tr>
+            
             <tr>
                 <td>ognl</td>
                 <td>An OGNL expression to be evaluated.</td>

Modified: tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Home.page
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Home.page?view=diff&rev=508289&r1=508288&r2=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Home.page (original)
+++ tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Home.page Thu Feb 15 18:58:15 2007
@@ -20,12 +20,8 @@
   "http://tapestry.apache.org/dtd/Tapestry_4_0.dtd">
 
 <page-specification class="org.apache.tapestry.timetracker.page.TaskEntryPage">
-   
-   <meta key="dlHiddenMeta" value="true" />
-   <inject property="dlHidden" object="dlHiddenMeta" type="meta"/>
-   <!-- 
+
    <property name="dlHidden" initial-value="true" />
-    -->
-    
+   
 </page-specification>
 

Modified: tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/log4j.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/log4j.properties?view=diff&rev=508289&r1=508288&r2=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/log4j.properties (original)
+++ tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/log4j.properties Thu Feb 15 18:58:15 2007
@@ -32,6 +32,6 @@
 log4j.logger.org.apache.tapestry.form=DEBUG
 log4j.logger.org.apache.tapestry.form.FormSupportImpl=DEBUG
 
-log4j.logger.tapestry.services.Asset=DEBUG
+#log4j.logger.tapestry.services.Asset=DEBUG
 #log4j.logger.tapestry.globals.ResponseBuilder=DEBUG
 #log4j.logger.org.apache.tapestry.services.impl.DojoAjaxResponseBuilder=DEBUG

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.bindings.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.bindings.xml?view=diff&rev=508289&r1=508288&r2=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.bindings.xml (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.bindings.xml Thu Feb 15 18:58:15 2007
@@ -142,6 +142,18 @@
     </invoke-factory>
   </service-point>  
   
+  <service-point id="MetaBindingFactory" interface="BindingFactory">    
+      
+    Utility binding for searching for a meta property value using org.apache.tapestry.services.ComponentPropertySource for meta key/value pairs.
+    
+    <invoke-factory>
+      <construct class="MetaBindingFactory">
+        <set-object property="propertySource" value="service:tapestry.props.ComponentPropertySource"/>
+        <set-object property="valueConverter" value="infrastructure:valueConverter"/>
+      </construct>
+    </invoke-factory>
+  </service-point>
+  
   <configuration-point id="BindingFactories">
     
     Used to map binding prefixes to binding factories.
@@ -177,6 +189,7 @@
     <binding prefix="state" service-id="StateBindingFactory"/>
     <binding prefix="hivemind" service-id="HiveMindBindingFactory"/>
     <binding prefix="clientId" service-id="ClientIdBindingFactory"/>
+    <binding prefix="meta" service-id="MetaBindingFactory" />
   </contribution>
   
   <service-point id="BindingSource">

Added: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/MetaBinding.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/MetaBinding.java?view=auto&rev=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/MetaBinding.java (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/MetaBinding.java Thu Feb 15 18:58:15 2007
@@ -0,0 +1,77 @@
+// Copyright 2004, 2005 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.binding;
+
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.Location;
+import org.apache.hivemind.util.Defense;
+import org.apache.tapestry.IComponent;
+import org.apache.tapestry.coerce.ValueConverter;
+import org.apache.tapestry.services.ComponentPropertySource;
+
+
+/**
+ * Simple implementation that allows injection / lookup of meta properties.
+ */
+public class MetaBinding extends AbstractBinding
+{
+    private final IComponent _component;
+
+    private final String _key;
+
+    private final ComponentPropertySource _propertySource;
+    
+    public MetaBinding(String description, ValueConverter valueConverter, Location location, IComponent component, 
+            ComponentPropertySource propertySource, String key)
+    {
+        super(description, valueConverter, location);
+
+        Defense.notNull(component, "component");
+        Defense.notNull(propertySource, "propertySource");
+        Defense.notNull(key, "key");
+        
+        _component = component;
+        _key = key;
+        _propertySource = propertySource;
+    }
+
+    public Object getObject()
+    {
+        try
+        {
+            return _propertySource.getComponentProperty(_component, _key);
+        }
+        catch (Exception ex)
+        {
+            throw new ApplicationRuntimeException(ex.getMessage(), getLocation(), ex);
+        }
+    }
+    
+    public Object getComponent()
+    {
+        return _component;
+    }
+    
+    public String toString()
+    {
+        StringBuffer buffer = new StringBuffer("MetaBinding");
+        buffer.append('[');
+        buffer.append(_component.getExtendedId());
+        buffer.append(' ');
+        buffer.append(_key);
+        buffer.append(']');
+
+        return buffer.toString();
+    }
+}

Added: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/MetaBindingFactory.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/MetaBindingFactory.java?view=auto&rev=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/MetaBindingFactory.java (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/MetaBindingFactory.java Thu Feb 15 18:58:15 2007
@@ -0,0 +1,44 @@
+// Copyright 2004, 2005 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.binding;
+
+import org.apache.hivemind.Location;
+import org.apache.tapestry.IBinding;
+import org.apache.tapestry.IComponent;
+import org.apache.tapestry.services.ComponentPropertySource;
+
+
+/**
+ * Implementation that handles meta configured properties.
+ */
+public class MetaBindingFactory extends AbstractBindingFactory
+{
+
+    ComponentPropertySource _propertySource;
+    
+    /**
+     * {@inheritDoc}
+     */
+    public IBinding createBinding(IComponent root, String bindingDescription, String expression, Location location)
+    {
+        
+        return new MetaBinding(bindingDescription, getValueConverter(), location, root, _propertySource, expression);
+    }
+
+    /** Injected. */
+    public void setPropertySource(ComponentPropertySource source)
+    {
+        _propertySource = source;
+    }
+}

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhanceUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhanceUtils.java?view=diff&rev=508289&r1=508288&r2=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhanceUtils.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhanceUtils.java Thu Feb 15 18:58:15 2007
@@ -125,8 +125,7 @@
      *            the type of an existing property.
      */
 
-    public static Class extractPropertyType(EnhancementOperation op, String propertyName,
-            String definedTypeName)
+    public static Class extractPropertyType(EnhancementOperation op, String propertyName, String definedTypeName)
     {
         Defense.notNull(op, "op");
         Defense.notNull(propertyName, "propertyName");
@@ -139,7 +138,7 @@
 
             return propertyType;
         }
-
+        
         Class propertyType = op.getPropertyType(propertyName);
 
         return propertyType == null ? Object.class : propertyType;

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/InjectMetaWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/InjectMetaWorker.java?view=diff&rev=508289&r1=508288&r2=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/InjectMetaWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/InjectMetaWorker.java Thu Feb 15 18:58:15 2007
@@ -68,8 +68,12 @@
         Defense.notNull(metaKey, "metaKey");
 
         Class propertyType = op.getPropertyType(propertyName);
+        
+        // Default to object if not specified
+        
         if (propertyType == null) {
             
+            propertyType = Object.class;
         }
         
         op.claimReadonlyProperty(propertyName);
@@ -147,22 +151,19 @@
     private void addObject(EnhancementOperation op, String metaKey, String propertyName,
             Class propertyType, MethodSignature sig, String sourceName, Location location)
     {
-        String valueConverterName = op.addInjectedField(
-                "_$valueConverter",
-                ValueConverter.class,
-                _valueConverter);
+        String valueConverterName = op.addInjectedField("_$valueConverter", ValueConverter.class, _valueConverter);
+        
         String classRef = op.getClassReference(propertyType);
-
+        
         BodyBuilder builder = new BodyBuilder();
         builder.begin();
-        builder.addln(
-                "java.lang.String meta = {0}.getComponentProperty(this, \"{1}\");",
+        builder.addln("java.lang.String meta = {0}.getComponentProperty(this, \"{1}\");",
                 sourceName,
                 metaKey);
         builder.addln("return ({0}) {1}.coerceValue(meta, {2});", ClassFabUtils
                 .getJavaClassName(propertyType), valueConverterName, classRef);
         builder.end();
-
+        
         op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location);
     }
 

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/ParameterPropertyWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/ParameterPropertyWorker.java?view=diff&rev=508289&r1=508288&r2=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/ParameterPropertyWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/ParameterPropertyWorker.java Thu Feb 15 18:58:15 2007
@@ -74,14 +74,14 @@
         // If the parameter name doesn't match, its because this is an alias
         // for a true parameter; we ignore aliases.
 
-        if (!parameterName.equals(ps.getParameterName())) return;
-
+        if (!parameterName.equals(ps.getParameterName())) 
+            return;
+        
         String propertyName = ps.getPropertyName();
         String specifiedType = ps.getType();
         boolean cache = ps.getCache();
-
-        addParameter(op, parameterName, propertyName, specifiedType, cache, ps
-                .getLocation());
+        
+        addParameter(op, parameterName, propertyName, specifiedType, cache, ps.getLocation());
     }
 
     /**
@@ -113,9 +113,8 @@
         Defense.notNull(parameterName, "parameterName");
         Defense.notNull(propertyName, "propertyName");
 
-        Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName,
-                specifiedType);
-
+        Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, specifiedType);
+        
         // 3.0 would allow connected parameter properties to be fully
         // implemented
         // in the component class. This is not supported in 4.0 and an existing
@@ -129,7 +128,7 @@
         String fieldName = "_$" + propertyName;
         String defaultFieldName = fieldName + "$Default";
         String cachedFieldName = fieldName + "$Cached";
-
+        
         op.addField(fieldName, propertyType);
         op.addField(defaultFieldName, propertyType);
         op.addField(cachedFieldName, boolean.class);
@@ -203,11 +202,8 @@
         addBindingReference(builder, "binding", parameterName);
 
         builder.addln("if (binding == null)");
-        builder
-                .addln(
-                        "  throw new {0}(\"Parameter ''{1}'' is not bound and can not be updated.\");",
-                        ApplicationRuntimeException.class.getName(),
-                        parameterName);
+        builder.addln("  throw new {0}(\"Parameter ''{1}'' is not bound and can not be updated.\");",
+                        ApplicationRuntimeException.class.getName(), parameterName);
 
         // Always updated the binding first (which may fail with an exception).
 
@@ -225,12 +221,11 @@
 
         builder.end();
 
-        String mutatorMethodName = EnhanceUtils
-                .createMutatorMethodName(propertyName);
+        String mutatorMethodName = EnhanceUtils.createMutatorMethodName(propertyName);
 
-        op.addMethod(Modifier.PUBLIC, new MethodSignature(void.class,
-                mutatorMethodName, new Class[] { propertyType }, null), builder
-                .toString(), location);
+        op.addMethod(Modifier.PUBLIC, 
+                new MethodSignature(void.class, mutatorMethodName, new Class[] { propertyType }, null), 
+                builder.toString(), location);
     }
 
     // Package private for testing
@@ -251,8 +246,7 @@
 
         String javaTypeName = ClassFabUtils.getJavaClassName(propertyType);
 
-        builder.addln("{0} result = {1};", javaTypeName, EnhanceUtils
-                .createUnwrapExpression(op, "binding", propertyType));
+        builder.addln("{0} result = {1};", javaTypeName, EnhanceUtils.createUnwrapExpression(op, "binding", propertyType));
 
         // Values read via the binding are cached during the render of
         // the component (if the parameter defines cache to be true, which

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/SpecifiedPropertyWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/SpecifiedPropertyWorker.java?view=diff&rev=508289&r1=508288&r2=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/SpecifiedPropertyWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/SpecifiedPropertyWorker.java Thu Feb 15 18:58:15 2007
@@ -40,7 +40,6 @@
  */
 public class SpecifiedPropertyWorker implements EnhancementWorker
 {
-
     private ErrorLog _errorLog;
 
     private BindingSource _bindingSource;
@@ -93,8 +92,7 @@
             String specifiedType, boolean persistent, String initialValue,
             Location location)
     {
-        Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName,
-                specifiedType);
+        Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, specifiedType);
 
         op.claimProperty(propertyName);
 

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/ComponentPropertySource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/ComponentPropertySource.java?view=diff&rev=508289&r1=508288&r2=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/ComponentPropertySource.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/ComponentPropertySource.java Thu Feb 15 18:58:15 2007
@@ -54,8 +54,7 @@
      * 
      * @return the value of the given property name, or null if not found.
      */
-    String getLocalizedComponentProperty(IComponent component, Locale locale,
-            String propertyName);
+    String getLocalizedComponentProperty(IComponent component, Locale locale, String propertyName);
 
     /**
      * Returns the property value for a particular named meta-data property of the namespace. The
@@ -75,6 +74,5 @@
      * {@link INamespace}.
      */
 
-    String getLocalizedNamespaceProperty(INamespace namespace, Locale locale,
-            String propertyName);
+    String getLocalizedNamespaceProperty(INamespace namespace, Locale locale, String propertyName);
 }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestClientIdBinding.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestClientIdBinding.java?view=diff&rev=508289&r1=508288&r2=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestClientIdBinding.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestClientIdBinding.java Thu Feb 15 18:58:15 2007
@@ -82,4 +82,4 @@
 
         verify();
     }
-}
\ No newline at end of file
+}

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestMessageBinding.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestMessageBinding.java?view=diff&rev=508289&r1=508288&r2=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestMessageBinding.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestMessageBinding.java Thu Feb 15 18:58:15 2007
@@ -84,4 +84,4 @@
 
         verify();
     }
-}
\ No newline at end of file
+}

Added: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestMetaBinding.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestMetaBinding.java?view=auto&rev=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestMetaBinding.java (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/binding/TestMetaBinding.java Thu Feb 15 18:58:15 2007
@@ -0,0 +1,67 @@
+// Copyright 2004, 2005 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.binding;
+
+import static org.easymock.EasyMock.expect;
+
+import org.apache.hivemind.Location;
+import org.apache.tapestry.IComponent;
+import org.apache.tapestry.coerce.ValueConverter;
+import org.apache.tapestry.services.ComponentPropertySource;
+import org.testng.annotations.Test;
+
+/**
+ * Tests functionality of {@link MetaBinding}.
+ */
+@Test
+public class TestMetaBinding extends BindingTestCase
+{
+    
+    public void test_Create()
+    {
+        IComponent component = newMock(IComponent.class);
+        ValueConverter vc = newValueConverter();
+        Location l = fabricateLocation(12);
+        ComponentPropertySource src = newMock(ComponentPropertySource.class);
+        
+        expect(src.getComponentProperty(component, "key")).andReturn("wiggle");
+        
+        replay();
+
+        MetaBinding b = new MetaBinding("param", vc, l, component, src, "key");
+        
+        assertSame(component, b.getComponent());
+        assertEquals(b.getObject(), "wiggle");
+
+        verify();
+    }
+
+    public void test_To_String()
+    {
+        IComponent component = newComponent();
+        ValueConverter vc = newValueConverter();
+        Location l = fabricateLocation(12);
+        ComponentPropertySource src = newMock(ComponentPropertySource.class);
+        
+        expect(component.getExtendedId()).andReturn("Foo/bar.baz");
+        
+        replay();
+
+        MetaBinding b = new MetaBinding("param", vc, l, component, src, "key");
+        
+        assertEquals(b.toString(), "MetaBinding[Foo/bar.baz key]");
+
+        verify();
+    }
+}

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestInjectMetaWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestInjectMetaWorker.java?view=diff&rev=508289&r1=508288&r2=508289
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestInjectMetaWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestInjectMetaWorker.java Thu Feb 15 18:58:15 2007
@@ -215,39 +215,43 @@
         verify();
     }
     
-    @Test(enabled = false)
     public void test_Unimplemented_Property()
     {
         Location l = newLocation();
         InjectSpecification spec = newSpec("fooBar", "foo.bar", l);
         
         ComponentPropertySource source = newSource();
+        ValueConverter converter = newMock(ValueConverter.class);
         
         EnhancementOperation op = newMock(EnhancementOperation.class);
 
         expect(op.getPropertyType("fooBar")).andReturn(null);
-
+        
         op.claimReadonlyProperty("fooBar");
 
-        MethodSignature sig = new MethodSignature(boolean.class, "getFooBar", null, null);
-
+        MethodSignature sig = new MethodSignature(Object.class, "getFooBar", null, null);
+        
         expect(op.addInjectedField(InjectMetaWorker.SOURCE_NAME, ComponentPropertySource.class, source)).andReturn("_source");
         
         expect(op.getAccessorMethodName("fooBar")).andReturn("getFooBar");
-
+        
+        expect(op.addInjectedField("_$valueConverter", ValueConverter.class, converter)).andReturn("vc");
+        
+        expect(op.getClassReference(Object.class)).andReturn("_$Object");
+        
         BodyBuilder builder = new BodyBuilder();
         builder.begin();
         builder.addln("java.lang.String meta = _source.getComponentProperty(this, \"foo.bar\");");
-        builder.addln("return java.lang.Boolean.valueOf(meta).booleanValue();");
+        builder.addln("return (java.lang.Object) vc.coerceValue(meta, _$Object);");
         builder.end();
-
+        
         op.addMethod(Modifier.PUBLIC, sig, builder.toString(), l);
 
         replay();
 
         InjectMetaWorker worker = new InjectMetaWorker();
-
         worker.setSource(source);
+        worker.setValueConverter(converter);
 
         worker.performEnhancement(op, spec);