Search in sources :

Example 66 with JAXBContext

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

the class NotificationsTest method unmarshall.

public NotificationPermission unmarshall(Reader reader) {
    try {
        JAXBContext context = JAXBContext.newInstance(NotificationPermission.class.getPackage().getName());
        Unmarshaller unmarshaller = context.createUnmarshaller();
        return (NotificationPermission) 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) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 67 with JAXBContext

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

the class ValidateV2RC4Identifiers method unmarshall.

private 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 68 with JAXBContext

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

the class ValidateV2RC3SamplesTest method marshall.

private void marshall(Object object, String path) throws JAXBException, SAXException, URISyntaxException {
    JAXBContext context = JAXBContext.newInstance(object.getClass());
    Marshaller marshaller = context.createMarshaller();
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(new File(getClass().getResource(path).toURI()));
    marshaller.setSchema(schema);
    marshaller.marshal(object, System.out);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Marshaller(javax.xml.bind.Marshaller) Schema(javax.xml.validation.Schema) JAXBContext(javax.xml.bind.JAXBContext) File(java.io.File)

Example 69 with JAXBContext

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

the class ValidateV2RC4SamplesTest method marshall.

private void marshall(Object object, String path) throws JAXBException, SAXException, URISyntaxException {
    JAXBContext context = JAXBContext.newInstance(object.getClass());
    Marshaller marshaller = context.createMarshaller();
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(new File(getClass().getResource(path).toURI()));
    marshaller.setSchema(schema);
    marshaller.marshal(object, System.out);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Marshaller(javax.xml.bind.Marshaller) Schema(javax.xml.validation.Schema) JAXBContext(javax.xml.bind.JAXBContext) File(java.io.File)

Example 70 with JAXBContext

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

the class BaseControllerTest method getOrcidProfile.

protected static OrcidProfile getOrcidProfile() {
    try {
        JAXBContext context = JAXBContext.newInstance(OrcidMessage.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        OrcidMessage orcidMessage = (OrcidMessage) unmarshaller.unmarshal(BaseControllerTest.class.getResourceAsStream("/orcid-internal-full-message-latest.xml"));
        return orcidMessage.getOrcidProfile();
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
}
Also used : OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) 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