| 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.Property; |
| 18 | |
import org.apache.tapestry5.ioc.internal.util.InternalUtils; |
| 19 | |
import org.apache.tapestry5.model.MutableComponentModel; |
| 20 | |
import org.apache.tapestry5.services.ClassTransformation; |
| 21 | |
import org.apache.tapestry5.services.ComponentClassTransformWorker; |
| 22 | |
import org.apache.tapestry5.services.TransformMethodSignature; |
| 23 | |
|
| 24 | |
import java.lang.reflect.Modifier; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | 58 | public class PropertyWorker implements ComponentClassTransformWorker |
| 34 | |
{ |
| 35 | |
public void transform(ClassTransformation transformation, MutableComponentModel model) |
| 36 | |
{ |
| 37 | 812 | for (String fieldName : transformation.findFieldsWithAnnotation(Property.class)) |
| 38 | |
{ |
| 39 | 230 | Property annotation = transformation.getFieldAnnotation(fieldName, Property.class); |
| 40 | |
|
| 41 | 230 | String propertyName = InternalUtils.capitalize(InternalUtils.stripMemberName(fieldName)); |
| 42 | |
|
| 43 | 230 | String fieldType = transformation.getFieldType(fieldName); |
| 44 | |
|
| 45 | 230 | if (annotation.read()) |
| 46 | |
{ |
| 47 | 230 | TransformMethodSignature getter |
| 48 | |
= new TransformMethodSignature(Modifier.PUBLIC | Modifier.FINAL, fieldType, |
| 49 | |
"get" + propertyName, |
| 50 | |
null, null); |
| 51 | |
|
| 52 | 230 | transformation.addTransformedMethod(getter, "return " + fieldName + ";"); |
| 53 | |
} |
| 54 | |
|
| 55 | 228 | if (annotation.write()) |
| 56 | |
{ |
| 57 | 156 | TransformMethodSignature setter |
| 58 | |
= new TransformMethodSignature(Modifier.PUBLIC | Modifier.FINAL, "void", "set" + propertyName, |
| 59 | |
new String[] {fieldType}, null); |
| 60 | |
|
| 61 | 156 | transformation.addTransformedMethod(setter, fieldName + " = $1;"); |
| 62 | |
} |
| 63 | |
|
| 64 | |
|
| 65 | 228 | } |
| 66 | 810 | } |
| 67 | |
} |