| 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.ioc.ObjectLocator; |
| 18 | |
import org.apache.tapestry5.ioc.annotations.Inject; |
| 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.InjectionProvider; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
public class InjectWorker implements ComponentClassTransformWorker |
| 32 | |
{ |
| 33 | |
private final ObjectLocator locator; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
private final InjectionProvider injectionProvider; |
| 38 | |
|
| 39 | |
public InjectWorker(ObjectLocator locator, InjectionProvider injectionProvider) |
| 40 | 64 | { |
| 41 | 64 | this.locator = locator; |
| 42 | 64 | this.injectionProvider = injectionProvider; |
| 43 | 64 | } |
| 44 | |
|
| 45 | |
public final void transform(ClassTransformation transformation, MutableComponentModel model) |
| 46 | |
{ |
| 47 | 822 | for (String fieldName : transformation.findFieldsWithAnnotation(Inject.class)) |
| 48 | |
{ |
| 49 | 838 | Inject annotation = transformation.getFieldAnnotation(fieldName, Inject.class); |
| 50 | |
|
| 51 | |
try |
| 52 | |
{ |
| 53 | 838 | String fieldType = transformation.getFieldType(fieldName); |
| 54 | |
|
| 55 | 838 | Class type = transformation.toClass(fieldType); |
| 56 | |
|
| 57 | 838 | boolean success = injectionProvider.provideInjection( |
| 58 | |
fieldName, |
| 59 | |
type, |
| 60 | |
locator, |
| 61 | |
transformation, |
| 62 | |
model); |
| 63 | |
|
| 64 | 834 | if (success) transformation.claimField(fieldName, annotation); |
| 65 | |
} |
| 66 | 4 | catch (RuntimeException ex) |
| 67 | |
{ |
| 68 | 4 | throw new RuntimeException(TransformMessages.fieldInjectionError(transformation |
| 69 | |
.getClassName(), fieldName, ex), ex); |
| 70 | 834 | } |
| 71 | |
|
| 72 | 834 | } |
| 73 | 818 | } |
| 74 | |
} |