Author: hlship
Date: Wed Nov 15 13:54:34 2006
New Revision: 475445
URL: http://svn.apache.org/viewvc?view=rev&rev=475445
Log:
Add support for render phase PreBeginRender and PostBeginRender
Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/PostBeginRender.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/PreBeginRender.java
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/BeginRender.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/Component.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TransformConstants.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/DefaultComponentLifecyle.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/BeginRender.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/BeginRender.java?view=diff&rev=475445&r1=475444&r2=475445
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/BeginRender.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/BeginRender.java
Wed Nov 15 13:54:34 2006
@@ -38,6 +38,10 @@
* <p>
* Returning false will skip rendering of the template and/or body, and jump
directly to the
* [EMAIL PROTECTED] org.apache.tapestry.annotations.CleanupRender} phase.
+ * <p>
+ * Execution of this phase is broken up into three steps: [EMAIL PROTECTED]
PreBeginRender}, BeginRender,
+ * [EMAIL PROTECTED] PostBeginRender}. Returning false from any of these
phases will jump directly to
+ * [EMAIL PROTECTED] CleanupRender}.
*/
@Target(ElementType.METHOD)
@Retention(RUNTIME)
Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/PostBeginRender.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/PostBeginRender.java?view=auto&rev=475445
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/PostBeginRender.java
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/PostBeginRender.java
Wed Nov 15 13:54:34 2006
@@ -0,0 +1,20 @@
+package org.apache.tapestry.annotations;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Phase that occurs just after the [EMAIL PROTECTED] BeginRender} phase, but
before template or body, etc.
+ * This is often used to write additional attributes into the element started
by the BeginRender
+ * phase.
+ */
[EMAIL PROTECTED](ElementType.METHOD)
[EMAIL PROTECTED](RUNTIME)
[EMAIL PROTECTED]
+public @interface PostBeginRender {
+
+}
Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/PreBeginRender.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/PreBeginRender.java?view=auto&rev=475445
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/PreBeginRender.java
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/annotations/PreBeginRender.java
Wed Nov 15 13:54:34 2006
@@ -0,0 +1,18 @@
+package org.apache.tapestry.annotations;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Phase the occurs just before [EMAIL PROTECTED] BeginRender}.
+ */
[EMAIL PROTECTED](ElementType.METHOD)
[EMAIL PROTECTED](RUNTIME)
[EMAIL PROTECTED]
+public @interface PreBeginRender {
+
+}
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java?view=diff&rev=475445&r1=475444&r2=475445
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
Wed Nov 15 13:54:34 2006
@@ -51,7 +51,6 @@
* via a [EMAIL PROTECTED] org.apache.tapestry.runtime.Component} instance.
* <p>
* Once instantiated, a ComponentPageElementImpl should be registered as a
- * [EMAIL PROTECTED] org.apache.tapestry.runtime.PageLifecycleListener} with
the containing
* [EMAIL PROTECTED] org.apache.tapestry.internal.structure.Page}. This could
be done inside the constructors,
* but that tends to complicate unit tests, so its done by
* [EMAIL PROTECTED]
org.apache.tapestry.internal.services.PageElementFactoryImpl}.
@@ -112,13 +111,7 @@
invoke(true, callback);
if (event.getResult())
- queue.push(_beginRender);
- }
-
- @Override
- public String toString()
- {
- return String.format("AfterRender[%s]", _completeId);
+ queue.push(_preBeginRender);
}
};
@@ -141,12 +134,6 @@
if (event.getResult())
queue.push(_beforeRenderBody);
}
-
- @Override
- public String toString()
- {
- return String.format("AfterRenderBody[%s]", _completeId);
- }
};
private final RenderCommand _afterRenderTemplate = new RenderCommand()
@@ -168,12 +155,6 @@
if (event.getResult())
queue.push(_beforeRenderTemplate);
}
-
- @Override
- public String toString()
- {
- return String.format("BeforeRenderTemplate[%s]", _completeId);
- }
};
private final RenderCommand _beforeRenderBody = new RenderCommand()
@@ -197,12 +178,6 @@
if (event.getResult())
pushElements(queue, _body);
}
-
- @Override
- public String toString()
- {
- return String.format("BeforeRenderBody[%s]", _completeId);
- }
};
private final RenderCommand _beforeRenderTemplate = new RenderCommand()
@@ -226,11 +201,26 @@
if (event.getResult())
pushElements(queue, _template);
}
+ };
- @Override
- public String toString()
+ private final RenderCommand _preBeginRender = new RenderCommand()
+ {
+ public void render(final MarkupWriter writer, final RenderQueue queue)
{
- return String.format("BeforeRenderTemplate[%s]", _completeId);
+ final LifecycleEvent<Boolean> event = newEvent(true);
+
+ ComponentCallback callback = new ComponentCallback()
+ {
+ public void run(Component component)
+ {
+ component.preBeginRender(writer, event);
+ }
+ };
+
+ invoke(false, callback);
+
+ if (event.getResult())
+ queue.push(_beginRender);
}
};
@@ -250,6 +240,27 @@
invoke(false, callback);
+ if (event.getResult())
+ queue.push(_postBeginRender);
+ }
+ };
+
+ private final RenderCommand _postBeginRender = new RenderCommand()
+ {
+ public void render(final MarkupWriter writer, final RenderQueue queue)
+ {
+ final LifecycleEvent<Boolean> event = newEvent(true);
+
+ ComponentCallback callback = new ComponentCallback()
+ {
+ public void run(Component component)
+ {
+ component.postBeginRender(writer, event);
+ }
+ };
+
+ invoke(false, callback);
+
// If the component has no template whatsoever, then a
// renderBody element is added as the lone element of the
component's template.
// So every component will have a non-empty template.
@@ -260,12 +271,6 @@
queue.push(_beforeRenderTemplate);
}
}
-
- @Override
- public String toString()
- {
- return String.format("BeginRender[%s]", _completeId);
- }
};
private List<PageElement> _body;
@@ -306,12 +311,6 @@
}
}
-
- @Override
- public String toString()
- {
- return String.format("CleanupRender[%s]", _completeId);
- }
};
private final String _completeId;
@@ -366,7 +365,7 @@
queue.push(_cleanupRender);
if (event.getResult())
- queue.push(_beginRender);
+ queue.push(_preBeginRender);
}
@Override
@@ -507,9 +506,14 @@
String simpleName = parameterName.substring(dotx + 1);
+ // TODO: If its informal? Ignore it unless the mixin supports
informals? Warn otherwise?
+ // We'll have to see.
+
mixinResources.addParameter(simpleName, binding);
}
+ InternalComponentResources informalParameterResources = null;
+
// Does it match a formal parameter name of the core component? That
takes precedence
if
(_coreResources.getComponentModel().getParameterModel(parameterName) != null)
@@ -526,12 +530,23 @@
resources.addParameter(parameterName, binding);
return;
}
+
+ if (informalParameterResources == null
+ &&
resources.getComponentModel().getSupportsInformalParameters())
+ informalParameterResources = resources;
}
+ // An informal parameter
+
+ 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.
- _coreResources.addParameter(parameterName, binding);
+ if (informalParameterResources != null)
+ informalParameterResources.addParameter(parameterName, binding);
}
public void addToBody(PageElement element)
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/Component.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/Component.java?view=diff&rev=475445&r1=475444&r2=475445
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/Component.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/Component.java
Wed Nov 15 13:54:34 2006
@@ -45,9 +45,21 @@
void setupRender(MarkupWriter writer, LifecycleEvent<Boolean> event);
/**
+ * Invoked just before [EMAIL PROTECTED] #beginRender(MarkupWriter,
LifecycleEvent)
+ */
+
+ void preBeginRender(MarkupWriter writer, LifecycleEvent<Boolean> event);
+
+ /**
* Invoked to allow a component to render its tag (start tag and
attributes).
*/
void beginRender(MarkupWriter writer, LifecycleEvent<Boolean> event);
+
+ /**
+ * Invoked just after [EMAIL PROTECTED] #beginRender(MarkupWriter,
LifecycleEvent)}, typically to allow a
+ * mixin to write additional attributes into the component's tag.
+ */
+ void postBeginRender(MarkupWriter writer, LifecycleEvent<Boolean> event);
/**
* This phase is only invoked for components with templates.
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java?view=diff&rev=475445&r1=475444&r2=475445
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
Wed Nov 15 13:54:34 2006
@@ -33,6 +33,8 @@
import org.apache.tapestry.annotations.BeforeRenderTemplate;
import org.apache.tapestry.annotations.BeginRender;
import org.apache.tapestry.annotations.CleanupRender;
+import org.apache.tapestry.annotations.PostBeginRender;
+import org.apache.tapestry.annotations.PreBeginRender;
import org.apache.tapestry.annotations.SetupRender;
import org.apache.tapestry.internal.InternalConstants;
import org.apache.tapestry.internal.bindings.LiteralBindingFactory;
@@ -524,7 +526,17 @@
// execution order.
add(configuration, TransformConstants.SETUP_RENDER_SIGNATURE,
SetupRender.class, false);
+ add(
+ configuration,
+ TransformConstants.PRE_BEGIN_RENDER_SIGNATURE,
+ PreBeginRender.class,
+ false);
add(configuration, TransformConstants.BEGIN_RENDER_SIGNATURE,
BeginRender.class, false);
+ add(
+ configuration,
+ TransformConstants.POST_BEGIN_RENDER_SIGNATURE,
+ PostBeginRender.class,
+ false);
add(
configuration,
TransformConstants.BEFORE_RENDER_TEMPLATE_SIGNATURE,
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TransformConstants.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TransformConstants.java?view=diff&rev=475445&r1=475444&r2=475445
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TransformConstants.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TransformConstants.java
Wed Nov 15 13:54:34 2006
@@ -17,6 +17,9 @@
import java.lang.reflect.Modifier;
import org.apache.tapestry.MarkupWriter;
+import org.apache.tapestry.annotations.PostBeginRender;
+import org.apache.tapestry.annotations.PreBeginRender;
+import org.apache.tapestry.runtime.Component;
import org.apache.tapestry.runtime.ComponentEvent;
import org.apache.tapestry.runtime.LifecycleEvent;
@@ -28,7 +31,7 @@
{
// Shared parameters of a whole bunch of lifecycle methods, representing
the different
// component render states.
- private static final String[] LIFECYCLE_METHOD_PARAMETER_TYPES =
+ private static final String[] RENDER_PHASE_METHOD_PARAMETERS =
{ MarkupWriter.class.getName(), LifecycleEvent.class.getName() };
/**
@@ -72,7 +75,7 @@
*
* @see org.apache.tapestry.annotations.SetupRender
*/
- public static final MethodSignature SETUP_RENDER_SIGNATURE =
newLifecycleMethodSignature("setupRender");
+ public static final MethodSignature SETUP_RENDER_SIGNATURE =
renderPhaseSignature("setupRender");
/**
* Signature for
@@ -80,15 +83,29 @@
*
* @see org.apache.tapestry.annotations.BeginRender
*/
- public static final MethodSignature BEGIN_RENDER_SIGNATURE =
newLifecycleMethodSignature("beginRender");
+ public static final MethodSignature BEGIN_RENDER_SIGNATURE =
renderPhaseSignature("beginRender");
/**
+ * Signature for [EMAIL PROTECTED] Component#preBeginRender(MarkupWriter,
LifecycleEvent)}.
+ *
+ * @see PreBeginRender
+ */
+ public static final MethodSignature PRE_BEGIN_RENDER_SIGNATURE =
renderPhaseSignature("preBeginRender");
+
+
+ /** Signature for [EMAIL PROTECTED]
Component#postBeginRender(MarkupWriter, LifecycleEvent)}.
+ *
+ * @see PostBeginRender
+ */
+ public static final MethodSignature POST_BEGIN_RENDER_SIGNATURE =
renderPhaseSignature("postBeginRender");
+
+ /**
* Signature for
* [EMAIL PROTECTED]
org.apache.tapestry.runtime.Component#beforeRenderTemplate(MarkupWriter,
LifecycleEvent)}.
*
* @see org.apache.tapestry.annotations.BeforeRenderTemplate
*/
- public static MethodSignature BEFORE_RENDER_TEMPLATE_SIGNATURE =
newLifecycleMethodSignature("beforeRenderTemplate");
+ public static MethodSignature BEFORE_RENDER_TEMPLATE_SIGNATURE =
renderPhaseSignature("beforeRenderTemplate");
/**
* Signature for
@@ -96,7 +113,7 @@
*
* @see org.apache.tapestry.annotations.BeforeRenderTemplate
*/
- public static MethodSignature AFTER_RENDER_TEMPLATE_SIGNATURE =
newLifecycleMethodSignature("afterRenderTemplate");
+ public static MethodSignature AFTER_RENDER_TEMPLATE_SIGNATURE =
renderPhaseSignature("afterRenderTemplate");
/**
* Signature for
@@ -104,7 +121,7 @@
*
* @see org.apache.tapestry.annotations.BeforeRenderBody
*/
- public static final MethodSignature BEFORE_RENDER_BODY_SIGNATURE =
newLifecycleMethodSignature("beforeRenderBody");
+ public static final MethodSignature BEFORE_RENDER_BODY_SIGNATURE =
renderPhaseSignature("beforeRenderBody");
/**
* Signature for
@@ -112,7 +129,7 @@
*
* @see org.apache.tapestry.annotations.AfterRenderBody
*/
- public static final MethodSignature AFTER_RENDER_BODY_SIGNATURE =
newLifecycleMethodSignature("afterRenderBody");
+ public static final MethodSignature AFTER_RENDER_BODY_SIGNATURE =
renderPhaseSignature("afterRenderBody");
/**
* Signature for
@@ -120,7 +137,7 @@
*
* @see org.apache.tapestry.annotations.AfterRender
*/
- public static final MethodSignature AFTER_RENDER_SIGNATURE =
newLifecycleMethodSignature("afterRender");
+ public static final MethodSignature AFTER_RENDER_SIGNATURE =
renderPhaseSignature("afterRender");
/**
* Signature for
@@ -128,15 +145,15 @@
*
* @see org.apache.tapestry.annotations.CleanupRender
*/
- public static final MethodSignature CLEANUP_RENDER_SIGNATURE =
newLifecycleMethodSignature("cleanupRender");
+ public static final MethodSignature CLEANUP_RENDER_SIGNATURE =
renderPhaseSignature("cleanupRender");
private TransformConstants()
{
}
- private static MethodSignature newLifecycleMethodSignature(String name)
+ private static MethodSignature renderPhaseSignature(String name)
{
- return new MethodSignature(Modifier.PUBLIC, "void", name,
LIFECYCLE_METHOD_PARAMETER_TYPES,
+ return new MethodSignature(Modifier.PUBLIC, "void", name,
RENDER_PHASE_METHOD_PARAMETERS,
null);
}
}
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/DefaultComponentLifecyle.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/DefaultComponentLifecyle.java?view=diff&rev=475445&r1=475444&r2=475445
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/DefaultComponentLifecyle.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/bindings/DefaultComponentLifecyle.java
Wed Nov 15 13:54:34 2006
@@ -87,6 +87,18 @@
public void beforeRenderTemplate(MarkupWriter writer,
LifecycleEvent<Boolean> event)
{
// TODO Auto-generated method stub
+ }
+
+ public void postBeginRender(MarkupWriter writer, LifecycleEvent<Boolean>
event)
+ {
+ // TODO Auto-generated method stub
+
+ }
+ public void preBeginRender(MarkupWriter writer, LifecycleEvent<Boolean>
event)
+ {
+ // TODO Auto-generated method stub
}
+
+
}
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java?view=diff&rev=475445&r1=475444&r2=475445
==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
Wed Nov 15 13:54:34 2006
@@ -45,6 +45,8 @@
train_getLog(model, newLog());
train_getParameterModel(model, "barney", null);
+
+ train_getSupportsInformalParameters(model, true);
replay();
@@ -213,6 +215,8 @@
TypeCoercer coercer = newTypeCoercer();
Binding binding = newBinding();
+ train_getSupportsInformalParameters(model, true);
+
Long boundValue = new Long(23);
Instantiator ins = newInstantiator(component, model);
@@ -237,6 +241,12 @@
verify();
}
+ protected final void train_getSupportsInformalParameters(ComponentModel
model, boolean supports)
+ {
+ model.getSupportsInformalParameters();
+ setReturnValue(supports);
+ }
+
@Test
public void write_binding()
{
@@ -251,6 +261,8 @@
train_getParameterModel(model, "barney", null);
+ train_getSupportsInformalParameters(model, true);
+
train_getLog(model, log);
binding.getBindingType();