1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.services.impl; |
16 |
| |
17 |
| import java.util.Collections; |
18 |
| import java.util.HashMap; |
19 |
| import java.util.Map; |
20 |
| |
21 |
| import org.apache.commons.logging.Log; |
22 |
| import org.apache.hivemind.ClassResolver; |
23 |
| import org.apache.hivemind.service.ClassFactory; |
24 |
| import org.apache.tapestry.enhance.EnhancedClassValidator; |
25 |
| import org.apache.tapestry.enhance.EnhancementOperationImpl; |
26 |
| import org.apache.tapestry.enhance.EnhancementWorker; |
27 |
| import org.apache.tapestry.event.ResetEventListener; |
28 |
| import org.apache.tapestry.services.ComponentConstructor; |
29 |
| import org.apache.tapestry.services.ComponentConstructorFactory; |
30 |
| import org.apache.tapestry.spec.IComponentSpecification; |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| public class ComponentConstructorFactoryImpl implements ComponentConstructorFactory, |
40 |
| ResetEventListener |
41 |
| { |
42 |
| private Log _log; |
43 |
| |
44 |
| private ClassFactory _classFactory; |
45 |
| |
46 |
| private ClassResolver _classResolver; |
47 |
| |
48 |
| private EnhancedClassValidator _validator; |
49 |
| |
50 |
| private EnhancementWorker _chain; |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| private Map _cachedConstructors = Collections.synchronizedMap(new HashMap()); |
58 |
| |
59 |
0
| public void resetEventDidOccur()
|
60 |
| { |
61 |
0
| _cachedConstructors.clear();
|
62 |
| } |
63 |
| |
64 |
1107
| public ComponentConstructor getComponentConstructor(IComponentSpecification specification,
|
65 |
| String className) |
66 |
| { |
67 |
1107
| ComponentConstructor result = (ComponentConstructor) _cachedConstructors.get(specification);
|
68 |
| |
69 |
1107
| if (result == null)
|
70 |
| { |
71 |
418
| Class baseClass = _classResolver.findClass(className);
|
72 |
| |
73 |
418
| EnhancementOperationImpl eo = new EnhancementOperationImpl(_classResolver,
|
74 |
| specification, baseClass, _classFactory, _log); |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
418
| _chain.performEnhancement(eo, specification);
|
80 |
| |
81 |
418
| result = eo.getConstructor();
|
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
418
| _validator.validate(baseClass, result.getComponentClass(), specification);
|
89 |
| |
90 |
418
| _cachedConstructors.put(specification, result);
|
91 |
| } |
92 |
| |
93 |
1107
| return result;
|
94 |
| } |
95 |
| |
96 |
41
| public void setClassFactory(ClassFactory classFactory)
|
97 |
| { |
98 |
41
| _classFactory = classFactory;
|
99 |
| } |
100 |
| |
101 |
41
| public void setClassResolver(ClassResolver classResolver)
|
102 |
| { |
103 |
41
| _classResolver = classResolver;
|
104 |
| } |
105 |
| |
106 |
41
| public void setValidator(EnhancedClassValidator validator)
|
107 |
| { |
108 |
41
| _validator = validator;
|
109 |
| } |
110 |
| |
111 |
41
| public void setChain(EnhancementWorker chain)
|
112 |
| { |
113 |
41
| _chain = chain;
|
114 |
| } |
115 |
| |
116 |
41
| public void setLog(Log log)
|
117 |
| { |
118 |
41
| _log = log;
|
119 |
| } |
120 |
| } |