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 void
close()
protected abstract boolean
consume()
Main method to be implemented by subclasses.int
getAttributeCount()
String
getAttributeLocalName(int index)
QName
getAttributeName(int index)
String
getAttributeNamespace(int index)
String
getAttributePrefix(int index)
String
getAttributeType(int index)
String
getAttributeValue(int index)
String
getAttributeValue(String namespaceURI, String localName)
String
getCharacterEncodingScheme()
String
getElementText()
String
getEncoding()
protected Object
getEventData()
protected String
getEventName()
int
getEventType()
String
getLocalName()
Location
getLocation()
QName
getName()
NamespaceContext
getNamespaceContext()
int
getNamespaceCount()
String
getNamespacePrefix(int index)
String
getNamespaceURI()
String
getNamespaceURI(int index)
String
getNamespaceURI(String prefix)
String
getPIData()
String
getPITarget()
String
getPrefix()
Object
getProperty(String name)
protected XMLStreamReaderScope<T>
getScope()
String
getText()
char[]
getTextCharacters()
int
getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
int
getTextLength()
int
getTextStart()
String
getVersion()
boolean
hasName()
boolean
hasNext()
boolean
hasText()
protected void
initialize()
Consume initial event.boolean
isAttributeSpecified(int index)
boolean
isCharacters()
boolean
isEndElement()
boolean
isStandalone()
protected boolean
isStartDocumentRead()
boolean
isStartElement()
boolean
isWhiteSpace()
int
next()
int
nextTag()
protected void
readAttr(String prefix, String localName, String namespaceURI, String value)
Read attribute.protected void
readData(String text, Object data, int type)
Read characters/comment/dtd/entity data.protected void
readEndDocument()
Read end document.protected void
readEndElementTag()
Read end element.protected void
readNsDecl(String prefix, String namespaceURI)
Read namespace declaration.protected void
readPI(String target, String data)
Read processing instruction.protected void
readStartDocument(String version, String encodingScheme, Boolean standalone)
Read start documentprotected void
readStartElementTag(String prefix, String localName, String namespaceURI, T scopeInfo)
Read start element.void
require(int eventType, String namespaceURI, String localName)
boolean
standaloneSet()
String
toString()
-
-
-
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:
true
ifSTART_DOCUMENT
event has been read
-
initialize
protected void initialize() throws XMLStreamException
Consume 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, IOException
Main 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:
true
if there's more to read- Throws:
XMLStreamException
IOException
-
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 providedscopeInfo
is stored in the new scope and will be available viagetScope().getInfo()
.- Parameters:
prefix
- element prefix (usenull
if unknown)localName
- local namenamespaceURI
- (usenull
if 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 (usenull
if unknown)localName
- local namenamespaceURI
- (usenull
if 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 XMLStreamException
Read end element. This will pop the current scope and make its parent the new current scope.- Throws:
XMLStreamException
-
readEndDocument
protected void readEndDocument() throws XMLStreamException
Read end document.- Throws:
XMLStreamException
-
require
public void require(int eventType, String namespaceURI, String localName) throws XMLStreamException
- Specified by:
require
in interfaceXMLStreamReader
- Throws:
XMLStreamException
-
getElementText
public String getElementText() throws XMLStreamException
- Specified by:
getElementText
in interfaceXMLStreamReader
- Throws:
XMLStreamException
-
hasNext
public boolean hasNext() throws XMLStreamException
- Specified by:
hasNext
in interfaceXMLStreamReader
- Throws:
XMLStreamException
-
next
public int next() throws XMLStreamException
- Specified by:
next
in interfaceXMLStreamReader
- Throws:
XMLStreamException
-
nextTag
public int nextTag() throws XMLStreamException
- Specified by:
nextTag
in interfaceXMLStreamReader
- Throws:
XMLStreamException
-
close
public void close() throws XMLStreamException
- Specified by:
close
in interfaceXMLStreamReader
- Throws:
XMLStreamException
-
isStartElement
public boolean isStartElement()
- Specified by:
isStartElement
in interfaceXMLStreamReader
-
isEndElement
public boolean isEndElement()
- Specified by:
isEndElement
in interfaceXMLStreamReader
-
isCharacters
public boolean isCharacters()
- Specified by:
isCharacters
in interfaceXMLStreamReader
-
isWhiteSpace
public boolean isWhiteSpace()
- Specified by:
isWhiteSpace
in interfaceXMLStreamReader
-
getAttributeCount
public int getAttributeCount()
- Specified by:
getAttributeCount
in interfaceXMLStreamReader
-
getAttributeName
public QName getAttributeName(int index)
- Specified by:
getAttributeName
in interfaceXMLStreamReader
-
getAttributeLocalName
public String getAttributeLocalName(int index)
- Specified by:
getAttributeLocalName
in interfaceXMLStreamReader
-
getAttributeValue
public String getAttributeValue(int index)
- Specified by:
getAttributeValue
in interfaceXMLStreamReader
-
getAttributePrefix
public String getAttributePrefix(int index)
- Specified by:
getAttributePrefix
in interfaceXMLStreamReader
-
getAttributeNamespace
public String getAttributeNamespace(int index)
- Specified by:
getAttributeNamespace
in interfaceXMLStreamReader
-
getAttributeType
public String getAttributeType(int index)
- Specified by:
getAttributeType
in interfaceXMLStreamReader
-
isAttributeSpecified
public boolean isAttributeSpecified(int index)
- Specified by:
isAttributeSpecified
in interfaceXMLStreamReader
-
getAttributeValue
public String getAttributeValue(String namespaceURI, String localName)
- Specified by:
getAttributeValue
in interfaceXMLStreamReader
-
getNamespaceURI
public String getNamespaceURI(String prefix)
- Specified by:
getNamespaceURI
in interfaceXMLStreamReader
-
getNamespaceCount
public int getNamespaceCount()
- Specified by:
getNamespaceCount
in interfaceXMLStreamReader
-
getNamespacePrefix
public String getNamespacePrefix(int index)
- Specified by:
getNamespacePrefix
in interfaceXMLStreamReader
-
getNamespaceURI
public String getNamespaceURI(int index)
- Specified by:
getNamespaceURI
in interfaceXMLStreamReader
-
getNamespaceContext
public NamespaceContext getNamespaceContext()
- Specified by:
getNamespaceContext
in interfaceXMLStreamReader
-
getEventType
public int getEventType()
- Specified by:
getEventType
in interfaceXMLStreamReader
-
getEventName
protected String getEventName()
-
getEventData
protected final Object getEventData()
- Returns:
- raw event data
-
getLocation
public Location getLocation()
- Specified by:
getLocation
in interfaceXMLStreamReader
-
hasText
public boolean hasText()
- Specified by:
hasText
in interfaceXMLStreamReader
-
getText
public String getText()
- Specified by:
getText
in interfaceXMLStreamReader
-
getTextCharacters
public char[] getTextCharacters()
- Specified by:
getTextCharacters
in interfaceXMLStreamReader
-
getTextCharacters
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException
- Specified by:
getTextCharacters
in interfaceXMLStreamReader
- Throws:
XMLStreamException
-
getTextStart
public int getTextStart()
- Specified by:
getTextStart
in interfaceXMLStreamReader
-
getTextLength
public int getTextLength()
- Specified by:
getTextLength
in interfaceXMLStreamReader
-
hasName
public boolean hasName()
- Specified by:
hasName
in interfaceXMLStreamReader
-
getName
public QName getName()
- Specified by:
getName
in interfaceXMLStreamReader
-
getLocalName
public String getLocalName()
- Specified by:
getLocalName
in interfaceXMLStreamReader
-
getNamespaceURI
public String getNamespaceURI()
- Specified by:
getNamespaceURI
in interfaceXMLStreamReader
-
getPrefix
public String getPrefix()
- Specified by:
getPrefix
in interfaceXMLStreamReader
-
getVersion
public String getVersion()
- Specified by:
getVersion
in interfaceXMLStreamReader
-
getEncoding
public String getEncoding()
- Specified by:
getEncoding
in interfaceXMLStreamReader
-
isStandalone
public boolean isStandalone()
- Specified by:
isStandalone
in interfaceXMLStreamReader
-
standaloneSet
public boolean standaloneSet()
- Specified by:
standaloneSet
in interfaceXMLStreamReader
-
getCharacterEncodingScheme
public String getCharacterEncodingScheme()
- Specified by:
getCharacterEncodingScheme
in interfaceXMLStreamReader
-
getPITarget
public String getPITarget()
- Specified by:
getPITarget
in interfaceXMLStreamReader
-
getPIData
public String getPIData()
- Specified by:
getPIData
in interfaceXMLStreamReader
-
getProperty
public Object getProperty(String name) throws IllegalArgumentException
- Specified by:
getProperty
in interfaceXMLStreamReader
- Throws:
IllegalArgumentException
-
-