KickJava   Java API By Example, From Geeks To Geeks.

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


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: OzoneDocumentImpl.java,v 1.1 2003/11/02 18:10:03 per_nyfelt Exp $
8
package org.ozoneDB.xml.dom4j.o3impl;
9
10 import org.dom4j.*;
11 import org.ozoneDB.OzoneCompatible;
12 import org.ozoneDB.OzoneInterface;
13 import org.ozoneDB.OzoneRemote;
14 import org.ozoneDB.OzoneRemoteException;
15 import org.ozoneDB.xml.dom4j.OzoneBranch;
16 import org.ozoneDB.xml.dom4j.OzoneDocument;
17 import org.ozoneDB.xml.dom4j.OzoneDocumentFactory;
18
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 /**
23  *
24  * @author Per Nyfelt
25  */

26 public class OzoneDocumentImpl extends DefaultDocument implements OzoneDocument, OzoneCompatible {
27
28     final static long serialVersionUID = 1L;
29
30     private void init() {
31     }
32
33     public static OzoneDocument create(OzoneInterface db) {
34         return (OzoneDocument) db.createObject(OzoneDocumentImpl.class);
35     }
36
37     public OzoneDocumentImpl() {
38         init();
39     }
40
41     /** creates a named Document. Document name and object name should
42      * be the same here i think
43      **/

44     public static OzoneDocument create(OzoneInterface db, String JavaDoc name) {
45         return (OzoneDocument) db.createObject(OzoneDocumentImpl.class,
46                 OzoneInterface.Public,
47                 name,
48                 new Class JavaDoc[] {String JavaDoc.class},
49                 new Object JavaDoc[]{name});
50     }
51
52     public OzoneDocumentImpl(String JavaDoc name) {
53         super(name);
54         init();
55     }
56
57     public static OzoneDocument create(OzoneInterface db, Element rootElement) {
58         return (OzoneDocument) db.createObject(OzoneDocumentImpl.class,
59                 new Class JavaDoc[] {Element.class},
60                 new Object JavaDoc[]{rootElement});
61     }
62
63     public OzoneDocumentImpl(Element rootElement) {
64         super(rootElement);
65         init();
66     }
67
68
69     public static OzoneDocument create(OzoneInterface db, DocumentType docType) {
70         return (OzoneDocument) db.createObject(OzoneDocumentImpl.class,
71                 new Class JavaDoc[] {DocumentType.class},
72                 new Object JavaDoc[]{docType});
73     }
74
75     public OzoneDocumentImpl(DocumentType docType) {
76         super(docType);
77         init();
78     }
79
80     public static OzoneDocument create(OzoneInterface db, Element rootElement, DocumentType docType) {
81         final Class JavaDoc[] signature = new Class JavaDoc[] {Element.class, DocumentType.class};
82         return (OzoneDocument) db.createObject(OzoneDocumentImpl.class,
83                 signature,
84                 new Object JavaDoc[]{rootElement, docType});
85     }
86
87     public OzoneDocumentImpl(Element rootElement, DocumentType docType) {
88         super(rootElement, docType);
89         init();
90     }
91
92     public static OzoneDocument create(OzoneInterface db, String JavaDoc name, Element rootElement, DocumentType docType) {
93         final Class JavaDoc[] signature = new Class JavaDoc[] {Element.class, DocumentType.class, String JavaDoc.class};
94         return (OzoneDocument) db.createObject(OzoneDocumentImpl.class,
95                 signature,
96                 new Object JavaDoc[]{name, rootElement, docType});
97     }
98
99     public OzoneDocumentImpl(String JavaDoc name, Element rootElement, DocumentType docType) {
100         super(name, rootElement, docType);
101         init();
102     }
103
104     public DocumentFactory getDocumentFactory() {
105         throw new OzoneRemoteException("getDocumentFactory will not work in Ozone");
106     }
107
108     protected NodeFactory getNodeFactory() {
109         try {
110             // todo: might be faster to return super.getNodeFactory() if it is instanceof OzoneCompatible first
111
// before falling back to object for name look-up
112
return (NodeFactory) database().objectForName(OzoneDocumentFactory.OBJECT_NAME);
113         } catch (Exception JavaDoc e) {
114             throw new OzoneRemoteException("NodeFctory not registered" + e.toString());
115         }
116     }
117
118     protected XPathFactory getXPathFactory() {
119         try {
120             // todo: might be faster to return super.getXPathFactory() if it is instanceof OzoneCompatible first
121
// before falling back to object for name look-up
122
return (XPathFactory) database().objectForName(OzoneDocumentFactory.OBJECT_NAME);
123         } catch (Exception JavaDoc e) {
124             throw new OzoneRemoteException("XPathFactory not registered" + e.toString());
125         }
126     }
127
128     public List JavaDoc content() {
129         List JavaDoc backingList = contentList();
130         return new O3ContentListFacade((OzoneBranch) self(), backingList);
131     }
132
133     /** Called when an invalid node has been added.
134      * Throws an {@link org.dom4j.IllegalAddException}.
135      */

136     public void invalidNodeTypeAddException(Node node) {
137         super.invalidNodeTypeAddException(node);
138     }
139
140     /** Called when the given List content has been removed so
141      * each node should have its parent and document relationships
142      * cleared
143      */

144     public void contentRemoved() {
145         super.contentRemoved();
146     }
147
148     /** @return the text value of the given content object
149      * as text which returns the text value of CDATA, Entity or Text nodes
150      */

151     public String JavaDoc getContentAsText(Object JavaDoc content) {
152         return super.getContentAsText(content);
153     }
154
155     /** @return the XPath defined string-value of the given content object
156      */

157     public String JavaDoc getContentAsStringValue(Object JavaDoc content) {
158         return super.getContentAsStringValue(content);
159     }
160
161     /** @return the ID of the given <code>Element</code>
162      */

163     public String JavaDoc elementID(Element element) {
164         return super.elementID(element);
165     }
166
167     /** A Factory Method pattern which creates
168      * a List implementation used to store content
169      */

170     public List JavaDoc createContentList() {
171         return super.createContentList();
172     }
173
174     /** A Factory Method pattern which creates
175      * a List implementation used to store content
176      */

177     public List JavaDoc createContentList(int size) {
178         return super.createContentList(size);
179     }
180
181     /** A Factory Method pattern which creates
182      * a BackedList implementation used to store results of
183      * a filtered content query. */

184     public BackedList createResultList() {
185         return super.createResultList();
186     }
187
188     /** A Factory Method pattern which creates
189      * a BackedList implementation which contains a single result
190      */

191     public List JavaDoc createSingleResultList(Object JavaDoc result) {
192         return super.createSingleResultList(result);
193     }
194
195     /** A Factory Method pattern which creates an empty
196      * a BackedList implementation
197      */

198     public List JavaDoc createEmptyList() {
199         return super.createEmptyList();
200     }
201
202     public void childRemoved(Node node) {
203         super.childRemoved(node);
204     }
205
206     public void childAdded(Node node) {
207         super.childAdded(node);
208     }
209
210     public boolean removeNode(Node node) {
211         return super.removeNode(node);
212     }
213
214     public void addNode(Node node) {
215         super.addNode(node);
216     }
217
218     public List JavaDoc contentList() {
219         return super.contentList();
220     }
221
222     public void addNode(int index, Node node) {
223         super.addNode(index, node);
224     }
225
226     public Object JavaDoc clone() {
227         try {
228             System.out.println("OzoneDocumentImpl, cloning...");
229             // first get a copy of the document
230
Document document = (Document) database().copyObject(self());
231             // now we need to copy the content, otherwist all the content would be
232
// referenced fromn both documents
233
document.setRootElement(null);
234             document.setContent(null);
235             document.appendContent((Document) self());
236             return document;
237         } catch (Exception JavaDoc e) {
238             e.printStackTrace();
239             return null;
240         }
241     }
242
243     public void onCreate() {
244     }
245
246     public void onActivate() {
247     }
248
249     public void onPassivate() {
250     }
251
252     public void onDelete() {
253         OzoneInterface db = database();
254         DocumentType docType = getDocType();
255         if (docType != null && docType instanceof OzoneRemote) {
256             System.out.println("deleting doctype " + docType);
257             db.deleteObject((OzoneRemote) docType);
258         }
259         List JavaDoc contentList = content();
260         Object JavaDoc content;
261         for (Iterator JavaDoc it = contentList.iterator(); it.hasNext();) {
262             content = it.next();
263             if (content instanceof OzoneRemote) {
264                 db.deleteObject((OzoneRemote) content);
265             }
266         }
267     }
268
269 }
270
271
Popular Tags