FileDocCategorySizeDatePackage
MultiDOM.javaAPI DocJava SE 6 API20861Tue Jun 10 00:22:32 BST 2008com.sun.org.apache.xalan.internal.xsltc.dom

MultiDOM

public final class MultiDOM extends Object implements DOM
author
Jacek Ambroziak
author
Morten Jorgensen
author
Erwin Bolwidt

Fields Summary
private static final int
NO_TYPE
private static final int
INITIAL_SIZE
private DOM[]
_adapters
private DOMAdapter
_main
private DTMManager
_dtmManager
private int
_free
private int
_size
private com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable
_documents
Constructors Summary
public MultiDOM(DOM main)

        _size = INITIAL_SIZE;
        _free = 1;
        _adapters = new DOM[INITIAL_SIZE];
        DOMAdapter adapter = (DOMAdapter)main;
        _adapters[0] = adapter;
        _main = adapter;
        DOM dom = adapter.getDOMImpl();
        if (dom instanceof DTMDefaultBase) {
            _dtmManager = ((DTMDefaultBase)dom).getManager();
        }

        // %HZ% %REVISIT% Is this the right thing to do here?  In the old
        // %HZ% %REVISIT% version, the main document did not get added through
        // %HZ% %REVISIT% a call to addDOMAdapter, which meant it couldn't be
        // %HZ% %REVISIT% found by a call to getDocumentMask.  The problem is
        // %HZ% %REVISIT% TransformerHandler is typically constructed with a
        // %HZ% %REVISIT% system ID equal to the stylesheet's URI; with SAX
        // %HZ% %REVISIT% input, it ends up giving that URI to the document.
        // %HZ% %REVISIT% Then, any references to document('') are resolved
        // %HZ% %REVISIT% using the stylesheet's URI.
        // %HZ% %REVISIT% MultiDOM.getDocumentMask is called to verify that
        // %HZ% %REVISIT% a document associated with that URI has not been
        // %HZ% %REVISIT% encountered, and that method ends up returning the
        // %HZ% %REVISIT% mask of the main document, when what we really what
        // %HZ% %REVISIT% is to read the stylesheet itself!
        addDOMAdapter(adapter, false);
    
Methods Summary
public intaddDOMAdapter(com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter adapter)

        return addDOMAdapter(adapter, true);
    
private intaddDOMAdapter(com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter adapter, boolean indexByURI)

        // Add the DOM adapter to the array of DOMs
        DOM dom = adapter.getDOMImpl();
        
        int domNo = 1;
        int dtmSize = 1;
        SuballocatedIntVector dtmIds = null;
        if (dom instanceof DTMDefaultBase) {
            DTMDefaultBase dtmdb = (DTMDefaultBase)dom;
            dtmIds = dtmdb.getDTMIDs();
            dtmSize = dtmIds.size();
            domNo = dtmIds.elementAt(dtmSize-1) >>> DTMManager.IDENT_DTM_NODE_BITS;
        }
        else if (dom instanceof SimpleResultTreeImpl) {
            SimpleResultTreeImpl simpleRTF = (SimpleResultTreeImpl)dom;
            domNo = simpleRTF.getDocument() >>> DTMManager.IDENT_DTM_NODE_BITS;
        }
                  
        if (domNo >= _size) {
            int oldSize = _size;
            do {
            	_size *= 2;
            } while (_size <= domNo);
            
            final DOMAdapter[] newArray = new DOMAdapter[_size];
            System.arraycopy(_adapters, 0, newArray, 0, oldSize);
            _adapters = newArray;
        }
        
        _free = domNo + 1;
        
        if (dtmSize == 1) {
            _adapters[domNo] = adapter;
        }
        else if (dtmIds != null) {
            int domPos = 0;
            for (int i = dtmSize - 1; i >= 0; i--) {
                domPos = dtmIds.elementAt(i) >>> DTMManager.IDENT_DTM_NODE_BITS;
                _adapters[domPos] = adapter;
            }
            domNo = domPos;
        }

        // Store reference to document (URI) in hashtable
        if (indexByURI) {
            String uri = adapter.getDocumentURI(0);
            _documents.put(uri, new Integer(domNo));
        }
        
        // If the dom is an AdaptiveResultTreeImpl, we need to create a
        // DOMAdapter around its nested dom object (if it is non-null) and
        // add the DOMAdapter to the list.
        if (dom instanceof AdaptiveResultTreeImpl) {
            AdaptiveResultTreeImpl adaptiveRTF = (AdaptiveResultTreeImpl)dom;
            DOM nestedDom = adaptiveRTF.getNestedDOM();
            if (nestedDom != null) {
                DOMAdapter newAdapter = new DOMAdapter(nestedDom, 
                                                       adapter.getNamesArray(),
                                                       adapter.getUrisArray(),
                                                       adapter.getTypesArray(),
                                                       adapter.getNamespaceArray());
                addDOMAdapter(newAdapter);  
            } 
        }
        
        return domNo;
    
public voidcharacters(int textNode, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler)

        if (textNode != DTM.NULL) {
            _adapters[textNode >>> DTMManager.IDENT_DTM_NODE_BITS].characters(textNode, handler);
        }
    
public voidcopy(int node, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler)

        if (node != DTM.NULL) {
            _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].copy(node, handler);
        }
    
public voidcopy(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator nodes, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler)

        int node;
        while ((node = nodes.next()) != DTM.NULL) {
            _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].copy(node, handler);
        }
    
public intgetAttributeNode(int type, int el)

        if (el == DTM.NULL) {
            return DTM.NULL;
        }
        return _adapters[el >>> DTMManager.IDENT_DTM_NODE_BITS].getAttributeNode(type, el);
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetAxisIterator(int axis)

        return new AxisIterator(axis, NO_TYPE);
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetChildren(int node)

        return _adapters[getDTMId(node)].getChildren(node);
    
public com.sun.org.apache.xalan.internal.xsltc.DOMgetDOMAdapter(java.lang.String uri)

        Integer domIdx = (Integer)_documents.get(uri);
        if (domIdx == null) {
            return(null);
        } else {
            return(_adapters[domIdx.intValue()]);
        }
    
public com.sun.org.apache.xalan.internal.xsltc.DOMgetDTM(int nodeHandle)

        return _adapters[getDTMId(nodeHandle)];
    
public intgetDTMId(int nodeHandle)

        if (nodeHandle == DTM.NULL)
            return 0;
        
        int id = nodeHandle >>> DTMManager.IDENT_DTM_NODE_BITS;
        while (id >= 2 && _adapters[id] == _adapters[id-1]) {
            id--;
        }
        return id;
    
public com.sun.org.apache.xml.internal.dtm.DTMManagergetDTMManager()

    	return _dtmManager;
    
public intgetDocument()

        return _main.getDocument();
    
public intgetDocumentMask(java.lang.String uri)

        Integer domIdx = (Integer)_documents.get(uri);
        if (domIdx == null) {
            return(-1);
        } else {
            return domIdx.intValue();
        }
    
public java.lang.StringgetDocumentURI(int node)

        if (node == DTM.NULL) {
            node = DOM.NULL;
        }
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getDocumentURI(0);
    
public com.sun.org.apache.xalan.internal.xsltc.runtime.HashtablegetElementsWithIDs()

        return _main.getElementsWithIDs();
    
public intgetExpandedTypeID(int node)

    	if (node != DTM.NULL) {
            return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getExpandedTypeID(node);
    	}
    	else {
    	    return DTM.NULL;
    	}
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetIterator()
Returns singleton iterator containing the document root

        // main source document @ 0
        return _main.getIterator();
    
public java.lang.StringgetLanguage(int node)

        return _adapters[getDTMId(node)].getLanguage(node);
    
public com.sun.org.apache.xalan.internal.xsltc.DOMgetMain()

        return _main;
    
public intgetNSType(int node)

        return _adapters[getDTMId(node)].getNSType(node);
   
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetNamespaceAxisIterator(int axis, int ns)

        DTMAxisIterator iterator = _main.getNamespaceAxisIterator(axis, ns);
        return(iterator);        
    
public java.lang.StringgetNamespaceName(int node)

        if (node == DTM.NULL) {
            return "";
        }
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getNamespaceName(node);
    
public intgetNamespaceType(int node)

        return _adapters[getDTMId(node)].getNamespaceType(node);
    
public intgetNodeHandle(int nodeId)

        return _main.getNodeHandle(nodeId);
    
public intgetNodeIdent(int nodeHandle)

        return _adapters[nodeHandle >>> DTMManager.IDENT_DTM_NODE_BITS].getNodeIdent(nodeHandle);
    
public java.lang.StringgetNodeName(int node)

        if (node == DTM.NULL) {
            return "";
        }
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getNodeName(node);
    
public java.lang.StringgetNodeNameX(int node)

        if (node == DTM.NULL) {
            return "";
        }
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getNodeNameX(node);
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetNodeValueIterator(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iterator, int type, java.lang.String value, boolean op)

        return(new NodeValueIterator(iterator, type, value, op));
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetNthDescendant(int node, int n, boolean includeself)

        return _adapters[getDTMId(node)].getNthDescendant(node, n, includeself);
    
public com.sun.org.apache.xml.internal.serializer.SerializationHandlergetOutputDomBuilder()
Returns a DOMBuilder class wrapped in a SAX adapter.

        return _main.getOutputDomBuilder();
    
public intgetParent(int node)

        if (node == DTM.NULL) {
            return DTM.NULL;
        }
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getParent(node);
    
public com.sun.org.apache.xalan.internal.xsltc.DOMgetResultTreeFrag(int initSize, int rtfType)

        return _main.getResultTreeFrag(initSize, rtfType);
    
public com.sun.org.apache.xalan.internal.xsltc.DOMgetResultTreeFrag(int initSize, int rtfType, boolean addToManager)

        return _main.getResultTreeFrag(initSize, rtfType, addToManager);
    
public intgetSize()

        int size = 0;
        for (int i=0; i<_size; i++) {
            size += _adapters[i].getSize();
        }
        return(size);
    
public java.lang.StringgetStringValue()

        return _main.getStringValue();
    
public java.lang.StringgetStringValueX(int node)

        if (node == DTM.NULL) {
            return "";
        }
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].getStringValueX(node);
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetTypedAxisIterator(int axis, int type)

        return new AxisIterator(axis, type);
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetTypedChildren(int type)

        return new AxisIterator(Axis.CHILD, type);
    
public java.lang.StringgetUnparsedEntityURI(java.lang.String entity)

        return _main.getUnparsedEntityURI(entity);
    
public booleanisAttribute(int node)

        if (node == DTM.NULL) {
            return false;
        }
        return(_adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].isAttribute(node));
    
public booleanisElement(int node)

        if (node == DTM.NULL) {
            return false;
        }
        return(_adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].isElement(node));
    
public booleanlessThan(int node1, int node2)

        if (node1 == DTM.NULL) {
            return true;
        }
        if (node2 == DTM.NULL) {
            return false;
        }
        final int dom1 = getDTMId(node1);
        final int dom2 = getDTMId(node2);
        return dom1 == dom2 ? _adapters[dom1].lessThan(node1, node2)
                            : dom1 < dom2;
    
public java.lang.StringlookupNamespace(int node, java.lang.String prefix)

        return _main.lookupNamespace(node, prefix);
    
public org.w3c.dom.NodemakeNode(int index)

        if (index == DTM.NULL) {
            return null;
        }
        return _adapters[getDTMId(index)].makeNode(index);
    
public org.w3c.dom.NodemakeNode(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iter)

        // TODO: gather nodes from all DOMs ?
        return _main.makeNode(iter);
    
public org.w3c.dom.NodeListmakeNodeList(int index)

        if (index == DTM.NULL) {
            return null;
        }
        return _adapters[getDTMId(index)].makeNodeList(index);
    
public org.w3c.dom.NodeListmakeNodeList(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iter)

        // TODO: gather nodes from all DOMs ?
        return _main.makeNodeList(iter);
    
public intnextMask()

        return _free;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratororderNodes(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator source, int node)

        return _adapters[getDTMId(node)].orderNodes(source, node);
    
public voidsetFilter(com.sun.org.apache.xalan.internal.xsltc.StripFilter filter)

        for (int dom=0; dom<_free; dom++) {
            if (_adapters[dom] != null) {
                _adapters[dom].setFilter(filter);
            }
        }
    
public voidsetupMapping(java.lang.String[] names, java.lang.String[] uris, int[] types, java.lang.String[] namespaces)

        // This method only has a function in DOM adapters
    
public java.lang.StringshallowCopy(int node, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler)

        if (node == DTM.NULL) {
            return "";
        }
        return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].shallowCopy(node, handler);