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.composite;
20
21 import javax.el.MethodExpression;
22 import javax.faces.view.facelets.ComponentConfig;
23 import javax.faces.view.facelets.ComponentHandler;
24 import javax.faces.view.facelets.FaceletContext;
25 import javax.faces.view.facelets.MetaRule;
26 import javax.faces.view.facelets.MetaRuleset;
27 import javax.faces.view.facelets.Metadata;
28 import javax.faces.view.facelets.MetadataTarget;
29 import javax.faces.view.facelets.TagAttribute;
30
31 public class SimpleComponentTagHandler extends ComponentHandler
32 {
33
34 public SimpleComponentTagHandler(ComponentConfig config)
35 {
36 super(config);
37
38 }
39
40 @Override
41 protected MetaRuleset createMetaRuleset(Class type)
42 {
43 return super.createMetaRuleset(type).addRule(new CustomMethodRule());
44 }
45
46 public final class CustomMethodRule extends MetaRule {
47
48 @Override
49 public Metadata applyRule(String name, TagAttribute attribute,
50 MetadataTarget meta)
51 {
52 if (meta.isTargetInstanceOf(SimpleComponent.class))
53 {
54 if ("customMethod".equals(name))
55 {
56 return new SimpleMethodMapper(attribute);
57 }
58 }
59 return null;
60 }
61
62 }
63
64 final static class SimpleMethodMapper extends Metadata
65 {
66 private final TagAttribute _attr;
67
68 public final static Class<?>[] CUSTOM_METHOD_SIG = new Class[]{String.class};
69
70 public SimpleMethodMapper(TagAttribute attr)
71 {
72 this._attr = attr;
73 }
74
75 public void applyMetadata(FaceletContext ctx, Object instance)
76 {
77 MethodExpression expr = _attr.getMethodExpression(ctx, null, CUSTOM_METHOD_SIG);
78 ((SimpleComponent) instance).setCustomMethod(expr);
79 }
80 }
81
82 }