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