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

SimpleResultTreeImpl

public class SimpleResultTreeImpl extends EmptySerializer implements DOM, DTM
This class represents a light-weight DOM model for simple result tree fragment(RTF). A simple RTF is an RTF that has only one Text node. The Text node can be produced by a combination of Text, xsl:value-of and xsl:number instructions. It can also be produced by a control structure (xsl:if or xsl:choose) whose body is pure Text.

A SimpleResultTreeImpl has only two nodes, i.e. the ROOT node and its Text child. All DOM interfaces are overridden with this in mind. For example, the getStringValue() interface returns the value of the Text node. This class receives the character data from the characters() interface.

This class implements DOM and SerializationHandler. It also implements the DTM interface for support in MultiDOM. The nested iterators (SimpleIterator and SingletonIterator) are used to support the nodeset() extension function.

Fields Summary
private static final DTMAxisIterator
EMPTY_ITERATOR
public static final int
RTF_ROOT
public static final int
RTF_TEXT
public static final int
NUMBER_OF_NODES
private static int
_documentURIIndex
private static final String
EMPTY_STR
private String
_text
protected String[]
_textArray
protected XSLTCDTMManager
_dtmManager
protected int
_size
private int
_documentID
private BitArray
_dontEscape
private boolean
_escaping
Constructors Summary
public SimpleResultTreeImpl(XSLTCDTMManager dtmManager, int documentID)

    
    // Create a SimpleResultTreeImpl from a DTMManager and a document ID.
        
    
        _dtmManager = dtmManager;
        _documentID = documentID;
        _textArray = new String[4];
    
Methods Summary
public voidappendChild(int newChild, boolean clone, boolean cloneDepth)

    
public voidappendTextChild(java.lang.String str)

    
public voidcharacters(int node, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler)
Dispatch the character content of a node to an output handler. The escape setting should be taken care of when outputting to a handler.

        int nodeID = getNodeIdent(node);
        if (nodeID == RTF_ROOT || nodeID == RTF_TEXT) {
            boolean escapeBit = false;
            boolean oldEscapeSetting = false;

            try {
                for (int i = 0; i < _size; i++) {

                    if (_dontEscape != null) {
                        escapeBit = _dontEscape.getBit(i);
                        if (escapeBit) {
                            oldEscapeSetting = handler.setEscaping(false);
                        }
                    }
                
                    handler.characters(_textArray[i]);
                
                    if (escapeBit) {
                        handler.setEscaping(oldEscapeSetting);
                    }
                }
            } catch (SAXException e) {
                throw new TransletException(e);
            }
        }
    
public voidcharacters(java.lang.String str)

        // Resize the text array if necessary
        if (_size >= _textArray.length) {
            String[] newTextArray = new String[_textArray.length * 2];
            System.arraycopy(_textArray, 0, newTextArray, 0, _textArray.length);
            _textArray = newTextArray;
        }
        
        // If the escape setting is false, set the corresponding bit in
        // the _dontEscape BitArray.
        if (!_escaping) {
            // The _dontEscape array is only created when needed.
            if (_dontEscape == null) {
                _dontEscape = new BitArray(8);
            }
            
            // Resize the _dontEscape array if necessary
            if (_size >= _dontEscape.size())
                _dontEscape.resize(_dontEscape.size() * 2);
            
            _dontEscape.setBit(_size);
        }
        
        _textArray[_size++] = str;
    
public voidcharacters(char[] ch, int offset, int length)

        if (_size >= _textArray.length) {
            String[] newTextArray = new String[_textArray.length * 2];
            System.arraycopy(_textArray, 0, newTextArray, 0, _textArray.length);
            _textArray = newTextArray;
        }

        if (!_escaping) {
            if (_dontEscape == null) {
                _dontEscape = new BitArray(8);
            }
            
            if (_size >= _dontEscape.size())
                _dontEscape.resize(_dontEscape.size() * 2);
            
            _dontEscape.setBit(_size);
        }
       
        _textArray[_size++] = new String(ch, offset, length);
        
    
public voidcopy(int node, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler)

        characters(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)
        {
            copy(node, handler);
        }
    
public voiddispatchCharactersEvents(int nodeHandle, org.xml.sax.ContentHandler ch, boolean normalize)

    
public voiddispatchToEvents(int nodeHandle, org.xml.sax.ContentHandler ch)

    
public voiddocumentRegistration()

    
public voiddocumentRelease()

    
public voidendDocument()

        // Set the String value when the document is built.
        if (_size == 1)
            _text = _textArray[0];
        else {
            StringBuffer buffer = new StringBuffer();
            for (int i = 0; i < _size; i++) {
                buffer.append(_textArray[i]);
            }
            _text = buffer.toString();
        }
    
public intgetAttributeNode(int gType, int element)

        return DTM.NULL;
    
public intgetAttributeNode(int elementHandle, java.lang.String namespaceURI, java.lang.String name)

        return DTM.NULL;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetAxisIterator(int axis)

        switch (axis)
        {
            case Axis.CHILD:
            case Axis.DESCENDANT:
                return new SimpleIterator(SimpleIterator.DIRECTION_DOWN);
            case Axis.PARENT:
            case Axis.ANCESTOR:
                return new SimpleIterator(SimpleIterator.DIRECTION_UP);
            case Axis.ANCESTORORSELF:
                return (new SimpleIterator(SimpleIterator.DIRECTION_UP)).includeSelf();
            case Axis.DESCENDANTORSELF:
                return (new SimpleIterator(SimpleIterator.DIRECTION_DOWN)).includeSelf();
            case Axis.SELF:
                return new SingletonIterator();
            default:
                return EMPTY_ITERATOR;
        }
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisTraversergetAxisTraverser(int axis)

        return null;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetChildren(int node)

        return new SimpleIterator().setStartNode(node);
    
public org.xml.sax.ContentHandlergetContentHandler()

        return null;
    
public org.xml.sax.DTDHandlergetDTDHandler()

        return null;
    
public com.sun.org.apache.xml.internal.dtm.ref.DTMManagerDefaultgetDTMManager()

        return _dtmManager;	
    
public org.xml.sax.ext.DeclHandlergetDeclHandler()

        return null;
    
public intgetDocument()

        return _documentID;
    
public booleangetDocumentAllDeclarationsProcessed()

        return false;
    
public java.lang.StringgetDocumentBaseURI()

        return EMPTY_STR;
    
public java.lang.StringgetDocumentEncoding(int nodeHandle)

        return null;
    
public intgetDocumentRoot(int nodeHandle)

        return getDocument();
    
public java.lang.StringgetDocumentStandalone(int nodeHandle)

        return null;
    
public java.lang.StringgetDocumentSystemIdentifier(int nodeHandle)

        return null;
    
public java.lang.StringgetDocumentTypeDeclarationPublicIdentifier()

        return null;
    
public java.lang.StringgetDocumentTypeDeclarationSystemIdentifier()

        return null;
    
public java.lang.StringgetDocumentURI(int node)

        return "simple_rtf" + _documentURIIndex++;
    
public java.lang.StringgetDocumentVersion(int documentHandle)

        return null;
    
public intgetElementById(java.lang.String elementId)

        return DTM.NULL;
    
public com.sun.org.apache.xalan.internal.xsltc.runtime.HashtablegetElementsWithIDs()

        return null;
    
public org.xml.sax.EntityResolvergetEntityResolver()

        return null;
    
public org.xml.sax.ErrorHandlergetErrorHandler()

        return null;
    
public intgetExpandedTypeID(int nodeHandle)

        int nodeID = getNodeIdent(nodeHandle);
        if (nodeID == RTF_TEXT)
            return DTM.TEXT_NODE;
        else if (nodeID == RTF_ROOT)
            return DTM.ROOT_NODE;
        else
            return DTM.NULL;
    
public intgetExpandedTypeID(java.lang.String namespace, java.lang.String localName, int type)

        return DTM.NULL;
    
public intgetFirstAttribute(int nodeHandle)

        return DTM.NULL;
    
public intgetFirstChild(int nodeHandle)

        int nodeID = getNodeIdent(nodeHandle);
        if (nodeID == RTF_ROOT)
            return getNodeHandle(RTF_TEXT);
        else
            return DTM.NULL;
    
public intgetFirstNamespaceNode(int nodeHandle, boolean inScope)

        return DTM.NULL;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetIterator()

        return new SingletonIterator(getDocument());
    
public java.lang.StringgetLanguage(int node)

        return null;
    
public intgetLastChild(int nodeHandle)

        return getFirstChild(nodeHandle);
    
public shortgetLevel(int nodeHandle)

        int nodeID = getNodeIdent(nodeHandle);
        if (nodeID == RTF_TEXT)
            return 2;
        else if (nodeID == RTF_ROOT)
            return 1;
        else
            return DTM.NULL;            
    
public org.xml.sax.ext.LexicalHandlergetLexicalHandler()

        return null;
    
public java.lang.StringgetLocalName(int nodeHandle)

        return EMPTY_STR;
    
public java.lang.StringgetLocalNameFromExpandedNameID(int ExpandedNameID)

        return EMPTY_STR;
    
public intgetNSType(int node)

        return 0;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetNamespaceAxisIterator(int axis, int ns)

        return null;
    
public java.lang.StringgetNamespaceFromExpandedNameID(int ExpandedNameID)

        return EMPTY_STR;
    
public java.lang.StringgetNamespaceName(int node)

        return EMPTY_STR;
    
public intgetNamespaceType(int node)

        return 0;
    
public java.lang.StringgetNamespaceURI(int nodeHandle)

        return EMPTY_STR;
    
public intgetNextAttribute(int nodeHandle)

        return DTM.NULL;
    
public intgetNextNamespaceNode(int baseHandle, int namespaceHandle, boolean inScope)

        return DTM.NULL;
    
public intgetNextSibling(int nodeHandle)

        return DTM.NULL;
    
public org.w3c.dom.NodegetNode(int nodeHandle)

        return makeNode(nodeHandle);
    
public intgetNodeHandle(int nodeId)
Return the node handle from a node identity.

        return (nodeId != DTM.NULL) ? (nodeId + _documentID) : DTM.NULL;
    
public intgetNodeIdent(int nodehandle)
Return the node identity from a node handle.

        return (nodehandle != DTM.NULL) ? (nodehandle - _documentID) : DTM.NULL;
    
public java.lang.StringgetNodeName(int node)

        if (getNodeIdent(node) == RTF_TEXT)
            return "#text";
        else
            return EMPTY_STR;
    
public java.lang.StringgetNodeNameX(int node)

        return EMPTY_STR;
    
public shortgetNodeType(int nodeHandle)

        int nodeID = getNodeIdent(nodeHandle);
        if (nodeID == RTF_TEXT)
            return DTM.TEXT_NODE;
        else if (nodeID == RTF_ROOT)
            return DTM.ROOT_NODE;
        else
            return DTM.NULL;
        
    
public java.lang.StringgetNodeValue(int nodeHandle)

        return (getNodeIdent(nodeHandle) == RTF_TEXT) ? _text : null;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetNodeValueIterator(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iter, int returnType, java.lang.String value, boolean op)

        return null;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetNthDescendant(int node, int n, boolean includeself)

        return null; 
    
public com.sun.org.apache.xml.internal.serializer.SerializationHandlergetOutputDomBuilder()

        return this;
    
public intgetOwnerDocument(int nodeHandle)

        return getDocument();
    
public intgetParent(int nodeHandle)

        int nodeID = getNodeIdent(nodeHandle);
        return (nodeID == RTF_TEXT) ? getNodeHandle(RTF_ROOT) : DTM.NULL;            
    
public java.lang.StringgetPrefix(int nodeHandle)

        return null;
    
public intgetPreviousSibling(int nodeHandle)

        return DTM.NULL;
    
public com.sun.org.apache.xalan.internal.xsltc.DOMgetResultTreeFrag(int initialSize, int rtfType)

        return null;
    
public com.sun.org.apache.xalan.internal.xsltc.DOMgetResultTreeFrag(int initialSize, int rtfType, boolean addToManager)

        return null;
    
public intgetSize()

        return 2;
    
public javax.xml.transform.SourceLocatorgetSourceLocatorFor(int node)

    	return null;
    
public java.lang.StringgetStringValue()

        return _text;
    
public com.sun.org.apache.xml.internal.utils.XMLStringgetStringValue(int nodeHandle)

        return new XMLStringDefault(getStringValueX(nodeHandle));
    
public char[]getStringValueChunk(int nodeHandle, int chunkIndex, int[] startAndLen)

        return null;
    
public intgetStringValueChunkCount(int nodeHandle)

        return 0;
    
public java.lang.StringgetStringValueX(int nodeHandle)

        int nodeID = getNodeIdent(nodeHandle);
        if (nodeID == RTF_ROOT || nodeID == RTF_TEXT)
            return _text;
        else
            return EMPTY_STR;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetTypedAxisIterator(int axis, int type)

        switch (axis)
        {
            case Axis.CHILD:
            case Axis.DESCENDANT:
                return new SimpleIterator(SimpleIterator.DIRECTION_DOWN, type);
            case Axis.PARENT:
            case Axis.ANCESTOR:
                return new SimpleIterator(SimpleIterator.DIRECTION_UP, type);
            case Axis.ANCESTORORSELF:
                return (new SimpleIterator(SimpleIterator.DIRECTION_UP, type)).includeSelf();
            case Axis.DESCENDANTORSELF:
                return (new SimpleIterator(SimpleIterator.DIRECTION_DOWN, type)).includeSelf();
            case Axis.SELF:
                return new SingletonIterator(type);
            default:
                return EMPTY_ITERATOR;
        }
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorgetTypedChildren(int type)

        return new SimpleIterator(SimpleIterator.DIRECTION_DOWN, type);
    
public java.lang.StringgetUnparsedEntityURI(java.lang.String name)

        return null;
    
public booleanhasChildNodes(int nodeHandle)

        return (getNodeIdent(nodeHandle) == RTF_ROOT);
    
public booleanisAttribute(int node)

        return false;
    
public booleanisAttributeSpecified(int attributeHandle)

        return false;
    
public booleanisCharacterElementContentWhitespace(int nodeHandle)

        return false;
    
public booleanisDocumentAllDeclarationsProcessed(int documentHandle)

        return false;
    
public booleanisElement(int node)

        return false;
    
public booleanisNodeAfter(int firstNodeHandle, int secondNodeHandle)

        return lessThan(firstNodeHandle, secondNodeHandle);
    
public booleanisSupported(java.lang.String feature, java.lang.String version)

        return false;
    
public booleanlessThan(int node1, int node2)

        if (node1 == DTM.NULL) {
            return false;
        }
        else if (node2 == DTM.NULL) {
            return true;
        }
        else
            return (node1 < node2);
    
public java.lang.StringlookupNamespace(int node, java.lang.String prefix)

        return null;
    
public org.w3c.dom.NodemakeNode(int index)

        return null;
    
public org.w3c.dom.NodemakeNode(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iter)

        return null;
    
public org.w3c.dom.NodeListmakeNodeList(int index)

        return null;
    
public org.w3c.dom.NodeListmakeNodeList(com.sun.org.apache.xml.internal.dtm.DTMAxisIterator iter)

        return null;
    
public voidmigrateTo(com.sun.org.apache.xml.internal.dtm.DTMManager manager)

    
public booleanneedsTwoThreads()

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

        return source;
    
public voidsetDocumentBaseURI(java.lang.String baseURI)

    
public booleansetEscaping(boolean escape)

        final boolean temp = _escaping;
        _escaping = escape; 
        return temp;
    
public voidsetFeature(java.lang.String featureId, boolean state)
The DTM interfaces are not used in this class. Implementing the DTM interface is a requirement from MultiDOM. If we have a better way of handling multiple documents, we can get rid of the DTM dependency. The following interfaces are just placeholders. The implementation does not have an impact because they will not be used.

    
public voidsetFilter(com.sun.org.apache.xalan.internal.xsltc.StripFilter filter)

    
public voidsetProperty(java.lang.String property, java.lang.Object value)

    
public voidsetupMapping(java.lang.String[] names, java.lang.String[] uris, int[] types, java.lang.String[] namespaces)

    
public java.lang.StringshallowCopy(int node, com.sun.org.apache.xml.internal.serializer.SerializationHandler handler)

        characters(node, handler);
        return null;
    
public voidstartDocument()
We only need to override the endDocument, characters, and setEscaping interfaces. A simple RTF does not have element nodes. We do not need to touch startElement and endElement.

    
    
public booleansupportsPreStripping()

        return false;