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