if (requestObjectCache.isCached(path))
{
return requestObjectCache.getObject(path);
}
ClassDescriptor classDescriptor = getClassDescriptor(clazz);
checkNodeType(session, classDescriptor);
Node node = session.getNode(path);
if (!classDescriptor.isInterface()) {
node = getActualNode(session,node);
checkCompatiblePrimaryNodeTypes(session, node, classDescriptor, true);
}
ClassDescriptor alternativeDescriptor = null;
if (classDescriptor.usesNodeTypePerHierarchyStrategy()) {
if (node.hasProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY)) {
String className = node.getProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY).getValue().getString();
alternativeDescriptor = getClassDescriptor(ReflectionUtils.forName(className));
}
} else {
if (classDescriptor.usesNodeTypePerConcreteClassStrategy()) {
String nodeType = node.getPrimaryNodeType().getName();
if (!nodeType.equals(classDescriptor.getJcrType())) {
alternativeDescriptor = classDescriptor.getDescendantClassDescriptor(nodeType);
// in case we an alternative could not be found by walking
// the class descriptor hierarchy, check whether we would
// have a descriptor for the node type directly (which
// may the case if the class descriptor hierarchy is
// incomplete due to missing configuration. See JCR-1145
// for details.
if (alternativeDescriptor == null) {
alternativeDescriptor = mapper.getClassDescriptorByNodeType(nodeType);
}
}
}
}
// if we have an alternative class descriptor, check whether its
// extends (or is the same) as the requested class.
if (alternativeDescriptor != null) {
Class alternativeClazz = ReflectionUtils.forName(alternativeDescriptor.getClassName());
if (clazz.isAssignableFrom(alternativeClazz)) {
clazz = alternativeClazz;
classDescriptor = alternativeDescriptor;
}
}