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 2011/07/24 05:45:31 UTC
svn commit: r1150273 - in
/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5:
internal/transform/PageLifecycleAnnotationWorker.java
services/TapestryModule.java services/TransformConstants.java
Author: hlship
Date: Sun Jul 24 03:45:30 2011
New Revision: 1150273
URL: http://svn.apache.org/viewvc?rev=1150273&view=rev
Log:
TAP5-1508: Record PageLifecycleAnnotationWorker to CCTW2
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PageLifecycleAnnotationWorker.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformConstants.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PageLifecycleAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PageLifecycleAnnotationWorker.java?rev=1150273&r1=1150272&r2=1150273&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PageLifecycleAnnotationWorker.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PageLifecycleAnnotationWorker.java Sun Jul 24 03:45:30 2011
@@ -1,4 +1,4 @@
-// Copyright 2007, 2010 The Apache Software Foundation
+// Copyright 2007, 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.
@@ -14,97 +14,93 @@
package org.apache.tapestry5.internal.transform;
-import java.lang.annotation.Annotation;
-import java.util.List;
-
+import org.apache.tapestry5.func.F;
+import org.apache.tapestry5.func.Flow;
import org.apache.tapestry5.func.Predicate;
+import org.apache.tapestry5.func.Worker;
import org.apache.tapestry5.model.MutableComponentModel;
-import org.apache.tapestry5.services.ClassTransformation;
-import org.apache.tapestry5.services.ComponentClassTransformWorker;
-import org.apache.tapestry5.services.ComponentMethodAdvice;
-import org.apache.tapestry5.services.ComponentMethodInvocation;
-import org.apache.tapestry5.services.MethodAccess;
-import org.apache.tapestry5.services.MethodInvocationResult;
-import org.apache.tapestry5.services.TransformMethod;
-import org.apache.tapestry5.services.TransformMethodSignature;
+import org.apache.tapestry5.plastic.*;
+import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2;
+import org.apache.tapestry5.services.transform.TransformationSupport;
+
+import java.lang.annotation.Annotation;
/**
* Similar to {@link org.apache.tapestry5.internal.transform.RenderPhaseMethodWorker} but applies to annotations/methods
* related to the overall page lifecycle. Page lifecycle methods are always void and take no parameters.
*/
-public class PageLifecycleAnnotationWorker implements ComponentClassTransformWorker
+public class PageLifecycleAnnotationWorker implements ComponentClassTransformWorker2
{
private final Class<? extends Annotation> methodAnnotationClass;
- private final TransformMethodSignature lifecycleMethodSignature;
+ private final MethodDescription lifecycleMethodDescription;
private final String methodAlias;
+ private final Predicate<PlasticMethod> MATCHER = new Predicate<PlasticMethod>()
+ {
+ public boolean accept(PlasticMethod method)
+ {
+ return method.getDescription().methodName.equalsIgnoreCase(methodAlias)
+ || method.hasAnnotation(methodAnnotationClass);
+ }
+ };
+
+ private final Worker<PlasticMethod> VALIDATE = new Worker<PlasticMethod>()
+ {
+ public void work(PlasticMethod method)
+ {
+ if (!method.isVoid())
+ throw new RuntimeException(String.format("Method %s is a lifecycle method and should return void.", method
+ .getMethodIdentifier()));
+
+ if (!method.getParameters().isEmpty())
+ throw new RuntimeException(String.format("Method %s is a lifecycle method and should take no parameters.",
+ method.getMethodIdentifier()));
+
+ }
+ };
+
public PageLifecycleAnnotationWorker(Class<? extends Annotation> methodAnnotationClass,
- TransformMethodSignature lifecycleMethodSignature, String methodAlias)
+ MethodDescription lifecycleMethodDescription, String methodAlias)
{
this.methodAnnotationClass = methodAnnotationClass;
- this.lifecycleMethodSignature = lifecycleMethodSignature;
+ this.lifecycleMethodDescription = lifecycleMethodDescription;
this.methodAlias = methodAlias;
}
- public void transform(final ClassTransformation transformation, MutableComponentModel model)
+ public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model)
{
- for (TransformMethod method : matchLifecycleMethods(transformation))
+ for (PlasticMethod method : matchLifecycleMethods(plasticClass))
{
- invokeMethodWithinLifecycle(transformation, method);
+ invokeMethodWithinLifecycle(plasticClass, method);
}
}
- private void invokeMethodWithinLifecycle(final ClassTransformation transformation, TransformMethod method)
- {
- validateMethodSignature(method);
-
- final MethodAccess access = method.getAccess();
- ComponentMethodAdvice advice = createAdviceToInvokeMethod(access);
+ private void invokeMethodWithinLifecycle(PlasticClass plasticClass, PlasticMethod method)
+ {
+ MethodHandle handle = method.getHandle();
- transformation.getOrCreateMethod(lifecycleMethodSignature).addAdvice(advice);
+ plasticClass.introduceMethod(lifecycleMethodDescription).addAdvice(createAdvice(handle));
}
- private ComponentMethodAdvice createAdviceToInvokeMethod(final MethodAccess access)
+ private MethodAdvice createAdvice(final MethodHandle handle)
{
- return new ComponentMethodAdvice()
+ return new MethodAdvice()
{
- public void advise(ComponentMethodInvocation invocation)
+ public void advise(MethodInvocation invocation)
{
invocation.proceed();
- MethodInvocationResult result = access.invoke(invocation.getInstance());
-
- result.rethrow();
+ handle.invoke(invocation.getInstance()).rethrow();
}
};
}
- private void validateMethodSignature(TransformMethod method)
- {
- TransformMethodSignature signature = method.getSignature();
-
- if (!signature.getReturnType().equals("void"))
- throw new RuntimeException(String.format("Method %s is a lifecycle method and should return void.", method
- .getMethodIdentifier()));
- if (signature.getParameterTypes().length > 0)
- throw new RuntimeException(String.format("Method %s is a lifecycle method and should take no parameters.",
- method.getMethodIdentifier()));
- }
-
- private List<TransformMethod> matchLifecycleMethods(final ClassTransformation transformation)
+ private Flow<PlasticMethod> matchLifecycleMethods(PlasticClass plasticClass)
{
- return transformation.matchMethods(new Predicate<TransformMethod>()
- {
-
- public boolean accept(TransformMethod method)
- {
- return method.getName().equalsIgnoreCase(methodAlias)
- || method.getAnnotation(methodAnnotationClass) != null;
- }
- });
+ return F.flow(plasticClass.getMethods()).filter(MATCHER).each(VALIDATE);
}
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=1150273&r1=1150272&r2=1150273&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java Sun Jul 24 03:45:30 2011
@@ -70,6 +70,7 @@ import org.apache.tapestry5.ioc.util.IdA
import org.apache.tapestry5.ioc.util.StrategyRegistry;
import org.apache.tapestry5.json.JSONArray;
import org.apache.tapestry5.json.JSONObject;
+import org.apache.tapestry5.plastic.MethodDescription;
import org.apache.tapestry5.runtime.Component;
import org.apache.tapestry5.runtime.ComponentResourcesAware;
import org.apache.tapestry5.runtime.RenderCommand;
@@ -525,6 +526,8 @@ public final class TapestryModule
* <dd>Checks for the {@link org.apache.tapestry5.annotations.Cached} annotation</dd>
* <dt>ActivationRequestParameter</dt>
* <dd>Support for the {@link ActivationRequestParameter} annotation</dd>
+ * <dt>PageLoaded, PageAttached, PageDetached</dt>
+ * <dd>Support for annotations {@link PageLoaded}, {@link PageAttached}, {@link PageDetached}</dd>
* </dl>
*/
@Contribute(ComponentClassTransformWorker2.class)
@@ -582,8 +585,13 @@ public final class TapestryModule
configuration.addInstance("DiscardAfter", DiscardAfterWorker.class);
+ add(configuration, PageLoaded.class, TransformConstants.CONTAINING_PAGE_DID_LOAD_DESCRIPTION);
+ add(configuration, PageAttached.class, TransformConstants.CONTAINING_PAGE_DID_ATTACH_DESCRIPTION);
+ add(configuration, PageDetached.class, TransformConstants.CONTAINING_PAGE_DID_DETACH_DESCRIPTION);
+
configuration.addInstance("PageReset", PageResetAnnotationWorker.class);
+
// This one is always last. Any additional private fields that aren't
// annotated will
// be converted to clear out at the end of the request.
@@ -629,15 +637,6 @@ public final class TapestryModule
configuration.addInstance("InjectNamed", InjectNamedWorker.class);
- // Ideally, these should be ordered pretty late in the process to make
- // sure there are no
- // side effects with other workers that do work inside the page
- // lifecycle methods.
-
- add(configuration, PageLoaded.class, TransformConstants.CONTAINING_PAGE_DID_LOAD_SIGNATURE, "pageLoaded");
- add(configuration, PageAttached.class, TransformConstants.CONTAINING_PAGE_DID_ATTACH_SIGNATURE, "pageAttached");
- add(configuration, PageDetached.class, TransformConstants.CONTAINING_PAGE_DID_DETACH_SIGNATURE, "pageDetached");
-
configuration.addInstance("Persist", PersistWorker.class);
configuration.addInstance("Log", LogWorker.class);
@@ -1200,15 +1199,14 @@ public final class TapestryModule
configuration.addInstance("Messages", MessagesConstraintGenerator.class);
}
- private static void add(OrderedConfiguration<ComponentClassTransformWorker> configuration,
- Class<? extends Annotation> annotationClass, TransformMethodSignature lifecycleMethodSignature,
- String methodAlias)
+ private static void add(OrderedConfiguration<ComponentClassTransformWorker2> configuration,
+ Class<? extends Annotation> annotationClass, MethodDescription description)
{
- ComponentClassTransformWorker worker = new PageLifecycleAnnotationWorker(annotationClass,
- lifecycleMethodSignature, methodAlias);
-
String name = TapestryInternalUtils.lastTerm(annotationClass.getName());
+ ComponentClassTransformWorker2 worker = new PageLifecycleAnnotationWorker(annotationClass,
+ description, name);
+
configuration.add(name, worker);
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformConstants.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformConstants.java?rev=1150273&r1=1150272&r2=1150273&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformConstants.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformConstants.java Sun Jul 24 03:45:30 2011
@@ -109,17 +109,35 @@ public final class TransformConstants
/**
* Signature for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidDetach()}.
+ *
+ * @deprecated Deprecated in Tapestry 5.3, use {@link #CONTAINING_PAGE_DID_DETACH_DESCRIPTION}
*/
public static final TransformMethodSignature CONTAINING_PAGE_DID_DETACH_SIGNATURE = new TransformMethodSignature(
"containingPageDidDetach");
/**
+ * Description for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidDetach()}.
+ *
+ * @since 5.3
+ */
+ public static final MethodDescription CONTAINING_PAGE_DID_DETACH_DESCRIPTION = PlasticUtils.getMethodDescription(PageLifecycleListener.class, "containingPageDidDetach");
+
+ /**
* Signature for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidAttach()}.
+ *
+ * @deprecated Deprecated in Tapestry 5.3, use {@link #CONTAINING_PAGE_DID_ATTACH_DESCRIPTION}
*/
public static final TransformMethodSignature CONTAINING_PAGE_DID_ATTACH_SIGNATURE = new TransformMethodSignature(
"containingPageDidAttach");
/**
+ * Description for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidAttach()}.
+ *
+ * @since 5.3
+ */
+ public static final MethodDescription CONTAINING_PAGE_DID_ATTACH_DESCRIPTION = PlasticUtils.getMethodDescription(PageLifecycleListener.class, "containingPageDidAttach");
+
+ /**
* Signature for {@link org.apache.tapestry5.runtime.PageLifecycleListener#restoreStateBeforePageAttach()}
*
* @since 5.1.0.1