Search in sources :

Example 1 with JAXBTypeElement

use of org.eclipse.persistence.jaxb.JAXBTypeElement in project metro-jax-ws by eclipse-ee4j.

the class JAXBBond method marshal.

// TODO NamespaceContext nsContext
@Override
public void marshal(T object, OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException {
    JAXBMarshaller marshaller = null;
    try {
        marshaller = parent.mpool.allocate();
        marshaller.setAttachmentMarshaller(am);
        marshaller.setProperty(jakarta.xml.bind.Marshaller.JAXB_FRAGMENT, true);
        if (mappingInfo != null) {
            if (isParameterizedType) {
                JAXBTypeElement jte = new JAXBTypeElement(mappingInfo.getXmlTagName(), object, (ParameterizedType) mappingInfo.getType());
                marshaller.marshal(jte, new StreamResult(output), mappingInfo);
            } else {
                JAXBElement<T> elt = new JAXBElement<>(mappingInfo.getXmlTagName(), (Class<T>) mappingInfo.getType(), object);
                // marshaller.marshal(elt, output);
                // GAG missing
                marshaller.marshal(elt, new StreamResult(output), mappingInfo);
            }
        } else {
            marshaller.marshal(object, output);
        }
    } finally {
        if (marshaller != null) {
            marshaller.setAttachmentMarshaller(null);
            parent.mpool.replace(marshaller);
        }
    }
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) JAXBTypeElement(org.eclipse.persistence.jaxb.JAXBTypeElement) JAXBElement(jakarta.xml.bind.JAXBElement) JAXBMarshaller(org.eclipse.persistence.jaxb.JAXBMarshaller)

Example 2 with JAXBTypeElement

use of org.eclipse.persistence.jaxb.JAXBTypeElement in project metro-jax-ws by eclipse-ee4j.

the class JAXBBond method marshal.

@Override
public void marshal(T object, Node output) throws JAXBException {
    JAXBMarshaller marshaller = null;
    try {
        marshaller = parent.mpool.allocate();
        // marshaller.setAttachmentMarshaller(am);
        marshaller.setProperty(jakarta.xml.bind.Marshaller.JAXB_FRAGMENT, true);
        if (mappingInfo != null) {
            if (isParameterizedType) {
                JAXBTypeElement jte = new JAXBTypeElement(mappingInfo.getXmlTagName(), object, (ParameterizedType) mappingInfo.getType());
                marshaller.marshal(jte, new DOMResult(output), mappingInfo);
            } else {
                JAXBElement<T> elt = new JAXBElement<>(mappingInfo.getXmlTagName(), (Class<T>) mappingInfo.getType(), object);
                // marshaller.marshal(elt, output);
                marshaller.marshal(elt, new DOMResult(output), mappingInfo);
            }
        } else {
            marshaller.marshal(object, output);
        }
    } finally {
        if (marshaller != null) {
            marshaller.setAttachmentMarshaller(null);
            parent.mpool.replace(marshaller);
        }
    }
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) JAXBTypeElement(org.eclipse.persistence.jaxb.JAXBTypeElement) JAXBElement(jakarta.xml.bind.JAXBElement) JAXBMarshaller(org.eclipse.persistence.jaxb.JAXBMarshaller)

Example 3 with JAXBTypeElement

use of org.eclipse.persistence.jaxb.JAXBTypeElement in project metro-jax-ws by eclipse-ee4j.

the class JAXBBond method marshal.

@Override
public void marshal(T object, Result result) throws JAXBException {
    JAXBMarshaller marshaller = null;
    try {
        marshaller = parent.mpool.allocate();
        marshaller.setAttachmentMarshaller(null);
        marshaller.setProperty(jakarta.xml.bind.Marshaller.JAXB_FRAGMENT, true);
        if (mappingInfo != null) {
            if (isParameterizedType) {
                JAXBTypeElement jte = new JAXBTypeElement(mappingInfo.getXmlTagName(), object, (ParameterizedType) mappingInfo.getType());
                marshaller.marshal(jte, result, mappingInfo);
            } else {
                JAXBElement<T> elt = new JAXBElement<>(mappingInfo.getXmlTagName(), (Class<T>) mappingInfo.getType(), object);
                // marshaller.marshal(elt, result);
                marshaller.marshal(elt, result, mappingInfo);
            }
        } else {
            TypeMappingInfo tmi = null;
            if (object instanceof JAXBElement) {
                QName q = ((JAXBElement) object).getName();
                JAXBContext ctx = (JAXBContext) parent.getJAXBContext();
                Map<TypeMappingInfo, QName> mtq = ctx.getTypeMappingInfoToSchemaType();
                for (Map.Entry<TypeMappingInfo, QName> es : mtq.entrySet()) {
                    if (q.equals(es.getValue())) {
                        tmi = es.getKey();
                        break;
                    }
                }
            }
            if (tmi != null) {
                marshaller.marshal(object, result, tmi);
            } else {
                marshaller.marshal(object, result);
            }
        }
    } finally {
        if (marshaller != null) {
            marshaller.setAttachmentMarshaller(null);
            parent.mpool.replace(marshaller);
        }
    }
}
Also used : JAXBTypeElement(org.eclipse.persistence.jaxb.JAXBTypeElement) QName(javax.xml.namespace.QName) JAXBContext(org.eclipse.persistence.jaxb.JAXBContext) JAXBElement(jakarta.xml.bind.JAXBElement) JAXBMarshaller(org.eclipse.persistence.jaxb.JAXBMarshaller) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo) Map(java.util.Map)

Example 4 with JAXBTypeElement

use of org.eclipse.persistence.jaxb.JAXBTypeElement in project metro-jax-ws by eclipse-ee4j.

the class JAXBBond method marshal.

@Override
public void marshal(T object, ContentHandler contentHandler, AttachmentMarshaller am) throws JAXBException {
    JAXBMarshaller marshaller = null;
    try {
        marshaller = parent.mpool.allocate();
        marshaller.setAttachmentMarshaller(am);
        marshaller.setProperty(jakarta.xml.bind.Marshaller.JAXB_FRAGMENT, true);
        if (mappingInfo != null) {
            if (isParameterizedType) {
                JAXBTypeElement jte = new JAXBTypeElement(mappingInfo.getXmlTagName(), object, (ParameterizedType) mappingInfo.getType());
                marshaller.marshal(jte, new SAXResult(contentHandler), mappingInfo);
            } else {
                JAXBElement<T> elt = new JAXBElement<>(mappingInfo.getXmlTagName(), (Class<T>) mappingInfo.getType(), object);
                // marshaller.marshal(elt, contentHandler);
                // GAG missing
                marshaller.marshal(elt, new SAXResult(contentHandler), mappingInfo);
            // marshaller.marshal(elt, contentHandler, mappingInfo);
            }
        } else {
            marshaller.marshal(object, contentHandler);
        }
    } finally {
        if (marshaller != null) {
            marshaller.setAttachmentMarshaller(null);
            parent.mpool.replace(marshaller);
        }
    }
}
Also used : SAXResult(javax.xml.transform.sax.SAXResult) JAXBTypeElement(org.eclipse.persistence.jaxb.JAXBTypeElement) JAXBElement(jakarta.xml.bind.JAXBElement) JAXBMarshaller(org.eclipse.persistence.jaxb.JAXBMarshaller)

Example 5 with JAXBTypeElement

use of org.eclipse.persistence.jaxb.JAXBTypeElement in project metro-jax-ws by eclipse-ee4j.

the class JAXBBond method marshal.

@Override
public void marshal(T object, XMLStreamWriter output, AttachmentMarshaller am) throws JAXBException {
    JAXBMarshaller marshaller = null;
    try {
        marshaller = parent.mpool.allocate();
        marshaller.setAttachmentMarshaller(am);
        marshaller.setProperty(jakarta.xml.bind.Marshaller.JAXB_FRAGMENT, true);
        boolean isEx = (output instanceof XMLStreamWriterEx);
        if (mappingInfo != null) {
            if (isParameterizedType) {
                JAXBTypeElement jte = new JAXBTypeElement(mappingInfo.getXmlTagName(), object, (ParameterizedType) mappingInfo.getType());
                if (isEx) {
                    marshaller.marshal(jte, new NewStreamWriterRecord((XMLStreamWriterEx) output), mappingInfo);
                } else {
                    marshaller.marshal(jte, output, mappingInfo);
                }
            } else {
                JAXBElement<T> elt = new JAXBElement<>(mappingInfo.getXmlTagName(), (Class<T>) typeInfo.type, object);
                if (isEx) {
                    marshaller.marshal(elt, new NewStreamWriterRecord((XMLStreamWriterEx) output), mappingInfo);
                } else {
                    marshaller.marshal(elt, output, mappingInfo);
                }
            }
        } else {
            if (isEx) {
                marshaller.marshal(object, new NewStreamWriterRecord((XMLStreamWriterEx) output));
            } else {
                marshaller.marshal(object, output);
            }
        }
    } finally {
        if (marshaller != null) {
            marshaller.setAttachmentMarshaller(null);
            parent.mpool.replace(marshaller);
        }
    }
}
Also used : JAXBTypeElement(org.eclipse.persistence.jaxb.JAXBTypeElement) XMLStreamWriterEx(org.jvnet.staxex.XMLStreamWriterEx) JAXBElement(jakarta.xml.bind.JAXBElement) JAXBMarshaller(org.eclipse.persistence.jaxb.JAXBMarshaller)

Aggregations

JAXBElement (jakarta.xml.bind.JAXBElement)5 JAXBMarshaller (org.eclipse.persistence.jaxb.JAXBMarshaller)5 JAXBTypeElement (org.eclipse.persistence.jaxb.JAXBTypeElement)5 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 DOMResult (javax.xml.transform.dom.DOMResult)1 SAXResult (javax.xml.transform.sax.SAXResult)1 StreamResult (javax.xml.transform.stream.StreamResult)1 JAXBContext (org.eclipse.persistence.jaxb.JAXBContext)1 TypeMappingInfo (org.eclipse.persistence.jaxb.TypeMappingInfo)1 XMLStreamWriterEx (org.jvnet.staxex.XMLStreamWriterEx)1