Package org.dbunit.dataset.xml
Class FlatXmlProducer
java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.dbunit.dataset.xml.FlatXmlProducer
- All Implemented Interfaces:
IDataSetProducer,ContentHandler,DTDHandler,EntityResolver,ErrorHandler
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 Summary
ConstructorsConstructorDescriptionFlatXmlProducer(InputSource xmlSource) Creates a producer that reads the given XML source, with DTD metadata enabled.FlatXmlProducer(InputSource xmlSource, boolean dtdMetadata) Creates a producer that reads the given XML source.FlatXmlProducer(InputSource xmlSource, boolean dtdMetadata, boolean columnSensing) Creates a producer that reads the given XML source.FlatXmlProducer(InputSource xmlSource, boolean dtdMetadata, boolean columnSensing, boolean caseSensitiveTableNames) Creates a producer that reads the given XML source.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.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. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddetermineAndSetRowValue(Attributes attributes, ITableMetaData activeMetaData, Object[] rowValues, int i) Resolves the given attribute's column index in the active metadata and stores its value at that index in rowValues.voidendElement(String uri, String localName, String qName) voidprotected voidhandleMissingColumns(Attributes attributes) parses the attributes in the current row, and checks whether a new column is found.booleanReturns whether or not this producer works case sensitively.voidproduce()Process this dataset source.resolveEntity(String publicId, String systemId) voidsetColumnSensing(boolean columnSensing) Sets whether or not the column sensing feature should be used.voidsetConsumer(IDataSetConsumer consumer) Sets the consumer notified of this producer's dataset content.voidsetValidating(boolean validating) Sets whether or not the XML parser should validate against its DTD.voidstartElement(String uri, String localName, String qName, Attributes attributes) Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endPrefixMapping, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warningMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.xml.sax.ContentHandler
characters, declaration, endDocument, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping
-
Constructor Details
-
FlatXmlProducer
Creates a producer that reads the given XML source, with DTD metadata enabled.- Parameters:
xmlSource- The input datasource
-
FlatXmlProducer
Creates a producer that reads the given XML source.- Parameters:
xmlSource- The input datasourcedtdMetadata- Whether or not DTD metadata is available to parse via a DTD handler
-
FlatXmlProducer
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 datasourcemetaDataSet- the dataset used as metadata source.
-
FlatXmlProducer
Creates a producer that reads the given XML source, with DTD metadata enabled and resolved using the given entity resolver.- Parameters:
xmlSource- The input datasourceresolver- the entity resolver used to resolve the DTD.
-
FlatXmlProducer
Creates a producer that reads the given XML source.- Parameters:
xmlSource- The input datasourcedtdMetadata- Whether or not DTD metadata is available to parse via a DTD handlercolumnSensing- 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 datasourcedtdMetadata- Whether or not DTD metadata is available to parse via a DTD handlercolumnSensing- 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
parses the attributes in the current row, and checks whether a new column is found.Depending on the value of the
columnSensingflag, 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
Description copied from interface:IDataSetProducerSets the consumer notified of this producer's dataset content.- Specified by:
setConsumerin interfaceIDataSetProducer- Parameters:
consumer- the consumer to notify.- Throws:
DataSetException- if the consumer cannot be set.
-
produce
Description copied from interface:IDataSetProducerProcess 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:
producein interfaceIDataSetProducer- Throws:
DataSetException- if processing the dataset source fails.
-
resolveEntity
- Specified by:
resolveEntityin interfaceEntityResolver- Overrides:
resolveEntityin classDefaultHandler- Throws:
SAXException
-
error
- Specified by:
errorin interfaceErrorHandler- Overrides:
errorin classDefaultHandler- Throws:
SAXException
-
startElement
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException - Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- 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
- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXException
-