Class AbstractXMLStreamReader<T>
- java.lang.Object
-
- org.apache.synapse.commons.staxon.core.base.AbstractXMLStreamReader<T>
-
- All Implemented Interfaces:
XMLStreamConstants,XMLStreamReader
- Direct Known Subclasses:
JsonXMLStreamReader
public abstract class AbstractXMLStreamReader<T> extends Object implements XMLStreamReader
Abstract XML stream reader.
-
-
Field Summary
-
Fields inherited from interface javax.xml.stream.XMLStreamConstants
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT
-
-
Constructor Summary
Constructors Constructor Description AbstractXMLStreamReader(T rootInfo)Create new reader instance.AbstractXMLStreamReader(T rootInfo, Location locationProvider)Create new reader instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()protected abstract booleanconsume()Main method to be implemented by subclasses.intgetAttributeCount()StringgetAttributeLocalName(int index)QNamegetAttributeName(int index)StringgetAttributeNamespace(int index)StringgetAttributePrefix(int index)StringgetAttributeType(int index)StringgetAttributeValue(int index)StringgetAttributeValue(String namespaceURI, String localName)StringgetCharacterEncodingScheme()StringgetElementText()StringgetEncoding()protected ObjectgetEventData()protected StringgetEventName()intgetEventType()StringgetLocalName()LocationgetLocation()QNamegetName()NamespaceContextgetNamespaceContext()intgetNamespaceCount()StringgetNamespacePrefix(int index)StringgetNamespaceURI()StringgetNamespaceURI(int index)StringgetNamespaceURI(String prefix)StringgetPIData()StringgetPITarget()StringgetPrefix()ObjectgetProperty(String name)protected XMLStreamReaderScope<T>getScope()StringgetText()char[]getTextCharacters()intgetTextCharacters(int sourceStart, char[] target, int targetStart, int length)intgetTextLength()intgetTextStart()StringgetVersion()booleanhasName()booleanhasNext()booleanhasText()protected voidinitialize()Consume initial event.booleanisAttributeSpecified(int index)booleanisCharacters()booleanisEndElement()booleanisStandalone()protected booleanisStartDocumentRead()booleanisStartElement()booleanisWhiteSpace()intnext()intnextTag()protected voidreadAttr(String prefix, String localName, String namespaceURI, String value)Read attribute.protected voidreadData(String text, Object data, int type)Read characters/comment/dtd/entity data.protected voidreadEndDocument()Read end document.protected voidreadEndElementTag()Read end element.protected voidreadNsDecl(String prefix, String namespaceURI)Read namespace declaration.protected voidreadPI(String target, String data)Read processing instruction.protected voidreadStartDocument(String version, String encodingScheme, Boolean standalone)Read start documentprotected voidreadStartElementTag(String prefix, String localName, String namespaceURI, T scopeInfo)Read start element.voidrequire(int eventType, String namespaceURI, String localName)booleanstandaloneSet()StringtoString()
-
-
-
Constructor Detail
-
AbstractXMLStreamReader
public AbstractXMLStreamReader(T rootInfo)
Create new reader instance.- Parameters:
rootInfo- root scope information
-
-
Method Detail
-
getScope
protected XMLStreamReaderScope<T> getScope()
- Returns:
- current scope
-
isStartDocumentRead
protected boolean isStartDocumentRead()
- Returns:
trueifSTART_DOCUMENTevent has been read
-
initialize
protected void initialize() throws XMLStreamExceptionConsume initial event. This method must be called by subclasses prior to any use of an instance (typically in constructor).- Throws:
XMLStreamException
-
consume
protected abstract boolean consume() throws XMLStreamException, IOExceptionMain method to be implemented by subclasses. This method is called by the reader when the event queue runs dry. Consume some events and delegate to the variousreadXXX()methods. When encountering an element start event, all attributes and namespace delarations must be consumed too, otherwise these won't be available during start element.- Returns:
trueif there's more to read- Throws:
XMLStreamExceptionIOException
-
readStartDocument
protected void readStartDocument(String version, String encodingScheme, Boolean standalone) throws XMLStreamException
Read start document- Parameters:
version- XML versionencodingScheme- encoding scheme (may benull)standalone- standalone flag (may benull)- Throws:
XMLStreamException
-
readStartElementTag
protected void readStartElementTag(String prefix, String localName, String namespaceURI, T scopeInfo) throws XMLStreamException
Read start element. A new scope is created and made the current scope. The providedscopeInfois stored in the new scope and will be available viagetScope().getInfo().- Parameters:
prefix- element prefix (usenullif unknown)localName- local namenamespaceURI- (usenullif unknown)scopeInfo- new scope info- Throws:
XMLStreamException
-
readAttr
protected void readAttr(String prefix, String localName, String namespaceURI, String value) throws XMLStreamException
Read attribute.- Parameters:
prefix- attribute prefix (usenullif unknown)localName- local namenamespaceURI- (usenullif unknown)value- attribute value- Throws:
XMLStreamException
-
readNsDecl
protected void readNsDecl(String prefix, String namespaceURI) throws XMLStreamException
Read namespace declaration.- Parameters:
prefix- namespace prefix (must not benull)namespaceURI- namespace URI (must not benull)- Throws:
XMLStreamException
-
readData
protected void readData(String text, Object data, int type) throws XMLStreamException
Read characters/comment/dtd/entity data.- Parameters:
text- textdata- additional data exposed bygetEventData()(e.g. type conversion)type- one ofCHARACTERS, COMMENT, CDATA, DTD, ENTITY_REFERENCE, SPACE- Throws:
XMLStreamException
-
readPI
protected void readPI(String target, String data) throws XMLStreamException
Read processing instruction.- Parameters:
target- PI targetdata- PI data (may benull)- Throws:
XMLStreamException
-
readEndElementTag
protected void readEndElementTag() throws XMLStreamExceptionRead end element. This will pop the current scope and make its parent the new current scope.- Throws:
XMLStreamException
-
readEndDocument
protected void readEndDocument() throws XMLStreamExceptionRead end document.- Throws:
XMLStreamException
-
require
public void require(int eventType, String namespaceURI, String localName) throws XMLStreamException- Specified by:
requirein interfaceXMLStreamReader- Throws:
XMLStreamException
-
getElementText
public String getElementText() throws XMLStreamException
- Specified by:
getElementTextin interfaceXMLStreamReader- Throws:
XMLStreamException
-
hasNext
public boolean hasNext() throws XMLStreamException- Specified by:
hasNextin interfaceXMLStreamReader- Throws:
XMLStreamException
-
next
public int next() throws XMLStreamException- Specified by:
nextin interfaceXMLStreamReader- Throws:
XMLStreamException
-
nextTag
public int nextTag() throws XMLStreamException- Specified by:
nextTagin interfaceXMLStreamReader- Throws:
XMLStreamException
-
close
public void close() throws XMLStreamException- Specified by:
closein interfaceXMLStreamReader- Throws:
XMLStreamException
-
isStartElement
public boolean isStartElement()
- Specified by:
isStartElementin interfaceXMLStreamReader
-
isEndElement
public boolean isEndElement()
- Specified by:
isEndElementin interfaceXMLStreamReader
-
isCharacters
public boolean isCharacters()
- Specified by:
isCharactersin interfaceXMLStreamReader
-
isWhiteSpace
public boolean isWhiteSpace()
- Specified by:
isWhiteSpacein interfaceXMLStreamReader
-
getAttributeCount
public int getAttributeCount()
- Specified by:
getAttributeCountin interfaceXMLStreamReader
-
getAttributeName
public QName getAttributeName(int index)
- Specified by:
getAttributeNamein interfaceXMLStreamReader
-
getAttributeLocalName
public String getAttributeLocalName(int index)
- Specified by:
getAttributeLocalNamein interfaceXMLStreamReader
-
getAttributeValue
public String getAttributeValue(int index)
- Specified by:
getAttributeValuein interfaceXMLStreamReader
-
getAttributePrefix
public String getAttributePrefix(int index)
- Specified by:
getAttributePrefixin interfaceXMLStreamReader
-
getAttributeNamespace
public String getAttributeNamespace(int index)
- Specified by:
getAttributeNamespacein interfaceXMLStreamReader
-
getAttributeType
public String getAttributeType(int index)
- Specified by:
getAttributeTypein interfaceXMLStreamReader
-
isAttributeSpecified
public boolean isAttributeSpecified(int index)
- Specified by:
isAttributeSpecifiedin interfaceXMLStreamReader
-
getAttributeValue
public String getAttributeValue(String namespaceURI, String localName)
- Specified by:
getAttributeValuein interfaceXMLStreamReader
-
getNamespaceURI
public String getNamespaceURI(String prefix)
- Specified by:
getNamespaceURIin interfaceXMLStreamReader
-
getNamespaceCount
public int getNamespaceCount()
- Specified by:
getNamespaceCountin interfaceXMLStreamReader
-
getNamespacePrefix
public String getNamespacePrefix(int index)
- Specified by:
getNamespacePrefixin interfaceXMLStreamReader
-
getNamespaceURI
public String getNamespaceURI(int index)
- Specified by:
getNamespaceURIin interfaceXMLStreamReader
-
getNamespaceContext
public NamespaceContext getNamespaceContext()
- Specified by:
getNamespaceContextin interfaceXMLStreamReader
-
getEventType
public int getEventType()
- Specified by:
getEventTypein interfaceXMLStreamReader
-
getEventName
protected String getEventName()
-
getEventData
protected final Object getEventData()
- Returns:
- raw event data
-
getLocation
public Location getLocation()
- Specified by:
getLocationin interfaceXMLStreamReader
-
hasText
public boolean hasText()
- Specified by:
hasTextin interfaceXMLStreamReader
-
getText
public String getText()
- Specified by:
getTextin interfaceXMLStreamReader
-
getTextCharacters
public char[] getTextCharacters()
- Specified by:
getTextCharactersin interfaceXMLStreamReader
-
getTextCharacters
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException- Specified by:
getTextCharactersin interfaceXMLStreamReader- Throws:
XMLStreamException
-
getTextStart
public int getTextStart()
- Specified by:
getTextStartin interfaceXMLStreamReader
-
getTextLength
public int getTextLength()
- Specified by:
getTextLengthin interfaceXMLStreamReader
-
hasName
public boolean hasName()
- Specified by:
hasNamein interfaceXMLStreamReader
-
getName
public QName getName()
- Specified by:
getNamein interfaceXMLStreamReader
-
getLocalName
public String getLocalName()
- Specified by:
getLocalNamein interfaceXMLStreamReader
-
getNamespaceURI
public String getNamespaceURI()
- Specified by:
getNamespaceURIin interfaceXMLStreamReader
-
getPrefix
public String getPrefix()
- Specified by:
getPrefixin interfaceXMLStreamReader
-
getVersion
public String getVersion()
- Specified by:
getVersionin interfaceXMLStreamReader
-
getEncoding
public String getEncoding()
- Specified by:
getEncodingin interfaceXMLStreamReader
-
isStandalone
public boolean isStandalone()
- Specified by:
isStandalonein interfaceXMLStreamReader
-
standaloneSet
public boolean standaloneSet()
- Specified by:
standaloneSetin interfaceXMLStreamReader
-
getCharacterEncodingScheme
public String getCharacterEncodingScheme()
- Specified by:
getCharacterEncodingSchemein interfaceXMLStreamReader
-
getPITarget
public String getPITarget()
- Specified by:
getPITargetin interfaceXMLStreamReader
-
getPIData
public String getPIData()
- Specified by:
getPIDatain interfaceXMLStreamReader
-
getProperty
public Object getProperty(String name) throws IllegalArgumentException
- Specified by:
getPropertyin interfaceXMLStreamReader- Throws:
IllegalArgumentException
-
-