jwo.landserf.process.io
Class MasterMapReader

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended byjwo.landserf.process.io.MasterMapReader
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class MasterMapReader
extends DefaultHandler

Reads in an Ordnance Survey MasterMap file in serial fashion using a SAX parser.

Version:
2.2, 5th December, 2004.
Author:
Jo Wood

Constructor Summary
MasterMapReader(String fileName, GISFrame gisFrame, LSThread lsThread)
          Starts the parsing of the given XML file, and gathers information about the attribute types.
MasterMapReader(String fileName, VectorMap vectorMap, GISFrame gisFrame, LSThread lsThread)
          Starts the parsing of the given XML file, placing all objects into the given vector map and reporting progress to the GISFrame.
MasterMapReader(String fileName, VectorMap vectorMap, TreeMap attributeTypes, int readStyle, GISFrame gisFrame, LSThread lsThread)
          Starts the parsing of the given XML file.
 
Method Summary
 void characters(char[] text, int offset, int length)
          Called by the parser when character text is found.
protected  void display(String message, boolean position)
          Displays the given message with an option of identifying the approximate currently parsed line and column identified by the parser Locator.
 void endDocument()
          Called by the parser when the document represented by the XML is finally closed.
 void endElement(String uri, String sName, String qName)
          Called by the parser when the end of an element is found.
 void error(SAXParseException e)
          Called when the parser encounters a non-fatal error.
 void fatalError(SAXParseException e)
          Called when the parser encounters a fatal error.
 TreeMap getAttributeTypes()
          Reports a sorted list of attribute types found after scanning the XML file.
 String getLastError()
          Reports last error that was generated by the parser, or null if no error or warning has occurred.
 void setDocumentLocator(Locator locator)
          This method is called by the parser when the XML file for parsing is first opened.
 void startDocument()
          Called by the parser when the document represented by the XML is first opened.
 void startElement(String uri, String sName, String qName, Attributes atts)
          Called by the parser when the start of an element is found.
 void warning(SAXParseException e)
          Called when the parser encounters a non-fatal warning.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MasterMapReader

public MasterMapReader(String fileName,
                       VectorMap vectorMap,
                       GISFrame gisFrame,
                       LSThread lsThread)
Starts the parsing of the given XML file, placing all objects into the given vector map and reporting progress to the GISFrame.

Parameters:
fileName - Name of XML file to process.
vectorMap - Vector map to contain XML data.
gisFrame - GIS Frame in which to report progress.
lsThread - Thread which called this method (allows it to be interrupted). Can be null if no external interruption allowed.

MasterMapReader

public MasterMapReader(String fileName,
                       GISFrame gisFrame,
                       LSThread lsThread)
Starts the parsing of the given XML file, and gathers information about the attribute types. Does not load any geometry or create a vector map. The results of the parsing can be retrieved by calling getAttributeTypes().

Parameters:
fileName - Name of XML file to process.
gisFrame - GIS Frame in which to report progress.
lsThread - Thread which called this method (allows it to be interrupted). Can be null if no external interruption allowed.

MasterMapReader

public MasterMapReader(String fileName,
                       VectorMap vectorMap,
                       TreeMap attributeTypes,
                       int readStyle,
                       GISFrame gisFrame,
                       LSThread lsThread)
Starts the parsing of the given XML file. If readStyle is GATHER_INFO, then the XML file is scanned for attribute groups and geometry data are not loaded. If readStyle is LOAD_ALL, all objects are placed into the given vector map. If readStyle is LOAD_SELECTED, only those attributes identifed in the given attributeTypes collection are read into the vector map.

Parameters:
fileName - Name of XML file to process.
vectorMap - Vector map to contain XML data.
attributeTypes - List of attribute types to be read (only applied to LOAD_SELECTED).
readStyle - Determines how file is processed.
gisFrame - GIS Frame in which to report progress.
lsThread - Thread which called this method (allows it to be interrupted). Can be null if no external interruption allowed.
Method Detail

getAttributeTypes

public TreeMap getAttributeTypes()
Reports a sorted list of attribute types found after scanning the XML file.

Returns:
A list of attribute types found in the XML file.

getLastError

public String getLastError()
Reports last error that was generated by the parser, or null if no error or warning has occurred.

Returns:
Text representing last parsing error or null if no errors.

setDocumentLocator

public void setDocumentLocator(Locator locator)
This method is called by the parser when the XML file for parsing is first opened. It stores a Locator that keeps track of the name of the XML file and the position in the file currently being processed.

Parameters:
locator - Keeps track of the parsing process.

startDocument

public void startDocument()
                   throws SAXException
Called by the parser when the document represented by the XML is first opened.

Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
Called by the parser when the document represented by the XML is finally closed.

Throws:
SAXException

startElement

public void startElement(String uri,
                         String sName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Called by the parser when the start of an element is found. Displays the element and its attributes.

Parameters:
uri - Namespace reference (ignored).
sName - Simple name of the element.
qName - Fully qualified name of the element.
atts - Attributes associated with the element.
Throws:
SAXException

endElement

public void endElement(String uri,
                       String sName,
                       String qName)
                throws SAXException
Called by the parser when the end of an element is found. Can process any preceding character elements such as coordinates or labels.

Parameters:
uri - Namespace reference (ignored).
sName - Simple name of the element.
qName - Fully qualified name of the element.
Throws:
SAXException

characters

public void characters(char[] text,
                       int offset,
                       int length)
                throws SAXException
Called by the parser when character text is found. For exmaple between element tags. Displays text found.

Parameters:
text - Array of characters.
offset - Position in array where characters start.
length - Number of characters to use from text array.
Throws:
SAXException

warning

public void warning(SAXParseException e)
             throws SAXException
Called when the parser encounters a non-fatal warning. Displays the warning in the standard error stream.

Parameters:
e - Exception that caused the warning.
Throws:
SAXException

error

public void error(SAXParseException e)
           throws SAXException
Called when the parser encounters a non-fatal error. Displays the error in the standard error stream.

Parameters:
e - Exception that caused the warning.
Throws:
SAXException

fatalError

public void fatalError(SAXParseException e)
                throws SAXException
Called when the parser encounters a fatal error. Displays the error in the standard error stream.

Parameters:
e - Exception that caused the warning.
Throws:
SAXException

display

protected void display(String message,
                       boolean position)
Displays the given message with an option of identifying the approximate currently parsed line and column identified by the parser Locator.

Parameters:
message - Message to display.
position - Position in the file identified if true.


Copyright Jo Wood, 1996-2005, last modified, 11th March, 2005