1 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 ; 20 import java.util.List ; 21 22 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 44 public static OzoneDocument create(OzoneInterface db, String name) { 45 return (OzoneDocument) db.createObject(OzoneDocumentImpl.class, 46 OzoneInterface.Public, 47 name, 48 new Class [] {String .class}, 49 new Object []{name}); 50 } 51 52 public OzoneDocumentImpl(String 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 [] {Element.class}, 60 new Object []{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 [] {DocumentType.class}, 72 new Object []{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 [] signature = new Class [] {Element.class, DocumentType.class}; 82 return (OzoneDocument) db.createObject(OzoneDocumentImpl.class, 83 signature, 84 new Object []{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 name, Element rootElement, DocumentType docType) { 93 final Class [] signature = new Class [] {Element.class, DocumentType.class, String .class}; 94 return (OzoneDocument) db.createObject(OzoneDocumentImpl.class, 95 signature, 96 new Object []{name, rootElement, docType}); 97 } 98 99 public OzoneDocumentImpl(String 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 return (NodeFactory) database().objectForName(OzoneDocumentFactory.OBJECT_NAME); 113 } catch (Exception e) { 114 throw new OzoneRemoteException("NodeFctory not registered" + e.toString()); 115 } 116 } 117 118 protected XPathFactory getXPathFactory() { 119 try { 120 return (XPathFactory) database().objectForName(OzoneDocumentFactory.OBJECT_NAME); 123 } catch (Exception e) { 124 throw new OzoneRemoteException("XPathFactory not registered" + e.toString()); 125 } 126 } 127 128 public List content() { 129 List backingList = contentList(); 130 return new O3ContentListFacade((OzoneBranch) self(), backingList); 131 } 132 133 136 public void invalidNodeTypeAddException(Node node) { 137 super.invalidNodeTypeAddException(node); 138 } 139 140 144 public void contentRemoved() { 145 super.contentRemoved(); 146 } 147 148 151 public String getContentAsText(Object content) { 152 return super.getContentAsText(content); 153 } 154 155 157 public String getContentAsStringValue(Object content) { 158 return super.getContentAsStringValue(content); 159 } 160 161 163 public String elementID(Element element) { 164 return super.elementID(element); 165 } 166 167 170 public List createContentList() { 171 return super.createContentList(); 172 } 173 174 177 public List createContentList(int size) { 178 return super.createContentList(size); 179 } 180 181 184 public BackedList createResultList() { 185 return super.createResultList(); 186 } 187 188 191 public List createSingleResultList(Object result) { 192 return super.createSingleResultList(result); 193 } 194 195 198 public List 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 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 clone() { 227 try { 228 System.out.println("OzoneDocumentImpl, cloning..."); 229 Document document = (Document) database().copyObject(self()); 231 document.setRootElement(null); 234 document.setContent(null); 235 document.appendContent((Document) self()); 236 return document; 237 } catch (Exception 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 contentList = content(); 260 Object content; 261 for (Iterator 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 |