tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r597164 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry/internal/services/ main/java/org/apache/tapestry/internal/structure/ test/java/org/apache/tapestry/internal/services/
Date Wed, 21 Nov 2007 17:59:25 GMT
Author: hlship
Date: Wed Nov 21 09:59:23 2007
New Revision: 597164

URL: http://svn.apache.org/viewvc?rev=597164&view=rev
Log:
TAPESTRY-1922: EJB3 Beans can not be referenced as properties inside JBoss 4.0

Modified:
    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/ReflectiveInstantiator.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentEventImplTest.java

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=597164&r1=597163&r2=597164&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
Wed Nov 21 09:59:23 2007
@@ -30,6 +30,8 @@
 
     private final TypeCoercer _typeCoercer;
 
+    private final ClassLoader _classLoader;
+
     /**
      * @param eventType              non blank string used to identify the type of event
that was triggered
      * @param originatingComponentId the id of the component that triggered the event (this
will likely need to change
@@ -38,9 +40,11 @@
      *                               parameters
      * @param handler                invoked when a non-null return value is obtained from
an event handler method
      * @param typeCoercer            used when coercing context values to parameter types
+     * @param classLoader            loader used when resolving a class name to a class 
(ultimately, this
+     *                               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)
+                              ComponentEventHandler handler, TypeCoercer typeCoercer, ClassLoader
classLoader)
     {
         super(handler);
 
@@ -48,13 +52,9 @@
         _originatingComponentId = originatingComponentId;
         _context = context != null ? context : new Object[0];
         _typeCoercer = notNull(typeCoercer, "typeCoercer");
+        _classLoader = classLoader;
     }
 
-    /**
-     * TODO: This implementation is broken, but will get the job done for simple cases. It
just
-     * doesn't do quite the right think when an event bubbles up past its originating component's
-     * container (can lead to false matches).
-     */
     public boolean matchesByComponentId(String componentId)
     {
         return _originatingComponentId.equalsIgnoreCase(componentId);
@@ -73,22 +73,18 @@
     @SuppressWarnings("unchecked")
     public Object coerceContext(int index, String desiredTypeName)
     {
-        if (index >= _context.length)
-            throw new IllegalArgumentException(ServicesMessages
-                    .contextIndexOutOfRange(getMethodDescription()));
-
+        if (index >= _context.length) throw new IllegalArgumentException(ServicesMessages
+                .contextIndexOutOfRange(getMethodDescription()));
         try
         {
-            Class desiredType = Class.forName(desiredTypeName);
+            Class desiredType = Class.forName(desiredTypeName, true, _classLoader);
 
             return _typeCoercer.coerce(_context[index], desiredType);
         }
         catch (Exception ex)
         {
-            throw new IllegalArgumentException(ServicesMessages.exceptionInMethodParameter(
-                    getMethodDescription(),
-                    index,
-                    ex), ex);
+            throw new IllegalArgumentException(
+                    ServicesMessages.exceptionInMethodParameter(getMethodDescription(), index,
ex), ex);
         }
     }
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ReflectiveInstantiator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ReflectiveInstantiator.java?rev=597164&r1=597163&r2=597164&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ReflectiveInstantiator.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ReflectiveInstantiator.java
Wed Nov 21 09:59:23 2007
@@ -1,17 +1,17 @@
-// Copyright 2006 The Apache Software Foundation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
+// 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.internal.services;
 
 import org.apache.tapestry.internal.InternalComponentResources;
@@ -34,12 +34,12 @@
     private final Object[] _constructorParameters;
 
     /**
-     * Creates a new instance that will instantiate the given class. The
+     * Creates a new instance that will instantiate the given class.
      *
-     * @param componentModel model defining the behavior of the component
-     * @param instanceClass  class to instantiate
-     * @param parameters     passed to the constructor; the first instance is ignored (and
overriden) as the
-     *                       {@link org.apache.tapestry.internal.InternalComponentResources}
instance.
+     * @param componentModel        model defining the behavior of the component
+     * @param instanceClass         class to instantiate
+     * @param constructorParameters passed to the constructor; the first instance is ignored
(and overriden) as the
+     *                              {@link org.apache.tapestry.internal.InternalComponentResources}
instance.
      */
     ReflectiveInstantiator(ComponentModel componentModel, Class instanceClass, Object[] constructorParameters)
     {

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=597164&r1=597163&r2=597164&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
Wed Nov 21 09:59:23 2007
@@ -53,8 +53,7 @@
  * {@link org.apache.tapestry.internal.services.PageElementFactoryImpl}.
  * <p/>
  */
-public class ComponentPageElementImpl extends BaseLocatable implements ComponentPageElement,
-                                                                       PageLifecycleListener
+public class ComponentPageElementImpl extends BaseLocatable implements ComponentPageElement,
PageLifecycleListener
 {
     private static final ComponentCallback CONTAINING_PAGE_DID_ATTACH = new ComponentCallback()
     {
@@ -148,9 +147,8 @@
                 return false;
             }
 
-            throw new TapestryException(StructureMessages.wrongEventResultType(
-                    methodDescription,
-                    Boolean.class), component, null);
+            throw new TapestryException(StructureMessages.wrongEventResultType(methodDescription,
Boolean.class),
+                                        component, null);
         }
 
         private void add(RenderCommand command)
@@ -387,8 +385,7 @@
                 Element current = writer.getElement();
 
                 if (current != _elementAtSetup)
-                    throw new TapestryException(StructureMessages.unbalancedElements(_completeId),
-                                                getLocation(), null);
+                    throw new TapestryException(StructureMessages.unbalancedElements(_completeId),
getLocation(), null);
 
                 _elementAtSetup = null;
 
@@ -496,6 +493,8 @@
 
     private final TypeCoercer _typeCoercer;
 
+    private final ClassLoader _classLoader;
+
     /**
      * Constructor for other components embedded within the root component or at deeper levels
of
      * the hierarchy.
@@ -512,8 +511,8 @@
      * @param location       location of the element (within a template), used as part of
exception reporting
      */
 
-    public ComponentPageElementImpl(Page page, ComponentPageElement container, String id,
-                                    String elementName, Instantiator instantiator, TypeCoercer
typeCoercer,
+    public ComponentPageElementImpl(Page page, ComponentPageElement container, String id,
String elementName,
+                                    Instantiator instantiator, TypeCoercer typeCoercer,
                                     ComponentMessagesSource messagesSource, Location location)
     {
         super(location);
@@ -528,11 +527,13 @@
         ComponentResources containerResources = container == null ? null : container
                 .getComponentResources();
 
-        _coreResources = new InternalComponentResourcesImpl(this, containerResources, instantiator,
-                                                            _typeCoercer, _messagesSource);
+        _coreResources = new InternalComponentResourcesImpl(this, containerResources, instantiator,
_typeCoercer,
+                                                            _messagesSource);
 
         _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.
@@ -581,8 +582,7 @@
 
         ComponentPageElement existing = _children.get(childId);
         if (existing != null)
-            throw new TapestryException(StructureMessages.duplicateChildComponent(this, childId),
-                                        child, null);
+            throw new TapestryException(StructureMessages.duplicateChildComponent(this, childId),
child, null);
 
         _children.put(childId, child);
     }
@@ -598,9 +598,9 @@
         String mixinClassName = instantiator.getModel().getComponentClassName();
         String mixinName = TapestryInternalUtils.lastTerm(mixinClassName);
 
-        InternalComponentResourcesImpl resources = new InternalComponentResourcesImpl(this,
-                                                                                      _coreResources,
instantiator,
-                                                                                      _typeCoercer,
_messagesSource);
+        InternalComponentResourcesImpl resources = new InternalComponentResourcesImpl(this,
_coreResources,
+                                                                                      instantiator,
_typeCoercer,
+                                                                                      _messagesSource);
 
         // TODO: Check for name collision?
 
@@ -618,15 +618,10 @@
         if (dotx > 0)
         {
             String mixinName = parameterName.substring(0, dotx);
-            InternalComponentResources mixinResources = InternalUtils.get(
-                    _mixinsByShortName,
-                    mixinName);
-
-            if (mixinResources == null)
-                throw new TapestryException(StructureMessages.missingMixinForParameter(
-                        _completeId,
-                        mixinName,
-                        parameterName), binding, null);
+            InternalComponentResources mixinResources = InternalUtils.get(_mixinsByShortName,
mixinName);
+
+            if (mixinResources == null) throw new TapestryException(
+                    StructureMessages.missingMixinForParameter(_completeId, mixinName, parameterName),
binding, null);
 
             String simpleName = parameterName.substring(dotx + 1);
 
@@ -653,22 +648,19 @@
                 return;
             }
 
-            if (informalParameterResources == null
-                    && resources.getComponentModel().getSupportsInformalParameters())
+            if (informalParameterResources == null && resources.getComponentModel().getSupportsInformalParameters())
                 informalParameterResources = resources;
         }
 
         // An informal parameter
 
-        if (informalParameterResources == null
-                && _coreResources.getComponentModel().getSupportsInformalParameters())
+        if (informalParameterResources == null && _coreResources.getComponentModel().getSupportsInformalParameters())
             informalParameterResources = _coreResources;
 
         // For the moment, informal parameters accumulate in the core component's resources,
but
         // that will likely change.
 
-        if (informalParameterResources != null)
-            informalParameterResources.bindParameter(parameterName, binding);
+        if (informalParameterResources != null) informalParameterResources.bindParameter(parameterName,
binding);
     }
 
     public void addToBody(PageElement element)
@@ -683,8 +675,7 @@
         _template.add(element);
     }
 
-    private void addUnboundParameterNames(String prefix, List<String> unbound,
-                                          InternalComponentResources resource)
+    private void addUnboundParameterNames(String prefix, List<String> unbound, InternalComponentResources
resource)
     {
         ComponentModel model = resource.getComponentModel();
 
@@ -812,8 +803,7 @@
                 .toLowerCase());
 
         if (embeddedElement == null)
-            throw new TapestryException(StructureMessages.noSuchComponent(this, embeddedId),
this,
-                                        null);
+            throw new TapestryException(StructureMessages.noSuchComponent(this, embeddedId),
this, null);
 
         return embeddedElement;
     }
@@ -849,10 +839,8 @@
             }
         }
 
-        if (result == null)
-            throw new TapestryException(
-                    StructureMessages.unknownMixin(_completeId, mixinClassName), getLocation(),
-                    null);
+        if (result == null) throw new TapestryException(StructureMessages.unknownMixin(_completeId,
mixinClassName),
+                                                        getLocation(), null);
 
         return result;
     }
@@ -906,11 +894,9 @@
                 return;
             }
 
-            Iterator<Component> i = reverse ? InternalUtils.reverseIterator(_components)
-                                    : _components.iterator();
+            Iterator<Component> i = reverse ? InternalUtils.reverseIterator(_components)
: _components.iterator();
 
-            while (i.hasNext())
-                callback.run(i.next());
+            while (i.hasNext()) callback.run(i.next());
         }
         catch (Exception ex)
         {
@@ -978,8 +964,8 @@
 
         while (component != null)
         {
-            ComponentEvent event = new ComponentEventImpl(eventType, componentId, context,
handler,
-                                                          _typeCoercer);
+            ComponentEvent event = new ComponentEventImpl(eventType, componentId, context,
handler, _typeCoercer,
+                                                          _classLoader);
 
             result |= component.handleEvent(event);
 
@@ -1030,8 +1016,7 @@
         Block result = findBlock(id);
 
         if (result == null)
-            throw new BlockNotFoundException(StructureMessages.blockNotFound(_completeId,
id),
-                                             getLocation());
+            throw new BlockNotFoundException(StructureMessages.blockNotFound(_completeId,
id), getLocation());
 
         return result;
     }
@@ -1048,8 +1033,7 @@
         if (_blocks == null) _blocks = newCaseInsensitiveMap();
 
         if (_blocks.containsKey(blockId))
-            throw new TapestryException(StructureMessages.duplicateBlock(this, blockId),
block,
-                                        null);
+            throw new TapestryException(StructureMessages.duplicateBlock(this, blockId),
block, null);
 
         _blocks.put(blockId, block);
     }
@@ -1061,15 +1045,10 @@
         if (dotx > 0)
         {
             String mixinName = parameterName.substring(0, dotx);
-            InternalComponentResources mixinResources = InternalUtils.get(
-                    _mixinsByShortName,
-                    mixinName);
-
-            if (mixinResources == null)
-                throw new TapestryException(StructureMessages.missingMixinForParameter(
-                        _completeId,
-                        mixinName,
-                        parameterName), null, null);
+            InternalComponentResources mixinResources = InternalUtils.get(_mixinsByShortName,
mixinName);
+
+            if (mixinResources == null) throw new TapestryException(
+                    StructureMessages.missingMixinForParameter(_completeId, mixinName, parameterName),
null, null);
 
             String simpleName = parameterName.substring(dotx + 1);
 

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=597164&r1=597163&r2=597164&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
Wed Nov 21 09:59:23 2007
@@ -46,8 +46,7 @@
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
-                                                      _coercer);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
_coercer, null);
 
         assertTrue(event.matchesByEventType("eventType"));
         assertFalse(event.matchesByEventType("foo"));
@@ -62,8 +61,7 @@
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
-                                                      _coercer);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
_coercer, null);
 
         assertTrue(event.matchesByEventType("EVENTTYPE"));
 
@@ -77,8 +75,7 @@
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
-                                                      _coercer);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
_coercer, null);
 
         assertTrue(event.matchesByComponentId("someId"));
 
@@ -93,8 +90,7 @@
         ComponentEventHandler handler = mockComponentEventHandler();
 
         replay();
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
-                                                      _coercer);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
_coercer, null);
 
         assertTrue(event.matchesByComponentId("SOMEID"));
 
@@ -108,8 +104,8 @@
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", new String[]
-                {"27"}, handler, _coercer);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", new String[]{"27"},
handler, _coercer,
+                                                      null);
 
         assertEquals(event.coerceContext(0, "java.lang.Integer"), new Integer(27));
 
@@ -124,8 +120,8 @@
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", new String[]
-                {"27"}, handler, _coercer);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", new String[]{"27"},
handler, _coercer,
+                                                      null);
 
         event.setSource(component, "foo.Bar.baz()");
 
@@ -135,9 +131,8 @@
         }
         catch (IllegalArgumentException ex)
         {
-            assertEquals(
-                    ex.getMessage(),
-                    "Method foo.Bar.baz() has more parameters than there are context values
for this component event.");
+            assertEquals(ex.getMessage(),
+                         "Method foo.Bar.baz() has more parameters than there are context
values for this component event.");
         }
 
         verify();
@@ -151,8 +146,8 @@
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", new String[]
-                {"abc"}, handler, _coercer);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", new String[]{"abc"},
handler, _coercer,
+                                                      null);
 
         event.setSource(component, "foo.Bar.baz()");
 
@@ -166,8 +161,7 @@
             // Different JVMs will report the conversion error slightly differently,
             // so we don't try to check that part of the error message.
 
-            assertTrue(ex.getMessage().startsWith(
-                    "Exception in method foo.Bar.baz(), parameter #1:"));
+            assertTrue(ex.getMessage().startsWith("Exception in method foo.Bar.baz(), parameter
#1:"));
         }
 
         verify();
@@ -186,8 +180,7 @@
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
-                                                      _coercer);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
_coercer, null);
 
         event.setSource(component, methodDescription);
 
@@ -212,8 +205,7 @@
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
-                                                      _coercer);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
_coercer, null);
 
         event.setSource(component, methodDescription);
 
@@ -232,8 +224,7 @@
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
-                                                      _coercer);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
_coercer, null);
 
         event.setSource(component, "foo.Bar.baz()");
 
@@ -256,8 +247,7 @@
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
-                                                      _coercer);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
_coercer, null);
 
         event.setSource(component, "foo.Bar.baz()");
         event.storeResult(result);



Mime
View raw message