de.hpi.fgis.dude.datasource
Class AbstractDataSource<S extends AbstractDataSource<S>>

java.lang.Object
  extended by de.hpi.fgis.dude.util.AbstractCleanable
      extended by de.hpi.fgis.dude.datasource.AbstractDataSource<S>
Type Parameters:
S - Type of subclass for fluent interface.
All Implemented Interfaces:
DataSource, Cleanable, AutoJsonable, JsonableReader<DuDeObject>, Closeable, Iterable<DuDeObject>
Direct Known Subclasses:
BibtexSource, CSVSource, DatabaseSource, DuDeObjectSource, JSONSource, XMLSource

public abstract class AbstractDataSource<S extends AbstractDataSource<S>>
extends AbstractCleanable
implements DataSource

AbstractDataSource provides the common functionality of all DataSource classes. The concrete DataSource implementations should extend this class in order to reduce the implementation effort.

Author:
Matthias Pohl, Arvid Heise
See Also:
DataSource, AbstractIterator

Nested Class Summary
protected  class AbstractDataSource.AbstractDataSourceIterator<T extends AbstractDataSource<?>>
          AbstractDataSourceIterator can be used to generate valid DuDeObjects.
 
Constructor Summary
protected AbstractDataSource()
          Internal constructor for Jsonable deserialization.
protected AbstractDataSource(String id)
          Initializes a AbstractDataExtractor with the passed identifier.
 
Method Summary
 void addIdAttributes(String... attributes)
          Sets the attributes that shall be used for id generation.
protected  boolean autoGeneratedIds()
          Checks whether the object id is generated automatically.
 void close()
           
 boolean equals(Object obj)
           
 int getExtractedRecordCount()
          Returns the number of already extracted records.
protected  Iterable<String> getIdAttributes()
          Returns the set id attributes.
 String getIdentifier()
          Returns the identifier of this DataSource.
 int hashCode()
           
abstract  Iterator<DuDeObject> iterator()
           
protected  void setExtractedRecordCount(int extractedRecordCnt)
          Resets the extracted-record count, if the passed count is larger than the current one.
 String toString()
           
 S withIdAttributes(String... attributes)
          Sets the id attributes.
 
Methods inherited from class de.hpi.fgis.dude.util.AbstractCleanable
cleanUp, 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
cleanUp, registerCleanable, registerCloseable
 

Constructor Detail

AbstractDataSource

protected AbstractDataSource()
Internal constructor for Jsonable deserialization.


AbstractDataSource

protected AbstractDataSource(String id)
Initializes a AbstractDataExtractor with the passed identifier.

Parameters:
id - The identifier that is used within each generated DuDeObject as its source identifier.
Method Detail

getIdentifier

public String getIdentifier()
Description copied from interface: DataSource
Returns the identifier of this DataSource. This identifier is used as a source id for each DuDeObject that is extracted out of the current DataSource instance.

Specified by:
getIdentifier in interface DataSource
Returns:
The DataSource's identifier.

addIdAttributes

public void addIdAttributes(String... attributes)
Description copied from interface: DataSource
Sets the attributes that shall be used for id generation. If no id attributes are set, the object ids are generated automatically.

Specified by:
addIdAttributes in interface DataSource
Parameters:
attributes - The attributes that shall be used for id generation.

withIdAttributes

public S withIdAttributes(String... attributes)
Sets the id attributes.

Parameters:
attributes - The id attributes which shall be used.
Returns:
The current instance.
See Also:
addIdAttributes(String...)

autoGeneratedIds

protected boolean autoGeneratedIds()
Checks whether the object id is generated automatically. This method indicates whether id attributes are set or not. If no id attributes are set, the id have to be generated automatically by incrementing an Integer value. Otherwise the values of the id attributes are used to generate the object id of each extracted record.

Returns:
true, if no id attributes are set; otherwise false.

getIdAttributes

protected Iterable<String> getIdAttributes()
Returns the set id attributes.

Returns:
The set id attributes.

iterator

public abstract Iterator<DuDeObject> iterator()
Specified by:
iterator in interface Iterable<DuDeObject>

setExtractedRecordCount

protected void setExtractedRecordCount(int extractedRecordCnt)
Resets the extracted-record count, if the passed count is larger than the current one.

Parameters:
extractedRecordCnt - The new record count. If this value is not larger than the current one, no reset is performed.

getExtractedRecordCount

public int getExtractedRecordCount()
Description copied from interface: DataSource
Returns the number of already extracted records.

Specified by:
getExtractedRecordCount in interface DataSource
Returns:
The number of already extracted records.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object


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