tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r1153724 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/services/ main/java/org/apache/tapestry5/internal/structure/ test/java/org/apache/tapestry5/integration/app1/ test/java/org/apache/tapestry5/...
Date Thu, 04 Aug 2011 01:49:32 GMT
Author: hlship
Date: Thu Aug  4 01:49:31 2011
New Revision: 1153724

URL: http://svn.apache.org/viewvc?rev=1153724&view=rev
Log:
Use the OperationTracker to identify the method which provides a result value for a render
phase event or component event

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EventImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/RenderPhaseEvent.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventImpl.java?rev=1153724&r1=1153723&r2=1153724&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventImpl.java
Thu Aug  4 01:49:31 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010, 2011 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.
@@ -47,7 +47,7 @@ public class ComponentEventImpl extends 
     public ComponentEventImpl(String eventType, String originatingComponentId, EventContext
context,
             ComponentEventCallback handler, ComponentPageElementResources elementResources,
Logger logger)
     {
-        super(handler, logger);
+        super(handler, logger, elementResources);
 
         this.eventType = eventType;
         this.originatingComponentId = originatingComponentId;

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EventImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EventImpl.java?rev=1153724&r1=1153723&r2=1153724&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EventImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EventImpl.java
Thu Aug  4 01:49:31 2011
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2007, 2008, 2010, 2011 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,8 @@ package org.apache.tapestry5.internal.se
 
 import org.apache.tapestry5.ComponentEventCallback;
 import org.apache.tapestry5.TapestryMarkers;
+import org.apache.tapestry5.ioc.Invokable;
+import org.apache.tapestry5.ioc.OperationTracker;
 import org.apache.tapestry5.runtime.Event;
 import org.slf4j.Logger;
 
@@ -32,12 +34,16 @@ public class EventImpl implements Event
 
     private final boolean debugEnabled;
 
+    protected final OperationTracker tracker;
+
     /**
      * @param handler informed of return values from methods, deems when the event is aborted
      * @param logger  used to log method invocations
+     * @param tracker
      */
-    public EventImpl(ComponentEventCallback handler, Logger logger)
+    public EventImpl(ComponentEventCallback handler, Logger logger, OperationTracker tracker)
     {
+        this.tracker = tracker;
         assert handler != null;
         this.handler = handler;
         this.logger = logger;
@@ -60,7 +66,7 @@ public class EventImpl implements Event
     }
 
     @SuppressWarnings("unchecked")
-    public boolean storeResult(Object result)
+    public boolean storeResult(final Object result)
     {
         // Given that this method is *only* invoked from code
         // that is generated at runtime and proven to be correct,
@@ -68,11 +74,24 @@ public class EventImpl implements Event
         // let's check anyway.
 
         if (aborted)
+        {
             throw new IllegalStateException(ServicesMessages.componentEventIsAborted(methodDescription));
+        }
 
 
         if (result != null)
-            aborted |= handler.handleResult(result);
+        {
+            boolean handleResult =
+                    tracker.invoke(String.format("Handling result from method %s.", methodDescription),
new Invokable<Boolean>()
+                    {
+                        public Boolean invoke()
+                        {
+                            return handler.handleResult(result);
+                        }
+                    });
+
+            aborted |= handleResult;
+        }
 
         return aborted;
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java?rev=1153724&r1=1153723&r2=1153724&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
Thu Aug  4 01:49:31 2011
@@ -433,7 +433,7 @@ public class ComponentPageElementImpl ex
 
         public void render(MarkupWriter writer, RenderQueue queue)
         {
-            rendering.set(false);
+            renderingValue.set(false);
 
             Element current = writer.getElement();
 
@@ -499,9 +499,9 @@ public class ComponentPageElementImpl ex
 
     private final Page page;
 
-    private final PerThreadValue<RenderPhaseEvent> renderEvent;
+    private final PerThreadValue<RenderPhaseEvent> renderPhaseEventValue;
 
-    private final PerThreadValue<Boolean> rendering;
+    private final PerThreadValue<Boolean> renderingValue;
 
     // should be okay since it's a shadow service object
     private final Request request;
@@ -562,8 +562,8 @@ public class ComponentPageElementImpl ex
 
         eventLogger = elementResources.getEventLogger(coreResources.getLogger());
 
-        renderEvent = elementResources.createPerThreadValue();
-        rendering = elementResources.createPerThreadValue();
+        renderPhaseEventValue = elementResources.createPerThreadValue();
+        renderingValue = elementResources.createPerThreadValue();
 
         page.addLifecycleListener(new PageLifecycleAdapter()
         {
@@ -975,7 +975,7 @@ public class ComponentPageElementImpl ex
 
     public boolean isRendering()
     {
-        return rendering.get(false);
+        return renderingValue.get(false);
     }
 
     /**
@@ -996,7 +996,7 @@ public class ComponentPageElementImpl ex
 
         // TODO: Check for recursive rendering.
 
-        rendering.set(true);
+        renderingValue.set(true);
 
         queue.startComponent(coreResources);
 
@@ -1263,7 +1263,7 @@ public class ComponentPageElementImpl ex
 
     protected RenderPhaseEvent createRenderEvent(RenderQueue queue)
     {
-        RenderPhaseEvent result = renderEvent.get();
+        RenderPhaseEvent result = renderPhaseEventValue.get();
 
         if (result != null)
             return result;
@@ -1272,9 +1272,9 @@ public class ComponentPageElementImpl ex
         // This assumes that the queue will not change during the current request,
         // which should be valid.
 
-        result = new RenderPhaseEvent(new RenderPhaseEventHandler(queue), eventLogger);
+        result = new RenderPhaseEvent(new RenderPhaseEventHandler(queue), eventLogger, elementResources);
 
-        renderEvent.set(result);
+        renderPhaseEventValue.set(result);
 
         return result;
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/RenderPhaseEvent.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/RenderPhaseEvent.java?rev=1153724&r1=1153723&r2=1153724&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/RenderPhaseEvent.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/RenderPhaseEvent.java
Thu Aug  4 01:49:31 2011
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2011 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,15 +15,16 @@
 package org.apache.tapestry5.internal.structure;
 
 import org.apache.tapestry5.internal.services.EventImpl;
+import org.apache.tapestry5.ioc.OperationTracker;
 import org.slf4j.Logger;
 
 public class RenderPhaseEvent extends EventImpl
 {
     private final RenderPhaseEventHandler handler;
 
-    public RenderPhaseEvent(RenderPhaseEventHandler handler, Logger logger)
+    public RenderPhaseEvent(RenderPhaseEventHandler handler, Logger logger, OperationTracker
tracker)
     {
-        super(handler, logger);
+        super(handler, logger, tracker);
 
         this.handler = handler;
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java?rev=1153724&r1=1153723&r2=1153724&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
Thu Aug  4 01:49:31 2011
@@ -651,6 +651,7 @@ public class CoreBehaviorsTests extends 
         clickAndWait("link=bad");
         assertTextPresent(
                 "An unexpected application exception has occurred.",
+                "Handling result from method org.apache.tapestry5.integration.app1.pages.ReturnTypes.onActionFromBadReturnValue().",
                 "A component event handler method returned the value 20. Return type java.lang.Integer
can not be handled.",
                 "context:ReturnTypes.tml, line 50");
         goBack();

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventImplTest.java?rev=1153724&r1=1153723&r2=1153724&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventImplTest.java
Thu Aug  4 01:49:31 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010, 2011 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.
@@ -19,30 +19,34 @@ import org.apache.tapestry5.EventContext
 import org.apache.tapestry5.TapestryMarkers;
 import org.apache.tapestry5.internal.structure.ComponentPageElementResources;
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
-import org.apache.tapestry5.ioc.services.TypeCoercer;
+import org.apache.tapestry5.ioc.Invokable;
 import org.apache.tapestry5.runtime.ComponentEvent;
 import org.easymock.EasyMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.isA;
+import org.easymock.IAnswer;
 import org.slf4j.Logger;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.isA;
+
 public class ComponentEventImplTest extends InternalBaseTestCase
 {
-    private TypeCoercer coercer;
 
-    @BeforeClass
-    public void setup_coercer()
+    private ComponentPageElementResources mockResources()
     {
-        coercer = getObject(TypeCoercer.class, null);
-    }
+        ComponentPageElementResources resources = newMock(ComponentPageElementResources.class);
 
-    @AfterClass
-    public void cleanup_coercer()
-    {
-        coercer = null;
+        expect(resources.invoke(EasyMock.isA(String.class), EasyMock.isA(Invokable.class))).andAnswer(new
IAnswer<Object>()
+        {
+            public Object answer() throws Throwable
+            {
+                Invokable inv = (Invokable) EasyMock.getCurrentArguments()[1];
+
+                return inv.invoke();
+            }
+        });
+
+        return resources;
     }
 
     @Test
@@ -66,7 +70,9 @@ public class ComponentEventImplTest exte
         verify();
     }
 
-    /** @since 5.2.0 */
+    /**
+     * @since 5.2.0
+     */
     @Test
     public void no_match_one_event_is_aborted()
     {
@@ -74,6 +80,7 @@ public class ComponentEventImplTest exte
         EventContext context = mockEventContext();
         Logger logger = mockLogger();
         Object result = new Object();
+        ComponentPageElementResources resources = mockResources();
 
         train_isDebugEnabled(logger, false);
 
@@ -81,7 +88,7 @@ public class ComponentEventImplTest exte
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler,
null, logger);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler,
resources, logger);
 
         event.storeResult(result);
 
@@ -199,8 +206,7 @@ public class ComponentEventImplTest exte
         try
         {
             event.coerceContext(1, "java.lang.Integer");
-        }
-        catch (IllegalArgumentException ex)
+        } catch (IllegalArgumentException ex)
         {
             assertEquals(ex.getMessage(),
                     "Method foo.Bar.baz() has more parameters than there are context values
for this component event.");
@@ -236,8 +242,7 @@ public class ComponentEventImplTest exte
         {
             event.coerceContext(0, "java.lang.Integer");
             unreachable();
-        }
-        catch (IllegalArgumentException ex)
+        } catch (IllegalArgumentException ex)
         {
             // Different JVMs will report the conversion error slightly differently,
             // so we don't try to check that part of the error message.
@@ -258,6 +263,8 @@ public class ComponentEventImplTest exte
         train_isDebugEnabled(logger, true);
         EasyMock.expectLastCall().atLeastOnce();
 
+        ComponentPageElementResources resources = mockResources();
+
         logger.debug(eq(TapestryMarkers.EVENT_HANDLER_METHOD), isA(String.class));
 
         ComponentEventCallback handler = mockComponentEventHandler();
@@ -266,7 +273,7 @@ public class ComponentEventImplTest exte
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
null, logger);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
resources, logger);
 
         event.setMethodDescription(methodDescription);
 
@@ -286,6 +293,7 @@ public class ComponentEventImplTest exte
         String methodDescription = "foo.Bar.baz()";
         ComponentEventCallback handler = mockComponentEventHandler();
         Logger logger = mockLogger();
+        ComponentPageElementResources resources = mockResources();
 
         train_isDebugEnabled(logger, true);
         logger.debug(eq(TapestryMarkers.EVENT_HANDLER_METHOD), isA(String.class));
@@ -294,7 +302,7 @@ public class ComponentEventImplTest exte
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
null, logger);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
resources, logger);
 
         event.setMethodDescription(methodDescription);
 
@@ -334,6 +342,7 @@ public class ComponentEventImplTest exte
         Object result = new Object();
         ComponentEventCallback handler = mockComponentEventHandler();
         Logger logger = mockLogger();
+        ComponentPageElementResources resources = mockResources();
 
         train_isDebugEnabled(logger, true);
         EasyMock.expectLastCall().atLeastOnce();
@@ -346,7 +355,7 @@ public class ComponentEventImplTest exte
 
         replay();
 
-        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
null, logger);
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
resources, logger);
 
         event.setMethodDescription("foo.Bar.baz()");
         event.storeResult(result);
@@ -356,8 +365,7 @@ public class ComponentEventImplTest exte
             event.setMethodDescription("foo.Bar.biff()");
             event.storeResult(null);
             unreachable();
-        }
-        catch (IllegalStateException ex)
+        } catch (IllegalStateException ex)
         {
             assertEquals(ex.getMessage(), ServicesMessages.componentEventIsAborted("foo.Bar.biff()"));
         }



Mime
View raw message