deferreddocumentimpl.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,813 行 · 第 1/5 页

JAVA
1,813
字号
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * 3. The end-user documentation included with the redistribution, *    if any, must include the following acknowledgment: *       "This product includes software developed by the *        Apache Software Foundation (http://www.apache.org/)." *    Alternately, this acknowledgment may appear in the software itself, *    if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", *    nor may "Apache" appear in their name, without prior written *    permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 1999, International * Business Machines, Inc., http://www.apache.org.  For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package com.sun.org.apache.xerces.internal.dom;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.TypeInfo;import java.util.Vector;/** * The Document interface represents the entire HTML or XML document. * Conceptually, it is the root of the document tree, and provides the * primary access to the document's data. * <P> * Since elements, text nodes, comments, processing instructions, * etc. cannot exist outside the context of a Document, the Document * interface also contains the factory methods needed to create these * objects. The Node objects created have a ownerDocument attribute * which associates them with the Document within whose context they * were created. *<<<<<<< DeferredDocumentImpl.java * @version $Id: DeferredDocumentImpl.java,v 1.3 2003/11/18 00:22:50 kk122374 Exp $======= * @version $Id: DeferredDocumentImpl.java,v 1.3 2003/11/18 00:22:50 kk122374 Exp $>>>>>>> 1.1.1.2 * @since  PR-DOM-Level-1-19980818. */public class DeferredDocumentImpl    extends DocumentImpl    implements DeferredNode {    //    // Constants    //    /** Serialization version. */    static final long serialVersionUID = 5186323580749626857L;    // debugging    /** To include code for printing the ref count tables. */    private static final boolean DEBUG_PRINT_REF_COUNTS = false;    /** To include code for printing the internal tables. */    private static final boolean DEBUG_PRINT_TABLES = false;    /** To debug identifiers set to true and recompile. */    private static final boolean DEBUG_IDS = false;    // protected    /** Chunk shift. */    protected static final int CHUNK_SHIFT = 11;           // 2^11 = 2k    /** Chunk size. */    protected static final int CHUNK_SIZE = (1 << CHUNK_SHIFT);    /** Chunk mask. */    protected static final int CHUNK_MASK = CHUNK_SIZE - 1;    /** Initial chunk size. */    protected static final int INITIAL_CHUNK_COUNT = (1 << (16 - CHUNK_SHIFT));   // 2^16 = 64k    //    // Data    //    // lazy-eval information    // To maximize memory consumption the actual semantic of these fields vary    // depending on the node type.    /** Node count. */    protected transient int fNodeCount = 0;    /** Node types. */    protected transient int fNodeType[][];    /** Node names. */    protected transient Object fNodeName[][];    /** Node values. */    protected transient Object fNodeValue[][];    /** Node parents. */    protected transient int fNodeParent[][];    /** Node first children. */    protected transient int fNodeLastChild[][];    /** Node prev siblings. */    protected transient int fNodePrevSib[][];    /** Node namespace URI. */    protected transient Object fNodeURI[][];    /** Extra data. */    protected transient int fNodeExtra[][];    /** Identifier count. */    protected transient int fIdCount;    /** Identifier name indexes. */    protected transient String fIdName[];    /** Identifier element indexes. */    protected transient int fIdElement[];    /** DOM2: For namespace support in the deferred case.     */    // Implementation Note: The deferred element and attribute must know how to    // interpret the int representing the qname.    protected boolean fNamespacesEnabled = false;        //    // private data    //    private transient final StringBuffer fBufferStr = new StringBuffer();    private transient final Vector fStrChunks = new Vector();    //    // Constructors    //    /**     * NON-DOM: Actually creating a Document is outside the DOM's spec,     * since it has to operate in terms of a particular implementation.     */    public DeferredDocumentImpl() {        this(false);    } // <init>()    /**     * NON-DOM: Actually creating a Document is outside the DOM's spec,     * since it has to operate in terms of a particular implementation.     */    public DeferredDocumentImpl(boolean namespacesEnabled) {        this(namespacesEnabled, false);    } // <init>(boolean)    /** Experimental constructor. */    public DeferredDocumentImpl(boolean namespaces, boolean grammarAccess) {        super(grammarAccess);        needsSyncData(true);        needsSyncChildren(true);        fNamespacesEnabled = namespaces;    } // <init>(boolean,boolean)    //    // Public methods    //    /** Returns the cached parser.getNamespaces() value.*/    boolean getNamespacesEnabled() {        return fNamespacesEnabled;    }    void setNamespacesEnabled(boolean enable) {        fNamespacesEnabled = enable;    }    // internal factory methods    /** Creates a document node in the table. */    public int createDeferredDocument() {        int nodeIndex = createNode(Node.DOCUMENT_NODE);        return nodeIndex;    }    /** Creates a doctype. */    public int createDeferredDocumentType(String rootElementName,                                          String publicId, String systemId) {        // create node        int nodeIndex = createNode(Node.DOCUMENT_TYPE_NODE);        int chunk     = nodeIndex >> CHUNK_SHIFT;        int index     = nodeIndex & CHUNK_MASK;        // save name, public id, system id        setChunkValue(fNodeName, rootElementName, chunk, index);        setChunkValue(fNodeValue, publicId, chunk, index);        setChunkValue(fNodeURI, systemId, chunk, index);        // return node index        return nodeIndex;    } // createDeferredDocumentType(String,String,String):int    public void setInternalSubset(int doctypeIndex, String subset) {        int chunk     = doctypeIndex >> CHUNK_SHIFT;        int index     = doctypeIndex & CHUNK_MASK;        // create extra data node to store internal subset        int extraDataIndex = createNode(Node.DOCUMENT_TYPE_NODE);         int echunk = extraDataIndex >> CHUNK_SHIFT;        int eindex = extraDataIndex & CHUNK_MASK;        setChunkIndex(fNodeExtra, extraDataIndex, chunk, index);                setChunkValue(fNodeValue, subset, echunk, eindex);    }    /** Creates a notation in the table. */    public int createDeferredNotation(String notationName,                                      String publicId, String systemId, String baseURI) {        // create node        int nodeIndex = createNode(Node.NOTATION_NODE);        int chunk     = nodeIndex >> CHUNK_SHIFT;        int index     = nodeIndex & CHUNK_MASK;        // create extra data node        int extraDataIndex = createNode(Node.NOTATION_NODE);         int echunk = extraDataIndex >> CHUNK_SHIFT;        int eindex = extraDataIndex & CHUNK_MASK;        // save name, public id, system id, and notation name        setChunkValue(fNodeName, notationName, chunk, index);        setChunkValue(fNodeValue, publicId, chunk, index);        setChunkValue(fNodeURI, systemId, chunk, index);        // in extra data node set baseURI value        setChunkIndex(fNodeExtra, extraDataIndex, chunk, index);        setChunkValue(fNodeName, baseURI, echunk, eindex);        // return node index        return nodeIndex;    } // createDeferredNotation(String,String,String):int    /** Creates an entity in the table. */    public int createDeferredEntity(String entityName, String publicId,                                    String systemId, String notationName,                                     String baseURI) {        // create node        int nodeIndex = createNode(Node.ENTITY_NODE);        int chunk     = nodeIndex >> CHUNK_SHIFT;        int index     = nodeIndex & CHUNK_MASK;        // create extra data node        int extraDataIndex = createNode(Node.ENTITY_NODE);         int echunk = extraDataIndex >> CHUNK_SHIFT;        int eindex = extraDataIndex & CHUNK_MASK;        // save name, public id, system id, and notation name        setChunkValue(fNodeName, entityName, chunk, index);        setChunkValue(fNodeValue, publicId, chunk, index);        setChunkValue(fNodeURI, systemId, chunk, index);        setChunkIndex(fNodeExtra, extraDataIndex, chunk, index);        // set other values in the extra chunk        // notation        setChunkValue(fNodeName, notationName, echunk, eindex);        // version  L3        setChunkValue(fNodeValue, null, echunk, eindex);        // encoding L3        setChunkValue(fNodeURI, null, echunk, eindex);        int extraDataIndex2 = createNode(Node.ENTITY_NODE);        int echunk2 = extraDataIndex2 >> CHUNK_SHIFT;        int eindex2 = extraDataIndex2 & CHUNK_MASK;        setChunkIndex(fNodeExtra, extraDataIndex2, echunk, eindex);        // baseURI        setChunkValue(fNodeName, baseURI, echunk2, eindex2);        // return node index        return nodeIndex;    } // createDeferredEntity(String,String,String,String):int    public String getDeferredEntityBaseURI (int entityIndex){        if (entityIndex != -1) {            int extraDataIndex = getNodeExtra(entityIndex, false);            extraDataIndex = getNodeExtra(extraDataIndex, false);            return getNodeName (extraDataIndex, false);        }        return null;    }    // DOM Level 3: setting encoding and version    public void setEntityInfo(int currentEntityDecl,                              String version, String encoding){        int eNodeIndex = getNodeExtra(currentEntityDecl, false);        if (eNodeIndex !=-1) {            int echunk = eNodeIndex >> CHUNK_SHIFT;            int eindex = eNodeIndex & CHUNK_MASK;            setChunkValue(fNodeValue, version, echunk, eindex);            setChunkValue(fNodeURI, encoding, echunk, eindex);        }    }    /**     * DOM Internal      *     * An attribute specifying the actual encoding of this document. This is     * <code>null</code> otherwise.     * <br> This attribute represents the property [character encoding scheme]     * defined in .     */    public void setInputEncoding(int currentEntityDecl, String value){        // get first extra data chunk        int nodeIndex = getNodeExtra(currentEntityDecl, false);

⌨️ 快捷键说明

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