1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javax.faces.view;
20
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.Iterator;
24 import java.util.LinkedList;
25
26 import javax.faces.component.UIComponent;
27 import javax.faces.component.UIImportConstants;
28 import javax.faces.component.UIViewAction;
29 import javax.faces.component.UIViewParameter;
30 import javax.faces.component.UIViewRoot;
31 import javax.faces.context.FacesContext;
32
33
34
35
36 public abstract class ViewMetadata
37 {
38 public abstract UIViewRoot createMetadataView(FacesContext context);
39
40 public abstract String getViewId();
41
42 public static Collection<UIViewParameter> getViewParameters(UIViewRoot root)
43 {
44 LinkedList<UIViewParameter> result = null;
45 UIComponent metadataFacet = root.getFacet (UIViewRoot.METADATA_FACET_NAME);
46 Iterator<UIComponent> children;
47
48 if (metadataFacet == null)
49 {
50
51
52 return Collections.emptyList();
53 }
54
55
56
57 if (metadataFacet.getChildCount() > 0)
58 {
59 children = metadataFacet.getChildren().iterator();
60
61 while (children.hasNext())
62 {
63 UIComponent component = children.next();
64
65 if (result == null)
66 {
67 result = new LinkedList<UIViewParameter>();
68 }
69
70 if (component instanceof UIViewParameter)
71 {
72 result.add ((UIViewParameter) component);
73 }
74 }
75 }
76
77
78
79 if (result == null)
80 {
81 return Collections.emptyList();
82 }
83 else
84 {
85 return Collections.unmodifiableCollection (result);
86 }
87 }
88
89
90
91
92
93
94 public static Collection<UIViewAction> getViewActions(UIViewRoot root)
95 {
96 LinkedList<UIViewAction> result = null;
97 UIComponent metadataFacet = root.getFacet (UIViewRoot.METADATA_FACET_NAME);
98 Iterator<UIComponent> children;
99
100 if (metadataFacet == null)
101 {
102
103
104 return Collections.emptyList();
105 }
106
107
108
109 if (metadataFacet.getChildCount() > 0)
110 {
111 children = metadataFacet.getChildren().iterator();
112
113 while (children.hasNext())
114 {
115 UIComponent component = children.next();
116
117 if (result == null)
118 {
119 result = new LinkedList<UIViewAction>();
120 }
121
122 if (component instanceof UIViewAction)
123 {
124 result.add ((UIViewAction) component);
125 }
126 }
127 }
128
129
130
131 if (result == null)
132 {
133 return Collections.emptyList();
134 }
135 else
136 {
137 return Collections.unmodifiableCollection (result);
138 }
139 }
140
141
142
143
144
145
146 public static boolean hasMetadata(UIViewRoot root)
147 {
148 UIComponent metadataFacet = root.getFacet(UIViewRoot.METADATA_FACET_NAME);
149 return metadataFacet != null ? metadataFacet.getChildCount() > 0 : false;
150 }
151
152
153
154
155
156
157 public static Collection<UIImportConstants> getImportConstants(UIViewRoot root)
158 {
159 LinkedList<UIImportConstants> result = null;
160 UIComponent metadataFacet = root.getFacet (UIViewRoot.METADATA_FACET_NAME);
161 Iterator<UIComponent> children;
162
163 if (metadataFacet == null)
164 {
165
166
167 return Collections.emptyList();
168 }
169
170
171
172 if (metadataFacet.getChildCount() > 0)
173 {
174 children = metadataFacet.getChildren().iterator();
175
176 while (children.hasNext())
177 {
178 UIComponent component = children.next();
179
180 if (result == null)
181 {
182 result = new LinkedList<UIImportConstants>();
183 }
184
185 if (component instanceof UIImportConstants)
186 {
187 result.add ((UIImportConstants) component);
188 }
189 }
190 }
191
192
193
194 if (result == null)
195 {
196 return Collections.emptyList();
197 }
198 else
199 {
200 return Collections.unmodifiableCollection (result);
201 }
202 }
203
204 }