1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package org.apache.tapestry.enhance; |
15 | |
|
16 | |
import org.apache.commons.logging.Log; |
17 | |
import org.apache.hivemind.Location; |
18 | |
import org.apache.hivemind.internal.Module; |
19 | |
import org.apache.tapestry.spec.IComponentSpecification; |
20 | |
|
21 | |
import java.util.Iterator; |
22 | |
import java.util.List; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public class AutowireWorker implements EnhancementWorker |
31 | |
{ |
32 | |
private final Log _log; |
33 | |
|
34 | |
private final Module _module; |
35 | |
|
36 | |
public AutowireWorker( Module module, Log log) |
37 | 0 | { |
38 | 0 | _module = module; |
39 | 0 | _log = log; |
40 | 0 | } |
41 | |
|
42 | |
public void performEnhancement( EnhancementOperation op, IComponentSpecification spec ) |
43 | |
{ |
44 | 0 | final List propertyNames = op.findUnclaimedAbstractProperties(); |
45 | |
|
46 | 0 | for( Iterator i = propertyNames.iterator(); i.hasNext(); ) { |
47 | |
|
48 | 0 | String propertyName = ( String ) i.next(); |
49 | |
|
50 | 0 | Class propertyType = op.getPropertyType( propertyName ); |
51 | 0 | if( propertyType == null ) |
52 | 0 | propertyType = Object.class; |
53 | |
|
54 | 0 | if (!op.canClaimAsReadOnlyProperty(propertyName)) |
55 | 0 | continue; |
56 | |
|
57 | 0 | if( _module.containsService( propertyType )) { |
58 | |
|
59 | 0 | final Object serviceProxy = _module.getService( propertyType ); |
60 | 0 | final Location location = spec.getLocation(); |
61 | |
|
62 | 0 | _log.debug( EnhanceMessages.autowiring( propertyName, spec, serviceProxy ) ); |
63 | |
|
64 | 0 | final String fieldName = op.addInjectedField( "_$" + propertyName, propertyType, serviceProxy ); |
65 | |
|
66 | 0 | EnhanceUtils.createSimpleAccessor( op, fieldName, propertyName, propertyType, location ); |
67 | 0 | op.claimReadonlyProperty( propertyName ); |
68 | |
} |
69 | |
|
70 | 0 | } |
71 | 0 | } |
72 | |
} |