simtools.data
Class DataSourcePool

java.lang.Object
  extended by simtools.data.DataSourcePool
All Implemented Interfaces:
DataSourceCollectionListener

public class DataSourcePool
extends java.lang.Object
implements DataSourceCollectionListener

Pool of data source: holds a certain number of data sources, and can send action events to listeners in case the pool is modified.

Version:
1.0 2001
Author:
Nicolas Brodu

Nested Class Summary
protected static class DataSourcePool.BufferMarker
          Those are markers we can recognize without any confusion possible for the serialized stream
protected static class DataSourcePool.DataSourceCollectionMarker
           
protected  class DataSourcePool.NotifySet
          A specific set that notifies the listeners when it changes See HashSet, this implementation is not synchronized.
protected static class DataSourcePool.SourceDependenciesMarker
           
 
Field Summary
protected  DataSourcePool.NotifySet collections
           
static DataSourcePool global
          A global pool for all to use
protected  ListenerManager listeners
           
protected  java.util.ArrayList localEmptySources
           
protected  boolean notification
           
protected  java.util.Vector providers
           
protected  DataSourcePool.NotifySet sources
           
protected  java.util.Hashtable translations
           
 
Constructor Summary
DataSourcePool()
           
 
Method Summary
 void addDataSource(DataSource ds)
           
 void addDataSourceCollection(DataSourceCollection dsc)
           
 void addListener(DataSourcePoolListener l)
           
protected  void addLocalEmptySource(java.lang.String source, java.lang.String reason)
           
 void addProvider(DataSourceProvider p)
          Adds a datasource provider.
 DataSource bufferize(DataSource ds, Buffer buffer)
          Apply a buffer to a datasource.
 DataSourceCollection bufferize(DataSourceCollection dsc, Buffer buffer)
          Apply a buffer to a datasource collection.
 void clearLocalEmptySources()
          Called before a synoptic loading.
 boolean contains(DataSource ds)
          Utility.
 boolean contains(DataSourceCollection dsc)
          Utility.
 void DataSourceCollectionDataSourceAdded(DataSourceCollection dsc, DataSource ds)
          Called when the information about the data source collection changed
 void DataSourceCollectionDataSourceRemoved(DataSourceCollection dsc, DataSource ds)
          Called when the information about the data source collection changed
 void DataSourceCollectionInfoChanged(DataSourceCollection dsc, DataInfo newInfo)
          Called when the information about the data source collection changed
 void DataSourceCollectionRemoved(DataSourceCollection dsc)
          Called when the data source collection has been removed
 java.util.Set dataSourceCollections()
          Data source collections
 java.util.Set dataSources()
          Data sources
 DataSourceCollection getCollectionForDataSourceId(java.lang.String id)
          Utility.
 DataSourceCollection getDataSourceCollectionWithId(java.lang.String id)
          Utility.
 DataSource getDataSourceWithAlias(java.lang.String name)
          Utility.
 DataSource getDataSourceWithId(java.lang.String id)
          Utility.
 DataSource getDataSourceWithIDOrLabelOrAlias(java.lang.String name)
          Utility.
 DataSource getDataSourceWithLabel(java.lang.String name)
          Utility.
 java.lang.String[][] getEmptySourcesDump()
          Called after a synoptic loading
 java.lang.String[] getEmptySourcesDumpColumnNames()
          Called after a synoptic loading.
 DataSourceProvider getProviderFor(DataSource ds, DataSourceCollection dsc)
           
protected  DataSourceCollection getTranslateCollection(java.lang.String dscId)
           
 boolean isEmpty()
           
 boolean localEmptySourcesIsEmpty()
           
protected  void notifyListeners(int action, java.lang.Object o, java.lang.Object old)
          Notify the listeners a change occured
 DataSource provide(java.lang.String id, java.lang.String dscId, java.lang.Object optionalInformation, boolean add)
          Asks the providers to resolve a symbolic datasource reference.
 DataSource readDataSource(java.io.ObjectInputStream in)
           
 boolean removeDataSource(DataSource ds)
           
 boolean removeDataSourceCollection(DataSourceCollection dsc)
           
 void removeListener(DataSourcePoolListener l)
           
 boolean removeProvider(DataSourceProvider p)
          Removes a datasource provider
protected  void setNotify(boolean state)
          Sets the notification on or off
protected  void setTranslateCollection(java.lang.String dscId, DataSource ds)
           
 void writeDataSource(java.io.ObjectOutputStream out, DataSource ds)
          DataSource serialization helper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

global

public static final DataSourcePool global
A global pool for all to use


listeners

protected ListenerManager listeners

providers

protected java.util.Vector providers

sources

protected DataSourcePool.NotifySet sources

collections

protected DataSourcePool.NotifySet collections

translations

protected java.util.Hashtable translations

notification

protected boolean notification

localEmptySources

protected java.util.ArrayList localEmptySources
Constructor Detail

DataSourcePool

public DataSourcePool()
Method Detail

addListener

public void addListener(DataSourcePoolListener l)

removeListener

public void removeListener(DataSourcePoolListener l)

addProvider

public void addProvider(DataSourceProvider p)
Adds a datasource provider. Providers are especially used to get datasource references back from ids, during internalization, and to get optional information (if any) about the datasources, during serialization. The new provider takes precedence over the existing ones in case of conflict for an id


getProviderFor

public DataSourceProvider getProviderFor(DataSource ds,
                                         DataSourceCollection dsc)

removeProvider

public boolean removeProvider(DataSourceProvider p)
Removes a datasource provider

Returns:
true if the provider was registered.

addDataSource

public void addDataSource(DataSource ds)

addDataSourceCollection

public void addDataSourceCollection(DataSourceCollection dsc)

removeDataSource

public boolean removeDataSource(DataSource ds)

removeDataSourceCollection

public boolean removeDataSourceCollection(DataSourceCollection dsc)

dataSourceCollections

public java.util.Set dataSourceCollections()
Data source collections


dataSources

public java.util.Set dataSources()
Data sources


bufferize

public DataSource bufferize(DataSource ds,
                            Buffer buffer)
Apply a buffer to a datasource. Notify the listeners of the change.

Parameters:
ds - The datasource to act on
buffer - The buffer. Its data provider will be set to the datasource
Returns:
the bufferized data source if the operation succeded, or null

bufferize

public DataSourceCollection bufferize(DataSourceCollection dsc,
                                      Buffer buffer)
Apply a buffer to a datasource collection. Notify the listeners of the change.

Parameters:
ds - The datasource collection to act on
buffer - The buffer. See DataSourceCollection.bufferize().
Returns:
the bufferized data source collection if the operation succeded, or null

contains

public boolean contains(DataSource ds)
Utility. Look in the datasource and collection sets for the given datasource.


contains

public boolean contains(DataSourceCollection dsc)
Utility. Look in the datasource and collection sets for the given datasource.


getDataSourceWithId

public DataSource getDataSourceWithId(java.lang.String id)
                               throws DuplicateIdException
Utility. Look in the datasource and collection sets for the given datasource id.

Returns:
null if this pool doesn't contain a datasource with the given id, or if multiple source have the same id (for example, in different collections)
Throws:
DuplicateIdException - when two or more datasource have the given Id

getDataSourceWithLabel

public DataSource getDataSourceWithLabel(java.lang.String name)
                                  throws DuplicateIdException
Utility. Look in the datasource and collection sets for the given datasource label.

Returns:
null if this pool doesn't contain a datasource with the given label, or if multiple source have the same label, (for example, in different collections)
Throws:
DuplicateIdException - when two or more datasource have the given alias

getDataSourceWithAlias

public DataSource getDataSourceWithAlias(java.lang.String name)
                                  throws DuplicateIdException
Utility. Look in the datasource and collection sets for the given datasource alias.

Returns:
null if this pool doesn't contain a datasource with the given alias, or if multiple source have the same alias, (for example, in different collections)
Throws:
DuplicateIdException - when two or more datasource have the given alias

getDataSourceWithIDOrLabelOrAlias

public DataSource getDataSourceWithIDOrLabelOrAlias(java.lang.String name)
                                             throws DuplicateIdException
Utility. Look in the datasource and collection sets for the given datasource name.

Returns:
null if this pool doesn't contain a datasource with the given alias, or if multiple source have the same alias, (for example, in different collections)
Throws:
DuplicateIdException - when two or more datasource have the given alias

getDataSourceCollectionWithId

public DataSourceCollection getDataSourceCollectionWithId(java.lang.String id)
                                                   throws DuplicateIdException
Utility. Look in the datasource collection set for the given datasource collection id.

Returns:
null if this pool doesn't contain a datasource collection with the given id
Throws:
DuplicateIdException

getCollectionForDataSourceId

public DataSourceCollection getCollectionForDataSourceId(java.lang.String id)
                                                  throws DuplicateIdException
Utility. Look in the datasource collection set for a collection containing the given datasource id.

Returns:
null if this pool doesn't contain such a datasource collection
Throws:
DuplicateIdException - when two or more collections contain a datasource with the given Id

provide

public DataSource provide(java.lang.String id,
                          java.lang.String dscId,
                          java.lang.Object optionalInformation,
                          boolean add)
Asks the providers to resolve a symbolic datasource reference.

Parameters:
id - The symbolic id of a datasource
dscId - The symbolic id of a datasourceCollection. May be null
optionalInformation - Can be set to help the providers. May be null
add - If set to true, the datasource will be added to the pool if it could be found, together with its collection if it belongs to a collection. True by default.
Returns:
The desired datasource if it could be found, or null.

writeDataSource

public void writeDataSource(java.io.ObjectOutputStream out,
                            DataSource ds)
                     throws java.io.IOException
DataSource serialization helper

Throws:
java.io.IOException

getTranslateCollection

protected DataSourceCollection getTranslateCollection(java.lang.String dscId)

setTranslateCollection

protected void setTranslateCollection(java.lang.String dscId,
                                      DataSource ds)

readDataSource

public DataSource readDataSource(java.io.ObjectInputStream in)
                          throws java.io.IOException
Throws:
java.io.IOException

notifyListeners

protected void notifyListeners(int action,
                               java.lang.Object o,
                               java.lang.Object old)
Notify the listeners a change occured

Parameters:
action - as defined in DataSourcePoolEvent
o - the target object. Must be a DataSource or DataSourceCollection

setNotify

protected void setNotify(boolean state)
Sets the notification on or off

Parameters:
state - the new state

DataSourceCollectionInfoChanged

public void DataSourceCollectionInfoChanged(DataSourceCollection dsc,
                                            DataInfo newInfo)
Description copied from interface: DataSourceCollectionListener
Called when the information about the data source collection changed

Specified by:
DataSourceCollectionInfoChanged in interface DataSourceCollectionListener
Parameters:
dsc - The data source collection that changed
newInfo - The new information concerning this collection

DataSourceCollectionDataSourceAdded

public void DataSourceCollectionDataSourceAdded(DataSourceCollection dsc,
                                                DataSource ds)
Description copied from interface: DataSourceCollectionListener
Called when the information about the data source collection changed

Specified by:
DataSourceCollectionDataSourceAdded in interface DataSourceCollectionListener
Parameters:
dsc - The data source collection that changed
ds - The data source that was added

DataSourceCollectionDataSourceRemoved

public void DataSourceCollectionDataSourceRemoved(DataSourceCollection dsc,
                                                  DataSource ds)
Description copied from interface: DataSourceCollectionListener
Called when the information about the data source collection changed

Specified by:
DataSourceCollectionDataSourceRemoved in interface DataSourceCollectionListener
Parameters:
dsc - The data source collection that changed
ds - The data source that was removed

DataSourceCollectionRemoved

public void DataSourceCollectionRemoved(DataSourceCollection dsc)
Description copied from interface: DataSourceCollectionListener
Called when the data source collection has been removed

Specified by:
DataSourceCollectionRemoved in interface DataSourceCollectionListener
Parameters:
dsc - The data source collection that has been removed

isEmpty

public boolean isEmpty()
Returns:
true if this pool has no source and no collections in it

getEmptySourcesDump

public java.lang.String[][] getEmptySourcesDump()
Called after a synoptic loading

Returns:
a list of data sources that could'nt be restored during a synoptic loading.

getEmptySourcesDumpColumnNames

public java.lang.String[] getEmptySourcesDumpColumnNames()
Called after a synoptic loading.

Returns:
the column names of the table that dumps all data sources restoring problems

addLocalEmptySource

protected void addLocalEmptySource(java.lang.String source,
                                   java.lang.String reason)

clearLocalEmptySources

public void clearLocalEmptySources()
Called before a synoptic loading.


localEmptySourcesIsEmpty

public boolean localEmptySourcesIsEmpty()