1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.component;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
22 import org.kuali.rice.krad.uif.UifConstants;
23 import org.kuali.rice.krad.uif.view.View;
24 import org.kuali.rice.krad.util.ObjectUtils;
25
26 import java.io.Serializable;
27
28
29
30
31
32
33
34
35
36
37
38
39
40 @BeanTag(name = "bindingInfo-bean", parent = "Uif-BindingInfo")
41 public class BindingInfo extends UifDictionaryBeanBase implements Serializable {
42 private static final long serialVersionUID = -7389398061672136091L;
43
44 private boolean bindToForm;
45 private boolean bindToMap;
46
47 private String bindingName;
48 private String bindByNamePrefix;
49 private String bindingObjectPath;
50
51 private String collectionPath;
52
53 private String bindingPath;
54
55 public BindingInfo() {
56 super();
57
58 bindToForm = false;
59 bindToMap = false;
60 }
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 public void setDefaults(View view, String propertyName) {
76 if (StringUtils.isBlank(bindingName)) {
77 bindingName = propertyName;
78 }
79
80 if (StringUtils.isBlank(bindingObjectPath)) {
81 bindingObjectPath = view.getDefaultBindingObjectPath();
82 }
83 }
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 @BeanTagAttribute(name = "bindingPath")
100 public String getBindingPath() {
101 if (StringUtils.isNotBlank(bindingPath)) {
102 return bindingPath;
103 }
104
105 String formedBindingPath = "";
106
107 if (!bindToForm && StringUtils.isNotBlank(bindingObjectPath)) {
108 formedBindingPath = bindingObjectPath;
109 }
110
111 if (StringUtils.isNotBlank(bindByNamePrefix)) {
112 if (!bindByNamePrefix.startsWith("[") && StringUtils.isNotBlank(formedBindingPath)) {
113 formedBindingPath += ".";
114 }
115 formedBindingPath += bindByNamePrefix;
116 }
117
118 if (StringUtils.isNotBlank(bindingName)) {
119 if (bindToMap) {
120 formedBindingPath += "[" + bindingName + "]";
121 } else {
122 if (StringUtils.isNotBlank(formedBindingPath)) {
123 formedBindingPath += ".";
124 }
125 formedBindingPath += bindingName;
126 }
127 }
128
129 return formedBindingPath;
130 }
131
132
133
134
135
136
137
138
139
140 public String getBindingPrefixForNested() {
141 String bindingPrefix = "";
142
143 if (StringUtils.isNotBlank(bindByNamePrefix)) {
144 bindingPrefix = bindByNamePrefix;
145 }
146
147 if (bindToMap) {
148 bindingPrefix += "[" + bindingName + "]";
149 } else {
150 if (StringUtils.isNotBlank(bindingPrefix)) {
151 bindingPrefix += ".";
152 }
153 bindingPrefix += bindingName;
154 }
155
156 return bindingPrefix;
157 }
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177 public String getPropertyAdjustedBindingPath(String propertyPath) {
178 if (propertyPath.startsWith(UifConstants.NO_BIND_ADJUST_PREFIX)) {
179 propertyPath = StringUtils.removeStart(propertyPath, UifConstants.NO_BIND_ADJUST_PREFIX);
180
181 return propertyPath;
182 }
183
184 if (propertyPath.startsWith(UifConstants.FIELD_PATH_BIND_ADJUST_PREFIX)) {
185 propertyPath = StringUtils.removeStart(propertyPath, UifConstants.FIELD_PATH_BIND_ADJUST_PREFIX);
186 }
187
188 String formedBindingPath = "";
189
190 if (!bindToForm && StringUtils.isNotBlank(bindingObjectPath)) {
191 formedBindingPath = bindingObjectPath;
192 }
193
194 if (StringUtils.isNotBlank(bindByNamePrefix)) {
195 if (!bindByNamePrefix.startsWith("[") && StringUtils.isNotBlank(formedBindingPath)) {
196 formedBindingPath += ".";
197 }
198 formedBindingPath += bindByNamePrefix;
199 }
200
201 if (bindToMap) {
202 formedBindingPath += "[" + propertyPath + "]";
203 } else {
204 if (StringUtils.isNotBlank(formedBindingPath)) {
205 formedBindingPath += ".";
206 }
207 formedBindingPath += propertyPath;
208 }
209
210 return formedBindingPath;
211 }
212
213
214
215
216
217
218 public void addToBindByNamePrefix(String bindPrefix) {
219 if (StringUtils.isNotBlank(bindByNamePrefix) && StringUtils.isNotBlank(bindPrefix)) {
220 bindByNamePrefix += "." + bindPrefix;
221 } else {
222 bindByNamePrefix = bindPrefix;
223 }
224 }
225
226
227
228
229
230
231
232 public void setBindingPath(String bindingPath) {
233 this.bindingPath = bindingPath;
234 }
235
236
237
238
239
240
241
242
243
244
245
246 @BeanTagAttribute(name = "bindToForm")
247 public boolean isBindToForm() {
248 return this.bindToForm;
249 }
250
251
252
253
254
255
256 public void setBindToForm(boolean bindToForm) {
257 this.bindToForm = bindToForm;
258 }
259
260
261
262
263
264
265
266
267
268
269
270
271 @BeanTagAttribute(name = "bindingName")
272 public String getBindingName() {
273 return this.bindingName;
274 }
275
276
277
278
279
280
281 public void setBindingName(String bindingName) {
282 this.bindingName = bindingName;
283 }
284
285
286
287
288
289
290
291 @BeanTagAttribute(name = "bindByNamePrefix")
292 public String getBindByNamePrefix() {
293 return this.bindByNamePrefix;
294 }
295
296
297
298
299
300
301 public void setBindByNamePrefix(String bindByNamePrefix) {
302 this.bindByNamePrefix = bindByNamePrefix;
303 }
304
305
306
307
308
309
310
311
312
313
314
315
316 public String getCollectionPath() {
317 return this.collectionPath;
318 }
319
320
321
322
323
324
325 public void setCollectionPath(String collectionPath) {
326 this.collectionPath = collectionPath;
327 }
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348 @BeanTagAttribute(name = "bindingObjectPath")
349 public String getBindingObjectPath() {
350 return this.bindingObjectPath;
351 }
352
353
354
355
356
357
358 public void setBindingObjectPath(String bindingObjectPath) {
359 this.bindingObjectPath = bindingObjectPath;
360 }
361
362
363
364
365
366
367
368
369 @BeanTagAttribute(name = "bindToMap")
370 public boolean isBindToMap() {
371 return this.bindToMap;
372 }
373
374
375
376
377
378
379 public void setBindToMap(boolean bindToMap) {
380 this.bindToMap = bindToMap;
381 }
382
383
384
385
386
387
388 public <T> T copy() {
389 T copiedClass = null;
390 try {
391 copiedClass = (T) this.getClass().newInstance();
392 } catch (Exception exception) {
393 throw new RuntimeException();
394 }
395
396 copyProperties(copiedClass);
397
398 return copiedClass;
399 }
400
401
402
403
404
405
406 protected <T> void copyProperties(T bindingInfo) {
407 super.copyProperties(bindingInfo);
408
409 BindingInfo bindingInfoCopy = (BindingInfo) bindingInfo;
410
411 bindingInfoCopy.setBindByNamePrefix(this.bindByNamePrefix);
412 bindingInfoCopy.setBindingName(this.bindingName);
413 bindingInfoCopy.setBindingObjectPath(this.bindingObjectPath);
414 bindingInfoCopy.setBindingPath(this.bindingPath);
415 bindingInfoCopy.setBindToForm(this.bindToForm);
416 bindingInfoCopy.setBindToMap(this.bindToMap);
417 bindingInfoCopy.setCollectionPath(this.collectionPath);
418 }
419 }