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
21 /***
22 * SecurityConstraintDefList
23 *
24 * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
25 * @version $Id$
26 */
27 class SecurityConstraintDefList extends AbstractList
28 {
29 private SecurityConstraintsDefImpl constraintsDef;
30
31 SecurityConstraintDefList(SecurityConstraintsDefImpl constraintsDef)
32 {
33 super();
34 this.constraintsDef = constraintsDef;
35 }
36
37 /***
38 * validateConstraintForAdd
39 *
40 * Validates constraint to be added to this list.
41 *
42 * @param constraint constraint to add
43 * @return list element to add
44 */
45 private PageSecuritySecurityConstraintImpl validateConstraintForAdd(PageSecuritySecurityConstraintImpl constraint)
46 {
47
48 if (constraint == null)
49 {
50 throw new NullPointerException("Unable to add null to list.");
51 }
52 return constraint;
53 }
54
55
56
57
58 public void add(int index, Object element)
59 {
60
61
62 if ((index < 0) || (index > constraintsDef.accessConstraintDefs().size()))
63 {
64 throw new IndexOutOfBoundsException("Unable to add to list at index: " + index);
65 }
66
67 PageSecuritySecurityConstraintImpl constraint = validateConstraintForAdd((PageSecuritySecurityConstraintImpl)element);
68
69 constraintsDef.accessConstraintDefs().add(index, constraint);
70
71 if (index > 0)
72 {
73 constraint.setApplyOrder(((PageSecuritySecurityConstraintImpl)constraintsDef.accessConstraintDefs().get(index-1)).getApplyOrder() + 1);
74 }
75 else
76 {
77 constraint.setApplyOrder(0);
78 }
79
80 for (int i = index, limit = constraintsDef.accessConstraintDefs().size() - 1; (i < limit); i++)
81 {
82 PageSecuritySecurityConstraintImpl nextConstraint = (PageSecuritySecurityConstraintImpl)constraintsDef.accessConstraintDefs().get(i + 1);
83 if (nextConstraint.getApplyOrder() <= constraint.getApplyOrder())
84 {
85
86 nextConstraint.setApplyOrder(constraint.getApplyOrder() + 1);
87 constraint = nextConstraint;
88 }
89 else
90 {
91
92 break;
93 }
94 }
95 }
96
97
98
99
100 public Object get(int index)
101 {
102
103 return constraintsDef.accessConstraintDefs().get(index);
104 }
105
106
107
108
109 public Object remove(int index)
110 {
111
112 return constraintsDef.accessConstraintDefs().remove(index);
113 }
114
115
116
117
118 public Object set(int index, Object element)
119 {
120
121
122 PageSecuritySecurityConstraintImpl newConstraint = validateConstraintForAdd((PageSecuritySecurityConstraintImpl)element);
123
124 PageSecuritySecurityConstraintImpl constraint = (PageSecuritySecurityConstraintImpl)constraintsDef.accessConstraintDefs().set(index, newConstraint);
125
126 newConstraint.setApplyOrder(constraint.getApplyOrder());
127
128 return constraint;
129 }
130
131
132
133
134 public int size()
135 {
136
137 return constraintsDef.accessConstraintDefs().size();
138 }
139 }