jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r636881 - in /jackrabbit/trunk/jackrabbit-ocm/src: main/java/org/apache/jackrabbit/ocm/manager/ main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ main/java/org/apache/jackrabbit/ocm/query/impl/ test/test-config/nodetypes/
Date Thu, 13 Mar 2008 20:51:05 GMT
Author: clombart
Date: Thu Mar 13 13:51:02 2008
New Revision: 636881

URL: http://svn.apache.org/viewvc?rev=636881&view=rev
Log:
Patch for JCR-1467. Now, the mixin ocm:discriminator and ocm namespace are not mandatory for
running the OCM framework.

Modified:
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/ManagerConstant.java
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/SimpleFieldsHelper.java
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/test-config/nodetypes/custom_nodetypes.xml

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/ManagerConstant.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/ManagerConstant.java?rev=636881&r1=636880&r2=636881&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/ManagerConstant.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/ManagerConstant.java
Thu Mar 13 13:51:02 2008
@@ -29,8 +29,8 @@
 {
 	public static final String NT_UNSTRUCTURED = "nt:unstructured";
 	public static final String DISCRIMINATOR_NODE_TYPE = "ocm:discriminator";
-	public static final String DISCRIMINATOR_PROPERTY_NAME = "ocm:classname";
-	
+	public static final String DISCRIMINATOR_CLASS_NAME_PROPERTY = "ocm_classname";
+
 	
 	public static final String FROZEN_NODE_TYPE = "nt:frozenNode";
 	public static final String FROZEN_PRIMARY_TYPE_PROPERTY = "jcr:frozenPrimaryType";

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java?rev=636881&r1=636880&r2=636881&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
Thu Mar 13 13:51:02 2008
@@ -24,9 +24,13 @@
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.ValueFormatException;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.version.VersionException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -202,10 +206,7 @@
 
 			// If required, add the discriminator node type
 			if (classDescriptor.hasDiscriminator()) {
-				mixinTypeName = ManagerConstant.DISCRIMINATOR_NODE_TYPE;
-				objectNode.addMixin(mixinTypeName);
-				objectNode.setProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME, ReflectionUtils.getBeanClass(object)
-						.getName());
+				addDiscriminatorProperty(object, objectNode);
 			}
 
 
@@ -222,6 +223,27 @@
 		simpleFieldsHelp.refreshUuidPath(session, classDescriptor, objectNode, object);
 	}
 
+	private void addDiscriminatorProperty(Object object, Node objectNode)
+			throws NoSuchNodeTypeException, VersionException,
+			ConstraintViolationException, LockException, RepositoryException,
+			ValueFormatException {
+		
+		try {
+			objectNode.setProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY,
+					ReflectionUtils.getBeanClass(object).getName());
+			
+		} catch (Exception e) {
+			// if it is not possible to add the CLASS_NAME_PROPERTY due to strong constraints in the

+			// node type definition, try to add the Discriminator node type.
+			String mixinTypeName;
+			mixinTypeName = ManagerConstant.DISCRIMINATOR_NODE_TYPE;
+			objectNode.addMixin(mixinTypeName);
+			objectNode.setProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY,
+					ReflectionUtils.getBeanClass(object).getName());
+		}
+		
+	}
+
 	/**
 	 * @see org.apache.jackrabbit.ocm.manager.objectconverter.ObjectConverter#update(javax.jcr.Session,
 	 *      java.lang.Object)
@@ -284,8 +306,8 @@
 
 			ClassDescriptor classDescriptor = null;
 			Node node = (Node) session.getItem(path);
-			if (node.hasProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME)) {
-				String className = node.getProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME).getValue().getString();
+			if (node.hasProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY)) {
+				String className = node.getProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY).getValue().getString();
 				classDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.forName(className));
 			} else {
 				String nodeType = node.getPrimaryNodeType().getName();
@@ -350,8 +372,8 @@
 
 			ClassDescriptor alternativeDescriptor = null;
 			if (classDescriptor.usesNodeTypePerHierarchyStrategy()) {
-				if (node.hasProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME)) {
-	                String className = node.getProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME).getValue().getString();
+				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 {

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/SimpleFieldsHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/SimpleFieldsHelper.java?rev=636881&r1=636880&r2=636881&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/SimpleFieldsHelper.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/SimpleFieldsHelper.java
Thu Mar 13 13:51:02 2008
@@ -83,7 +83,7 @@
 
 			if (classDescriptor.usesNodeTypePerHierarchyStrategy() && classDescriptor.hasDiscriminator())
 			{
-				if (!node.hasProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME))
+				if (!node.hasProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY))
 				{
 					throw new ObjectContentManagerException("Class '"
 							+ classDescriptor.getClassName()

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java?rev=636881&r1=636880&r2=636881&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java
Thu Mar 13 13:51:02 2008
@@ -93,7 +93,7 @@
     private Filter buildDiscriminatorFilter(Query query, ClassDescriptor classDescriptor)
{
         Filter discriminatorFilter = this.createFilter(query.getFilter().getFilterClass());
         if (!classDescriptor.isAbstract() && (! classDescriptor.isInterface()) )
{
-            discriminatorFilter.addJCRExpression("@" + ManagerConstant.DISCRIMINATOR_PROPERTY_NAME
+ "='" +    classDescriptor.getClassName() + "'");
+            discriminatorFilter.addJCRExpression("@" + ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY
+ "='" +    classDescriptor.getClassName() + "'");
         }
 
         if (classDescriptor.hasDescendants()) {

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/test-config/nodetypes/custom_nodetypes.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/test-config/nodetypes/custom_nodetypes.xml?rev=636881&r1=636880&r2=636881&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/test-config/nodetypes/custom_nodetypes.xml (original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/test-config/nodetypes/custom_nodetypes.xml Thu
Mar 13 13:51:02 2008
@@ -26,7 +26,7 @@
     <supertypes>
       <supertype>nt:base</supertype>
     </supertypes>
-    <propertyDefinition name="ocm:classname" requiredType="String" autoCreated="false"
mandatory="true" onParentVersion="COPY" protected="false" multiple="false" />    
+    <propertyDefinition name="ocm_classname" requiredType="String" autoCreated="false"
mandatory="true" onParentVersion="COPY" protected="false" multiple="false" />    
   </nodeType>
 
   <nodeType name="ocm:TestLockable" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
@@ -34,7 +34,6 @@
       <supertype>mix:lockable</supertype>
       <supertype>nt:base</supertype>
     </supertypes>
-    <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="false"
onParentVersion="COPY" protected="false" multiple="false" />
     <propertyDefinition name="ocm:a1" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
 	<propertyDefinition name="ocm:a2" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
   </nodeType>
@@ -44,7 +43,6 @@
       <supertype>mix:versionable</supertype>
       <supertype>nt:base</supertype>
     </supertypes>
-    <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="false"
onParentVersion="COPY" protected="false" multiple="false" />
     <propertyDefinition name="ocm:id" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
 	<propertyDefinition name="ocm:name" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
   </nodeType>
@@ -54,7 +52,6 @@
       <supertype>mix:versionable</supertype>
       <supertype>nt:base</supertype>
     </supertypes>
-    <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="false"
onParentVersion="COPY" protected="false" multiple="false" />
     <propertyDefinition name="ocm:text" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
   </nodeType>
   
@@ -63,7 +60,6 @@
       <supertype>mix:versionable</supertype>
       <supertype>nt:base</supertype>
     </supertypes>
-    <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="false"
onParentVersion="COPY" protected="false" multiple="false" />
     <propertyDefinition name="ocm:title" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
     <childNodeDefinition name="*" defaultPrimaryType="ocm:paragraph" autoCreated="false"
mandatory="false" onParentVersion="COPY" protected="false" sameNameSiblings="true">
       <requiredPrimaryTypes>
@@ -77,7 +73,6 @@
       <supertype>mix:versionable</supertype>
       <supertype>nt:base</supertype>
     </supertypes>
-    <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="false"
onParentVersion="COPY" protected="false" multiple="false" />
     <propertyDefinition name="ocm:title" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
     <childNodeDefinition name="*" defaultPrimaryType="ocm:paragraph" autoCreated="false"
mandatory="false" onParentVersion="COPY" protected="false" sameNameSiblings="false">
       <requiredPrimaryTypes>
@@ -91,7 +86,6 @@
       <supertype>mix:versionable</supertype>
       <supertype>nt:base</supertype>
     </supertypes>
-    <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="false"
onParentVersion="COPY" protected="false" multiple="false" />
     <propertyDefinition name="ocm:id" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
     <propertyDefinition name="ocm:text" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />    
   </nodeType>
@@ -100,7 +94,6 @@
     <supertypes>
       <supertype>nt:base</supertype>
     </supertypes>
-    <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
     <propertyDefinition name="ocm:name" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
 
   </nodeType>
@@ -116,7 +109,6 @@
       <supertype>mix:versionable</supertype>
       <supertype>nt:base</supertype>
     </supertypes>
-    <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
     <propertyDefinition name="ocm:encoding" requiredType="String" autoCreated="false"
mandatory="true" onParentVersion="COPY" protected="false" multiple="false" />
     <propertyDefinition name="ocm:binarycontent" requiredType="Binary" autoCreated="false"
mandatory="true" onParentVersion="COPY" protected="false" multiple="false" />    
   </nodeType>
@@ -158,7 +150,6 @@
       <supertype>mix:versionable</supertype>
       <supertype>nt:base</supertype>
     </supertypes>
-    <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="false"
onParentVersion="COPY" protected="false" multiple="false" />
     <propertyDefinition name="ocm:content" requiredType="String" autoCreated="false" mandatory="true"
onParentVersion="COPY" protected="false" multiple="false" />
   </nodeType>
   
@@ -241,7 +232,6 @@
     <supertypes>
       <supertype>nt:base</supertype>
     </supertypes>
-    <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="false"
onParentVersion="COPY" protected="false" multiple="false" />
     <childNodeDefinition name="*" defaultPrimaryType="ocm:ntdetail" autoCreated="false"
mandatory="false" onParentVersion="COPY" protected="false" sameNameSiblings="true">
       <requiredPrimaryTypes>
         <requiredPrimaryType>ocm:ntdetail</requiredPrimaryType>



Mime
View raw message