Search in sources :

Example 46 with JAXBContext

use of javax.xml.bind.JAXBContext 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 47 with JAXBContext

use of javax.xml.bind.JAXBContext 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 48 with JAXBContext

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

the class OrcidClientGroup method toString.

@Override
public String toString() {
    try {
        JAXBContext context = JAXBContext.newInstance(getClass());
        StringWriter writer = new StringWriter();
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(this, writer);
        return writer.toString();
    } catch (JAXBException e) {
        return ("Unable to unmarshal because: " + e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext)

Example 49 with JAXBContext

use of javax.xml.bind.JAXBContext 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 50 with JAXBContext

use of javax.xml.bind.JAXBContext 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)

Aggregations

JAXBContext (javax.xml.bind.JAXBContext)1150 Unmarshaller (javax.xml.bind.Unmarshaller)558 Marshaller (javax.xml.bind.Marshaller)371 JAXBException (javax.xml.bind.JAXBException)330 Test (org.junit.Test)226 File (java.io.File)161 InputStream (java.io.InputStream)150 StringWriter (java.io.StringWriter)138 IOException (java.io.IOException)105 ByteArrayOutputStream (java.io.ByteArrayOutputStream)76 StringReader (java.io.StringReader)74 StreamSource (javax.xml.transform.stream.StreamSource)73 JAXBElement (javax.xml.bind.JAXBElement)72 ArrayList (java.util.ArrayList)58 URL (java.net.URL)55 ByteArrayInputStream (java.io.ByteArrayInputStream)50 Schema (javax.xml.validation.Schema)48 SchemaFactory (javax.xml.validation.SchemaFactory)48 OutputStream (java.io.OutputStream)42 BaseTest (org.orcid.core.BaseTest)39