uk.ac.starlink.votable

## Class VOTableBuilder

- java.lang.Object
- - uk.ac.starlink.table.formats.DocumentedTableBuilder
  - - uk.ac.starlink.votable.VOTableBuilder

- All Implemented Interfaces:
    Documented, DocumentedIOHandler, MultiTableBuilder, TableBuilder

      public class VOTableBuilder
      extends DocumentedTableBuilder
      implements MultiTableBuilder

  Implementation of the `TableBuilder` interface which gets `StarTable`s from VOTable documents.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `VOTableBuilder()` Default constructor.
    `VOTableBuilder(boolean strict)` Constructs a builder with explicit setting of whether VOTable standard interpreation is strict or not.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `canImport(java.awt.datatransfer.DataFlavor flavor)` Returns `true` for flavors which have MIME types starting text/xml application/xml application/x-votable+xml
    `boolean` | `canStream()` Indicates whether this handler can read tables from a stream.
    `boolean` | `docIncludesExample()` Indicates whether the serialization of some (short) example table should be added to the user documentation for this handler.
    `java.lang.String` | `getFormatName()` Returns the string "VOTable".
    `java.lang.String` | `getXmlDescription()` Returns user-directed documentation in XML format.
    `StarTable` | `makeStarTable(DataSource datsrc, boolean wantRandom, StoragePolicy storagePolicy)` Makes a StarTable out of a DataSource which points to a VOTable.
    `TableSequence` | `makeStarTables(DataSource datsrc, StoragePolicy storagePolicy)` Constructs a sequence of StarTables based on a given DataSource.
    `void` | `streamStarTable(java.io.InputStream istrm, TableSink sink, java.lang.String index)` Acquires the data from a single TABLE element in a VOTable document, writing the result to a sink.

    - ### Methods inherited from class uk.ac.starlink.table.formats.DocumentedTableBuilder

      `getExtensions, looksLikeFile`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface uk.ac.starlink.table.TableBuilder

      `looksLikeFile`

    - ### Methods inherited from interface uk.ac.starlink.table.formats.DocumentedIOHandler

      `matchesExtension, readText, toLink`

- - ### Constructor Detail

    - #### VOTableBuilder

          public VOTableBuilder()

      Default constructor. Strictness of VOTable standard enforcement is determined by `VOElementFactory.isStrictByDefault()`.

    - #### VOTableBuilder

          public VOTableBuilder(boolean strict)

      Constructs a builder with explicit setting of whether VOTable standard interpreation is strict or not.
      Parameters:
        `strict` - true iff you want strict enforcement of VOTable standard
      See Also:
        `VOElementFactory.setStrict(boolean)`

  - ### Method Detail

    - #### getFormatName

          public java.lang.String getFormatName()

      Returns the string "VOTable".
      Specified by:
        `getFormatName` in interface `TableBuilder`
      Returns:
        format name

    - #### makeStarTable

          public StarTable makeStarTable(DataSource datsrc,
                                         boolean wantRandom,
                                         StoragePolicy storagePolicy)
                                  throws TableFormatException,
                                         java.io.IOException

      Makes a StarTable out of a DataSource which points to a VOTable. If the source has a position attribute, it is currently interpreted as an index into a breadth-first list of the TABLE elements in the document pointed to by `datsrc`, thus it must be a non-negative integer less than the number of TABLE elements. If it has no position attribute, the first TABLE element is used. The interpretation of the position should probably change or be extended in the future to allow XPath expressions.
      Specified by:
        `makeStarTable` in interface `TableBuilder`
      Parameters:
        `datsrc` - the location of the VOTable document to use
        `wantRandom` - whether, preferentially, a random access table should be returned (doesn't guarantee that it will be random)
        `storagePolicy` - a StoragePolicy object which may be used to supply scratch storage if the builder needs it
      Returns:
        a StarTable made out of `datsrc`, or `null` if this handler can't handle it
      Throws:
        `TableFormatException` - if the table is not of a kind that can be handled by this handler
        `java.io.IOException` - if an unexpected I/O error occurs during processing

    - #### makeStarTables

          public TableSequence makeStarTables(DataSource datsrc,
                                              StoragePolicy storagePolicy)
                                       throws TableFormatException,
                                              java.io.IOException

      Description copied from interface: `MultiTableBuilder`
      Constructs a sequence of StarTables based on a given DataSource. If the source is not recognised or this object does not know how to make tables from it, then a `TableFormatException` should be thrown. If this builder thinks it should be able to handle the source but an error occurs during processing, an `IOException` can be thrown.

      If the `position` of the data source is not null, then this method should return a sequence containing a single table, the one which would be returned by the `makeStarTable` method with that position.

      Specified by:
        `makeStarTables` in interface `MultiTableBuilder`
      Parameters:
        `datsrc` - the DataSource containing the table resource
        `storagePolicy` - a StoragePolicy object which may be used to supply scratch storage if the builder needs it
      Returns:
        an array of StarTables read from `datsrc`
      Throws:
        `TableFormatException` - if the table is not of a kind that can be handled by this handler
        `java.io.IOException` - if an unexpected I/O error occurs during processing

    - #### canImport

          public boolean canImport(java.awt.datatransfer.DataFlavor flavor)

      Returns `true` for flavors which have MIME types starting
      - text/xml
      - application/xml
      - application/x-votable+xml
      Specified by:
        `canImport` in interface `TableBuilder`
      Parameters:
        `flavor` - the DataFlavor whose suitability as stream input is to be assessed
      Returns:
        `true` iff this builder reckons it stands a good chance of turning a stream of type `flavor` into a `StarTable`

    - #### streamStarTable

          public void streamStarTable(java.io.InputStream istrm,
                                      TableSink sink,
                                      java.lang.String index)
                               throws java.io.IOException

      Acquires the data from a single TABLE element in a VOTable document, writing the result to a sink. This can be used if only one-shot access to the data is required. Invocation of this method should be cheap on memory even for large XML documents and/or tables. Invocation is synchronous, so the method only returns when the streaming has been done (successfully or otherwise).

      Note that only table metadata that precedes the TABLE element in the XML stream can be picked up when using this method. If there are any XML elements following the end of the TABLE whose content would normally show up in table metadata, it will be ignored when using this method.

      For more flexible streamed access to VOTable data, use a `TableContentHandler`.

      Specified by:
        `streamStarTable` in interface `TableBuilder`
      Parameters:
        `istrm` - stream from which the VOTable document will be supplied
        `sink` - callback interface into which the table metadata and data will be dumped
        `index` - if present, a string representation of the index of the table in the document to be read - "0" means the first one encountered, "1" means the second, etc. If it's `null` or not of numeric form the first table will be used
      Throws:
        `TableFormatException` - if the table can't be streamed or the data is malformed
        `java.io.IOException` - if some other error occurs

    - #### canStream

          public boolean canStream()

      Description copied from class: `DocumentedTableBuilder`
      Indicates whether this handler can read tables from a stream.
      Specified by:
        `canStream` in class `DocumentedTableBuilder`
      Returns:
        true iff this handler can read from streams

    - #### docIncludesExample

          public boolean docIncludesExample()

      Description copied from interface: `DocumentedIOHandler`
      Indicates whether the serialization of some (short) example table should be added to the user documentation for this handler. Binary formats, or instances for which the `Documented.getXmlDescription()` method already includes some example output, should return false.
      Specified by:
        `docIncludesExample` in interface `DocumentedIOHandler`
      Returns:
        true if the user documentation would benefit from the addition of an example serialization

    - #### getXmlDescription

          public java.lang.String getXmlDescription()

      Description copied from interface: `Documented`
      Returns user-directed documentation in XML format.

      The output should be a sequence of one or more <P> elements, using XHTML-like XML. Since rendering may be done in a number of contexts however, use of the full range of XHTML elements is discouraged. Where possible, the content should stick to simple markup such as the elements P, A, UL, OL, LI, DL, DT, DD EM, STRONG, I, B, CODE, TT, PRE.

      Specified by:
        `getXmlDescription` in interface `Documented`
      Returns:
        XML description of this object