* @param clr ClassLoaderResolver to use for loading any key/value types
* @param primary the primary ClassLoader to use (or null)
*/
public void populate(ClassLoaderResolver clr, ClassLoader primary)
{
ApiAdapter api = getMetaDataManager().getApiAdapter();
// Check the field type and see if it is castable to a Map
Class field_type = getMemberMetaData().getType();
if (!java.util.Map.class.isAssignableFrom(field_type))
{
throw new InvalidMetaDataException(LOCALISER,
"044145",
getFieldName(),getMemberMetaData().getClassName(false));
}
// "key-type"
if (key.type == null)
{
throw new InvalidMetaDataException(LOCALISER,
"044146",
getFieldName(),getMemberMetaData().getClassName(false));
}
// Check that the key type exists
Class keyTypeClass = null;
try
{
keyTypeClass = clr.classForName(key.type, primary);
}
catch (ClassNotResolvedException cnre)
{
try
{
// Maybe the user specified a java.lang class without fully-qualifying it
// This is beyond the scope of the JDO spec which expects java.lang cases to be fully-qualified
keyTypeClass = clr.classForName(ClassUtils.getJavaLangClassForType(key.type), primary);
}
catch (ClassNotResolvedException cnre2)
{
throw new InvalidMetaDataException(LOCALISER,
"044147",
getFieldName(),getMemberMetaData().getClassName(false),
key.type);
}
}
if (!keyTypeClass.getName().equals(key.type))
{
// The value-type has been resolved from what was specified in the MetaData - update to the fully-qualified name
JPOXLogger.METADATA.info(LOCALISER.msg("044148", getFieldName(), getMemberMetaData().getClassName(false),
key.type, keyTypeClass.getName()));
key.type = keyTypeClass.getName();
}
// "embedded-key"
if (key.embedded == null)
{
// Assign default for "embedded-key" based on 18.13.2 of JDO 2 spec
if (getMetaDataManager().getOMFContext().getTypeManager().isDefaultEmbeddedType(keyTypeClass))
{
key.embedded = Boolean.TRUE;
}
else if (api.isPersistable(keyTypeClass) ||
Object.class.isAssignableFrom(keyTypeClass) ||
keyTypeClass.isInterface())
{
key.embedded = Boolean.FALSE;
}
else
{
key.embedded = Boolean.TRUE;
}
}
if (key.embedded == Boolean.FALSE)
{
// If the user has set a non-PC/non-Interface as not embedded, correct it since not supported.
// Note : this fails when using in the enhancer since not yet PC
if (!api.isPersistable(keyTypeClass) && !keyTypeClass.isInterface() &&
keyTypeClass != java.lang.Object.class)
{
key.embedded = Boolean.TRUE;
}
}
KeyMetaData keymd = ((AbstractMemberMetaData)parent).getKeyMetaData();
if (keymd != null && keymd.getEmbeddedMetaData() != null)
{
// If the user has specified <embedded>, set to true
key.embedded = Boolean.TRUE;
}
// "value-type"
if (value.type == null)
{
throw new InvalidMetaDataException(LOCALISER,
"044149",
getFieldName(),getMemberMetaData().getClassName(false));
}
// Check that the value-type exists
Class valueTypeClass = null;
try
{
valueTypeClass = clr.classForName(value.type);
}
catch (ClassNotResolvedException cnre)
{
try
{
// Maybe the user specified a java.lang class without fully-qualifying it
// This is beyond the scope of the JDO spec which expects java.lang cases to be fully-qualified
valueTypeClass = clr.classForName(ClassUtils.getJavaLangClassForType(value.type));
}
catch (ClassNotResolvedException cnre2)
{
throw new InvalidMetaDataException(LOCALISER,
"044150",
getFieldName(),getMemberMetaData().getClassName(false),
value.type);
}
}
if (!valueTypeClass.getName().equals(value.type))
{
// The value-type has been resolved from what was specified in the MetaData - update to the fully-qualified name
JPOXLogger.METADATA.info(LOCALISER.msg("044151", getFieldName(), getMemberMetaData().getClassName(false),
value.type, valueTypeClass.getName()));
value.type = valueTypeClass.getName();
}
// "embedded-value"
if (value.embedded == null)
{
// Assign default for "embedded-value" based on 18.13.2 of JDO 2 spec
if (getMetaDataManager().getOMFContext().getTypeManager().isDefaultEmbeddedType(valueTypeClass))
{
value.embedded = Boolean.TRUE;
}
else if (api.isPersistable(valueTypeClass) ||
Object.class.isAssignableFrom(valueTypeClass) ||
valueTypeClass.isInterface())
{
value.embedded = Boolean.FALSE;
}
else
{
value.embedded = Boolean.TRUE;
}
}
if (value.embedded == Boolean.FALSE)
{
// If the user has set a non-PC/non-Interface as not embedded, correct it since not supported.
// Note : this fails when using in the enhancer since not yet PC
if (!api.isPersistable(valueTypeClass) && !valueTypeClass.isInterface() &&
valueTypeClass != java.lang.Object.class)
{
value.embedded = Boolean.TRUE;
}
}