Search in sources :

Example 1 with JAXBResult

use of jakarta.xml.bind.util.JAXBResult in project mycore by MyCoRe-Org.

the class MCRXSL2JAXBTransformer method getJAXBObject.

private T getJAXBObject(MCRContent source, XMLReader reader, TransformerHandler transformerHandler) throws JAXBException, IOException, SAXException {
    checkContext();
    JAXBResult result = new JAXBResult(context);
    transformerHandler.setResult(result);
    // Parse the source XML, and send the parse events to the
    // TransformerHandler.
    reader.parse(source.getInputSource());
    Object parsedResult = result.getResult();
    if (parsedResult instanceof JAXBElement<?>) {
        @SuppressWarnings("unchecked") JAXBElement<T> jaxbElement = (JAXBElement<T>) parsedResult;
        return jaxbElement.getValue();
    }
    @SuppressWarnings("unchecked") T jaxbResult = (T) result.getResult();
    return jaxbResult;
}
Also used : JAXBElement(jakarta.xml.bind.JAXBElement) JAXBResult(jakarta.xml.bind.util.JAXBResult)

Example 2 with JAXBResult

use of jakarta.xml.bind.util.JAXBResult in project metro-jax-ws by eclipse-ee4j.

the class JAXBHeader method readAsJAXB.

public <T> T readAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
    try {
        JAXBResult r = new JAXBResult(unmarshaller);
        // bridge marshals a fragment, so we need to add start/endDocument by ourselves
        r.getHandler().startDocument();
        bridge.marshal(jaxbObject, r);
        r.getHandler().endDocument();
        return (T) r.getResult();
    } catch (SAXException e) {
        throw new JAXBException(e);
    }
}
Also used : JAXBException(jakarta.xml.bind.JAXBException) JAXBResult(jakarta.xml.bind.util.JAXBResult) SAXException(org.xml.sax.SAXException)

Example 3 with JAXBResult

use of jakarta.xml.bind.util.JAXBResult in project metro-jax-ws by eclipse-ee4j.

the class JAXBMessage method readPayloadAsJAXB.

@Override
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
    JAXBResult out = new JAXBResult(unmarshaller);
    // since the bridge only produces fragments, we need to fire start/end document.
    try {
        out.getHandler().startDocument();
        if (rawContext != null) {
            Marshaller m = rawContext.createMarshaller();
            m.setProperty("jaxb.fragment", Boolean.TRUE);
            m.marshal(jaxbObject, out);
        } else
            bridge.marshal(jaxbObject, out);
        out.getHandler().endDocument();
    } catch (SAXException e) {
        throw new JAXBException(e);
    }
    return (T) out.getResult();
}
Also used : Marshaller(jakarta.xml.bind.Marshaller) AttachmentMarshaller(jakarta.xml.bind.attachment.AttachmentMarshaller) JAXBException(jakarta.xml.bind.JAXBException) JAXBResult(jakarta.xml.bind.util.JAXBResult) SAXException(org.xml.sax.SAXException)

Example 4 with JAXBResult

use of jakarta.xml.bind.util.JAXBResult in project metro-jax-ws by eclipse-ee4j.

the class EprMarshalUnmarshalTester method testW3CEprMarshalling.

public void testW3CEprMarshalling() throws Exception {
    JAXBContext ctx = JAXBContext.newInstance(W3CEndpointReference.class);
    JAXBResult res = new JAXBResult(ctx);
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    builder.address("http://example.com");
    W3CEndpointReference epr = builder.build();
    // You will get the NPE
    epr.writeTo(res);
}
Also used : W3CEndpointReferenceBuilder(jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference) JAXBContext(jakarta.xml.bind.JAXBContext) JAXBResult(jakarta.xml.bind.util.JAXBResult)

Example 5 with JAXBResult

use of jakarta.xml.bind.util.JAXBResult in project metro-jax-ws by eclipse-ee4j.

the class EprMarshalUnmarshalTester method testMSEprMarshalling1.

public void testMSEprMarshalling1() throws Exception {
    JAXBContext ctx = JAXBContext.newInstance(com.sun.xml.ws.developer.MemberSubmissionEndpointReference.class);
    JAXBResult res = new JAXBResult(ctx);
    com.sun.xml.ws.developer.MemberSubmissionEndpointReference mepr = new com.sun.xml.ws.developer.MemberSubmissionEndpointReference();
    mepr.writeTo(res);
}
Also used : MemberSubmissionEndpointReference(com.sun.xml.ws.developer.MemberSubmissionEndpointReference) JAXBContext(jakarta.xml.bind.JAXBContext) MemberSubmissionEndpointReference(com.sun.xml.ws.developer.MemberSubmissionEndpointReference) JAXBResult(jakarta.xml.bind.util.JAXBResult)

Aggregations

JAXBResult (jakarta.xml.bind.util.JAXBResult)7 JAXBContext (jakarta.xml.bind.JAXBContext)4 MemberSubmissionEndpointReference (com.sun.xml.ws.developer.MemberSubmissionEndpointReference)2 JAXBException (jakarta.xml.bind.JAXBException)2 W3CEndpointReference (jakarta.xml.ws.wsaddressing.W3CEndpointReference)2 W3CEndpointReferenceBuilder (jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)2 SAXException (org.xml.sax.SAXException)2 JAXBElement (jakarta.xml.bind.JAXBElement)1 Marshaller (jakarta.xml.bind.Marshaller)1 AttachmentMarshaller (jakarta.xml.bind.attachment.AttachmentMarshaller)1