public class VOTableFormat extends java.lang.Object implements OutputFormat
Format any given query (table) result into VOTable.
Format and version of the resulting VOTable can be provided in parameters at the construction time. This formatter is using STIL. So all formats and versions managed by STIL are also here. Basically, you have the following formats: TABLEDATA, BINARY, BINARY2 (only when using VOTable v1.3) and FITS. The versions are: 1.0, 1.1, 1.2 and 1.3.
Note: The MIME type is automatically set in function of the given VOTable serialization:
It is however possible to change these default values thanks to setMimeType(String, String)
.
In addition of the INFO elements for QUERY_STATUS="OK" and QUERY_STATUS="OVERFLOW", two additional INFO elements are written:
ServiceConnection.getProviderName()
and ServiceConnection.getProviderDescription()
Furthermore, this formatter provides a function to format an error in VOTable: writeError(String, Map, PrintWriter)
.
This is useful for TAP which requires to return in VOTable any error that occurs while any operation.
See DefaultTAPErrorWriter
for more details.
Modifier and Type | Class and Description |
---|---|
static class |
VOTableFormat.LimitedStarTable
Special
StarTable able to read a fixed maximum number of rows TableIterator . |
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
mimeType
MIME type associated with this format.
|
protected ServiceConnection |
service
The
ServiceConnection to use (for the log and to have some information about the service (particularly: name, description). |
protected java.lang.String |
shortMimeType
Short form of the MIME type associated with this format.
|
protected uk.ac.starlink.votable.DataFormat |
votFormat
Format of the VOTable data part in which data must be formatted.
|
protected uk.ac.starlink.votable.VOTableVersion |
votVersion
VOTable version in which table data must be formatted.
|
Constructor and Description |
---|
VOTableFormat(ServiceConnection service)
Creates a VOTable formatter.
|
VOTableFormat(ServiceConnection service,
uk.ac.starlink.votable.DataFormat votFormat)
Creates a VOTable formatter.
|
VOTableFormat(ServiceConnection service,
uk.ac.starlink.votable.DataFormat votFormat,
uk.ac.starlink.votable.VOTableVersion votVersion)
Creates a VOTable formatter.
|
Modifier and Type | Method and Description |
---|---|
protected static uk.ac.starlink.table.ColumnInfo |
getColumnInfo(TAPColumn tapCol)
Convert the given
TAPColumn object into a ColumnInfo object. |
protected static java.lang.Class<?> |
getDatatypeClass(VotType.VotDatatype datatype,
java.lang.String arraysize)
Convert the VOTable datatype string into a corresponding
Class object. |
java.lang.String |
getDescription()
Gets a description of this format.
|
java.lang.String |
getFileExtension()
Gets a file extension for this format.
|
java.lang.String |
getMimeType()
Gets the MIME type corresponding to this format.
|
protected static int[] |
getShape(java.lang.String arraysize)
Convert the given VOTable arraysize into a
ColumnInfo shape. |
java.lang.String |
getShortMimeType()
Gets a short expression of its MIME type.
|
protected static TAPColumn |
getValidColMeta(DBColumn typeFromQuery,
TAPColumn typeFromResult)
Try to get or otherwise to build appropriate metadata using those extracted from the ADQL query and those extracted from the result.
|
uk.ac.starlink.votable.DataFormat |
getVotSerialization()
Get the set VOTable data serialization/format (e.g.
|
uk.ac.starlink.votable.VOTableVersion |
getVotVersion()
Get the set VOTable version.
|
void |
setMimeType(java.lang.String mimeType,
java.lang.String shortForm)
Set the MIME type associated with this format.
|
static uk.ac.starlink.table.ColumnInfo[] |
toColumnInfos(TableIterator result,
TAPExecutionReport execReport,
java.lang.Thread thread)
Writes fields' metadata of the given query result.
|
void |
writeError(java.lang.String message,
java.util.Map<java.lang.String,java.lang.String> otherInfo,
java.io.PrintWriter writer)
Write the given error message as VOTable document.
|
protected void |
writeHeader(uk.ac.starlink.votable.VOTableVersion votVersion,
TAPExecutionReport execReport,
java.io.BufferedWriter out)
Writes the first VOTable nodes/elements preceding the data: VOTABLE, RESOURCE and 3 INFOS (QUERY_STATUS, PROVIDER, QUERY).
|
void |
writeResult(TableIterator queryResult,
java.io.OutputStream output,
TAPExecutionReport execReport,
java.lang.Thread thread)
Formats the given query result and writes it in the given output stream.
|
protected final ServiceConnection service
ServiceConnection
to use (for the log and to have some information about the service (particularly: name, description).protected final uk.ac.starlink.votable.DataFormat votFormat
protected final uk.ac.starlink.votable.VOTableVersion votVersion
protected java.lang.String mimeType
protected java.lang.String shortMimeType
public VOTableFormat(ServiceConnection service) throws java.lang.NullPointerException
Creates a VOTable formatter.
Note:
The MIME type is automatically set to "application/x-votable+xml" = "votable".
It is however possible to change this default value thanks to setMimeType(String, String)
.
service
- The service to use (for the log and to have some information about the service (particularly: name, description).java.lang.NullPointerException
- If the given service connection is null
.public VOTableFormat(ServiceConnection service, uk.ac.starlink.votable.DataFormat votFormat) throws java.lang.NullPointerException
Creates a VOTable formatter.
Note: The MIME type is automatically set in function of the given VOTable serialization:It is however possible to change these default values thanks to setMimeType(String, String)
.
service
- The service to use (for the log and to have some information about the service (particularly: name, description).votFormat
- Serialization of the VOTable data part. (TABLEDATA, BINARY, BINARY2 or FITS).java.lang.NullPointerException
- If the given service connection is null
.public VOTableFormat(ServiceConnection service, uk.ac.starlink.votable.DataFormat votFormat, uk.ac.starlink.votable.VOTableVersion votVersion) throws java.lang.NullPointerException
Creates a VOTable formatter.
Note: The MIME type is automatically set in function of the given VOTable serialization:It is however possible to change these default values thanks to setMimeType(String, String)
.
service
- The service to use (for the log and to have some information about the service (particularly: name, description).votFormat
- Serialization of the VOTable data part. (TABLEDATA, BINARY, BINARY2 or FITS).votVersion
- Version of the resulting VOTable.java.lang.NullPointerException
- If the given service connection is null
.public final java.lang.String getMimeType()
OutputFormat
getMimeType
in interface OutputFormat
public final java.lang.String getShortMimeType()
OutputFormat
getShortMimeType
in interface OutputFormat
public final void setMimeType(java.lang.String mimeType, java.lang.String shortForm)
Set the MIME type associated with this format.
Note: NULL means no modification of the current value:
mimeType
- Full MIME type of this VOTable format. note: if NULL, the MIME type is not modified.shortForm
- Short form of this MIME type. note: if NULL, the short MIME type is not modified.public final uk.ac.starlink.votable.DataFormat getVotSerialization()
public final uk.ac.starlink.votable.VOTableVersion getVotVersion()
public java.lang.String getDescription()
OutputFormat
getDescription
in interface OutputFormat
public java.lang.String getFileExtension()
OutputFormat
getFileExtension
in interface OutputFormat
public void writeError(java.lang.String message, java.util.Map<java.lang.String,java.lang.String> otherInfo, java.io.PrintWriter writer) throws java.io.IOException
Write the given error message as VOTable document.
Note:
In the TAP protocol, all errors must be returned as VOTable. The class DefaultTAPErrorWriter
is in charge of the management
and reporting of all errors. It is calling this function while the error message to display to the user is ready and
must be written in the HTTP response.
Here is the XML format of this VOTable error:
<VOTABLE version="..." xmlns="..." > <RESOURCE type="results"> <INFO name="QUERY_STATUS" value="ERROR> ... </INFO> <INFO name="PROVIDER" value="...">...</INFO> <!-- other optional INFOs (e.g. request parameters) --> </RESOURCE> </VOTABLE>
message
- Error message to display to the user.otherInfo
- List of other additional information to display. optionalwriter
- Stream in which the VOTable error must be written.java.io.IOException
- If any error occurs while writing in the given output.public final void writeResult(TableIterator queryResult, java.io.OutputStream output, TAPExecutionReport execReport, java.lang.Thread thread) throws TAPException, java.io.IOException, java.lang.InterruptedException
OutputFormat
Formats the given query result and writes it in the given output stream.
Note: the given output stream should not be closed at the end of this function. It is up to the called to do it.
writeResult
in interface OutputFormat
queryResult
- The raw (table) result to format.output
- The output stream (a ServletOutputStream or a stream on a file) in which the formatted result must be written.execReport
- The report of the execution of the TAP query whose the result must be now written.thread
- The thread which has asked the result writing.TAPException
- If there is an error while formatting the query result.java.io.IOException
- If any error occurs while writing into the given stream.java.lang.InterruptedException
- If the query has been interrupted/aborted.protected void writeHeader(uk.ac.starlink.votable.VOTableVersion votVersion, TAPExecutionReport execReport, java.io.BufferedWriter out) throws java.io.IOException, TAPException
Writes the first VOTable nodes/elements preceding the data: VOTABLE, RESOURCE and 3 INFOS (QUERY_STATUS, PROVIDER, QUERY).
votVersion
- Target VOTable version.execReport
- The report of the query execution.out
- Writer in which the root node must be written.java.io.IOException
- If there is an error while writing the root node in the given Writer.TAPException
- If there is any other error (by default: never happen).public static final uk.ac.starlink.table.ColumnInfo[] toColumnInfos(TableIterator result, TAPExecutionReport execReport, java.lang.Thread thread) throws java.io.IOException, TAPException, java.lang.InterruptedException
result
- The query result from whose fields' metadata must be written.execReport
- The report of the query execution.thread
- The thread which asked for the result writing.java.io.IOException
- If there is an error while writing the metadata.TAPException
- If there is any other error.java.lang.InterruptedException
- If the given thread has been interrupted.protected static final TAPColumn getValidColMeta(DBColumn typeFromQuery, TAPColumn typeFromResult)
typeFromQuery
- Metadata extracted/guessed from the ADQL query.typeFromResult
- Metadata extracted/guessed from the result.protected static final uk.ac.starlink.table.ColumnInfo getColumnInfo(TAPColumn tapCol)
TAPColumn
object into a ColumnInfo
object.tapCol
- TAPColumn
to convert into ColumnInfo
.ColumnInfo
.protected static final java.lang.Class<?> getDatatypeClass(VotType.VotDatatype datatype, java.lang.String arraysize)
Class
object.datatype
- Value of the VOTable attribute "datatype".arraysize
- Value of the VOTable attribute "arraysize".Class
object.protected static final int[] getShape(java.lang.String arraysize)
ColumnInfo
shape.arraysize
- Value of the VOTable attribute "arraysize".ColumnInfo
shape.