|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--uk.ac.starlink.table.StarTableFactory
Manufactures StarTable
objects from generic inputs.
This factory delegates the actual table creation to external
TableBuilder
objects, each of which knows how to read a
particular table format. Various makeStarTable methods
are offered, which construct StarTables from different
types of object, such as URL
and
DataSource
. Each of these comes in
two types: automatic format detection and named format.
In the case of a named format, a specifier must be given for the format in which the table to be read is held. This may be one of the following:
In the case of automatic format detection (no format specified), the factory hands the table location to each of the handlers in the default handler list in turn, and if any of them can make a table out of it, it is returned.
In either case, failure to make a table will usually result in a TableFormatException, though if an error in actual I/O is encountered an IOException may be thrown instead.
By default, if the corresponding classes are present, the following TableBuilders are installed in the default handler list (used by default in automatic format detection):
FitsPlusTableBuilder
(format name="fits-plus")
FitsTableBuilder
(format name="fits")
VOTableBuilder
(format name="votable")
The following additional handlers are installed in the known handler list (not used by default but available by specifying the format name):
AsciiTableBuilder
(format name="ascii")
CsvTableBuilder
(format name="csv")
WDCTableBuilder
(format name="wdc")
TableBuilder
interface and have a no-arg
constructor will be instantiated and added to the known handler list.
The factory has a flag wantRandom which determines
whether random-access tables are
preferred results of the makeStarTable methods.
Setting this flag to true does not guarantee
that returned tables will have random access
(the randomTable(uk.ac.starlink.table.StarTable)
method should be used for that),
but this flag is passed to builders as a hint in case they know
how to make either random or non-random tables.
Field Summary | |
static String |
KNOWN_BUILDERS_PROPERTY
System property which can contain a list of TableBuilder classes
for addition to the known (non-automatically detected) handler list. |
Constructor Summary | |
StarTableFactory()
Constructs a StarTableFactory with a default list of builders which will not preferentially construct random-access tables. |
|
StarTableFactory(boolean wantRandom)
Constructs a StarTableFactory with a default list of builders specifying whether it should preferentially construct random-access tables. |
Method Summary | |
boolean |
canImport(DataFlavor[] flavors)
Indicates whether a particular set of DataFlavor ojects offered by a Transferable
is suitable for attempting to turn the Transferable
into a StarTable. |
List |
getDefaultBuilders()
Gets the list of builders which are used for automatic format detection. |
JDBCHandler |
getJDBCHandler()
Returns the JDBC handler object used by this factory. |
List |
getKnownBuilders()
Gets the list of builders which are available for selection by format name. |
List |
getKnownFormats()
Returns the list of format names, one for each of the handlers returned by getKnownBuilders() . |
StoragePolicy |
getStoragePolicy()
Returns the current storage policy. |
TableBuilder |
getTableBuilder(String name)
Returns a table handler with a given name. |
StarTable |
makeStarTable(DataSource datsrc)
Constructs a readable StarTable from a DataSource object using automatic format detection. |
StarTable |
makeStarTable(DataSource datsrc,
String handler)
Constructs a readable StarTable from a DataSource using a named table input handler. |
StarTable |
makeStarTable(String location)
Constructs a readable StarTable from a location string using automatic format detection. |
StarTable |
makeStarTable(String location,
String handler)
Constructs a readable StarTable from a location string using a named table input handler. |
StarTable |
makeStarTable(Transferable trans)
Constructs a StarTable from a Transferable object
using automatic format detection. |
StarTable |
makeStarTable(URL url)
Constructs a readable StarTable from a URL using automatic format detection. |
StarTable |
makeStarTable(URL url,
String handler)
Constructs a readable StarTable from a URL using a named table input handler. |
StarTable |
randomTable(StarTable table)
Returns a table based on a given table and guaranteed to have random access. |
void |
setDefaultBuilders(TableBuilder[] builders)
Sets the list of builders which actually do the table construction. |
void |
setJDBCHandler(JDBCHandler handler)
Sets the JDBC handler object used by this factory. |
void |
setKnownBuilders(TableBuilder[] builders)
Sets the list of builders which are available for selection by format name. |
void |
setStoragePolicy(StoragePolicy policy)
Sets the storage policy. |
void |
setWantRandom(boolean wantRandom)
Sets whether random-access tables are by preference created by this factory. |
boolean |
wantRandom()
Returns the wantRandom flag. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String KNOWN_BUILDERS_PROPERTY
TableBuilder
classes
for addition to the known (non-automatically detected) handler list.
Constructor Detail |
public StarTableFactory()
public StarTableFactory(boolean wantRandom)
wantRandom
- whether random-access tables are preferredMethod Detail |
public List getDefaultBuilders()
TableBuilder
objects used to
construct StarTablespublic void setDefaultBuilders(TableBuilder[] builders)
builders
- an array of TableBuilder objects used to
construct StarTablespublic List getKnownBuilders()
TableBuilder
objects which may be
specified for table buildingpublic void setKnownBuilders(TableBuilder[] builders)
builders
- an array of TableBuilder objects used to
construct StarTablespublic List getKnownFormats()
getKnownBuilders()
.
public void setWantRandom(boolean wantRandom)
wantRandom
- whether, preferentially, this factory should
create random-access tablespublic boolean wantRandom()
public void setStoragePolicy(StoragePolicy policy)
policy
- the new storage policy objectpublic StoragePolicy getStoragePolicy()
StoragePolicy.getDefaultPolicy()
).
public StarTable randomTable(StarTable table) throws IOException
This convenience method is equivalent to getStoragePolicy().randomTable(table).
table
- original table
IOException
public StarTable makeStarTable(DataSource datsrc) throws TableFormatException, IOException
datsrc
- the data source containing the table data
TableFormatException
- if none of the default handlers
could turn datsrc into a table
IOException
- if an I/O error is encounteredpublic StarTable makeStarTable(String location) throws TableFormatException, IOException
location
- the name of the table resource
TableFormatException
- if no handler capable of turning
location into a table is available
IOException
- if one of the handlers encounters an error
constructing a tablepublic StarTable makeStarTable(URL url) throws IOException
url
- the URL where the table lives
TableFormatException
- if no handler capable of turning
datsrc into a table is available
IOException
- if one of the handlers encounters an error
constructing a tablepublic StarTable makeStarTable(DataSource datsrc, String handler) throws TableFormatException, IOException
TableBuilder.getFormatName()
method)
or by giving the full class name of the handler. In the latter
case this factory does not need to have been informed about the
handler previously. If null or the empty string is
supplied for handler, it will fall back on automatic
format detection.
datsrc
- the data source containing the table datahandler
- specifier for the handler which can handle tables
of the right format
TableFormatException
- if datsrc does not contain
a table in the format named by handler
IOException
- if an I/O error is encounteredpublic StarTable makeStarTable(String location, String handler) throws TableFormatException, IOException
TableBuilder.getFormatName()
method)
or by giving the full class name of the handler. In the latter
case this factory does not need to have been informed about the
handler previously. If null or the empty string is
supplied for handler, it will fall back on automatic
format detection.
location
- the name of the table resourcehandler
- specifier for the handler which can handle tables
of the right format
TableFormatException
- if location does not point to
a table in the format named by handler
IOException
- if an I/O error is encounteredpublic StarTable makeStarTable(URL url, String handler) throws TableFormatException, IOException
TableBuilder.getFormatName()
method)
or by giving the full class name of the handler. In the latter
case this factory does not need to have been informed about the
handler previously. If null or the empty string is
supplied for handler, it will fall back on automatic
format detection.
url
- the URL where the table liveshandler
- specifier for the handler which can handle tables
of the right format
TableFormatException
- if the resource at url cannot
be turned into a table by handler
IOException
- if an I/O error is encounteredpublic StarTable makeStarTable(Transferable trans) throws IOException
Transferable
object
using automatic format detection.
In conjunction with a suitable TransferHandler
this makes it easy to accept drop of an object representing a table
which has been dragged from another application.
The implementation of this method currently tries the following on a given transferable to turn it into a table:
URL
object, passes that to the
URL factory method
InputStream
, turns it into a
DataSource
and passes that to the
DataSource constructor
trans
- the Transferable object to construct a table from
TableFormatException
- if no table can be constructed
IOException
canImport(java.awt.datatransfer.DataFlavor[])
public boolean canImport(DataFlavor[] flavors)
Transferable
is suitable for attempting to turn the Transferable
into a StarTable.
Each of the builder objects is queried about whether it can
import the given flavour, and if one says it can, a true value
is returned. A true value is also returned if one of the flavours
has a representation class of URL
.
flavors
- the data flavours offeredpublic JDBCHandler getJDBCHandler()
public void setJDBCHandler(JDBCHandler handler)
handler
- the JDBC handlerpublic TableBuilder getTableBuilder(String name) throws TableFormatException
TableBuilder.getFormatName()
method)
or by giving the full class name of the handler. In the latter
case this factory does not need to have been informed about the
handler previously.
name
- specification of the handler required
TableFormatException
- if name doesn't name any
available handler
|
Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |