gistoolkit.datasources
Class SimpleDataSource

java.lang.Object
  extended bygistoolkit.datasources.SimpleDataSource
All Implemented Interfaces:
DataSource
Direct Known Subclasses:
ArcIMSDataSource, ERMapperDatasource, ImageDirectoryDataSource, ImageFileDataSource, MemoryDataSource, OGCWebServiceDataSource, RasterCatalogDataSource, ReadOnlyShapeFileDataSource, SeamlessDataSource, ShapeFileDataSource, SimpleDBDataSource, SimpleJoinDataSource

public abstract class SimpleDataSource
extends java.lang.Object
implements DataSource

The SimpleDataSource implements the DataSource, and implements some of the more tedious methods of it.

It handles Projections (Using the ToolkitProjection Engine), and handles the getting and setting of the name, the projection, the insert and update methods, and the filters.

To create an ReadOnly data source, subclassing the SimpleDataSource is the easiest way to go. The only methods that must be overridden are the methods: readEnvelope(), readShapes(), and getValidShapeTypes(). The rest of the plumming should be taken care of.

To create an Updateable data source, additional methods must be overridden, they include the doInsert, doUpdate, doDelete, doRollback, and doCommit methods. Do not forget to overide the isUpdateable method to return true as the default is to return false.

Additional methods may be overridden to provide speed if the underlying data souce provides similar capabilities.

Author:
bitterstorm

Field Summary
(package private)  java.lang.String[] myTypes
          Return the array of shape types that are valid for this data source
 
Constructor Summary
SimpleDataSource()
          Creates new SimpleDataSource
 
Method Summary
 void addDataSourceListener(DataSourceListener inDataSourceListener)
          Adds a datasource listener to this datasource.
protected  void clearCache()
          Clear the cache.
 void commit()
          Commit all changes since the last commit.
 void delete(Record inRecord)
          Delete the given record from the data source.
 void doCommit()
          Commit all changes since the last commit.
 void doDelete(Record inRecord)
          Delete this record from the database.
 void doInsert(Record inRecord)
          Insert the record into the data source.
 void doRollback()
          Rollback any changes to this datasource since the last commit.
 void doUpdate(Record inRecord)
          Update the data source with the changed record.
protected  GISDataset filterDataset(GISDataset inDataset)
           
protected  void fireCommit()
          Called to notify the listeners that a commit has occured
protected  void fireDelete(Record inRecord)
          Called to notify the listeners that the record has been deleted
protected  void fireInsert(Record inRecord)
          Called to notify the listeners that the record has been inserted
protected  void fireRead(Record inRecord)
          Called to notify the listeners that the record has been read
protected  void fireRollBack()
          Called to notify the listeners that a rollback has occured
protected  void fireUpdate(Record inRecord)
          Called to notify the listeners that the record has been updated
 boolean getCached()
          Returns true if this datasource is caching it's shapes.
protected  GISDataset getCacheDataset()
          Return the cached data set.
protected  Envelope getCacheEnvelope()
          Return the envelope of the cached dataset
 Envelope getEnvelope()
          Returns the projected envelope.
 Filter getFilter()
          Get the filter used with this data source.
 Projection getFromProjection()
          Returns the projection to use to convert from the datasource native projection to the display projection, or a basis projection for the display projection.
 java.lang.String getName()
          Gets the identifier string for the datasource.
 Node getNode()
          Get the configuration information for this data source
 Style getStyle()
          Get the default style to use with this datasource.
 Projection getToProjection()
          Returns the ToProjection.
 java.lang.String[] getValidShapeTypes()
           
 void insert(Record inRecord)
          Inserts the given record into the datasource.
protected  boolean isCachedProjected()
          Returs true if the dataset is supposed to cache the data projected.
 boolean isUpdateable()
          Determines if this datasource is updateable.
 void projectBackward(Projection inProjection, GISDataset inDataset)
          Project the dataset backward
 void projectForward(Projection inProjection, GISDataset inDataset)
          Project the dataset forward
protected  GISDataset queryFromCache(Envelope inEnvelope)
          Retrieve the data from the cache that intersect these envelope.
 GISDataset readDataset()
          Reads all the objects from the data source.
 GISDataset readDataset(Envelope inEnvelope)
          Reads only the objects from the data source that intersect these envelopes.
abstract  Envelope readEnvelope()
          Returns the bounding rectangle of all the shapes in the Data Source.
protected abstract  GISDataset readShapes(Envelope inEnvelope)
          This method should return the shapes from the data source
 void removeDataSourceListener(DataSourceListener inDataSourceListener)
          Removes the datasource lisener from this datasource.
 void rollback()
          Rollback any changes to this datasource since the last commit.
protected  void setCache(GISDataset inDataset, Envelope inEnvelope)
          Set the cached data set and envelope.
 void setCached(boolean inCached)
          Set to true if this datasource should cache it's shapes.
 void setFilter(Filter inFilter)
          Set the filter to use when querying data from this data source.
 void setFromProjection(Projection inProjection)
          Sets the projection to use to convert from the storage media, source projection.
 void setName(java.lang.String inName)
          Sets an identifier string for the datasource.
 void setNode(Node inNode)
          Set the configuration information for this data source
 void setProjection(Projection inProjection)
           
 void setToProjection(Projection inProjection, boolean inCacheProjected)
          Allows another projection to be used to convert to the screen projection.
 void update(Record inRecord)
          Update the given record in the data source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myTypes

java.lang.String[] myTypes
Return the array of shape types that are valid for this data source

Constructor Detail

SimpleDataSource

public SimpleDataSource()
Creates new SimpleDataSource

Method Detail

getName

public java.lang.String getName()
Gets the identifier string for the datasource.

Specified by:
getName in interface DataSource

setName

public void setName(java.lang.String inName)
Sets an identifier string for the datasource.

Specified by:
setName in interface DataSource

setFromProjection

public void setFromProjection(Projection inProjection)
                       throws java.lang.Exception
Sets the projection to use to convert from the storage media, source projection. It is expected that this projection will be run in reverse, to reverse project already projected data, and that it will not change often so it is OK for this to be done just once.

Specified by:
setFromProjection in interface DataSource
Throws:
java.lang.Exception

getFromProjection

public Projection getFromProjection()
Returns the projection to use to convert from the datasource native projection to the display projection, or a basis projection for the display projection.

Specified by:
getFromProjection in interface DataSource

setCached

public void setCached(boolean inCached)
Set to true if this datasource should cache it's shapes.


getCached

public boolean getCached()
Returns true if this datasource is caching it's shapes.


isCachedProjected

protected boolean isCachedProjected()
Returs true if the dataset is supposed to cache the data projected.


setToProjection

public void setToProjection(Projection inProjection,
                            boolean inCacheProjected)
                     throws java.lang.Exception
Allows another projection to be used to convert to the screen projection. The CacheProjected flag indicates to the Data source that the to projection will not be changing often, and it is OK to project once and cache it. Setting this flag to false indicates to the DataSource that the toProjection will be changing often.

Specified by:
setToProjection in interface DataSource
Throws:
java.lang.Exception

setProjection

public void setProjection(Projection inProjection)
                   throws java.lang.Exception
Throws:
java.lang.Exception

getToProjection

public Projection getToProjection()
Returns the ToProjection.

Specified by:
getToProjection in interface DataSource

projectForward

public void projectForward(Projection inProjection,
                           GISDataset inDataset)
                    throws java.lang.Exception
Project the dataset forward

Throws:
java.lang.Exception

projectBackward

public void projectBackward(Projection inProjection,
                            GISDataset inDataset)
                     throws java.lang.Exception
Project the dataset backward

Throws:
java.lang.Exception

getFilter

public Filter getFilter()
Get the filter used with this data source.

Specified by:
getFilter in interface DataSource

setFilter

public void setFilter(Filter inFilter)
Set the filter to use when querying data from this data source.

Specified by:
setFilter in interface DataSource

filterDataset

protected GISDataset filterDataset(GISDataset inDataset)

getCacheDataset

protected GISDataset getCacheDataset()
Return the cached data set.


getCacheEnvelope

protected Envelope getCacheEnvelope()
Return the envelope of the cached dataset


setCache

protected void setCache(GISDataset inDataset,
                        Envelope inEnvelope)
Set the cached data set and envelope. This should be set after each new query.


clearCache

protected void clearCache()
Clear the cache.


queryFromCache

protected GISDataset queryFromCache(Envelope inEnvelope)
Retrieve the data from the cache that intersect these envelope.


readDataset

public GISDataset readDataset(Envelope inEnvelope)
                       throws java.lang.Exception
Reads only the objects from the data source that intersect these envelopes.

Specified by:
readDataset in interface DataSource
Throws:
java.lang.Exception

readDataset

public GISDataset readDataset()
                       throws java.lang.Exception
Reads all the objects from the data source.

Specified by:
readDataset in interface DataSource
Throws:
java.lang.Exception

readShapes

protected abstract GISDataset readShapes(Envelope inEnvelope)
                                  throws java.lang.Exception
This method should return the shapes from the data source

Throws:
java.lang.Exception

readEnvelope

public abstract Envelope readEnvelope()
                               throws java.lang.Exception
Returns the bounding rectangle of all the shapes in the Data Source.

Throws:
java.lang.Exception

getEnvelope

public Envelope getEnvelope()
                     throws java.lang.Exception
Returns the projected envelope.

Specified by:
getEnvelope in interface DataSource
Throws:
java.lang.Exception

getNode

public Node getNode()
Get the configuration information for this data source

Specified by:
getNode in interface DataSource

setNode

public void setNode(Node inNode)
             throws java.lang.Exception
Set the configuration information for this data source

Specified by:
setNode in interface DataSource
Throws:
java.lang.Exception

addDataSourceListener

public void addDataSourceListener(DataSourceListener inDataSourceListener)
Adds a datasource listener to this datasource.

Specified by:
addDataSourceListener in interface DataSource

removeDataSourceListener

public void removeDataSourceListener(DataSourceListener inDataSourceListener)
Removes the datasource lisener from this datasource.

Specified by:
removeDataSourceListener in interface DataSource

fireRead

protected void fireRead(Record inRecord)
Called to notify the listeners that the record has been read


fireInsert

protected void fireInsert(Record inRecord)
Called to notify the listeners that the record has been inserted


fireUpdate

protected void fireUpdate(Record inRecord)
Called to notify the listeners that the record has been updated


fireDelete

protected void fireDelete(Record inRecord)
Called to notify the listeners that the record has been deleted


fireCommit

protected void fireCommit()
Called to notify the listeners that a commit has occured


fireRollBack

protected void fireRollBack()
Called to notify the listeners that a rollback has occured


isUpdateable

public boolean isUpdateable()
Determines if this datasource is updateable. By default it is not, so this method always returns false.

Specified by:
isUpdateable in interface DataSource

doInsert

public void doInsert(Record inRecord)
              throws java.lang.Exception
Insert the record into the data source. By default this is a read only data source, so this method does nothing.

Throws:
java.lang.Exception

doUpdate

public void doUpdate(Record inRecord)
              throws java.lang.Exception
Update the data source with the changed record. By default this is a read only data source, so this method does nothing.

Throws:
java.lang.Exception

doDelete

public void doDelete(Record inRecord)
              throws java.lang.Exception
Delete this record from the database. By default this is a read only data source, so this method does nothing.

Throws:
java.lang.Exception

doCommit

public void doCommit()
              throws java.lang.Exception
Commit all changes since the last commit. This is a read only data source by default, so this method does nothing.

Throws:
java.lang.Exception

doRollback

public void doRollback()
                throws java.lang.Exception
Rollback any changes to this datasource since the last commit.

Throws:
java.lang.Exception

commit

public void commit()
            throws java.lang.Exception
Commit all changes since the last commit. This is a read only data source by default, so this method does nothing.

Specified by:
commit in interface DataSource
Throws:
java.lang.Exception

rollback

public void rollback()
              throws java.lang.Exception
Rollback any changes to this datasource since the last commit.

Specified by:
rollback in interface DataSource
Throws:
java.lang.Exception

getValidShapeTypes

public java.lang.String[] getValidShapeTypes()

insert

public void insert(Record inRecord)
            throws java.lang.Exception
Inserts the given record into the datasource.

Specified by:
insert in interface DataSource
Throws:
java.lang.Exception

update

public void update(Record inRecord)
            throws java.lang.Exception
Update the given record in the data source.

Specified by:
update in interface DataSource
Throws:
java.lang.Exception

delete

public void delete(Record inRecord)
            throws java.lang.Exception
Delete the given record from the data source.

Specified by:
delete in interface DataSource
Throws:
java.lang.Exception

getStyle

public Style getStyle()
Get the default style to use with this datasource. The default style for the layer is a black line whith a white fill. This is usually a less than optimal style to use for a particular layer. Further, there are some layers that are displayed in such a manner as to appear non functional using this style. If this data source knows about a better default than the one provided by the layer, then it can create and return that style here and the layer will use it instead of the black lines/white fill it would normally use. If the black lines/white fill style is fine then just return null and the layer will return the correct style.

Specified by:
getStyle in interface DataSource