protected static void validateLink(final OProperty p, final Object fieldValue) {
if (fieldValue == null)
throw new OValidationException("The field '" + p.getFullName() + "' has been declared as " + p.getType()
+ " but contains a null record (probably a deleted record?)");
final ORecord linkedRecord;
if (fieldValue instanceof OIdentifiable)
linkedRecord = ((OIdentifiable) fieldValue).getRecord();
else if (fieldValue instanceof String)
linkedRecord = new ORecordId((String) fieldValue).getRecord();
else
throw new OValidationException("The field '" + p.getFullName() + "' has been declared as " + p.getType()
+ " but the value is not a record or a record-id");
if (linkedRecord != null && p.getLinkedClass() != null) {
if (!(linkedRecord instanceof ODocument))
throw new OValidationException("The field '" + p.getFullName() + "' has been declared as " + p.getType() + " of type '"
+ p.getLinkedClass() + "' but the value is the record " + linkedRecord.getIdentity() + " that is not a document");
final ODocument doc = (ODocument) linkedRecord;
// AT THIS POINT CHECK THE CLASS ONLY IF != NULL BECAUSE IN CASE OF GRAPHS THE RECORD COULD BE PARTIAL
if (doc.getSchemaClass() != null && !p.getLinkedClass().isSuperClassOf(doc.getSchemaClass()))
throw new OValidationException("The field '" + p.getFullName() + "' has been declared as " + p.getType() + " of type '"
+ p.getLinkedClass().getName() + "' but the value is the document " + linkedRecord.getIdentity() + " of class '"
+ doc.getSchemaClass() + "'");
}
}