| 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.annotations.PageActivationContext; |
| 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.TransformMethodSignature; |
| 22 | |
|
| 23 | |
import java.lang.reflect.Modifier; |
| 24 | |
import java.util.List; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | 66 | public class PageActivationContextWorker implements ComponentClassTransformWorker |
| 34 | |
{ |
| 35 | |
public void transform(ClassTransformation transformation, MutableComponentModel model) |
| 36 | |
{ |
| 37 | 822 | List<String> fields = transformation.findFieldsWithAnnotation(PageActivationContext.class); |
| 38 | |
|
| 39 | 822 | if (fields.size() > 1) |
| 40 | 2 | throw new RuntimeException(TransformMessages.illegalNumberOfPageActivationContextHandlers(fields)); |
| 41 | |
|
| 42 | 820 | for (String fieldName : fields) |
| 43 | |
{ |
| 44 | 8 | PageActivationContext annotation = transformation.getFieldAnnotation(fieldName, |
| 45 | |
PageActivationContext.class); |
| 46 | |
|
| 47 | 8 | String fieldType = transformation.getFieldType(fieldName); |
| 48 | |
|
| 49 | 8 | if (annotation.activate()) |
| 50 | |
{ |
| 51 | 4 | TransformMethodSignature activate |
| 52 | |
= new TransformMethodSignature(Modifier.PROTECTED | Modifier.FINAL, "void", |
| 53 | |
"onActivate", |
| 54 | |
new String[] { fieldType }, null); |
| 55 | 4 | transformation.addTransformedMethod(activate, fieldName + " = $1;"); |
| 56 | |
} |
| 57 | |
|
| 58 | 8 | if (annotation.passivate()) |
| 59 | |
{ |
| 60 | 4 | TransformMethodSignature passivate |
| 61 | |
= new TransformMethodSignature(Modifier.PROTECTED | Modifier.FINAL, "java.lang.Object", |
| 62 | |
"onPassivate", |
| 63 | |
null, null); |
| 64 | 4 | transformation.addTransformedMethod(passivate, "return ($w) " + fieldName + ";"); |
| 65 | |
} |
| 66 | 8 | } |
| 67 | |
|
| 68 | 820 | } |
| 69 | |
} |