jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r578959 - /jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
Date Mon, 24 Sep 2007 20:45:50 GMT
Author: clombart
Date: Mon Sep 24 13:45:49 2007
New Revision: 578959

URL: http://svn.apache.org/viewvc?rev=578959&view=rev
Log:
Apply patch for JCR-1142.

Modified:
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java?rev=578959&r1=578958&r2=578959&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
(original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
Mon Sep 24 13:45:49 2007
@@ -345,27 +345,32 @@
 				checkCompatiblePrimaryNodeTypes(session, node, classDescriptor, true);
 			}
 
-			Object object = null;
+			ClassDescriptor alternativeDescriptor = null;
 			if (classDescriptor.usesNodeTypePerHierarchyStrategy()) {
-				if (!node.hasProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME)) {
-					throw new ObjectContentManagerException("Cannot fetch object of type '" + clazz.getName()
-							+ "' using NODETYPE_PER_HIERARCHY. Discriminator property is not present.");
+				if (node.hasProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME)) {
+	                String className = node.getProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME).getValue().getString();
+	                alternativeDescriptor = getClassDescriptor(ReflectionUtils.forName(className));
 				}
-
-				String className = node.getProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME).getValue().getString();
-				classDescriptor = getClassDescriptor(ReflectionUtils.forName(className));
-				object = ReflectionUtils.newInstance(className);
 			} else {
 				if (classDescriptor.usesNodeTypePerConcreteClassStrategy()) {
 					String nodeType = node.getPrimaryNodeType().getName();
 					if (!nodeType.equals(classDescriptor.getJcrType())) {
-						classDescriptor = classDescriptor.getDescendantClassDescriptor(nodeType);
+					    alternativeDescriptor = classDescriptor.getDescendantClassDescriptor(nodeType);
 					}
 				}
-				object = ReflectionUtils.newInstance(classDescriptor.getClassName());
+			}
 
+			// 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)) {
+			        classDescriptor = alternativeDescriptor;
+			    }
 			}
 			
+            Object object = ReflectionUtils.newInstance(classDescriptor.getClassName());
+            
             if (! requestObjectCache.isCached(path))
             {
 			  requestObjectCache.cache(path, object);



Mime
View raw message