}
return mapping;
}
public XMLBinaryDataMapping generateBinaryMapping(Property property, XMLDescriptor descriptor, NamespaceInfo namespaceInfo) {
XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
mapping.setAttributeName(property.getPropertyName());
// handle read-only set via metadata
if (property.isSetReadOnly()) {
mapping.setIsReadOnly(property.isReadOnly());
}
// handle write-only set via metadata
if (property.isSetWriteOnly()) {
mapping.setIsWriteOnly(property.isWriteOnly());
}
if (property.isMethodProperty()) {
if (property.getGetMethodName() == null) {
// handle case of set with no get method
String paramTypeAsString = property.getType().getName();
mapping.setAttributeAccessor(new JAXBSetMethodAttributeAccessor(paramTypeAsString, helper.getClassLoader()));
mapping.setIsReadOnly(true);
mapping.setSetMethodName(property.getSetMethodName());
} else if (property.getSetMethodName() == null) {
mapping.setGetMethodName(property.getGetMethodName());
mapping.setIsWriteOnly(true);
} else {
mapping.setSetMethodName(property.getSetMethodName());
mapping.setGetMethodName(property.getGetMethodName());
}
}
// if the XPath is set (via xml-path) use it
mapping.setField(getXPathForField(property, namespaceInfo, false));
if (property.isSwaAttachmentRef()) {
((XMLField) mapping.getField()).setSchemaType(XMLConstants.SWA_REF_QNAME);
mapping.setSwaRef(true);
} else if (property.isMtomAttachment()) {
XMLField f = ((XMLField) mapping.getField());
if (!f.getSchemaType().equals(XMLConstants.HEX_BINARY_QNAME)) {
f.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
}
}
if (property.isInlineBinaryData()) {
mapping.setShouldInlineBinaryData(true);
}
// use a non-dynamic implementation of MimeTypePolicy to wrap the MIME string
if (property.getMimeType() != null) {
mapping.setMimeTypePolicy(new FixedMimeTypePolicy(property.getMimeType(), mapping));
} else {
if(areEquals(property.getType(), javax.xml.transform.Source.class)) {
mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/xml", mapping));
} else if(areEquals(property.getType(), java.awt.Image.class)) {
mapping.setMimeTypePolicy(new FixedMimeTypePolicy("image/png", mapping));
} else {
mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/octet-stream", mapping));
}
}
if (property.isSetNullPolicy()) {
mapping.setNullPolicy(getNullPolicyFromProperty(property, namespaceInfo.getNamespaceResolverForDescriptor()));
} else {
if (property.isNillable()){
mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
mapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
}
mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
if (!mapping.getXPath().equals("text()")) {
((NullPolicy) mapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
}
}
mapping.setAttributeClassificationName(property.getActualType().getQualifiedName());
return mapping;
}