in src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java [373:454]
public Object getObject(Session session, Class clazz, String path)
{
try {
if (!session.nodeExists(path)) {
return null;
}
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;
}
}
// ensure class is concrete (neither interface nor abstract)
if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
throw new JcrMappingException( "Cannot instantiate non-concrete class " + clazz.getName()
+ " for node " + path + " of type " + node.getPrimaryNodeType().getName());
}
Object object = ReflectionUtils.newInstance(classDescriptor.getClassName());
if (! requestObjectCache.isCached(path))
{
requestObjectCache.cache(path, object);
}
simpleFieldsHelp.retrieveSimpleFields(session, classDescriptor, node, object);
retrieveBeanFields(session, classDescriptor, node, object, false);
retrieveCollectionFields(session, classDescriptor, node, object, false);
return object;
} catch (PathNotFoundException pnfe) {
// HINT should never get here
throw new ObjectContentManagerException("Impossible to get the object at " + path, pnfe);
} catch (RepositoryException re) {
throw new org.apache.jackrabbit.ocm.exception.RepositoryException("Impossible to get the object at " + path, re);
}
}