public abstract class AbstractXMLEventParser extends java.lang.Object implements XMLEventParser
A parser holds the information parsed from the event stream. That information can be queried via the parser's accessors. A parser typically does not maintain a reference to the event stream it parsed or the parser context used during parsing.
Parsers are created when events of the associated type are encountered in the input stream. An allocate(XMLEventParserContext, javax.xml.stream.events.XMLEvent)
method in the parser typically creates a default
parser prior to consulting the XMLEventParserContext
, which returns a new parser whose type is determined by
consulting a table of event types. The default parser is returned if the table contains no entry for the event type.
A parser can be associated with a specific namespace. The namespace is used to qualify the parser's association with event types.
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
CHARACTERS_CONTENT |
protected AVList |
fields |
protected java.lang.String |
namespaceURI |
protected XMLEventParser |
parent |
Constructor and Description |
---|
AbstractXMLEventParser()
Construct a parser with no qualifying namespace.
|
AbstractXMLEventParser(java.lang.String namespaceURI)
Constructs a parser and qualifies it for a specified namespace.
|
Modifier and Type | Method and Description |
---|---|
XMLEventParser |
allocate(XMLEventParserContext ctx,
javax.xml.stream.events.XMLEvent event)
Create a parser for a specified event.
|
protected void |
doAddCharacters(XMLEventParserContext ctx,
javax.xml.stream.events.XMLEvent event,
java.lang.Object... args) |
protected void |
doAddEventAttribute(javax.xml.stream.events.Attribute attr,
XMLEventParserContext ctx,
javax.xml.stream.events.XMLEvent event,
java.lang.Object... args) |
protected void |
doAddEventContent(java.lang.Object o,
XMLEventParserContext ctx,
javax.xml.stream.events.XMLEvent event,
java.lang.Object... args) |
protected void |
doParseEventAttributes(XMLEventParserContext ctx,
javax.xml.stream.events.XMLEvent event,
java.lang.Object... args)
Parse an event's attributes.
|
protected void |
doParseEventContent(XMLEventParserContext ctx,
javax.xml.stream.events.XMLEvent event,
java.lang.Object... args)
Parse an event's sub-elements.
|
void |
freeResources()
Release large resources used by the parser, but does not dispose of the parser itself.
|
protected java.lang.reflect.Constructor<? extends AbstractXMLEventParser> |
getAConstructor(java.lang.Class... parameterTypes) |
java.lang.String |
getCharacters() |
java.lang.Object |
getField(javax.xml.namespace.QName keyName) |
java.lang.Object |
getField(java.lang.String keyName) |
AVList |
getFields() |
java.lang.String |
getNamespaceURI()
Returns the qualifying namespace URI specified at construction.
|
XMLEventParser |
getParent()
Returns this parser's parent parser.
|
XMLEventParser |
getRoot() |
boolean |
hasField(javax.xml.namespace.QName keyName) |
boolean |
hasField(java.lang.String keyName) |
boolean |
hasFields() |
protected AbstractXMLEventParser |
mergeFields(AbstractXMLEventParser s1,
AbstractXMLEventParser s2) |
XMLEventParser |
newInstance()
Creates a new empty parser instance of the same type.
|
protected AbstractXMLEventParser |
overrideFields(AbstractXMLEventParser s1,
AbstractXMLEventParser s2) |
java.lang.Object |
parse(XMLEventParserContext ctx,
javax.xml.stream.events.XMLEvent inputEvent,
java.lang.Object... args)
Parse the event and initialize the parser's values to those found in the event.
|
protected java.lang.String |
parseCharacterContent(XMLEventParserContext ctx,
javax.xml.stream.events.XMLEvent stringEvent,
java.lang.Object... args) |
void |
removeField(java.lang.String keyName) |
void |
setField(javax.xml.namespace.QName keyName,
java.lang.Object value) |
void |
setField(java.lang.String keyName,
java.lang.Object value) |
void |
setFields(java.util.Map<java.lang.String,java.lang.Object> newFields) |
protected void |
setNamespaceURI(java.lang.String namespaceURI) |
void |
setParent(XMLEventParser parent)
Specifies the parent parser of this parser.
|
protected static final java.lang.String CHARACTERS_CONTENT
protected AVList fields
protected java.lang.String namespaceURI
protected XMLEventParser parent
public AbstractXMLEventParser()
public AbstractXMLEventParser(java.lang.String namespaceURI)
namespaceURI
- the qualifying namespace URI. May be null to indicate no namespace qualification.public XMLEventParser allocate(XMLEventParserContext ctx, javax.xml.stream.events.XMLEvent event)
ctx
- the current parser context.event
- the event for which the parser is created. Only the event type is used; the new parser can operate
on any event of that type.protected void doAddCharacters(XMLEventParserContext ctx, javax.xml.stream.events.XMLEvent event, java.lang.Object... args)
protected void doAddEventAttribute(javax.xml.stream.events.Attribute attr, XMLEventParserContext ctx, javax.xml.stream.events.XMLEvent event, java.lang.Object... args) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
protected void doAddEventContent(java.lang.Object o, XMLEventParserContext ctx, javax.xml.stream.events.XMLEvent event, java.lang.Object... args) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
protected void doParseEventAttributes(XMLEventParserContext ctx, javax.xml.stream.events.XMLEvent event, java.lang.Object... args) throws javax.xml.stream.XMLStreamException
ctx
- a current parser context.event
- the event to parse.args
- an optional list of arguments that may by used by subclasses.javax.xml.stream.XMLStreamException
- if an exception occurs during event-stream reading.protected void doParseEventContent(XMLEventParserContext ctx, javax.xml.stream.events.XMLEvent event, java.lang.Object... args) throws javax.xml.stream.XMLStreamException
ctx
- a current parser context.event
- the event to parse.args
- an optional list of arguments that may by used by subclasses.javax.xml.stream.XMLStreamException
- if an exception occurs during event-stream reading.public void freeResources()
XMLEventParser
freeResources
in interface XMLEventParser
protected java.lang.reflect.Constructor<? extends AbstractXMLEventParser> getAConstructor(java.lang.Class... parameterTypes)
public java.lang.String getCharacters()
public java.lang.Object getField(javax.xml.namespace.QName keyName)
public java.lang.Object getField(java.lang.String keyName)
public AVList getFields()
public java.lang.String getNamespaceURI()
public XMLEventParser getParent()
XMLEventParser
getParent
in interface XMLEventParser
public XMLEventParser getRoot()
public boolean hasField(javax.xml.namespace.QName keyName)
public boolean hasField(java.lang.String keyName)
public boolean hasFields()
protected AbstractXMLEventParser mergeFields(AbstractXMLEventParser s1, AbstractXMLEventParser s2)
public XMLEventParser newInstance() throws java.lang.Exception
XMLEventParser
XMLEventParserContext
when creating parsers associated with specific event types.
The returned parser has the same namespace as the instance creating it, but has empty fields for all other
values.newInstance
in interface XMLEventParser
java.lang.Exception
- if an error or exception occurs while attempting to create the parser.protected AbstractXMLEventParser overrideFields(AbstractXMLEventParser s1, AbstractXMLEventParser s2)
public java.lang.Object parse(XMLEventParserContext ctx, javax.xml.stream.events.XMLEvent inputEvent, java.lang.Object... args) throws javax.xml.stream.XMLStreamException
parse
in interface XMLEventParser
ctx
- a current parser context.inputEvent
- the event to parse.args
- an optional list of arguments that may by used by subclasses.this
, otherwise returns null.javax.xml.stream.XMLStreamException
- if an exception occurs during event-stream reading.protected java.lang.String parseCharacterContent(XMLEventParserContext ctx, javax.xml.stream.events.XMLEvent stringEvent, java.lang.Object... args) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
public void removeField(java.lang.String keyName)
public void setField(javax.xml.namespace.QName keyName, java.lang.Object value)
public void setField(java.lang.String keyName, java.lang.Object value)
public void setFields(java.util.Map<java.lang.String,java.lang.Object> newFields)
protected void setNamespaceURI(java.lang.String namespaceURI)
public void setParent(XMLEventParser parent)
XMLEventParser
setParent
in interface XMLEventParser
parent
- this parser's parent parser.