KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > dom4j > o3impl > O3ContentListFacade


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 JavaDoc;
8 import java.util.Collection JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.List JavaDoc;
11
12 /**
13  * $Id: O3ContentListFacade.java,v 1.1 2003/07/07 10:30:29 per_nyfelt Exp $
14  */

15 public class O3ContentListFacade extends ContentListFacade implements Serializable JavaDoc {
16
17     static final long serialVersionUID = 1L;
18
19     /** The content of the Branch which is modified if I am modified */
20     private List JavaDoc branchContent;
21
22     /** The <code>AbstractBranch</code> instance which owns the content */
23     private OzoneBranch branch;
24
25
26     public O3ContentListFacade(OzoneBranch branch, List JavaDoc branchContent) {
27         this.branch = branch;
28         this.branchContent = branchContent;
29     }
30
31     public boolean add(Object JavaDoc object) {
32         branch.childAdded(asNode(object));
33         return branchContent.add(object);
34     }
35
36     public void add(int index, Object JavaDoc object) {
37         branch.childAdded(asNode(object));
38         branchContent.add(index, object);
39     }
40
41     public Object JavaDoc set(int index, Object JavaDoc object) {
42         branch.childAdded(asNode(object));
43         return branchContent.set(index, object);
44     }
45
46     public boolean remove(Object JavaDoc object) {
47         branch.childRemoved(asNode(object));
48         return branchContent.remove(object);
49     }
50
51     public Object JavaDoc remove(int index) {
52         Object JavaDoc object = branchContent.remove(index);
53         if (object != null) {
54             branch.childRemoved(asNode(object));
55         }
56         return object;
57     }
58
59     public boolean addAll(Collection JavaDoc collection) {
60         int count = branchContent.size();
61         for (Iterator JavaDoc 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 JavaDoc collection) {
68         int count = branchContent.size();
69         for (Iterator JavaDoc 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 JavaDoc iter = iterator(); iter.hasNext();) {
77             Object JavaDoc object = iter.next();
78             branch.childRemoved(asNode(object));
79         }
80         branchContent.clear();
81     }
82
83     public boolean removeAll(Collection JavaDoc c) {
84         for (Iterator JavaDoc iter = c.iterator(); iter.hasNext();) {
85             Object JavaDoc 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 JavaDoc o) {
100         return branchContent.contains(o);
101     }
102
103     public Object JavaDoc[] toArray() {
104         return branchContent.toArray();
105     }
106
107     public Object JavaDoc[] toArray(Object JavaDoc[] a) {
108         return branchContent.toArray(a);
109     }
110
111     public boolean containsAll(Collection JavaDoc c) {
112         return branchContent.containsAll(c);
113     }
114
115     public Object JavaDoc get(int index) {
116         return branchContent.get(index);
117     }
118
119     public int indexOf(Object JavaDoc o) {
120         return branchContent.indexOf(o);
121     }
122
123     public int lastIndexOf(Object JavaDoc o) {
124         return branchContent.lastIndexOf(o);
125     }
126
127     protected Node asNode(Object JavaDoc 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 JavaDoc getBackingList() {
136         return branchContent;
137     }
138 }
139
140
141 /*
142  * Redistribution and use of this software and associated documentation
143  * ("Software"), with or without modification, are permitted provided
144  * that the following conditions are met:
145  *
146  * 1. Redistributions of source code must retain copyright
147  * statements and notices. Redistributions must also contain a
148  * copy of this document.
149  *
150  * 2. Redistributions in binary form must reproduce the
151  * above copyright notice, this list of conditions and the
152  * following disclaimer in the documentation and/or other
153  * materials provided with the distribution.
154  *
155  * 3. The name "DOM4J" must not be used to endorse or promote
156  * products derived from this Software without prior written
157  * permission of MetaStuff, Ltd. For written permission,
158  * please contact dom4j-info@metastuff.com.
159  *
160  * 4. Products derived from this Software may not be called "DOM4J"
161  * nor may "DOM4J" appear in their names without prior written
162  * permission of MetaStuff, Ltd. DOM4J is a registered
163  * trademark of MetaStuff, Ltd.
164  *
165  * 5. Due credit should be given to the DOM4J Project
166  * (http://dom4j.org/).
167  *
168  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
169  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
170  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
171  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
172  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
173  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
174  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
175  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
176  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
177  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
178  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
179  * OF THE POSSIBILITY OF SUCH DAMAGE.
180  *
181  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
182  *
183  * $Id: O3ContentListFacade.java,v 1.1 2003/07/07 10:30:29 per_nyfelt Exp $
184  */

185
Popular Tags