Search in sources :

Example 1 with CoreIoException

use of org.sbolstandard.core.io.CoreIoException in project libSBOLj by SynBioDex.

the class SBOLReader method readJSON.

/**
 * @param stream
 * @return
 * @throws SBOLValidationException if the following SBOL validation rule was violated: 10105.
 */
private static DocumentRoot<QName> readJSON(Reader stream) throws SBOLValidationException {
    JsonReader reader = Json.createReaderFactory(Collections.<String, Object>emptyMap()).createReader(stream);
    JsonIo jsonIo = new JsonIo();
    IoReader<String> ioReader = jsonIo.createIoReader(reader.read());
    DocumentRoot<String> root;
    try {
        root = ioReader.read();
    } catch (CoreIoException e) {
        throw new SBOLValidationException("sbol-10105", e);
    }
    return StringifyQName.string2qname.mapDR(root);
}
Also used : JsonIo(org.sbolstandard.core.io.json.JsonIo) JsonReader(javax.json.JsonReader) CoreIoException(org.sbolstandard.core.io.CoreIoException)

Example 2 with CoreIoException

use of org.sbolstandard.core.io.CoreIoException in project libSBOLj by SynBioDex.

the class SBOLReader method readRDF.

/**
 * @param reader
 * @return
 * @throws SBOLValidationException if either of the following SBOL validation rules was violated: 10105, 10201.
 */
private static DocumentRoot<QName> readRDF(Reader reader) throws SBOLValidationException {
    try {
        XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(reader);
        RdfIo rdfIo = new RdfIo();
        return rdfIo.createIoReader(xmlReader).read();
    } catch (FactoryConfigurationError e) {
        throw new SBOLValidationException("sbol-10105", e);
    } catch (XMLStreamException e) {
        throw new SBOLValidationException("sbol-10105", e);
    } catch (CoreIoException e) {
        throw new SBOLValidationException("sbol-10105", e);
    } catch (ClassCastException e) {
        if (e.getMessage().contains("IdentifiableDocument")) {
            throw new SBOLValidationException("sbol-10201", e);
        }
        throw new SBOLValidationException("sbol-10105", e);
    } catch (IllegalArgumentException e) {
        if (e.getCause() instanceof URISyntaxException) {
            throw new SBOLValidationException("sbol-10201", e);
        }
        throw new SBOLValidationException("sbol-10105", e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) RdfIo(org.sbolstandard.core.io.rdf.RdfIo) URISyntaxException(java.net.URISyntaxException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError) CoreIoException(org.sbolstandard.core.io.CoreIoException)

Aggregations

CoreIoException (org.sbolstandard.core.io.CoreIoException)2 URISyntaxException (java.net.URISyntaxException)1 JsonReader (javax.json.JsonReader)1 FactoryConfigurationError (javax.xml.stream.FactoryConfigurationError)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 JsonIo (org.sbolstandard.core.io.json.JsonIo)1 RdfIo (org.sbolstandard.core.io.rdf.RdfIo)1