Search in sources :

Example 71 with Unmarshaller

use of javax.xml.bind.Unmarshaller 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_rc2.NotificationPermission) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 72 with Unmarshaller

use of javax.xml.bind.Unmarshaller 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 73 with Unmarshaller

use of javax.xml.bind.Unmarshaller 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 74 with Unmarshaller

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

Example 75 with Unmarshaller

use of javax.xml.bind.Unmarshaller in project opennms by OpenNMS.

the class JaxbUtilsUnmarshalProcessor method process.

/**
	 * Make sure that this method is fast because it is used to deserialize
	 * JMS messages.
	 */
@Override
public void process(final Exchange exchange) throws Exception {
    Unmarshaller unmarshaller = m_unmarshaller.get();
    if (unmarshaller == null) {
        unmarshaller = JaxbUtils.getUnmarshallerFor(m_class, null, false);
        m_unmarshaller.set(unmarshaller);
    }
    // Super slow
    //final String object = exchange.getIn().getBody(String.class);
    //exchange.getIn().setBody(JaxbUtils.unmarshal(m_class, object), m_class);
    // Faster
    //final InputStream object = exchange.getIn().getBody(InputStream.class);
    //exchange.getIn().setBody(unmarshaller.unmarshal(new StreamSource(object)));
    // Somehow, using String is marginally faster than using InputStream ¯\_(ツ)_/¯
    final String object = exchange.getIn().getBody(String.class);
    exchange.getIn().setBody(m_class.cast(unmarshaller.unmarshal(new StringReader(object))));
}
Also used : StringReader(java.io.StringReader) Unmarshaller(javax.xml.bind.Unmarshaller)

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