NASA World Wind

gov.nasa.worldwind.util.xml
Class AbstractXMLEventParser

java.lang.Object
  extended by gov.nasa.worldwind.util.xml.AbstractXMLEventParser
All Implemented Interfaces:
XMLEventParser
Direct Known Subclasses:
AngleXMLEventParser, AtomAbstractObject, BooleanIntegerXMLEventParser, BooleanXMLEventParser, ColladaAbstractObject, DoubleXMLEventParser, IntegerXMLEventParser, KMLAbstractEventParser, KMLAbstractObject, KMLChange, KMLCoordinatesParser, KMLCreate, KMLDelete, KMLNetworkLinkControl, KMLSchema, KMLSimpleData, KMLSimpleField, OGCAddress, OGCBoundingBox, OGCCapabilities, OGCCapabilityInformation, OGCContactInformation, OGCDCType, OGCOnlineResource, OGCRequestDescription, OGCServiceInformation, StringSetXMLEventParser, StringXMLEventParser, WMSLayerAttribution, WMSLayerCapabilities, WMSLayerDimension, WMSLayerExtent, WMSLayerIdentifier, WMSLayerInfoURL, WMSLayerStyle, XALAbstractObject

public abstract class AbstractXMLEventParser
extends Object
implements XMLEventParser

Base class for XML event parsers. Handles parsing control and creation of new parser instances.

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.


Field Summary
protected static String CHARACTERS_CONTENT
           
protected  AVList fields
           
protected  String namespaceURI
           
protected  XMLEventParser parent
           
 
Constructor Summary
AbstractXMLEventParser()
          Construct a parser with no qualifying namespace.
AbstractXMLEventParser(String namespaceURI)
          Constructs a parser and qualifies it for a specified namespace.
 
Method Summary
 XMLEventParser allocate(XMLEventParserContext ctx, XMLEvent event)
          Create a parser for a specified event.
protected  void doAddCharacters(XMLEventParserContext ctx, XMLEvent event, Object... args)
           
protected  void doAddEventAttribute(Attribute attr, XMLEventParserContext ctx, XMLEvent event, Object... args)
           
protected  void doAddEventContent(Object o, XMLEventParserContext ctx, XMLEvent event, Object... args)
           
protected  void doParseEventAttributes(XMLEventParserContext ctx, XMLEvent event, Object... args)
          Parse an event's attributes.
protected  void doParseEventContent(XMLEventParserContext ctx, XMLEvent event, 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  Constructor<? extends AbstractXMLEventParser> getAConstructor(Class... parameterTypes)
           
 String getCharacters()
           
 Object getField(QName keyName)
           
 Object getField(String keyName)
           
 AVList getFields()
           
 String getNamespaceURI()
          Returns the qualifying namespace URI specified at construction.
 XMLEventParser getParent()
          Returns this parser's parent parser.
 XMLEventParser getRoot()
           
 boolean hasField(QName keyName)
           
 boolean hasField(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)
           
 Object parse(XMLEventParserContext ctx, XMLEvent inputEvent, Object... args)
          Parse the event and initialize the parser's values to those found in the event.
protected  String parseCharacterContent(XMLEventParserContext ctx, XMLEvent stringEvent, Object... args)
           
 void removeField(String keyName)
           
 void setField(QName keyName, Object value)
           
 void setField(String keyName, Object value)
           
 void setFields(Map<String,Object> newFields)
           
 void setParent(XMLEventParser parent)
          Specifies the parent parser of this parser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHARACTERS_CONTENT

protected static final String CHARACTERS_CONTENT
See Also:
Constant Field Values

fields

protected AVList fields

namespaceURI

protected final String namespaceURI

parent

protected XMLEventParser parent
Constructor Detail

AbstractXMLEventParser

public AbstractXMLEventParser()
Construct a parser with no qualifying namespace.


AbstractXMLEventParser

public AbstractXMLEventParser(String namespaceURI)
Constructs a parser and qualifies it for a specified namespace.

Parameters:
namespaceURI - the qualifying namespace URI. May be null to indicate no namespace qualification.
Method Detail

allocate

public XMLEventParser allocate(XMLEventParserContext ctx,
                               XMLEvent event)
Create a parser for a specified event.

Parameters:
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.
Returns:
the new parser.

doAddCharacters

protected void doAddCharacters(XMLEventParserContext ctx,
                               XMLEvent event,
                               Object... args)

doAddEventAttribute

protected void doAddEventAttribute(Attribute attr,
                                   XMLEventParserContext ctx,
                                   XMLEvent event,
                                   Object... args)
                            throws XMLStreamException
Throws:
XMLStreamException

doAddEventContent

protected void doAddEventContent(Object o,
                                 XMLEventParserContext ctx,
                                 XMLEvent event,
                                 Object... args)
                          throws XMLStreamException
Throws:
XMLStreamException

doParseEventAttributes

protected void doParseEventAttributes(XMLEventParserContext ctx,
                                      XMLEvent event,
                                      Object... args)
                               throws XMLStreamException
Parse an event's attributes.

Parameters:
ctx - a current parser context.
event - the event to parse.
args - an optional list of arguments that may by used by subclasses.
Throws:
XMLStreamException - if an exception occurs during event-stream reading.

doParseEventContent

protected void doParseEventContent(XMLEventParserContext ctx,
                                   XMLEvent event,
                                   Object... args)
                            throws XMLStreamException
Parse an event's sub-elements.

Parameters:
ctx - a current parser context.
event - the event to parse.
args - an optional list of arguments that may by used by subclasses.
Throws:
XMLStreamException - if an exception occurs during event-stream reading.

freeResources

public void freeResources()
Description copied from interface: XMLEventParser
Release large resources used by the parser, but does not dispose of the parser itself. Call this method once its data is no longer needed, such as after mappings and related representations are created. For example, if a parser holds a large number of positions, and those positions are no longer needed after the positions are converted to points or copied to other storage, this method releases the memory associated with the original positions.

Specified by:
freeResources in interface XMLEventParser

getAConstructor

protected Constructor<? extends AbstractXMLEventParser> getAConstructor(Class... parameterTypes)

getCharacters

public String getCharacters()

getField

public Object getField(QName keyName)

getField

public Object getField(String keyName)

getFields

public AVList getFields()

getNamespaceURI

public String getNamespaceURI()
Returns the qualifying namespace URI specified at construction.

Returns:
the namespace URI. Returns null if no name space was specified at construction.

getParent

public XMLEventParser getParent()
Description copied from interface: XMLEventParser
Returns this parser's parent parser.

Specified by:
getParent in interface XMLEventParser
Returns:
this parser's parent parser.

getRoot

public XMLEventParser getRoot()

hasField

public boolean hasField(QName keyName)

hasField

public boolean hasField(String keyName)

hasFields

public boolean hasFields()

mergeFields

protected AbstractXMLEventParser mergeFields(AbstractXMLEventParser s1,
                                             AbstractXMLEventParser s2)

newInstance

public XMLEventParser newInstance()
                           throws Exception
Description copied from interface: XMLEventParser
Creates a new empty parser instance of the same type. This is used by 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.

Specified by:
newInstance in interface XMLEventParser
Returns:
a new parser instance. The namespace URI is the same as the creating parser, but all other fields are empty.
Throws:
Exception - if an error or exception occurs while attempting to create the parser.

overrideFields

protected AbstractXMLEventParser overrideFields(AbstractXMLEventParser s1,
                                                AbstractXMLEventParser s2)

parse

public Object parse(XMLEventParserContext ctx,
                    XMLEvent inputEvent,
                    Object... args)
             throws XMLStreamException
Parse the event and initialize the parser's values to those found in the event.

Specified by:
parse in interface XMLEventParser
Parameters:
ctx - a current parser context.
inputEvent - the event to parse.
args - an optional list of arguments that may by used by subclasses.
Returns:
if parsing is successful, returns this, otherwise returns null.
Throws:
XMLStreamException - if an exception occurs during event-stream reading.

parseCharacterContent

protected String parseCharacterContent(XMLEventParserContext ctx,
                                       XMLEvent stringEvent,
                                       Object... args)
                                throws XMLStreamException
Throws:
XMLStreamException

removeField

public void removeField(String keyName)

setField

public void setField(QName keyName,
                     Object value)

setField

public void setField(String keyName,
                     Object value)

setFields

public void setFields(Map<String,Object> newFields)

setParent

public void setParent(XMLEventParser parent)
Description copied from interface: XMLEventParser
Specifies the parent parser of this parser.

Specified by:
setParent in interface XMLEventParser
Parameters:
parent - this parser's parent parser.

NASA World Wind