public void writeObject(Object object, MessageWriter writer,
Context context) throws DatabindingException {
// add the content type attribute even if we are going to fall back.
String contentType = getContentType(object, context);
if (contentType != null && useXmimeBinaryType) {
MessageWriter ctWriter = writer.getAttributeWriter(XML_MIME_CONTENT_TYPE);
ctWriter.writeValue(contentType);
}
if (!context.isMtomEnabled()) {
fallbackDelegate.writeObject(getBytes(object), writer, context);
return;
}
Collection<Attachment> attachments = context.getAttachments();
if (attachments == null) {
attachments = new ArrayList<Attachment>();
context.setAttachments(attachments);
}
String id = AttachmentUtil.createContentID(getSchemaType().getNamespaceURI());
Attachment att = createAttachment(object, id);
attachments.add(att);
MessageWriter include = writer.getElementWriter(XOP_INCLUDE);
MessageWriter href = include.getAttributeWriter(XOP_HREF);
href.writeValue("cid:" + id);
include.close();
}