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 |
2734
| protected void reset()
|
71 |
| { |
72 |
2734
| _type = null;
|
73 |
| |
74 |
2734
| super.reset();
|
75 |
| } |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
1794
| public void resolve(IRequestCycle cycle, INamespace containerNamespace, String type,
|
94 |
| Location location) |
95 |
| { |
96 |
1794
| Defense.notNull(type, "type");
|
97 |
| |
98 |
1794
| int colonx = type.indexOf(':');
|
99 |
| |
100 |
1794
| if (colonx > 0)
|
101 |
| { |
102 |
180
| String libraryId = type.substring(0, colonx);
|
103 |
180
| String simpleType = type.substring(colonx + 1);
|
104 |
| |
105 |
180
| resolve(cycle, containerNamespace, libraryId, simpleType, location);
|
106 |
| } |
107 |
| else |
108 |
1614
| resolve(cycle, containerNamespace, null, type, location);
|
109 |
| |
110 |
1792
| IComponentSpecification spec = getSpecification();
|
111 |
| |
112 |
1792
| if (spec.isDeprecated())
|
113 |
12
| _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 |
2734
| public void resolve(IRequestCycle cycle, INamespace containerNamespace, String libraryId,
|
136 |
| String type, Location location) |
137 |
| { |
138 |
2734
| reset();
|
139 |
2734
| _type = type;
|
140 |
| |
141 |
2734
| INamespace namespace = findNamespaceForId(containerNamespace, libraryId);
|
142 |
| |
143 |
2734
| setNamespace(namespace);
|
144 |
| |
145 |
2734
| if (namespace.containsComponentType(type))
|
146 |
| { |
147 |
2420
| setSpecification(namespace.getComponentSpecification(type));
|
148 |
2420
| return;
|
149 |
| } |
150 |
| |
151 |
314
| IComponentSpecification spec = searchForComponent(cycle);
|
152 |
| |
153 |
| |
154 |
| |
155 |
| |
156 |
314
| if (spec == null)
|
157 |
| { |
158 |
2
| throw new ApplicationRuntimeException(ResolverMessages.noSuchComponentType(
|
159 |
| type, |
160 |
| namespace), location, null); |
161 |
| |
162 |
| } |
163 |
| |
164 |
312
| setSpecification(spec);
|
165 |
| |
166 |
| |
167 |
| |
168 |
312
| install();
|
169 |
| } |
170 |
| |
171 |
| |
172 |
| |
173 |
314
| private IComponentSpecification searchForComponent(IRequestCycle cycle)
|
174 |
| { |
175 |
314
| IComponentSpecification result = null;
|
176 |
314
| INamespace namespace = getNamespace();
|
177 |
| |
178 |
314
| if (_log.isDebugEnabled())
|
179 |
14
| _log.debug(ResolverMessages.resolvingComponent(_type, namespace));
|
180 |
| |
181 |
314
| String expectedName = _type + ".jwc";
|
182 |
314
| Resource namespaceLocation = namespace.getSpecificationLocation();
|
183 |
| |
184 |
| |
185 |
| |
186 |
| |
187 |
314
| result = check(namespaceLocation.getRelativeResource(expectedName));
|
188 |
| |
189 |
314
| if (result != null)
|
190 |
18
| return result;
|
191 |
| |
192 |
296
| if (namespace.isApplicationNamespace())
|
193 |
| { |
194 |
| |
195 |
| |
196 |
| |
197 |
216
| result = check(getWebInfAppLocation().getRelativeResource(expectedName));
|
198 |
| |
199 |
216
| if (result == null)
|
200 |
214
| result = check(getWebInfLocation().getRelativeResource(expectedName));
|
201 |
| |
202 |
216
| if (result == null)
|
203 |
212
| result = check((getContextRoot().getRelativeResource(expectedName)));
|
204 |
| |
205 |
216
| if (result != null)
|
206 |
6
| return result;
|
207 |
| } |
208 |
| |
209 |
290
| result = searchForComponentClass(namespace, _type);
|
210 |
| |
211 |
290
| if (result != null)
|
212 |
0
| return result;
|
213 |
| |
214 |
| |
215 |
| |
216 |
| |
217 |
290
| INamespace framework = getSpecificationSource().getFrameworkNamespace();
|
218 |
| |
219 |
290
| if (framework.containsComponentType(_type))
|
220 |
286
| return framework.getComponentSpecification(_type);
|
221 |
| |
222 |
4
| return getDelegate().findComponentSpecification(cycle, namespace, _type);
|
223 |
| } |
224 |
| |
225 |
292
| IComponentSpecification searchForComponentClass(INamespace namespace, String type)
|
226 |
| { |
227 |
292
| String packages = namespace
|
228 |
| .getPropertyValue("org.apache.tapestry.component-class-packages"); |
229 |
| |
230 |
292
| String className = type.replace('/', '.');
|
231 |
| |
232 |
292
| Class componentClass = _classFinder.findClass(packages, className);
|
233 |
| |
234 |
292
| if (componentClass == null)
|
235 |
290
| return null;
|
236 |
| |
237 |
2
| IComponentSpecification spec = new ComponentSpecification();
|
238 |
| |
239 |
2
| Resource namespaceResource = namespace.getSpecificationLocation();
|
240 |
| |
241 |
2
| Resource componentResource = namespaceResource.getRelativeResource(type + ".jwc");
|
242 |
| |
243 |
2
| Location location = new LocationImpl(componentResource);
|
244 |
| |
245 |
2
| spec.setLocation(location);
|
246 |
2
| spec.setSpecificationLocation(componentResource);
|
247 |
2
| spec.setComponentClassName(componentClass.getName());
|
248 |
| |
249 |
2
| return spec;
|
250 |
| } |
251 |
| |
252 |
956
| private IComponentSpecification check(Resource resource)
|
253 |
| { |
254 |
956
| if (_log.isDebugEnabled())
|
255 |
26
| _log.debug("Checking: " + resource);
|
256 |
| |
257 |
956
| if (resource.getResourceURL() == null)
|
258 |
932
| return null;
|
259 |
| |
260 |
24
| return getSpecificationSource().getComponentSpecification(resource);
|
261 |
| } |
262 |
| |
263 |
312
| private void install()
|
264 |
| { |
265 |
312
| INamespace namespace = getNamespace();
|
266 |
312
| IComponentSpecification specification = getSpecification();
|
267 |
| |
268 |
312
| if (_log.isDebugEnabled())
|
269 |
10
| _log.debug(ResolverMessages.installingComponent(_type, namespace, specification));
|
270 |
| |
271 |
312
| namespace.installComponentSpecification(_type, specification);
|
272 |
| } |
273 |
| |
274 |
1774
| public String getType()
|
275 |
| { |
276 |
1774
| return _type;
|
277 |
| } |
278 |
| |
279 |
204
| public void setLog(Log log)
|
280 |
| { |
281 |
204
| _log = log;
|
282 |
| } |
283 |
| |
284 |
196
| public void setClassFinder(ClassFinder classFinder)
|
285 |
| { |
286 |
196
| _classFinder = classFinder;
|
287 |
| } |
288 |
| |
289 |
| } |