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

SAXImpl

public final class SAXImpl extends SAX2DTM2 implements DOMEnhancedForDTM, DOMBuilder
SAXImpl is the core model for SAX input source. SAXImpl objects are usually created from an XSLTCDTMManager.

DOMSource inputs are handled using DOM2SAX + SAXImpl. SAXImpl has a few specific fields (e.g. _node2Ids, _document) to keep DOM-related information. They are used when the processing behavior between DOM and SAX has to be different. Examples of these include id function and unparsed entity.

SAXImpl extends SAX2DTM2 instead of SAX2DTM for better performance.

author
Jacek Ambroziak
author
Santiago Pericas-Geertsen
author
Morten Jorgensen
author
Douglas Sellers

Fields Summary
private int
_uriCount
private int
_prefixCount
private int[]
_xmlSpaceStack
private int
_idx
private boolean
_preserve
private static final String
XML_STRING
private static final String
XML_PREFIX
private static final String
XMLSPACE_STRING
private static final String
PRESERVE_STRING
private static final String
XMLNS_PREFIX
private static final String
XML_URI
private boolean
_escaping
private boolean
_disableEscaping
private int
_textNodeToProcess
private static final String
EMPTYSTRING
private static final DTMAxisIterator
EMPTYITERATOR
private int
_namesSize
private com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable
_nsIndex
private int
_size
private BitArray
_dontEscape
private String
_documentURI
private static int
_documentURIIndex
private Document
_document
private com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable
_node2Ids
private boolean
_hasDOMSource
private XSLTCDTMManager
_dtmManager
private Node[]
_nodes
private NodeList[]
_nodeLists
private static final String
XML_LANG_ATTRIBUTE
Constructors Summary
public SAXImpl(XSLTCDTMManager mgr, Source source, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing, boolean buildIdIndex)
Construct a SAXImpl object using the default block size.

        this(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory,
            doIndexing, DEFAULT_BLOCKSIZE, buildIdIndex, false);
    
public SAXImpl(XSLTCDTMManager mgr, Source source, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing, int blocksize, boolean buildIdIndex, boolean newNameTable)
Construct a SAXImpl object using the given block size.

        super(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory,
            doIndexing, blocksize, false, buildIdIndex, newNameTable);
      
        _dtmManager = mgr;      
        _size = blocksize;
      
        // Use a smaller size for the space stack if the blocksize is small
        _xmlSpaceStack = new int[blocksize <= 64 ? 4 : 64];
                                  
        /* From DOMBuilder */ 
        _xmlSpaceStack[0] = DTMDefaultBase.ROOTNODE;
      
        // If the input source is DOMSource, set the _document field and
        // create the node2Ids table.
        if (source instanceof DOMSource) {
            _hasDOMSource = true;
            DOMSource domsrc = (DOMSource)source;
            Node node = domsrc.getNode();
            if (node instanceof Document) {
                _document = (Document)node;
            }
            else {
                _document = node.getOwnerDocument();
            }
            _node2Ids = new Hashtable();
        }                          
    
Methods Summary
public voidcharacters(char[] ch, int start, int length)
/ /** SAX2: Receive notification of character data.

        super.characters(ch, start, length);
        
        _disableEscaping = !_escaping;  
        _textNodeToProcess = getNumberOfNodes();
    
public voidcharacters(int node, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler)
Copy the string value of a node directly to an output handler

        if (node != DTM.NULL) {
            try {
                dispatchCharactersEvents(node, handler, false);
            } catch (SAXException e) {
                throw new TransletException(e);
            }
        }
    
public voidcomment(char[] ch, int start, int length)
SAX2: Report an XML comment anywhere in the document.

        super.comment(ch, start, length);
        handleTextEscaping();
    
public voidcopy(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator nodes, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler)
Copy a node-set to an output handler

        int node;
        while ((node = nodes.next()) != DTM.NULL) {
            copy(node, handler);
        }
    
public voidcopy(com.sun.org.apache.xml.internal.serializer.SerializationHandler handler)
Copy the whole tree to an output handler

        copy(getDocument(), handler);
    
public voidcopy(int node, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler)
Performs a deep copy (ref. XSLs copy-of()) TODO: Copy namespace declarations. Can't be done until we add namespace nodes and keep track of NS prefixes TODO: Copy comment nodes

        copy(node, handler, false );
    
private final voidcopy(int node, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler, boolean isChild)

     int nodeID = makeNodeIdentity(node);
        int eType = _exptype2(nodeID);
        int type = _exptype2Type(eType);

        try {
            switch(type)
            {
                case DTM.ROOT_NODE:
                case DTM.DOCUMENT_NODE:
                    for(int c = _firstch2(nodeID); c != DTM.NULL; c = _nextsib2(c)) {
                        copy(makeNodeHandle(c), handler, true);
                    }
                    break;
                case DTM.PROCESSING_INSTRUCTION_NODE:
                    copyPI(node, handler);
                    break;
                case DTM.COMMENT_NODE:
                    handler.comment(getStringValueX(node));
                    break;
                case DTM.TEXT_NODE:
                    boolean oldEscapeSetting = false;
                    boolean escapeBit = false;

                    if (_dontEscape != null) {
                        escapeBit = _dontEscape.getBit(getNodeIdent(node));
                        if (escapeBit) {
                            oldEscapeSetting = handler.setEscaping(false);
                        }
                    }
                    
                    copyTextNode(nodeID, handler);
        
                    if (escapeBit) {
                        handler.setEscaping(oldEscapeSetting);
                    }
                    break;
                case DTM.ATTRIBUTE_NODE:
                    copyAttribute(nodeID, eType, handler);
                    break;
                case DTM.NAMESPACE_NODE:
                    handler.namespaceAfterStartElement(getNodeNameX(node), getNodeValue(node));
                    break;
                default:
                    if (type == DTM.ELEMENT_NODE) 
                    {
                        // Start element definition
                        final String name = copyElement(nodeID, eType, handler);
                        //if(isChild) => not to copy any namespaces  from parents
                        // else copy all namespaces in scope
                        copyNS(nodeID, handler,!isChild);
                        copyAttributes(nodeID, handler);
                        // Copy element children
                        for (int c = _firstch2(nodeID); c != DTM.NULL; c = _nextsib2(c)) {
                            copy(makeNodeHandle(c), handler, true);
                        }
          
                        // Close element definition
                        handler.endElement(name);
                    }
                    // Shallow copy of attribute to output handler
                    else {
                        final String uri = getNamespaceName(node);
                        if (uri.length() != 0) {
                            final String prefix = getPrefix(node);
                            handler.namespaceAfterStartElement(prefix, uri);
                        }
                        handler.addAttribute(getNodeName(node), getNodeValue(node));
                    }
                    break;
            }
        } 
        catch (Exception e) {
            throw new TransletException(e);
        }
    
    
private voidcopyPI(int node, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler)
Copies a processing instruction node to an output handler

        final String target = getNodeName(node);
        final String value = getStringValueX(node);
      
        try {
            handler.processingInstruction(target, value);
        } catch (Exception e) {
            throw new TransletException(e);
        }
    
private voiddefinePrefixAndUri(java.lang.String prefix, java.lang.String uri)

        // Check if the URI already exists before pushing on stack
        Integer eType = new Integer(getIdForNamespace(uri));
        if ((Integer)_nsIndex.get(eType) == null) {
            _nsIndex.put(eType, new Integer(_uriCount++));
        }
    
public voidendDocument()
SAX2: Receive notification of the end of a document.

        super.endDocument();
        
        handleTextEscaping();
        _namesSize = m_expandedNameTable.getSize();
    
public voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qname)
SAX2: Receive notification of the end of an element.

        super.endElement(namespaceURI, localName, qname);
        
        handleTextEscaping();

        // Revert to strip/preserve-space setting from before this element
        if (m_wsfilter != null) {
            xmlSpaceRevert(m_previous);
        }
    
public intgetAttributeNode(int type, int element)
Returns the attribute node of a given type (if any) for an element

        for (int attr = getFirstAttribute(element);
           attr != DTM.NULL;
           attr = getNextAttribute(attr))
        {
            if (getExpandedTypeID(attr) == type) return attr;
        }
        return DTM.NULL;
    
public java.lang.StringgetAttributeValue(int type, int element)
Returns the value of a given attribute type of a given element

        final int attr = getAttributeNode(type, element);
        return (attr != DTM.NULL) ? getStringValueX(attr) : EMPTYSTRING;
    
public java.lang.StringgetAttributeValue(java.lang.String name, int element)
This method is for testing/debugging only

        return getAttributeValue(getGeneralizedType(name), element);
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetAxisIterator(int axis)
This is a shortcut to the iterators that implement the supported XPath axes (only namespace::) is not supported. Returns a bare-bones iterator that must be initialized with a start node (using iterator.setStartNode()).

        switch (axis)
        {
            case Axis.SELF:
                return new SingletonIterator();
            case Axis.CHILD:
                return new ChildrenIterator();
            case Axis.PARENT:
                return new ParentIterator();
            case Axis.ANCESTOR:
                return new AncestorIterator();
            case Axis.ANCESTORORSELF:
                return (new AncestorIterator()).includeSelf();
            case Axis.ATTRIBUTE:
                return new AttributeIterator();
            case Axis.DESCENDANT:
                return new DescendantIterator();
            case Axis.DESCENDANTORSELF:
                return (new DescendantIterator()).includeSelf();
            case Axis.FOLLOWING:
                return new FollowingIterator();
            case Axis.PRECEDING:
                return new PrecedingIterator();
            case Axis.FOLLOWINGSIBLING:
                return new FollowingSiblingIterator();
            case Axis.PRECEDINGSIBLING:
                return new PrecedingSiblingIterator();
            case Axis.NAMESPACE:
                return new NamespaceIterator();
            case Axis.ROOT:
                return new RootIterator();
            default:
                BasisLibrary.runTimeError(BasisLibrary.AXIS_SUPPORT_ERR, 
                        Axis.getNames(axis));
        }
        return null;
    
public com.sun.org.apache.xalan.internal.xsltc.dom.DOMBuildergetBuilder()
Returns an instance of the DOMBuilder inner class This class will consume the input document through a SAX2 interface and populate the tree.

	return this;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetChildren(int node)
Returns an iterator with all the children of a given node

        return (new ChildrenIterator()).setStartNode(node);
    
public java.lang.StringgetDocumentURI()
Returns the origin of the document from which the tree was built

        String baseURI = getDocumentBaseURI();
        return (baseURI != null) ? baseURI : "rtf" + _documentURIIndex++;
    
public java.lang.StringgetDocumentURI(int node)

        return getDocumentURI();
    
public intgetElementById(java.lang.String idString)
Return the node identity for a given id String

param
idString The id String
return
The identity of the node whose id is the given String.

        Node node = _document.getElementById(idString);
        if (node != null) {
            Integer id = (Integer)_node2Ids.get(node);
            return (id != null) ? id.intValue() : DTM.NULL;
        }
        else {
            return DTM.NULL;
        }
    
public com.sun.org.apache.xalan.internal.xsltc.runtime.HashtablegetElementsWithIDs()
%HZ% Need Javadoc

        if (m_idAttributes == null) {
            return null;
        }

        // Convert a java.util.Hashtable to an xsltc.runtime.Hashtable
        Enumeration idValues = m_idAttributes.keys();
        if (!idValues.hasMoreElements()) {
            return null;
        }

        Hashtable idAttrsTable = new Hashtable();

        while (idValues.hasMoreElements()) {
            Object idValue = idValues.nextElement();

            idAttrsTable.put(idValue, m_idAttributes.get(idValue));
        }

        return idAttrsTable;
    
public intgetGeneralizedType(java.lang.String name)
Returns the internal type associated with an expanded QName

        return getGeneralizedType(name, true);
    
public intgetGeneralizedType(java.lang.String name, boolean searchOnly)
Returns the internal type associated with an expanded QName

        String lName, ns = null;
        int index = -1;
        int code;

        // Is there a prefix?
        if ((index = name.lastIndexOf(":"))> -1) {
            ns = name.substring(0, index);
        }

        // Local part of name is after colon.  lastIndexOf returns -1 if
        // there is no colon, so lNameStartIdx will be zero in that case.
        int lNameStartIdx = index+1;

        // Distinguish attribute and element names.  Attribute has @ before
        // local part of name.
        if (name.charAt(lNameStartIdx) == '@") {
            code = DTM.ATTRIBUTE_NODE;
            lNameStartIdx++;
        }
        else {
            code = DTM.ELEMENT_NODE;
        }

        // Extract local name
        lName = (lNameStartIdx == 0) ? name : name.substring(lNameStartIdx);

        return m_expandedNameTable.getExpandedTypeID(ns, lName, code, searchOnly);
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetIterator()
Returns singleton iterator containg the document root Works for them main document (mark == 0). It cannot be made to point to any other node through setStartNode().

        return new SingletonIterator(getDocument(), true);
    
public java.lang.StringgetLanguage(int node)
Returns a node' defined language for a node (if any)

        int parent = node;
    	while (DTM.NULL != parent) {
            if (DTM.ELEMENT_NODE == getNodeType(parent)) {
                int langAttr = getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

                if (DTM.NULL != langAttr) {
                    return getNodeValue(langAttr);     
                }
            }

            parent = getParent(parent);
        }      
        return(null);
    
public short[]getMapping(java.lang.String[] names, java.lang.String[] uris, int[] types)
Get mapping from DOM element/attribute types to external types

        // Delegate the work to getMapping2 if the document is not fully built.
        // Some of the processing has to be different in this case.
        if (_namesSize < 0) {
            return getMapping2(names, uris, types);
        }

        int i;
        final int namesLength = names.length;
        final int exLength = m_expandedNameTable.getSize();
      
        final short[] result = new short[exLength];

        // primitive types map to themselves
        for (i = 0; i < DTM.NTYPES; i++) {
            result[i] = (short)i;
        }
        
        for (i = NTYPES; i < exLength; i++) { 
      	    result[i] = m_expandedNameTable.getType(i);
      	}
      	
        // actual mapping of caller requested names
        for (i = 0; i < namesLength; i++) {
            int genType = m_expandedNameTable.getExpandedTypeID(uris[i],
                                                                names[i],
                                                                types[i],
                                                                true);
            if (genType >= 0 && genType < exLength) {
                result[genType] = (short)(i + DTM.NTYPES);
            }
        }

        return result;
    
private short[]getMapping2(java.lang.String[] names, java.lang.String[] uris, int[] types)
Get mapping from DOM element/attribute types to external types. This method is used when the document is not fully built.

        int i;
        final int namesLength = names.length;
        final int exLength = m_expandedNameTable.getSize();
        int[] generalizedTypes = null;
        if (namesLength > 0) {
            generalizedTypes = new int[namesLength];
        }

        int resultLength = exLength;

        for (i = 0; i < namesLength; i++) {
            // When the document is not fully built, the searchOnly
            // flag should be set to false. That means we should add
            // the type if it is not already in the expanded name table.
            //generalizedTypes[i] = getGeneralizedType(names[i], false);
            generalizedTypes[i] =
                m_expandedNameTable.getExpandedTypeID(uris[i],
                                                      names[i],
                                                      types[i],
                                                      false);
            if (_namesSize < 0 && generalizedTypes[i] >= resultLength) {
                resultLength = generalizedTypes[i] + 1;
            }
        }

        final short[] result = new short[resultLength];

        // primitive types map to themselves
        for (i = 0; i < DTM.NTYPES; i++) {
            result[i] = (short)i;
        }

        for (i = NTYPES; i < exLength; i++) {
            result[i] = m_expandedNameTable.getType(i);
        }

        // actual mapping of caller requested names
        for (i = 0; i < namesLength; i++) {
            int genType = generalizedTypes[i];
            if (genType >= 0 && genType < resultLength) {
                result[genType] = (short)(i + DTM.NTYPES);
            }
        }

        return(result);
    
public intgetNSType(int node)
Get mapping from DOM namespace types to external namespace types

    	String s = getNamespaceURI(node);
    	if (s == null) {
    	    return 0;
    	}
    	int eType = getIdForNamespace(s);
    	return ((Integer)_nsIndex.get(new Integer(eType))).intValue();        
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetNamespaceAxisIterator(int axis, int ns)
Do not think that this returns an iterator for the namespace axis. It returns an iterator with nodes that belong in a certain namespace, such as with The 'axis' specifies the axis for the base iterator from which the nodes are taken, while 'ns' specifies the namespace URI type.


        DTMAxisIterator iterator = null;

        if (ns == NO_TYPE) {
            return EMPTYITERATOR;
        }
        else {
            switch (axis) {
                case Axis.CHILD:
                    return new NamespaceChildrenIterator(ns);
                case Axis.ATTRIBUTE:
                    return new NamespaceAttributeIterator(ns);
                default:
                    return new NamespaceWildcardIterator(axis, ns);
            }
        }
    
public short[]getNamespaceMapping(java.lang.String[] namespaces)
Get mapping from DOM namespace types to external namespace types

        int i;
        final int nsLength = namespaces.length;
        final int mappingLength = _uriCount;

        final short[] result = new short[mappingLength];

        // Initialize all entries to -1
        for (i=0; i<mappingLength; i++) {
            result[i] = (short)(-1);
        }

        for (i=0; i<nsLength; i++) {
            int eType = getIdForNamespace(namespaces[i]); 
            Integer type = (Integer)_nsIndex.get(new Integer(eType));
            if (type != null) {
                result[type.intValue()] = (short)i;
            }
        }

        return(result);
    
public java.lang.StringgetNamespaceName(int node)
Returns the namespace URI to which a node belongs

    	if (node == DTM.NULL) {
    	    return "";
    	}
    	
        String s;
        return (s = getNamespaceURI(node)) == null ? EMPTYSTRING : s;
    
public intgetNamespaceType(int node)
Returns the namespace type of a specific node

    	return super.getNamespaceType(node);
    
public java.lang.StringgetNodeName(int node)
Returns the name of a node (attribute or element).

	// Get the node type and make sure that it is within limits
	int nodeh = node;
	final short type = getNodeType(nodeh);
	switch(type)
        {
	    case DTM.ROOT_NODE:
	    case DTM.DOCUMENT_NODE:
	    case DTM.TEXT_NODE:
	    case DTM.COMMENT_NODE:
	        return EMPTYSTRING;
	    case DTM.NAMESPACE_NODE:
		return this.getLocalName(nodeh);
	    default:
	        return super.getNodeName(nodeh);
	}
    
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(DTMAxisIterator)(new NodeValueIterator(iterator, type, value, op));
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetNthDescendant(int type, int n, boolean includeself)
Returns the nth descendant of a node

        DTMAxisIterator source = (DTMAxisIterator) new TypedDescendantIterator(type);
        return new NthDescendantIterator(n);
    
public com.sun.org.apache.xml.internal.serializer.SerializationHandlergetOutputDomBuilder()
Return a SerializationHandler for output handling. This method is used by Result Tree Fragments.

        return new ToXMLSAXHandler(this, "UTF-8");
    
public com.sun.org.apache.xalan.internal.xsltc.DOMgetResultTreeFrag(int initSize, int rtfType)
Return a instance of a DOM class to be used as an RTF

        return getResultTreeFrag(initSize, rtfType, true);
    
public com.sun.org.apache.xalan.internal.xsltc.DOMgetResultTreeFrag(int initSize, int rtfType, boolean addToManager)
Return a instance of a DOM class to be used as an RTF

param
initSize The initial size of the DOM.
param
rtfType The type of the RTF
param
addToManager true if the RTF should be registered with the DTMManager.
return
The DOM object which represents the RTF.

    	if (rtfType == DOM.SIMPLE_RTF) {
            if (addToManager) {
                int dtmPos = _dtmManager.getFirstFreeDTMID();
    	        SimpleResultTreeImpl rtf = new SimpleResultTreeImpl(_dtmManager,
    	                                   dtmPos << DTMManager.IDENT_DTM_NODE_BITS);
    	        _dtmManager.addDTM(rtf, dtmPos, 0);
    	        return rtf;
    	    }
            else {
            	return new SimpleResultTreeImpl(_dtmManager, 0);
            }
    	}
    	else if (rtfType == DOM.ADAPTIVE_RTF) {
            if (addToManager) {
                int dtmPos = _dtmManager.getFirstFreeDTMID();
    	        AdaptiveResultTreeImpl rtf = new AdaptiveResultTreeImpl(_dtmManager,
    	                               dtmPos << DTMManager.IDENT_DTM_NODE_BITS,
    	                               m_wsfilter, initSize, m_buildIdIndex);
    	        _dtmManager.addDTM(rtf, dtmPos, 0);
    	        return rtf;
    	
    	    }
    	    else {
            	return new AdaptiveResultTreeImpl(_dtmManager, 0,
    	                               m_wsfilter, initSize, m_buildIdIndex);
            }    	
    	}
    	else {
    	    return (DOM) _dtmManager.getDTM(null, true, m_wsfilter,
                                            true, false, false,
                                            initSize, m_buildIdIndex);
        }
    
public int[]getReverseMapping(java.lang.String[] names, java.lang.String[] uris, int[] types)
Get mapping from external element/attribute types to DOM types

        int i;
        final int[] result = new int[names.length + DTM.NTYPES];
        
        // primitive types map to themselves
        for (i = 0; i < DTM.NTYPES; i++) {
            result[i] = i;
        }
        
        // caller's types map into appropriate dom types
        for (i = 0; i < names.length; i++) {
            int type = m_expandedNameTable.getExpandedTypeID(uris[i], names[i], types[i], true);
            result[i+DTM.NTYPES] = type;
        }
        return(result);
    
public short[]getReverseNamespaceMapping(java.lang.String[] namespaces)
Get mapping from external namespace types to DOM namespace types

        int i;
        final int length = namespaces.length;
        final short[] result = new short[length];

        for (i = 0; i < length; i++) {
            int eType = getIdForNamespace(namespaces[i]);
            Integer type = (Integer)_nsIndex.get(new Integer(eType));
            result[i] = (type == null) ? -1 : type.shortValue();
        }

        return result;
    
protected booleangetShouldStripWhitespace()
Find out whether or not to strip whitespace nodes.

return
whether or not to strip whitespace nodes.

        return _preserve ? false : super.getShouldStripWhitespace();
    
public intgetSize()
Returns the number of nodes in the tree (used for indexing)

        return getNumberOfNodes();
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetTypedAxisIterator(int axis, int type)
Similar to getAxisIterator, but this one returns an iterator containing nodes of a typed axis (ex.: child::foo)

        // Most common case handled first
        if (axis == Axis.CHILD) {
            return new TypedChildrenIterator(type);
        }

        if (type == NO_TYPE) {
            return(EMPTYITERATOR);
        }

        switch (axis)
        {
            case Axis.SELF:
                return new TypedSingletonIterator(type);
            case Axis.CHILD:
                return new TypedChildrenIterator(type);
            case Axis.PARENT:
                return new ParentIterator().setNodeType(type);
            case Axis.ANCESTOR:
                return new TypedAncestorIterator(type);
            case Axis.ANCESTORORSELF:
                return (new TypedAncestorIterator(type)).includeSelf();
            case Axis.ATTRIBUTE:
                return new TypedAttributeIterator(type);
            case Axis.DESCENDANT:
                return new TypedDescendantIterator(type);
            case Axis.DESCENDANTORSELF:
                return (new TypedDescendantIterator(type)).includeSelf();
            case Axis.FOLLOWING:
                return new TypedFollowingIterator(type);
            case Axis.PRECEDING:
                return new TypedPrecedingIterator(type);
            case Axis.FOLLOWINGSIBLING:
                return new TypedFollowingSiblingIterator(type);
            case Axis.PRECEDINGSIBLING:
                return new TypedPrecedingSiblingIterator(type);
            case Axis.NAMESPACE:
                return  new TypedNamespaceIterator(type);
            case Axis.ROOT:
                return new TypedRootIterator(type);
            default:
                BasisLibrary.runTimeError(BasisLibrary.TYPED_AXIS_SUPPORT_ERR, 
                        Axis.getNames(axis));
        }
        return null;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetTypedChildren(int type)
Returns an iterator with all children of a specific type for a given node (element)

        return(new TypedChildrenIterator(type));
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetTypedDescendantIterator(int type)
Returns an iterator with all descendants of a node that are of a given type.

        return new TypedDescendantIterator(type);
    
public java.lang.StringgetUnparsedEntityURI(java.lang.String name)
The getUnparsedEntityURI function returns the URI of the unparsed entity with the specified name in the same document as the context node (see [3.3 Unparsed Entities]). It returns the empty string if there is no such entity.

        // Special handling for DOM input
        if (_document != null) {
            String uri = "";
            DocumentType doctype = _document.getDoctype();
            if (doctype != null) {
                NamedNodeMap entities = doctype.getEntities();
                
                if (entities == null) {
                    return uri;
                }
                
                Entity entity = (Entity) entities.getNamedItem(name);
                
                if (entity == null) {
                    return uri;
                }
                
                String notationName = entity.getNotationName();
                if (notationName != null) {
                    uri = entity.getSystemId();
                    if (uri == null) {
                        uri = entity.getPublicId();
                    }
                }
            }
            return uri;
        }
        else {
            return super.getUnparsedEntityURI(name);
        }	
    
private voidhandleTextEscaping()
Creates a text-node and checks if it is a whitespace node.

        if (_disableEscaping && _textNodeToProcess != DTM.NULL
            && _type(_textNodeToProcess) == DTM.TEXT_NODE) {
            if (_dontEscape == null) {
                _dontEscape = new BitArray(_size);
            }
          
            // Resize the _dontEscape BitArray if necessary.
            if (_textNodeToProcess >= _dontEscape.size()) {
                _dontEscape.resize(_dontEscape.size() * 2);
            }
          
            _dontEscape.setBit(_textNodeToProcess);
            _disableEscaping = false;
        }
        _textNodeToProcess = DTM.NULL;
    
public booleanhasDOMSource()
Return true if the input source is DOMSource.

        return _hasDOMSource;	
    
public voidignorableWhitespace(char[] ch, int start, int length)
SAX2: Receive notification of ignorable whitespace in element content. Similar to characters(char[], int, int).

        super.ignorableWhitespace(ch, start, length);
        _textNodeToProcess = getNumberOfNodes();
    
public booleanisAttribute(int node)
Returns 'true' if a specific node is an attribute (of any type)

        return getNodeType(node) == DTM.ATTRIBUTE_NODE;
    
public booleanisElement(int node)
Returns 'true' if a specific node is an element (of any type)

        return getNodeType(node) == DTM.ELEMENT_NODE;
    
public booleanlessThan(int node1, int node2)
Returns true if node1 comes before node2 in document order

        if (node1 == DTM.NULL) {
            return false;
        }

        if (node2 == DTM.NULL) {
            return true;
        }

        return (node1 < node2);
    
public java.lang.StringlookupNamespace(int node, java.lang.String prefix)
Lookup a namespace URI from a prefix starting at node. This method is used in the execution of xsl:element when the prefix is not known at compile time.

        int anode, nsnode;
        final AncestorIterator ancestors = new AncestorIterator();

        if (isElement(node)) {
            ancestors.includeSelf();
        }

        ancestors.setStartNode(node);
        while ((anode = ancestors.next()) != DTM.NULL) {
            final NamespaceIterator namespaces = new NamespaceIterator();

            namespaces.setStartNode(anode);
            while ((nsnode = namespaces.next()) != DTM.NULL) {
                if (getLocalName(nsnode).equals(prefix)) {
                    return getNodeValue(nsnode);
                }
            }
        }

        BasisLibrary.runTimeError(BasisLibrary.NAMESPACE_PREFIX_ERR, prefix);
        return null;
    
public org.w3c.dom.NodemakeNode(int index)
Create an org.w3c.dom.Node from a node in the tree

        if (_nodes == null) {
            _nodes = new Node[_namesSize];
        }

        int nodeID = makeNodeIdentity(index);
        if (nodeID < 0) {
            return null;
        }
        else if (nodeID < _nodes.length) {
            return (_nodes[nodeID] != null) ? _nodes[nodeID] 
                : (_nodes[nodeID] = new DTMNodeProxy((DTM)this, index));
        }
        else {
            return new DTMNodeProxy((DTM)this, index);
        }
    
public org.w3c.dom.NodemakeNode(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iter)
Create an org.w3c.dom.Node from a node in an iterator The iterator most be started before this method is called

        return makeNode(iter.next());
    
public org.w3c.dom.NodeListmakeNodeList(int index)
Create an org.w3c.dom.NodeList from a node in the tree

        if (_nodeLists == null) {
            _nodeLists = new NodeList[_namesSize];
        }
        
        int nodeID = makeNodeIdentity(index);
        if (nodeID < 0) {
            return null;
        }
        else if (nodeID < _nodeLists.length) {
            return (_nodeLists[nodeID] != null) ? _nodeLists[nodeID]
                   : (_nodeLists[nodeID] = new DTMAxisIterNodeList(this,
                                                 new SingletonIterator(index)));
    }
        else {
            return new DTMAxisIterNodeList(this, new SingletonIterator(index));
        }
    
public org.w3c.dom.NodeListmakeNodeList(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iter)
Create an org.w3c.dom.NodeList from a node iterator The iterator most be started before this method is called

        return new DTMAxisIterNodeList(this, iter);
    
public voidmigrateTo(com.sun.org.apache.xml.internal.dtm.DTMManager manager)
Migrate a DTM built with an old DTMManager to a new DTMManager. After the migration, the new DTMManager will treat the DTM as one that is built by itself. This is used to support DTM sharing between multiple transformations.

param
manager the DTMManager

    	super.migrateTo(manager);
    	if (manager instanceof XSLTCDTMManager) {
    	    _dtmManager = (XSLTCDTMManager)manager;
    	}
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratororderNodes(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator source, int node)
Encapsulates an iterator in an OrderedIterator to ensure node order

        return new DupFilterIterator(source);
    
public voidprint(int node, int level)
Prints the whole tree to standard output

        switch(getNodeType(node))
        {
	    case DTM.ROOT_NODE:
	    case DTM.DOCUMENT_NODE:
	        print(getFirstChild(node), level);
	        break;
	    case DTM.TEXT_NODE:
	    case DTM.COMMENT_NODE:
	    case DTM.PROCESSING_INSTRUCTION_NODE:
	        System.out.print(getStringValueX(node));
	        break;
	    default:
	        final String name = getNodeName(node);
	        System.out.print("<" + name);
	        for (int a = getFirstAttribute(node); a != DTM.NULL; a = getNextAttribute(a))
                {
		    System.out.print("\n" + getNodeName(a) + "=\"" + getStringValueX(a) + "\"");
	        }
	        System.out.print('>");
	        for (int child = getFirstChild(node); child != DTM.NULL;
		    child = getNextSibling(child)) {
		    print(child, level + 1);
	        }
	        System.out.println("</" + name + '>");
	        break;
	}
    
public voidprocessingInstruction(java.lang.String target, java.lang.String data)
SAX2: Receive notification of a processing instruction.

        super.processingInstruction(target, data);
        handleTextEscaping();
    
public voidsetDocumentURI(java.lang.String uri)
Define the origin of the document from which the tree was built


                     
        
        if (uri != null) {
            setDocumentBaseURI(SystemIDResolver.getAbsoluteURI(uri));
        }
    
public booleansetEscaping(boolean value)

        final boolean temp = _escaping;
        _escaping = value; 
        return temp;
    
public voidsetFilter(com.sun.org.apache.xalan.internal.xsltc.StripFilter filter)
Part of the DOM interface - no function here.

    
private int[]setupMapping(java.lang.String[] names, java.lang.String[] uris, int[] types, int nNames)
Sets up a translet-to-dom type mapping table

        // Padding with number of names, because they
        // may need to be added, i.e for RTFs. See copy03  
        final int[] result = new int[m_expandedNameTable.getSize()];
        for (int i = 0; i < nNames; i++)      {
            //int type = getGeneralizedType(namesArray[i]);
            int type = m_expandedNameTable.getExpandedTypeID(uris[i], names[i], types[i], false);
            result[type] = type;
        }
        return result;
    
public voidsetupMapping(java.lang.String[] names, java.lang.String[] urisArray, int[] typesArray, 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)
Performs a shallow copy (ref. XSLs copy())

        int nodeID = makeNodeIdentity(node);
        int exptype = _exptype2(nodeID);
        int type = _exptype2Type(exptype);
      
        try {
            switch(type)
            {
                case DTM.ELEMENT_NODE:
                    final String name = copyElement(nodeID, exptype, handler);
                    copyNS(nodeID, handler, true);
                    return name;
                case DTM.ROOT_NODE:
                case DTM.DOCUMENT_NODE:
                    return EMPTYSTRING;
                case DTM.TEXT_NODE:
                    copyTextNode(nodeID, handler);
                    return null;
                case DTM.PROCESSING_INSTRUCTION_NODE:
                    copyPI(node, handler);
                    return null;
                case DTM.COMMENT_NODE:
                    handler.comment(getStringValueX(node));
                    return null;
                case DTM.NAMESPACE_NODE:
                    handler.namespaceAfterStartElement(getNodeNameX(node), getNodeValue(node));
                    return null;
                case DTM.ATTRIBUTE_NODE:
                    copyAttribute(nodeID, exptype, handler);
                    return null;  
                default:
                    final String uri1 = getNamespaceName(node);
                    if (uri1.length() != 0) {
                        final String prefix = getPrefix(node);
                        handler.namespaceAfterStartElement(prefix, uri1);
                    }
                    handler.addAttribute(getNodeName(node), getNodeValue(node));
                    return null;
            }
        } catch (Exception e) {
            throw new TransletException(e);
        }   
    
public voidstartDocument()
SAX2: Receive notification of the beginning of a document.

        super.startDocument();

        _nsIndex.put(new Integer(0), new Integer(_uriCount++));
        definePrefixAndUri(XML_PREFIX, XML_URI);
    
public voidstartElement(java.lang.String uri, java.lang.String localName, java.lang.String qname, org.xml.sax.Attributes attributes, org.w3c.dom.Node node)
Specialized interface used by DOM2SAX. This one has an extra Node parameter to build the Node -> id map.

    	this.startElement(uri, localName, qname, attributes);
    	
    	if (m_buildIdIndex) {
    	    _node2Ids.put(node, new Integer(m_parents.peek()));
    	}
    
public voidstartElement(java.lang.String uri, java.lang.String localName, java.lang.String qname, org.xml.sax.Attributes attributes)
SAX2: Receive notification of the beginning of an element.

        super.startElement(uri, localName, qname, attributes);
        
        handleTextEscaping();

        if (m_wsfilter != null) {
            // Look for any xml:space attributes
            // Depending on the implementation of attributes, this
            // might be faster than looping through all attributes. ILENE
            final int index = attributes.getIndex(XMLSPACE_STRING);
            if (index >= 0) {
                xmlSpaceDefine(attributes.getValue(index), m_parents.peek());
            }
        }
    
public voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)
SAX2: Begin the scope of a prefix-URI Namespace mapping.

        super.startPrefixMapping(prefix, uri);
        handleTextEscaping();

        definePrefixAndUri(prefix, uri);
    
private voidxmlSpaceDefine(java.lang.String val, int node)
Call this when an xml:space attribute is encountered to define the whitespace strip/preserve settings.

        final boolean setting = val.equals(PRESERVE_STRING);
        if (setting != _preserve) {
            _xmlSpaceStack[_idx++] = node;
            _preserve = setting;
        }
    
private voidxmlSpaceRevert(int node)
Call this from endElement() to revert strip/preserve setting to whatever it was before the corresponding startElement().

        if (node == _xmlSpaceStack[_idx - 1]) {
            _idx--;
            _preserve = !_preserve;
        }