com.vividsolutions.jump.io
Class GMLInputTemplate

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by com.vividsolutions.jump.io.GMLInputTemplate
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class GMLInputTemplate
extends org.xml.sax.helpers.DefaultHandler

Reads an XML file that starts with a 'JCSGMLInputTemplate'.
Will abort read at the end of the 'JCSGMLInputTemplate' tag.
Constructs a description of the Columns and geometry tag so the
actual GML parser (GMLReader) will know what to do with different tags.

This is a SAX Handler.


Field Summary
 boolean loaded
           
 
Constructor Summary
GMLInputTemplate()
          constructor - makes a new org.apache.xerces.parser and makes this class be the SAX content and error handler.
 
Method Summary
 void characters(char[] ch, int start, int length)
          SAX handler for characters - just store and accumulate for later use
 java.lang.String columnName(int index)
          Returns the column name for the 'index'th column.
 void endDocument()
          SAX endDocument handler - null
 void endElement(java.lang.String uri, java.lang.String name, java.lang.String qName)
          SAX endElement handler - the main working function

handles the following tags in the appropriate manner:
GeometryElement : sets the name of the document's geometry tag
CollectionElement : sets the name of the document's collection tag
FeatureElement : sets the name of the document's feature tag
type : sets a column type (to be used when a column ends)
valueelement : sets information about what element a column is associated with
valuelocation : set information about where a column's value is stored in the document
column : takes the accumlated information about a column and constructs a ColumnDescription object
 void error(org.xml.sax.SAXParseException exception)
           
 void fatalError(org.xml.sax.SAXParseException exception)
           
 java.lang.Object getColumnValue(int index, java.lang.String tagBody, org.xml.sax.Attributes xmlAtts)
          Given a ColumnDescription index, the XML tagBody, and the tag's attributes, return the actual value (it could be an attribute or the tag's body).
 java.lang.String getFeatureCollectionElementName()
          Get the name of the FeatureCollectionElement tag
 java.lang.String getFeatureElementName()
          Get the name of the FeatureElement tag
 boolean isGeometryElement(java.lang.String tag)
          Function to help the GMLParser - is this tag name the Geometry Element tag name?
 void load(java.io.Reader r)
          Helper function - load a GMLInputTemplate file with the stream name "Unknown Stream"
 void load(java.io.Reader r, java.lang.String readerName)
          Main function - load in an XML file.
 int match(java.lang.String XMLtagName, org.xml.sax.Attributes xmlAtts)
          Given a tag name and its XML attributes, find the index of the column it belongs to.
Returns -1 if it doesnt match any of the columns.
 void startDocument()
          SAX startDocument handler - null
 void startElement(java.lang.String uri, java.lang.String name, java.lang.String qName, org.xml.sax.Attributes atts)
          SAX startElement handler
Basically just records the tag name and its attributes since all the smarts are in the endElement handler.
 FeatureSchema toFeatureSchema()
          Converts this GMLInputTemplate to a feature schema.
 void warning(org.xml.sax.SAXParseException exception)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loaded

public boolean loaded
Constructor Detail

GMLInputTemplate

public GMLInputTemplate()
constructor - makes a new org.apache.xerces.parser and makes this class be the SAX content and error handler.

Method Detail

columnName

public java.lang.String columnName(int index)
                            throws ParseException
Returns the column name for the 'index'th column.

Parameters:
index - 0=first
Throws:
ParseException

toFeatureSchema

public FeatureSchema toFeatureSchema()
                              throws ParseException
Converts this GMLInputTemplate to a feature schema.

Throws:
ParseException

isGeometryElement

public boolean isGeometryElement(java.lang.String tag)
Function to help the GMLParser - is this tag name the Geometry Element tag name?

Parameters:
tag - an XML tag name

load

public void load(java.io.Reader r)
          throws ParseException,
                 java.io.IOException
Helper function - load a GMLInputTemplate file with the stream name "Unknown Stream"

Throws:
ParseException
java.io.IOException

load

public void load(java.io.Reader r,
                 java.lang.String readerName)
          throws ParseException,
                 java.io.IOException
Main function - load in an XML file.
Error handling/reporting also done here.

Parameters:
r - where to read the XML file from
readerName - name of the stream for error reporting
Throws:
ParseException
java.io.IOException

getFeatureCollectionElementName

public java.lang.String getFeatureCollectionElementName()
                                                 throws ParseException
Get the name of the FeatureCollectionElement tag

Throws:
ParseException

getFeatureElementName

public java.lang.String getFeatureElementName()
                                       throws ParseException
Get the name of the FeatureElement tag

Throws:
ParseException

match

public int match(java.lang.String XMLtagName,
                 org.xml.sax.Attributes xmlAtts)
          throws ParseException
Given a tag name and its XML attributes, find the index of the column it belongs to.
Returns -1 if it doesnt match any of the columns.

Parameters:
XMLtagName - the tag name found in the xml
the - attributes associated with the xml
Throws:
ParseException

getColumnValue

public java.lang.Object getColumnValue(int index,
                                       java.lang.String tagBody,
                                       org.xml.sax.Attributes xmlAtts)
                                throws ParseException
Given a ColumnDescription index, the XML tagBody, and the tag's attributes, return the actual value (it could be an attribute or the tag's body). You probably got the index from the match() function.

Parameters:
index - index number of the column description
tagBody - value of the XML tag body
xmlAtts - key/values of the XML tag's attributes
Throws:
ParseException

warning

public void warning(org.xml.sax.SAXParseException exception)
             throws org.xml.sax.SAXException
Specified by:
warning in interface org.xml.sax.ErrorHandler
Overrides:
warning in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

error

public void error(org.xml.sax.SAXParseException exception)
           throws org.xml.sax.SAXException
Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

fatalError

public void fatalError(org.xml.sax.SAXParseException exception)
                throws org.xml.sax.SAXException
Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Overrides:
fatalError in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

startDocument

public void startDocument()
SAX startDocument handler - null

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler

endDocument

public void endDocument()
SAX endDocument handler - null

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler

startElement

public void startElement(java.lang.String uri,
                         java.lang.String name,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
SAX startElement handler
Basically just records the tag name and its attributes since all the smarts are in the endElement handler.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String name,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
SAX endElement handler - the main working function

handles the following tags in the appropriate manner:
GeometryElement : sets the name of the document's geometry tag
CollectionElement : sets the name of the document's collection tag
FeatureElement : sets the name of the document's feature tag
type : sets a column type (to be used when a column ends)
valueelement : sets information about what element a column is associated with
valuelocation : set information about where a column's value is stored in the document
column : takes the accumlated information about a column and constructs a ColumnDescription object

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
SAX handler for characters - just store and accumulate for later use

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException