FileDocCategorySizeDatePackage
DOMNodePool.javaAPI DocJava SE 5 API7702Fri Aug 26 14:55:50 BST 2005com.sun.org.apache.xerces.internal.impl.xs.dom

DOMNodePool

public final class DOMNodePool extends Object
This class is pool that enables caching of DOM nodes, such as Element, Attr, Text, that are used to parse and later traverse XML Schemas. The pool is reset before a new set of schemas is traversed. Note: pool is not reset during traversals of imported/included schemas.
author
Elena Litani, IBM
version
$Id: DOMNodePool.java,v 1.3 2002/11/20 00:49:47 twl Exp $

Fields Summary
private static final int
CHUNK_SHIFT
Chunk shift (8).
private static final int
CHUNK_SIZE
Chunk size (1 << CHUNK_SHIFT).
private static final int
CHUNK_MASK
Chunk mask (CHUNK_SIZE - 1).
private static final int
INITIAL_CHUNK_COUNT
Initial chunk count ().
private ElementNSImpl[]
fElements
Element nodes pool
private int
fElementIndex
private TextImpl[]
fTextNode
Text nodes pool
private int
fTextNodeIndex
private AttrNSImpl[]
fAttrNode
Attribute nodes pool
private int
fAttrNodeIndex
Constructors Summary
Methods Summary
private voidensureAttrsCapacity(int chunk)

        if (fAttrNode.length <= chunk) {
            fAttrNode = resize(fAttrNode, fAttrNode.length * 2);
        }
        else if (fAttrNode[chunk] != null) {
            return;
        }

        fAttrNode[chunk] = new AttrNSImpl[CHUNK_SIZE];
        return;
    
private voidensureElementsCapacity(int chunk)

        if (fElements.length <= chunk) {
            fElements = resize(fElements, fElements.length * 2);
        }
        else if (fElements[chunk] != null) {
            return;
        }

        fElements[chunk] = new ElementNSImpl[CHUNK_SIZE];
        return;
    
private voidensureTextCapacity(int chunk)

        if (fTextNode.length <= chunk) {
            fTextNode = resize(fTextNode, fTextNode.length * 2);
        }
        else if (fTextNode[chunk] != null) {
            return;
        }

        fTextNode[chunk] = new TextImpl[CHUNK_SIZE];
        return;
    
public final com.sun.org.apache.xerces.internal.dom.AttrNSImplgetAttrNode()
This methods creates attribute node or provides a free attribute node if such exists in the pool.

return
a usable attribute node

        int     chunk       = fAttrNodeIndex >> CHUNK_SHIFT;
        int     index       = fAttrNodeIndex &  CHUNK_MASK;
        ensureAttrsCapacity(chunk);
        if (fAttrNode[chunk][index] == null) {
            fAttrNode[chunk][index] = new AttrNSImpl();
        } 
        fAttrNodeIndex++;
        return fAttrNode[chunk][index];
    
public final ElementNSImplgetElementNode()
This method creates a new element node or provides a free element node if such exists in the pool.

return
usable element node


    

                                  
        
        int     chunk       = fElementIndex >> CHUNK_SHIFT;
        int     index       = fElementIndex &  CHUNK_MASK;
        ensureElementsCapacity(chunk);
        if (fElements[chunk][index] == null) {
            fElements[chunk][index] = new ElementNSImpl();
        } 
        fElementIndex++;
        return fElements[chunk][index];
    
public final com.sun.org.apache.xerces.internal.dom.TextImplgetTextNode()
This methods creates text node or provides a free text node if such exists in the pool.

return
a usable TextNode

        int     chunk       = fTextNodeIndex >> CHUNK_SHIFT;
        int     index       = fTextNodeIndex &  CHUNK_MASK;
        ensureTextCapacity(chunk);
        if (fTextNode[chunk][index] == null) {
            fTextNode[chunk][index] = new TextImpl();
        } 
        fTextNodeIndex++;
        return fTextNode[chunk][index];
    
public voidreset()
Reset the pool. The nodes in the pool become 'free' nodes.

        fElementIndex = 0;
        fTextNodeIndex = 0;
        fAttrNodeIndex = 0;
    
private static ElementNSImpl[][]resize(ElementNSImpl[][] array, int newsize)

        ElementNSImpl newarray[][] = new ElementNSImpl[newsize][];
        System.arraycopy(array, 0, newarray, 0, array.length);
        return newarray;
    
private static com.sun.org.apache.xerces.internal.dom.TextImpl[][]resize(com.sun.org.apache.xerces.internal.dom.TextImpl[][] array, int newsize)

        TextImpl newarray[][] = new TextImpl[newsize][];
        System.arraycopy(array, 0, newarray, 0, array.length);
        return newarray;
    
private static com.sun.org.apache.xerces.internal.dom.AttrNSImpl[][]resize(com.sun.org.apache.xerces.internal.dom.AttrNSImpl[][] array, int newsize)

        AttrNSImpl newarray[][] = new AttrNSImpl[newsize][];
        System.arraycopy(array, 0, newarray, 0, array.length);
        return newarray;