You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2007/04/09 12:25:59 UTC

svn commit: r526703 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype: NodeTypeDefDiff.java NodeTypeRegistry.java

Author: jukka
Date: Mon Apr  9 03:25:55 2007
New Revision: 526703

URL: http://svn.apache.org/viewvc?view=rev&rev=526703
Log:
JCR-808: Applied patch from Christoph Kiehl to get better error messages for non-trivial nodetype changes

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java?view=diff&rev=526703&r1=526702&r2=526703
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java Mon Apr  9 03:25:55 2007
@@ -118,20 +118,22 @@
             // assume TRIVIAL change by default
             type = TRIVIAL;
 
-            // check supertypes (MAJOR modification)
-            if (supertypesChanged()) {
-                type = MAJOR;
+            // check supertypes
+            int tmpType = supertypesDiff(); 
+            if (tmpType > type) {
+                type = tmpType;
             }
 
             // check mixin flag (MAJOR modification)
-            if (oldDef.isMixin() != newDef.isMixin()) {
-                type = MAJOR;
+            tmpType = mixinFlagDiff();
+            if (tmpType > type) {
+                type = tmpType;
             }
 
             // no need to check orderableChildNodes flag (TRIVIAL modification)
 
             // check property definitions
-            int tmpType = buildPropDefDiffs();
+            tmpType = buildPropDefDiffs();
             if (tmpType > type) {
                 type = tmpType;
             }
@@ -208,22 +210,15 @@
     /**
      * @return
      */
-    public boolean supertypesChanged() {
-        return !Arrays.equals(oldDef.getSupertypes(), newDef.getSupertypes());
+    public int mixinFlagDiff() {
+        return oldDef.isMixin() != newDef.isMixin() ? MAJOR : NONE;
     }
 
     /**
      * @return
      */
-    public boolean propertyDefsChanged() {
-        return !Arrays.equals(oldDef.getPropertyDefs(), newDef.getPropertyDefs());
-    }
-
-    /**
-     * @return
-     */
-    public boolean childNodeDefsChanged() {
-        return !Arrays.equals(oldDef.getChildNodeDefs(), newDef.getChildNodeDefs());
+    public int supertypesDiff() {
+        return !Arrays.equals(oldDef.getSupertypes(), newDef.getSupertypes()) ? MAJOR : NONE;
     }
 
     /**
@@ -339,8 +334,61 @@
 
         return maxType;
     }
+    
+    public String toString() {
+        String result = this.getClass().getSimpleName() + "[\n\tnodeTypeName="
+                + oldDef.getName();
+        
+        result += ",\n\tmixinFlagDiff=" + modificationTypeToString(mixinFlagDiff());
+        result += ",\n\tsupertypesDiff=" + modificationTypeToString(supertypesDiff());
+
+        result += ",\n\tpropertyDifferences=[\n";
+        result += toString(propDefDiffs);
+        result += "\t]";
+
+        result += ",\n\tchildNodeDifferences=[\n";
+        result += toString(childNodeDefDiffs);
+        result += "\t]\n";
+        result += "]\n";
+
+        return result;
+    }
+
+    private String toString(List childItemDefDiffs) {
+        String result = "";
+        for (Iterator iter = childItemDefDiffs.iterator(); iter.hasNext();) {
+            ChildItemDefDiff propDefDiff = (ChildItemDefDiff) iter.next();
+            result += "\t\t" + propDefDiff;
+            if (iter.hasNext()) {
+                result += ",";
+            }
+            result += "\n";
+        }
+        return result;
+    }
+
+    private String modificationTypeToString(int modifcationType) {
+        String typeString = "unknown";
+        switch (modifcationType) {
+            case NONE:
+                typeString = "NONE";
+                break;
+            case TRIVIAL:
+                typeString = "TRIVIAL";
+                break;
+            case MINOR:
+                typeString = "MINOR";
+                break;
+            case MAJOR:
+                typeString = "MAJOR";
+                break;
+        }
+        return typeString;
+    }
+
 
     //--------------------------------------------------------< inner classes >
+
     abstract class ChildItemDefDiff {
         protected final ItemDef oldDef;
         protected final ItemDef newDef;
@@ -414,6 +462,28 @@
             return oldDef != null && newDef != null
                     && !oldDef.equals(newDef);
         }
+
+        public String toString() {
+            String typeString = modificationTypeToString(getType());
+
+            String operationString;
+            if (isAdded()) {
+                operationString = "ADDED";
+            } else if (isModified()) {
+                operationString = "MODIFIED";
+            } else if (isRemoved()) {
+                operationString = "REMOVED";
+            } else {
+                operationString = "NONE";
+            }
+
+            ItemDef itemDefinition = (oldDef != null) ? oldDef : newDef;
+
+            return getClass().getSimpleName() + "[itemName="
+                    + itemDefinition.getName() + ", type=" + typeString
+                    + ", operation=" + operationString + "]";
+        }
+
     }
 
     public class PropDefDiff extends ChildItemDefDiff {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java?view=diff&rev=526703&r1=526702&r2=526703
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java Mon Apr  9 03:25:55 2007
@@ -362,24 +362,32 @@
             notifyReRegistered(name);
             return entNew;
         }
+        
+       	String message = "The following nodetype change contains non-trivial changes."
+                + "Up until now only trivial changes are supported."
+                + " (see javadoc for "
+                + NodeTypeDefDiff.class.getName()
+                + "):\n" + diff.toString();
+        throw new RepositoryException(message);
 
+        // TODO Implement checkForConflictingContent()
         // make sure existing content would not conflict
         // with new node type definition
-        checkForConflictingContent(ntd);
-
+        //checkForConflictingContent(ntd);
+        //
         // unregister old node type definition
-        internalUnregister(name);
+        //internalUnregister(name);
         // register new definition
-        EffectiveNodeType entNew = internalRegister(ntd);
-
+        //EffectiveNodeType entNew = internalRegister(ntd);
+        //
         // persist modified node type definitions
-        customNTDefs.remove(name);
-        customNTDefs.add(ntd);
-        persistCustomNodeTypeDefs(customNTDefs);
-
+        //customNTDefs.remove(name);
+        //customNTDefs.add(ntd);
+        //persistCustomNodeTypeDefs(customNTDefs);
+        //
         // notify listeners
-        notifyReRegistered(name);
-        return entNew;
+        //notifyReRegistered(name);
+        //return entNew;
     }
 
     /**