ucar.unidata.data
Class DataManager

java.lang.Object
  extended by ucar.unidata.data.DataManager

public class DataManager
extends Object

A class for managing DataSources

Version:
$Revision: 1.122 $Date: 2007/08/08 16:24:11 $
Author:
Metapps development team

Field Summary
protected  ArrayList allDataSourceIds
          A list of TwoFacedObjects (label, datasource_id) for all datasource descriptors
protected  ArrayList allFilters
          The list of PatternFileFilters that we create from the datasources.xml.
static String ATTR_DOESMULTIPLES
          The XML attribute for allowing multiple data choices
static String ATTR_FACTORY
          The XML factory attribute
static String ATTR_FILESELECTION
          The XML file selection attribute
static String ATTR_ID
          The XML "id" attribute
static String ATTR_LABEL
          The XML label attribute
static String ATTR_NAME
          The XML name attribute
static String ATTR_NCMLTEMPLATE
          xml attribute identifier for the datasource.xml file
static String ATTR_PATTERNS
          The XML patterns attribute
static String ATTR_STANDALONE
          xml attribute identifier for the datasource.xml file
static String ATTR_VALUE
          The XML value attribute
protected  Hashtable dataSourceNameMap
          Maps data source names
static String DATATYPE_ID
          The known data type id
static String DATATYPE_UNKNOWN
          The "unknown" data type
protected  ArrayList descriptors
          The list of DataSourceDescriptors defined by the datasource.xml resource files.
protected  ArrayList fileDataSourceIds
          A list of TwoFacedObjects (label, datasource_id) for those datasource descriptors that are for file selection.
protected  ArrayList fileFilters
          The list of PatternFileFilters that we create from the datasources.xml for those that are specified to be for file selection (i.e., the xml tag has fileselection="true").
protected  Hashtable idToDescriptor
          A mapping from datasource_id (String) to DataSourceDescriptor object.
static String PREF_GRIBINDEXINCACHE
          Preference for where to save the grib index
static String PROP_CACHE_PERCENT
          The cache percent property
static String PROP_DEFAULT_DISPLAY
          The default display property
static String PROP_GEOSUBSET_BBOX
          bbox property
static String PROP_NETCDF_CONVENTIONHANDLERS
          preference id
static String PROP_SHOW_IN_TREE
          The show in tree property
protected  Hashtable seenFilters
          This hashtable allows us to keep track of the filter strings that we have already seen so we don't create duplicates.
static String TAG_DATASOURCE
          The XML tag for a datasource
static String TAG_DATASOURCES
          The XML tag for datasources
static String TAG_PROPERTY
          The XML tag for a property
 
Constructor Summary
DataManager(DataContext dataContext)
          Create a new DataManager with the given DataContext.
 
Method Summary
 boolean addDataSource(DataSource dataSource)
          Add the given DataSource into the list of datasources if it is not in the list and if it is not in error.
 DataSourceResults createDataSource(Object definingObject)
          Create a DataSource (if we know how) defined with the given definingObject.
 DataSourceResults createDataSource(Object definingObject, Hashtable properties)
          Create a DataSource (if we know how) defined with the given definingObject and set of properties (which may be null).
 DataSourceResults createDataSource(Object definingObject, String dataType, Hashtable properties)
          Create a DataSource (if we know how) defined with the given dataType (if non-null) or by the given definingObject and set of properties (which may be null).
 void createDataSourceAndAskForType(Object definingObject, Hashtable properties)
          Ask the user for the data soruce type and create the given data source
 DataSource findDataSource(String name)
          Find the data source with the given name
 List getAllDataSourceIds()
          This is used by the IdvChooserManager
 DataSourceDescriptor getCurrent(DataSourceDescriptor dds)
          Get the actual current descriptor with the id of the given or return the given one if one is not found.
 String getDataCacheDirectory()
          Get the data cache dir
 DataContext getDataContext()
          Get this DataManager's DataContext.
 StringBuffer getDataSourceHtml()
          get an html listing of all of the data source descriptions
 ArrayList getDataSources()
          The DataManager holds a set of active DataSource objects.
static String getDatasourceXml(String type, String label, Class datasourceClass, Hashtable properties)
          Create a snippet of the datasource xml for the given data source
static String getDatasourceXml(String type, String label, Class datasourceClass, Hashtable properties, String[] attributes)
          Create a snippet of the datasource xml for the given data source
 DataSourceDescriptor getDescriptor(String dataType)
          Find the DataSourceDescriptor with the given dataType id.
 List<DataSourceDescriptor> getDescriptors()
          get the data source descriptors
 List getFileDataSourceList()
          This is used by the IdvChooserManager to allow the user to create new file data chooser items.
 ArrayList getFileFilters()
          The DataManager creates a list of PatternFileFilters from the datasource xml.
static List<String> getNewVariableName(String varName)
          Get the new name for a variable name
 String getProperty(String dataType, String property)
          Find the given property on the DataSourceDescriptor defined by the given dataType.
 boolean getProperty(String dataType, String property, boolean dflt)
          Find the given property on the DataSourceDescriptor defined by the given dataType.
 List<DataSourceDescriptor> getStandaloneDescriptors()
          get the data source descriptors for those data sources that can be stand-alone
 boolean haveDataSource(DataSource dataSource)
          Is the given DataSource currently in the list of active datasources.
 void initEncoder(XmlEncoder encoder, boolean forRead)
          Seed the given encoder with the DataSourceDescriptors and the DataManager object.
 void initResources(IdvResourceManager resourceManager)
          Initialize the resources
 void initURLStreamHandlers()
          Add in the AddeURLStreamHandler
static boolean isFormulaDataSource(Object s)
          Check if an object is a data source that holds formulas.
 void loadDataSourceXml(XmlResourceCollection resources)
          Process the list of xml documents that define the different DataSources used within the idv.
protected  void loadGribResources(IdvResourceManager resourceManager)
          Deprecated. use loadIOSPResources(IdvResourceManager) instead
protected  void loadIospResources(IdvResourceManager resourceManager)
          Load the grib lookup tables
static void main(String[] args)
          test main
 void reloadAllDataSources()
          Reload all the data sources
 void removeAllDataSources()
          As the method name implies, remove all datasources managed by this DataManager.
 void removeDataSource(DataSource dataSource)
          Remove the given DataSource from the list of datasources.
static void setDODSCompression(boolean compress)
          Set whether compression is used on DODS file transfers
 boolean validDatasourceId(Object definingObject)
          Is there a mapping defined from the given definingObject (which should be a String) to a DataSourceDescriptor.
 boolean validDatasourceId(Object definingObject, Hashtable properties)
          Is there a mapping defined from the given definingObject (which should be a String) to a DataSourceDescriptor or is there a DATATYPE_ID entry in the given properties Hashtable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATATYPE_UNKNOWN

public static final String DATATYPE_UNKNOWN
The "unknown" data type

See Also:
Constant Field Values

DATATYPE_ID

public static final String DATATYPE_ID
The known data type id

See Also:
Constant Field Values

PROP_SHOW_IN_TREE

public static final String PROP_SHOW_IN_TREE
The show in tree property

See Also:
Constant Field Values

PROP_CACHE_PERCENT

public static final String PROP_CACHE_PERCENT
The cache percent property

See Also:
Constant Field Values

PROP_GEOSUBSET_BBOX

public static final String PROP_GEOSUBSET_BBOX
bbox property

See Also:
Constant Field Values

PROP_NETCDF_CONVENTIONHANDLERS

public static final String PROP_NETCDF_CONVENTIONHANDLERS
preference id

See Also:
Constant Field Values

PROP_DEFAULT_DISPLAY

public static final String PROP_DEFAULT_DISPLAY
The default display property

See Also:
Constant Field Values

TAG_DATASOURCES

public static final String TAG_DATASOURCES
The XML tag for datasources

See Also:
Constant Field Values

TAG_DATASOURCE

public static final String TAG_DATASOURCE
The XML tag for a datasource

See Also:
Constant Field Values

TAG_PROPERTY

public static final String TAG_PROPERTY
The XML tag for a property

See Also:
Constant Field Values

ATTR_DOESMULTIPLES

public static final String ATTR_DOESMULTIPLES
The XML attribute for allowing multiple data choices

See Also:
Constant Field Values

ATTR_STANDALONE

public static final String ATTR_STANDALONE
xml attribute identifier for the datasource.xml file

See Also:
Constant Field Values

ATTR_NCMLTEMPLATE

public static final String ATTR_NCMLTEMPLATE
xml attribute identifier for the datasource.xml file

See Also:
Constant Field Values

ATTR_ID

public static final String ATTR_ID
The XML "id" attribute

See Also:
Constant Field Values

ATTR_FACTORY

public static final String ATTR_FACTORY
The XML factory attribute

See Also:
Constant Field Values

ATTR_LABEL

public static final String ATTR_LABEL
The XML label attribute

See Also:
Constant Field Values

ATTR_NAME

public static final String ATTR_NAME
The XML name attribute

See Also:
Constant Field Values

ATTR_PATTERNS

public static final String ATTR_PATTERNS
The XML patterns attribute

See Also:
Constant Field Values

ATTR_FILESELECTION

public static final String ATTR_FILESELECTION
The XML file selection attribute

See Also:
Constant Field Values

ATTR_VALUE

public static final String ATTR_VALUE
The XML value attribute

See Also:
Constant Field Values

PREF_GRIBINDEXINCACHE

public static final String PREF_GRIBINDEXINCACHE
Preference for where to save the grib index

See Also:
Constant Field Values

descriptors

protected ArrayList descriptors
The list of DataSourceDescriptors defined by the datasource.xml resource files.


idToDescriptor

protected Hashtable idToDescriptor
A mapping from datasource_id (String) to DataSourceDescriptor object. This is used when we load multiple datasource descriptor files so we can know whether we have already loaded a descriptor and to do a lookup of a descriptor based on its id.


allFilters

protected ArrayList allFilters
The list of PatternFileFilters that we create from the datasources.xml. We use this list when we are given a file name or a URL and are looking for the DataSourceDescriptor that handles that type of file.


fileFilters

protected ArrayList fileFilters
The list of PatternFileFilters that we create from the datasources.xml for those that are specified to be for file selection (i.e., the xml tag has fileselection="true").


seenFilters

protected Hashtable seenFilters
This hashtable allows us to keep track of the filter strings that we have already seen so we don't create duplicates.


fileDataSourceIds

protected ArrayList fileDataSourceIds
A list of TwoFacedObjects (label, datasource_id) for those datasource descriptors that are for file selection.


allDataSourceIds

protected ArrayList allDataSourceIds
A list of TwoFacedObjects (label, datasource_id) for all datasource descriptors


dataSourceNameMap

protected Hashtable dataSourceNameMap
Maps data source names

Constructor Detail

DataManager

public DataManager(DataContext dataContext)
Create a new DataManager with the given DataContext.

Parameters:
dataContext - The DataContext that this DataManager exists within (this is usually an instance of IntegratedDataViewer).
Method Detail

getDataCacheDirectory

public String getDataCacheDirectory()
Get the data cache dir

Returns:
data cache dir

initResources

public void initResources(IdvResourceManager resourceManager)
Initialize the resources

Parameters:
resourceManager - resource manager

setDODSCompression

public static void setDODSCompression(boolean compress)
Set whether compression is used on DODS file transfers

Parameters:
compress - true to compress

loadGribResources

protected void loadGribResources(IdvResourceManager resourceManager)
Deprecated. use loadIOSPResources(IdvResourceManager) instead

Load the grib lookup tables

Parameters:
resourceManager - The resource manager

loadIospResources

protected void loadIospResources(IdvResourceManager resourceManager)
Load the grib lookup tables

Parameters:
resourceManager - The resource manager

getDataContext

public DataContext getDataContext()
Get this DataManager's DataContext.

Returns:
The DataContext of this DataManager.

loadDataSourceXml

public void loadDataSourceXml(XmlResourceCollection resources)
Process the list of xml documents that define the different DataSources used within the idv.

Parameters:
resources - The XmlResourceCollection that holds the set of datasource xml documents. This may be null.

getDataSourceHtml

public StringBuffer getDataSourceHtml()
get an html listing of all of the data source descriptions

Returns:
html listing of data sources

getDatasourceXml

public static String getDatasourceXml(String type,
                                      String label,
                                      Class datasourceClass,
                                      Hashtable properties)
                               throws Exception
Create a snippet of the datasource xml for the given data source

Parameters:
type - The data source type
label - the label
datasourceClass - the class
properties - properties
Returns:
The xml
Throws:
Exception - On badness

getDatasourceXml

public static String getDatasourceXml(String type,
                                      String label,
                                      Class datasourceClass,
                                      Hashtable properties,
                                      String[] attributes)
                               throws Exception
Create a snippet of the datasource xml for the given data source

Parameters:
type - The data source type
label - the label
datasourceClass - the class
properties - properties
attributes - If non-null then add these are xml attributes
Returns:
The xml
Throws:
Exception - On badness

getDescriptors

public List<DataSourceDescriptor> getDescriptors()
get the data source descriptors

Returns:
the descriptors

getStandaloneDescriptors

public List<DataSourceDescriptor> getStandaloneDescriptors()
get the data source descriptors for those data sources that can be stand-alone

Returns:
stand alone descriptors

getFileDataSourceList

public List getFileDataSourceList()
This is used by the IdvChooserManager to allow the user to create new file data chooser items.

Returns:
The list of DataSourceDescriptors that are meant to be used for files.

getAllDataSourceIds

public List getAllDataSourceIds()
This is used by the IdvChooserManager

Returns:
The list of DataSourceDescriptors

getDataSources

public ArrayList getDataSources()
The DataManager holds a set of active DataSource objects.

Returns:
The list of active DataSources.

haveDataSource

public boolean haveDataSource(DataSource dataSource)
Is the given DataSource currently in the list of active datasources.

Parameters:
dataSource - The DataSource to check.
Returns:
Is dataSource in the datasources list.

addDataSource

public boolean addDataSource(DataSource dataSource)
Add the given DataSource into the list of datasources if it is not in the list and if it is not in error.

Parameters:
dataSource - The DataSource to add into the list.
Returns:
True if we added this data source, false if we already have this data source

reloadAllDataSources

public void reloadAllDataSources()
Reload all the data sources


removeAllDataSources

public void removeAllDataSources()
As the method name implies, remove all datasources managed by this DataManager.


removeDataSource

public void removeDataSource(DataSource dataSource)
Remove the given DataSource from the list of datasources.

Parameters:
dataSource - The DataSource to remove.

getFileFilters

public ArrayList getFileFilters()
The DataManager creates a list of PatternFileFilters from the datasource xml.

Returns:
The list of PatternFileFilters.

getCurrent

public DataSourceDescriptor getCurrent(DataSourceDescriptor dds)
Get the actual current descriptor with the id of the given or return the given one if one is not found. We use this for data sources that are unpersisted so they can get an updated descriptor

Parameters:
dds - Given
Returns:
Current

validDatasourceId

public boolean validDatasourceId(Object definingObject)
Is there a mapping defined from the given definingObject (which should be a String) to a DataSourceDescriptor.

Parameters:
definingObject - This is the object passed in when we try to create a DataSource.
Returns:
Do we know how to handle the given definingObject.

validDatasourceId

public boolean validDatasourceId(Object definingObject,
                                 Hashtable properties)
Is there a mapping defined from the given definingObject (which should be a String) to a DataSourceDescriptor or is there a DATATYPE_ID entry in the given properties Hashtable.

Parameters:
definingObject - This is the object passed in when we try to create a DataSource.
properties - May hold a DATATYPE_ID entry.
Returns:
Do we know how to handle the given definingObject.

findDataSource

public DataSource findDataSource(String name)
Find the data source with the given name

Parameters:
name - The name. This is passed to DataSource.identifiedBy() method. It can be 'class:some_class' or a regexp pattern that matches on the data source name
Returns:
the data source or null if none found

createDataSource

public DataSourceResults createDataSource(Object definingObject)
Create a DataSource (if we know how) defined with the given definingObject.

Parameters:
definingObject - This is the data used to create a DataSource. It may be a String (e.g., a URL, a filename) or something else (e.g., a list of URLs).
Returns:
The list of DataSources defined by the given definingObject or null.

createDataSource

public DataSourceResults createDataSource(Object definingObject,
                                          Hashtable properties)
Create a DataSource (if we know how) defined with the given definingObject and set of properties (which may be null).

Parameters:
definingObject - This is the data used to create a DataSource. It may be a String (e.g., a URL, a filename) or something else (e.g., a list of URLs).
properties - The properties for the new DataSource.
Returns:
The list of DataSource defined by the given definingObject or null.

createDataSourceAndAskForType

public void createDataSourceAndAskForType(Object definingObject,
                                          Hashtable properties)
Ask the user for the data soruce type and create the given data source

Parameters:
definingObject - This is the data used to create a DataSource. It may be a String (e.g., a URL, a filename) or something else (e.g., a list of URLs).
properties - The properties for the new DataSource.

createDataSource

public DataSourceResults createDataSource(Object definingObject,
                                          String dataType,
                                          Hashtable properties)
Create a DataSource (if we know how) defined with the given dataType (if non-null) or by the given definingObject and set of properties (which may be null).

Parameters:
definingObject - This is the data used to create a DataSource. It may be a String (e.g., a URL, a filename) or something else (e.g., a list of URLs).
dataType - The id of the DataSourceDescriptor (or null).
properties - The properties for the new DataSource.
Returns:
The list of DataSource defined by the given definingObject or null.

initEncoder

public void initEncoder(XmlEncoder encoder,
                        boolean forRead)
Seed the given encoder with the DataSourceDescriptors and the DataManager object.

Parameters:
encoder - The encoder to seed.
forRead - Is this encoding for a read or a write.

getDescriptor

public DataSourceDescriptor getDescriptor(String dataType)
Find the DataSourceDescriptor with the given dataType id.

Parameters:
dataType - The dataType id to lookup.
Returns:
The DataSourceDescriptor defined by the given dataType (or null).

getProperty

public String getProperty(String dataType,
                          String property)
Find the given property on the DataSourceDescriptor defined by the given dataType.

Parameters:
dataType - The data source descriptor id.
property - The property name.
Returns:
The property or null.

getProperty

public boolean getProperty(String dataType,
                           String property,
                           boolean dflt)
Find the given property on the DataSourceDescriptor defined by the given dataType. If not found then return the given dflt.

Parameters:
dataType - The data source descriptor id.
property - The property name.
dflt - The default value.
Returns:
The property or the dflt parameter.

getNewVariableName

public static List<String> getNewVariableName(String varName)
Get the new name for a variable name

Parameters:
varName - _more_
Returns:
new name

initURLStreamHandlers

public void initURLStreamHandlers()
Add in the AddeURLStreamHandler


isFormulaDataSource

public static boolean isFormulaDataSource(Object s)
Check if an object is a data source that holds formulas.

Parameters:
s - object to check
Returns:
true if it is

main

public static void main(String[] args)
                 throws Exception
test main

Parameters:
args - cmd line args
Throws:
Exception - On error