| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.internal.transform; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.internal.util.MethodInvocationBuilder; |
| 18 | |
import org.apache.tapestry5.model.MutableComponentModel; |
| 19 | |
import org.apache.tapestry5.services.ClassTransformation; |
| 20 | |
import org.apache.tapestry5.services.ComponentClassTransformWorker; |
| 21 | |
import org.apache.tapestry5.services.MethodFilter; |
| 22 | |
import org.apache.tapestry5.services.TransformMethodSignature; |
| 23 | |
|
| 24 | |
import java.lang.annotation.Annotation; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | 103844 | public class PageLifecycleAnnotationWorker implements ComponentClassTransformWorker |
| 31 | |
{ |
| 32 | |
private final Class<? extends Annotation> methodAnnotationClass; |
| 33 | |
|
| 34 | |
private final TransformMethodSignature lifecycleMethodSignature; |
| 35 | |
|
| 36 | |
private final String methodAlias; |
| 37 | |
|
| 38 | 174 | private final MethodInvocationBuilder invocationBuilder = new MethodInvocationBuilder(); |
| 39 | |
|
| 40 | |
public PageLifecycleAnnotationWorker(final Class<? extends Annotation> methodAnnotationClass, |
| 41 | |
final TransformMethodSignature lifecycleMethodSignature, |
| 42 | |
final String methodAlias) |
| 43 | 174 | { |
| 44 | 174 | this.methodAnnotationClass = methodAnnotationClass; |
| 45 | 174 | this.lifecycleMethodSignature = lifecycleMethodSignature; |
| 46 | 174 | this.methodAlias = methodAlias; |
| 47 | 174 | } |
| 48 | |
|
| 49 | |
public void transform(final ClassTransformation transformation, MutableComponentModel model) |
| 50 | |
{ |
| 51 | 2436 | MethodFilter filter = new MethodFilter() |
| 52 | |
{ |
| 53 | 2436 | public boolean accept(TransformMethodSignature signature) |
| 54 | |
{ |
| 55 | 51924 | if (signature.getMethodName().equals(methodAlias)) |
| 56 | 4 | return true; |
| 57 | |
|
| 58 | 51920 | return transformation.getMethodAnnotation(signature, methodAnnotationClass) != null; |
| 59 | |
} |
| 60 | |
}; |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | 2436 | for (TransformMethodSignature signature : transformation.findMethods(filter)) |
| 67 | |
{ |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | 4 | String body = invocationBuilder.buildMethodInvocation(signature, transformation); |
| 73 | |
|
| 74 | 4 | transformation.extendMethod(lifecycleMethodSignature, body + ";"); |
| 75 | 4 | } |
| 76 | 2436 | } |
| 77 | |
|
| 78 | |
} |