Skip to main content
summaryrefslogtreecommitdiffstats
blob: caf4716c5ffdfa352cb77739686bb6b50d0ea13b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
package org.eclipse.jst.jsf.common.runtime.internal.model.component;

import java.util.Map;

import org.eclipse.jst.jsf.common.runtime.internal.model.bean.DataModelInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.behavioural.IActionSource2Info;
import org.eclipse.jst.jsf.common.runtime.internal.model.behavioural.IActionSourceInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.behavioural.IEditableValueHolderInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.behavioural.INamingContainerInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.behavioural.IValueHolderInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.decorator.ConverterDecorator;
import org.eclipse.jst.jsf.common.runtime.internal.model.decorator.FacetDecorator;
import org.eclipse.jst.jsf.common.runtime.internal.model.decorator.ValidatorDecorator;
import org.eclipse.jst.jsf.common.runtime.internal.model.event.IActionListenerInfo;
import org.eclipse.jst.jsf.common.runtime.internal.model.event.IValueChangeListenerInfo;

/**
 * Factory for creating component related objects.
 * 
 * @author cbateman
 * 
 */
public class ComponentFactory
{

    /**
     * The key for the standard ValueHolder adapter interface
     */
    public final static Class VALUE_HOLDER = IValueHolderInfo.class;
    /**
     * The key for the standard EditableValueHolder adapter interface
     */
    public final static Class EDITABLE_VALUE_HOLDER = IEditableValueHolderInfo.class;
    /**
     * The key for the standard ActionSource adapter interface
     */
    public final static Class ACTION_SOURCE = IActionSourceInfo.class;
    /**
     * The key for the standard ActionSource2 adapter interface
     */
    public final static Class ACTION_SOURCE2 = IActionSource2Info.class;
    /**
     * The key for the standard NamingContainer adapter interface
     */
    public final static Class NAMING_CONTAINER = INamingContainerInfo.class;

    /**
     * The key for the standard Converter decorator
     */
    public final static Class CONVERTER = ConverterDecorator.class;
    /**
     * The key for the standard Facet decorator
     */
    public final static Class FACET = FacetDecorator.class;
    /**
     * The key for the standard Validator decorator
     */
    public final static Class VALIDATOR = ValidatorDecorator.class;
    /**
     * The key for the standard ValueChangeListener decorator
     */
    public final static Class VALUE_CHANGE_LISTENER = IValueChangeListenerInfo.class;
    /**
     * The key for the standard ActionListener decorator
     */
    public final static Class ACTION_LISTENER = IActionListenerInfo.class;

    /**
     * Base class name for UIInput's
     */
    public final static String BASE_CLASS_UIINPUT = "javax.faces.component.UIInput";
    /**
     * Base class name for UIOutput's
     */
    public final static String BASE_CLASS_UIOUTPUT = "javax.faces.component.UIOutput";
    /**
     * Base class name for UICommand's
     */
    public final static String BASE_CLASS_UICOMMAND = "javax.faces.component.UICommand";
    /**
     * Base class name for UIData's
     */
    public final static String BASE_CLASS_UIDATA = "javax.faces.component.UIData";
    /**
     * Base class name for UIForm's
     */
    public final static String BASE_CLASS_UIFORM = "javax.faces.component.UIForm";

    /**
     * Interface name for ValueHolder's
     */
    public final static String INTERFACE_VALUEHOLDER = "javax.faces.component.ValueHolder";
    /**
     * Interface name for EditableValueHolder's
     */
    public final static String INTERFACE_EDITABLEVALUEHOLDER = "javax.faces.component.EditableValueHolder";
    /**
     * Interface name for ActionSource's
     */
    public final static String INTERFACE_ACTIONSOURCE = "javax.faces.component.ActionSource";
    /**
     * Interface name for ActionSource2's
     */
    public final static String INTERFACE_ACTIONSOURCE2 = "javax.faces.component.ActionSource2";
    /**
     * Interface name for NamingContainer's
     */
    public final static String INTERFACE_NAMINGCONTAINER = "javax.faces.component.NamingContainer";

    /**
     * @param id
     * @param parent
     * @param typeInfo
     * @param isRendered
     * @return a new component info
     */
    public static ComponentInfo createComponentInfo(final String id,
            final ComponentInfo parent, final ComponentTypeInfo typeInfo,
            final boolean isRendered)
    {
        return new ComponentInfo(id, parent, typeInfo, isRendered);
    }

    /**
     * If the rendered attribute isn't set, defaults it.
     * 
     * @param attributes
     */
    public static void maybeDefaultRendered(final Map attributes)
    {
        if (!(attributes.get("rendered") instanceof Boolean))
        {
            attributes.put("rendered", Boolean.TRUE);
        }
    }

    /**
     * @param parent
     * @param componentTypeInfo
     * @param attributes
     * @return a new component info
     */
    public static ComponentInfo createComponentInfo(final ComponentInfo parent,
            final ComponentTypeInfo componentTypeInfo, final Map attributes)
    {
        maybeDefaultRendered(attributes);
        return new ComponentInfo(parent, componentTypeInfo, attributes);
    }

    /**
     * @param id
     * @param parent
     * @param typeInfo
     * @param editableValueHolder
     * @param isRendered
     * @return a new UIInputInfo
     */
    public static UIInputInfo createUIInputInfo(final String id,
            final ComponentInfo parent, final ComponentTypeInfo typeInfo,
            final IEditableValueHolderInfo editableValueHolder,
            final boolean isRendered)
    {
        return new UIInputInfo(id, parent, typeInfo, editableValueHolder,
                isRendered);
    }

    /**
     * @param parent
     * @param typeInfo
     * @param attributes
     * @return a new UIInputInfo
     */
    public static UIInputInfo createUIInputInfo(final ComponentInfo parent,
            final ComponentTypeInfo typeInfo, final Map attributes)
    {
        maybeDefaultRendered(attributes);
        return new UIInputInfo(parent, typeInfo, attributes);
    }

    /**
     * @param id
     * @param parent
     * @param typeInfo
     * @param valueHolderInfo
     * @param isRendered
     * @return a new UIOutputInfo
     */
    public static UIOutputInfo createUIOutputInfo(final String id,
            final ComponentInfo parent, final ComponentTypeInfo typeInfo,
            final IValueHolderInfo valueHolderInfo, final boolean isRendered)
    {
        return new UIOutputInfo(id, parent, typeInfo, valueHolderInfo,
                isRendered);
    }

    /**
     * @param parent
     * @param typeInfo
     * @param attributes
     * @return a new UIOutputInfo
     */
    public static UIOutputInfo createUIOutputInfo(final ComponentInfo parent,
            final ComponentTypeInfo typeInfo, final Map attributes)
    {
        maybeDefaultRendered(attributes);
        return new UIOutputInfo(parent, typeInfo, attributes);
    }

    /**
     * @param id
     * @param parent
     * @param typeInfo
     * @param actionSourceInfo
     * @param isRendered
     * @return a new UICommandInfo
     */
    public static UICommandInfo createUICommandInfo(final String id,
            final ComponentInfo parent, final ComponentTypeInfo typeInfo,
            final IActionSourceInfo actionSourceInfo, final boolean isRendered)
    {
        return new UICommandInfo(id, parent, typeInfo, isRendered,
                actionSourceInfo);
    }

    /**
     * @param parent
     * @param typeInfo
     * @param attributes
     * @return a new UICommandInfo
     */
    public static UICommandInfo createUICommandInfo(final ComponentInfo parent,
            final ComponentTypeInfo typeInfo, final Map attributes)
    {
        maybeDefaultRendered(attributes);
        return new UICommandInfo(parent, typeInfo, attributes);
    }

    /**
     * @param id
     * @param parent
     * @param typeInfo
     * @param isRendered
     * @param prependId
     * @param submitted
     * @return a new UIFormInfo
     */
    public static UIFormInfo createUIFormInfo(final String id,
            final ComponentInfo parent, final ComponentTypeInfo typeInfo,
            final boolean isRendered, final boolean prependId,
            final boolean submitted)
    {
        return new UIFormInfo(id, parent, typeInfo, isRendered, prependId,
                submitted);
    }

    /**
     * @param parent
     * @param typeInfo
     * @param attributes
     * @return a new UIFormInfo
     */
    public static UIFormInfo createUIFormInfo(final ComponentInfo parent,
            final ComponentTypeInfo typeInfo, final Map attributes)
    {
        maybeDefaultRendered(attributes);
        maybeDefaultPrependId(attributes);
        maybeDefaultSubmitted(attributes);
        return new UIFormInfo(parent, typeInfo, attributes);
    }

    private static void maybeDefaultSubmitted(Map attributes)
    {
        if (!(attributes.get("submitted") instanceof Boolean))
        {
            attributes.put("submitted", Boolean.FALSE);
        }
    }

    private static void maybeDefaultPrependId(Map attributes)
    {
        if (!(attributes.get("prependId") instanceof Boolean))
        {
            attributes.put("prependId", Boolean.FALSE);
        }
    }

    /**
     * @param id
     * @param parent
     * @param typeInfo
     * @param isRendered
     * @param dataModel
     * @param first
     * @param footer
     * @param header
     * @param rowCount
     * @param rowAvailable
     * @param rowData
     * @param rowIndex
     * @param rows
     * @param value
     * @param var
     * @return a new UIDataInfo
     */
    public static UIDataInfo createUIDataInfo(final String id,
            final ComponentInfo parent, final ComponentTypeInfo typeInfo,
            final boolean isRendered, final DataModelInfo dataModel,
            final int first, final ComponentInfo footer,
            final ComponentInfo header, final int rowCount,
            final boolean rowAvailable, final Object rowData,
            final int rowIndex, final int rows, final Object value,
            final String var)
    {
        return new UIDataInfo(id, parent, typeInfo, isRendered, dataModel,
                first, footer, header, rowCount, rowAvailable, rowData,
                rowIndex, rows, value, var);
    }

    /**
     * @param parent
     * @param typeInfo
     * @param attributes
     * @return the UIDataInfo
     */
    public static UIDataInfo createUIDataInfo(final ComponentInfo parent,
            final ComponentTypeInfo typeInfo, final Map attributes)
    {
        maybeDefaultRendered(attributes);
        maybeDefaultFirst(attributes);
        maybeDefaultRowCount(attributes);
        maybeDefaultRowAvailable(attributes);
        maybeDefaultRowIndex(attributes);
        maybeDefaultRows(attributes);
        maybeDefaultVar(attributes);
        return new UIDataInfo(parent, typeInfo, attributes);
    }


    private static final Integer ZERO = new Integer(0);
    private static final Integer MINUS_ONE = new Integer(-1);

    private static void maybeDefaultFirst(Map attributes)
    {
        if (!(attributes.get("first") instanceof Integer))
        {
            attributes.put("first", ZERO);
        }
    }

    private static void maybeDefaultRowCount(Map attributes)
    {
        if (!(attributes.get("rowCount") instanceof Integer))
        {
            attributes.put("rowCount", MINUS_ONE);
        }
    }

    private static void maybeDefaultRowAvailable(Map attributes)
    {
        if (! (attributes.get("rowAvailable") instanceof Boolean))
        {
            attributes.put("rowAvailable", Boolean.FALSE);
        }
    }

    private static void maybeDefaultRowIndex(Map attributes)
    {
        if (! (attributes.get("rowIndex") instanceof Integer))
        {
            attributes.put("rowIndex", MINUS_ONE);
        }
    }

    private static void maybeDefaultRows(Map attributes)
    {
        if (! (attributes.get("rows") instanceof Integer))
        {
            attributes.put("rows", ZERO);
        }
    }

    private static void maybeDefaultVar(Map attributes)
    {
        if (! (attributes.get("var") instanceof String))
        {
            attributes.put("var", "** default variable **");
        }
    }
}

Back to the top