de.hpi.fgis.dude.datasource
Class XMLSource

java.lang.Object
  extended by de.hpi.fgis.dude.util.AbstractCleanable
      extended by de.hpi.fgis.dude.datasource.AbstractDataSource<XMLSource>
          extended by de.hpi.fgis.dude.datasource.XMLSource
All Implemented Interfaces:
DataSource, Cleanable, AutoJsonable, Jsonable, JsonableReader<DuDeObject>, Closeable, Iterable<DuDeObject>

public class XMLSource
extends AbstractDataSource<XMLSource>
implements Jsonable

XMLSource represents *.xml files.

Author:
Matthias Pohl

Nested Class Summary
protected  class XMLSource.XMLSourceIterator
          XMLSourceIterator is used for generating DuDeObjects out of XMLSources.
 
Nested classes/interfaces inherited from class de.hpi.fgis.dude.datasource.AbstractDataSource
AbstractDataSource.AbstractDataSourceIterator<T extends AbstractDataSource<?>>
 
Constructor Summary
protected XMLSource()
          Internal constructor for Jsonable deserialization.
  XMLSource(String identifier, File file)
          Initializes a XMLSource that converts all elements in the first XML layer into JsonRecords.
  XMLSource(String identifier, File file, String root)
          Initializes a XMLSource that converts all direct child elements of the given root into DuDeObjects.
 
Method Summary
 void cleanUp()
          Closes all registered Closeable and Cleanable instances.
protected  XMLStreamReader createXMLStreamReader()
          Instantiates a new XMLStreamReader.
 void fromJson(DuDeJsonParser<?> jsonParser)
          Initializes the current instance using the passed DuDeJsonParser.
protected  String getRootElementTag()
          Returns the set root element or null, if no root was set.
 Iterator<DuDeObject> iterator()
           
protected  boolean rootIsSet()
          Checks whether a root element was set.
 void toJson(DuDeJsonGenerator jsonGenerator)
          Generates the Json code using the passed DuDeJsonGenerator.
 
Methods inherited from class de.hpi.fgis.dude.datasource.AbstractDataSource
addIdAttributes, autoGeneratedIds, close, equals, getExtractedRecordCount, getIdAttributes, getIdentifier, hashCode, setExtractedRecordCount, toString, withIdAttributes
 
Methods inherited from class de.hpi.fgis.dude.util.AbstractCleanable
registerCleanable, registerCloseable
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.hpi.fgis.dude.util.Cleanable
registerCleanable, registerCloseable
 

Constructor Detail

XMLSource

protected XMLSource()
Internal constructor for Jsonable deserialization.


XMLSource

public XMLSource(String identifier,
                 File file)
          throws FileNotFoundException
Initializes a XMLSource that converts all elements in the first XML layer into JsonRecords.

Parameters:
identifier - The identifier of the DataSource instance.
file - The XML file from which the data shall be extracted.
Throws:
FileNotFoundException - If the passed file does not exist.

XMLSource

public XMLSource(String identifier,
                 File file,
                 String root)
          throws FileNotFoundException
Initializes a XMLSource that converts all direct child elements of the given root into DuDeObjects.

Parameters:
identifier - The identifier of the DataSource instance.
file - The XML file from which the data shall be extracted.
root - The tag of the element, of which the child elements will be extracted.
Throws:
FileNotFoundException - If the passed file does not exist.
Method Detail

cleanUp

public void cleanUp()
Description copied from interface: Cleanable
Closes all registered Closeable and Cleanable instances.

Specified by:
cleanUp in interface Cleanable
Overrides:
cleanUp in class AbstractCleanable

createXMLStreamReader

protected XMLStreamReader createXMLStreamReader()
                                         throws XMLStreamException
Instantiates a new XMLStreamReader.

Returns:
The newly instantiated XMLStreamReader.
Throws:
XMLStreamException - If an error occurred while instantiating the XMLStreamReader.

rootIsSet

protected boolean rootIsSet()
Checks whether a root element was set.

Returns:
true, if a root element was set; otherwise false.

getRootElementTag

protected String getRootElementTag()
Returns the set root element or null, if no root was set.

Returns:
The set root element.

iterator

public Iterator<DuDeObject> iterator()
Specified by:
iterator in interface Iterable<DuDeObject>
Specified by:
iterator in class AbstractDataSource<XMLSource>

toJson

public void toJson(DuDeJsonGenerator jsonGenerator)
            throws org.codehaus.jackson.JsonGenerationException,
                   IOException
Description copied from interface: Jsonable
Generates the Json code using the passed DuDeJsonGenerator.

Specified by:
toJson in interface Jsonable
Parameters:
jsonGenerator - The DuDeJsonGenerator that is used internally.
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while writing to the output.

fromJson

public void fromJson(DuDeJsonParser<?> jsonParser)
              throws org.codehaus.jackson.JsonParseException,
                     IOException
Description copied from interface: Jsonable
Initializes the current instance using the passed DuDeJsonParser.

Specified by:
fromJson in interface Jsonable
Parameters:
jsonParser - The parser that is used for extracting the data out of the Json.
Throws:
org.codehaus.jackson.JsonParseException - If an error occurs while parsing the Json.
IOException - If an error occurs while reading from the stream.


Copyright © 2011 Hasso Plattner Institute - Chair of Information Systems. All Rights Reserved.