Object oid = null;
try {
oid = oidClass.newInstance();
} catch (Exception e) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.statemanager.cantnewoid", oidClass.getName()), e); // NOI18N
}
Field keyFields[] = foreignConfig.getKeyFields();
String keyFieldNames[] = foreignConfig.getKeyFieldNames();
for (int i = 0; i < keyFields.length && oid != null; i++) {
Field keyField = keyFields[i];
for (int j = 0; j < foreignFields.size() && oid != null; j++) {
LocalFieldDesc fa = (LocalFieldDesc) foreignFields.get(j);
if (fa.getName().compareTo(keyFieldNames[i]) == 0) {
LocalFieldDesc la = (LocalFieldDesc) localFields.get(j);
Object keyFieldValue = null;
if (la == fieldDesc) {
keyFieldValue = value;
} else if (sm.getSetMaskBit(la.absoluteID) && !sm.getSetMaskBit(absoluteID)) {
keyFieldValue = la.getValue(sm.getBeforeImage());
} else {
keyFieldValue = la.getValue(sm);
}
if (keyFieldValue != null) {
try {
// We need to convert the keyFieldValue to the proper type before
// setting it.
keyField.set(oid, fa.convertValue(keyFieldValue, sm));
} catch (IllegalAccessException e) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages,
"core.statemanager.cantsetkeyfield", keyField.getName()), e); // NOI18N
}
} else {
oid = null;
}