NASA World Wind

gov.nasa.worldwind.util.xml
Class BasicXMLEventParserContext

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.util.xml.BasicXMLEventParserContext
All Implemented Interfaces:
AVList, XMLEventParserContext
Direct Known Subclasses:
AtomParserContext, ColladaParserContext, GXParserContext, KMLParserContext, XALParserContext

public class BasicXMLEventParserContext
extends AVListImpl
implements XMLEventParserContext

Provides an implementation of XMLEventParserContext. This class is meant to be the base class for schema-specific parsers.


Field Summary
static QName BOOLEAN
          The parser name of the default boolean parser.
static QName BOOLEAN_INTEGER
          The parser name of the default boolean integer parser.
protected  BooleanIntegerXMLEventParser booleanIntegerParser
           
protected  BooleanXMLEventParser booleanParser
           
protected  String defaultNamespaceURI
           
static QName DOUBLE
          The parser name of the default double parser.
protected  DoubleXMLEventParser doubleParser
           
protected  ConcurrentHashMap<String,Object> idTable
           
static QName INTEGER
          The parser name of the default integer parser.
protected  IntegerXMLEventParser integerParser
           
protected  XMLParserNotificationListener notificationListener
           
protected  ConcurrentHashMap<QName,XMLEventParser> parsers
           
protected  XMLEventReader reader
           
static QName STRING
          The parser name of the default string parser.
protected  StringXMLEventParser stringParser
           
static QName UNRECOGNIZED
          The parser name of the unrecognized-element parser.
 
Fields inherited from interface gov.nasa.worldwind.util.xml.XMLEventParserContext
UNRECOGNIZED_ELEMENT_PARSER
 
Constructor Summary
BasicXMLEventParserContext()
          Construct an instance.
BasicXMLEventParserContext(BasicXMLEventParserContext ctx)
           
BasicXMLEventParserContext(XMLEventReader eventReader)
          Construct an instance for a specified event reader.
BasicXMLEventParserContext(XMLEventReader eventReader, String defaultNamespace)
          Construct an instance for a specified event reader and default namespace.
 
Method Summary
protected  void addBooleanIntegerParsers(String namespace, String[] booleanIntegerFields)
          Add boolean integer parsers for a list of element types and qualified for a specified namespace.
protected  void addBooleanParsers(String namespace, String[] booleanFields)
          Add boolean parsers for a list of element types and qualified for a specified namespace.
protected  void addDoubleParsers(String namespace, String[] doubleFields)
          Add double parsers for a list of element types and qualified for a specified namespace.
 void addId(String id, Object o)
          Adds a mapping of an id attribute to its associated KML object.
protected  void addIntegerParsers(String namespace, String[] integerFields)
          Add integer parsers for a list of element types and qualified for a specified namespace.
protected  void addStringParsers(String namespace, String[] stringFields)
          Add string parsers for a list of element types and qualified for a specified namespace.
 XMLEventParser allocate(XMLEvent event)
          Create a parser for a specified event's element name, if a parser for that name is registered with the context.
 XMLEventParser allocate(XMLEvent event, XMLEventParser defaultParser)
          Create a parser for a specified event's element name, if a parser for that name is registered with the context.
 BooleanIntegerXMLEventParser getBooleanIntegerParser()
          Returns the default parser for a simple boolean integer (0 or 1).
 BooleanXMLEventParser getBooleanParser()
          Returns the default parser for a simple boolean.
 String getCharacters(XMLEvent event)
          Returns the text associated with the event.
 String getDefaultNamespaceURI()
          Returns the context's default namespace URI.
 DoubleXMLEventParser getDoubleParser()
          Returns a parser for a simple double.
 XMLEventReader getEventReader()
          Returns the event reader used by this instance.
 Map<String,Object> getIdTable()
          Returns the table associating objects with their id attribute as specified in the object's KML file.
 IntegerXMLEventParser getIntegerParser()
          Returns the default parser for a simple integer.
 XMLEventParser getParser(QName name)
          Returns a new parser for a specified element name.
 XMLEventParser getParser(XMLEvent event)
          Returns a new parser for a specified event.
protected  XMLEventParser getParser(XMLEvent event, XMLEventParser defaultParser)
           
 StringXMLEventParser getStringParser()
          Returns the default parser for a simple string.
 XMLEventParser getUnrecognizedElementParser()
          Returns a parser to handle unrecognized elements.
 boolean hasNext()
          Indicates whether the event stream associated with this context contains another event.
protected  void initialize()
           
protected  void initializeDefaultNotificationListener()
           
protected  void initializeParsers()
          Initializes the parser table with the default parsers for the strings, integers, etc., qualified for the default namespace.
 boolean isDefaultNamespace(String namespaceURI)
          Indicates whether the specified namespace URI is the default namespace URI used by this parser context.
 boolean isEndElement(XMLEvent event, XMLEvent startElement)
          Determines whether an event is the corresponding end element for a specified start event.
static boolean isEndElementEvent(XMLEvent event, XMLEvent startElement)
           
protected static boolean isNullNamespace(String namespaceURI)
           
 boolean isSameAttributeName(QName qa, QName qb)
          Determines whether two fully qualified attribute names are the same.
 boolean isSameName(QName qa, QName qb)
          Determines whether two element names are the same.
 boolean isStartElement(XMLEvent event, QName elementName)
          Determines whether an event is a start event for a specific event type.
 XMLEvent nextEvent()
          Returns the next event in the event stream associated with this context.
 void registerParser(QName elementName, XMLEventParser parser)
          Registers a parser for a specified element name.
 void resolveInternalReferences(String referenceName, String fieldName, AbstractXMLEventParser parser)
          Deprecated. 
 void setDefaultNamespaceURI(String defaultNamespaceURI)
          Specifies the context's default namespace URI.
 void setEventReader(XMLEventReader reader)
          Specify the event reader for the parser context to use to parse XML.
 void setNotificationListener(XMLParserNotificationListener listener)
          Specify the object to receive notifications, which are sent when exceptions occur during parsing and when unrecognized element types are encountered.
 
Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
 

Field Detail

BOOLEAN

public static QName BOOLEAN
The parser name of the default boolean parser.


BOOLEAN_INTEGER

public static QName BOOLEAN_INTEGER
The parser name of the default boolean integer parser.


booleanIntegerParser

protected BooleanIntegerXMLEventParser booleanIntegerParser

booleanParser

protected BooleanXMLEventParser booleanParser

defaultNamespaceURI

protected String defaultNamespaceURI

DOUBLE

public static QName DOUBLE
The parser name of the default double parser.


doubleParser

protected DoubleXMLEventParser doubleParser

idTable

protected ConcurrentHashMap<String,Object> idTable

INTEGER

public static QName INTEGER
The parser name of the default integer parser.


integerParser

protected IntegerXMLEventParser integerParser

notificationListener

protected XMLParserNotificationListener notificationListener

parsers

protected ConcurrentHashMap<QName,XMLEventParser> parsers

reader

protected XMLEventReader reader

STRING

public static QName STRING
The parser name of the default string parser.


stringParser

protected StringXMLEventParser stringParser

UNRECOGNIZED

public static QName UNRECOGNIZED
The parser name of the unrecognized-element parser.

Constructor Detail

BasicXMLEventParserContext

public BasicXMLEventParserContext()
Construct an instance. Invokes initializeParsers() and initialize().


BasicXMLEventParserContext

public BasicXMLEventParserContext(BasicXMLEventParserContext ctx)

BasicXMLEventParserContext

public BasicXMLEventParserContext(XMLEventReader eventReader)
Construct an instance for a specified event reader. Invokes initializeParsers() and initialize().

Parameters:
eventReader - the event reader to use for XML parsing.

BasicXMLEventParserContext

public BasicXMLEventParserContext(XMLEventReader eventReader,
                                  String defaultNamespace)
Construct an instance for a specified event reader and default namespace. Invokes initializeParsers() and initialize().

Parameters:
eventReader - the event reader to use for XML parsing.
defaultNamespace - the namespace URI of the default namespace.
Method Detail

addBooleanIntegerParsers

protected void addBooleanIntegerParsers(String namespace,
                                        String[] booleanIntegerFields)
Add boolean integer parsers for a list of element types and qualified for a specified namespace.

Parameters:
namespace - the namespace URI.
booleanIntegerFields - the string parser.

addBooleanParsers

protected void addBooleanParsers(String namespace,
                                 String[] booleanFields)
Add boolean parsers for a list of element types and qualified for a specified namespace.

Parameters:
namespace - the namespace URI.
booleanFields - the string parsers.

addDoubleParsers

protected void addDoubleParsers(String namespace,
                                String[] doubleFields)
Add double parsers for a list of element types and qualified for a specified namespace.

Parameters:
namespace - the namespace URI.
doubleFields - the string parsers.

addId

public void addId(String id,
                  Object o)
Description copied from interface: XMLEventParserContext
Adds a mapping of an id attribute to its associated KML object.

Specified by:
addId in interface XMLEventParserContext
Parameters:
id - the object id. If null, this method returns without creating a mapping.
o - the object to associate with the id.

addIntegerParsers

protected void addIntegerParsers(String namespace,
                                 String[] integerFields)
Add integer parsers for a list of element types and qualified for a specified namespace.

Parameters:
namespace - the namespace URI.
integerFields - the string parsers.

addStringParsers

protected void addStringParsers(String namespace,
                                String[] stringFields)
Add string parsers for a list of element types and qualified for a specified namespace.

Parameters:
namespace - the namespace URI.
stringFields - the string parsers.

allocate

public XMLEventParser allocate(XMLEvent event)
Description copied from interface: XMLEventParserContext
Create a parser for a specified event's element name, if a parser for that name is registered with the context.

Specified by:
allocate in interface XMLEventParserContext
Parameters:
event - the event whose element name identifies the parser to create.
Returns:
a new parser, or the specified default parser if no parser has been registered for the element name.

allocate

public XMLEventParser allocate(XMLEvent event,
                               XMLEventParser defaultParser)
Description copied from interface: XMLEventParserContext
Create a parser for a specified event's element name, if a parser for that name is registered with the context.

Specified by:
allocate in interface XMLEventParserContext
Parameters:
event - the event whose element name identifies the parser to create.
defaultParser - a parser to return if no parser is registered for the specified name. May be null.
Returns:
a new parser, or the specified default parser if no parser has been registered for the element name.

getBooleanIntegerParser

public BooleanIntegerXMLEventParser getBooleanIntegerParser()
Description copied from interface: XMLEventParserContext
Returns the default parser for a simple boolean integer (0 or 1).

Specified by:
getBooleanIntegerParser in interface XMLEventParserContext
Returns:
a boolean integer parser.

getBooleanParser

public BooleanXMLEventParser getBooleanParser()
Description copied from interface: XMLEventParserContext
Returns the default parser for a simple boolean.

Specified by:
getBooleanParser in interface XMLEventParserContext
Returns:
a boolean parser.

getCharacters

public String getCharacters(XMLEvent event)
Description copied from interface: XMLEventParserContext
Returns the text associated with the event.

Specified by:
getCharacters in interface XMLEventParserContext
Parameters:
event - the event of interest.
Returns:
the event's characters, or null if the event is not a character event.

getDefaultNamespaceURI

public String getDefaultNamespaceURI()
Description copied from interface: XMLEventParserContext
Returns the context's default namespace URI.

Specified by:
getDefaultNamespaceURI in interface XMLEventParserContext
Returns:
the context's default namespace URI.
See Also:
XMLEventParserContext.setDefaultNamespaceURI(String)

getDoubleParser

public DoubleXMLEventParser getDoubleParser()
Description copied from interface: XMLEventParserContext
Returns a parser for a simple double.

Specified by:
getDoubleParser in interface XMLEventParserContext
Returns:
a double parser.

getEventReader

public XMLEventReader getEventReader()
Returns the event reader used by this instance.

Specified by:
getEventReader in interface XMLEventParserContext
Returns:
the instance's event reader.

getIdTable

public Map<String,Object> getIdTable()
Description copied from interface: XMLEventParserContext
Returns the table associating objects with their id attribute as specified in the object's KML file.

Specified by:
getIdTable in interface XMLEventParserContext
Returns:
the mapping table.

getIntegerParser

public IntegerXMLEventParser getIntegerParser()
Description copied from interface: XMLEventParserContext
Returns the default parser for a simple integer.

Specified by:
getIntegerParser in interface XMLEventParserContext
Returns:
an integer parser.

getParser

public XMLEventParser getParser(QName name)
Description copied from interface: XMLEventParserContext
Returns a new parser for a specified element name.

Specified by:
getParser in interface XMLEventParserContext
Parameters:
name - indicates the element name for which a parser is created.
Returns:
the new parser, or null if no parser has been registered for the specified element name.

getParser

public XMLEventParser getParser(XMLEvent event)
Description copied from interface: XMLEventParserContext
Returns a new parser for a specified event.

Specified by:
getParser in interface XMLEventParserContext
Parameters:
event - indicates the element name for which a parser is created.
Returns:
the new parser, or null if no parser has been registered for the specified event's element name.

getParser

protected XMLEventParser getParser(XMLEvent event,
                                   XMLEventParser defaultParser)

getStringParser

public StringXMLEventParser getStringParser()
Description copied from interface: XMLEventParserContext
Returns the default parser for a simple string.

Specified by:
getStringParser in interface XMLEventParserContext
Returns:
a string parser.

getUnrecognizedElementParser

public XMLEventParser getUnrecognizedElementParser()
Returns a parser to handle unrecognized elements. The default unrecognized event parser is UnrecognizedXMLEventParser, and may be replaced by calling registerParser(javax.xml.namespace.QName, XMLEventParser) and specifying UNRECOGNIZED as the parser name.

Specified by:
getUnrecognizedElementParser in interface XMLEventParserContext
Returns:
a parser to handle unrecognized elements.

hasNext

public boolean hasNext()
Description copied from interface: XMLEventParserContext
Indicates whether the event stream associated with this context contains another event.

Specified by:
hasNext in interface XMLEventParserContext
Returns:
true if the stream contains another event, otherwise false.
See Also:
XMLEventReader.hasNext()

initialize

protected void initialize()

initializeDefaultNotificationListener

protected void initializeDefaultNotificationListener()

initializeParsers

protected void initializeParsers()
Initializes the parser table with the default parsers for the strings, integers, etc., qualified for the default namespace.


isDefaultNamespace

public boolean isDefaultNamespace(String namespaceURI)
Description copied from interface: XMLEventParserContext
Indicates whether the specified namespace URI is the default namespace URI used by this parser context.

Specified by:
isDefaultNamespace in interface XMLEventParserContext
Parameters:
namespaceURI - the namespace URI to check.
Returns:
true if the specified namespace is the default namespace, otherwise false.

isEndElement

public boolean isEndElement(XMLEvent event,
                            XMLEvent startElement)
Description copied from interface: XMLEventParserContext
Determines whether an event is the corresponding end element for a specified start event.

Note: Only the event's element name and type are compared. The method returns true if the start and end events are the corresponding event types for an element of the same name.

Specified by:
isEndElement in interface XMLEventParserContext
Parameters:
event - the event of interest.
startElement - the start event associated with the potential end event.
Returns:
true if the event is the corresponding end event to the specified start event, otherwise false.

isEndElementEvent

public static boolean isEndElementEvent(XMLEvent event,
                                        XMLEvent startElement)

isNullNamespace

protected static boolean isNullNamespace(String namespaceURI)

isSameAttributeName

public boolean isSameAttributeName(QName qa,
                                   QName qb)
Description copied from interface: XMLEventParserContext
Determines whether two fully qualified attribute names are the same.

Specified by:
isSameAttributeName in interface XMLEventParserContext
Parameters:
qa - the first attribute name.
qb - the second attribute name.
Returns:
true if the names are the same, otherwise false.

isSameName

public boolean isSameName(QName qa,
                          QName qb)
Description copied from interface: XMLEventParserContext
Determines whether two element names are the same.

Specified by:
isSameName in interface XMLEventParserContext
Parameters:
qa - first element name
qb - second element name
Returns:
true if both names have the same namespace (or no namespace) and local name, or if either name has no namespace but the namespace of the other is the context's default namespace.

isStartElement

public boolean isStartElement(XMLEvent event,
                              QName elementName)
Description copied from interface: XMLEventParserContext
Determines whether an event is a start event for a specific event type.

Specified by:
isStartElement in interface XMLEventParserContext
Parameters:
event - an event identifying the event type of interest.
elementName - the event name.
Returns:
true if the event is a start event for the named event type.

nextEvent

public XMLEvent nextEvent()
                   throws XMLStreamException
Description copied from interface: XMLEventParserContext
Returns the next event in the event stream associated with this context.

Specified by:
nextEvent in interface XMLEventParserContext
Returns:
the next event,
Throws:
XMLStreamException - if there is an error with the underlying XML.
See Also:
XMLEventReader.nextEvent()

registerParser

public void registerParser(QName elementName,
                           XMLEventParser parser)
Description copied from interface: XMLEventParserContext
Registers a parser for a specified element name. A parser of the same type and namespace is returned when XMLEventParserContext.getParser(javax.xml.stream.events.XMLEvent) is called for the same element name.

Specified by:
registerParser in interface XMLEventParserContext
Parameters:
elementName - the element name for which to return a parser.
parser - the parser to register.

resolveInternalReferences

@Deprecated
public void resolveInternalReferences(String referenceName,
                                                 String fieldName,
                                                 AbstractXMLEventParser parser)
Deprecated. 

Description copied from interface: XMLEventParserContext
Resolves references to elements in the same KML file. Certain KML elements such as styleUrl may contain references to other elements within the same KML file. (A leading "#" indicates a reference to an element within the same file.) This method searches the elements in the file for these references and adds the object for the element they refer to the referring object's field table.

Specified by:
resolveInternalReferences in interface XMLEventParserContext
Parameters:
referenceName - the element name of the elements whose references this method resolves. An example is styleUrl. Resolution is performed for only elements of this name.
fieldName - the key used to identify the resolved object in a parser's field table. After this method resolves references, the referenced object can be obtained by calling the parsers AbstractXMLEventParser.getField(javax.xml.namespace.QName) method with the fieldName specified here as the name argument.
parser - the parser whose references to resolve.

setDefaultNamespaceURI

public void setDefaultNamespaceURI(String defaultNamespaceURI)
Description copied from interface: XMLEventParserContext
Specifies the context's default namespace URI. Must be called prior to initiating the parser table if this context's parsers will be qualified for the default namespace.

Specified by:
setDefaultNamespaceURI in interface XMLEventParserContext
Parameters:
defaultNamespaceURI - the default namespace URI.
See Also:
XMLEventParserContext.getDefaultNamespaceURI(), XMLEventParserContext.isSameName(javax.xml.namespace.QName, javax.xml.namespace.QName)

setEventReader

public void setEventReader(XMLEventReader reader)
Specify the event reader for the parser context to use to parse XML.

Parameters:
reader - the event reader to use.

setNotificationListener

public void setNotificationListener(XMLParserNotificationListener listener)
Description copied from interface: XMLEventParserContext
Specify the object to receive notifications, which are sent when exceptions occur during parsing and when unrecognized element types are encountered. See XMLParserNotification for more information.

The parser context may have only one notification listener. That listener may be changed at any time.

Specified by:
setNotificationListener in interface XMLEventParserContext
Parameters:
listener - the object to receive notification events.

NASA World Wind