📄 ozonedocumentimpl.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id: OzoneDocumentImpl.java,v 1.1 2003/11/02 18:10:03 per_nyfelt Exp $package org.ozoneDB.xml.dom4j.o3impl;import org.dom4j.*;import org.ozoneDB.OzoneCompatible;import org.ozoneDB.OzoneInterface;import org.ozoneDB.OzoneRemote;import org.ozoneDB.OzoneRemoteException;import org.ozoneDB.xml.dom4j.OzoneBranch;import org.ozoneDB.xml.dom4j.OzoneDocument;import org.ozoneDB.xml.dom4j.OzoneDocumentFactory;import java.util.Iterator;import java.util.List;/** * * @author Per Nyfelt */public class OzoneDocumentImpl extends DefaultDocument implements OzoneDocument, OzoneCompatible { final static long serialVersionUID = 1L; private void init() { } public static OzoneDocument create(OzoneInterface db) { return (OzoneDocument) db.createObject(OzoneDocumentImpl.class); } public OzoneDocumentImpl() { init(); } /** creates a named Document. Document name and object name should * be the same here i think **/ public static OzoneDocument create(OzoneInterface db, String name) { return (OzoneDocument) db.createObject(OzoneDocumentImpl.class, OzoneInterface.Public, name, new Class[] {String.class}, new Object[]{name}); } public OzoneDocumentImpl(String name) { super(name); init(); } public static OzoneDocument create(OzoneInterface db, Element rootElement) { return (OzoneDocument) db.createObject(OzoneDocumentImpl.class, new Class[] {Element.class}, new Object[]{rootElement}); } public OzoneDocumentImpl(Element rootElement) { super(rootElement); init(); } public static OzoneDocument create(OzoneInterface db, DocumentType docType) { return (OzoneDocument) db.createObject(OzoneDocumentImpl.class, new Class[] {DocumentType.class}, new Object[]{docType}); } public OzoneDocumentImpl(DocumentType docType) { super(docType); init(); } public static OzoneDocument create(OzoneInterface db, Element rootElement, DocumentType docType) { final Class[] signature = new Class[] {Element.class, DocumentType.class}; return (OzoneDocument) db.createObject(OzoneDocumentImpl.class, signature, new Object[]{rootElement, docType}); } public OzoneDocumentImpl(Element rootElement, DocumentType docType) { super(rootElement, docType); init(); } public static OzoneDocument create(OzoneInterface db, String name, Element rootElement, DocumentType docType) { final Class[] signature = new Class[] {Element.class, DocumentType.class, String.class}; return (OzoneDocument) db.createObject(OzoneDocumentImpl.class, signature, new Object[]{name, rootElement, docType}); } public OzoneDocumentImpl(String name, Element rootElement, DocumentType docType) { super(name, rootElement, docType); init(); } public DocumentFactory getDocumentFactory() { throw new OzoneRemoteException("getDocumentFactory will not work in Ozone"); } protected NodeFactory getNodeFactory() { try { // todo: might be faster to return super.getNodeFactory() if it is instanceof OzoneCompatible first // before falling back to object for name look-up return (NodeFactory) database().objectForName(OzoneDocumentFactory.OBJECT_NAME); } catch (Exception e) { throw new OzoneRemoteException("NodeFctory not registered" + e.toString()); } } protected XPathFactory getXPathFactory() { try { // todo: might be faster to return super.getXPathFactory() if it is instanceof OzoneCompatible first // before falling back to object for name look-up return (XPathFactory) database().objectForName(OzoneDocumentFactory.OBJECT_NAME); } catch (Exception e) { throw new OzoneRemoteException("XPathFactory not registered" + e.toString()); } } public List content() { List backingList = contentList(); return new O3ContentListFacade((OzoneBranch) self(), backingList); } /** Called when an invalid node has been added. * Throws an {@link org.dom4j.IllegalAddException}. */ public void invalidNodeTypeAddException(Node node) { super.invalidNodeTypeAddException(node); } /** Called when the given List content has been removed so * each node should have its parent and document relationships * cleared */ public void contentRemoved() { super.contentRemoved(); } /** @return the text value of the given content object * as text which returns the text value of CDATA, Entity or Text nodes */ public String getContentAsText(Object content) { return super.getContentAsText(content); } /** @return the XPath defined string-value of the given content object */ public String getContentAsStringValue(Object content) { return super.getContentAsStringValue(content); } /** @return the ID of the given <code>Element</code> */ public String elementID(Element element) { return super.elementID(element); } /** A Factory Method pattern which creates * a List implementation used to store content */ public List createContentList() { return super.createContentList(); } /** A Factory Method pattern which creates * a List implementation used to store content */ public List createContentList(int size) { return super.createContentList(size); } /** A Factory Method pattern which creates * a BackedList implementation used to store results of * a filtered content query. */ public BackedList createResultList() { return super.createResultList(); } /** A Factory Method pattern which creates * a BackedList implementation which contains a single result */ public List createSingleResultList(Object result) { return super.createSingleResultList(result); } /** A Factory Method pattern which creates an empty * a BackedList implementation */ public List createEmptyList() { return super.createEmptyList(); } public void childRemoved(Node node) { super.childRemoved(node); } public void childAdded(Node node) { super.childAdded(node); } public boolean removeNode(Node node) { return super.removeNode(node); } public void addNode(Node node) { super.addNode(node); } public List contentList() { return super.contentList(); } public void addNode(int index, Node node) { super.addNode(index, node); } public Object clone() { try { System.out.println("OzoneDocumentImpl, cloning..."); // first get a copy of the document Document document = (Document) database().copyObject(self()); // now we need to copy the content, otherwist all the content would be // referenced fromn both documents document.setRootElement(null); document.setContent(null); document.appendContent((Document) self()); return document; } catch (Exception e) { e.printStackTrace(); return null; } } public void onCreate() { } public void onActivate() { } public void onPassivate() { } public void onDelete() { OzoneInterface db = database(); DocumentType docType = getDocType(); if (docType != null && docType instanceof OzoneRemote) { System.out.println("deleting doctype " + docType); db.deleteObject((OzoneRemote) docType); } List contentList = content(); Object content; for (Iterator it = contentList.iterator(); it.hasNext();) { content = it.next(); if (content instanceof OzoneRemote) { db.deleteObject((OzoneRemote) content); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -