public class TAPMetadata extends java.lang.Object implements java.lang.Iterable<TAPSchema>, VOSIResource, TAPResource
Let listing all schemas, tables and columns available in a TAP service. This list also corresponds to the TAP resource "/tables".
Only schemas are stored in this object. So that's why only schemas can be
added and removed from this class. However, TAPSchema
objects are
listing tables, whose the object representation is listing columns. So to
add tables, you must first embed them in a schema.
All metadata have two names: one to use in ADQL queries and the other to use
when really querying the database. This is very useful to hide the real
complexity of the database and propose a simpler view of the query-able
data. It is particularly useful if a schema does not exist in the database
but has been added in the TAP schema for more logical separation on the user
point of view. In a such case, the schema would have an ADQL name but no DB
name (NULL value ; which is possible only with TAPSchema
objects).
This class lets also detect the ObsCore and RegTAP data models, thanks to
the functions getObsCoreTable()
and getRegTAPSchema()
which return resp. the ObsCore table and the RegTAP schema if matching the
IVOA specification.
Modifier and Type | Class and Description |
---|---|
static class |
TAPMetadata.STDSchema
Enumeration of all schemas defined in the TAP standard.
|
static class |
TAPMetadata.STDTable
Enumeration of all tables of TAP_SCHEMA.
|
protected static class |
TAPMetadata.TAPTableIterator
Let iterating over the list of all tables contained in a given
TAPMetadata object. |
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
accessURL
Part of the TAP URI which identify this TAP resource.
|
protected java.util.Map<java.lang.String,TAPCoosys> |
coordinateSystems
List of all coordinate systems used by columns published in the TAP_SCHEMA.
|
static java.lang.String |
RESOURCE_NAME
Resource name of the TAP metadata.
|
protected java.util.Map<java.lang.String,TAPSchema> |
schemas
List of all schemas available through the TAP service.
|
protected java.lang.String |
xsltPath
The path of the XSLT style-sheet to apply.
|
Constructor and Description |
---|
TAPMetadata()
Build an empty list of metadata.
|
Modifier and Type | Method and Description |
---|---|
TAPCoosys |
addCoosys(TAPCoosys newCoosys)
Add the given coordinate system definition.
|
TAPSchema |
addSchema(java.lang.String schemaName)
Build a new
TAPSchema object with the given ADQL name. |
TAPSchema |
addSchema(java.lang.String schemaName,
java.lang.String description,
java.lang.String utype)
Build a new
TAPSchema object with the given ADQL name. |
void |
addSchema(TAPSchema s)
Add the given schema inside this TAP metadata set.
|
void |
destroy()
Let free properly all system/file/DB resources kept opened by this TAP resource.
|
boolean |
executeResource(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Interpret the given request, execute the appropriate action and finally return a result or display information to the user.
|
java.lang.String |
getAccessURL()
Get the URL which lets access this resource.
|
java.lang.String |
getCapability()
Get the capabilities of this resource.
|
TAPCoosys |
getCoosys(java.lang.String coosysId)
Get the coordinate system definition associated with the given ID.
|
static TAPTable |
getCoosysTable()
Get the minimum definition of the table TAP_SCHEMA.coosys as expected by
the library (see
JDBCConnection.getTAPSchema() . |
java.lang.String |
getName()
Get the name of this TAP resource.
|
int |
getNbSchemas()
Get the number of schemas contained in this TAP metadata set.
|
int |
getNbTables()
Get the number of all tables contained in this TAP metadata set.
|
TAPTable |
getObsCoreTable()
Get the description of the ObsCore table, if it is defined.
|
TAPSchema |
getRegTAPSchema()
Get the description of the RegTAP schema, if it is defined.
|
TAPSchema |
getSchema(java.lang.String schemaName)
Search for a schema having the given ADQL name.
|
java.lang.String |
getStandardID()
Get the standardID of this endpoint of the VOSI interface.
|
static TAPSchema |
getStdSchema(boolean isSchemaSupported)
Get the definition of the whole standard TAP_SCHEMA.
|
static TAPTable |
getStdTable(TAPMetadata.STDTable tableId)
Get the definition of the specified standard TAP table.
|
java.util.List<DBTable> |
getTable(java.lang.String tableName)
Search in this TAP metadata set for all tables whose the ADQL name matches the given one,
whatever is their schema.
|
TAPTable |
getTable(java.lang.String schemaName,
java.lang.String tableName)
Search for the specified table in this TAP metadata set.
|
java.util.Iterator<TAPTable> |
getTables()
Get the list of all tables available in this TAP metadata set.
|
java.lang.String |
getXSLTPath()
Gets the path/URL of the XSLT style-sheet to use.
|
boolean |
hasSchema(java.lang.String schemaName)
Tell whether there is a schema with the given ADQL name.
|
boolean |
hasTable(java.lang.String tableName)
Tell whether this TAP metadata set contains a table with the given ADQL name, whatever is its schema.
|
boolean |
hasTable(java.lang.String schemaName,
java.lang.String tableName)
Tell whether this TAP metadata set contains the specified table.
|
void |
init(javax.servlet.ServletConfig config)
Let initialize this TAP resource.
|
boolean |
isEmpty()
Tell whether this TAP metadata set contains no schema.
|
java.util.Iterator<TAPSchema> |
iterator() |
void |
removeAllSchemas()
Remove all schemas of this metadata set.
|
TAPCoosys |
removeCoosys(java.lang.String coosysId)
Remove the coordinate system declared with the given ID.
|
TAPSchema |
removeSchema(java.lang.String schemaName)
Remove the schema having the given ADQL name.
|
static TAPMetadata.STDTable |
resolveStdTable(java.lang.String tableName)
Tell whether the given table name is a standard TAP table.
|
void |
setTAPBaseURL(java.lang.String baseURL)
Let diffuse the base URL of the TAP service to all its TAP resources.
|
void |
setXSLTPath(java.lang.String path)
Sets the path/URL of the XSLT style-sheet to use.
|
void |
write(java.io.PrintWriter writer)
Format in XML this whole metadata set and write it in the given writer.
|
protected void |
writeAtt(java.lang.String prefix,
java.lang.String attributeName,
java.lang.String attributeValue,
boolean isOptionalAttr,
java.io.PrintWriter writer)
Write the specified metadata attribute as a simple XML node.
|
protected void |
writeColumn(TAPColumn c,
java.io.PrintWriter writer)
Format in XML the given column and then write it in the given writer.
|
protected void |
writeForeignKey(TAPForeignKey fk,
java.io.PrintWriter writer)
Format in XML the given foreign key and then write it in the given writer.
|
protected void |
writeSchema(TAPSchema s,
java.io.PrintWriter writer)
Format in XML the given schema and then write it in the given writer.
|
protected int |
writeTable(TAPTable t,
java.io.PrintWriter writer)
Format in XML the given table and then write it in the given writer.
|
public static final java.lang.String RESOURCE_NAME
protected final java.util.Map<java.lang.String,TAPSchema> schemas
protected final java.util.Map<java.lang.String,TAPCoosys> coordinateSystems
protected java.lang.String accessURL
protected java.lang.String xsltPath
public TAPMetadata()
Build an empty list of metadata.
Note:
By default, a TAP service must have at least a TAP_SCHEMA schema which contains a set of 5 tables
(schemas, tables, columns, keys and key_columns). This schema is not created here by default
because it can be customized by the service implementor. Besides, the DB name may be different.
However, you can easily get this schema thanks to the function getStdSchema(boolean)
which returns the standard definition of this schema (including all tables and columns described
by the standard). For a standard definition of this schema, you can then write the following:
TAPMetadata meta = new TAPMetadata(); meta.addSchema(TAPMetadata.getStdSchema());
Of course, this schema (and its tables and their columns) can be customized after if needed.
Otherwise, if you want customize just some part of this schema, you can also use the function
getStdTable(STDTable)
to get just the standard definition of some of its tables, either
to customize them or to merely get them and keep them like they are.
public final java.lang.String getXSLTPath()
public final void setXSLTPath(java.lang.String path)
path
- The new XSLT path/URL.public final void addSchema(TAPSchema s)
Add the given schema inside this TAP metadata set.
Note: If the given schema is NULL, nothing will be done.
s
- The schema to add.public TAPSchema addSchema(java.lang.String schemaName)
Build a new TAPSchema
object with the given ADQL name.
Then, add it inside this TAP metadata set.
Note:
The built TAPSchema
object is returned, so that being modified afterwards if needed.
schemaName
- ADQL name of the schema to create and add inside this TAP metadata set.TAPSchema.TAPSchema(String)
,
addSchema(TAPSchema)
public TAPSchema addSchema(java.lang.String schemaName, java.lang.String description, java.lang.String utype)
Build a new TAPSchema
object with the given ADQL name.
Then, add it inside this TAP metadata set.
Note:
The built TAPSchema
object is returned, so that being modified afterwards if needed.
schemaName
- ADQL name of the schema to create and add inside this TAP metadata set.description
- Description of the new schema. MAY be NULLutype
- UType associating the new schema with a data-model. MAY be NULLTAPSchema.TAPSchema(String, String, String)
,
addSchema(TAPSchema)
public final boolean hasSchema(java.lang.String schemaName)
Tell whether there is a schema with the given ADQL name.
Important note: This function is case sensitive!
schemaName
- ADQL name of the schema whose the existence must be checked.public final TAPSchema getSchema(java.lang.String schemaName)
Search for a schema having the given ADQL name.
Important note: This function is case sensitive!
schemaName
- ADQL name of the schema to search.public final int getNbSchemas()
public final boolean isEmpty()
public final TAPSchema removeSchema(java.lang.String schemaName)
Remove the schema having the given ADQL name.
Important note: This function is case sensitive!
WARNING:
If the goal of this function's call is to delete definitely the specified schema
from the metadata, you SHOULD also call TAPTable.removeAllForeignKeys()
on the
removed table. Indeed, foreign keys of this table would still link the removed table
with other tables AND columns of the whole metadata set.
schemaName
- ADQL name of the schema to remove from this TAP metadata set.public final void removeAllSchemas()
public final java.util.Iterator<TAPSchema> iterator()
iterator
in interface java.lang.Iterable<TAPSchema>
public java.util.Iterator<TAPTable> getTables()
public boolean hasTable(java.lang.String schemaName, java.lang.String tableName)
Tell whether this TAP metadata set contains the specified table.
Note: This function is case sensitive!
schemaName
- ADQL name of the schema owning the table to search.tableName
- ADQL name of the table to search.public boolean hasTable(java.lang.String tableName)
Tell whether this TAP metadata set contains a table with the given ADQL name, whatever is its schema.
Note: This function is case sensitive!
tableName
- ADQL name of the table to search.public TAPTable getTable(java.lang.String schemaName, java.lang.String tableName)
Search for the specified table in this TAP metadata set.
Note: This function is case sensitive!
schemaName
- ADQL name of the schema owning the table to search.tableName
- ADQL name of the table to search.public java.util.List<DBTable> getTable(java.lang.String tableName)
Search in this TAP metadata set for all tables whose the ADQL name matches the given one, whatever is their schema.
Note: This function is case sensitive!
tableName
- ADQL name of the tables to search.public TAPTable getObsCoreTable()
This function is case sensitive only on the schema name
(i.e. ivoa
) which must be defined in full lower case.
The table name (i.e. ObsCore
) will be found whatever
the case it is written in and whether it is prefixed or not.
NULL
if this table is not provided by this TAP
service.public TAPSchema getRegTAPSchema()
This function is case sensitive only on the schema name
(i.e. rr
) which must be defined in full lower case.
The tables name (e.g. capability
) will be searched case
sensitively as well. However, it does not matter if the table name is
prefixed or not.
NULL
if RegTAP is not supported in this TAP
service.public int getNbTables()
public TAPCoosys getCoosys(java.lang.String coosysId)
coosysId
- ID of the coordinate system to get. (case sensitive)public TAPCoosys addCoosys(TAPCoosys newCoosys)
Important:
If a coordinate system with the same ID (case sensitive) is already declared in
this TAPMetadata
, it will be replaced by the given one. The replaced
coordinate system is returned by this function.
newCoosys
- The coordinate system definition to add.TAPMetadata
,
or NULL if no coord. sys. was declared with this ID.public TAPCoosys removeCoosys(java.lang.String coosysId)
coosysId
- The ID of the coordinate system definition to remove.public java.lang.String getName()
TAPResource
Get the name of this TAP resource.
Important note: This name MUST NOT be NULL and SHOULD NEVER change.
getName
in interface TAPResource
public void setTAPBaseURL(java.lang.String baseURL)
TAPResource
Let diffuse the base URL of the TAP service to all its TAP resources.
Important note: This function should be called just once: either at the creation of the service or when the first request is sent to the TAP service (in this case, the request is also used to finish the initialization of the TAP service, and of all its resources).
setTAPBaseURL
in interface TAPResource
baseURL
- Common URL/URI used in all requests sent by any user to the TAP service.public java.lang.String getAccessURL()
VOSIResource
getAccessURL
in interface VOSIResource
public java.lang.String getCapability()
VOSIResource
getCapability
in interface VOSIResource
public java.lang.String getStandardID()
VOSIResource
Get the standardID of this endpoint of the VOSI interface.
The standard IDs of the VOSI endpoints are the following:
getStandardID
in interface VOSIResource
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException
TAPResource
init
in interface TAPResource
config
- Servlet configuration. (may be useful for the configuration of this resource)javax.servlet.ServletException
- If any error prevent the initialization of this TAP resource. In case a such exception is thrown, the service should stop immediately.public void destroy()
TAPResource
destroy
in interface TAPResource
public boolean executeResource(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
TAPResource
Interpret the given request, execute the appropriate action and finally return a result or display information to the user.
IMPORTANT:
"TAP resources can not take the law in their own hands!" :-)
Errors that could occur inside this function should not be written directly in the given HttpServletResponse
.
They should be thrown to the resources executor: an instance of TAP
, which
will fill the HttpServletResponse
with the error in the format described by the IVOA standard - VOTable. Besides, TAP
may also
add more information and may log the error (in function of this type).
executeResource
in interface TAPResource
request
- Request sent by the user and which should be interpreted/executed here.response
- Response in which the result of the request must be written.java.io.IOException
- If any error occurs while writing the result of the given request.public void write(java.io.PrintWriter writer) throws java.io.IOException
writer
- Stream in which the XML representation of this metadata must be written.java.io.IOException
- If there is any error while writing the XML in the given writer.protected void writeSchema(TAPSchema s, java.io.PrintWriter writer) throws java.io.IOException
Format in XML the given schema and then write it in the given writer.
Written lines:
<schema> <name>...</name> <title>...</title> <description>...</description> <utype>...</utype> // call #writeTable(TAPTable, PrintWriter) for each table </schema>
Note: When NULL an attribute or a field is not written. Here this rule concerns: description and utype.
s
- The schema to format and to write in XML.writer
- Output in which the XML serialization of the given schema must be written.java.io.IOException
- If the connection with the HTTP client has been either canceled or closed for another reason.writeTable(TAPTable, PrintWriter)
protected int writeTable(TAPTable t, java.io.PrintWriter writer)
Format in XML the given table and then write it in the given writer.
Written lines:
<table type="..."> <name>...</name> <title>...</title> <description>...</description> <utype>...</utype> // call #writeColumn(TAPColumn, PrintWriter) for each column // call #writeForeignKey(TAPForeignKey, PrintWriter) for each foreign key </table>
Note 1: When NULL an attribute or a field is not written. Here this rule concerns: description and utype.
Note 2:
The PrintWriter buffer is flushed all the 10 columns. At that moment the writer is checked for errors.
If the error flag is set, a ClientAbortException
is thrown in order to stop the metadata writing.
This is particularly useful if the metadata data is pretty large.
t
- The table to format and to write in XML.writer
- Output in which the XML serialization of the given table must be written.protected void writeColumn(TAPColumn c, java.io.PrintWriter writer)
Format in XML the given column and then write it in the given writer.
Written lines:
<column std="true|false"> // the value of this field is TAPColumn#isStd() <name>...</name> <description>...</description> <unit>...</unit> <utype>...</utype> <ucd>...</ucd> <dataType xsi:type="vod:TAPType" size="...">...</dataType> <flag>indexed</flag> // if TAPColumn#isIndexed() <flag>primary</flag> // if TAPColumn#isPrincipal() </column>
Note: When NULL an attribute or a field is not written. Here this rule concerns: description, unit, utype, ucd and flags.
c
- The column to format and to write in XML.writer
- Output in which the XML serialization of the given column must be written.protected void writeForeignKey(TAPForeignKey fk, java.io.PrintWriter writer)
Format in XML the given foreign key and then write it in the given writer.
Written lines:
<foreignKey> <targetTable>...</targetTable> <fkColumn> <fromColumn>...</fromColumn> <targetColumn>...</targetColumn> </fkColumn> ... <description>...</description> <utype>...</utype> </foreignKey>
Note: When NULL an attribute or a field is not written. Here this rule concerns: description and utype.
fk
- The foreign key to format and to write in XML.writer
- Output in which the XML serialization of the given foreign key must be written.protected final void writeAtt(java.lang.String prefix, java.lang.String attributeName, java.lang.String attributeValue, boolean isOptionalAttr, java.io.PrintWriter writer)
prefix
- Prefix of the XML node. (generally, space characters)attributeName
- Name of the metadata attribute to write (= Name of the XML node).attributeValue
- Value of the metadata attribute (= Value of the XML node).isOptionalAttr
- true if the attribute to write is optional (in this case, if the value is NULL or an empty string, the whole attribute item won't be written),
false otherwise (here, if the value is NULL or an empty string, the XML item will be written with an empty string as value).writer
- Output in which the XML node must be written.public static final TAPSchema getStdSchema(boolean isSchemaSupported)
Get the definition of the whole standard TAP_SCHEMA. Thus, all standard TAP_SCHEMA tables (with all their columns) are also included in this object.
Note:
This function create the TAPSchema
and all its TAPTable
s objects on the fly.
isSchemaSupported
- false if the DB name must be prefixed by "TAP_SCHEMA_", true otherwise.TAPMetadata.STDSchema.TAPSCHEMA
,
TAPMetadata.STDTable
,
getStdTable(STDTable)
public static final TAPTable getCoosysTable()
JDBCConnection.getTAPSchema()
.public static final TAPTable getStdTable(TAPMetadata.STDTable tableId)
Get the definition of the specified standard TAP table.
Important note:
The returned table is not linked at all with a schema, on the contrary of getStdSchema(boolean)
which returns tables linked with the returned schema.
So, you may have to linked this table to schema (by using TAPSchema.addTable(TAPTable)
) whose the ADQL name is TAP_SCHEMA after calling this function.
Note:
This function create the TAPTable
object on the fly.
tableId
- ID of the TAP table to return.public static final TAPMetadata.STDTable resolveStdTable(java.lang.String tableName)
Tell whether the given table name is a standard TAP table.
Note: This function is case sensitive. Indeed TAP_SCHEMA tables are defined by the TAP standard by a given case. Thus, this case is expected here.
tableName
- Unqualified table name.TAPMetadata.STDTable
or NULL if the given table is not part of the TAP standard.