&& ((classMapping.getClassChoice() == null)
|| (classMapping.getClassChoice().getFieldMappingCount() == 0))
&& (classMapping.getIdentityCount() == 0)) {
// If we make it here we simply try to load a compiled mapping
try {
ClassDescriptor clsDesc =
getInternalContext()
.getXMLClassDescriptorResolver().resolve(classMapping.getName());
if (clsDesc != null) { return clsDesc; }
} catch (ResolverException e) {
if (LOG.isDebugEnabled()) {
String message =
new StringBuffer().append("Ignoring exception: ").append(e)
.append(" at resolving: ").append(classMapping.getName()).toString();
LOG.debug(message);
}
}
}
}
// Obtain the Java class.
Class javaClass = resolveType(classMapping.getName());
if (classMapping.getVerifyConstructable()) {
if (!Types.isConstructable(javaClass, true)) {
throw new MappingException(
"mapping.classNotConstructable", javaClass.getName());
}
}
xmlClassDesc.setJavaClass(javaClass);
// Obtain XML name.
String xmlName;
MapTo mapTo = classMapping.getMapTo();
if ((mapTo != null) && (mapTo.getXml() != null)) {
xmlName = mapTo.getXml();
} else {
String clsName = getInternalContext().getJavaNaming().getClassName(javaClass);
xmlName = getInternalContext().getXMLNaming().toXMLName(clsName);
}
xmlClassDesc.setXMLName(xmlName);
// If this class extends another class, we need to obtain the extended
// class and make sure this class indeed extends it.
ClassDescriptor extDesc = getExtended(classMapping, javaClass);
xmlClassDesc.setExtends((XMLClassDescriptor) extDesc);
// Create all field descriptors.
FieldDescriptorImpl[] allFields = createFieldDescriptors(classMapping, javaClass);
// Make sure there are no two fields with the same name.
checkFieldNameDuplicates(allFields, javaClass);
// Identify identity and normal fields. Note that order must be preserved.
List fieldList = new ArrayList(allFields.length);
List idList = new ArrayList();
if (extDesc == null) {
// Sort fields into 2 lists based on identity definition of field.
for (int i = 0; i < allFields.length; i++) {
if (!allFields[i].isIdentity()) {
fieldList.add(allFields[i]);
} else {
idList.add(allFields[i]);
}
}
if (idList.size() == 0) {
// Found no identities based on identity definition of field.
// Try to find identities based on identity definition on class.
String[] idNames = classMapping.getIdentity();
FieldDescriptor identity;
for (int i = 0; i < idNames.length; i++) {
identity = findIdentityByName(fieldList, idNames[i], javaClass);
if (identity != null) {
idList.add(identity);
} else {
throw new MappingException("mapping.identityMissing",
idNames[i], javaClass.getName());
}
}
}
} else {
// Add all fields of extending class to field list.
for (int i = 0; i < allFields.length; i++) { fieldList.add(allFields[i]); }
// Add identity of extended class to identity list.
if (extDesc.getIdentity() != null) { idList.add(extDesc.getIdentity()); }
// Search redefined identities in extending class.
FieldDescriptor identity;
for (int i = 0; i < idList.size(); i++) {
String idname = ((FieldDescriptor) idList.get(i)).getFieldName();