1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.lifecycle;
17
18 import org.apache.log4j.Logger;
19 import org.kuali.rice.krad.uif.component.Component;
20 import org.kuali.rice.krad.web.bind.UifEncryptionPropertyEditorWrapper;
21
22 import java.beans.PropertyEditor;
23 import java.io.Serializable;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Set;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public class ViewPostMetadata implements Serializable {
46
47 private static final long serialVersionUID = -515221881981451818L;
48 private static final Logger LOG = Logger.getLogger(ViewPostMetadata.class);
49
50 private String id;
51
52 private Map<String, ComponentPostMetadata> componentPostMetadataMap;
53
54 private Map<String, PropertyEditor> fieldPropertyEditors;
55 private Map<String, PropertyEditor> secureFieldPropertyEditors;
56
57 private Set<String> inputFieldIds;
58 private Set<String> allRenderedPropertyPaths;
59 private Map<String, List<Object>> addedCollectionObjects;
60
61 private Map<String, Map<String, Object>> lookupCriteria;
62
63 private Set<String> accessibleBindingPaths;
64 private Set<String> accessibleMethodToCalls;
65 private Set<String> availableMethodToCalls;
66
67
68
69
70 public ViewPostMetadata() {
71 fieldPropertyEditors = Collections.synchronizedMap(new HashMap<String, PropertyEditor>());
72 secureFieldPropertyEditors = Collections.synchronizedMap(new HashMap<String, PropertyEditor>());
73 inputFieldIds = Collections.synchronizedSet(new HashSet<String>());
74 allRenderedPropertyPaths = Collections.synchronizedSet(new HashSet<String>());
75 addedCollectionObjects = Collections.synchronizedMap(new HashMap<String, List<Object>>());
76 lookupCriteria = Collections.synchronizedMap(new HashMap<String, Map<String, Object>>());
77 accessibleBindingPaths = Collections.synchronizedSet(new HashSet<String>());
78 accessibleMethodToCalls = Collections.synchronizedSet(new HashSet<String>());
79 availableMethodToCalls = Collections.synchronizedSet(new HashSet<String>());
80 }
81
82
83
84
85
86
87 public ViewPostMetadata(String id) {
88 this();
89
90 this.id = id;
91 }
92
93
94
95
96 public void cleanAfterLifecycle() {
97 allRenderedPropertyPaths = Collections.synchronizedSet(new HashSet<String>());
98 addedCollectionObjects = Collections.synchronizedMap(new HashMap<String, List<Object>>());
99 }
100
101
102
103
104
105
106 public String getId() {
107 return id;
108 }
109
110
111
112
113 public void setId(String id) {
114 this.id = id;
115 }
116
117
118
119
120
121
122 public Map<String, ComponentPostMetadata> getComponentPostMetadataMap() {
123 return componentPostMetadataMap;
124 }
125
126
127
128
129 public void setComponentPostMetadataMap(Map<String, ComponentPostMetadata> componentPostMetadataMap) {
130 this.componentPostMetadataMap = componentPostMetadataMap;
131 }
132
133
134
135
136
137
138
139 public ComponentPostMetadata getComponentPostMetadata(String componentId) {
140 ComponentPostMetadata componentPostMetadata = null;
141
142 if (componentPostMetadataMap != null && (componentPostMetadataMap.containsKey(componentId))) {
143 componentPostMetadata = componentPostMetadataMap.get(componentId);
144 }
145
146 return componentPostMetadata;
147 }
148
149
150
151
152
153
154
155
156 public void addComponentPostData(Component component, String key, Object value) {
157 if (component == null) {
158 throw new IllegalArgumentException("Component must not be null for adding post data");
159 }
160
161 addComponentPostData(component.getId(), key, value);
162 }
163
164
165
166
167
168
169
170
171 public void addComponentPostData(String componentId, String key, Object value) {
172 if (value == null) {
173 return;
174 }
175
176 ComponentPostMetadata componentPostMetadata = initializeComponentPostMetadata(componentId);
177
178 componentPostMetadata.addData(key, value);
179 }
180
181
182
183
184
185
186
187
188 public Object getComponentPostData(String componentId, String key) {
189 ComponentPostMetadata componentPostMetadata = getComponentPostMetadata(componentId);
190
191 if (componentPostMetadata != null) {
192 return componentPostMetadata.getData(key);
193 }
194
195 return null;
196 }
197
198
199
200
201
202
203
204 public ComponentPostMetadata initializeComponentPostMetadata(Component component) {
205 if (component == null) {
206 throw new IllegalArgumentException("Component must not be null to initialize post metadata");
207 }
208
209 return initializeComponentPostMetadata(component.getId());
210 }
211
212
213
214
215
216
217
218 public ComponentPostMetadata initializeComponentPostMetadata(String componentId) {
219 if (componentPostMetadataMap == null) {
220 synchronized (this) {
221 if (componentPostMetadataMap == null) {
222 componentPostMetadataMap = new HashMap<String, ComponentPostMetadata>();
223 }
224 }
225 }
226
227 ComponentPostMetadata componentPostMetadata;
228 if (componentPostMetadataMap.containsKey(componentId)) {
229 componentPostMetadata = componentPostMetadataMap.get(componentId);
230 } else {
231 synchronized (componentPostMetadataMap) {
232 componentPostMetadata = new ComponentPostMetadata(componentId);
233 componentPostMetadataMap.put(componentId, componentPostMetadata);
234 }
235 }
236
237 return componentPostMetadata;
238 }
239
240
241
242
243
244
245
246 public ComponentPostMetadata getComponentPostMetadataForPath(String path) {
247 if (componentPostMetadataMap == null) {
248 return null;
249 }
250
251 Collection<ComponentPostMetadata> componentPostMetadataCollection = componentPostMetadataMap.values();
252
253 for (ComponentPostMetadata metadata : componentPostMetadataCollection) {
254 if (metadata.getPath() != null && metadata.getPath().equals(path)) {
255 return metadata;
256 }
257 }
258
259 return null;
260 }
261
262
263
264
265
266
267
268
269
270
271
272 public Map<String, PropertyEditor> getFieldPropertyEditors() {
273 return fieldPropertyEditors;
274 }
275
276
277
278
279
280
281
282 public void addFieldPropertyEditor(String propertyPath, PropertyEditor propertyEditor) {
283 if (fieldPropertyEditors == null) {
284 fieldPropertyEditors = new HashMap<String, PropertyEditor>();
285 }
286
287 fieldPropertyEditors.put(propertyPath, propertyEditor);
288 }
289
290
291
292
293
294
295
296
297
298
299
300 public Map<String, PropertyEditor> getSecureFieldPropertyEditors() {
301 return secureFieldPropertyEditors;
302 }
303
304
305
306
307
308
309
310 public void addSecureFieldPropertyEditor(String propertyPath, PropertyEditor propertyEditor) {
311 if (secureFieldPropertyEditors == null) {
312 secureFieldPropertyEditors = new HashMap<String, PropertyEditor>();
313 }
314
315 secureFieldPropertyEditors.put(propertyPath, propertyEditor);
316 }
317
318
319
320
321
322
323 public Set<String> getInputFieldIds() {
324 return inputFieldIds;
325 }
326
327
328
329
330 public void setInputFieldIds(Set<String> inputFieldIds) {
331 this.inputFieldIds = inputFieldIds;
332 }
333
334
335
336
337
338
339
340
341
342
343 public Set<String> getAllRenderedPropertyPaths() {
344 return allRenderedPropertyPaths;
345 }
346
347
348
349
350 public void setAllRenderedPropertyPaths(Set<String> allRenderedPropertyPaths) {
351 this.allRenderedPropertyPaths = allRenderedPropertyPaths;
352 }
353
354
355
356
357
358
359
360 public void addRenderedPropertyPath(String propertyPath) {
361 if (this.allRenderedPropertyPaths == null) {
362 this.allRenderedPropertyPaths = new HashSet<String>();
363 }
364
365 this.allRenderedPropertyPaths.add(propertyPath);
366 }
367
368
369
370
371
372
373
374
375
376
377
378
379
380 public Map<String, List<Object>> getAddedCollectionObjects() {
381 return addedCollectionObjects;
382 }
383
384
385
386
387 public void setAddedCollectionObjects(Map<String, List<Object>> addedCollectionObjects) {
388 this.addedCollectionObjects = addedCollectionObjects;
389 }
390
391
392
393
394
395
396
397
398
399
400 public Map<String, Map<String, Object>> getLookupCriteria() {
401 return lookupCriteria;
402 }
403
404
405
406
407 public void setLookupCriteria(Map<String, Map<String, Object>> lookupCriteria) {
408 this.lookupCriteria = lookupCriteria;
409 }
410
411
412
413
414
415
416
417
418
419 public Set<String> getAccessibleBindingPaths() {
420 return accessibleBindingPaths;
421 }
422
423
424
425
426 public void setAccessibleBindingPaths(Set<String> accessibleBindingPaths) {
427 this.accessibleBindingPaths = accessibleBindingPaths;
428 }
429
430
431
432
433
434
435
436 public void addAccessibleBindingPath(String accessibleBindingPath) {
437 if (this.accessibleBindingPaths == null) {
438 this.accessibleBindingPaths = Collections.synchronizedSet(new HashSet<String>());
439 }
440
441 this.accessibleBindingPaths.add(accessibleBindingPath);
442 }
443
444
445
446
447
448
449
450
451
452 public Set<String> getAccessibleMethodToCalls() {
453 return accessibleMethodToCalls;
454 }
455
456
457
458
459 public void setAccessibleMethodToCalls(Set<String> accessibleMethodToCalls) {
460 this.accessibleMethodToCalls = accessibleMethodToCalls;
461 }
462
463
464
465
466
467
468
469 public void addAccessibleMethodToCall(String methodToCall) {
470 if (this.accessibleMethodToCalls == null) {
471 this.accessibleMethodToCalls = Collections.synchronizedSet(new HashSet<String>());
472 }
473
474 this.accessibleMethodToCalls.add(methodToCall);
475 }
476
477
478
479
480
481
482
483
484
485
486 public Set<String> getAvailableMethodToCalls() {
487 return availableMethodToCalls;
488 }
489
490
491
492
493 public void setAvailableMethodToCalls(Set<String> availableMethodToCalls) {
494 this.availableMethodToCalls = availableMethodToCalls;
495 }
496
497
498
499
500
501
502
503 public void addAvailableMethodToCall(String methodToCall) {
504 if (this.availableMethodToCalls == null) {
505 this.availableMethodToCalls = Collections.synchronizedSet(new HashSet<String>());
506 }
507
508 this.availableMethodToCalls.add(methodToCall);
509 }
510
511
512
513
514
515
516 public PropertyEditor getFieldEditor(String propertyName) {
517 if (LOG.isDebugEnabled()) {
518 LOG.debug("Attempting to find property editor for property '" + propertyName + "'");
519 }
520
521 PropertyEditor propertyEditor = null;
522 boolean requiresEncryption = false;
523
524 if (fieldPropertyEditors != null && fieldPropertyEditors.containsKey(propertyName)) {
525 propertyEditor = fieldPropertyEditors.get(propertyName);
526 } else if (secureFieldPropertyEditors != null && secureFieldPropertyEditors.containsKey(propertyName)) {
527 propertyEditor = secureFieldPropertyEditors.get(propertyName);
528 requiresEncryption = true;
529 }
530
531 if (propertyEditor != null) {
532 if (LOG.isDebugEnabled()) {
533 LOG.debug(
534 "Registering custom editor for property path '" + propertyName + "' and property editor class '"
535 + propertyEditor.getClass().getName() + "'");
536 }
537
538 if (requiresEncryption) {
539 if (LOG.isDebugEnabled()) {
540 LOG.debug("Enabling encryption for custom editor '" + propertyName +
541 "' and property editor class '" + propertyEditor.getClass().getName() + "'");
542 }
543
544 return new UifEncryptionPropertyEditorWrapper(propertyEditor);
545 }
546 }
547
548 return propertyEditor;
549 }
550 }