1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.view.facelets.tag; |
20 | |
|
21 | |
import java.lang.reflect.Constructor; |
22 | |
import java.lang.reflect.InvocationTargetException; |
23 | |
import java.lang.reflect.Method; |
24 | |
import java.net.URL; |
25 | |
import java.util.HashMap; |
26 | |
import java.util.Map; |
27 | |
|
28 | |
import javax.el.ELException; |
29 | |
import javax.faces.FacesException; |
30 | |
import javax.faces.application.Resource; |
31 | |
import javax.faces.application.ResourceHandler; |
32 | |
import javax.faces.context.FacesContext; |
33 | |
import javax.faces.view.facelets.BehaviorConfig; |
34 | |
import javax.faces.view.facelets.BehaviorHandler; |
35 | |
import javax.faces.view.facelets.ComponentConfig; |
36 | |
import javax.faces.view.facelets.ComponentHandler; |
37 | |
import javax.faces.view.facelets.ConverterConfig; |
38 | |
import javax.faces.view.facelets.ConverterHandler; |
39 | |
import javax.faces.view.facelets.FaceletException; |
40 | |
import javax.faces.view.facelets.FaceletHandler; |
41 | |
import javax.faces.view.facelets.Tag; |
42 | |
import javax.faces.view.facelets.TagConfig; |
43 | |
import javax.faces.view.facelets.TagHandler; |
44 | |
import javax.faces.view.facelets.ValidatorConfig; |
45 | |
import javax.faces.view.facelets.ValidatorHandler; |
46 | |
import org.apache.myfaces.shared.config.MyfacesConfig; |
47 | |
import org.apache.myfaces.view.facelets.tag.composite.CompositeComponentResourceTagHandler; |
48 | |
import org.apache.myfaces.view.facelets.tag.composite.CompositeResouceWrapper; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public abstract class AbstractTagLibrary implements TagLibrary |
57 | |
{ |
58 | |
private final Map<String, TagHandlerFactory> _factories; |
59 | |
|
60 | |
private final Map<String, Method> _functions; |
61 | |
|
62 | |
private final String _namespace; |
63 | |
private final String _aliasNamespace; |
64 | |
private Boolean _strictJsf2FaceletsCompatibility; |
65 | |
|
66 | |
public AbstractTagLibrary(String namespace, String aliasNamespace) |
67 | 0 | { |
68 | 0 | _namespace = namespace; |
69 | 0 | _aliasNamespace = aliasNamespace; |
70 | 0 | _factories = new HashMap<String, TagHandlerFactory>(); |
71 | 0 | _functions = new HashMap<String, Method>(); |
72 | 0 | } |
73 | |
|
74 | |
public AbstractTagLibrary(String namespace) |
75 | |
{ |
76 | 0 | this(namespace,null); |
77 | 0 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public boolean containsNamespace(String ns) |
86 | |
{ |
87 | 0 | return _namespace.equals(ns) || (_aliasNamespace != null && _aliasNamespace.equals(ns)); |
88 | |
} |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
public boolean containsTagHandler(String ns, String localName) |
96 | |
{ |
97 | 0 | return containsNamespace(ns) && _factories.containsKey(localName); |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public TagHandler createTagHandler(String ns, String localName, TagConfig tag) throws FacesException |
107 | |
{ |
108 | 0 | if (containsNamespace(ns)) |
109 | |
{ |
110 | 0 | TagHandlerFactory f = _factories.get(localName); |
111 | 0 | if (f != null) |
112 | |
{ |
113 | 0 | return f.createHandler(tag); |
114 | |
} |
115 | |
} |
116 | |
|
117 | 0 | return null; |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
public boolean containsFunction(String ns, String name) |
126 | |
{ |
127 | 0 | return containsNamespace(ns) && _functions.containsKey(name); |
128 | |
} |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
public Method createFunction(String ns, String name) |
136 | |
{ |
137 | 0 | return containsNamespace(ns) ? _functions.get(name) : null; |
138 | |
} |
139 | |
|
140 | |
public String getNamespace() |
141 | |
{ |
142 | 0 | return _namespace; |
143 | |
} |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
protected final void addComponent(String name, String componentType, String rendererType) |
158 | |
{ |
159 | 0 | _factories.put(name, new ComponentHandlerFactory(componentType, rendererType)); |
160 | 0 | } |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
protected final void addComponent(String name, String componentType, String rendererType, |
177 | |
Class<? extends TagHandler> handlerType) |
178 | |
{ |
179 | 0 | _factories.put(name, new UserComponentHandlerFactory(componentType, rendererType, handlerType)); |
180 | 0 | } |
181 | |
|
182 | |
protected final void addComponentFromResourceId(String name, String resourceId) |
183 | |
{ |
184 | 0 | _factories.put(name, new UserComponentFromResourceIdHandlerFactory(resourceId)); |
185 | 0 | } |
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
protected final void addConverter(String name, String converterId) |
198 | |
{ |
199 | 0 | _factories.put(name, new ConverterHandlerFactory(converterId)); |
200 | 0 | } |
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
protected final void addConverter(String name, String converterId, Class<? extends TagHandler> type) |
216 | |
{ |
217 | 0 | _factories.put(name, new UserConverterHandlerFactory(converterId, type)); |
218 | 0 | } |
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
protected final void addValidator(String name, String validatorId) |
231 | |
{ |
232 | 0 | _factories.put(name, new ValidatorHandlerFactory(validatorId)); |
233 | 0 | } |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
protected final void addValidator(String name, String validatorId, Class<? extends TagHandler> type) |
249 | |
{ |
250 | 0 | _factories.put(name, new UserValidatorHandlerFactory(validatorId, type)); |
251 | 0 | } |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
protected final void addTagHandler(String name, Class<? extends TagHandler> handlerType) |
263 | |
{ |
264 | 0 | _factories.put(name, new HandlerFactory(handlerType)); |
265 | 0 | } |
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
protected final void addUserTag(String name, URL source) |
277 | |
{ |
278 | 0 | if (_strictJsf2FaceletsCompatibility == null) |
279 | |
{ |
280 | 0 | MyfacesConfig config = MyfacesConfig.getCurrentInstance( |
281 | |
FacesContext.getCurrentInstance().getExternalContext()); |
282 | |
|
283 | 0 | _strictJsf2FaceletsCompatibility = config.isStrictJsf2FaceletsCompatibility(); |
284 | |
} |
285 | 0 | if (Boolean.TRUE.equals(_strictJsf2FaceletsCompatibility)) |
286 | |
{ |
287 | 0 | _factories.put(name, new LegacyUserTagFactory(source)); |
288 | |
} |
289 | |
else |
290 | |
{ |
291 | 0 | _factories.put(name, new UserTagFactory(source)); |
292 | |
} |
293 | 0 | } |
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
protected final void addFunction(String name, Method method) |
306 | |
{ |
307 | 0 | _functions.put(name, method); |
308 | 0 | } |
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
protected final void addBehavior(String name, String behaviorId) |
316 | |
{ |
317 | 0 | _factories.put(name, new BehaviorHandlerFactory(behaviorId)); |
318 | 0 | } |
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
protected final void addBehavior(String name, String behaviorId, |
327 | |
Class<? extends TagHandler> handlerType) |
328 | |
{ |
329 | 0 | _factories.put(name, new UserBehaviorHandlerFactory(behaviorId,handlerType)); |
330 | 0 | } |
331 | |
|
332 | |
private static class ValidatorConfigWrapper implements ValidatorConfig |
333 | |
{ |
334 | |
|
335 | |
private final TagConfig parent; |
336 | |
private final String validatorId; |
337 | |
|
338 | |
public ValidatorConfigWrapper(TagConfig parent, String validatorId) |
339 | 0 | { |
340 | 0 | this.parent = parent; |
341 | 0 | this.validatorId = validatorId; |
342 | 0 | } |
343 | |
|
344 | |
public String getValidatorId() |
345 | |
{ |
346 | 0 | return this.validatorId; |
347 | |
} |
348 | |
|
349 | |
public FaceletHandler getNextHandler() |
350 | |
{ |
351 | 0 | return this.parent.getNextHandler(); |
352 | |
} |
353 | |
|
354 | |
public Tag getTag() |
355 | |
{ |
356 | 0 | return this.parent.getTag(); |
357 | |
} |
358 | |
|
359 | |
public String getTagId() |
360 | |
{ |
361 | 0 | return this.parent.getTagId(); |
362 | |
} |
363 | |
} |
364 | |
|
365 | |
private static class ConverterConfigWrapper implements ConverterConfig |
366 | |
{ |
367 | |
private final TagConfig parent; |
368 | |
private final String converterId; |
369 | |
|
370 | |
public ConverterConfigWrapper(TagConfig parent, String converterId) |
371 | 0 | { |
372 | 0 | this.parent = parent; |
373 | 0 | this.converterId = converterId; |
374 | 0 | } |
375 | |
|
376 | |
public String getConverterId() |
377 | |
{ |
378 | 0 | return this.converterId; |
379 | |
} |
380 | |
|
381 | |
public FaceletHandler getNextHandler() |
382 | |
{ |
383 | 0 | return this.parent.getNextHandler(); |
384 | |
} |
385 | |
|
386 | |
public Tag getTag() |
387 | |
{ |
388 | 0 | return this.parent.getTag(); |
389 | |
} |
390 | |
|
391 | |
public String getTagId() |
392 | |
{ |
393 | 0 | return this.parent.getTagId(); |
394 | |
} |
395 | |
} |
396 | |
|
397 | |
private static class HandlerFactory implements TagHandlerFactory |
398 | |
{ |
399 | 0 | private final static Class<?>[] CONSTRUCTOR_SIG = new Class[]{TagConfig.class}; |
400 | |
|
401 | |
protected final Class<? extends TagHandler> handlerType; |
402 | |
|
403 | |
public HandlerFactory(Class<? extends TagHandler> handlerType) |
404 | 0 | { |
405 | 0 | this.handlerType = handlerType; |
406 | 0 | } |
407 | |
|
408 | |
public TagHandler createHandler(TagConfig cfg) throws FacesException, ELException |
409 | |
{ |
410 | |
try |
411 | |
{ |
412 | 0 | return handlerType.getConstructor(CONSTRUCTOR_SIG).newInstance(new Object[] { cfg }); |
413 | |
} |
414 | 0 | catch (InvocationTargetException ite) |
415 | |
{ |
416 | 0 | Throwable t = ite.getCause(); |
417 | 0 | if (t instanceof FacesException) |
418 | |
{ |
419 | 0 | throw (FacesException) t; |
420 | |
} |
421 | 0 | else if (t instanceof ELException) |
422 | |
{ |
423 | 0 | throw (ELException) t; |
424 | |
} |
425 | |
else |
426 | |
{ |
427 | 0 | throw new FacesException("Error Instantiating: " + handlerType.getName(), t); |
428 | |
} |
429 | |
} |
430 | 0 | catch (Exception e) |
431 | |
{ |
432 | 0 | throw new FacesException("Error Instantiating: " + handlerType.getName(), e); |
433 | |
} |
434 | |
} |
435 | |
} |
436 | |
|
437 | |
private static class ComponentConfigWrapper implements ComponentConfig |
438 | |
{ |
439 | |
|
440 | |
protected final TagConfig parent; |
441 | |
|
442 | |
protected final String componentType; |
443 | |
|
444 | |
protected final String rendererType; |
445 | |
|
446 | |
public ComponentConfigWrapper(TagConfig parent, String componentType, String rendererType) |
447 | 0 | { |
448 | 0 | this.parent = parent; |
449 | 0 | this.componentType = componentType; |
450 | 0 | this.rendererType = rendererType; |
451 | 0 | } |
452 | |
|
453 | |
public String getComponentType() |
454 | |
{ |
455 | 0 | return this.componentType; |
456 | |
} |
457 | |
|
458 | |
public String getRendererType() |
459 | |
{ |
460 | 0 | return this.rendererType; |
461 | |
} |
462 | |
|
463 | |
public FaceletHandler getNextHandler() |
464 | |
{ |
465 | 0 | return this.parent.getNextHandler(); |
466 | |
} |
467 | |
|
468 | |
public Tag getTag() |
469 | |
{ |
470 | 0 | return this.parent.getTag(); |
471 | |
} |
472 | |
|
473 | |
public String getTagId() |
474 | |
{ |
475 | 0 | return this.parent.getTagId(); |
476 | |
} |
477 | |
} |
478 | |
|
479 | |
private static class UserTagFactory implements TagHandlerFactory |
480 | |
{ |
481 | |
protected final URL location; |
482 | |
|
483 | |
public UserTagFactory(URL location) |
484 | 0 | { |
485 | 0 | this.location = location; |
486 | 0 | } |
487 | |
|
488 | |
public TagHandler createHandler(TagConfig cfg) throws FacesException, ELException |
489 | |
{ |
490 | 0 | return new UserTagHandler(cfg, this.location); |
491 | |
} |
492 | |
} |
493 | |
|
494 | |
private static class LegacyUserTagFactory implements TagHandlerFactory |
495 | |
{ |
496 | |
protected final URL location; |
497 | |
|
498 | |
public LegacyUserTagFactory(URL location) |
499 | 0 | { |
500 | 0 | this.location = location; |
501 | 0 | } |
502 | |
|
503 | |
public TagHandler createHandler(TagConfig cfg) throws FacesException, ELException |
504 | |
{ |
505 | 0 | return new LegacyUserTagHandler(cfg, this.location); |
506 | |
} |
507 | |
} |
508 | |
|
509 | |
private static class ComponentHandlerFactory implements TagHandlerFactory |
510 | |
{ |
511 | |
|
512 | |
protected final String componentType; |
513 | |
|
514 | |
protected final String renderType; |
515 | |
|
516 | |
|
517 | |
|
518 | |
|
519 | |
public ComponentHandlerFactory(String componentType, String renderType) |
520 | 0 | { |
521 | 0 | this.componentType = componentType; |
522 | 0 | this.renderType = renderType; |
523 | 0 | } |
524 | |
|
525 | |
public TagHandler createHandler(TagConfig cfg) throws FacesException, ELException |
526 | |
{ |
527 | 0 | ComponentConfig ccfg = new ComponentConfigWrapper(cfg, this.componentType, this.renderType); |
528 | 0 | return new ComponentHandler(ccfg); |
529 | |
} |
530 | |
} |
531 | |
|
532 | |
private static class UserComponentHandlerFactory implements TagHandlerFactory |
533 | |
{ |
534 | |
|
535 | 0 | private final static Class<?>[] CONS_SIG = new Class[] { ComponentConfig.class }; |
536 | |
|
537 | |
protected final String componentType; |
538 | |
|
539 | |
protected final String renderType; |
540 | |
|
541 | |
protected final Class<? extends TagHandler> type; |
542 | |
|
543 | |
protected final Constructor<? extends TagHandler> constructor; |
544 | |
|
545 | |
|
546 | |
|
547 | |
|
548 | |
public UserComponentHandlerFactory(String componentType, String renderType, Class<? extends TagHandler> type) |
549 | 0 | { |
550 | 0 | this.componentType = componentType; |
551 | 0 | this.renderType = renderType; |
552 | 0 | this.type = type; |
553 | |
try |
554 | |
{ |
555 | 0 | this.constructor = this.type.getConstructor(CONS_SIG); |
556 | |
} |
557 | 0 | catch (Exception e) |
558 | |
{ |
559 | 0 | throw new FaceletException("Must have a Constructor that takes in a ComponentConfig", e); |
560 | 0 | } |
561 | 0 | } |
562 | |
|
563 | |
public TagHandler createHandler(TagConfig cfg) throws FacesException, ELException |
564 | |
{ |
565 | |
try |
566 | |
{ |
567 | 0 | ComponentConfig ccfg = new ComponentConfigWrapper(cfg, componentType, renderType); |
568 | 0 | return constructor.newInstance(new Object[] { ccfg }); |
569 | |
} |
570 | 0 | catch (InvocationTargetException e) |
571 | |
{ |
572 | 0 | throw new FaceletException(e.getCause().getMessage(), e.getCause().getCause()); |
573 | |
} |
574 | 0 | catch (Exception e) |
575 | |
{ |
576 | 0 | throw new FaceletException("Error Instantiating ComponentHandler: " + this.type.getName(), e); |
577 | |
} |
578 | |
} |
579 | |
} |
580 | |
|
581 | |
private static class ValidatorHandlerFactory implements TagHandlerFactory |
582 | |
{ |
583 | |
|
584 | |
protected final String validatorId; |
585 | |
|
586 | |
public ValidatorHandlerFactory(String validatorId) |
587 | 0 | { |
588 | 0 | this.validatorId = validatorId; |
589 | 0 | } |
590 | |
|
591 | |
public TagHandler createHandler(TagConfig cfg) throws FacesException, ELException |
592 | |
{ |
593 | 0 | return new ValidatorHandler(new ValidatorConfigWrapper(cfg, this.validatorId)); |
594 | |
} |
595 | |
} |
596 | |
|
597 | |
private static class ConverterHandlerFactory implements TagHandlerFactory |
598 | |
{ |
599 | |
|
600 | |
protected final String converterId; |
601 | |
|
602 | |
public ConverterHandlerFactory(String converterId) |
603 | 0 | { |
604 | 0 | this.converterId = converterId; |
605 | 0 | } |
606 | |
|
607 | |
public TagHandler createHandler(TagConfig cfg) throws FacesException, ELException |
608 | |
{ |
609 | 0 | return new ConverterHandler(new ConverterConfigWrapper(cfg, this.converterId)); |
610 | |
} |
611 | |
} |
612 | |
|
613 | |
private static class UserConverterHandlerFactory implements TagHandlerFactory |
614 | |
{ |
615 | 0 | private final static Class<?>[] CONS_SIG = new Class[] { ConverterConfig.class }; |
616 | |
|
617 | |
protected final String converterId; |
618 | |
|
619 | |
protected final Class<? extends TagHandler> type; |
620 | |
|
621 | |
protected final Constructor<? extends TagHandler> constructor; |
622 | |
|
623 | |
public UserConverterHandlerFactory(String converterId, Class<? extends TagHandler> type) |
624 | 0 | { |
625 | 0 | this.converterId = converterId; |
626 | 0 | this.type = type; |
627 | |
try |
628 | |
{ |
629 | 0 | this.constructor = this.type.getConstructor(CONS_SIG); |
630 | |
} |
631 | 0 | catch (Exception e) |
632 | |
{ |
633 | 0 | throw new FaceletException("Must have a Constructor that takes in a ConverterConfig", e); |
634 | 0 | } |
635 | 0 | } |
636 | |
|
637 | |
public TagHandler createHandler(TagConfig cfg) throws FacesException, ELException |
638 | |
{ |
639 | |
try |
640 | |
{ |
641 | 0 | ConverterConfig ccfg = new ConverterConfigWrapper(cfg, converterId); |
642 | 0 | return constructor.newInstance(new Object[] { ccfg }); |
643 | |
} |
644 | 0 | catch (InvocationTargetException e) |
645 | |
{ |
646 | 0 | throw new FaceletException(e.getCause().getMessage(), e.getCause().getCause()); |
647 | |
} |
648 | 0 | catch (Exception e) |
649 | |
{ |
650 | 0 | throw new FaceletException("Error Instantiating ConverterHandler: " + type.getName(), e); |
651 | |
} |
652 | |
} |
653 | |
} |
654 | |
|
655 | |
private static class UserValidatorHandlerFactory implements TagHandlerFactory |
656 | |
{ |
657 | 0 | private final static Class<?>[] CONS_SIG = new Class[] { ValidatorConfig.class }; |
658 | |
|
659 | |
protected final String validatorId; |
660 | |
|
661 | |
protected final Class<? extends TagHandler> type; |
662 | |
|
663 | |
protected final Constructor<? extends TagHandler> constructor; |
664 | |
|
665 | |
public UserValidatorHandlerFactory(String validatorId, Class<? extends TagHandler> type) |
666 | 0 | { |
667 | 0 | this.validatorId = validatorId; |
668 | 0 | this.type = type; |
669 | |
try |
670 | |
{ |
671 | 0 | this.constructor = this.type.getConstructor(CONS_SIG); |
672 | |
} |
673 | 0 | catch (Exception e) |
674 | |
{ |
675 | 0 | throw new FaceletException("Must have a Constructor that takes in a ConverterConfig", e); |
676 | 0 | } |
677 | 0 | } |
678 | |
|
679 | |
public TagHandler createHandler(TagConfig cfg) throws FacesException, ELException |
680 | |
{ |
681 | |
try |
682 | |
{ |
683 | 0 | ValidatorConfig ccfg = new ValidatorConfigWrapper(cfg, validatorId); |
684 | 0 | return constructor.newInstance(new Object[] { ccfg }); |
685 | |
} |
686 | 0 | catch (InvocationTargetException e) |
687 | |
{ |
688 | 0 | throw new FaceletException(e.getCause().getMessage(), e.getCause().getCause()); |
689 | |
} |
690 | 0 | catch (Exception e) |
691 | |
{ |
692 | 0 | throw new FaceletException("Error Instantiating ValidatorHandler: " + type.getName(), e); |
693 | |
} |
694 | |
} |
695 | |
} |
696 | |
|
697 | |
private static class BehaviorConfigWrapper implements BehaviorConfig |
698 | |
{ |
699 | |
protected final TagConfig parent; |
700 | |
|
701 | |
protected final String behaviorId; |
702 | |
|
703 | |
public BehaviorConfigWrapper(TagConfig parent, String behaviorId) |
704 | 0 | { |
705 | 0 | this.parent = parent; |
706 | 0 | this.behaviorId = behaviorId; |
707 | 0 | } |
708 | |
|
709 | |
public FaceletHandler getNextHandler() |
710 | |
{ |
711 | 0 | return this.parent.getNextHandler(); |
712 | |
} |
713 | |
|
714 | |
public Tag getTag() |
715 | |
{ |
716 | 0 | return this.parent.getTag(); |
717 | |
} |
718 | |
|
719 | |
public String getTagId() |
720 | |
{ |
721 | 0 | return this.parent.getTagId(); |
722 | |
} |
723 | |
|
724 | |
public String getBehaviorId() |
725 | |
{ |
726 | 0 | return this.behaviorId; |
727 | |
} |
728 | |
} |
729 | |
|
730 | |
private static class BehaviorHandlerFactory implements TagHandlerFactory |
731 | |
{ |
732 | |
protected final String behaviorId; |
733 | |
|
734 | |
public BehaviorHandlerFactory(String behaviorId) |
735 | |
{ |
736 | 0 | super(); |
737 | 0 | this.behaviorId = behaviorId; |
738 | 0 | } |
739 | |
|
740 | |
public TagHandler createHandler(TagConfig cfg) throws FacesException, ELException |
741 | |
{ |
742 | 0 | BehaviorConfig bcfg = new BehaviorConfigWrapper(cfg,this.behaviorId); |
743 | 0 | return new BehaviorHandler(bcfg); |
744 | |
} |
745 | |
} |
746 | |
|
747 | |
private static class UserBehaviorHandlerFactory implements TagHandlerFactory |
748 | |
{ |
749 | 0 | private final static Class<?>[] CONS_SIG = new Class[] { BehaviorConfig.class }; |
750 | |
|
751 | |
protected final String behaviorId; |
752 | |
|
753 | |
protected final Class<? extends TagHandler> type; |
754 | |
|
755 | |
protected final Constructor<? extends TagHandler> constructor; |
756 | |
|
757 | |
public UserBehaviorHandlerFactory(String behaviorId, Class<? extends TagHandler> type) |
758 | 0 | { |
759 | 0 | this.behaviorId = behaviorId; |
760 | 0 | this.type = type; |
761 | |
try |
762 | |
{ |
763 | 0 | this.constructor = this.type.getConstructor(CONS_SIG); |
764 | |
} |
765 | 0 | catch (Exception e) |
766 | |
{ |
767 | 0 | throw new FaceletException("Must have a Constructor that takes in a BehaviorConfig", e); |
768 | 0 | } |
769 | 0 | } |
770 | |
|
771 | |
public TagHandler createHandler(TagConfig cfg) throws FacesException, ELException |
772 | |
{ |
773 | |
try |
774 | |
{ |
775 | 0 | BehaviorConfig bcfg = new BehaviorConfigWrapper(cfg,this.behaviorId); |
776 | 0 | return constructor.newInstance(new Object[] { bcfg }); |
777 | |
} |
778 | 0 | catch (InvocationTargetException e) |
779 | |
{ |
780 | 0 | throw new FaceletException(e.getCause().getMessage(), e.getCause().getCause()); |
781 | |
} |
782 | 0 | catch (Exception e) |
783 | |
{ |
784 | 0 | throw new FaceletException("Error Instantiating BehaviorHandler: " + this.type.getName(), e); |
785 | |
} |
786 | |
} |
787 | |
} |
788 | |
|
789 | |
private static class UserComponentFromResourceIdHandlerFactory implements TagHandlerFactory |
790 | |
{ |
791 | |
protected final String resourceId; |
792 | |
|
793 | |
public UserComponentFromResourceIdHandlerFactory(String resourceId) |
794 | 0 | { |
795 | 0 | this.resourceId = resourceId; |
796 | 0 | } |
797 | |
|
798 | |
public TagHandler createHandler(TagConfig cfg) throws FacesException, ELException |
799 | |
{ |
800 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
801 | 0 | ResourceHandler resourceHandler = facesContext.getApplication().getResourceHandler(); |
802 | 0 | Resource compositeComponentResourceWrapped = resourceHandler.createResourceFromId(resourceId); |
803 | 0 | if (compositeComponentResourceWrapped != null) |
804 | |
{ |
805 | 0 | Resource compositeComponentResource |
806 | |
= new CompositeResouceWrapper(compositeComponentResourceWrapped); |
807 | 0 | ComponentConfig componentConfig = new ComponentConfigWrapper(cfg, |
808 | |
"javax.faces.NamingContainer", null); |
809 | |
|
810 | 0 | return new CompositeComponentResourceTagHandler(componentConfig, |
811 | |
compositeComponentResource); |
812 | |
} |
813 | |
else |
814 | |
{ |
815 | 0 | throw new FaceletException( |
816 | |
"Error Instantiating Component from <resource-id> declaration: " + this.resourceId); |
817 | |
} |
818 | |
} |
819 | |
} |
820 | |
} |