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