Class FlatXmlProducer

java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.dbunit.dataset.xml.FlatXmlProducer
All Implemented Interfaces:
IDataSetProducer, ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class FlatXmlProducer extends DefaultHandler implements IDataSetProducer, ContentHandler
IDataSetProducer that parses a flat XML dataset document via SAX and streams table/row events.
Since:
1.5 (Apr 18, 2003)
Version:
$Revision$ $Date$
Author:
Manuel Laflamme, Last changed by: $Author$
  • Constructor Details

    • FlatXmlProducer

      public FlatXmlProducer(InputSource xmlSource)
      Creates a producer that reads the given XML source, with DTD metadata enabled.
      Parameters:
      xmlSource - The input datasource
    • FlatXmlProducer

      public FlatXmlProducer(InputSource xmlSource, boolean dtdMetadata)
      Creates a producer that reads the given XML source.
      Parameters:
      xmlSource - The input datasource
      dtdMetadata - Whether or not DTD metadata is available to parse via a DTD handler
    • FlatXmlProducer

      public FlatXmlProducer(InputSource xmlSource, IDataSet metaDataSet)
      Creates a producer that reads the given XML source, using the given dataset as the source of metadata instead of parsing a DTD.
      Parameters:
      xmlSource - The input datasource
      metaDataSet - the dataset used as metadata source.
    • FlatXmlProducer

      public FlatXmlProducer(InputSource xmlSource, EntityResolver resolver)
      Creates a producer that reads the given XML source, with DTD metadata enabled and resolved using the given entity resolver.
      Parameters:
      xmlSource - The input datasource
      resolver - the entity resolver used to resolve the DTD.
    • FlatXmlProducer

      public FlatXmlProducer(InputSource xmlSource, boolean dtdMetadata, boolean columnSensing)
      Creates a producer that reads the given XML source.
      Parameters:
      xmlSource - The input datasource
      dtdMetadata - Whether or not DTD metadata is available to parse via a DTD handler
      columnSensing - Whether or not the column sensing feature should be used (see FAQ)
    • FlatXmlProducer

      public FlatXmlProducer(InputSource xmlSource, boolean dtdMetadata, boolean columnSensing, boolean caseSensitiveTableNames)
      Creates a producer that reads the given XML source.
      Parameters:
      xmlSource - The input datasource
      dtdMetadata - Whether or not DTD metadata is available to parse via a DTD handler
      columnSensing - Whether or not the column sensing feature should be used (see FAQ)
      caseSensitiveTableNames - Whether or not this dataset should use case sensitive table names
      Since:
      2.4.2
  • Method Details

    • isCaseSensitiveTableNames

      public boolean isCaseSensitiveTableNames()
      Returns whether or not this producer works case sensitively.
      Returns:
      Whether or not this producer works case sensitively
      Since:
      2.4.7
    • handleMissingColumns

      protected void handleMissingColumns(Attributes attributes) throws DataSetException
      parses the attributes in the current row, and checks whether a new column is found.

      Depending on the value of the columnSensing flag, the appropriate action is taken:

      • If it is true, the new column is merged back into the metadata;
      • If not, a warning message is displayed.
      Parameters:
      attributes - Attributed for the current row.
      Throws:
      DataSetException - if the metadata cannot be merged.
    • setColumnSensing

      public void setColumnSensing(boolean columnSensing)
      Sets whether or not the column sensing feature should be used.
      Parameters:
      columnSensing - whether or not the column sensing feature should be used.
    • setValidating

      public void setValidating(boolean validating)
      Sets whether or not the XML parser should validate against its DTD.
      Parameters:
      validating - whether or not the XML parser should validate against its DTD.
    • setConsumer

      public void setConsumer(IDataSetConsumer consumer) throws DataSetException
      Description copied from interface: IDataSetProducer
      Sets the consumer notified of this producer's dataset content.
      Specified by:
      setConsumer in interface IDataSetProducer
      Parameters:
      consumer - the consumer to notify.
      Throws:
      DataSetException - if the consumer cannot be set.
    • produce

      public void produce() throws DataSetException
      Description copied from interface: IDataSetProducer
      Process this dataset source. During the processing, the IDataSetProducer will provide information about the dataset through the specified event listener.

      This method is synchronous: it will not return until processing has ended. If a client application wants to terminate parsing early, it should throw an exception from the listener.

      Specified by:
      produce in interface IDataSetProducer
      Throws:
      DataSetException - if processing the dataset source fails.
    • resolveEntity

      public InputSource resolveEntity(String publicId, String systemId) throws SAXException
      Specified by:
      resolveEntity in interface EntityResolver
      Overrides:
      resolveEntity in class DefaultHandler
      Throws:
      SAXException
    • error

      public void error(SAXParseException e) throws SAXException
      Specified by:
      error in interface ErrorHandler
      Overrides:
      error in class DefaultHandler
      Throws:
      SAXException
    • startElement

      public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
      Specified by:
      startElement in interface ContentHandler
      Overrides:
      startElement in class DefaultHandler
      Throws:
      SAXException
    • determineAndSetRowValue

      protected void determineAndSetRowValue(Attributes attributes, ITableMetaData activeMetaData, Object[] rowValues, int i) throws DataSetException, NoSuchColumnException
      Resolves the given attribute's column index in the active metadata and stores its value at that index in rowValues.
      Parameters:
      attributes - the current row's attributes.
      activeMetaData - the active table metadata.
      rowValues - the row value array to populate.
      i - the index, into attributes, of the attribute to process.
      Throws:
      DataSetException - if resolving the column index fails.
      NoSuchColumnException - if the attribute has no corresponding column.
    • endElement

      public void endElement(String uri, String localName, String qName) throws SAXException
      Specified by:
      endElement in interface ContentHandler
      Overrides:
      endElement in class DefaultHandler
      Throws:
      SAXException