if (value == null)
{
return -1;
}
ClassLoaderResolver clr = ec.getClassLoaderResolver();
// Find the appropriate mapping
for (int i=0; i<javaTypeMappings.length; i++)
{
Class cls = clr.classForName(javaTypeMappings[i].getType());
if (cls.isAssignableFrom(value.getClass()))
{
return i;
}
}
// PERSISTENT INTERFACE : allow for the value (impl) not be directly assignable from the superclass impl
// e.g If we have interface "Base" with impl "BaseImpl", and sub-interface "Sub1" with impl "Sub1Impl"
// So if the mapping is of type BaseImpl and the value is Sub1Impl then they don't come up as "assignable"
// but they are
Class mappingJavaType = null;
MetaDataManager mmgr = ec.getStoreManager().getNucleusContext().getMetaDataManager();
boolean isPersistentInterface = mmgr.isPersistentInterface(getType());
if (isPersistentInterface)
{
// Field is declared as a "persistent-interface" type so all impls of that type should match
mappingJavaType = clr.classForName(getType());
}
else if (mmd != null && mmd.getFieldTypes() != null && mmd.getFieldTypes().length == 1)
{
isPersistentInterface = mmgr.isPersistentInterface(mmd.getFieldTypes()[0]);
if (isPersistentInterface)
{
// Field is declared as interface and accepts "persistent-interface" value, so all impls should match
mappingJavaType = clr.classForName(mmd.getFieldTypes()[0]);
}
}
if (mappingJavaType != null && mappingJavaType.isAssignableFrom(value.getClass()))
{
return -2; // Persistent interface persistable in all mappings. Should only be 1 anyway