dbxml.sax
Class JDBCSAXParser

java.lang.Object
  |
  +--dbxml.sax.ParserBase
        |
        +--dbxml.sax.JDBCSAXParser

public class JDBCSAXParser
extends ParserBase

SAX parser that uses a JDBC data source a input instead of an XML file of byte stream. This is a proof-of-concept implemention and does not address all the issues. Many improvements to this parser are possible. This parser treats a table in a database as a virtual XML document.

Author:
Ramnivas Laddad

Fields inherited from class dbxml.sax.ParserBase
_documentHandler, _dtdHandler, _entityResolver, _errorHandler
 
Constructor Summary
JDBCSAXParser()
           
 
Method Summary
protected  void generateSAXEventForColumn(java.sql.ResultSetMetaData rsmd, java.sql.ResultSet rs, int columnIndex)
          Generate SAX event when visting a column.
protected  java.lang.String getColumnMarker(java.lang.String columnName)
          Get the marker for indicating the start and end of a column.
protected  java.lang.String getRowMarker()
          Get the marker for indicating the start and end of a row.
protected  java.lang.String getSelectorSQLStatement(java.lang.String tableName)
          Get the select query that will be used to obtain the result set for parsing.
protected  java.lang.String getTableMarker(java.lang.String tableName)
          Get the marker for indicating the start and end of the document.
 void parse(org.xml.sax.InputSource source)
          Implement the method from base interface.
 void parse(JDBCInputSource source)
          Parse the given JDBC source to generate SAX events.
 void parse(java.sql.ResultSet rs, java.lang.String tableName)
          Parse the given JDBC result set object to generate SAX events.
 void parse(java.lang.String systemId)
          Implement the method from base interface.
 void parse(java.lang.String connectionURL, java.lang.String userName, java.lang.String passwd, java.lang.String tableName)
          A convenience method that creates a JDBCInputSource object from its argument and parses it
 
Methods inherited from class dbxml.sax.ParserBase
setDocumentHandler, setDTDHandler, setEntityResolver, setErrorHandler, setLocale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCSAXParser

public JDBCSAXParser()
Method Detail

parse

public void parse(org.xml.sax.InputSource source)
           throws org.xml.sax.SAXException,
                  java.io.IOException
Implement the method from base interface. If the argument input source is of type other than JDBCInputSource, it throws an SAXException as this parser cannot deal with it
Parameters:
source - an input source (must be of type JDBCInputSource)
Throws:
org.xml.sax.SAXException - if an error occurs or the argument is not of type JDBCInputSource
java.io.IOException - if an error occurs

parse

public void parse(java.lang.String systemId)
           throws org.xml.sax.SAXException,
                  java.io.IOException
Implement the method from base interface. Always thows an SAXException as the information passed is not sufficient to carry out parsing.
Parameters:
systemId - unused
Throws:
org.xml.sax.SAXException - thrown always
java.io.IOException - never thrown

parse

public void parse(JDBCInputSource source)
           throws org.xml.sax.SAXException,
                  java.io.IOException
Parse the given JDBC source to generate SAX events. Obtains a result set by executing a query returned by getSelectorSQLStatement and then parses that result set.
Parameters:
source - a input source describing database table to be parsed
Throws:
org.xml.sax.SAXException - if an error occurs
java.io.IOException - if an error occurs

parse

public void parse(java.sql.ResultSet rs,
                  java.lang.String tableName)
           throws org.xml.sax.SAXException,
                  java.sql.SQLException,
                  java.io.IOException
Parse the given JDBC result set object to generate SAX events.
Parameters:
rs - result set object to be parsed
tableName - the name of table name being parsed
Throws:
org.xml.sax.SAXException - if an parsing error occurs
java.sql.SQLException - if an SQL error occurs
java.io.IOException - if an i/o error occurs

parse

public void parse(java.lang.String connectionURL,
                  java.lang.String userName,
                  java.lang.String passwd,
                  java.lang.String tableName)
           throws org.xml.sax.SAXException,
                  java.io.IOException
A convenience method that creates a JDBCInputSource object from its argument and parses it
Parameters:
connectionURL - a JDBC URL for the database
userName - user name to connect to the database
passwd - password to connect to the database
tableName - the name of table name being parsed
Throws:
org.xml.sax.SAXException - if an parsing error occurs
java.io.IOException - if an i/o error occurs

generateSAXEventForColumn

protected void generateSAXEventForColumn(java.sql.ResultSetMetaData rsmd,
                                         java.sql.ResultSet rs,
                                         int columnIndex)
                                  throws org.xml.sax.SAXException,
                                         java.sql.SQLException
Generate SAX event when visting a column. Fires startElement event followed by a characters event followed by endElement event. No events are fired for a null data.
This method may be overriden to customize event generation for columns. For example, if one wishes to use special attribute, instead of no events, for indicating null column, then this is the method to override. Also for handling binary data or using desired format for special types such as date and currency, one may override this method.
Parameters:
rsmd - meta data for the result set
rs - the result set
columnIndex - index of column being visited (1 for first column)
Throws:
org.xml.sax.SAXException - if an parsing error occurs
java.sql.SQLException - if an SQL error occurs

getTableMarker

protected java.lang.String getTableMarker(java.lang.String tableName)
Get the marker for indicating the start and end of the document. By default, it is same as the name of the table. Override this to use custom marker.
Parameters:
tableName - the name of table name being parsed
Returns:
the marker desired

getRowMarker

protected java.lang.String getRowMarker()
Get the marker for indicating the start and end of a row. By default it is "row". Override this to use custome marker.
Returns:
the marker desired

getColumnMarker

protected java.lang.String getColumnMarker(java.lang.String columnName)
Get the marker for indicating the start and end of a column. By default it is same as the name of column. Override this to use custome marker.
Parameters:
columnName - a value of type 'String'
Returns:
a value of type 'String'

getSelectorSQLStatement

protected java.lang.String getSelectorSQLStatement(java.lang.String tableName)
Get the select query that will be used to obtain the result set for parsing. By default it is "select * from ". Override this to allow database-level filtering.
Parameters:
tableName - the name of table name being parsed
Returns:
query string