return mapping;
}
public DirectMapping generateDirectMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo) {
DirectMapping mapping = new XMLDirectMapping();
mapping.setNullValueMarshalled(true);
mapping.setAttributeName(property.getPropertyName());
String fixedValue = property.getFixedValue();
if (fixedValue != null) {
mapping.setIsWriteOnly(true);
}
// 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; otherwise figure it out
Field xmlField = getXPathForField(property, namespaceInfo, true, false);
mapping.setField(xmlField);
if (property.getDefaultValue() != null) {
mapping.setNullValue(property.getDefaultValue());
}
if (property.isXmlId()) {
mapping.setCollapsingStringValues(true);
}
// handle null policy set via xml metadata
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);
}
}
if (property.isRequired()) {
((Field) mapping.getField()).setRequired(true);
}
if (property.getType() != null) {
String theClass = null;
if (property.isSetXmlJavaTypeAdapter()) {
theClass = property.getOriginalType().getQualifiedName();
} else {
theClass = property.getType().getQualifiedName();
}
// Try to get the actual Class
try {
JavaClass actualJavaClass = helper.getJavaClass(theClass);
Class actualClass = helper.getClassForJavaClass(actualJavaClass);
mapping.setAttributeClassification(actualClass);
} catch (Exception e) {
// Couldn't find Class (Dynamic?), so set class name instead.
mapping.setAttributeClassificationName(theClass);
}
}
if (Constants.QNAME_QNAME.equals(property.getSchemaType())){
((Field) mapping.getField()).setSchemaType(Constants.QNAME_QNAME);
}
// handle cdata set via metadata
if (property.isSetCdata()) {
mapping.setIsCDATA(property.isCdata());
}
return mapping;
}