1 9 10 package org.ozoneDB.xml.dom4j.o3impl; 11 12 import org.dom4j.IllegalAddException; 13 import org.dom4j.Node; 14 15 import java.util.AbstractList ; 16 import java.util.Collection ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 20 31 public class ContentListFacade extends AbstractList { 32 33 34 private List branchContent; 35 36 37 private AbstractBranch branch; 38 39 protected ContentListFacade() { 40 } 41 42 public ContentListFacade(AbstractBranch branch, List branchContent) { 43 this.branch = branch; 44 this.branchContent = branchContent; 45 } 46 47 public boolean add(Object object) { 48 branch.childAdded(asNode(object)); 49 return branchContent.add(object); 50 } 51 52 public void add(int index, Object object) { 53 branch.childAdded(asNode(object)); 54 branchContent.add(index, object); 55 } 56 57 public Object set(int index, Object object) { 58 branch.childAdded(asNode(object)); 59 return branchContent.set(index, object); 60 } 61 62 public boolean remove(Object object) { 63 branch.childRemoved(asNode(object)); 64 return branchContent.remove(object); 65 } 66 67 public Object remove(int index) { 68 Object object = branchContent.remove(index); 69 if (object != null) { 70 branch.childRemoved(asNode(object)); 71 } 72 return object; 73 } 74 75 public boolean addAll(Collection collection) { 76 int count = branchContent.size(); 77 for (Iterator iter = collection.iterator(); iter.hasNext(); count++) { 78 add(iter.next()); 79 } 80 return count == branchContent.size(); 81 } 82 83 public boolean addAll(int index, Collection collection) { 84 int count = branchContent.size(); 85 for (Iterator iter = collection.iterator(); iter.hasNext(); count--) { 86 add(index++, iter.next()); 87 } 88 return count == branchContent.size(); 89 } 90 91 public void clear() { 92 for (Iterator iter = iterator(); iter.hasNext();) { 93 Object object = iter.next(); 94 branch.childRemoved(asNode(object)); 95 } 96 branchContent.clear(); 97 } 98 99 public boolean removeAll(Collection c) { 100 for (Iterator iter = c.iterator(); iter.hasNext();) { 101 Object object = iter.next(); 102 branch.childRemoved(asNode(object)); 103 } 104 return branchContent.removeAll(c); 105 } 106 107 public int size() { 108 return branchContent.size(); 109 } 110 111 public boolean isEmpty() { 112 return branchContent.isEmpty(); 113 } 114 115 public boolean contains(Object o) { 116 return branchContent.contains(o); 117 } 118 119 public Object [] toArray() { 120 return branchContent.toArray(); 121 } 122 123 public Object [] toArray(Object [] a) { 124 return branchContent.toArray(a); 125 } 126 127 public boolean containsAll(Collection c) { 128 return branchContent.containsAll(c); 129 } 130 131 public Object get(int index) { 132 return branchContent.get(index); 133 } 134 135 public int indexOf(Object o) { 136 return branchContent.indexOf(o); 137 } 138 139 public int lastIndexOf(Object o) { 140 return branchContent.lastIndexOf(o); 141 } 142 143 protected Node asNode(Object object) { 144 if (object instanceof Node) { 145 return (Node) object; 146 } else { 147 throw new IllegalAddException("This list must contain instances of Node. Invalid type: " + object); 148 } 149 } 150 151 protected List getBackingList() { 152 return branchContent; 153 } 154 } 155 156 157 201 | Popular Tags |