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