Author: hlship
Date: Thu Aug 11 00:17:40 2011
New Revision: 1156411
URL: http://svn.apache.org/viewvc?rev=1156411&view=rev
Log:
Reorganize/simplify the PageRenderQueue service
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRenderer.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueue.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderCommandComponentEventResultProcessor.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/SingleZonePartialRendererFilter.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java?rev=1156411&r1=1156410&r2=1156411&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
Thu Aug 11 00:17:40 2011
@@ -81,15 +81,15 @@ public class AjaxComponentEventRequestHa
}
};
- if
(pageActivator.activatePage(activePage.getRootElement().getComponentResources(),
parameters
- .getPageActivationContext(), interceptor))
- return;
-
// If we end up doing a partial render, the page render queue service
needs to know the
// page that will be rendered (for logging purposes, if nothing else).
queue.setRenderingPage(activePage);
+ if
(pageActivator.activatePage(activePage.getRootElement().getComponentResources(),
parameters
+ .getPageActivationContext(), interceptor))
+ return;
+
ContentType contentType =
pageContentTypeAnalyzer.findContentType(activePage);
request.setAttribute(InternalConstants.CONTENT_TYPE_ATTRIBUTE_NAME,
contentType);
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRenderer.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRenderer.java?rev=1156411&r1=1156410&r2=1156411&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRenderer.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRenderer.java
Thu Aug 11 00:17:40 2011
@@ -28,7 +28,7 @@ public interface AjaxPartialResponseRend
{
/**
* Used to render a partial response as part of an Ajax action request. A
call to {@link
- *
org.apache.tapestry5.internal.services.PageRenderQueue#initializeForPartialPageRender(org.apache.tapestry5.runtime.RenderCommand)}
+ *
PageRenderQueue#addPartialRenderer(org.apache.tapestry5.runtime.RenderCommand)}
* should precede this call.
*/
void renderPartialPageMarkup() throws IOException;
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueue.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueue.java?rev=1156411&r1=1156410&r2=1156411&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueue.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueue.java
Thu Aug 11 00:17:40 2011
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 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.
@@ -43,50 +43,34 @@ public interface PageRenderQueue
Page getRenderingPage();
/**
- * Initializes the queue for rendering of a portion of a page.
+ * Adds a rendering command to the queue of rendering commands. This must
not be invoked until after
+ * the {@linkplain
#setRenderingPage(org.apache.tapestry5.internal.structure.Page) rendering page
has been identified}.
+ *
+ * @param renderer responsible for rendering a portion of the final markup
*/
- void initializeForPartialPageRender(RenderCommand rootCommand);
+ void addPartialRenderer(RenderCommand renderer);
/**
- * Obtains the value previously supplied to
- * {@link
#initializeForPartialPageRender(org.apache.tapestry5.runtime.RenderCommand)}.
- * This allows the "natural" renderer to be substituted or otherwise
manipulated.
- *
- * @return the root renderer
- */
- RenderCommand getRootRenderCommand();
-
- /**
- * Returns true if {@link
#initializeForPartialPageRender(org.apache.tapestry5.runtime.RenderCommand)}
has been
- * invoked.
+ * Returns true if either {@link
#addPartialRenderer(org.apache.tapestry5.runtime.RenderCommand)} or
+ * {@link
#addPartialMarkupRendererFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter)}
+ * has been invoked.
*/
boolean isPartialRenderInitialized();
/**
- * Forces the partialRenderInitialized flag to true, even if there isn't a
root render command.
- * This is used by the {@link
org.apache.tapestry5.internal.services.ajax.MultiZoneUpdateEventResultProcessor}
which doesn't add a render command
- * until after rendering starts (care-of a stack of filters).
- *
- * @since 5.2.2
- */
- void forcePartialRenderInitialized();
-
- /**
- * Render to the write, as setup by the initialize method.
- *
- * @param writer
- * to write markup to
+ * Render to the markup writer, as setup by the {@link
#initializeForCompletePage(org.apache.tapestry5.internal.structure.Page)} or
+ * {@link #addPartialRenderer(org.apache.tapestry5.runtime.RenderCommand)}
methods.
+ *
+ * @param writer to write markup to
*/
void render(MarkupWriter writer);
/**
* Performs a partial markup render, as configured via
- * {@link
#initializeForPartialPageRender(org.apache.tapestry5.runtime.RenderCommand)}.
- *
- * @param writer
- * to which markup should be written
- * @param reply
- * JSONObject which will contain the partial response
+ * {@link #addPartialRenderer(org.apache.tapestry5.runtime.RenderCommand)}.
+ *
+ * @param writer to which markup should be written
+ * @param reply JSONObject which will contain the partial response
*/
void renderPartial(MarkupWriter writer, JSONObject reply);
@@ -98,9 +82,8 @@ public interface PageRenderQueue
* Filters are added to the <em>end</em> of the pipeline (after all
permanent contributions).
* <p/>
* Filters will be executed in the order in which they are added.
- *
- * @param filter
- * to add to the pipeline
+ *
+ * @param filter to add to the pipeline
*/
void addPartialMarkupRendererFilter(PartialMarkupRendererFilter filter);
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java?rev=1156411&r1=1156410&r2=1156411&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java
Thu Aug 11 00:17:40 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.
@@ -23,7 +23,6 @@ import org.apache.tapestry5.ioc.internal
import org.apache.tapestry5.ioc.util.Stack;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.runtime.RenderCommand;
-import org.apache.tapestry5.runtime.RenderQueue;
import org.apache.tapestry5.services.PartialMarkupRenderer;
import org.apache.tapestry5.services.PartialMarkupRendererFilter;
import org.slf4j.Logger;
@@ -36,24 +35,16 @@ import org.slf4j.Logger;
@Scope(ScopeConstants.PERTHREAD)
public class PageRenderQueueImpl implements PageRenderQueue
{
- public static final RenderCommand NOOP_RENDER_COMMAND = new RenderCommand()
- {
- public void render(MarkupWriter writer, RenderQueue queue)
- {
- // Do nothing. The command is just to let the filters do their
thing.
- }
- };
-
private final LoggerSource loggerSource;
private Page page;
- private RenderCommand rootCommand;
-
private boolean partialRenderInitialized;
private final Stack<PartialMarkupRendererFilter> filters =
CollectionFactory.newStack();
+ private RenderQueueImpl queue;
+
private static class Bridge implements PartialMarkupRenderer
{
private final PartialMarkupRendererFilter filter;
@@ -79,14 +70,22 @@ public class PageRenderQueueImpl impleme
public void initializeForCompletePage(Page page)
{
- this.page = page;
- rootCommand = page.getRootElement();
+ setRenderingPage(page);
+
+ queue.push(page.getRootElement());
}
public void setRenderingPage(Page page)
{
assert page != null;
+
this.page = page;
+
+ String name = "tapestry.render." + page.getLogger().getName();
+
+ Logger logger = loggerSource.getLogger(name);
+
+ queue = new RenderQueueImpl(logger);
}
public boolean isPartialRenderInitialized()
@@ -94,31 +93,23 @@ public class PageRenderQueueImpl impleme
return partialRenderInitialized;
}
- public void forcePartialRenderInitialized()
+ private void partialRenderInitialized()
{
- partialRenderInitialized = true;
-
- if (rootCommand == null)
+ if (page == null)
{
- rootCommand = NOOP_RENDER_COMMAND;
+ throw new IllegalStateException("Page must be specified before
initializing for partial page render.");
}
- }
-
- public void initializeForPartialPageRender(RenderCommand rootCommand)
- {
- assert rootCommand != null;
-
- if (page == null)
- throw new IllegalStateException("Page must be specified before
root render command.");
-
- this.rootCommand = rootCommand;
partialRenderInitialized = true;
}
- public RenderCommand getRootRenderCommand()
+ public void addPartialRenderer(RenderCommand renderer)
{
- return rootCommand;
+ assert renderer != null;
+
+ partialRenderInitialized();
+
+ queue.push(renderer);
}
public Page getRenderingPage()
@@ -128,14 +119,6 @@ public class PageRenderQueueImpl impleme
public void render(MarkupWriter writer)
{
- String name = "tapestry.render." + page.getLogger().getName();
-
- Logger logger = loggerSource.getLogger(name);
-
- RenderQueueImpl queue = new RenderQueueImpl(logger);
-
- queue.push(rootCommand);
-
// Run the queue until empty.
queue.run(writer);
@@ -145,6 +128,8 @@ public class PageRenderQueueImpl impleme
{
assert filter != null;
+ partialRenderInitialized();
+
filters.push(filter);
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderCommandComponentEventResultProcessor.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderCommandComponentEventResultProcessor.java?rev=1156411&r1=1156410&r2=1156411&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderCommandComponentEventResultProcessor.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderCommandComponentEventResultProcessor.java
Thu Aug 11 00:17:40 2011
@@ -51,7 +51,7 @@ public class RenderCommandComponentEvent
public void processResultValue(RenderCommand value) throws IOException
{
pageRenderQueue.addPartialMarkupRendererFilter(this);
- pageRenderQueue.initializeForPartialPageRender(value);
+ pageRenderQueue.addPartialRenderer(value);
// And render the content right now.
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java?rev=1156411&r1=1156410&r2=1156411&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
Thu Aug 11 00:17:40 2011
@@ -73,12 +73,6 @@ public class AjaxResponseRendererImpl im
{
assert filter != null;
- // When a filter is added, it is assumed that some partial render will
occur. This covers the case where
- // a MultiZoneUpdate or a null is returned from the Ajax event handler
method, so there is not actual
- // renderer (a default no-op renderer is supplied).
-
- queue.forcePartialRenderInitialized();
-
queue.addPartialMarkupRendererFilter(filter);
return this;
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/SingleZonePartialRendererFilter.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/SingleZonePartialRendererFilter.java?rev=1156411&r1=1156410&r2=1156411&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/SingleZonePartialRendererFilter.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/SingleZonePartialRendererFilter.java
Thu Aug 11 00:17:40 2011
@@ -1,4 +1,4 @@
-// Copyright 2009, 2010 The Apache Software Foundation
+// Copyright 2009, 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.
@@ -24,7 +24,8 @@ import org.apache.tapestry5.services.Par
import org.apache.tapestry5.services.PartialMarkupRendererFilter;
/**
- * Responsible for capturing the content for a single zone and storing it into
the JSON reply object.
+ * Responsible for capturing the content for a single zone and storing it into
the JSON reply object. As a {@link PartialMarkupRendererFilter} , this
+ * has access to the {@link JSONObject} for the reply, and can {@linkplain
PageRenderQueue#addPartialRenderer(org.apache.tapestry5.runtime.RenderCommand)
add renderers that generate and package the markup content}.
*
* @see org.apache.tapestry5.ajax.MultiZoneUpdate
* @see
org.apache.tapestry5.services.ajax.AjaxResponseRenderer#addRender(String,
Object)
@@ -92,9 +93,7 @@ public class SingleZonePartialRendererFi
}
};
- RenderCommand existing = queue.getRootRenderCommand();
-
- queue.initializeForPartialPageRender(mergeRenderCommands(existing,
forZone));
+ queue.addPartialRenderer(forZone);
renderer.renderMarkup(writer, reply);
}