1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.om.page.impl;
18
19 import java.util.AbstractList;
20 import java.util.List;
21
22 import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
23
24 /***
25 * PageSecurityConstraintsRefList
26 *
27 * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
28 * @version $Id$
29 */
30 class PageSecurityConstraintsRefList extends AbstractList
31 {
32 private PageSecurityImpl pageSecurity;
33
34 private List removedConstraintsRefs;
35
36 PageSecurityConstraintsRefList(PageSecurityImpl pageSecurity)
37 {
38 super();
39 this.pageSecurity = pageSecurity;
40 }
41
42 /***
43 * wrapNameStringForAdd
44 *
45 * Wraps and validates constraints ref name string
46 * to be added to this list.
47 *
48 * @param name constraints ref name string to add
49 * @return list element to add
50 */
51 private PageSecurityGlobalSecurityConstraintsRef wrapNameStringForAdd(String name)
52 {
53
54 if (name == null)
55 {
56 throw new NullPointerException("Unable to add null to list.");
57 }
58
59 PageSecurityGlobalSecurityConstraintsRef constraintsRef = new PageSecurityGlobalSecurityConstraintsRef();
60 constraintsRef.setName(name);
61
62 if (pageSecurity.accessGlobalConstraintsRefs().contains(constraintsRef))
63 {
64 throw new IllegalArgumentException("Unable to add duplicate entry to list: " + constraintsRef.getName());
65 }
66
67
68 if (removedConstraintsRefs != null)
69 {
70 int removedIndex = removedConstraintsRefs.indexOf(constraintsRef);
71 if (removedIndex >= 0)
72 {
73 constraintsRef = (PageSecurityGlobalSecurityConstraintsRef)removedConstraintsRefs.remove(removedIndex);
74 }
75 }
76 return constraintsRef;
77 }
78
79 /***
80 * getRemovedConstraintsRefs
81 *
82 * @return removed constraints refs tracking collection
83 */
84 private List getRemovedConstraintsRefs()
85 {
86 if (removedConstraintsRefs == null)
87 {
88 removedConstraintsRefs = DatabasePageManagerUtils.createList();
89 }
90 return removedConstraintsRefs;
91 }
92
93
94
95
96 public void add(int index, Object element)
97 {
98
99
100 if ((index < 0) || (index > pageSecurity.accessGlobalConstraintsRefs().size()))
101 {
102 throw new IndexOutOfBoundsException("Unable to add to list at index: " + index);
103 }
104
105 PageSecurityGlobalSecurityConstraintsRef constraintsRef = wrapNameStringForAdd((String)element);
106
107 pageSecurity.accessGlobalConstraintsRefs().add(index, constraintsRef);
108
109 if (index > 0)
110 {
111 constraintsRef.setApplyOrder(((PageSecurityGlobalSecurityConstraintsRef)pageSecurity.accessGlobalConstraintsRefs().get(index-1)).getApplyOrder() + 1);
112 }
113 else
114 {
115 constraintsRef.setApplyOrder(0);
116 }
117
118 for (int i = index, limit = pageSecurity.accessGlobalConstraintsRefs().size() - 1; (i < limit); i++)
119 {
120 PageSecurityGlobalSecurityConstraintsRef nextConstraintsRef = (PageSecurityGlobalSecurityConstraintsRef)pageSecurity.accessGlobalConstraintsRefs().get(i + 1);
121 if (nextConstraintsRef.getApplyOrder() <= constraintsRef.getApplyOrder())
122 {
123
124 nextConstraintsRef.setApplyOrder(constraintsRef.getApplyOrder() + 1);
125 constraintsRef = nextConstraintsRef;
126 }
127 else
128 {
129
130 break;
131 }
132 }
133 }
134
135
136
137
138 public Object get(int index)
139 {
140
141
142 return ((PageSecurityGlobalSecurityConstraintsRef)pageSecurity.accessGlobalConstraintsRefs().get(index)).getName();
143 }
144
145
146
147
148 public Object remove(int index)
149 {
150
151
152 PageSecurityGlobalSecurityConstraintsRef removed = (PageSecurityGlobalSecurityConstraintsRef)pageSecurity.accessGlobalConstraintsRefs().remove(index);
153 if (removed != null)
154 {
155 getRemovedConstraintsRefs().add(removed);
156 }
157 return removed;
158 }
159
160
161
162
163 public Object set(int index, Object element)
164 {
165
166
167 PageSecurityGlobalSecurityConstraintsRef newConstraintsRef = wrapNameStringForAdd((String)element);
168
169 PageSecurityGlobalSecurityConstraintsRef constraintsRef = (PageSecurityGlobalSecurityConstraintsRef)pageSecurity.accessGlobalConstraintsRefs().set(index, newConstraintsRef);
170
171 newConstraintsRef.setApplyOrder(constraintsRef.getApplyOrder());
172
173 getRemovedConstraintsRefs().add(constraintsRef);
174
175 return constraintsRef.getName();
176 }
177
178
179
180
181 public int size()
182 {
183
184 return pageSecurity.accessGlobalConstraintsRefs().size();
185 }
186 }