protected void discoverMappedSuperclassesAndInheritanceParents(boolean addMappedSuperclassAccessors) {
// Clear any previous discovery.
clearMappedSuperclassesAndInheritanceParents();
EntityAccessor currentEntityAccessor = this;
MetadataClass parentClass = getJavaClass().getSuperclass();
List<String> genericTypes = getJavaClass().getGenericType();
// We keep a list of potential subclass accessors to ensure they
// have their root parent descriptor set correctly.
List<EntityAccessor> subclassEntityAccessors = new ArrayList<EntityAccessor>();
subclassEntityAccessors.add(currentEntityAccessor);
if (! parentClass.isObject()) {
while (parentClass != null && ! parentClass.isObject()) {
if (getProject().hasEntity(parentClass)) {
// Our parent is an entity.
EntityAccessor parentEntityAccessor = getProject().getEntityAccessor(parentClass);
// Set the current entity's inheritance parent descriptor.
currentEntityAccessor.getDescriptor().setInheritanceParentDescriptor(parentEntityAccessor.getDescriptor());
// Update the current entity accessor.
currentEntityAccessor = parentEntityAccessor;
// Clear out any previous mapped superclasses and inheritance
// parents that were discovered. We're going to re-discover
// them now.
currentEntityAccessor.clearMappedSuperclassesAndInheritanceParents();
// If we found an entity with inheritance metadata, set the
// root descriptor on its subclasses.
if (currentEntityAccessor.hasInheritance()) {
for (EntityAccessor subclassEntityAccessor : subclassEntityAccessors) {
subclassEntityAccessor.getDescriptor().setInheritanceRootDescriptor(currentEntityAccessor.getDescriptor());
}
// Clear the subclass list, we'll keep looking but the
// inheritance strategy may have changed so we need to
// build a new list of subclasses.
subclassEntityAccessors.clear();
}
// Add the descriptor to the subclass list
subclassEntityAccessors.add(currentEntityAccessor);
} else {
// Our parent might be a mapped superclass, check and add
// as needed.
currentEntityAccessor.addPotentialMappedSuperclass(parentClass, addMappedSuperclassAccessors);
}
// Resolve any generic types from the generic parent onto the
// current entity accessor.
currentEntityAccessor.resolveGenericTypes(genericTypes, parentClass);
// Grab the generic types from the parent class.
genericTypes = parentClass.getGenericType();
// Finally, get the next parent and keep processing ...
parentClass = parentClass.getSuperclass();
}
} else {
// Resolve any generic types we have (we may be an inheritance root).
currentEntityAccessor.resolveGenericTypes(genericTypes, parentClass);
}