You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2004/12/13 19:22:24 UTC

svn commit: r111739 - /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java

Author: stefan
Date: Mon Dec 13 10:22:16 2004
New Revision: 111739

URL: http://svn.apache.org/viewcvs?view=rev&rev=111739
Log:
working on comparison of node type definitions
Added:
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java   (contents, props changed)
Modified:
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java?view=auto&rev=111739
==============================================================================
--- (empty file)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java	Mon Dec 13 10:22:16 2004
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.nodetype;
+
+/**
+ * A <code>NodeTypeDefDiff</code> represents the result of the comparison of
+ * two node type definitions.
+ */
+public class NodeTypeDefDiff {
+
+    // type constants
+    public static final int TRIVIAL = 0;
+    public static final int MINOR = 0;
+    public static final int MAJOR = 0;
+
+    private final NodeTypeDef oldDef;
+    private final NodeTypeDef newDef;
+    private int type;
+/*
+    private QName name;
+    private QName[] supertypes;
+    private boolean mixin;
+    private boolean orderableChildNodes;
+    private PropDef[] propDefs;
+    private ChildNodeDef[] nodeDefs;
+*/
+    /**
+     * Constructor
+     */
+    private NodeTypeDefDiff(NodeTypeDef oldDef, NodeTypeDef newDef) {
+	this.oldDef = oldDef;
+	this.newDef = newDef;
+	init();
+    }
+
+    /**
+     *
+     */
+    private void init() {
+	// @todo build diff and set type
+    }
+
+    /**
+     *
+     * @param oldDef
+     * @param newDef
+     * @return
+     */
+    public static NodeTypeDefDiff create(NodeTypeDef oldDef, NodeTypeDef newDef) {
+	if (oldDef == null || newDef == null) {
+	    throw new IllegalArgumentException("arguments can not be null");
+	}
+	if (!oldDef.getName().equals(newDef.getName())) {
+	    throw new IllegalArgumentException("node type names must match");
+	}
+	return new NodeTypeDefDiff(oldDef, newDef);
+    }
+
+    /**
+     *
+     * @return
+     */ 
+    public boolean isTrivial() {
+	return type == TRIVIAL;
+    }
+
+    /**
+     *
+     * @return
+     */
+    public int getType() {
+	return type;
+    }
+}

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java?view=diff&rev=111739&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java&r1=111738&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java&r2=111739
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java	Mon Dec 13 10:22:16 2004
@@ -1256,49 +1256,59 @@
     public synchronized EffectiveNodeType reregisterNodeType(NodeTypeDef ntd)
             throws NoSuchNodeTypeException, InvalidNodeTypeDefException,
             RepositoryException {
-        QName name = ntd.getName();
-        if (!registeredNTDefs.containsKey(name)) {
-            throw new NoSuchNodeTypeException(name.toString());
-        }
-        if (builtInNTDefs.contains(name)) {
-            throw new RepositoryException(name.toString() + ": can't reregister built-in node type.");
-        }
+	QName name = ntd.getName();
+	if (!registeredNTDefs.containsKey(name)) {
+	    throw new NoSuchNodeTypeException(name.toString());
+	}
+	if (builtInNTDefs.contains(name)) {
+	    throw new RepositoryException(name.toString() + ": can't reregister built-in node type.");
+	}
 
-        /**
-         * validate new node type definition
-         */
-        EffectiveNodeType ent = validateNodeTypeDef(ntd);
+	/**
+	 * validate new node type definition
+	 */
+	validateNodeTypeDef(ntd);
 
-        /**
-         * collect names of node types that have dependencies on the given
-         * node type
-         */
-        Set dependentNTs = getDependentNodeTypes(name);
+	/**
+	 * build diff of current and new definition and determine type of change
+	 */
+	NodeTypeDef ntdOld = (NodeTypeDef) registeredNTDefs.get(name);
+	NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntdOld, ntd);
+	if (diff.isTrivial()) {
+	    /**
+	     * the change is trivial and has no effect on current content
+	     * (e.g. that would be the case when non-mandatory properties were
+	     * added)
+	     * todo re-register node type definition and update caches & notify listeners on re-registration
+	     */
+            //return entNew;
+	}
 
-        /**
-         * todo
-         * 1. determine type of change and build diff of current and new
-         *    definition
-         * 2. if the change is trivial and has no effect on current content
-         *    (e.g. when a property defintion has been changed from
-         *    single-valued to multi-valued): continue with step 7, otherwise
-         *    continue with next step
-         * 3. apply deep locks on root nodes in every workspace or alternatively
-         *    put repository in 'exclusive' or 'single-user' mode
-         * 4. check if the given node type (or any node type that has
-         *    dependencies on this node type) is currently referenced by nodes
-         *    in the repository.
-         * 5. check if applying changes to affected nodes would violate
-         *    existing node type constraints
-         * 6. re-register node type definition and update caches
-         * 7. notify listeners on re-registration
-         * 8. apply and persist changes to affected nodes (e.g. update
-         *    definition id's, etc.)
-         * 9. what else?
-         */
-        //unregisterNodeType(name);
-        //return registerNodeType(ntd);
-        throw new RepositoryException("not yet implemented");
+	/**
+	 * collect names of node types that have dependencies on the given
+	 * node type
+	 */
+	Set dependentNTs = getDependentNodeTypes(name);
+
+	/**
+	 * non-trivial change of node type definition
+	 * todo
+	 * 1. apply deep locks on root nodes in every workspace or alternatively
+	 *    put repository in 'exclusive' or 'single-user' mode
+	 * 2. check if the given node type (or any node type that has
+	 *    dependencies on this node type) is currently referenced by nodes
+	 *    in the repository.
+	 * 3. check if applying changes to affected nodes would violate
+	 *    existing node type constraints
+	 * 4. re-register node type definition and update caches
+	 * 5. notify listeners on re-registration
+	 * 7. apply and persist changes to affected nodes (e.g. update
+	 *    definition id's, etc.)
+	 * 7. what else?
+	 */
+	//unregisterNodeType(name);
+	//return registerNodeType(ntd);
+	throw new RepositoryException("not yet implemented");
     }
 
     /**