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 java.beans.BeanDescriptor; |
22 | |
import java.beans.IntrospectionException; |
23 | |
import java.beans.PropertyDescriptor; |
24 | |
import java.io.IOException; |
25 | |
import java.util.HashMap; |
26 | |
import java.util.Map; |
27 | |
import java.util.logging.Level; |
28 | |
import java.util.logging.Logger; |
29 | |
|
30 | |
import javax.faces.component.UIComponent; |
31 | |
import javax.faces.view.Location; |
32 | |
import javax.faces.view.facelets.FaceletContext; |
33 | |
import javax.faces.view.facelets.TagConfig; |
34 | |
import javax.faces.view.facelets.TagException; |
35 | |
import javax.faces.view.facelets.TagHandler; |
36 | |
|
37 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag; |
38 | |
import org.apache.myfaces.view.facelets.AbstractFaceletContext; |
39 | |
import org.apache.myfaces.view.facelets.FaceletCompositionContext; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
@JSFFaceletTag(name="composite:implementation") |
46 | |
public class ImplementationHandler extends TagHandler |
47 | |
{ |
48 | |
|
49 | 0 | private static final Logger log = Logger.getLogger(ImplementationHandler.class.getName()); |
50 | |
|
51 | |
public final static String NAME = "implementation"; |
52 | |
|
53 | |
public ImplementationHandler(TagConfig config) |
54 | |
{ |
55 | 0 | super(config); |
56 | 0 | } |
57 | |
|
58 | |
public void apply(FaceletContext ctx, UIComponent parent) |
59 | |
throws IOException |
60 | |
{ |
61 | 0 | if (!((AbstractFaceletContext)ctx).isBuildingCompositeComponentMetadata()) |
62 | |
{ |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | 0 | nextHandler.apply(ctx, parent); |
68 | |
} |
69 | |
else |
70 | |
{ |
71 | 0 | UIComponent compositeBaseParent |
72 | |
= FaceletCompositionContext.getCurrentInstance(ctx).getCompositeComponentFromStack(); |
73 | |
|
74 | 0 | CompositeComponentBeanInfo beanInfo = |
75 | |
(CompositeComponentBeanInfo) compositeBaseParent.getAttributes() |
76 | |
.get(UIComponent.BEANINFO_KEY); |
77 | |
|
78 | 0 | if (beanInfo == null) |
79 | |
{ |
80 | 0 | if (log.isLoggable(Level.SEVERE)) |
81 | |
{ |
82 | 0 | log.severe("Cannot find composite bean descriptor UIComponent.BEANINFO_KEY "); |
83 | |
} |
84 | 0 | return; |
85 | |
} |
86 | |
|
87 | 0 | BeanDescriptor beanDescriptor = beanInfo.getBeanDescriptor(); |
88 | |
|
89 | 0 | Map<String, PropertyDescriptor> facetPropertyDescriptorMap = |
90 | |
(Map<String, PropertyDescriptor>) beanDescriptor.getValue(UIComponent.FACETS_KEY); |
91 | |
|
92 | 0 | if (facetPropertyDescriptorMap == null) |
93 | |
{ |
94 | 0 | facetPropertyDescriptorMap = new HashMap<String, PropertyDescriptor>(); |
95 | 0 | beanDescriptor.setValue(UIComponent.FACETS_KEY, facetPropertyDescriptorMap); |
96 | |
} |
97 | |
|
98 | 0 | if (!facetPropertyDescriptorMap.containsKey(UIComponent.COMPOSITE_FACET_NAME)) |
99 | |
{ |
100 | |
try |
101 | |
{ |
102 | 0 | facetPropertyDescriptorMap.put(UIComponent.COMPOSITE_FACET_NAME, |
103 | |
new CompositeComponentPropertyDescriptor(UIComponent.COMPOSITE_FACET_NAME)); |
104 | |
} |
105 | 0 | catch (IntrospectionException e) |
106 | |
{ |
107 | 0 | if (log.isLoggable(Level.SEVERE)) |
108 | |
{ |
109 | 0 | log.log(Level.SEVERE, "Cannot create PropertyDescriptor for facet ",e); |
110 | |
} |
111 | 0 | throw new TagException(tag,e); |
112 | 0 | } |
113 | |
} |
114 | |
|
115 | |
|
116 | |
|
117 | 0 | nextHandler.apply(ctx, parent); |
118 | |
} |
119 | 0 | } |
120 | |
|
121 | |
public Location getLocation() |
122 | |
{ |
123 | 0 | return this.tag.getLocation(); |
124 | |
} |
125 | |
} |