1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.orchestra.dynaForm.metadata.impl;
20
21 import org.apache.myfaces.orchestra.dynaForm.lib.SelectionSourceEnum;
22 import org.apache.myfaces.orchestra.dynaForm.metadata.FieldRepresentation;
23 import org.apache.myfaces.orchestra.dynaForm.metadata.MetaFieldWritable;
24 import org.apache.myfaces.orchestra.dynaForm.metadata.RelationType;
25 import org.apache.myfaces.orchestra.dynaForm.metadata.Selection;
26
27 import javax.faces.component.UIComponent;
28 import javax.faces.convert.Converter;
29 import javax.persistence.TemporalType;
30 import java.io.Serializable;
31 import java.util.HashMap;
32 import java.util.Map;
33
34
35
36
37
38 class MetaFieldImpl implements MetaFieldWritable, Serializable
39 {
40 private final String name;
41 private final String baseName;
42 private Class<?> type;
43 private boolean entityType;
44 private boolean id;
45 private boolean canRead;
46 private boolean canWrite;
47 private boolean disabled;
48 private boolean displayOnly;
49 private boolean required;
50 private RelationType relationType = RelationType.NONE;
51 private boolean embedded = true;
52 private Integer displaySize;
53 private Integer minSize;
54 private Integer maxSize;
55 private Double minValue;
56 private Double maxValue;
57 private TemporalType temporalType;
58
59 private Selection[] allowedSelection;
60 private boolean allowMultipleSelections;
61 private SelectionSourceEnum selectionSource;
62
63
64 private UIComponent wantedComponent;
65 private FieldRepresentation wantedComponentType = FieldRepresentation.Automatic;
66 private Object componentHandler;
67
68 private String dataSource;
69 private String dataSourceDescription;
70 private String dataComparator;
71
72 private String converterId;
73 private Class<Converter> converterClass;
74 private String converterBean;
75
76 private Map<String, Object> attributes;
77
78 protected MetaFieldImpl(String name)
79 {
80 this.name = name;
81 int pos = name.lastIndexOf('.');
82 if (pos > -1)
83 {
84 this.baseName = name.substring(pos + 1);
85 }
86 else
87 {
88 this.baseName = name;
89 }
90 }
91
92
93 public String getName()
94 {
95 return name;
96 }
97
98
99 public String getBaseName()
100 {
101 return baseName;
102 }
103
104 public Class<?> getType()
105 {
106 return type;
107 }
108
109 public void setType(Class<?> type)
110 {
111 if (this.type != null && this.type != type)
112 {
113 throw new IllegalArgumentException("" + name
114 + ": reset with different type denied. curr:"
115 + this.type.getName() + " new:" + type.getName());
116 }
117 this.type = type;
118 }
119
120 public boolean getDisplayOnly()
121 {
122 return displayOnly;
123 }
124
125 public void setDisplayOnly(boolean displayOnly)
126 {
127 this.displayOnly = displayOnly;
128 }
129
130 public void setCanRead(boolean canRead)
131 {
132 this.canRead = canRead;
133 }
134
135 public boolean getCanRead()
136 {
137 return this.canRead;
138 }
139
140 public void setCanWrite(boolean canWrite)
141 {
142 this.canWrite = canWrite;
143 }
144
145 public boolean getCanWrite()
146 {
147 return canWrite;
148 }
149
150 public void setDisabled(boolean disabled)
151 {
152 this.disabled = disabled;
153 }
154
155 public boolean getDisabled()
156 {
157 return disabled;
158 }
159
160 public boolean getRequired()
161 {
162 return required;
163 }
164
165 public void setRequired(boolean nullable)
166 {
167 this.required = nullable;
168 }
169
170 public Selection[] getAllowedSelections()
171 {
172 return allowedSelection;
173 }
174
175 public void setAllowedSelections(Selection[] allowedSelections)
176 {
177 this.allowedSelection = allowedSelections;
178 }
179
180 public RelationType getRelationType()
181 {
182 return relationType;
183 }
184
185 public void setRelationType(RelationType relationType)
186 {
187 this.relationType = relationType;
188 }
189
190 public Integer getMaxSize()
191 {
192 return maxSize;
193 }
194
195 public void setMaxSize(Integer maxSize)
196 {
197 this.maxSize = maxSize;
198 }
199
200 public Double getMaxValue()
201 {
202 return maxValue;
203 }
204
205 public void setMaxValue(Double maxValue)
206 {
207 this.maxValue = maxValue;
208 }
209
210 public Integer getMinSize()
211 {
212 return minSize;
213 }
214
215 public void setMinSize(Integer minSize)
216 {
217 this.minSize = minSize;
218 }
219
220 public Double getMinValue()
221 {
222 return minValue;
223 }
224
225 public void setMinValue(Double minValue)
226 {
227 this.minValue = minValue;
228 }
229
230 public void setWantedComponent(UIComponent component)
231 {
232 this.wantedComponent = component;
233 }
234
235 public UIComponent getWantedComponent()
236 {
237 return wantedComponent;
238 }
239
240 public void setWantedComponentType(FieldRepresentation componentType)
241 {
242 this.wantedComponentType = componentType;
243 }
244
245 public FieldRepresentation getWantedComponentType()
246 {
247 return this.wantedComponentType;
248 }
249
250 public void setDisplaySize(int displaySize)
251 {
252 this.displaySize = displaySize;
253 }
254
255 public Integer getDisplaySize()
256 {
257 return displaySize;
258 }
259
260 public void setTemporalType(TemporalType temporalType)
261 {
262 this.temporalType = temporalType;
263 }
264
265 public TemporalType getTemporalType()
266 {
267 return temporalType;
268 }
269
270 public boolean getAllowMultipleSelections()
271 {
272 return allowMultipleSelections;
273 }
274
275 public void setAllowMultipleSelections(boolean allowMultipleSelections)
276 {
277 this.allowMultipleSelections = allowMultipleSelections;
278 }
279
280 public SelectionSourceEnum getSelectionSource()
281 {
282 return selectionSource;
283 }
284
285 public void setSelectionSource(SelectionSourceEnum selectionSource)
286 {
287 this.selectionSource = selectionSource;
288 }
289
290 public boolean isEntityType()
291 {
292 return entityType;
293 }
294
295 public void setEntityType(boolean entityType)
296 {
297 this.entityType = entityType;
298 }
299
300 public boolean isId()
301 {
302 return id;
303 }
304
305 public void setId(boolean id)
306 {
307 this.id = id;
308 }
309
310 public boolean isEmbedded()
311 {
312 return embedded;
313 }
314
315 public void setEmbedded(boolean embedded)
316 {
317 this.embedded = embedded;
318 }
319
320 public String getDataSource()
321 {
322 return dataSource;
323 }
324
325 public void setDataSource(String dataSource)
326 {
327 this.dataSource = dataSource;
328 }
329
330 public String getDataSourceDescription()
331 {
332 return dataSourceDescription;
333 }
334
335 public void setDataSourceDescription(String dataSourceDescription)
336 {
337 this.dataSourceDescription = dataSourceDescription;
338 }
339
340 public String getDataComparator()
341 {
342 return dataComparator;
343 }
344
345 public void setDataComparator(String dataComparator)
346 {
347 this.dataComparator = dataComparator;
348 }
349
350 public String getConverterId()
351 {
352 return converterId;
353 }
354
355 public void setConverterId(String converterId)
356 {
357 this.converterId = converterId;
358 }
359
360 public Class<Converter> getConverterClass()
361 {
362 return converterClass;
363 }
364
365 public void setConverterClass(Class<Converter> converterClass)
366 {
367 this.converterClass = converterClass;
368 }
369
370 public String getConverterBean()
371 {
372 return converterBean;
373 }
374
375 public void setConverterBean(String converterBean)
376 {
377 this.converterBean = converterBean;
378 }
379
380 public Object getComponentHandler()
381 {
382 return componentHandler;
383 }
384
385 public void setComponentHandler(Object componentHandler)
386 {
387 this.componentHandler = componentHandler;
388 }
389
390 public void setAttribute(String name, Object value)
391 {
392 if (attributes == null)
393 {
394 attributes = new HashMap<String, Object>();
395 }
396 attributes.put(name, value);
397 }
398
399 public Object getAttribute(String name)
400 {
401 if (attributes == null)
402 {
403 return null;
404 }
405
406 return attributes.get(name);
407 }
408 }
409