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.tapestry.INamespace; |
22 |
| import org.apache.tapestry.IRequestCycle; |
23 |
| import org.apache.tapestry.spec.IComponentSpecification; |
24 |
| |
25 |
| |
26 |
| |
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 |
| public class ComponentSpecificationResolverImpl extends AbstractSpecificationResolver implements |
54 |
| ComponentSpecificationResolver |
55 |
| { |
56 |
| |
57 |
| private Log _log; |
58 |
| |
59 |
| |
60 |
| private String _type; |
61 |
| |
62 |
1469
| protected void reset()
|
63 |
| { |
64 |
1469
| _type = null;
|
65 |
| |
66 |
1469
| super.reset();
|
67 |
| } |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
978
| public void resolve(IRequestCycle cycle, INamespace containerNamespace, String type,
|
86 |
| Location location) |
87 |
| { |
88 |
978
| int colonx = type.indexOf(':');
|
89 |
| |
90 |
978
| if (colonx > 0)
|
91 |
| { |
92 |
90
| String libraryId = type.substring(0, colonx);
|
93 |
90
| String simpleType = type.substring(colonx + 1);
|
94 |
| |
95 |
90
| resolve(cycle, containerNamespace, libraryId, simpleType, location);
|
96 |
| } |
97 |
| else |
98 |
888
| resolve(cycle, containerNamespace, null, type, location);
|
99 |
| |
100 |
977
| IComponentSpecification spec = getSpecification();
|
101 |
| |
102 |
977
| if (spec.isDeprecated())
|
103 |
5
| _log.error(ResolverMessages.componentIsDeprecated(type, location));
|
104 |
| } |
105 |
| |
106 |
| |
107 |
| |
108 |
| |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
| |
118 |
| |
119 |
| |
120 |
| |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
1469
| public void resolve(IRequestCycle cycle, INamespace containerNamespace, String libraryId,
|
126 |
| String type, Location location) |
127 |
| { |
128 |
1469
| reset();
|
129 |
1469
| _type = type;
|
130 |
| |
131 |
1469
| INamespace namespace = null;
|
132 |
| |
133 |
1469
| if (libraryId != null)
|
134 |
160
| namespace = containerNamespace.getChildNamespace(libraryId);
|
135 |
| else |
136 |
1309
| namespace = containerNamespace;
|
137 |
| |
138 |
1469
| setNamespace(namespace);
|
139 |
| |
140 |
1469
| if (namespace.containsComponentType(type))
|
141 |
1303
| setSpecification(namespace.getComponentSpecification(type));
|
142 |
| else |
143 |
166
| searchForComponent(cycle);
|
144 |
| |
145 |
| |
146 |
| |
147 |
| |
148 |
1469
| if (getSpecification() == null)
|
149 |
| { |
150 |
| |
151 |
1
| throw new ApplicationRuntimeException(ResolverMessages.noSuchComponentType(
|
152 |
| type, |
153 |
| namespace), location, null); |
154 |
| |
155 |
| } |
156 |
| } |
157 |
| |
158 |
| |
159 |
| |
160 |
166
| private void searchForComponent(IRequestCycle cycle)
|
161 |
| { |
162 |
166
| INamespace namespace = getNamespace();
|
163 |
| |
164 |
166
| if (_log.isDebugEnabled())
|
165 |
7
| _log.debug(ResolverMessages.resolvingComponent(_type, namespace));
|
166 |
| |
167 |
166
| String expectedName = _type + ".jwc";
|
168 |
166
| Resource namespaceLocation = namespace.getSpecificationLocation();
|
169 |
| |
170 |
| |
171 |
| |
172 |
| |
173 |
166
| if (found(namespaceLocation.getRelativeResource(expectedName)))
|
174 |
9
| return;
|
175 |
| |
176 |
157
| if (namespace.isApplicationNamespace())
|
177 |
| { |
178 |
| |
179 |
| |
180 |
| |
181 |
117
| if (found(getWebInfAppLocation().getRelativeResource(expectedName)))
|
182 |
1
| return;
|
183 |
| |
184 |
116
| if (found(getWebInfLocation().getRelativeResource(expectedName)))
|
185 |
1
| return;
|
186 |
| |
187 |
115
| if (found(getContextRoot().getRelativeResource(expectedName)))
|
188 |
1
| return;
|
189 |
| } |
190 |
| |
191 |
| |
192 |
| |
193 |
| |
194 |
154
| INamespace framework = getSpecificationSource().getFrameworkNamespace();
|
195 |
| |
196 |
154
| if (framework.containsComponentType(_type))
|
197 |
| { |
198 |
152
| setSpecification(framework.getComponentSpecification(_type));
|
199 |
| |
200 |
152
| install();
|
201 |
| |
202 |
152
| return;
|
203 |
| } |
204 |
| |
205 |
2
| IComponentSpecification specification = getDelegate().findComponentSpecification(
|
206 |
| cycle, |
207 |
| namespace, |
208 |
| _type); |
209 |
| |
210 |
2
| if (specification != null)
|
211 |
| { |
212 |
1
| setSpecification(specification);
|
213 |
1
| install();
|
214 |
1
| return;
|
215 |
| } |
216 |
| } |
217 |
| |
218 |
514
| private boolean found(Resource resource)
|
219 |
| { |
220 |
514
| if (_log.isDebugEnabled())
|
221 |
13
| _log.debug("Checking: " + resource);
|
222 |
| |
223 |
514
| if (resource.getResourceURL() == null)
|
224 |
502
| return false;
|
225 |
| |
226 |
12
| setSpecification(getSpecificationSource().getComponentSpecification(resource));
|
227 |
| |
228 |
12
| install();
|
229 |
| |
230 |
12
| return true;
|
231 |
| } |
232 |
| |
233 |
165
| private void install()
|
234 |
| { |
235 |
165
| INamespace namespace = getNamespace();
|
236 |
165
| IComponentSpecification specification = getSpecification();
|
237 |
| |
238 |
165
| if (_log.isDebugEnabled())
|
239 |
5
| _log.debug(ResolverMessages.installingComponent(_type, namespace, specification));
|
240 |
| |
241 |
165
| namespace.installComponentSpecification(_type, specification);
|
242 |
| } |
243 |
| |
244 |
968
| public String getType()
|
245 |
| { |
246 |
968
| return _type;
|
247 |
| } |
248 |
| |
249 |
109
| public void setLog(Log log)
|
250 |
| { |
251 |
109
| _log = log;
|
252 |
| } |
253 |
| |
254 |
| } |