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 2010/06/25 02:05:45 UTC
svn commit: r957757 - in
/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5:
internal/services/ services/
Author: hlship
Date: Fri Jun 25 00:05:44 2010
New Revision: 957757
URL: http://svn.apache.org/viewvc?rev=957757&view=rev
Log:
TAP5-1190: Add new interface ComponentInstanceOperation as a simplified alternative to ComponentMethodAdvice
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentInstanceOperation.java
- copied, changed from r957756, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentMethodAdvice.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalClassTransformationImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentMethodAdvice.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformMethod.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalClassTransformationImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalClassTransformationImpl.java?rev=957757&r1=957756&r2=957757&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalClassTransformationImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalClassTransformationImpl.java Fri Jun 25 00:05:44 2010
@@ -184,6 +184,16 @@ public final class InternalClassTransfor
formatter.format("add advice %s : %s\n\n", sig.getMediumDescription(), advice);
}
+ public void addOperationAfter(ComponentInstanceOperation operation)
+ {
+ addAdvice(toAfterAdvice(operation));
+ }
+
+ public void addOperationBefore(ComponentInstanceOperation operation)
+ {
+ addAdvice(toBeforeAdvice(operation));
+ }
+
public MethodAccess getAccess()
{
failIfFrozen();
@@ -2268,4 +2278,32 @@ public final class InternalClassTransfor
"Method ClassTransformation.%s has been deprecated and is no longer functional. "
+ "Please consult the JavaDoc for a suitable replacement.", methodName));
}
+
+ private static ComponentMethodAdvice toBeforeAdvice(final ComponentInstanceOperation operation)
+ {
+ return new ComponentMethodAdvice()
+ {
+
+ public void advise(ComponentMethodInvocation invocation)
+ {
+ operation.invoke(invocation.getInstance());
+
+ invocation.proceed();
+ }
+ };
+ }
+
+ private static ComponentMethodAdvice toAfterAdvice(final ComponentInstanceOperation operation)
+ {
+ return new ComponentMethodAdvice()
+ {
+ public void advise(ComponentMethodInvocation invocation)
+ {
+ invocation.proceed();
+
+ operation.invoke(invocation.getInstance());
+ }
+ };
+ }
+
}
Copied: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentInstanceOperation.java (from r957756, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentMethodAdvice.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentInstanceOperation.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentInstanceOperation.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentMethodAdvice.java&r1=957756&r2=957757&rev=957757&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentMethodAdvice.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentInstanceOperation.java Fri Jun 25 00:05:44 2010
@@ -1,4 +1,4 @@
-// Copyright 2008, 2010 The Apache Software Foundation
+// Copyright 2010 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,14 +14,18 @@
package org.apache.tapestry5.services;
+import org.apache.tapestry5.runtime.Component;
+
/**
- * An object that receives control around an "advised" method of a component. The advise can query or even replace
- * method parameters. After invoking {@link org.apache.tapestry5.services.ComponentMethodInvocation#proceed()}, the
- * advice may query and override thrown exceptions or the return value of the invocation.
+ * An operation that requires an instance of a component.
+ * This is a simpler alternative to a {@link ComponentMethodAdvice}.
*
- * @see TransformMethod#addAdvice(ComponentMethodAdvice)
+ * @since 5.2.0
+ * @see TransformMethod#addOperationAfter(ComponentInstanceOperation)
+ * @see TransformMethod#addOperationBefore(ComponentInstanceOperation)
*/
-public interface ComponentMethodAdvice
+public interface ComponentInstanceOperation
{
- void advise(ComponentMethodInvocation invocation);
+ /** Called to preform the desired operation on a component instance. */
+ public void invoke(Component instance);
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentMethodAdvice.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentMethodAdvice.java?rev=957757&r1=957756&r2=957757&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentMethodAdvice.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentMethodAdvice.java Fri Jun 25 00:05:44 2010
@@ -20,6 +20,7 @@ package org.apache.tapestry5.services;
* advice may query and override thrown exceptions or the return value of the invocation.
*
* @see TransformMethod#addAdvice(ComponentMethodAdvice)
+ * @see ComponentInstanceOperation
*/
public interface ComponentMethodAdvice
{
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformMethod.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformMethod.java?rev=957757&r1=957756&r2=957757&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformMethod.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformMethod.java Fri Jun 25 00:05:44 2010
@@ -55,6 +55,20 @@ public interface TransformMethod extends
void addAdvice(ComponentMethodAdvice advice);
/**
+ * Adds an operation that will execute before any
+ * further advice or operations. This is converted into
+ * advice that invokes the operation, then invokes {@link ComponentMethodInvocation#proceed()}.
+ */
+ void addOperationBefore(ComponentInstanceOperation operation);
+
+ /**
+ * Adds an operation that will execute after any
+ * further advice or operations. This is converted into
+ * advice that invokes {@link ComponentMethodInvocation#proceed()} before invoking the operation.
+ */
+ void addOperationAfter(ComponentInstanceOperation operation);
+
+ /**
* Converts a signature to a string used to identify the method; this consists of the
* {@link TransformMethodSignature#getMediumDescription()} appended with source file information
* and line number