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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
Aggregations