001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.om.page.impl;
018:
019: import java.util.AbstractList;
020:
021: /**
022: * SecurityConstraintDefList
023: *
024: * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
025: * @version $Id$
026: */
027: class SecurityConstraintDefList extends AbstractList {
028: private SecurityConstraintsDefImpl constraintsDef;
029:
030: SecurityConstraintDefList(SecurityConstraintsDefImpl constraintsDef) {
031: super ();
032: this .constraintsDef = constraintsDef;
033: }
034:
035: /**
036: * validateConstraintForAdd
037: *
038: * Validates constraint to be added to this list.
039: *
040: * @param constraint constraint to add
041: * @return list element to add
042: */
043: private PageSecuritySecurityConstraintImpl validateConstraintForAdd(
044: PageSecuritySecurityConstraintImpl constraint) {
045: // validate constraint instance class
046: if (constraint == null) {
047: throw new NullPointerException(
048: "Unable to add null to list.");
049: }
050: return constraint;
051: }
052:
053: /* (non-Javadoc)
054: * @see java.util.List#add(int,java.lang.Object)
055: */
056: public void add(int index, Object element) {
057: // implement for modifiable AbstractList:
058: // validate index
059: if ((index < 0)
060: || (index > constraintsDef.accessConstraintDefs()
061: .size())) {
062: throw new IndexOutOfBoundsException(
063: "Unable to add to list at index: " + index);
064: }
065: // verify constraint
066: PageSecuritySecurityConstraintImpl constraint = validateConstraintForAdd((PageSecuritySecurityConstraintImpl) element);
067: // add to underlying ordered list
068: constraintsDef.accessConstraintDefs().add(index, constraint);
069: // set apply order in added element
070: if (index > 0) {
071: constraint
072: .setApplyOrder(((PageSecuritySecurityConstraintImpl) constraintsDef
073: .accessConstraintDefs().get(index - 1))
074: .getApplyOrder() + 1);
075: } else {
076: constraint.setApplyOrder(0);
077: }
078: // maintain apply order in subsequent elements
079: for (int i = index, limit = constraintsDef
080: .accessConstraintDefs().size() - 1; (i < limit); i++) {
081: PageSecuritySecurityConstraintImpl nextConstraint = (PageSecuritySecurityConstraintImpl) constraintsDef
082: .accessConstraintDefs().get(i + 1);
083: if (nextConstraint.getApplyOrder() <= constraint
084: .getApplyOrder()) {
085: // adjust apply order for next element
086: nextConstraint
087: .setApplyOrder(constraint.getApplyOrder() + 1);
088: constraint = nextConstraint;
089: } else {
090: // apply order maintained for remaining list elements
091: break;
092: }
093: }
094: }
095:
096: /* (non-Javadoc)
097: * @see java.util.List#get(int)
098: */
099: public Object get(int index) {
100: // implement for modifiable AbstractList
101: return constraintsDef.accessConstraintDefs().get(index);
102: }
103:
104: /* (non-Javadoc)
105: * @see java.util.List#remove(int)
106: */
107: public Object remove(int index) {
108: // implement for modifiable AbstractList
109: return constraintsDef.accessConstraintDefs().remove(index);
110: }
111:
112: /* (non-Javadoc)
113: * @see java.util.List#set(int,java.lang.Object)
114: */
115: public Object set(int index, Object element) {
116: // implement for modifiable AbstractList:
117: // verify constraint
118: PageSecuritySecurityConstraintImpl newConstraint = validateConstraintForAdd((PageSecuritySecurityConstraintImpl) element);
119: // set in underlying ordered list
120: PageSecuritySecurityConstraintImpl constraint = (PageSecuritySecurityConstraintImpl) constraintsDef
121: .accessConstraintDefs().set(index, newConstraint);
122: // set apply order in new element
123: newConstraint.setApplyOrder(constraint.getApplyOrder());
124: // return constraint
125: return constraint;
126: }
127:
128: /* (non-Javadoc)
129: * @see java.util.List#size()
130: */
131: public int size() {
132: // implement for modifiable AbstractList
133: return constraintsDef.accessConstraintDefs().size();
134: }
135: }
|