}
}
// now checking the type
ClassDescriptorDef ownerClassDef = (ClassDescriptorDef)refDef.getOwner();
ModelDef model = (ModelDef)ownerClassDef.getOwner();
String targetClassName = refDef.getProperty(PropertyHelper.OJB_PROPERTY_CLASS_REF);
ClassDescriptorDef targetClassDef = model.getClass(targetClassName);
if (targetClassDef == null)
{
throw new ConstraintException("The class "+targetClassName+" referenced by "+refDef.getName()+" in class "+ownerClassDef.getName()+" is unknown or not persistent");
}
if (!targetClassDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_OJB_PERSISTENT, false))
{
throw new ConstraintException("The class "+targetClassName+" referenced by "+refDef.getName()+" in class "+ownerClassDef.getName()+" is not persistent");
}
if (CHECKLEVEL_STRICT.equals(checkLevel))
{
try
{
InheritanceHelper helper = new InheritanceHelper();
if (refDef.isAnonymous())
{
// anonymous reference: class must be a baseclass of the owner class
if (!helper.isSameOrSubTypeOf(ownerClassDef, targetClassDef.getName(), true))
{
throw new ConstraintException("The class "+targetClassName+" referenced by the anonymous reference "+refDef.getName()+" in class "+ownerClassDef.getName()+" is not a basetype of the class");
}
}
else
{
// specified element class must be a subtype of the variable type (if it exists, i.e. not for anonymous references)
String varType = refDef.getProperty(PropertyHelper.OJB_PROPERTY_VARIABLE_TYPE);
boolean performCheck = true;
// but we first check whether there is a useable type for the the variable type
if (model.getClass(varType) == null)
{
try
{
InheritanceHelper.getClass(varType);
}