Class InteropFramework

  • All Implemented Interfaces:
    InteropMediaType

    public class InteropFramework
    extends Object
    implements InteropMediaType
    The interoperability framework for PROV, with utility methods to write and read documents to files and streams, according to media types, format (specified as InteropFramework.ProvFormat). The class also provides helper functions to support content negotiation.
    Author:
    lavm, dtm
    • Constructor Detail

      • InteropFramework

        public InteropFramework()
        Default constructor for the ProvToolbox interoperability framework. It uses ProvFactory as its default factory.
      • InteropFramework

        public InteropFramework​(org.openprovenance.prov.model.ProvFactory pFactory)
      • InteropFramework

        public InteropFramework​(CommandLineArguments config,
                                org.openprovenance.prov.model.ProvFactory pFactory)
    • Method Detail

      • buildAcceptHeader

        public String buildAcceptHeader()
        Create a list of mime types supported by ProvToolbox in view of constructing an Accept Header.
        Returns:
        a string representing the mime types.
      • connectWithRedirect

        public URLConnection connectWithRedirect​(URL theURL)
                                          throws IOException
        A method to connect to a URL and follow redirects if any.
        Parameters:
        theURL - a URL to connect to
        Returns:
        a URLConnection
        Throws:
        IOException - if connection cannot be opened and no response is received.
      • convertExtensionToMediaType

        public String convertExtensionToMediaType​(String extension)
        Maps an file extension to a Media type
        Parameters:
        extension - the extension of a file containing a serialization of PROV
        Returns:
        a String for the Internet Media type corresponding to a file with this extension
      • getExtension

        public String getExtension​(InteropFramework.ProvFormat format)
        Returns an extension for a given type of serialization of PROV
        Parameters:
        format - InteropFramework.ProvFormat for which file extension is sought
        Returns:
        a String for the extension of a file containing such a serialization
      • getVariants

        public List<javax.ws.rs.core.Variant> getVariants()
        Support for content negotiation, jax-rs style. Create a list of media type supported by the framework.
        See Also:
        Content Negotiation
      • loadProvUnknownGraph

        public Object loadProvUnknownGraph​(String filename)
        Experimental code, trying to load a document without knowing its serialization format. First parser that succeeds returns a results. Not a robust method!
        Parameters:
        filename - a file to load the provenance document from
        Returns:
        a document
      • newXMLProvFactory

        public static org.openprovenance.prov.model.ProvFactory newXMLProvFactory()
        Creates a factory for the XML Java beans.
        Returns:
        a ProvFactory
      • readDocument

        public org.openprovenance.prov.model.Document readDocument​(InputStream is,
                                                                   InteropFramework.ProvFormat format,
                                                                   String baseuri)
        Reads a Document from an input stream, using the parser specified by the format argument.
        Parameters:
        is - an input stream
        format - one of the input formats supported by ProvToolbox
        baseuri - a base uri for the input stream document
        Returns:
        a Document
      • readDocument

        public org.openprovenance.prov.model.Document readDocument​(InputStream is,
                                                                   InteropFramework.ProvFormat format,
                                                                   org.openprovenance.prov.model.ProvFactory pFactory,
                                                                   String baseuri)
        Reads a Document from an input stream, using the parser specified by the format argument.
        Parameters:
        is - an input stream
        format - one of the input formats supported by ProvToolbox
        pFactory - a provenance factory used to construct the Document
        baseuri - a base uri for the input stream document
        Returns:
        a Document
      • readDocument

        public org.openprovenance.prov.model.Document readDocument​(String url)
        Reads a document from a URL. Uses the Content-type header field to determine the mime-type of the resource, and therefore the parser to read the document.
        Parameters:
        url - a URL
        Returns:
        a Document
      • readDocumentFromFile

        public org.openprovenance.prov.model.Document readDocumentFromFile​(String filename)
        Reads a document from a file, using the file extension to decide which parser to read the file with.
        Parameters:
        filename - the file to read a document from
        Returns:
        a Document
      • readDocumentFromFile

        public org.openprovenance.prov.model.Document readDocumentFromFile​(String filename,
                                                                           InteropFramework.ProvFormat format)
        Reads a document from a file, using the format to decide which parser to read the file with.
        Parameters:
        filename - the file to read a document from
        format - the format of the file
        Returns:
        a Document
      • readDocument

        public org.openprovenance.prov.model.Document readDocument​(org.openprovenance.prov.interop.InteropFramework.ToRead something)
      • setNamespaces

        public void setNamespaces​(org.openprovenance.prov.model.Document doc)
        Initializes a Document's namespace.
      • writeDocument

        public void writeDocument​(OutputStream os,
                                  javax.ws.rs.core.MediaType mt,
                                  org.openprovenance.prov.model.Document document)
        Write a Document to output stream, according to specified Internet Media Type
        Parameters:
        os - an OutputStream to write the Document to
        mt - a MediaType
        document - a Document to serialize
      • writeDocument

        public void writeDocument​(String filename,
                                  org.openprovenance.prov.model.Document document)
        Write a Document to file, serialized according to the file extension
        Parameters:
        filename - path of the file to write the Document to
        document - a Document to serialize
      • writeDocument

        public void writeDocument​(String filename,
                                  InteropFramework.ProvFormat format,
                                  org.openprovenance.prov.model.Document document)
        Write a Document to file, serialized according to the file extension
        Parameters:
        filename - path of the file to write the Document to
        document - a Document to serialize