FileDocCategorySizeDatePackage
XMLStreamFilterImpl.javaAPI DocJava SE 6 API12926Tue Jun 10 00:22:40 BST 2008com.sun.org.apache.xerces.internal.impl

XMLStreamFilterImpl

public class XMLStreamFilterImpl extends Object implements XMLStreamReader
author
Joe Wang: This is a rewrite of the original class. The focus is on removing caching, and make the filtered stream reader more compatible with those in other implementations. Note however, that this version will not solve all the issues related to the undefined condition in the spec. The priority is to pass the TCK. Issues arising due to the requirement, that is, (1) should it initiate at BEGIN_DOCUMENT or an accepted event; (2) should hasNext() advance the underlining stream in order to find an acceptable event, would have to wait until 1.1 of StAX in which the filtered stream reader would be defined more clearly.

Fields Summary
private StreamFilter
fStreamFilter
private XMLStreamReader
fStreamReader
private int
fCurrentEvent
private boolean
fEventAccepted
private boolean
fStreamAdvancedByHasNext
the very issue around a long discussion. but since we must pass the TCK, we have to allow hasNext() to advance the underlining stream in order to find the next acceptable event
Constructors Summary
public XMLStreamFilterImpl(XMLStreamReader reader, StreamFilter filter)
Creates a new instance of XMLStreamFilterImpl

    
           
    
       
        fStreamReader = reader;
        this.fStreamFilter = filter;
        
        //this is debatable to initiate at an acceptable event, 
        //but it's neccessary in order to pass the TCK and yet avoid skipping element
        try {
            if (fStreamFilter.accept(fStreamReader)) {
                fEventAccepted = true;
            } else {
                findNextEvent();
            }
        }catch(XMLStreamException xs){
            System.err.println("Error while creating a stream Filter"+xs);
        }
    
Methods Summary
public voidclose()

throws
XMLStreamException

        fStreamReader.close();
    
private intfindNextEvent()

        fStreamAdvancedByHasNext = false;
        while(fStreamReader.hasNext()){
            fCurrentEvent = fStreamReader.next();
            if(fStreamFilter.accept(fStreamReader)){
                fEventAccepted = true;
                return fCurrentEvent;
            }
        }
        //although it seems that IllegalStateException should be thrown when next() is called
        //on a stream that has no more items, we have to assume END_DOCUMENT is always accepted 
        //in order to pass the TCK
        if (fCurrentEvent == XMLEvent.END_DOCUMENT)
            return fCurrentEvent;
        else
            return -1;
    
private intfindNextTag()

        fStreamAdvancedByHasNext = false;
        while(fStreamReader.hasNext()){
            fCurrentEvent = fStreamReader.nextTag();
            if(fStreamFilter.accept(fStreamReader)){
                fEventAccepted = true;
                return fCurrentEvent;
            }
        }
        if (fCurrentEvent == XMLEvent.END_DOCUMENT)
            return fCurrentEvent;
        else
            return -1;
    
public intgetAttributeCount()

return

        return fStreamReader.getAttributeCount();
    
public java.lang.StringgetAttributeLocalName(int index)

param
index
return

        return fStreamReader.getAttributeLocalName(index);
    
public javax.xml.namespace.QNamegetAttributeName(int index)

param
index
return

        return fStreamReader.getAttributeName(index);
    
public java.lang.StringgetAttributeNamespace(int index)

param
index
return

        return fStreamReader.getAttributeNamespace(index);
    
public java.lang.StringgetAttributePrefix(int index)

param
index
return

        return fStreamReader.getAttributePrefix(index);
    
public java.lang.StringgetAttributeType(int index)

param
index
return

        return fStreamReader.getAttributeType(index);
    
public java.lang.StringgetAttributeValue(int index)

param
index
return

        return fStreamReader.getAttributeValue(index);
    
public java.lang.StringgetAttributeValue(java.lang.String namespaceURI, java.lang.String localName)

param
namespaceURI
param
localName
return

        return fStreamReader.getAttributeValue(namespaceURI,localName);
    
public java.lang.StringgetCharacterEncodingScheme()

return

        return fStreamReader.getCharacterEncodingScheme();
    
public java.lang.StringgetElementText()

throws
XMLStreamException
return

        return fStreamReader.getElementText();
    
public java.lang.StringgetEncoding()

return

        return fStreamReader.getEncoding();
    
public intgetEventType()

return

        return fStreamReader.getEventType();
    
public java.lang.StringgetLocalName()

return

        return fStreamReader.getLocalName();
    
public javax.xml.stream.LocationgetLocation()

return

        return fStreamReader.getLocation();
    
public javax.xml.namespace.QNamegetName()

return

        return fStreamReader.getName();
    
public javax.xml.namespace.NamespaceContextgetNamespaceContext()

return

        return fStreamReader.getNamespaceContext();
    
public intgetNamespaceCount()

return

        return fStreamReader.getNamespaceCount();
    
public java.lang.StringgetNamespacePrefix(int index)

param
index
return

        return fStreamReader.getNamespacePrefix(index);
    
public java.lang.StringgetNamespaceURI()

return

        return fStreamReader.getNamespaceURI();
    
public java.lang.StringgetNamespaceURI(int index)

param
index
return

        return fStreamReader.getNamespaceURI(index);
    
public java.lang.StringgetNamespaceURI(java.lang.String prefix)

param
prefix
return

        return fStreamReader.getNamespaceURI(prefix);
    
public java.lang.StringgetPIData()

return

        return fStreamReader.getPIData();
    
public java.lang.StringgetPITarget()

return

        return fStreamReader.getPITarget();
    
public java.lang.StringgetPrefix()

return

        return fStreamReader.getPrefix();
    
public java.lang.ObjectgetProperty(java.lang.String name)

param
name
throws
IllegalArgumentException
return

        return fStreamReader.getProperty(name);
    
public java.lang.StringgetText()

return

        return fStreamReader.getText();
    
public char[]getTextCharacters()

return

        return fStreamReader.getTextCharacters();
    
public intgetTextCharacters(int sourceStart, char[] target, int targetStart, int length)

param
sourceStart
param
target
param
targetStart
param
length
throws
XMLStreamException
return

        return fStreamReader.getTextCharacters(sourceStart, target,targetStart,length);
    
public intgetTextLength()

return

        return fStreamReader.getTextLength();
    
public intgetTextStart()

return

        return fStreamReader.getTextStart();
    
public java.lang.StringgetVersion()

return

        return fStreamReader.getVersion();
        
    
public booleanhasName()

return

        return fStreamReader.hasName();
    
public booleanhasNext()

throws
XMLStreamException
return

        if (fStreamReader.hasNext()) {
            if (!fEventAccepted) {
                if ((fCurrentEvent = findNextEvent()) == -1) {
                    return false;
                } else {
                    fStreamAdvancedByHasNext = true;
                }
            }
            return true;
        }
        return false;
    
public booleanhasText()

return

        return fStreamReader.hasText();
    
public booleanisAttributeSpecified(int index)

return
param
index

        return fStreamReader.isAttributeSpecified(index);
    
public booleanisCharacters()

return

        return fStreamReader.isCharacters();
    
public booleanisEndElement()

return

        return fStreamReader.isEndElement();
    
public booleanisStandalone()

return

        return fStreamReader.isStandalone();
    
public booleanisStartElement()

return

        return fStreamReader.isStartElement();
    
public booleanisWhiteSpace()

return

        return fStreamReader.isWhiteSpace();
    
public intnext()

return
throws
XMLStreamException

        if (fStreamAdvancedByHasNext && fEventAccepted) {
            fStreamAdvancedByHasNext = false;
            return fCurrentEvent;
        }
        int event = findNextEvent();
        if (event != -1) {
            return event;
        }
        
        throw new IllegalStateException("The stream reader has reached the end of the document, or there are no more "+
                                    " items to return");
    
public intnextTag()

throws
XMLStreamException
return

        if (fStreamAdvancedByHasNext && fEventAccepted && 
                (fCurrentEvent == XMLEvent.START_ELEMENT || fCurrentEvent == XMLEvent.START_ELEMENT)) {
            fStreamAdvancedByHasNext = false;
            return fCurrentEvent;
        }
        
        int event = findNextTag();
        if (event != -1) {
            return event;
        }
        throw new IllegalStateException("The stream reader has reached the end of the document, or there are no more "+
                                    " items to return");
    
public voidrequire(int type, java.lang.String namespaceURI, java.lang.String localName)

param
type
param
namespaceURI
param
localName
throws
XMLStreamException

        fStreamReader.require(type,namespaceURI,localName);
    
protected voidsetStreamFilter(javax.xml.stream.StreamFilter sf)

param
sf

        this.fStreamFilter = sf;
    
public booleanstandaloneSet()

return

        return fStreamReader.standaloneSet();