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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations