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.hivemind.util.Defense; |
25 |
| import org.apache.tapestry.enhance.EnhancedClassValidator; |
26 |
| import org.apache.tapestry.enhance.EnhancementOperationImpl; |
27 |
| import org.apache.tapestry.enhance.EnhancementWorker; |
28 |
| import org.apache.tapestry.event.ReportStatusEvent; |
29 |
| import org.apache.tapestry.event.ReportStatusListener; |
30 |
| import org.apache.tapestry.event.ResetEventListener; |
31 |
| import org.apache.tapestry.services.ComponentConstructor; |
32 |
| import org.apache.tapestry.services.ComponentConstructorFactory; |
33 |
| import org.apache.tapestry.spec.IComponentSpecification; |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| public class ComponentConstructorFactoryImpl implements ComponentConstructorFactory, |
43 |
| ResetEventListener, ReportStatusListener |
44 |
| { |
45 |
| private String _serviceId; |
46 |
| |
47 |
| private Log _log; |
48 |
| |
49 |
| private ClassFactory _classFactory; |
50 |
| |
51 |
| private ClassResolver _classResolver; |
52 |
| |
53 |
| private EnhancedClassValidator _validator; |
54 |
| |
55 |
| private EnhancementWorker _chain; |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| private Map _cachedConstructors = Collections.synchronizedMap(new HashMap()); |
63 |
| |
64 |
0
| public void resetEventDidOccur()
|
65 |
| { |
66 |
0
| _cachedConstructors.clear();
|
67 |
| } |
68 |
| |
69 |
34
| public synchronized void reportStatus(ReportStatusEvent event)
|
70 |
| { |
71 |
34
| event.title(_serviceId);
|
72 |
| |
73 |
34
| event.property("enhanced class count", _cachedConstructors.size());
|
74 |
34
| event.collection("enhanced classes", _cachedConstructors.keySet());
|
75 |
| } |
76 |
| |
77 |
2012
| public ComponentConstructor getComponentConstructor(IComponentSpecification specification,
|
78 |
| String className) |
79 |
| { |
80 |
2012
| Defense.notNull(specification, "specification");
|
81 |
| |
82 |
2012
| synchronized (specification)
|
83 |
| { |
84 |
2012
| ComponentConstructor result = (ComponentConstructor) _cachedConstructors
|
85 |
| .get(specification); |
86 |
| |
87 |
2012
| if (result == null)
|
88 |
| { |
89 |
778
| Class baseClass = _classResolver.findClass(className);
|
90 |
| |
91 |
778
| EnhancementOperationImpl eo = new EnhancementOperationImpl(_classResolver,
|
92 |
| specification, baseClass, _classFactory, _log); |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
778
| _chain.performEnhancement(eo, specification);
|
98 |
| |
99 |
778
| result = eo.getConstructor();
|
100 |
| |
101 |
| |
102 |
| |
103 |
778
| _validator.validate(baseClass, result.getComponentClass(), specification);
|
104 |
| |
105 |
778
| _cachedConstructors.put(specification, result);
|
106 |
| } |
107 |
| |
108 |
2012
| return result;
|
109 |
| } |
110 |
| } |
111 |
| |
112 |
78
| public void setClassFactory(ClassFactory classFactory)
|
113 |
| { |
114 |
78
| _classFactory = classFactory;
|
115 |
| } |
116 |
| |
117 |
78
| public void setClassResolver(ClassResolver classResolver)
|
118 |
| { |
119 |
78
| _classResolver = classResolver;
|
120 |
| } |
121 |
| |
122 |
78
| public void setValidator(EnhancedClassValidator validator)
|
123 |
| { |
124 |
78
| _validator = validator;
|
125 |
| } |
126 |
| |
127 |
78
| public void setChain(EnhancementWorker chain)
|
128 |
| { |
129 |
78
| _chain = chain;
|
130 |
| } |
131 |
| |
132 |
78
| public void setLog(Log log)
|
133 |
| { |
134 |
78
| _log = log;
|
135 |
| } |
136 |
| |
137 |
78
| public void setServiceId(String serviceId)
|
138 |
| { |
139 |
78
| _serviceId = serviceId;
|
140 |
| } |
141 |
| } |