clsDesc.setMapping(classMapping);
// Obtain the Java class.
Class javaClass = resolveType(classMapping.getName());
if (!Types.isConstructable(javaClass, true)) {
throw new MappingException(
"mapping.classNotConstructable", javaClass.getName());
}
clsDesc.setJavaClass(javaClass);
// 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);
if (extDesc != null) {
if (!(extDesc.hasNature(ClassDescriptorJDONature.class.getName()))) {
throw new IllegalArgumentException(
"Extended class does not have a JDO descriptor");
}
new ClassDescriptorJDONature(extDesc).addExtended(clsDesc);
}
clsDesc.setExtends(extDesc);
// If this class depends on another class, obtain the depended class.
clsDesc.setDepends(getDepended(classMapping, javaClass));
// Create all field descriptors.
FieldDescriptorImpl[] allFields = createFieldDescriptors(classMapping, javaClass);
// Make sure there are no two fields with the same name.
checkFieldNameDuplicates(allFields, javaClass);
// Set class descriptor containing the field
for (int i = 0; i < allFields.length; i++) {
allFields[i].setContainingClassDescriptor(clsDesc);
}
// 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();
if ((idNames == null) || (idNames.length == 0)) {
// There are also no identity definitions on class.
throw new MappingException("mapping.noIdentity", javaClass.getName());
}
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 {