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

svn commit: r607895 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry/internal/ main/java/org/apache/tapestry/internal/services/ main/java/org/apache/tapestry/internal/structure/ main/java/org/apache/tapestry/internal/test...

Author: hlship
Date: Tue Jan  1 11:33:19 2008
New Revision: 607895

URL: http://svn.apache.org/viewvc?rev=607895&view=rev
Log:
TAPESTRY-2005: Using component classes as component parameters fails (Could not find a coercion)

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassCache.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassCacheImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ComponentParameter.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/components/ActionLinkIndirect.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ComponentParameter.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/InternalComponentResources.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageElementFactoryImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ParameterWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/MarkupWriterFactory.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridDemo.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentEventImplTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageElementFactoryImplTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/InternalComponentResources.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/InternalComponentResources.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/InternalComponentResources.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/InternalComponentResources.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -34,6 +34,16 @@
      * @return the value for the parameter, or null if the parameter is not bound.
      */
     <T> T readParameter(String parameterName, Class<T> expectedType);
+
+    /**
+     * Used by generated component code to read a parameter value.
+     *
+     * @param parameterName   the name of the parameter to read
+     * @param desiredTypeName the class name of the desired value (classes will be resolved in the
+     *                        component class loader)
+     * @return the value coerced to the correct type
+     */
+    Object readParameter(String parameterName, String desiredTypeName);
 
     /**
      * Updates a parameter. It is an error to update a parameter which is not bound. The parameter

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassCache.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassCache.java?rev=607895&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassCache.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassCache.java Tue Jan  1 11:33:19 2008
@@ -0,0 +1,30 @@
+// Copyright 2008 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;
+
+/**
+ * A cache for converting between class names and component (or other) classes.  For component classes,
+ * ensures that the class is the transformed class.
+ */
+public interface ComponentClassCache
+{
+    /**
+     * Gets the Class instance for the give name.
+     *
+     * @param className fully qualified class name
+     * @return the class instance
+     */
+    Class forName(String className);
+}

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassCacheImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassCacheImpl.java?rev=607895&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassCacheImpl.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassCacheImpl.java Tue Jan  1 11:33:19 2008
@@ -0,0 +1,62 @@
+// Copyright 2008 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.internal.events.InvalidationListener;
+import org.apache.tapestry.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry.ioc.services.ClassFactory;
+
+import java.util.Map;
+
+public class ComponentClassCacheImpl implements ComponentClassCache, InvalidationListener
+{
+    private final Map<String, Class> _cache = CollectionFactory.newConcurrentMap();
+
+    private final ClassFactory _classFactory;
+
+    public ComponentClassCacheImpl(ClassFactory classFactory)
+    {
+        _classFactory = classFactory;
+    }
+
+    public void objectWasInvalidated()
+    {
+        _cache.clear();
+    }
+
+
+    public Class forName(final String className)
+    {
+        Class result = _cache.get(className);
+
+        if (result == null)
+        {
+            ClassLoader componentLoader = _classFactory.getClassLoader();
+
+            try
+            {
+                result = Class.forName(className, true, componentLoader);
+            }
+            catch (ClassNotFoundException ex)
+            {
+                throw new RuntimeException(ex);
+            }
+
+            _cache.put(className, result);
+        }
+
+        return result;
+    }
+}

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -15,8 +15,6 @@
 package org.apache.tapestry.internal.services;
 
 import org.apache.tapestry.ComponentEventHandler;
-import static org.apache.tapestry.ioc.internal.util.Defense.notBlank;
-import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
 import org.apache.tapestry.ioc.services.TypeCoercer;
 import org.apache.tapestry.runtime.ComponentEvent;
 
@@ -30,7 +28,7 @@
 
     private final TypeCoercer _typeCoercer;
 
-    private final ClassLoader _classLoader;
+    private final ComponentClassCache _componentClassCache;
 
     /**
      * @param eventType              non blank string used to identify the type of event that was triggered
@@ -44,15 +42,16 @@
      *                               is the class loader used to create the component class; that loader's parent is the Thread's context class loader).
      */
     public ComponentEventImpl(String eventType, String originatingComponentId, Object[] context,
-                              ComponentEventHandler handler, TypeCoercer typeCoercer, ClassLoader classLoader)
+                              ComponentEventHandler handler, TypeCoercer typeCoercer,
+                              ComponentClassCache componentClassCache)
     {
         super(handler);
 
-        _eventType = notBlank(eventType, "eventType");
+        _eventType = eventType;
         _originatingComponentId = originatingComponentId;
         _context = context != null ? context : new Object[0];
-        _typeCoercer = notNull(typeCoercer, "typeCoercer");
-        _classLoader = classLoader;
+        _typeCoercer = typeCoercer;
+        _componentClassCache = componentClassCache;
     }
 
     public boolean matches(String eventType, String componentId, int parameterCount)
@@ -69,7 +68,7 @@
                 .contextIndexOutOfRange(getMethodDescription()));
         try
         {
-            Class desiredType = Class.forName(desiredTypeName, true, _classLoader);
+            Class desiredType = _componentClassCache.forName(desiredTypeName);
 
             return _typeCoercer.coerce(_context[index], desiredType);
         }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageElementFactoryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageElementFactoryImpl.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageElementFactoryImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageElementFactoryImpl.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -41,6 +41,8 @@
 
     private final TypeCoercer _typeCoercer;
 
+    private final ComponentClassCache _componentClassCache;
+
     private final BindingSource _bindingSource;
 
     private final ComponentMessagesSource _messagesSource;
@@ -63,12 +65,14 @@
     }
 
     public PageElementFactoryImpl(ComponentInstantiatorSource componentInstantiatorSource,
-                                  ComponentClassResolver resolver, TypeCoercer typeCoercer, BindingSource bindingSource,
+                                  ComponentClassResolver resolver, TypeCoercer typeCoercer,
+                                  ComponentClassCache componentClassCache, BindingSource bindingSource,
                                   ComponentMessagesSource messagesSource)
     {
         _componentInstantiatorSource = componentInstantiatorSource;
         _componentClassResolver = resolver;
         _typeCoercer = typeCoercer;
+        _componentClassCache = componentClassCache;
         _bindingSource = bindingSource;
         _messagesSource = messagesSource;
     }
@@ -253,7 +257,8 @@
             // template.
 
             ComponentPageElementImpl result = new ComponentPageElementImpl(page, container, id, elementName,
-                                                                           instantiator, _typeCoercer, _messagesSource,
+                                                                           instantiator, _typeCoercer,
+                                                                           _componentClassCache, _messagesSource,
                                                                            location);
 
             page.addLifecycleListener(result);
@@ -292,7 +297,7 @@
         Instantiator instantiator = _componentInstantiatorSource.findInstantiator(componentType);
 
         ComponentPageElementImpl result = new ComponentPageElementImpl(page, instantiator, _typeCoercer,
-                                                                       _messagesSource);
+                                                                       _componentClassCache, _messagesSource);
 
         addMixins(result, instantiator);
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ParameterWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ParameterWorker.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ParameterWorker.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ParameterWorker.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -65,15 +65,14 @@
         convertFieldsIntoParameters(transformation, model, fieldNames);
     }
 
-    private void convertFieldsIntoParameters(ClassTransformation transformation,
-                                             MutableComponentModel model, List<String> fieldNames)
+    private void convertFieldsIntoParameters(ClassTransformation transformation, MutableComponentModel model,
+                                             List<String> fieldNames)
     {
         for (String name : fieldNames)
             convertFieldIntoParameter(name, transformation, model);
     }
 
-    private void convertFieldIntoParameter(String name, ClassTransformation transformation,
-                                           MutableComponentModel model)
+    private void convertFieldIntoParameter(String name, ClassTransformation transformation, MutableComponentModel model)
     {
         Parameter annotation = transformation.getFieldAnnotation(name, Parameter.class);
 
@@ -85,40 +84,18 @@
 
         boolean cache = annotation.cache();
 
-        String cachedFieldName = transformation.addField(Modifier.PRIVATE, "boolean", name
-                + "_cached");
+        String cachedFieldName = transformation.addField(Modifier.PRIVATE, "boolean", name + "_cached");
 
         String resourcesFieldName = transformation.getResourcesFieldName();
 
-        String invariantFieldName = addParameterSetup(
-                name,
-                annotation.defaultPrefix(),
-                annotation.value(),
-                parameterName,
-                cachedFieldName,
-                cache,
-                type,
-                resourcesFieldName,
-                transformation);
-
-        addReaderMethod(
-                name,
-                cachedFieldName,
-                invariantFieldName,
-                cache,
-                parameterName,
-                type,
-                resourcesFieldName,
-                transformation);
-
-        addWriterMethod(
-                name,
-                cachedFieldName,
-                cache,
-                parameterName,
-                type,
-                resourcesFieldName,
-                transformation);
+        String invariantFieldName = addParameterSetup(name, annotation.defaultPrefix(), annotation.value(),
+                                                      parameterName, cachedFieldName, cache, type, resourcesFieldName,
+                                                      transformation);
+
+        addReaderMethod(name, cachedFieldName, invariantFieldName, cache, parameterName, type, resourcesFieldName,
+                        transformation);
+
+        addWriterMethod(name, cachedFieldName, cache, parameterName, type, resourcesFieldName, transformation);
 
         transformation.claimField(name, annotation);
     }
@@ -130,28 +107,17 @@
                                      String parameterName, String cachedFieldName, boolean cache, String fieldType,
                                      String resourcesFieldName, ClassTransformation transformation)
     {
-        String defaultFieldName = transformation.addField(Modifier.PRIVATE, fieldType, fieldName
-                + "_default");
+        String defaultFieldName = transformation.addField(Modifier.PRIVATE, fieldType, fieldName + "_default");
 
-        String invariantFieldName = transformation.addField(Modifier.PRIVATE, "boolean", fieldName
-                + "_invariant");
+        String invariantFieldName = transformation.addField(Modifier.PRIVATE, "boolean", fieldName + "_invariant");
 
         BodyBuilder builder = new BodyBuilder();
         builder.begin();
 
-        addDefaultBindingSetup(
-                parameterName,
-                defaultPrefix,
-                defaultBinding,
-                resourcesFieldName,
-                transformation,
-                builder);
-
-        builder.addln(
-                "%s = %s.isInvariant(\"%s\");",
-                invariantFieldName,
-                resourcesFieldName,
-                parameterName);
+        addDefaultBindingSetup(parameterName, defaultPrefix, defaultBinding, resourcesFieldName, transformation,
+                               builder);
+
+        builder.addln("%s = %s.isInvariant(\"%s\");", invariantFieldName, resourcesFieldName, parameterName);
 
         // Store the current value of the field into the default field. This value will
         // be used to reset the field after rendering.
@@ -184,28 +150,20 @@
         return invariantFieldName;
     }
 
-    private void addDefaultBindingSetup(String parameterName, String defaultPrefix,
-                                        String defaultBinding, String resourcesFieldName,
-                                        ClassTransformation transformation,
+    private void addDefaultBindingSetup(String parameterName, String defaultPrefix, String defaultBinding,
+                                        String resourcesFieldName, ClassTransformation transformation,
                                         BodyBuilder builder)
     {
         if (InternalUtils.isNonBlank(defaultBinding))
         {
             builder.addln("if (! %s.isBound(\"%s\"))", resourcesFieldName, parameterName);
 
-            String bindingFactoryFieldName = transformation.addInjectedField(
-                    BindingSource.class,
-                    "bindingSource",
-                    _bindingSource);
+            String bindingFactoryFieldName = transformation.addInjectedField(BindingSource.class, "bindingSource",
+                                                                             _bindingSource);
 
             builder
-                    .addln(
-                            "  %s.bindParameter(\"%s\", %s.newBinding(\"default %2$s\", %1$s, \"%s\", \"%s\"));",
-                            resourcesFieldName,
-                            parameterName,
-                            bindingFactoryFieldName,
-                            defaultPrefix,
-                            defaultBinding);
+                    .addln("  %s.bindParameter(\"%s\", %s.newBinding(\"default %2$s\", %1$s, \"%s\", \"%s\"));",
+                           resourcesFieldName, parameterName, bindingFactoryFieldName, defaultPrefix, defaultBinding);
 
             return;
 
@@ -220,8 +178,7 @@
         {
             public boolean accept(TransformMethodSignature signature)
             {
-                return signature.getParameterTypes().length == 0
-                        && signature.getMethodName().equals(methodName);
+                return signature.getParameterTypes().length == 0 && signature.getMethodName().equals(methodName);
             }
         };
 
@@ -230,21 +187,14 @@
 
         List<TransformMethodSignature> signatures = transformation.findMethods(filter);
 
-        if (signatures.isEmpty())
-            return;
+        if (signatures.isEmpty()) return;
 
         builder.addln("if (! %s.isBound(\"%s\"))", resourcesFieldName, parameterName);
-        builder.addln(
-                "  %s(\"%s\", %s, %s());",
-                BIND_METHOD_NAME,
-                parameterName,
-                resourcesFieldName,
-                methodName);
+        builder.addln("  %s(\"%s\", %s, %s());", BIND_METHOD_NAME, parameterName, resourcesFieldName, methodName);
     }
 
-    private void addWriterMethod(String fieldName, String cachedFieldName, boolean cache,
-                                 String parameterName, String fieldType, String resourcesFieldName,
-                                 ClassTransformation transformation)
+    private void addWriterMethod(String fieldName, String cachedFieldName, boolean cache, String parameterName,
+                                 String fieldType, String resourcesFieldName, ClassTransformation transformation)
     {
         BodyBuilder builder = new BodyBuilder();
         builder.begin();
@@ -268,16 +218,14 @@
 
         builder.addln("%s = $1;", fieldName);
 
-        if (cache)
-            builder.addln("%s = %s.isRendering();", cachedFieldName, resourcesFieldName);
+        if (cache) builder.addln("%s = %s.isRendering();", cachedFieldName, resourcesFieldName);
 
         builder.end();
 
         String methodName = transformation.newMemberName("update_parameter", parameterName);
 
         TransformMethodSignature signature = new TransformMethodSignature(Modifier.PRIVATE, "void", methodName,
-                                                                          new String[]
-                                                                                  {fieldType}, null);
+                                                                          new String[]{fieldType}, null);
 
         transformation.addMethod(signature, builder.toString());
 
@@ -287,9 +235,9 @@
     /**
      * Adds a private method that will be the replacement for read-access to the field.
      */
-    private void addReaderMethod(String fieldName, String cachedFieldName,
-                                 String invariantFieldName, boolean cache, String parameterName, String fieldType,
-                                 String resourcesFieldName, ClassTransformation transformation)
+    private void addReaderMethod(String fieldName, String cachedFieldName, String invariantFieldName, boolean cache,
+                                 String parameterName, String fieldType, String resourcesFieldName,
+                                 ClassTransformation transformation)
     {
         BodyBuilder builder = new BodyBuilder();
         builder.begin();
@@ -297,25 +245,19 @@
         // While the component is still loading, or when the value for the component is cached,
         // or if the value is not bound, then return the current value of the field.
 
-        builder.addln(
-                "if (%s || ! %s.isLoaded() || ! %<s.isBound(\"%s\")) return %s;",
-                cachedFieldName,
-                resourcesFieldName,
-                parameterName,
-                fieldName);
+        builder.addln("if (%s || ! %s.isLoaded() || ! %<s.isBound(\"%s\")) return %s;", cachedFieldName,
+                      resourcesFieldName, parameterName, fieldName);
 
         String cast = TransformUtils.getWrapperTypeName(fieldType);
 
         // The ($r) cast will convert the result to the method return type; generally
         // this does nothing. but for primitive types, it will unwrap
-        // the wrapper type back to a primitive.
+        // the wrapper type back to a primitive.  We pass the desired type name
+        // to readParameter(), since its easier to convert it properly to
+        // a type on that end than in the generated code.
 
-        builder.addln(
-                "%s result = ($r) ((%s) %s.readParameter(\"%s\", $type));",
-                fieldType,
-                cast,
-                resourcesFieldName,
-                parameterName);
+        builder.addln("%s result = ($r) ((%s) %s.readParameter(\"%s\", \"%2$s\"));", fieldType, cast,
+                      resourcesFieldName, parameterName);
 
         // If the binding is invariant, then it's ok to cache. Othewise, its only
         // ok to cache if a) the @Parameter says to cache and b) the component
@@ -323,8 +265,7 @@
 
         builder.add("if (%s", invariantFieldName);
 
-        if (cache)
-            builder.add(" || %s.isRendering()", resourcesFieldName);
+        if (cache) builder.add(" || %s.isRendering()", resourcesFieldName);
 
         builder.addln(")");
         builder.begin();
@@ -337,8 +278,8 @@
 
         String methodName = transformation.newMemberName("read_parameter", parameterName);
 
-        TransformMethodSignature signature = new TransformMethodSignature(Modifier.PRIVATE, fieldType, methodName,
-                                                                          null, null);
+        TransformMethodSignature signature = new TransformMethodSignature(Modifier.PRIVATE, fieldType, methodName, null,
+                                                                          null);
 
         transformation.addMethod(signature, builder.toString());
 
@@ -347,16 +288,14 @@
 
     private String getParameterName(String fieldName, String annotatedName)
     {
-        if (InternalUtils.isNonBlank(annotatedName))
-            return annotatedName;
+        if (InternalUtils.isNonBlank(annotatedName)) return annotatedName;
 
         return InternalUtils.stripMemberPrefix(fieldName);
     }
 
     public static void bind(String parameterName, InternalComponentResources resources, Object value)
     {
-        if (value == null)
-            return;
+        if (value == null) return;
 
         if (value instanceof Binding)
         {
@@ -366,7 +305,6 @@
             return;
         }
 
-        resources.bindParameter(parameterName, new LiteralBinding("default " + parameterName,
-                                                                  value, null));
+        resources.bindParameter(parameterName, new LiteralBinding("default " + parameterName, value, null));
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -18,6 +18,7 @@
 import org.apache.tapestry.dom.Element;
 import org.apache.tapestry.internal.InternalComponentResources;
 import org.apache.tapestry.internal.TapestryInternalUtils;
+import org.apache.tapestry.internal.services.ComponentClassCache;
 import org.apache.tapestry.internal.services.ComponentEventImpl;
 import org.apache.tapestry.internal.services.EventImpl;
 import org.apache.tapestry.internal.services.Instantiator;
@@ -491,7 +492,7 @@
 
     private final TypeCoercer _typeCoercer;
 
-    private final ClassLoader _classLoader;
+    private final ComponentClassCache _componentClassCache;
 
     /**
      * Constructor for other components embedded within the root component or at deeper levels of
@@ -511,7 +512,8 @@
 
     public ComponentPageElementImpl(Page page, ComponentPageElement container, String id, String elementName,
                                     Instantiator instantiator, TypeCoercer typeCoercer,
-                                    ComponentMessagesSource messagesSource, Location location)
+                                    ComponentClassCache componentClassCache, ComponentMessagesSource messagesSource,
+                                    Location location)
     {
         super(location);
 
@@ -520,18 +522,18 @@
         _id = id;
         _elementName = elementName;
         _typeCoercer = typeCoercer;
+        _componentClassCache = componentClassCache;
+
         _messagesSource = messagesSource;
 
         ComponentResources containerResources = container == null ? null : container
                 .getComponentResources();
 
         _coreResources = new InternalComponentResourcesImpl(this, containerResources, instantiator, _typeCoercer,
-                                                            _messagesSource);
+                                                            _messagesSource, _componentClassCache);
 
         _coreComponent = _coreResources.getComponent();
 
-        _classLoader = _coreComponent.getClass().getClassLoader();
-
         String pageName = _page.getLogicalName();
 
         // A page (really, the root component of a page) does not have a container.
@@ -567,9 +569,9 @@
      * Constructor for the root component of a page.
      */
     public ComponentPageElementImpl(Page page, Instantiator instantiator, TypeCoercer typeCoercer,
-                                    ComponentMessagesSource messagesSource)
+                                    ComponentClassCache componentClassCache, ComponentMessagesSource messagesSource)
     {
-        this(page, null, null, null, instantiator, typeCoercer, messagesSource, null);
+        this(page, null, null, null, instantiator, typeCoercer, componentClassCache, messagesSource, null);
     }
 
     public void addEmbeddedElement(ComponentPageElement child)
@@ -598,7 +600,8 @@
 
         InternalComponentResourcesImpl resources = new InternalComponentResourcesImpl(this, _coreResources,
                                                                                       instantiator, _typeCoercer,
-                                                                                      _messagesSource);
+                                                                                      _messagesSource,
+                                                                                      _componentClassCache);
 
         // TODO: Check for name collision?
 
@@ -977,7 +980,7 @@
         while (component != null)
         {
             ComponentEvent event = new ComponentEventImpl(eventType, componentId, context, wrappedHandler, _typeCoercer,
-                                                          _classLoader);
+                                                          _componentClassCache);
 
             result |= component.handleEvent(event);
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -16,6 +16,7 @@
 
 import org.apache.tapestry.*;
 import org.apache.tapestry.internal.InternalComponentResources;
+import org.apache.tapestry.internal.services.ComponentClassCache;
 import org.apache.tapestry.internal.services.Instantiator;
 import org.apache.tapestry.ioc.AnnotationProvider;
 import org.apache.tapestry.ioc.Location;
@@ -50,6 +51,8 @@
 
     private final ComponentResources _containerResources;
 
+    private final ComponentClassCache _componentClassCache;
+
     // Case insensitive
     private Map<String, Binding> _bindings;
 
@@ -57,12 +60,14 @@
 
     private Messages _messages;
 
-    public InternalComponentResourcesImpl(ComponentPageElement element,
-                                          ComponentResources containerResources, Instantiator componentInstantiator,
-                                          TypeCoercer typeCoercer, ComponentMessagesSource messagesSource)
+    public InternalComponentResourcesImpl(ComponentPageElement element, ComponentResources containerResources,
+                                          Instantiator componentInstantiator, TypeCoercer typeCoercer,
+                                          ComponentMessagesSource messagesSource,
+                                          ComponentClassCache componentClassCache)
     {
         _element = element;
         _containerResources = containerResources;
+        _componentClassCache = componentClassCache;
         _componentModel = componentInstantiator.getModel();
         _typeCoercer = typeCoercer;
         _messagesSource = messagesSource;
@@ -171,10 +176,8 @@
         }
         catch (Exception ex)
         {
-            throw new TapestryException(StructureMessages.fieldPersistFailure(
-                    getCompleteId(),
-                    fieldName,
-                    ex), getLocation(), ex);
+            throw new TapestryException(StructureMessages.fieldPersistFailure(getCompleteId(), fieldName, ex),
+                                        getLocation(), ex);
         }
     }
 
@@ -201,13 +204,18 @@
         }
         catch (Exception ex)
         {
-            throw new TapestryException(StructureMessages.getParameterFailure(
-                    parameterName,
-                    getCompleteId(),
-                    ex), b, ex);
+            throw new TapestryException(StructureMessages.getParameterFailure(parameterName, getCompleteId(), ex), b,
+                                        ex);
         }
     }
 
+    public Object readParameter(String parameterName, String desiredTypeName)
+    {
+        Class parameterType = _componentClassCache.forName(desiredTypeName);
+
+        return readParameter(parameterName, parameterType);
+    }
+
     public Class getBoundType(String parameterName)
     {
         Binding b = getBinding(parameterName);
@@ -230,10 +238,8 @@
         }
         catch (Exception ex)
         {
-            throw new TapestryException(StructureMessages.writeParameterFailure(
-                    parameterName,
-                    getCompleteId(),
-                    ex), b, ex);
+            throw new TapestryException(StructureMessages.writeParameterFailure(parameterName, getCompleteId(), ex), b,
+                                        ex);
         }
     }
 
@@ -308,8 +314,7 @@
 
     public Messages getMessages()
     {
-        if (_messages == null)
-            _messages = _messagesSource.getMessages(_componentModel, getLocale());
+        if (_messages == null) _messages = _messagesSource.getMessages(_componentModel, getLocale());
 
         return _messages;
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -530,5 +530,15 @@
     protected final void train_detached(Page page, boolean dirty)
     {
         expect(page.detached()).andReturn(dirty);
+    }
+
+    protected void train_forName(ComponentClassCache cache, String className, Class cachedClass)
+    {
+        expect(cache.forName(className)).andReturn(cachedClass).atLeastOnce();
+    }
+
+    protected final ComponentClassCache mockComponentClassCache()
+    {
+        return newMock(ComponentClassCache.class);
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/MarkupWriterFactory.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/MarkupWriterFactory.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/MarkupWriterFactory.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/MarkupWriterFactory.java Tue Jan  1 11:33:19 2008
@@ -1,17 +1,17 @@
-// Copyright 2006, 2007 The Apache Software Foundation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// 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 andand
-// limitations under the License.
-
+// Copyright 2006, 2007 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
 package org.apache.tapestry.services;
 
 import org.apache.tapestry.MarkupWriter;

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -113,6 +113,7 @@
         binder.bind(PageRenderQueue.class, PageRenderQueueImpl.class);
         binder.bind(AjaxPartialResponseRenderer.class, AjaxPartialResponseRendererImpl.class);
         binder.bind(PageContentTypeAnalyzer.class, PageContentTypeAnalyzerImpl.class);
+
     }
 
     public static Alias build(Logger logger,
@@ -2051,4 +2052,12 @@
         configuration.add("Ajax", new AjaxFilter(_request, ajaxHandler));
     }
 
+    public ComponentClassCache buildComponentClassCache(@ComponentLayer ClassFactory classFactory)
+    {
+        ComponentClassCacheImpl service = new ComponentClassCacheImpl(classFactory);
+
+        _componentInstantiatorSource.addInvalidationListener(service);
+
+        return service;
+    }
 }

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ComponentParameter.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ComponentParameter.tml?rev=607895&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ComponentParameter.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ComponentParameter.tml Tue Jan  1 11:33:19 2008
@@ -0,0 +1,17 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+    <h1>Component as Parameter</h1>
+
+    <p>Tests the ability to use a component type as a parameter.</p>
+
+    <t:if test="message">
+        <p>${message}</p>
+    </t:if>
+
+    <t:block>
+        <t:actionlink t:id="blockAction">click me</t:actionlink>
+    </t:block>
+
+    <t:actionlinkindirect component="blockAction"/>
+
+</html>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridDemo.tml?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/GridDemo.tml Tue Jan  1 11:33:19 2008
@@ -1,11 +1,11 @@
 <html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
-    
+
     <h1>Grid Demo</h1>
-    
+
     <table t:type="Grid" source="tracks" row="track">
         <t:parameter name="ratingcell">
             <t:outputRating rating="track.rating"/>
         </t:parameter>
     </table>
-    
+
 </html>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml Tue Jan  1 11:33:19 2008
@@ -285,6 +285,12 @@
             -- Demo the autocomplete mixin for text fields.
         </li>
 
+        <li>
+            <t:pagelink page="componentparameter">ComponentParameter Demo</t:pagelink>
+            -- Demo using a component type as a parameter type and succesfuly passing
+            a component
+        </li>
+
     </ul>
 
 </html>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml Tue Jan  1 11:33:19 2008
@@ -1,6 +1,6 @@
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
 <!-- 
-   Copyright 2007 The Apache Software Foundation
+   Copyright 2008 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.

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -1236,5 +1236,21 @@
         // Commented out ... Selenium can't seem to handle an XML response.
 
         // assertSourcePresent("<![CDATA[< & >]]>");
+    }
+
+    /**
+     * Tests TAPESTRY-2005.
+     */
+    @Test
+    public void components_passed_as_parameters() throws Exception
+    {
+        start("ComponentParameter Demo");
+
+        // This component is inside a block, and is only rendered because it is passed as a parameter, of type ActionLink,
+        // to an ActionLinkIndirect component.
+
+        clickAndWait("link=click me");
+
+        assertTextPresent("Link was clicked.");
     }
 }

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/components/ActionLinkIndirect.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/components/ActionLinkIndirect.java?rev=607895&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/components/ActionLinkIndirect.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/components/ActionLinkIndirect.java Tue Jan  1 11:33:19 2008
@@ -0,0 +1,40 @@
+// Copyright 2008 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.integration.app1.components;
+
+import org.apache.tapestry.MarkupWriter;
+import org.apache.tapestry.annotations.Parameter;
+import org.apache.tapestry.corelib.components.ActionLink;
+
+public class ActionLinkIndirect
+{
+    /**
+     * The component to be rendered.
+     */
+    @Parameter(required = true, defaultPrefix = "component")
+    private ActionLink _component;
+
+    Object beginRender(MarkupWriter writer)
+    {
+        writer.element("p");
+
+        return _component;
+    }
+
+    void afterRender(MarkupWriter writer)
+    {
+        writer.end(); // p
+    }
+}

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ComponentParameter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ComponentParameter.java?rev=607895&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ComponentParameter.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ComponentParameter.java Tue Jan  1 11:33:19 2008
@@ -0,0 +1,35 @@
+// Copyright 2008 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.integration.app1.pages;
+
+import org.apache.tapestry.annotations.Persist;
+
+public class ComponentParameter
+{
+    @Persist("flash")
+    private String _message;
+
+
+    public String getMessage()
+    {
+        return _message;
+    }
+
+    void onActionFromBlockAction()
+    {
+        _message = "Link was clicked.";
+    }
+
+}

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentEventImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentEventImplTest.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentEventImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentEventImplTest.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -101,11 +101,14 @@
     public void coerce_context()
     {
         ComponentEventHandler handler = mockComponentEventHandler();
+        ComponentClassCache cache = mockComponentClassCache();
+
+        train_forName(cache, "java.lang.Integer", Integer.class);
 
         replay();
 
         ComponentEvent event = new ComponentEventImpl("eventType", "someId", new String[]{"27"}, handler, _coercer,
-                                                      null);
+                                                      cache);
 
         assertEquals(event.coerceContext(0, "java.lang.Integer"), new Integer(27));
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageElementFactoryImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageElementFactoryImplTest.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageElementFactoryImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageElementFactoryImplTest.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -48,7 +48,7 @@
 
         replay();
 
-        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, null, null, null);
+        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, null, null, null, null);
         StartElementToken token = new StartElementToken("http://foo.com", "fred", l);
 
         PageElement element = factory.newStartElement(token);
@@ -75,7 +75,7 @@
 
         replay();
 
-        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, null, null, null);
+        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, null, null, null, null);
         AttributeToken token = new AttributeToken(null, "name", "value", l);
 
         PageElement element = factory.newAttributeElement(null, token);
@@ -99,7 +99,7 @@
 
         replay();
 
-        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, null, null, null);
+        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, null, null, null, null);
 
         PageElement element = factory.newEndElement();
 
@@ -125,7 +125,7 @@
 
         replay();
 
-        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, null, null, null);
+        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, null, null, null, null);
 
         PageElement element1 = factory.newEndElement();
         PageElement element2 = factory.newEndElement();
@@ -146,7 +146,7 @@
 
         replay();
 
-        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, null, null, null);
+        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, null, null, null, null);
         TextToken token = new TextToken("some text", l);
 
         PageElement element = factory.newTextElement(token);
@@ -173,7 +173,7 @@
 
         replay();
 
-        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, null, null, null);
+        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, null, null, null, null);
 
         PageElement element = factory.newRenderBodyElement(component);
 
@@ -197,7 +197,7 @@
 
         replay();
 
-        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, typeCoercer, bindingSource,
+        PageElementFactory factory = new PageElementFactoryImpl(source, resolver, typeCoercer, null, bindingSource,
                                                                 messagesSource);
 
         try

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -119,7 +119,7 @@
 
         train_isLoaded(resources, true);
         train_isBound(resources, "invariantPrimitive", true);
-        train_readParameter(resources, "invariantPrimitive", long.class, value);
+        train_readParameter(resources, "invariantPrimitive", Long.class, value);
 
         replay();
 
@@ -354,7 +354,7 @@
 
         train_isLoaded(resources, true);
         train_isBound(resources, "primitive", true);
-        train_readParameter(resources, "primitive", int.class, 123);
+        train_readParameter(resources, "primitive", Integer.class, 123);
         train_isRendering(resources, false);
 
         replay();
@@ -382,7 +382,7 @@
 
         train_isLoaded(resources, true);
         train_isBound(resources, "primitive", true);
-        train_readParameter(resources, "primitive", int.class, 890);
+        train_readParameter(resources, "primitive", Integer.class, 890);
         train_isRendering(resources, false);
 
         replay();
@@ -420,8 +420,7 @@
         verify();
     }
 
-    protected void train_isBound(InternalComponentResources resources, String parameterName,
-                                 boolean isBound)
+    protected void train_isBound(InternalComponentResources resources, String parameterName, boolean isBound)
     {
         expect(resources.isBound(parameterName)).andReturn(isBound);
     }
@@ -471,12 +470,8 @@
             {
                 train_isBound(resources, "value", false);
 
-                expect(
-                        source.newBinding(
-                                "default value",
-                                resources,
-                                TapestryConstants.PROP_BINDING_PREFIX,
-                                "literal:greeting")).andReturn(binding);
+                expect(source.newBinding("default value", resources, TapestryConstants.PROP_BINDING_PREFIX,
+                                         "literal:greeting")).andReturn(binding);
 
                 resources.bindParameter("value", binding);
 
@@ -487,13 +482,9 @@
             ;
         };
 
-        Component component = setupForIntegrationTest(
-                resources,
-                mockLogger(),
-                DefaultParameterComponent.class.getName(),
-                model,
-                source,
-                phaseTwoTraining);
+        Component component = setupForIntegrationTest(resources, mockLogger(),
+                                                      DefaultParameterComponent.class.getName(), model, source,
+                                                      phaseTwoTraining);
 
         train_isLoaded(resources, true);
         train_isBound(resources, "value", true);
@@ -534,13 +525,9 @@
             ;
         };
 
-        Component component = setupForIntegrationTest(
-                resources,
-                mockLogger(),
-                DefaultParameterBindingMethodComponent.class.getName(),
-                model,
-                source,
-                phaseTwoTraining);
+        Component component = setupForIntegrationTest(resources, mockLogger(),
+                                                      DefaultParameterBindingMethodComponent.class.getName(), model,
+                                                      source, phaseTwoTraining);
 
         train_isLoaded(resources, true);
         train_isBound(resources, "value", true);
@@ -558,17 +545,16 @@
         expect(resources.isRendering()).andReturn(rendering);
     }
 
-    protected final <T> void train_readParameter(InternalComponentResources resources,
-                                                 String parameterName, Class<T> expectedType, T value)
+    protected final <T> void train_readParameter(InternalComponentResources resources, String parameterName,
+                                                 Class<T> expectedType, T value)
     {
-        expect(resources.readParameter(parameterName, expectedType)).andReturn(value);
+        expect(resources.readParameter(parameterName, expectedType.getName())).andReturn(value);
     }
 
     /**
      * This is for the majority of tests.
      */
-    private Component setupForIntegrationTest(final InternalComponentResources resources)
-            throws Exception
+    private Component setupForIntegrationTest(final InternalComponentResources resources) throws Exception
     {
         MutableComponentModel model = mockMutableComponentModel();
 
@@ -586,19 +572,13 @@
             }
         };
 
-        return setupForIntegrationTest(
-                resources,
-                mockLogger(),
-                ParameterComponent.class.getName(),
-                model,
-                mockBindingSource(),
-                phaseTwoTraining);
+        return setupForIntegrationTest(resources, mockLogger(), ParameterComponent.class.getName(), model,
+                                       mockBindingSource(), phaseTwoTraining);
     }
 
     private Component setupForIntegrationTest(InternalComponentResources resources, Logger logger,
                                               String componentClassName, MutableComponentModel model,
-                                              BindingSource source,
-                                              Runnable phaseTwoTraining) throws Exception
+                                              BindingSource source, Runnable phaseTwoTraining) throws Exception
     {
         ClassPool pool = new ClassPool();
         ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
@@ -609,9 +589,8 @@
         loader.delegateLoadingOf("org.apache.tapestry.");
 
         CtClass ctClass = pool.get(componentClassName);
-        InternalClassTransformation transformation = new InternalClassTransformationImpl(ctClass,
-                                                                                         _contextClassLoader, logger,
-                                                                                         null);
+        InternalClassTransformation transformation = new InternalClassTransformationImpl(ctClass, _contextClassLoader,
+                                                                                         logger, null);
 
         replay();
 
@@ -649,8 +628,8 @@
         train_isInvariant(resources, "uncached", false);
     }
 
-    protected final void train_isInvariant(InternalComponentResources resources,
-                                           String parameterName, boolean invariant)
+    protected final void train_isInvariant(InternalComponentResources resources, String parameterName,
+                                           boolean invariant)
     {
         expect(resources.isInvariant(parameterName)).andReturn(invariant);
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -55,7 +55,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         ComponentResources resources = cpe.getComponentResources();
 
@@ -66,8 +66,7 @@
         }
         catch (BlockNotFoundException ex)
         {
-            assertTrue(ex.getMessage().contains(
-                    "does not contain a block with identifier 'notFound'."));
+            assertTrue(ex.getMessage().contains("does not contain a block with identifier 'notFound'."));
         }
 
         verify();
@@ -86,7 +85,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         ComponentResources resources = cpe.getComponentResources();
 
@@ -116,7 +115,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         ComponentResources resources = cpe.getComponentResources();
         assertFalse(resources.isBound("fred"));
@@ -143,7 +142,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         cpe.addBlock("myblock", block1);
 
@@ -154,9 +153,8 @@
         }
         catch (TapestryException ex)
         {
-            assertEquals(
-                    ex.getMessage(),
-                    "Component Foo already contains a block with id \'MyBlock\'. Block ids must be unique (excluding case, which is ignored).");
+            assertEquals(ex.getMessage(),
+                         "Component Foo already contains a block with id \'MyBlock\'. Block ids must be unique (excluding case, which is ignored).");
         }
 
         verify();
@@ -181,7 +179,7 @@
 
         replay();
 
-        ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         cpe.bindParameter("barney", binding);
 
@@ -209,7 +207,7 @@
 
         replay();
 
-        ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         cpe.containingPageDidLoad();
 
@@ -253,8 +251,8 @@
 
         replay();
 
-        ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, container, "myid", null,
-                                                                    ins, coercer, null, l);
+        ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, container, "myid", null, ins, coercer, null,
+                                                                    null, l);
 
         try
         {
@@ -262,9 +260,8 @@
         }
         catch (TapestryException ex)
         {
-            assertEquals(
-                    ex.getMessage(),
-                    "Parameter(s) fred, wilma are required for foo.components.MyComponent, but have not been bound.");
+            assertEquals(ex.getMessage(),
+                         "Parameter(s) fred, wilma are required for foo.components.MyComponent, but have not been bound.");
             assertSame(ex.getLocation(), l);
         }
 
@@ -289,7 +286,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         assertFalse(cpe.getComponentResources().isInvariant("fred"));
 
@@ -324,7 +321,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         cpe.bindParameter("barney", binding);
 
@@ -356,7 +353,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         cpe.bindParameter("barney", binding);
 
@@ -377,7 +374,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         try
         {
@@ -386,8 +383,8 @@
         }
         catch (TapestryException ex)
         {
-            assertEquals(ex.getMessage(), "Component " + PAGE_NAME
-                    + " does not contain an embedded component with id 'unknown'.");
+            assertEquals(ex.getMessage(),
+                         "Component " + PAGE_NAME + " does not contain an embedded component with id 'unknown'.");
         }
 
         verify();
@@ -410,7 +407,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         cpe.addEmbeddedElement(childElement);
 
@@ -443,7 +440,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         cpe.addEmbeddedElement(child1);
 
@@ -454,8 +451,7 @@
         }
         catch (TapestryException ex)
         {
-            assertTrue(ex.getMessage().contains(
-                    "already contains a child component with id 'CHILD'."));
+            assertTrue(ex.getMessage().contains("already contains a child component with id 'CHILD'."));
             assertSame(ex.getLocation(), l);
         }
 
@@ -480,7 +476,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         cpe.addMixin(mixinIns);
 
@@ -506,7 +502,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         cpe.addMixin(mixinIns);
 
@@ -542,7 +538,7 @@
 
         replay();
 
-        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
 
         cpe.addMixin(mixinInstantiator);
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java?rev=607895&r1=607894&r2=607895&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java Tue Jan  1 11:33:19 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -41,8 +41,8 @@
 
         replay();
 
-        InternalComponentResources resources = new InternalComponentResourcesImpl(element, null,
-                                                                                  ins, coercer, null);
+        InternalComponentResources resources = new InternalComponentResourcesImpl(element, null, ins, coercer, null,
+                                                                                  null);
 
         resources.renderInformalParameters(writer);
 
@@ -67,8 +67,8 @@
 
         replay();
 
-        InternalComponentResources resources = new InternalComponentResourcesImpl(element, null,
-                                                                                  ins, coercer, null);
+        InternalComponentResources resources = new InternalComponentResourcesImpl(element, null, ins, coercer, null,
+                                                                                  null);
 
         resources.bindParameter("fred", binding);
 
@@ -102,8 +102,8 @@
 
         replay();
 
-        InternalComponentResources resources = new InternalComponentResourcesImpl(element, null,
-                                                                                  ins, coercer, null);
+        InternalComponentResources resources = new InternalComponentResourcesImpl(element, null, ins, coercer, null,
+                                                                                  null);
 
         resources.bindParameter("fred", binding);