deferreddocumentimpl.java

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

JAVA
1,830
字号
                System.out.print('\t');                switch (getChunkIndex(fNodeType, chunk, index)) {                    case DocumentImpl.ELEMENT_DEFINITION_NODE: { System.out.print("EDef"); break; }                    case Node.DOCUMENT_NODE: { System.out.print("Doc"); break; }                    case Node.DOCUMENT_TYPE_NODE: { System.out.print("DType"); break; }                    case Node.COMMENT_NODE: { System.out.print("Com"); break; }                    case Node.PROCESSING_INSTRUCTION_NODE: { System.out.print("PI"); break; }                    case Node.ELEMENT_NODE: { System.out.print("Elem"); break; }                    case Node.ENTITY_NODE: { System.out.print("Ent"); break; }                    case Node.ENTITY_REFERENCE_NODE: { System.out.print("ERef"); break; }                    case Node.TEXT_NODE: { System.out.print("Text"); break; }                    case Node.ATTRIBUTE_NODE: { System.out.print("Attr"); break; }                    case DeferredNode.TYPE_NODE: { System.out.print("TypeInfo"); break; }                    default: { System.out.print("?"+getChunkIndex(fNodeType, chunk, index)); }                }                System.out.print('\t');                System.out.print(getChunkValue(fNodeName, chunk, index));                System.out.print('\t');                System.out.print(getNodeValue(chunk, index));                System.out.print('\t');                System.out.print(getChunkValue(fNodeURI, chunk, index));                System.out.print('\t');                System.out.print(getChunkIndex(fNodeParent, chunk, index));                System.out.print('\t');                System.out.print(getChunkIndex(fNodeLastChild, chunk, index));                System.out.print('\t');                System.out.print(getChunkIndex(fNodePrevSib, chunk, index));                System.out.print('\t');                System.out.print(getChunkIndex(fNodeExtra, chunk, index));                System.out.println();            }            System.out.println("# end table");        }    } // print()    //    // DeferredNode methods    //    /** Returns the node index. */    public int getNodeIndex() {        return 0;    }    //    // Protected methods    //    /** Synchronizes the node's data. */    protected void synchronizeData() {        // no need to sync in the future        needsSyncData(false);        // fluff up enough nodes to fill identifiers hash        if (fIdElement != null) {            // REVISIT: There has to be a more efficient way of            //          doing this. But keep in mind that the            //          tree can have been altered and re-ordered            //          before all of the element nodes with ID            //          attributes have been registered. For now            //          this is reasonable and safe. -Ac            IntVector path = new IntVector();            for (int i = 0; i < fIdCount; i++) {                // ignore if it's already been registered                int elementNodeIndex = fIdElement[i];                String idName      = fIdName[i];                if (idName == null) {                    continue;                }                // find path from this element to the root                path.removeAllElements();                int index = elementNodeIndex;                do {                    path.addElement(index);                    int pchunk = index >> CHUNK_SHIFT;                    int pindex = index & CHUNK_MASK;                    index = getChunkIndex(fNodeParent, pchunk, pindex);                } while (index != -1);                // Traverse path (backwards), fluffing the elements                // along the way. When this loop finishes, "place"                // will contain the reference to the element node                // we're interested in. -Ac                Node place = this;                for (int j = path.size() - 2; j >= 0; j--) {                    index = path.elementAt(j);                    Node child = place.getLastChild();                    while (child != null) {                        if (child instanceof DeferredNode) {                            int nodeIndex =                                ((DeferredNode)child).getNodeIndex();                            if (nodeIndex == index) {                                place = child;                                break;                            }                        }                        child = child.getPreviousSibling();                    }                }                // register the element                Element element = (Element)place;                putIdentifier0(idName, element);                fIdName[i] = null;                // see if there are more IDs on this element                while (i + 1 < fIdCount &&                    fIdElement[i + 1] == elementNodeIndex) {                    idName = fIdName[++i];                    if (idName == null) {                        continue;                    }                    putIdentifier0(idName, element);                }            }        } // if identifiers    } // synchronizeData()    /**     * Synchronizes the node's children with the internal structure.     * Fluffing the children at once solves a lot of work to keep     * the two structures in sync. The problem gets worse when     * editing the tree -- this makes it a lot easier.     */    protected void synchronizeChildren() {        if (needsSyncData()) {            synchronizeData();            /*             * when we have elements with IDs this method is being recursively             * called from synchronizeData, in which case we've already gone             * through the following and we can now simply stop here.             */            if (!needsSyncChildren()) {                return;            }        }        // we don't want to generate any event for this so turn them off        boolean orig = mutationEvents;        mutationEvents = false;        // no need to sync in the future        needsSyncChildren(false);        getNodeType(0);        // create children and link them as siblings        ChildNode first = null;        ChildNode last = null;        for (int index = getLastChild(0);             index != -1;             index = getPrevSibling(index)) {            ChildNode node = (ChildNode)getNodeObject(index);            if (last == null) {                last = node;            }            else {                first.previousSibling = node;            }            node.ownerNode = this;            node.isOwned(true);            node.nextSibling = first;            first = node;            // save doctype and document type            int type = node.getNodeType();            if (type == Node.ELEMENT_NODE) {                docElement = (ElementImpl)node;            }            else if (type == Node.DOCUMENT_TYPE_NODE) {                docType = (DocumentTypeImpl)node;            }        }        if (first != null) {            firstChild = first;            first.isFirstChild(true);            lastChild(last);        }        // set mutation events flag back to its original value        mutationEvents = orig;    } // synchronizeChildren()    /**     * Synchronizes the node's children with the internal structure.     * Fluffing the children at once solves a lot of work to keep     * the two structures in sync. The problem gets worse when     * editing the tree -- this makes it a lot easier.     * This is not directly used in this class but this method is     * here so that it can be shared by all deferred subclasses of AttrImpl.     */    protected final void synchronizeChildren(AttrImpl a, int nodeIndex) {        // we don't want to generate any event for this so turn them off        boolean orig = getMutationEvents();        setMutationEvents(false);        // no need to sync in the future        a.needsSyncChildren(false);        // create children and link them as siblings or simply store the value        // as a String if all we have is one piece of text        int last = getLastChild(nodeIndex);        int prev = getPrevSibling(last);        if (prev == -1) {            a.value = getNodeValueString(nodeIndex);            a.hasStringValue(true);        }        else {            ChildNode firstNode = null;            ChildNode lastNode = null;            for (int index = last; index != -1;                 index = getPrevSibling(index)) {                ChildNode node = (ChildNode) getNodeObject(index);                if (lastNode == null) {                    lastNode = node;                }                else {                    firstNode.previousSibling = node;                }                node.ownerNode = a;                node.isOwned(true);                node.nextSibling = firstNode;                firstNode = node;            }            if (lastNode != null) {                a.value = firstNode; // firstChild = firstNode                firstNode.isFirstChild(true);                a.lastChild(lastNode);            }            a.hasStringValue(false);        }        // set mutation events flag back to its original value        setMutationEvents(orig);    } // synchronizeChildren(AttrImpl,int):void    /**     * Synchronizes the node's children with the internal structure.     * Fluffing the children at once solves a lot of work to keep     * the two structures in sync. The problem gets worse when     * editing the tree -- this makes it a lot easier.     * This is not directly used in this class but this method is     * here so that it can be shared by all deferred subclasses of ParentNode.     */    protected final void synchronizeChildren(ParentNode p, int nodeIndex) {        // we don't want to generate any event for this so turn them off        boolean orig = getMutationEvents();        setMutationEvents(false);        // no need to sync in the future        p.needsSyncChildren(false);        // create children and link them as siblings        ChildNode firstNode = null;        ChildNode lastNode = null;        for (int index = getLastChild(nodeIndex);             index != -1;             index = getPrevSibling(index)) {            ChildNode node = (ChildNode) getNodeObject(index);            if (lastNode == null) {                lastNode = node;            }            else {                firstNode.previousSibling = node;            }            node.ownerNode = p;            node.isOwned(true);            node.nextSibling = firstNode;            firstNode = node;        }        if (lastNode != null) {            p.firstChild = firstNode;            firstNode.isFirstChild(true);            p.lastChild(lastNode);        }        // set mutation events flag back to its original value        setMutationEvents(orig);    } // synchronizeChildren(ParentNode,int):void    // utility methods    /** Ensures that the internal tables are large enough. */    protected void ensureCapacity(int chunk) {        if (fNodeType == null) {            // create buffers            fNodeType       = new int[INITIAL_CHUNK_COUNT][];            fNodeName       = new Object[INITIAL_CHUNK_COUNT][];            fNodeValue      = new Object[INITIAL_CHUNK_COUNT][];            fNodeParent     = new int[INITIAL_CHUNK_COUNT][];            fNodeLastChild  = new int[INITIAL_CHUNK_COUNT][];            fNodePrevSib    = new int[INITIAL_CHUNK_COUNT][];            fNodeURI        = new Object[INITIAL_CHUNK_COUNT][];            fNodeExtra      = new int[INITIAL_CHUNK_COUNT][];        }        else if (fNodeType.length <= chunk) {            // resize the tables            int newsize = chunk * 2;            int[][] newArray = new int[newsize][];            System.arraycopy(fNodeType, 0, newArray, 0, chunk);            fNodeType = newArray;            Object[][] newStrArray = new Object[newsize][];            System.arraycopy(fNodeName, 0, newStrArray, 0, chunk);            fNodeName = newStrArray;            newStrArray = new Object[newsize][];            System.arraycopy(fNodeValue, 0, newStrArray, 0, chunk);            fNodeValue = newStrArray;            newArray = new int[newsize][];            System.arraycopy(fNodeParent, 0, newArray, 0, chunk);            fNodeParent = newArray;            newArray = new int[newsize][];            System.arraycopy(fNodeLastChild, 0, newArray, 0, chunk);            fNodeLastChild = newArray;            newArray = new int[newsize][];            System.arraycopy(fNodePrevSib, 0, newArray, 0, chunk);            fNodePrevSib = newArray;            newStrArray = new Object[newsize][];            System.arraycopy(fNodeURI, 0, newStrArray, 0, chunk);            fNodeURI = newStrArray;            newArray = new int[newsize][];            System.arraycopy(fNodeExtra, 0, newArray, 0, chunk);            fNodeExtra = newArray;        }        else if (fNodeType[chunk] != null) {            // Done - there's sufficient capacity            return;        }        // create new chunks        createChunk(fNodeType, chunk);        createChunk(fNodeName, chunk);        createChunk(fNodeValue, chunk);        createChunk(fNodeParent, chunk);        createChunk(fNodeLastChild, chunk);        createChunk(fNodePrevSib, chunk);        createChunk(fNodeURI, chunk);        createChunk(fNodeExtra, chunk);        //

⌨️ 快捷键说明

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