%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.om.page.impl.SecurityConstraintsRefList |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
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 | * SecurityConstraintsRefList |
|
26 | * |
|
27 | * @author <a href="mailto:rwatler@apache.org">Randy Watler</a> |
|
28 | * @version $Id$ |
|
29 | */ |
|
30 | class SecurityConstraintsRefList extends AbstractList |
|
31 | { |
|
32 | private SecurityConstraintsImpl constraints; |
|
33 | ||
34 | private List removedConstraintsRefs; |
|
35 | ||
36 | SecurityConstraintsRefList(SecurityConstraintsImpl constraints) |
|
37 | { |
|
38 | 0 | super(); |
39 | 0 | this.constraints = constraints; |
40 | 0 | } |
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 BaseSecurityConstraintsRef wrapNameStringForAdd(String name) |
|
52 | { |
|
53 | // only non-null names supported |
|
54 | 0 | if (name == null) |
55 | { |
|
56 | 0 | throw new NullPointerException("Unable to add null to list."); |
57 | } |
|
58 | // wrap constraints ref name string; use |
|
59 | // specific constraints ref name string wrapper |
|
60 | 0 | BaseSecurityConstraintsRef constraintsRef = null; |
61 | 0 | if (constraints.getSecurityConstraintsRefClass() != null) |
62 | { |
|
63 | try |
|
64 | { |
|
65 | 0 | constraintsRef = (BaseSecurityConstraintsRef)constraints.getSecurityConstraintsRefClass().newInstance(); |
66 | } |
|
67 | 0 | catch (InstantiationException ie) |
68 | { |
|
69 | 0 | throw new ClassCastException("Unable to create constratins reference list element instance: " + constraints.getSecurityConstraintsRefClass().getName() + ", (" + ie + ")."); |
70 | } |
|
71 | 0 | catch (IllegalAccessException iae) |
72 | { |
|
73 | 0 | throw new ClassCastException("Unable to create constraints reference list element instance: " + constraints.getSecurityConstraintsRefClass().getName() + ", (" + iae + ")."); |
74 | 0 | } |
75 | } |
|
76 | else |
|
77 | { |
|
78 | 0 | constraintsRef = new BaseSecurityConstraintsRef(); |
79 | } |
|
80 | 0 | constraintsRef.setName(name); |
81 | // make sure element is unique |
|
82 | 0 | if (constraints.accessConstraintsRefs().contains(constraintsRef)) |
83 | { |
|
84 | 0 | throw new IllegalArgumentException("Unable to add duplicate entry to list: " + constraintsRef.getName()); |
85 | } |
|
86 | // retrieve from removed list to reuse |
|
87 | // previously removed element |
|
88 | 0 | if (removedConstraintsRefs != null) |
89 | { |
|
90 | 0 | int removedIndex = removedConstraclass="keyword">intsRefs.indexOf(constraclass="keyword">intsRef); |
91 | 0 | if (removedIndex >= 0) |
92 | { |
|
93 | 0 | constraintsRef = (BaseSecurityConstraintsRef)removedConstraintsRefs.remove(removedIndex); |
94 | } |
|
95 | } |
|
96 | 0 | return constraintsRef; |
97 | } |
|
98 | ||
99 | /** |
|
100 | * getRemovedConstraintsRefs |
|
101 | * |
|
102 | * @return removed constraints refs tracking collection |
|
103 | */ |
|
104 | private List getRemovedConstraintsRefs() |
|
105 | { |
|
106 | 0 | if (removedConstraintsRefs == null) |
107 | { |
|
108 | 0 | removedConstraintsRefs = DatabasePageManagerUtils.createList(); |
109 | } |
|
110 | 0 | return removedConstraintsRefs; |
111 | } |
|
112 | ||
113 | /* (non-Javadoc) |
|
114 | * @see java.util.List#add(int,java.lang.Object) |
|
115 | */ |
|
116 | public void add(int index, Object element) |
|
117 | { |
|
118 | // implement for modifiable AbstractList: |
|
119 | // validate index |
|
120 | 0 | if ((index < 0) || (index > constraints.accessConstraintsRefs().size())) |
121 | { |
|
122 | 0 | throw new IndexOutOfBoundsException("Unable to add to list at index: " + index); |
123 | } |
|
124 | // wrap and verify constraints ref name string |
|
125 | 0 | BaseSecurityConstraintsRef constraintsRef = wrapNameStringForAdd((String)element); |
126 | // add to underlying ordered list |
|
127 | 0 | constraints.accessConstraintsRefs().add(index, constraintsRef); |
128 | // set apply order in added element |
|
129 | 0 | if (index > 0) |
130 | { |
|
131 | 0 | constraintsRef.setApplyOrder(((BaseSecurityConstraintsRef)constraints.accessConstraintsRefs().get(index-1)).getApplyOrder() + 1); |
132 | } |
|
133 | else |
|
134 | { |
|
135 | 0 | constraintsRef.setApplyOrder(0); |
136 | } |
|
137 | // maintain apply order in subsequent elements |
|
138 | 0 | for (int i = index, limit = constraclass="keyword">ints.accessConstraclass="keyword">intsRefs().size() - 1; (i < limit); i++) |
139 | { |
|
140 | 0 | BaseSecurityConstraintsRef nextConstraintsRef = (BaseSecurityConstraintsRef)constraints.accessConstraintsRefs().get(i + 1); |
141 | 0 | if (nextConstraintsRef.getApplyOrder() <= constraintsRef.getApplyOrder()) |
142 | { |
|
143 | // adjust apply order for next element |
|
144 | 0 | nextConstraintsRef.setApplyOrder(constraintsRef.getApplyOrder() + 1); |
145 | 0 | constraintsRef = nextConstraintsRef; |
146 | } |
|
147 | else |
|
148 | { |
|
149 | // apply order maintained for remaining list elements |
|
150 | break; |
|
151 | } |
|
152 | } |
|
153 | // clear all cached security constraints |
|
154 | 0 | constraints.clearAllSecurityConstraints(); |
155 | 0 | } |
156 | ||
157 | /* (non-Javadoc) |
|
158 | * @see java.util.List#get(int) |
|
159 | */ |
|
160 | public Object get(int index) |
|
161 | { |
|
162 | // implement for modifiable AbstractList: |
|
163 | // unwrap constraints ref name string |
|
164 | 0 | return ((BaseSecurityConstraintsRef)constraints.accessConstraintsRefs().get(index)).getName(); |
165 | } |
|
166 | ||
167 | /* (non-Javadoc) |
|
168 | * @see java.util.List#remove(int) |
|
169 | */ |
|
170 | public Object remove(int index) |
|
171 | { |
|
172 | // implement for modifiable AbstractList |
|
173 | 0 | BaseSecurityConstraintsRef removed = (BaseSecurityConstraintsRef)constraints.accessConstraintsRefs().remove(index); |
174 | 0 | if (removed != null) |
175 | { |
|
176 | // save removed element |
|
177 | 0 | getRemovedConstraintsRefs().add(removed); |
178 | // clear all cached security constraints |
|
179 | 0 | constraints.clearAllSecurityConstraints(); |
180 | } |
|
181 | 0 | return removed; |
182 | } |
|
183 | ||
184 | /* (non-Javadoc) |
|
185 | * @see java.util.List#set(int,java.lang.Object) |
|
186 | */ |
|
187 | public Object set(int index, Object element) |
|
188 | { |
|
189 | // implement for modifiable AbstractList: |
|
190 | // wrap and verify constraints ref name string |
|
191 | 0 | BaseSecurityConstraintsRef newConstraintsRef = wrapNameStringForAdd((String)element); |
192 | // set in underlying ordered list |
|
193 | 0 | BaseSecurityConstraintsRef constraintsRef = (BaseSecurityConstraintsRef)constraints.accessConstraintsRefs().set(index, newConstraintsRef); |
194 | // set apply order in new element |
|
195 | 0 | newConstraintsRef.setApplyOrder(constraintsRef.getApplyOrder()); |
196 | // save replaced element |
|
197 | 0 | getRemovedConstraintsRefs().add(constraintsRef); |
198 | // clear all cached security constraints |
|
199 | 0 | constraints.clearAllSecurityConstraints(); |
200 | // return unwrapped constraints ref name string |
|
201 | 0 | return constraintsRef.getName(); |
202 | } |
|
203 | ||
204 | /* (non-Javadoc) |
|
205 | * @see java.util.List#size() |
|
206 | */ |
|
207 | public int size() |
|
208 | { |
|
209 | // implement for modifiable AbstractList |
|
210 | 0 | return constraints.accessConstraintsRefs().size(); |
211 | } |
|
212 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |