ucar.unidata.data.DataSourceinterface defines the api through which all data sources are accessed. There is a base class
ucar.unidata.data.DataSourceImplthat provides a set of base services. There are a variety of DataSource implementations:
ucar.unidata.data.DataManagerclass to create and manage the set of DataSource-s. This singleton object can be accessed by the
The DataManager knows nothing about the specific DataSource classes. Rather, the set of available DataSource-s is defined within the datasource.xml resource file.
This file has the form:
<datasource id="EXAMPLE.DATA" factory="ucar.unidata.apps.example.ExampleDataSource" patterns="\.txt$,\.html$" label="Example data source"/> ...The DataManager parses the XML and creates a set of
ucar.unidata.data.DataSourceDescriptorobjects which hold this information.
The patterns attribute is a set of
comma separated regular expression patterns
used to determine if this data source is applicable for a given file or url.
For example, from the main IDV
ucar/unidata/idv/resources/datasource.xml file we have the
entry for the GeoGridDataSource:
<datasource id="FILE.NETCDF" factory="ucar.unidata.data.grid.GeoGridDataSource" patterns=".nc$,.cdf$" label="Netcdf files">This data source type is applicable to anything that ends with .nc of .cdf (The $ used in the patterns represents the end of line character in a regular expression.). The patterns are also used to instantiate a set of PatternFileFilters used when choosing files from the file system.
The factory attribute in the XML
is the name of the class that implements ucar.unidata.data.DataSourceFactory.
This is the class that is instantiated for a particular data source. The DataManager
then asks this class to
getDataSource. We do this so we could
separate out the class that creates a DataSource form the actual DataSource.
In practice however, the DataSourceImpl class implements this interface
by simply returning itself. i.e., the factory that is created is the actual
The important DataManager methods include:
DataSource createDataSource (String dataName)
Here dataName is typically either a url or a file. The DataManager find the data source entry that which contains a pattern that matches the given dataName. It then turns around and calls createDataSource, as described below, passing in the dataName, dataType (i.e., the id from the XML), and an empty properties table.
DataSource createDataSource (Object dataName, String dataType, Hashtable properties)
This method can get called directly by data choosers and the IDV. Here dataName can be anything (a url, a filename, a complex data structure). The argument dataType is an id within the datasource.xml file. The properties table allows one to pass in extra information when creating a DataSource.
The DataManager first sees if a DataSource with the given dataName object already exists in its list of created DataSource-s. If it does exists then that previously created DataSource is returned. If not, the DataManager looks up the DataSourceFactory class to instantiate from datasource.xml. The DataManager then tries to find and call a constructor on this factory class with the following signature:
(DataSourceDescriptor.class, dataName.getClass(), Hashtable.class)
This class also has to be registered with the IDV so that when some file or other data source on a network has been selected the IDV knows what DataSource to create. You do this by adding an entry into a datasource.xml:
<datasource id="EXAMPLE.DATA" factory="ucar.unidata.apps.example.ExampleDataSource" patterns="\.txt$,\.html$" label="Example data"/>This could be the core IDV resource file (located in
ucar/unidata/idv/resources/datasource.xml) or in a different file that is included as a resource in your application (like the example
DirectDataChoice (DataSource dataSource, Object id, String name, String description, List categories, DataSelection dataSelection);Where:
So you can do:
Object someIdForField1 = "field1"; List categories = DataCategory.parseCategories ("2D grid;GRID-2D-TIME;"); DataChoice dc = new DirectDataChoice (this, someIdForField1, "Field 1", "Some desc", categories, null); addDataChoice (dc);
Français Español Portugese Italian Japanese Korean Russian Chinese-simp Chinese-trad Dutch German Greek Français Español Portugese Italian Japanese Korean Russian Chinese-simp Chinese-trad Dutch German Greek