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/31 19:57:41 UTC

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

Author: hlship
Date: Thu Jan 31 10:57:18 2008
New Revision: 617190

URL: http://svn.apache.org/viewvc?rev=617190&view=rev
Log:
TAPESTRY-2097: Render exceptions should identify the components that are actively rendering

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentResourcesRenderer.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueException.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueImpl.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/runtime/RenderQueue.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
    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/RenderQueueImplTest.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/util/CollectionFactory.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/util/StackTest.java

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentResourcesRenderer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentResourcesRenderer.java?rev=617190&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentResourcesRenderer.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentResourcesRenderer.java Thu Jan 31 10:57:18 2008
@@ -0,0 +1,50 @@
+// 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.ComponentResources;
+import org.apache.tapestry.MarkupWriter;
+import org.apache.tapestry.ioc.Location;
+import org.apache.tapestry.ioc.annotations.Primary;
+import org.apache.tapestry.services.ObjectRenderer;
+
+/**
+ * Renders {@link ComponentResources} instance, showing the complete id and the class name and the location (if a
+ * location is available, it won't be for pages).
+ */
+public class ComponentResourcesRenderer implements ObjectRenderer<ComponentResources>
+{
+    private final ObjectRenderer _masterRenderer;
+
+    public ComponentResourcesRenderer(@Primary ObjectRenderer masterRenderer)
+    {
+        _masterRenderer = masterRenderer;
+    }
+
+    public void render(ComponentResources object, MarkupWriter writer)
+    {
+        writer.writef("%s (class %s)", object.getCompleteId(), object.getComponentModel().getComponentClassName());
+
+        Location location = object.getLocation();
+
+        if (location != null)
+        {
+            writer.element("br");
+            writer.end();
+
+            _masterRenderer.render(location, writer);
+        }
+    }
+}

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueException.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueException.java?rev=617190&r1=617189&r2=617190&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueException.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueException.java Thu Jan 31 10:57:18 2008
@@ -16,19 +16,23 @@
 
 import org.apache.tapestry.ioc.internal.util.TapestryException;
 
+/**
+ * Exception used when rendering, to capture the stack of active components (for propery reporting in the exception
+ * page).
+ */
 public class RenderQueueException extends TapestryException
 {
-    private final Object[] _activeComponentIds;
+    private final Object[] _activeComponents;
 
-    public RenderQueueException(String message, Object[] activeComponentIds, Throwable cause)
+    public RenderQueueException(String message, Object[] activeComponents, Throwable cause)
     {
         super(message, cause);
 
-        _activeComponentIds = activeComponentIds;
+        _activeComponents = activeComponents;
     }
 
-    public Object[] getActiveComponentIds()
+    public Object[] getActiveComponents()
     {
-        return _activeComponentIds;
+        return _activeComponents;
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueImpl.java?rev=617190&r1=617189&r2=617190&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RenderQueueImpl.java Thu Jan 31 10:57:18 2008
@@ -14,7 +14,9 @@
 
 package org.apache.tapestry.internal.services;
 
+import org.apache.tapestry.ComponentResources;
 import org.apache.tapestry.MarkupWriter;
+import org.apache.tapestry.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry.ioc.internal.util.Defense;
 import org.apache.tapestry.ioc.util.Stack;
 import org.apache.tapestry.runtime.RenderCommand;
@@ -25,9 +27,9 @@
 {
     private static final int INITIAL_QUEUE_DEPTH = 100;
 
-    private final Stack<RenderCommand> _queue = new Stack<RenderCommand>(INITIAL_QUEUE_DEPTH);
+    private final Stack<RenderCommand> _queue = CollectionFactory.newStack(INITIAL_QUEUE_DEPTH);
 
-    private final Stack<String> _nestedIds = new Stack<String>(INITIAL_QUEUE_DEPTH);
+    private final Stack<ComponentResources> _renderingComponents = CollectionFactory.newStack();
 
     private final Logger _logger;
 
@@ -70,19 +72,19 @@
 
             _logger.error(message, ex);
 
-            throw new RenderQueueException(message, _nestedIds.getSnapshot(), ex);
+            throw new RenderQueueException(message, _renderingComponents.getSnapshot(), ex);
         }
     }
 
-    public void startComponent(String componentId)
+    public void startComponent(ComponentResources resources)
     {
-        Defense.notBlank(componentId, "componentId");
+        Defense.notNull(resources, "resources");
 
-        _nestedIds.push(componentId);
+        _renderingComponents.push(resources);
     }
 
     public void endComponent()
     {
-        _nestedIds.pop();
+        _renderingComponents.pop();
     }
 }

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=617190&r1=617189&r2=617190&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 Thu Jan 31 10:57:18 2008
@@ -916,7 +916,7 @@
 
         _page.incrementDirtyCount();
 
-        queue.startComponent(_completeId);
+        queue.startComponent(_coreResources);
 
         queue.push(POP_COMPONENT_ID);
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/runtime/RenderQueue.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/runtime/RenderQueue.java?rev=617190&r1=617189&r2=617190&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/runtime/RenderQueue.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/runtime/RenderQueue.java Thu Jan 31 10:57:18 2008
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry.runtime;
 
+import org.apache.tapestry.ComponentResources;
+
 /**
  * A stateful object that manages the process of rendering a page. Rending a page in Tapestry is based on a command
  * queue.
@@ -26,12 +28,11 @@
     void push(RenderCommand command);
 
     /**
-     * Indicates that a component is starting its render. A stack of active component ids is used for exception
-     * reporting.
+     * Indicates that a component is starting its render. A stack of active components is used for exception reporting.
      *
-     * @param componentId of component that is rendering
+     * @param resources identifies the component that is rendering
      */
-    void startComponent(String componentId);
+    void startComponent(ComponentResources resources);
 
     /**
      * Corresponds to {@link #startComponent(String)}, used to denote when the most recently started component finishes

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=617190&r1=617189&r2=617190&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 Thu Jan 31 10:57:18 2008
@@ -1237,7 +1237,7 @@
 
     /**
      * Contributes a default object renderer for type Object, plus specialized renderers for {@link Request}, {@link
-     * Location}, List, and Object[].
+     * Location}, {@link ComponentResources}, List, and Object[].
      */
     public void contributeObjectRenderer(MappedConfiguration<Class, ObjectRenderer> configuration,
 
@@ -1274,6 +1274,7 @@
 
         configuration.add(List.class, locator.autobuild(ListRenderer.class));
         configuration.add(Object[].class, locator.autobuild(ObjectArrayRenderer.class));
+        configuration.add(ComponentResources.class, locator.autobuild(ComponentResourcesRenderer.class));
     }
 
 

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=617190&r1=617189&r2=617190&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 Thu Jan 31 10:57:18 2008
@@ -15,6 +15,7 @@
 package org.apache.tapestry.integration;
 
 import org.apache.tapestry.corelib.mixins.RenderDisabled;
+import org.apache.tapestry.integration.app1.pages.RenderErrorDemo;
 import org.apache.tapestry.internal.services.InjectContainerWorker;
 import org.apache.tapestry.ioc.Resource;
 import org.apache.tapestry.ioc.internal.util.ClasspathResource;
@@ -1533,10 +1534,9 @@
 
         assertTextPresent("An unexpected application exception has occurred");
 
-        for (String s : new String[]{"RenderErrorDemo", "RenderErrorDemo:border", "RenderErrorDemo:echo"})
-        {
-            assertSourcePresent(String.format("<li>%s</li>", s));
-        }
+        // Just sample a smattering of the vast amount of data in the exception report.
 
+        assertTextPresent("RenderErrorDemo", "class " + RenderErrorDemo.class.getName(), "RenderErrorDemo:border",
+                          "RenderErrorDemo:echo");
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java?rev=617190&r1=617189&r2=617190&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java Thu Jan 31 10:57:18 2008
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry.internal.services;
 
+import org.apache.tapestry.ComponentResources;
 import org.apache.tapestry.MarkupWriter;
 import org.apache.tapestry.internal.test.InternalBaseTestCase;
 import org.apache.tapestry.runtime.RenderCommand;
@@ -56,6 +57,10 @@
     @Test
     public void command_failed()
     {
+        ComponentResources foo = mockInternalComponentResources();
+        ComponentResources bar = mockInternalComponentResources();
+        ComponentResources baz = mockInternalComponentResources();
+
         final RuntimeException t = new RuntimeException("Oops.");
 
         RenderCommand rc = new RenderCommand()
@@ -84,10 +89,10 @@
 
         RenderQueueImpl queue = new RenderQueueImpl(logger);
 
-        queue.startComponent("foo");
-        queue.startComponent("bar");
+        queue.startComponent(foo);
+        queue.startComponent(bar);
         queue.endComponent();
-        queue.startComponent("baz");
+        queue.startComponent(baz);
 
         queue.push(rc);
 
@@ -100,7 +105,7 @@
         {
             assertSame(ex.getCause(), t);
 
-            assertArraysEqual(ex.getActiveComponentIds(), new String[]{"foo", "baz"});
+            assertArraysEqual(ex.getActiveComponents(), new Object[]{foo, baz});
         }
 
         verify();

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/util/CollectionFactory.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/util/CollectionFactory.java?rev=617190&r1=617189&r2=617190&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/util/CollectionFactory.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/util/CollectionFactory.java Thu Jan 31 10:57:18 2008
@@ -23,9 +23,8 @@
 import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
- * Static factory methods to ease the creation of new collection types (when using generics). Most
- * of these method leverage the compiler's ability to match generic types by return value. Typical
- * usage (with a static import):
+ * Static factory methods to ease the creation of new collection types (when using generics). Most of these method
+ * leverage the compiler's ability to match generic types by return value. Typical usage (with a static import):
  * <p/>
  * <pre>
  * Map&lt;Foo, Bar&gt; map = newMap();
@@ -134,6 +133,11 @@
     public static <T> Stack<T> newStack()
     {
         return new Stack<T>();
+    }
+
+    public static <T> Stack<T> newStack(int initialSize)
+    {
+        return new Stack<T>(initialSize);
     }
 
     public static <V> Map<String, V> newCaseInsensitiveMap()

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/util/StackTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/util/StackTest.java?rev=617190&r1=617189&r2=617190&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/util/StackTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/util/StackTest.java Thu Jan 31 10:57:18 2008
@@ -87,7 +87,7 @@
     {
         final int LIMIT = 1000;
 
-        Stack<Integer> stack = newStack();
+        Stack<Integer> stack = newStack(10);
 
         for (int i = 0; i < LIMIT; i++)
         {