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.HashMap; |
18 |
| import java.util.Map; |
19 |
| |
20 |
| import org.apache.hivemind.ApplicationRuntimeException; |
21 |
| import org.apache.hivemind.ClassResolver; |
22 |
| import org.apache.hivemind.Resource; |
23 |
| import org.apache.hivemind.util.ClasspathResource; |
24 |
| import org.apache.tapestry.INamespace; |
25 |
| import org.apache.tapestry.asset.AssetSource; |
26 |
| import org.apache.tapestry.engine.ISpecificationSource; |
27 |
| import org.apache.tapestry.engine.Namespace; |
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.parse.ISpecificationParser; |
32 |
| import org.apache.tapestry.services.NamespaceResources; |
33 |
| import org.apache.tapestry.spec.IApplicationSpecification; |
34 |
| import org.apache.tapestry.spec.IComponentSpecification; |
35 |
| import org.apache.tapestry.spec.ILibrarySpecification; |
36 |
| import org.apache.tapestry.spec.LibrarySpecification; |
37 |
| import org.apache.tapestry.util.xml.DocumentParseException; |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| public class SpecificationSourceImpl implements ISpecificationSource, ResetEventListener, |
48 |
| ReportStatusListener |
49 |
| { |
50 |
| private ClassResolver _classResolver; |
51 |
| |
52 |
| private IApplicationSpecification _specification; |
53 |
| |
54 |
| private ISpecificationParser _parser; |
55 |
| |
56 |
| private NamespaceResources _namespaceResources; |
57 |
| |
58 |
| private INamespace _applicationNamespace; |
59 |
| |
60 |
| private INamespace _frameworkNamespace; |
61 |
| |
62 |
| private AssetSource _assetSource; |
63 |
| |
64 |
| private String _serviceId; |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| private Map _componentCache = new HashMap(); |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| private Map _pageCache = new HashMap(); |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| private Map _libraryCache = new HashMap(); |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
| private Map _namespaceCache = new HashMap(); |
94 |
| |
95 |
17
| public void reportStatus(ReportStatusEvent event)
|
96 |
| { |
97 |
17
| event.title(_serviceId);
|
98 |
| |
99 |
17
| event.property("page specification count", _pageCache.size());
|
100 |
17
| event.collection("page specifications", _pageCache.keySet());
|
101 |
17
| event.property("component specification count", _componentCache.size());
|
102 |
17
| event.collection("component specifications", _componentCache.keySet());
|
103 |
| } |
104 |
| |
105 |
39
| public void initializeService()
|
106 |
| { |
107 |
39
| _namespaceResources = new NamespaceResourcesImpl(this, _assetSource);
|
108 |
| } |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
0
| public synchronized void resetEventDidOccur()
|
115 |
| { |
116 |
0
| _componentCache.clear();
|
117 |
0
| _pageCache.clear();
|
118 |
0
| _libraryCache.clear();
|
119 |
0
| _namespaceCache.clear();
|
120 |
| |
121 |
0
| _applicationNamespace = null;
|
122 |
0
| _frameworkNamespace = null;
|
123 |
| } |
124 |
| |
125 |
375
| protected IComponentSpecification parseSpecification(Resource resource, boolean asPage)
|
126 |
| { |
127 |
375
| IComponentSpecification result = null;
|
128 |
| |
129 |
375
| try
|
130 |
| { |
131 |
375
| if (asPage)
|
132 |
85
| result = _parser.parsePageSpecification(resource);
|
133 |
| else |
134 |
290
| result = _parser.parseComponentSpecification(resource);
|
135 |
| } |
136 |
| catch (DocumentParseException ex) |
137 |
| { |
138 |
0
| throw new ApplicationRuntimeException(
|
139 |
| ImplMessages.unableToParseSpecification(resource), ex); |
140 |
| } |
141 |
| |
142 |
375
| return result;
|
143 |
| } |
144 |
| |
145 |
56
| protected ILibrarySpecification parseLibrarySpecification(Resource resource)
|
146 |
| { |
147 |
56
| try
|
148 |
| { |
149 |
56
| return _parser.parseLibrarySpecification(resource);
|
150 |
| } |
151 |
| catch (DocumentParseException ex) |
152 |
| { |
153 |
0
| throw new ApplicationRuntimeException(
|
154 |
| ImplMessages.unableToParseSpecification(resource), ex); |
155 |
| } |
156 |
| |
157 |
| } |
158 |
| |
159 |
| |
160 |
| |
161 |
| |
162 |
| |
163 |
| |
164 |
| |
165 |
| |
166 |
| |
167 |
| |
168 |
290
| public synchronized IComponentSpecification getComponentSpecification(Resource resourceLocation)
|
169 |
| { |
170 |
290
| IComponentSpecification result = (IComponentSpecification) _componentCache
|
171 |
| .get(resourceLocation); |
172 |
| |
173 |
290
| if (result == null)
|
174 |
| { |
175 |
290
| result = parseSpecification(resourceLocation, false);
|
176 |
| |
177 |
290
| _componentCache.put(resourceLocation, result);
|
178 |
| } |
179 |
| |
180 |
290
| return result;
|
181 |
| } |
182 |
| |
183 |
85
| public synchronized IComponentSpecification getPageSpecification(Resource resourceLocation)
|
184 |
| { |
185 |
85
| IComponentSpecification result = (IComponentSpecification) _pageCache.get(resourceLocation);
|
186 |
| |
187 |
85
| if (result == null)
|
188 |
| { |
189 |
85
| result = parseSpecification(resourceLocation, true);
|
190 |
| |
191 |
85
| _pageCache.put(resourceLocation, result);
|
192 |
| } |
193 |
| |
194 |
85
| return result;
|
195 |
| } |
196 |
| |
197 |
56
| public synchronized ILibrarySpecification getLibrarySpecification(Resource resourceLocation)
|
198 |
| { |
199 |
56
| ILibrarySpecification result = (LibrarySpecification) _libraryCache.get(resourceLocation);
|
200 |
| |
201 |
56
| if (result == null)
|
202 |
| { |
203 |
56
| result = parseLibrarySpecification(resourceLocation);
|
204 |
56
| _libraryCache.put(resourceLocation, result);
|
205 |
| } |
206 |
| |
207 |
56
| return result;
|
208 |
| } |
209 |
| |
210 |
95
| public synchronized INamespace getApplicationNamespace()
|
211 |
| { |
212 |
95
| if (_applicationNamespace == null)
|
213 |
39
| _applicationNamespace = new Namespace(null, null, _specification, _namespaceResources);
|
214 |
| |
215 |
95
| return _applicationNamespace;
|
216 |
| } |
217 |
| |
218 |
237
| public synchronized INamespace getFrameworkNamespace()
|
219 |
| { |
220 |
237
| if (_frameworkNamespace == null)
|
221 |
| { |
222 |
39
| Resource resource = new ClasspathResource(_classResolver,
|
223 |
| "/org/apache/tapestry/Framework.library"); |
224 |
| |
225 |
39
| ILibrarySpecification ls = getLibrarySpecification(resource);
|
226 |
| |
227 |
39
| _frameworkNamespace = new Namespace(INamespace.FRAMEWORK_NAMESPACE, null, ls,
|
228 |
| _namespaceResources); |
229 |
| } |
230 |
| |
231 |
237
| return _frameworkNamespace;
|
232 |
| } |
233 |
| |
234 |
39
| public void setParser(ISpecificationParser parser)
|
235 |
| { |
236 |
39
| _parser = parser;
|
237 |
| } |
238 |
| |
239 |
39
| public void setClassResolver(ClassResolver resolver)
|
240 |
| { |
241 |
39
| _classResolver = resolver;
|
242 |
| } |
243 |
| |
244 |
39
| public void setSpecification(IApplicationSpecification specification)
|
245 |
| { |
246 |
39
| _specification = specification;
|
247 |
| } |
248 |
| |
249 |
39
| public void setAssetSource(AssetSource assetSource)
|
250 |
| { |
251 |
39
| _assetSource = assetSource;
|
252 |
| } |
253 |
| |
254 |
39
| public void setServiceId(String serviceId)
|
255 |
| { |
256 |
39
| _serviceId = serviceId;
|
257 |
| } |
258 |
| |
259 |
| } |