Search in sources :

Example 41 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.

the class BlackBoxBaseRC3 method unmarshall.

public Object unmarshall(Reader reader, Class<?> type) {
    try {
        JAXBContext context = JAXBContext.newInstance(type);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        return unmarshaller.unmarshal(reader);
    } catch (JAXBException e) {
        throw new RuntimeException("Unable to unmarshall orcid message" + e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 42 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.

the class OrcidRecordToSolrDocumentTest method getRecord.

private Record getRecord(String name) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(Record.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    InputStream inputStream = this.getClass().getResourceAsStream(name);
    return (Record) unmarshaller.unmarshal(inputStream);
}
Also used : InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) Record(org.orcid.jaxb.model.record_v2.Record) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 43 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.

the class OrcidClientGroup method unmarshall.

public static OrcidClientGroup unmarshall(InputStream input) {
    try {
        JAXBContext context = JAXBContext.newInstance(OrcidClientGroup.class.getPackage().getName());
        Unmarshaller unmarshaller = context.createUnmarshaller();
        return (OrcidClientGroup) unmarshaller.unmarshal(input);
    } catch (JAXBException e) {
        // XXX Should be more specific exception
        throw new RuntimeException("Unable to unmarshall client group" + e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 44 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.

the class OrcidMessage method unmarshall.

public static OrcidMessage unmarshall(Reader reader) {
    try {
        JAXBContext context = JAXBContext.newInstance(OrcidMessage.class.getPackage().getName());
        Unmarshaller unmarshaller = context.createUnmarshaller();
        return (OrcidMessage) unmarshaller.unmarshal(reader);
    } catch (JAXBException e) {
        // XXX Should be more specific exception
        throw new RuntimeException("Unable to unmarshall orcid message" + e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 45 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.

the class ValidateV2_1SamplesTest method unmarshall.

private Object unmarshall(Reader reader, Class<?> type, String schemaPath) throws SAXException, URISyntaxException {
    try {
        JAXBContext context = JAXBContext.newInstance(type);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        if (schemaPath != null) {
            SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = sf.newSchema(new File(getClass().getResource(schemaPath).toURI()));
            unmarshaller.setSchema(schema);
        }
        return unmarshaller.unmarshal(reader);
    } catch (JAXBException e) {
        throw new RuntimeException("Unable to unmarshall orcid message" + e);
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Schema(javax.xml.validation.Schema) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Aggregations

Unmarshaller (javax.xml.bind.Unmarshaller)292 JAXBContext (javax.xml.bind.JAXBContext)240 JAXBException (javax.xml.bind.JAXBException)97 InputStream (java.io.InputStream)91 Test (org.junit.Test)79 StringReader (java.io.StringReader)40 BaseTest (org.orcid.core.BaseTest)39 V2Convertible (org.orcid.core.version.V2Convertible)39 File (java.io.File)33 InputSource (org.xml.sax.InputSource)22 IOException (java.io.IOException)21 JAXBElement (javax.xml.bind.JAXBElement)18 Marshaller (javax.xml.bind.Marshaller)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 SAXSource (javax.xml.transform.sax.SAXSource)17 SAXParserFactory (javax.xml.parsers.SAXParserFactory)13 XMLInputFactory (javax.xml.stream.XMLInputFactory)13 XMLStreamException (javax.xml.stream.XMLStreamException)13 XMLStreamReader (javax.xml.stream.XMLStreamReader)13 Schema (javax.xml.validation.Schema)13