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 2010/08/20 14:33:38 UTC
svn commit: r987477 - in /jackrabbit/trunk:
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/
jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/
jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/common...
Author: stefan
Date: Fri Aug 20 12:33:38 2010
New Revision: 987477
URL: http://svn.apache.org/viewvc?rev=987477&view=rev
Log:
consolidate redundant/duplicate nodetype-related code
Removed:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefId.java
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/PropDefId.java
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QItemDefinitionImpl.java
jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java
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?rev=987477&r1=987476&r2=987477&view=diff
==============================================================================
--- 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 Fri Aug 20 12:33:38 2010
@@ -57,6 +57,7 @@ import org.apache.jackrabbit.spi.QNodeDe
import org.apache.jackrabbit.spi.QNodeTypeDefinition;
import org.apache.jackrabbit.spi.commons.name.NameConstants;
import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefDiff;
import org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder;
import org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl;
import org.slf4j.Logger;
@@ -326,7 +327,7 @@ public class NodeTypeRegistry implements
* @throws NoSuchNodeTypeException if <code>ntName</code> does not
* denote a registered node type.
* @throws RepositoryException if another error occurs.
- * @see #unregisterNodeTypes(Collection)
+ * @see #unregisterNodeTypes(Collection, boolean)
*/
public void unregisterNodeType(Name ntName)
throws NoSuchNodeTypeException, RepositoryException {
@@ -1812,8 +1813,8 @@ public class NodeTypeRegistry implements
}
/**
- * Notify the listeners that a node type <code>ntName</code> has been unregistered.
- * @param ntName node type name
+ * Notify the listeners that oone or more node types have been unregistered.
+ * @param names node type names
*/
private void notifyUnregistered(Collection<Name> names) {
// copy listeners to array to avoid ConcurrentModificationException
Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QItemDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QItemDefinitionImpl.java?rev=987477&r1=987476&r2=987477&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QItemDefinitionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QItemDefinitionImpl.java Fri Aug 20 12:33:38 2010
@@ -139,7 +139,7 @@ public abstract class QItemDefinitionImp
//-------------------------------------------< java.lang.Object overrides >
/**
* Compares two item definitions for equality. Returns <code>true</code>
- * if the given object is an item defintion and has the same attributes
+ * if the given object is an item definition and has the same attributes
* as this item definition.
*
* @param obj the object to compare this item definition with
Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java?rev=987477&r1=987476&r2=987477&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java Fri Aug 20 12:33:38 2010
@@ -16,23 +16,23 @@
*/
package org.apache.jackrabbit.spi.commons.nodetype;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QItemDefinition;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QValueConstraint;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+
+import javax.jcr.PropertyType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
import java.util.Map;
-
-import javax.jcr.PropertyType;
-
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.QItemDefinition;
-import org.apache.jackrabbit.spi.QNodeDefinition;
-import org.apache.jackrabbit.spi.QNodeTypeDefinition;
-import org.apache.jackrabbit.spi.QPropertyDefinition;
-import org.apache.jackrabbit.spi.QValueConstraint;
+import java.util.Set;
/**
* A <code>NodeTypeDefDiff</code> represents the result of the comparison of
@@ -142,7 +142,14 @@ public class NodeTypeDefDiff {
type = tmpType;
}
+ // check abstract flag (MAJOR modification)
+ tmpType = abstractFlagDiff();
+ if (tmpType > type) {
+ type = tmpType;
+ }
+
// no need to check orderableChildNodes flag (TRIVIAL modification)
+ // no need to check queryable flag (TRIVIAL modification)
// check property definitions
tmpType = buildPropDefDiffs();
@@ -220,13 +227,20 @@ public class NodeTypeDefDiff {
}
/**
- * @return <code>true</code> if mixin diff
+ * @return <code>true</code> if mixin flag diff
*/
public int mixinFlagDiff() {
return oldDef.isMixin() != newDef.isMixin() ? MAJOR : NONE;
}
/**
+ * @return <code>true</code> if abstract flag diff
+ */
+ public int abstractFlagDiff() {
+ return oldDef.isAbstract() && !newDef.isAbstract() ? MAJOR : NONE;
+ }
+
+ /**
* @return <code>true</code> if supertypes diff
*/
public int supertypesDiff() {
@@ -243,43 +257,38 @@ public class NodeTypeDefDiff {
*/
int maxType = NONE;
- QPropertyDefinition[] pda1 = oldDef.getPropertyDefs();
- Map<Name, QPropertyDefinition> defs1 = new HashMap<Name, QPropertyDefinition>();
- for (QPropertyDefinition aPda1 : pda1) {
- defs1.put(aPda1.getName(), aPda1);
+ Map<QPropertyDefinitionId, QPropertyDefinition> oldDefs = new HashMap<QPropertyDefinitionId, QPropertyDefinition>();
+ for (QPropertyDefinition def : oldDef.getPropertyDefs()) {
+ oldDefs.put(new QPropertyDefinitionId(def), def);
}
- QPropertyDefinition[] pda2 = newDef.getPropertyDefs();
- Map<Name, QPropertyDefinition> defs2 = new HashMap<Name, QPropertyDefinition>();
- for (QPropertyDefinition aPda2 : pda2) {
- defs2.put(aPda2.getName(), aPda2);
+ Map<QPropertyDefinitionId, QPropertyDefinition> newDefs = new HashMap<QPropertyDefinitionId, QPropertyDefinition>();
+ for (QPropertyDefinition def : newDef.getPropertyDefs()) {
+ newDefs.put(new QPropertyDefinitionId(def), def);
}
/**
* walk through defs1 and process all entries found in
* both defs1 & defs2 and those found only in defs1
*/
- Iterator iter = defs1.keySet().iterator();
- while (iter.hasNext()) {
- Name name = (Name) iter.next();
- QPropertyDefinition def1 = defs1.get(name);
- QPropertyDefinition def2 = defs2.get(name);
+ for (Map.Entry<QPropertyDefinitionId, QPropertyDefinition> entry : oldDefs.entrySet()) {
+ QPropertyDefinitionId id = entry.getKey();
+ QPropertyDefinition def1 = entry.getValue();
+ QPropertyDefinition def2 = newDefs.get(id);
PropDefDiff diff = new PropDefDiff(def1, def2);
if (diff.getType() > maxType) {
maxType = diff.getType();
}
propDefDiffs.add(diff);
- defs2.remove(name);
+ newDefs.remove(id);
}
/**
* defs2 by now only contains entries found in defs2 only;
* walk through defs2 and process all remaining entries
*/
- iter = defs2.keySet().iterator();
- while (iter.hasNext()) {
- Name name = (Name) iter.next();
- QPropertyDefinition def = defs2.get(name);
+ for (Map.Entry<QPropertyDefinitionId, QPropertyDefinition> entry : newDefs.entrySet()) {
+ QPropertyDefinition def = entry.getValue();
PropDefDiff diff = new PropDefDiff(null, def);
if (diff.getType() > maxType) {
maxType = diff.getType();
@@ -301,43 +310,40 @@ public class NodeTypeDefDiff {
int maxType = NONE;
QNodeDefinition[] cnda1 = oldDef.getChildNodeDefs();
- Map<Name, QNodeDefinition> defs1 = new HashMap<Name, QNodeDefinition>();
- for (QNodeDefinition aCnda1 : cnda1) {
- defs1.put(aCnda1.getName(), aCnda1);
+ Map<QNodeDefinitionId, QNodeDefinition> defs1 = new HashMap<QNodeDefinitionId, QNodeDefinition>();
+ for (QNodeDefinition def1 : cnda1) {
+ defs1.put(new QNodeDefinitionId(def1), def1);
}
QNodeDefinition[] cnda2 = newDef.getChildNodeDefs();
- Map<Name, QNodeDefinition> defs2 = new HashMap<Name, QNodeDefinition>();
- for (QNodeDefinition aCnda2 : cnda2) {
- defs2.put(aCnda2.getName(), aCnda2);
+ Map<QNodeDefinitionId, QNodeDefinition> defs2 = new HashMap<QNodeDefinitionId, QNodeDefinition>();
+ for (QNodeDefinition def2 : cnda2) {
+ defs2.put(new QNodeDefinitionId(def2), def2);
}
/**
* walk through defs1 and process all entries found in
* both defs1 & defs2 and those found only in defs1
*/
- Iterator iter = defs1.keySet().iterator();
- while (iter.hasNext()) {
- Name name = (Name) iter.next();
- QNodeDefinition def1 = defs1.get(name);
- QNodeDefinition def2 = defs2.get(name);
+ for (Map.Entry<QNodeDefinitionId, QNodeDefinition> entry1 : defs1.entrySet()) {
+ QNodeDefinitionId id = entry1.getKey();
+ QNodeDefinition def1 = entry1.getValue();
+ QNodeDefinition def2 = defs2.get(id);
ChildNodeDefDiff diff = new ChildNodeDefDiff(def1, def2);
if (diff.getType() > maxType) {
maxType = diff.getType();
}
childNodeDefDiffs.add(diff);
- defs2.remove(name);
+ defs2.remove(id);
}
/**
* defs2 by now only contains entries found in defs2 only;
* walk through defs2 and process all remaining entries
*/
- iter = defs2.keySet().iterator();
- while (iter.hasNext()) {
- Name name = (Name) iter.next();
- QNodeDefinition def = defs2.get(name);
- ChildNodeDefDiff diff = new ChildNodeDefDiff(null, def);
+ for (Map.Entry<QNodeDefinitionId, QNodeDefinition> entry2 : defs2.entrySet()) {
+ QNodeDefinition def2 = entry2.getValue();
+ ChildNodeDefDiff diff = new ChildNodeDefDiff(null, def2);
if (diff.getType() > maxType) {
maxType = diff.getType();
}
@@ -548,6 +554,8 @@ public class NodeTypeDefDiff {
}
// no need to check defaultValues (TRIVIAL change)
+ // no need to check availableQueryOperators (TRIVIAL change)
+ // no need to check queryOrderable (TRIVIAL change)
if (type == TRIVIAL) {
int t1 = getOldDef().getRequiredType();
@@ -627,4 +635,98 @@ public class NodeTypeDefDiff {
}
}
}
+
+ /**
+ * Identifier used to identify corresponding property definitions
+ */
+ static class QPropertyDefinitionId {
+
+ Name declaringNodeType;
+ Name name;
+ int requiredType;
+ boolean definesResidual;
+ boolean isMultiple;
+
+ QPropertyDefinitionId(QPropertyDefinition def) {
+ declaringNodeType = def.getDeclaringNodeType();
+ name = def.getName();
+ requiredType = def.getRequiredType();
+ definesResidual = def.definesResidual();
+ isMultiple = def.isMultiple();
+ }
+
+ //---------------------------------------< java.lang.Object overrides >
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof QPropertyDefinitionId) {
+ QPropertyDefinitionId other = (QPropertyDefinitionId) obj;
+ return declaringNodeType.equals(other.declaringNodeType)
+ && name.equals(other.name)
+ && requiredType == other.requiredType
+ && definesResidual == other.definesResidual
+ && isMultiple == other.isMultiple;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ int h = 17;
+ h = 37 * h + declaringNodeType.hashCode();
+ h = 37 * h + name.hashCode();
+ h = 37 * h + (definesResidual ? 11 : 43);
+ h = 37 * h + (isMultiple ? 11 : 43);
+ h = 37 * h + requiredType;
+ return h;
+ }
+ }
+
+ /**
+ * Identifier used to identify corresponding node definitions
+ */
+ static class QNodeDefinitionId {
+
+ Name declaringNodeType;
+ Name name;
+ Name[] requiredPrimaryTypes;
+
+ QNodeDefinitionId(QNodeDefinition def) {
+ declaringNodeType = def.getDeclaringNodeType();
+ name = def.getName();
+ requiredPrimaryTypes = def.getRequiredPrimaryTypes();
+ if (requiredPrimaryTypes == null || requiredPrimaryTypes.length == 0) {
+ requiredPrimaryTypes = new Name[]{NameConstants.NT_BASE};
+ }
+ Arrays.sort(requiredPrimaryTypes);
+ }
+
+ //---------------------------------------< java.lang.Object overrides >
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof QNodeDefinitionId) {
+ QNodeDefinitionId other = (QNodeDefinitionId) obj;
+ return declaringNodeType.equals(other.declaringNodeType)
+ && name.equals(other.name)
+ && Arrays.equals(requiredPrimaryTypes, other.requiredPrimaryTypes);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ int h = 17;
+ h = 37 * h + declaringNodeType.hashCode();
+ h = 37 * h + name.hashCode();
+ for (int i = 0; i < requiredPrimaryTypes.length; i++) {
+ h = 37 * h + requiredPrimaryTypes[i].hashCode();
+ }
+ return h;
+ }
+ }
}