return mapping;
}
public DirectMapping generateDirectMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo) {
DirectMapping mapping = new XMLDirectMapping();
mapping.setNullValueMarshalled(true);
String fixedValue = property.getFixedValue();
if (fixedValue != null) {
mapping.setIsWriteOnly(true);
}
initializeXMLMapping((XMLMapping)mapping, property);
// 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;
String targetClass = null;
if (property.isSetXmlJavaTypeAdapter()) {
theClass = property.getOriginalType().getQualifiedName();
targetClass = property.getType().getQualifiedName();
} else {
theClass = property.getType().getQualifiedName();
}
// Try to get the actual Class
try {
JavaClass actualJavaClass = helper.getJavaClass(theClass);
Class actualClass = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(actualJavaClass.getQualifiedName(), helper.getClassLoader());
mapping.setAttributeClassification(actualClass);
if(targetClass != null) {
Class fieldClass = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(targetClass, helper.getClassLoader());
mapping.getField().setType(fieldClass);
}
} 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;
}