1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.datadictionary.impl; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
import org.kuali.rice.kns.datadictionary.FieldOverride; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 0 | public class FieldOverrideForListElementInsertImpl extends FieldOverrideForListElementBase implements FieldOverride{ |
29 | |
|
30 | |
private Object insertBefore; |
31 | |
private Object insertAfter; |
32 | |
|
33 | |
public Object getInsertBefore() { |
34 | 0 | return insertBefore; |
35 | |
} |
36 | |
|
37 | |
public void setInsertBefore(Object insertBefore) { |
38 | 0 | this.insertBefore = insertBefore; |
39 | 0 | } |
40 | |
|
41 | |
public Object getInsertAfter() { |
42 | 0 | return insertAfter; |
43 | |
} |
44 | |
|
45 | |
|
46 | |
public void setInsertAfter(Object insertAfter) { |
47 | 0 | this.insertAfter = insertAfter; |
48 | 0 | } |
49 | |
|
50 | |
|
51 | |
protected void varifyConfig() |
52 | |
{ |
53 | 0 | if ( insertBefore != null && insertAfter != null ) |
54 | |
{ |
55 | 0 | throw new RuntimeException("Configuration Error, insertBefore and insertAfter can not be both NOT-NULL"); |
56 | |
} |
57 | 0 | if ( insertBefore == null && insertAfter == null ) |
58 | |
{ |
59 | 0 | throw new RuntimeException("Configuration Error, Either insertBefore or insertAfter should be NOT-NULL"); |
60 | |
} |
61 | 0 | } |
62 | |
|
63 | |
private Object getObjectToInsert() |
64 | |
{ |
65 | 0 | Object objToInsert = null; |
66 | 0 | if ( insertBefore != null ) |
67 | |
{ |
68 | 0 | objToInsert = insertBefore; |
69 | |
} |
70 | 0 | if ( insertAfter != null ) |
71 | |
{ |
72 | 0 | if ( objToInsert != null ) |
73 | |
{ |
74 | 0 | throw new RuntimeException("Configuration Error, insertBefore and insertAfter can not be both NOT-NULL"); |
75 | |
} |
76 | 0 | objToInsert = insertAfter; |
77 | |
} |
78 | 0 | if ( objToInsert == null ) |
79 | |
{ |
80 | 0 | throw new RuntimeException("Configuration Error, Either insertBefore or insertAfter must be NOT-NULL"); |
81 | |
} |
82 | 0 | return objToInsert; |
83 | |
} |
84 | |
|
85 | |
public Object performFieldOverride(Object bean, Object property) { |
86 | 0 | Object objToInsert = getObjectToInsert(); |
87 | |
|
88 | 0 | List oldList = (List)property; |
89 | |
|
90 | 0 | int insertPos = getElementPositionInList(getElement(), oldList); |
91 | |
|
92 | 0 | if ( insertPos == -1 ) |
93 | |
{ |
94 | 0 | insertPos = oldList.size(); |
95 | |
} |
96 | |
else |
97 | |
{ |
98 | 0 | if ( insertAfter != null ) |
99 | |
{ |
100 | 0 | insertPos = insertPos + 1; |
101 | |
} |
102 | |
} |
103 | |
|
104 | 0 | if ( objToInsert instanceof List ) |
105 | |
{ |
106 | 0 | oldList.addAll(insertPos, (List)objToInsert); |
107 | |
} |
108 | |
else |
109 | |
{ |
110 | 0 | oldList.add(insertPos, objToInsert); |
111 | |
} |
112 | 0 | return oldList; |
113 | |
} |
114 | |
} |