|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.resolver; |
|
16 |
| |
|
17 |
| import org.apache.commons.logging.Log; |
|
18 |
| import org.apache.hivemind.ApplicationRuntimeException; |
|
19 |
| import org.apache.hivemind.Location; |
|
20 |
| import org.apache.hivemind.Resource; |
|
21 |
| import org.apache.hivemind.impl.LocationImpl; |
|
22 |
| import org.apache.hivemind.util.Defense; |
|
23 |
| import org.apache.tapestry.INamespace; |
|
24 |
| import org.apache.tapestry.IRequestCycle; |
|
25 |
| import org.apache.tapestry.services.ClassFinder; |
|
26 |
| import org.apache.tapestry.spec.ComponentSpecification; |
|
27 |
| import org.apache.tapestry.spec.IComponentSpecification; |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| public class ComponentSpecificationResolverImpl extends AbstractSpecificationResolver implements |
|
60 |
| ComponentSpecificationResolver |
|
61 |
| { |
|
62 |
| |
|
63 |
| private Log _log; |
|
64 |
| |
|
65 |
| |
|
66 |
| private String _type; |
|
67 |
| |
|
68 |
| private ClassFinder _classFinder; |
|
69 |
| |
|
70 |
4101
| protected void reset()
|
|
71 |
| { |
|
72 |
4101
| _type = null;
|
|
73 |
| |
|
74 |
4101
| super.reset();
|
|
75 |
| } |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
2691
| public void resolve(IRequestCycle cycle, INamespace containerNamespace, String type,
|
|
94 |
| Location location) |
|
95 |
| { |
|
96 |
2691
| Defense.notNull(type, "type");
|
|
97 |
| |
|
98 |
2691
| int colonx = type.indexOf(':');
|
|
99 |
| |
|
100 |
2691
| if (colonx > 0)
|
|
101 |
| { |
|
102 |
270
| String libraryId = type.substring(0, colonx);
|
|
103 |
270
| String simpleType = type.substring(colonx + 1);
|
|
104 |
| |
|
105 |
270
| resolve(cycle, containerNamespace, libraryId, simpleType, location);
|
|
106 |
| } |
|
107 |
| else |
|
108 |
2421
| resolve(cycle, containerNamespace, null, type, location);
|
|
109 |
| |
|
110 |
2688
| IComponentSpecification spec = getSpecification();
|
|
111 |
| |
|
112 |
2688
| if (spec.isDeprecated())
|
|
113 |
18
| _log.warn(ResolverMessages.componentIsDeprecated(type, location));
|
|
114 |
| } |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
4101
| public void resolve(IRequestCycle cycle, INamespace containerNamespace, String libraryId,
|
|
136 |
| String type, Location location) |
|
137 |
| { |
|
138 |
4101
| reset();
|
|
139 |
4101
| _type = type;
|
|
140 |
| |
|
141 |
4101
| INamespace namespace = findNamespaceForId(containerNamespace, libraryId);
|
|
142 |
| |
|
143 |
4101
| setNamespace(namespace);
|
|
144 |
| |
|
145 |
4101
| if (namespace.containsComponentType(type))
|
|
146 |
| { |
|
147 |
3630
| setSpecification(namespace.getComponentSpecification(type));
|
|
148 |
3630
| return;
|
|
149 |
| } |
|
150 |
| |
|
151 |
471
| IComponentSpecification spec = searchForComponent(cycle);
|
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
471
| if (spec == null)
|
|
157 |
| { |
|
158 |
3
| throw new ApplicationRuntimeException(ResolverMessages.noSuchComponentType(
|
|
159 |
| type, |
|
160 |
| namespace), location, null); |
|
161 |
| |
|
162 |
| } |
|
163 |
| |
|
164 |
468
| setSpecification(spec);
|
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
468
| install();
|
|
169 |
| } |
|
170 |
| |
|
171 |
| |
|
172 |
| |
|
173 |
471
| private IComponentSpecification searchForComponent(IRequestCycle cycle)
|
|
174 |
| { |
|
175 |
471
| IComponentSpecification result = null;
|
|
176 |
471
| INamespace namespace = getNamespace();
|
|
177 |
| |
|
178 |
471
| if (_log.isDebugEnabled())
|
|
179 |
21
| _log.debug(ResolverMessages.resolvingComponent(_type, namespace));
|
|
180 |
| |
|
181 |
471
| String expectedName = _type + ".jwc";
|
|
182 |
471
| Resource namespaceLocation = namespace.getSpecificationLocation();
|
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
| |
|
187 |
471
| result = check(namespaceLocation.getRelativeResource(expectedName));
|
|
188 |
| |
|
189 |
471
| if (result != null)
|
|
190 |
27
| return result;
|
|
191 |
| |
|
192 |
444
| if (namespace.isApplicationNamespace())
|
|
193 |
| { |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
324
| result = check(getWebInfAppLocation().getRelativeResource(expectedName));
|
|
198 |
| |
|
199 |
324
| if (result == null)
|
|
200 |
321
| result = check(getWebInfLocation().getRelativeResource(expectedName));
|
|
201 |
| |
|
202 |
324
| if (result == null)
|
|
203 |
318
| result = check((getContextRoot().getRelativeResource(expectedName)));
|
|
204 |
| |
|
205 |
324
| if (result != null)
|
|
206 |
9
| return result;
|
|
207 |
| } |
|
208 |
| |
|
209 |
435
| result = searchForComponentClass(namespace, _type);
|
|
210 |
| |
|
211 |
435
| if (result != null)
|
|
212 |
0
| return result;
|
|
213 |
| |
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
435
| INamespace framework = getSpecificationSource().getFrameworkNamespace();
|
|
218 |
| |
|
219 |
435
| if (framework.containsComponentType(_type))
|
|
220 |
429
| return framework.getComponentSpecification(_type);
|
|
221 |
| |
|
222 |
6
| return getDelegate().findComponentSpecification(cycle, namespace, _type);
|
|
223 |
| } |
|
224 |
| |
|
225 |
438
| IComponentSpecification searchForComponentClass(INamespace namespace, String type)
|
|
226 |
| { |
|
227 |
438
| String packages = namespace
|
|
228 |
| .getPropertyValue("org.apache.tapestry.component-class-packages"); |
|
229 |
| |
|
230 |
438
| String className = type.replace('/', '.');
|
|
231 |
| |
|
232 |
438
| Class componentClass = _classFinder.findClass(packages, className);
|
|
233 |
| |
|
234 |
438
| if (componentClass == null)
|
|
235 |
435
| return null;
|
|
236 |
| |
|
237 |
3
| IComponentSpecification spec = new ComponentSpecification();
|
|
238 |
| |
|
239 |
3
| Resource namespaceResource = namespace.getSpecificationLocation();
|
|
240 |
| |
|
241 |
3
| Resource componentResource = namespaceResource.getRelativeResource(type + ".jwc");
|
|
242 |
| |
|
243 |
3
| Location location = new LocationImpl(componentResource);
|
|
244 |
| |
|
245 |
3
| spec.setLocation(location);
|
|
246 |
3
| spec.setSpecificationLocation(componentResource);
|
|
247 |
3
| spec.setComponentClassName(componentClass.getName());
|
|
248 |
| |
|
249 |
3
| return spec;
|
|
250 |
| } |
|
251 |
| |
|
252 |
1434
| private IComponentSpecification check(Resource resource)
|
|
253 |
| { |
|
254 |
1434
| if (_log.isDebugEnabled())
|
|
255 |
39
| _log.debug("Checking: " + resource);
|
|
256 |
| |
|
257 |
1434
| if (resource.getResourceURL() == null)
|
|
258 |
1398
| return null;
|
|
259 |
| |
|
260 |
36
| return getSpecificationSource().getComponentSpecification(resource);
|
|
261 |
| } |
|
262 |
| |
|
263 |
468
| private void install()
|
|
264 |
| { |
|
265 |
468
| INamespace namespace = getNamespace();
|
|
266 |
468
| IComponentSpecification specification = getSpecification();
|
|
267 |
| |
|
268 |
468
| if (_log.isDebugEnabled())
|
|
269 |
15
| _log.debug(ResolverMessages.installingComponent(_type, namespace, specification));
|
|
270 |
| |
|
271 |
468
| namespace.installComponentSpecification(_type, specification);
|
|
272 |
| } |
|
273 |
| |
|
274 |
2661
| public String getType()
|
|
275 |
| { |
|
276 |
2661
| return _type;
|
|
277 |
| } |
|
278 |
| |
|
279 |
306
| public void setLog(Log log)
|
|
280 |
| { |
|
281 |
306
| _log = log;
|
|
282 |
| } |
|
283 |
| |
|
284 |
294
| public void setClassFinder(ClassFinder classFinder)
|
|
285 |
| { |
|
286 |
294
| _classFinder = classFinder;
|
|
287 |
| } |
|
288 |
| |
|
289 |
| } |