uk.ac.starlink.table
Class StarTableFactory

java.lang.Object
  |
  +--uk.ac.starlink.table.StarTableFactory

public class StarTableFactory
extends Object

Manufactures StarTable objects from generic inputs. This factory delegates the actual table creation to external TableBuilder objects; the generic input is passed to each one in turn until one can make a StarTable from it, which object is returned to the caller. JDBC is also used to create tables under appropriate circumstances.

By default, if the corresponding classes are present, the following TableBuilders are installed:

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 Tables.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.


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 getBuilders()
          Gets the list of builders which actually do the table construction.
 JDBCHandler getJDBCHandler()
          Returns the JDBC handler object used by this factory.
 StarTable makeStarTable(DataSource datsrc)
          Constructs a readable StarTable from a DataSource object.
 StarTable makeStarTable(String location)
          Constructs a readable StarTable from a location string, which can represent a filename or URL, including a jdbc: protocol URL if an appropriate JDBC driver is installed.
 StarTable makeStarTable(Transferable trans)
          Constructs a StarTable from a Transferable object.
 StarTable makeStarTable(URL url)
          Constructs a readable StarTable from a URL.
 void setBuilders(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 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
 

Constructor Detail

StarTableFactory

public StarTableFactory()
Constructs a StarTableFactory with a default list of builders which will not preferentially construct random-access tables.


StarTableFactory

public StarTableFactory(boolean wantRandom)
Constructs a StarTableFactory with a default list of builders specifying whether it should preferentially construct random-access tables.

Parameters:
wantRandom - whether random-access tables are preferred
Method Detail

getBuilders

public List getBuilders()
Gets the list of builders which actually do the table construction. Builders earlier in the list are given a chance to make the table before ones later in the list. This list may be modified to change the behaviour of the factory.

Returns:
a mutable list of TableBuilder objects used to construct StarTables

setBuilders

public void setBuilders(TableBuilder[] builders)
Sets the list of builders which actually do the table construction. Builders earlier in the list are given a chance to make the table before ones later in the list.

Parameters:
builders - an array of TableBuilder objects used to construct StarTables

setWantRandom

public void setWantRandom(boolean wantRandom)
Sets whether random-access tables are by preference created by this factory.

Parameters:
wantRandom - whether, preferentially, this factory should create random-access tables

wantRandom

public boolean wantRandom()
Returns the wantRandom flag.

Returns:
whether, preferentially, this factory should create random-access tables

makeStarTable

public StarTable makeStarTable(DataSource datsrc)
                        throws IOException
Constructs a readable StarTable from a DataSource object.

Parameters:
datsrc - the data source containing the table data
Returns:
a new StarTable view of the resource datsrc
Throws:
UnknownTableFormatException - if no handler capable of turning datsrc into a table is available
IOException - if one of the handlers encounters an error constructing a table

makeStarTable

public StarTable makeStarTable(String location)
                        throws IOException
Constructs a readable StarTable from a location string, which can represent a filename or URL, including a jdbc: protocol URL if an appropriate JDBC driver is installed.

Parameters:
location - the name of the table resource
Returns:
a new StarTable view of the resource at location
Throws:
UnknownTableFormatException - if no handler capable of turning location into a table is available
IOException - if one of the handlers encounters an error constructing a table

makeStarTable

public StarTable makeStarTable(URL url)
                        throws IOException
Constructs a readable StarTable from a URL.

Parameters:
url - the URL where the table lives
Returns:
a new StarTable view of the resource at url
Throws:
UnknownTableFormatException - if no handler capable of turning datsrc into a table is available
IOException - if one of the handlers encounters an error constructing a table

makeStarTable

public StarTable makeStarTable(Transferable trans)
                        throws IOException
Constructs a StarTable from a Transferable object. 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:

This method doesn't throw an exception if it fails to come up with a StarTable, it merely returns null. This is because with many flavours to choose from, it's not clear which exception ought to get thrown.

Parameters:
trans - the Transferable object to construct a table from
Returns:
a new StarTable constructed from the Transferable, or null if it can't be done
IOException
See Also:
canImport(java.awt.datatransfer.DataFlavor[])

canImport

public 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.

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.

Parameters:
flavors - the data flavours offered

getJDBCHandler

public JDBCHandler getJDBCHandler()
Returns the JDBC handler object used by this factory.

Returns:
the JDBC handler

setJDBCHandler

public void setJDBCHandler(JDBCHandler handler)
Sets the JDBC handler object used by this factory.

Parameters:
handler - the JDBC handler

Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved.