}
}
@Override
public void marshal(T object, Result result) throws JAXBException {
JAXBMarshaller marshaller = null;
try {
marshaller = parent.mpool.allocate();
marshaller.setAttachmentMarshaller(null);
marshaller.setProperty(javax.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<T>(
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);
}
}
}