deferreddocumentimpl.java

来自「JAVA 所有包」· Java 代码 · 共 1,830 行 · 第 1/5 页

JAVA
1,830
字号
/* * Copyright 1999-2002,2004,2005 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.sun.org.apache.xerces.internal.dom;import org.w3c.dom.DOMImplementation;import org.w3c.dom.Element;import org.w3c.dom.Node;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. *  * @xerces.internal * * @version $Id: DeferredDocumentImpl.java,v 1.2.6.1 2005/08/31 10:30:07 sunithareddy Exp $ * @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    //    /**     * Retrieve information describing the abilities of this particular     * DOM implementation. Intended to support applications that may be     * using DOMs retrieved from several different sources, potentially     * with different underlying representations.     */    public DOMImplementation getImplementation() {        // Currently implemented as a singleton, since it's hardcoded        // information anyway.        return DeferredDOMImplementationImpl.getDOMImplementation();    }        /** 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);        // get second extra data chunk        int extraDataIndex = getNodeExtra(nodeIndex, false);        int echunk = extraDataIndex >> CHUNK_SHIFT;        int eindex = extraDataIndex & CHUNK_MASK;                setChunkValue(fNodeValue, value, echunk, eindex);            }    /** Creates an entity reference node in the table. */    public int createDeferredEntityReference(String name, String baseURI) {        // create node        int nodeIndex = createNode(Node.ENTITY_REFERENCE_NODE);        int chunk     = nodeIndex >> CHUNK_SHIFT;        int index     = nodeIndex & CHUNK_MASK;        setChunkValue(fNodeName, name, chunk, index);        setChunkValue(fNodeValue, baseURI, chunk, index);        // return node index        return nodeIndex;    } // createDeferredEntityReference(String):int    /** Creates an element node with a URI in the table and type information. */    public int createDeferredElement(String elementURI, String elementName,                                       Object type) {        // create node        int elementNodeIndex = createNode(Node.ELEMENT_NODE);        int elementChunk     = elementNodeIndex >> CHUNK_SHIFT;        int elementIndex     = elementNodeIndex & CHUNK_MASK;

⌨️ 快捷键说明

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