Search in sources :

Example 46 with Unmarshaller

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

the class ValidateV2SamplesTest 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)

Example 47 with Unmarshaller

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

the class JpaJaxbOtherNameAdapterTest method getOtherName.

private OtherName getOtherName() throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(new Class[] { OtherName.class });
    Unmarshaller unmarshaller = context.createUnmarshaller();
    String name = "/record_2.0/samples/read_samples/other-name-2.0.xml";
    InputStream inputStream = getClass().getResourceAsStream(name);
    return (OtherName) unmarshaller.unmarshal(inputStream);
}
Also used : InputStream(java.io.InputStream) OtherName(org.orcid.jaxb.model.record_v2.OtherName) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 48 with Unmarshaller

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

the class JpaJaxbExternalIdentifierAdapterTest method getExternalIdentifier.

private PersonExternalIdentifier getExternalIdentifier() throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(new Class[] { PersonExternalIdentifier.class });
    Unmarshaller unmarshaller = context.createUnmarshaller();
    String name = "/record_2.0/samples/read_samples/external-identifier-2.0.xml";
    InputStream inputStream = getClass().getResourceAsStream(name);
    return (PersonExternalIdentifier) unmarshaller.unmarshal(inputStream);
}
Also used : InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)

Example 49 with Unmarshaller

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

the class JpaJaxbEmploymentAdapterTest method getEmployment.

private Employment getEmployment(boolean full) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(new Class[] { Employment.class });
    Unmarshaller unmarshaller = context.createUnmarshaller();
    String name = "/record_2.0/samples/read_samples/employment-2.0.xml";
    if (full) {
        name = "/record_2.0/samples/read_samples/employment-full-2.0.xml";
    }
    InputStream inputStream = getClass().getResourceAsStream(name);
    return (Employment) unmarshaller.unmarshal(inputStream);
}
Also used : Employment(org.orcid.jaxb.model.record_v2.Employment) InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 50 with Unmarshaller

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

the class ConvertV2ToV2_1Test method upgradePeerReviewsToV21Test.

@Test
public void upgradePeerReviewsToV21Test() throws JAXBException {
    JAXBContext jaxbContext1 = JAXBContext.newInstance(PeerReviews.class);
    JAXBContext jaxbContext2 = JAXBContext.newInstance(PeerReviews.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext1.createUnmarshaller();
    InputStream v20Stream = ConvertV2ToV2_1Test.class.getClassLoader().getResourceAsStream("test-peer-reviews-2.0.xml");
    InputStream v21Stream = ConvertV2ToV2_1Test.class.getClassLoader().getResourceAsStream("test-peer-reviews-2.1.xml");
    PeerReviews v20PeerReviews = (PeerReviews) jaxbUnmarshaller.unmarshal(v20Stream);
    jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
    PeerReviews v21PeerReviews1 = (PeerReviews) jaxbUnmarshaller.unmarshal(v21Stream);
    V2Convertible result = versionConverterV2_0ToV2_1.upgrade(new V2Convertible(v20PeerReviews, "v2.1"));
    PeerReviews v21PeerReviews2 = (PeerReviews) result.getObjectToConvert();
    assertEquals(v21PeerReviews1, v21PeerReviews2);
}
Also used : V2Convertible(org.orcid.core.version.V2Convertible) InputStream(java.io.InputStream) PeerReviews(org.orcid.jaxb.model.record.summary_v2.PeerReviews) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

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