⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlcontainer.java

📁 用Java写的面相对象的数据库管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// 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-2000 by SMB GmbH. All rights reserved.//// $Id: XMLContainer.java,v 1.15 2000/11/09 14:56:53 daniela Exp $package org.ozoneDB.xml.util;import java.io.IOException;import java.io.ObjectOutput;import java.io.ObjectInput;import java.io.Externalizable;import org.ozoneDB.*;import org.w3c.dom.Document;import org.w3c.dom.Node;import org.xml.sax.InputSource;import org.xml.sax.ContentHandler;import org.ozoneDB.xml.xpath.XPathProcessor;import org.ozoneDB.xml.xpath.XPathQuery;import org.ozoneDB.xml.xpath.XObject;import org.ozoneDB.xml.dom.DocumentProxy;/** *  <p>This class is the central part of the ozone/XML API. Basically it provides a *  persistent container for a XML document, which is stored in an ozone database.</p> * *  <p><dl><dt>IMPORTANT:</dt><dd>Before calling one of the store or extract methods the *  thread <b>must</b> have joined a transaction.</dd></dl> *  </p> * *  Usage of the SAX methods is recomended, because of the better performance. * * @version $Revision: 1.15 $ $Date: 2000/11/09 14:56:53 $ * @author <a href="http://www.smb-tec.com">SMB</a> */public class XMLContainer implements Externalizable, SAXChunkProducerDelegate {        // Class data        public final static boolean debug = false;        private static String   	XPathProcessorName;        // Data        private XMLContainerHelper  helper;        private transient       	OzoneInterface db;        private transient Document  doc;    /** True if this object runs outside an ozone server. */    private transient boolean   runsExternal;            // Class methods            /**     *  Creates a new container with the given name.     *  @param _db The database where the container will be stored.     *  @param _docName The name of the container (and the document).     *  @return the new container.     */    public static XMLContainer newContainer( OzoneInterface _db, String _docName ) throws Exception {        XMLContainerHelper helper = (XMLContainerHelper)_db.createObject(                 XMLContainerHelperImpl.class.getName(),                 OzoneInterface.Public,                _docName );        return new XMLContainer( _db, helper );    }             /**     *  Returns the XMLContainer representing the document with the given name.     *  @param _db The database where the container is stored.     *  @param _docName The name under which the container has been stored.     *  @return the container for the given name or null if the container     *          does not exist.     */    public static XMLContainer forName( OzoneInterface _db, String _docName ) throws Exception {        XMLContainerHelper helper = (XMLContainerHelper)_db.objectForName( _docName );        return helper != null ? new XMLContainer( _db, helper ) : null;    }             /**     *  Returns the XMLContainer representing the document the given node     *  belongs to.     *  @param _db The database where the container is stored.     *  @param _pNode A node of the document the container represents.     *  @return the container for the given node or null if the node has not     *          been stored using the XMLContainer class.     */    public static XMLContainer forNode( OzoneInterface _db, Node _pNode ) throws Exception {        if (!(_pNode instanceof OzoneProxy)) {            throw new IllegalArgumentException("Not a persistent DOM node: " + _pNode.getClass().getName());        }        DocumentProxy pDoc = _pNode instanceof Document                 ? (DocumentProxy)_pNode                 : (DocumentProxy)_pNode.getOwnerDocument();        XMLContainerHelper helper = (XMLContainerHelper)pDoc.getContainer();        return helper != null ? new XMLContainer( _db, helper ) : null;    }             public static void setXPathProcessor( Class _cl ) throws Exception {    }             // Constructors            protected XMLContainer( OzoneInterface _db, XMLContainerHelper _helper ) {        db = _db;        helper = _helper;        runsExternal = (db instanceof Database);    }            // Methods        /**     * Changes the name of this container.     * @param _name The new name of this container or null to remove the     *     current name.     */    public void setName( String _name ) throws Exception {        if (helper == null) {            throw new IllegalStateException( "Document has already been deleted." );        }         db.nameObject( helper, _name );    }    /**     * Deletes the container (and the associated document) from the database.     */    public synchronized void delete() throws Exception {        if (helper == null) {            throw new IllegalStateException("Document has already been deleted.");        }         db.deleteObject(helper);        helper = null;        doc = null;    }             /**     *  Get the underlying persistent document that this container is working on.     *  @return The persistent document.     */    public Document getPDocument() throws Exception {        if (helper == null) {            throw new IllegalStateException( "Document has already been deleted." );        }         // not synchronized because it wouldn't make a difference here        if (doc == null) {            doc = helper.getDocument();        }        return doc;    }             /**     * Stores a transient DOM tree database. The newly created Nodes are     * appended to the Document Node of this container.     *     * @see #storeDOM(Node, Node)     */    public void storeDOM( Document _tNode ) throws Exception {        if (helper == null)            throw new IllegalStateException("Document has already been deleted.");        storeDOM( null, _tNode );    }    /**     *  Stores a transient node into the database.     *     *  <p>Before calling this method the current thread <b>must</b> have joined an     *  {@link org.ozoneDB.ExternalTransaction explicit Transaction}. This is an     *  exception to the normal case, where an implicit transaction (handled by     *  Ozone) is more appropriate.</p>     *  <p><dl><dt>Note:</dt><dd>If ever possible the corresponding     *  {@link #storeSAX(Node) SAX method} should be used, because the performance     *  of SAX storage is much better.</dd></dl></p>     *     *  @param _pNode The persistent node where the stored node will be appended to.     *      Null replaces the current document.     *  @param _tnode The transient node to be stored.     *     *  @throws IllegalStateException if the underlying document has already been deleted.     *  @throws IllegalArgumentException if _tnode was null.     *  @throws IllegalStateException if the current thread has not joined a     *          {@link org.ozoneDB.ExternalTransaction transaction}.     *  @see org.ozoneDB.ExternalTransaction     *  @see org.ozoneDB.ExternalDatabase#newTransaction()     */    public void storeDOM(Node _pNode, Node _tNode ) throws Exception {        long time = 0;        long starttime = 0;                if (helper == null) {            throw new IllegalStateException( "Document has already been deleted." );        }         if (_tNode == null) {            throw new IllegalArgumentException( "tNode == null." );        }         // thread must have joined a transaction        if (runsExternal && ((ExternalDatabase)db).currentTransaction() == null) {            throw new IllegalStateException( "Thread must have joined a transaction!" );        }                 SAXChunkConsumer consumer = helper.beginInputSequence(_pNode);        SAXChunkProducer producer = new SAXChunkProducer(_tNode);        ChunkOutputStream cos;        do {            producer.createNextChunk();            cos = producer.chunkStream();            if (XMLContainer.debug) {                starttime = System.currentTimeMillis();            }            consumer = helper.putChunk(cos.toByteArray(), consumer);            if (XMLContainer.debug) {                time += (System.currentTimeMillis() - starttime);            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -