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.psml;
018:
019: import java.util.AbstractList;
020: import java.util.List;
021: import java.util.ListIterator;
022:
023: /**
024: * FragmentList
025: *
026: * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
027: * @version $Id$
028: */
029: class FilteredFragmentList extends AbstractList {
030: private FragmentImpl fragment;
031: private List filteredList;
032:
033: FilteredFragmentList(FragmentImpl fragment, List filteredList) {
034: super ();
035: this .fragment = fragment;
036: this .filteredList = filteredList;
037: }
038:
039: /* (non-Javadoc)
040: * @see java.util.List#add(int,java.lang.Object)
041: */
042: public void add(int index, Object element) {
043: // implement for modifiable AbstractList
044: filteredList.add(index, element);
045: // add object to persistent list
046: fragment.accessFragments().add(element);
047: // maintain page implementation reference
048: if ((fragment.getPage() != null)
049: && (element instanceof FragmentImpl)) {
050: ((FragmentImpl) element).setPage(fragment.getPage());
051: }
052: }
053:
054: /* (non-Javadoc)
055: * @see java.util.List#get(int)
056: */
057: public Object get(int index) {
058: // implement for modifiable AbstractList
059: return filteredList.get(index);
060: }
061:
062: /* (non-Javadoc)
063: * @see java.util.List#remove(int)
064: */
065: public Object remove(int index) {
066: // implement for modifiable AbstractList
067: Object o = filteredList.remove(index);
068: // remove removed object from persistent list
069: if (o != null) {
070: ListIterator iter = fragment.accessFragments()
071: .listIterator();
072: while (iter.hasNext()) {
073: if (iter.next() == o) {
074: iter.remove();
075: break;
076: }
077: }
078: }
079: return o;
080: }
081:
082: /* (non-Javadoc)
083: * @see java.util.List#set(int,java.lang.Object)
084: */
085: public Object set(int index, Object element) {
086: // implement for modifiable AbstractList
087: Object o = filteredList.set(index, element);
088: // replace replaced object in persistent list
089: if (o != null) {
090: ListIterator iter = fragment.accessFragments()
091: .listIterator();
092: while (iter.hasNext()) {
093: if (iter.next() == o) {
094: iter.set(element);
095: break;
096: }
097: }
098: }
099: // maintain page implementation reference
100: if ((fragment.getPage() != null)
101: && (element instanceof FragmentImpl)) {
102: ((FragmentImpl) element).setPage(fragment.getPage());
103: }
104: return o;
105: }
106:
107: /* (non-Javadoc)
108: * @see java.util.List#size()
109: */
110: public int size() {
111: // implement for modifiable AbstractList
112: return filteredList.size();
113: }
114: }
|