Search in sources :

Example 1 with JAXBRIContext

use of org.glassfish.jaxb.runtime.api.JAXBRIContext in project metro-jax-ws by eclipse-ee4j.

the class JAXBTest method testJAXBElementMarshalling.

public void testJAXBElementMarshalling() throws Exception {
    JAXBRIContext jc = (JAXBRIContext) JAXBContext.newInstance(whitebox.jaxb.client.DetailType.class);
    DetailType dt = new DetailType();
    SOAPFault sf = createFault();
    dt.getDetails().add(sf.getDetail());
    Marshaller m = jc.createMarshaller();
    m.marshal(dt, System.out);
    XMLStreamBufferResult sbr = new XMLStreamBufferResult();
    m.setProperty(Marshaller.JAXB_FRAGMENT, true);
    m.marshal(dt, sbr);
    XMLStreamBuffer infoset = sbr.getXMLStreamBuffer();
    XMLStreamReader reader = infoset.readAsXMLStreamReader();
    if (reader.getEventType() == START_DOCUMENT)
        XMLStreamReaderUtil.nextElementContent(reader);
    verifyDetail(reader);
}
Also used : Marshaller(jakarta.xml.bind.Marshaller) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamBuffer(com.sun.xml.stream.buffer.XMLStreamBuffer) SOAPFault(jakarta.xml.soap.SOAPFault) XMLStreamBufferResult(com.sun.xml.stream.buffer.XMLStreamBufferResult) JAXBRIContext(org.glassfish.jaxb.runtime.api.JAXBRIContext)

Example 2 with JAXBRIContext

use of org.glassfish.jaxb.runtime.api.JAXBRIContext in project jaxb-ri by eclipse-ee4j.

the class CompositeStructureTest method test1.

// this annotation is just so that we can pass it to tr4.
@XmlJavaTypeAdapter(HexBinaryAdapter.class)
public void test1() throws Exception {
    TypeReference tr1 = new TypeReference(new QName("", "foo"), String.class);
    TypeReference tr2 = new TypeReference(new QName("", "bar"), int.class);
    TypeReference tr3 = new TypeReference(new QName("", "zot"), byte[].class);
    TypeReference tr4 = new TypeReference(new QName("", "zoo"), byte[].class, this.getClass().getMethod("test1").getAnnotation(XmlJavaTypeAdapter.class));
    JAXBRIContext c = JAXBRIContext.newInstance(new Class[0], Arrays.asList(tr1, tr2, tr3, tr4), "", false);
    CompositeStructure cs = new CompositeStructure();
    cs.bridges = new Bridge[] { c.createBridge(tr1), c.createBridge(tr2), c.createBridge(tr3), c.createBridge(tr4) };
    cs.values = new Object[] { "foo", 5, new byte[4], new byte[4] };
    JAXBElement<CompositeStructure> root = new JAXBElement<>(new QName("", "root"), CompositeStructure.class, cs);
    StringWriter sw = new StringWriter();
    c.createMarshaller().marshal(root, System.out);
    c.createMarshaller().marshal(root, sw);
    assertTrue(sw.toString().contains("<root><foo>foo</foo><bar>5</bar><zot>AAAAAA==</zot><zoo>00000000</zoo></root>"));
}
Also used : CompositeStructure(org.glassfish.jaxb.runtime.api.CompositeStructure) StringWriter(java.io.StringWriter) QName(javax.xml.namespace.QName) XmlJavaTypeAdapter(jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter) TypeReference(org.glassfish.jaxb.runtime.api.TypeReference) JAXBElement(jakarta.xml.bind.JAXBElement) JAXBRIContext(org.glassfish.jaxb.runtime.api.JAXBRIContext) XmlJavaTypeAdapter(jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter)

Example 3 with JAXBRIContext

use of org.glassfish.jaxb.runtime.api.JAXBRIContext in project metro-jax-ws by eclipse-ee4j.

the class JAXBRIContextFactory method newContext.

@Override
public BindingContext newContext(BindingInfo bi) {
    Class[] classes = bi.contentClasses().toArray(new Class[0]);
    for (int i = 0; i < classes.length; i++) {
        if (WrapperComposite.class.equals(classes[i])) {
            classes[i] = CompositeStructure.class;
        }
    }
    Map<TypeInfo, TypeReference> typeInfoMappings = typeInfoMappings(bi.typeInfos());
    Map<Class, Class> subclassReplacements = bi.subclassReplacements();
    String defaultNamespaceRemap = bi.getDefaultNamespace();
    Boolean c14nSupport = (Boolean) bi.properties().get("c14nSupport");
    RuntimeAnnotationReader ar = (RuntimeAnnotationReader) bi.properties().get("org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader");
    JAXBContextFactory jaxbContextFactory = (JAXBContextFactory) bi.properties().get(JAXBContextFactory.class.getName());
    try {
        JAXBRIContext context = (jaxbContextFactory != null) ? jaxbContextFactory.createJAXBContext(bi.getSEIModel(), toList(classes), toList(typeInfoMappings.values())) : ContextFactory.createContext(classes, typeInfoMappings.values(), subclassReplacements, defaultNamespaceRemap, (c14nSupport != null) ? c14nSupport : false, ar, false, false, false);
        return new JAXBRIContextWrapper(context, typeInfoMappings);
    } catch (Exception e) {
        throw new DatabindingException(e);
    }
}
Also used : TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) JAXBRIContext(org.glassfish.jaxb.runtime.api.JAXBRIContext) DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) RuntimeAnnotationReader(org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader) JAXBContextFactory(com.sun.xml.ws.developer.JAXBContextFactory) TypeReference(org.glassfish.jaxb.runtime.api.TypeReference)

Aggregations

JAXBRIContext (org.glassfish.jaxb.runtime.api.JAXBRIContext)3 TypeReference (org.glassfish.jaxb.runtime.api.TypeReference)2 XMLStreamBuffer (com.sun.xml.stream.buffer.XMLStreamBuffer)1 XMLStreamBufferResult (com.sun.xml.stream.buffer.XMLStreamBufferResult)1 JAXBContextFactory (com.sun.xml.ws.developer.JAXBContextFactory)1 DatabindingException (com.sun.xml.ws.spi.db.DatabindingException)1 TypeInfo (com.sun.xml.ws.spi.db.TypeInfo)1 JAXBElement (jakarta.xml.bind.JAXBElement)1 Marshaller (jakarta.xml.bind.Marshaller)1 XmlJavaTypeAdapter (jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter)1 SOAPFault (jakarta.xml.soap.SOAPFault)1 StringWriter (java.io.StringWriter)1 QName (javax.xml.namespace.QName)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 CompositeStructure (org.glassfish.jaxb.runtime.api.CompositeStructure)1 RuntimeAnnotationReader (org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader)1