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 17:18:28 UTC
svn commit: r1150403 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/internal/transform/
main/java/org/apache/tapestry5/services/
test/java/org/apache/tapestry5/internal/transform/
Author: hlship
Date: Sun Jul 24 15:18:27 2011
New Revision: 1150403
URL: http://svn.apache.org/viewvc?rev=1150403&view=rev
Log:
TAP5-1508: Convert HeartbeatDeferredWorker to CCTW2
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/HeartbeatDeferredWorker.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/transform/HeartbeatDeferredWorkerTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/HeartbeatDeferredWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/HeartbeatDeferredWorker.java?rev=1150403&r1=1150402&r2=1150403&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/HeartbeatDeferredWorker.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/HeartbeatDeferredWorker.java Sun Jul 24 15:18:27 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.
@@ -16,24 +16,24 @@ package org.apache.tapestry5.internal.tr
import org.apache.tapestry5.annotations.HeartbeatDeferred;
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.plastic.MethodAdvice;
+import org.apache.tapestry5.plastic.MethodInvocation;
+import org.apache.tapestry5.plastic.PlasticClass;
+import org.apache.tapestry5.plastic.PlasticMethod;
import org.apache.tapestry5.services.Heartbeat;
-import org.apache.tapestry5.services.TransformMethod;
+import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2;
+import org.apache.tapestry5.services.transform.TransformationSupport;
-public class HeartbeatDeferredWorker implements ComponentClassTransformWorker
+public class HeartbeatDeferredWorker implements ComponentClassTransformWorker2
{
private final Heartbeat heartbeat;
- private final ComponentMethodAdvice deferredAdvice = new ComponentMethodAdvice()
+ private final MethodAdvice deferredAdvice = new MethodAdvice()
{
- public void advise(final ComponentMethodInvocation invocation)
+ public void advise(final MethodInvocation invocation)
{
heartbeat.defer(new Runnable()
{
-
public void run()
{
invocation.proceed();
@@ -47,15 +47,15 @@ public class HeartbeatDeferredWorker imp
this.heartbeat = heartbeat;
}
- public void transform(ClassTransformation transformation, MutableComponentModel model)
+ public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model)
{
- for (TransformMethod method : transformation.matchMethodsWithAnnotation(HeartbeatDeferred.class))
+ for (PlasticMethod method : plasticClass.getMethodsWithAnnotation(HeartbeatDeferred.class))
{
deferMethodInvocations(method);
}
}
- void deferMethodInvocations(TransformMethod method)
+ void deferMethodInvocations(PlasticMethod method)
{
validateVoid(method);
@@ -65,19 +65,18 @@ public class HeartbeatDeferredWorker imp
}
- private void validateNoCheckedExceptions(TransformMethod method)
+ private void validateNoCheckedExceptions(PlasticMethod method)
{
- if (method.getSignature().getExceptionTypes().length > 0)
+ if (method.getDescription().checkedExceptionTypes.length > 0)
throw new RuntimeException(
- String
- .format(
- "Method %s is not compatible with the @HeartbeatDeferred annotation, as it throws checked exceptions.",
- method.getMethodIdentifier()));
+ String.format(
+ "Method %s is not compatible with the @HeartbeatDeferred annotation, as it throws checked exceptions.",
+ method.getMethodIdentifier()));
}
- private void validateVoid(TransformMethod method)
+ private void validateVoid(PlasticMethod method)
{
- if (!method.getSignature().getReturnType().equals("void"))
+ if (!method.isVoid())
throw new RuntimeException(String.format(
"Method %s is not compatible with the @HeartbeatDeferred annotation, as it is not a void method.",
method.getMethodIdentifier()));
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=1150403&r1=1150402&r2=1150403&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 15:18:27 2011
@@ -544,6 +544,8 @@ public final class TapestryModule
* <dd>Support for the {@link SessionAttribute}</dd>
* <dt>Log</dt>
* <dd>Checks for the {@link org.apache.tapestry5.annotations.Log} annotation</dd>
+ * <dt>HeartbeatDeferred
+ * <dd>Support for the {@link HeartbeatDeferred} annotation, which defers method invocation to the end of the {@link Heartbeat}
* </dl>
*/
@Contribute(ComponentClassTransformWorker2.class)
@@ -615,6 +617,8 @@ public final class TapestryModule
configuration.addInstance("Log", LogWorker.class);
+ configuration.addInstance("HeartbeatDeferred", HeartbeatDeferredWorker.class, "after:RenderPhase");
+
// 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.
@@ -627,8 +631,6 @@ public final class TapestryModule
* <dl>
* <dt>Inject</dt>
* <dd>Used with the {@link org.apache.tapestry5.ioc.annotations.Inject} annotation, when a value is supplied</dd>
- * <dt>HeartbeatDeferred
- * <dd>Support for the {@link HeartbeatDeferred} annotation
* </dl>
*/
@Contribute(ComponentClassTransformWorker2.class)
@@ -637,8 +639,6 @@ public final class TapestryModule
OrderedConfiguration<ComponentClassTransformWorker> configuration)
{
configuration.addInstance("Inject", InjectWorker.class);
-
- configuration.addInstance("HeartbeatDeferred", HeartbeatDeferredWorker.class, "after:RenderPhase");
}
/**
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/transform/HeartbeatDeferredWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/transform/HeartbeatDeferredWorkerTest.java?rev=1150403&r1=1150402&r2=1150403&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/transform/HeartbeatDeferredWorkerTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/transform/HeartbeatDeferredWorkerTest.java Sun Jul 24 15:18:27 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.
@@ -14,36 +14,51 @@
package org.apache.tapestry5.internal.transform;
-import java.lang.reflect.Modifier;
-
import org.apache.tapestry5.internal.test.InternalBaseTestCase;
-import org.apache.tapestry5.services.TransformMethod;
-import org.apache.tapestry5.services.TransformMethodSignature;
+import org.apache.tapestry5.plastic.MethodDescription;
+import org.apache.tapestry5.plastic.PlasticMethod;
+import org.apache.tapestry5.plastic.PlasticUtils;
import org.testng.annotations.Test;
public class HeartbeatDeferredWorkerTest extends InternalBaseTestCase
{
private final HeartbeatDeferredWorker worker = new HeartbeatDeferredWorker(null);
+ public String shouldReturnVoid()
+ {
+ return null;
+ }
+
+ public void noCheckedException() throws Exception
+ {
+ }
+
@Test
public void non_void_method_will_fail()
{
- testFailure(new TransformMethodSignature(Modifier.PUBLIC, "java.lang.String", "shouldReturnVoid", null, null),
+ testFailure(
+ PlasticUtils.getMethodDescription(getClass(), "shouldReturnVoid"),
"as it is not a void method");
}
@Test
public void checked_exceptions_will_fail()
{
- testFailure(new TransformMethodSignature(Modifier.PUBLIC, "void", "noCheckedExceptions", null, new String[]
- { "java.lang.Exception" }), "as it throws checked exceptions");
+ testFailure(PlasticUtils.getMethodDescription(getClass(), "noCheckedException"),
+ "as it throws checked exceptions");
}
- private void testFailure(TransformMethodSignature transformMethodSignature, String messageFragment)
+ private void testFailure(MethodDescription description, String messageFragment)
{
- TransformMethod method = newMock(TransformMethod.class);
+ PlasticMethod method = newMock(PlasticMethod.class);
- expect(method.getSignature()).andReturn(transformMethodSignature).atLeastOnce();
+ boolean isVoid = description.returnType.equals("void");
+ expect(method.isVoid()).andReturn(isVoid);
+
+ if (isVoid)
+ {
+ expect(method.getDescription()).andReturn(description).atLeastOnce();
+ }
expect(method.getMethodIdentifier()).andReturn("<MethodId>");
@@ -53,8 +68,7 @@ public class HeartbeatDeferredWorkerTest
{
worker.deferMethodInvocations(method);
unreachable();
- }
- catch (RuntimeException ex)
+ } catch (RuntimeException ex)
{
assertMessageContains(ex, messageFragment);
}