simtools.data
Class FileDataSourceProvider

java.lang.Object
  extended by simtools.data.FileDataSourceProvider
All Implemented Interfaces:
DataSourceProvider
Direct Known Subclasses:
AsciiFileDataSourceProvider, DataSourceCollectionAnimatorProvider, DataSourceProvider

public abstract class FileDataSourceProvider
extends java.lang.Object
implements DataSourceProvider

Author:
zxpletran007 A data source provider that restores a collection from a file

Field Summary
protected static int CANCEL_OPTION
           
protected  boolean chooseAgain
           
protected  javax.swing.filechooser.FileFilter filter
           
protected  java.lang.String marker
           
protected static int NO_OPTION
           
protected static int YES_OPTION
           
 
Constructor Summary
FileDataSourceProvider(javax.swing.filechooser.FileFilter filter, java.lang.String marker)
           
 
Method Summary
 java.io.File chooseFile(java.lang.String fileName, java.lang.String reason)
          Provides a file, using the given fileName or not.
 int chooseUseCollection(DataSourceCollection existingDsc, java.lang.String dscId, java.lang.String Id)
          Chooses whether to use an already existing collection if it contains the datasource to provide, instead of the collection with the given id.
protected  int chooseUseCollectionIfMissingDs(java.lang.String dscId, java.lang.String dsMissingId)
          Chooses whether to use created collection even if required data source is missing Default implementation says YES_OPTION.
protected  DataSourceCollection createCollection(java.io.File f, java.lang.Object optionalInformation)
           
protected abstract  DataSource createEmptyDatasource(java.lang.String dsId, java.lang.String dscId, java.lang.Object optionalInformation)
           
protected  boolean getChooseFileAgain()
           
 java.lang.Object getOptionalInformation(DataSource ds, DataSourceCollection dsc)
          Asks this provider some optional information about a datasource and possibly its collection.
 DataSource provide(java.lang.String id, java.lang.String dscId, java.lang.Object optionalInformation, DataSourcePool pool)
          Asks this provider to resolve a symbolic datasource reference.
protected  void setChooseFileAgain(boolean chooseAgain)
          Subclasses can set this flag to call chooseFile again if the file isn't valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

chooseAgain

protected boolean chooseAgain

marker

protected java.lang.String marker

filter

protected javax.swing.filechooser.FileFilter filter

YES_OPTION

protected static final int YES_OPTION
See Also:
Constant Field Values

NO_OPTION

protected static final int NO_OPTION
See Also:
Constant Field Values

CANCEL_OPTION

protected static final int CANCEL_OPTION
See Also:
Constant Field Values
Constructor Detail

FileDataSourceProvider

public FileDataSourceProvider(javax.swing.filechooser.FileFilter filter,
                              java.lang.String marker)
Method Detail

setChooseFileAgain

protected void setChooseFileAgain(boolean chooseAgain)
Subclasses can set this flag to call chooseFile again if the file isn't valid. By default, the file is ignored and nothing happens. The file is considered valid if it can provide the desired datasource for the id in the 'provide' function. In case the file isn't valid, chooseFile is called again. Warning: subclasses setting this flag to true should also modify chooseFile. The default implementation always return the same file from the fileName and never returns null, so this could cause an infinite loop. It is the subclass responsability to provide a chooseFile function that can be called again.


getChooseFileAgain

protected boolean getChooseFileAgain()

chooseFile

public java.io.File chooseFile(java.lang.String fileName,
                               java.lang.String reason)
Provides a file, using the given fileName or not. Default implementation just checks if the fileName exists in the current directory and returns it. Subclasses should overload this function and ask the user for a file.

Parameters:
fileName - The default fileName.
reason - What to look for.
Returns:
A candidate File, or null if no File can be provided.

chooseUseCollection

public int chooseUseCollection(DataSourceCollection existingDsc,
                               java.lang.String dscId,
                               java.lang.String Id)
Chooses whether to use an already existing collection if it contains the datasource to provide, instead of the collection with the given id. Default implementation says no.

Parameters:
existingDsc - The existing collection
dscId - The collection id to replace
id - The source id present in both collections
Returns:
YES_OPTION to use the collection present in the pool, NO_OPTION to choose collection with given id,

chooseUseCollectionIfMissingDs

protected int chooseUseCollectionIfMissingDs(java.lang.String dscId,
                                             java.lang.String dsMissingId)
Chooses whether to use created collection even if required data source is missing Default implementation says YES_OPTION.

Parameters:
dscId - The created collection id
dsMissingId - The required data source id
Returns:
YES_OPTION to use the collection, NO_OPTION to choose another collection, CANCEL_OPTION to cancel opening process

createEmptyDatasource

protected abstract DataSource createEmptyDatasource(java.lang.String dsId,
                                                    java.lang.String dscId,
                                                    java.lang.Object optionalInformation)

createCollection

protected DataSourceCollection createCollection(java.io.File f,
                                                java.lang.Object optionalInformation)
                                         throws java.io.IOException,
                                                TimeStampedDataSourceCollection.InvalidFormatException
Throws:
java.io.IOException
TimeStampedDataSourceCollection.InvalidFormatException

getOptionalInformation

public java.lang.Object getOptionalInformation(DataSource ds,
                                               DataSourceCollection dsc)
Description copied from interface: DataSourceProvider
Asks this provider some optional information about a datasource and possibly its collection.

Specified by:
getOptionalInformation in interface DataSourceProvider
Parameters:
ds - The datasource
dsc - The datasource collection, or null.
Returns:
null if this provider cannot provide optional information, an arbitrary object otherwise.

provide

public DataSource provide(java.lang.String id,
                          java.lang.String dscId,
                          java.lang.Object optionalInformation,
                          DataSourcePool pool)
Description copied from interface: DataSourceProvider
Asks this provider to resolve a symbolic datasource reference.

Specified by:
provide in interface DataSourceProvider
Parameters:
id - The symbolic id of a datasource
dscId - The symbolic id of a datasourceCollection. May be null
optionalInformation - Can be set to help this provider. May be null
pool - DataSourcePool in which to add the source and collection if they can be provided. May be null.
Returns:
The desired datasource if it can be provided, or null.