jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r389555 - in /jackrabbit/branches/1.0/jackrabbit/src: main/java/org/apache/jackrabbit/core/nodetype/ test/java/org/apache/jackrabbit/core/nodetype/xml/ test/java/org/apache/jackrabbit/test/api/nodetype/ test/java/org/apache/jackrabbit/test/...
Date Tue, 28 Mar 2006 17:49:48 GMT
Author: jukka
Date: Tue Mar 28 09:49:47 2006
New Revision: 389555

URL: http://svn.apache.org/viewcvs?rev=389555&view=rev
Log:
1.0: Merged revisions 384271, 384546, and 384767: JCR-333 NodeTypeDef depends on supertype
ordering

Modified:
    jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java
    jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
    jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
    jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/nodetype/PredefinedNodeTypeTest.java
    jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/nodetype/spec/nt-unstructured.txt

Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java?rev=389555&r1=389554&r2=389555&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java
Tue Mar 28 09:49:47 2006
@@ -18,6 +18,7 @@
 import org.apache.jackrabbit.name.QName;
 
 import java.util.Arrays;
+import java.util.HashSet;
 
 /**
  * This class implements the <code>NodeDef</code> interface and additionally
@@ -28,29 +29,34 @@
     /**
      * The name of the default primary type.
      */
-    private QName defaultPrimaryType = null;
+    private QName defaultPrimaryType;
 
     /**
      * The names of the required primary types.
      */
-    private QName[] requiredPrimaryTypes = new QName[] { QName.NT_BASE };
+    private HashSet requiredPrimaryTypes;
 
     /**
      * The 'allowsSameNameSiblings' flag.
      */
-    private boolean allowsSameNameSiblings = false;
+    private boolean allowsSameNameSiblings;
 
     /**
      * The identifier of this node definition. The identifier is lazily computed
      * based on the characteristics of this node definition and reset on every
      * attribute change.
      */
-    private NodeDefId id = null;
+    private NodeDefId id;
 
     /**
      * Default constructor.
      */
     public NodeDefImpl() {
+        defaultPrimaryType = null;
+        requiredPrimaryTypes = new HashSet();
+        requiredPrimaryTypes.add(QName.NT_BASE);
+        allowsSameNameSiblings = false;
+        id = null;
     }
 
     /**
@@ -70,12 +76,13 @@
      * @param requiredPrimaryTypes
      */
     public void setRequiredPrimaryTypes(QName[] requiredPrimaryTypes) {
-        // reset id field in order to force lazy recomputation of identifier
-        id = null;
         if (requiredPrimaryTypes == null) {
             throw new IllegalArgumentException("requiredPrimaryTypes can not be null");
         }
-        this.requiredPrimaryTypes = requiredPrimaryTypes;
+        // reset id field in order to force lazy recomputation of identifier
+        id = null;
+        this.requiredPrimaryTypes.clear();
+        this.requiredPrimaryTypes.addAll(Arrays.asList(requiredPrimaryTypes));
     }
 
     /**
@@ -171,7 +178,11 @@
      * {@inheritDoc}
      */
     public QName[] getRequiredPrimaryTypes() {
-        return requiredPrimaryTypes;
+        if (requiredPrimaryTypes.isEmpty()) {
+            return QName.EMPTY_ARRAY;
+        }
+        return (QName[]) requiredPrimaryTypes.toArray(
+                new QName[requiredPrimaryTypes.size()]);
     }
 
     /**
@@ -208,7 +219,7 @@
         if (obj instanceof NodeDefImpl) {
             NodeDefImpl other = (NodeDefImpl) obj;
             return super.equals(obj)
-                    && Arrays.equals(requiredPrimaryTypes, other.requiredPrimaryTypes)
+                    && requiredPrimaryTypes.equals(other.requiredPrimaryTypes)
                     && (defaultPrimaryType == null
                             ? other.defaultPrimaryType == null
                             : defaultPrimaryType.equals(other.defaultPrimaryType))

Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java?rev=389555&r1=389554&r2=389555&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
Tue Mar 28 09:49:47 2006
@@ -22,6 +22,7 @@
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.Iterator;
 
 /**
  * A <code>NodeTypeDef</code> holds the definition of a node type.
@@ -29,12 +30,12 @@
 public class NodeTypeDef implements Cloneable {
 
     private QName name;
-    private QName[] supertypes;
+    private HashSet supertypes;
     private boolean mixin;
     private boolean orderableChildNodes;
     private QName primaryItemName;
-    private PropDef[] propDefs;
-    private NodeDef[] nodeDefs;
+    private HashSet propDefs;
+    private HashSet nodeDefs;
     private Set dependencies;
 
     /**
@@ -44,9 +45,9 @@
         dependencies = null;
         name = null;
         primaryItemName = null;
-        nodeDefs = NodeDef.EMPTY_ARRAY;
-        propDefs = PropDef.EMPTY_ARRAY;
-        supertypes = QName.EMPTY_ARRAY;
+        nodeDefs = new HashSet();
+        propDefs = new HashSet();
+        supertypes = new HashSet();
         mixin = false;
         orderableChildNodes = false;
     }
@@ -67,18 +68,17 @@
         if (dependencies == null) {
             dependencies = new HashSet();
             // supertypes
-            for (int i = 0; i < supertypes.length; i++) {
-                dependencies.add(supertypes[i]);
-            }
+            dependencies.addAll(supertypes);
             // child node definitions
-            for (int i = 0; i < nodeDefs.length; i++) {
+            for (Iterator iter = nodeDefs.iterator(); iter.hasNext();) {
+                NodeDef nd = (NodeDef) iter.next();
                 // default primary type
-                QName ntName = nodeDefs[i].getDefaultPrimaryType();
+                QName ntName = nd.getDefaultPrimaryType();
                 if (ntName != null && !name.equals(ntName)) {
                     dependencies.add(ntName);
                 }
                 // required primary type
-                QName[] ntNames = nodeDefs[i].getRequiredPrimaryTypes();
+                QName[] ntNames = nd.getRequiredPrimaryTypes();
                 for (int j = 0; j < ntNames.length; j++) {
                     if (ntNames[j] != null && !name.equals(ntNames[j])) {
                         dependencies.add(ntNames[j]);
@@ -86,10 +86,11 @@
                 }
             }
             // property definitions
-            for (int i = 0; i < propDefs.length; i++) {
+            for (Iterator iter = propDefs.iterator(); iter.hasNext();) {
+                PropDef pd = (PropDef) iter.next();
                 // REFERENCE value constraints
-                if (propDefs[i].getRequiredType() == PropertyType.REFERENCE) {
-                    ValueConstraint[] ca = propDefs[i].getValueConstraints();
+                if (pd.getRequiredType() == PropertyType.REFERENCE) {
+                    ValueConstraint[] ca = pd.getValueConstraints();
                     if (ca != null) {
                         for (int j = 0; j < ca.length; j++) {
                             ReferenceConstraint rc = (ReferenceConstraint) ca[j];
@@ -125,7 +126,8 @@
      */
     public void setSupertypes(QName[] names) {
         resetDependencies();
-        supertypes = names;
+        supertypes.clear();
+        supertypes.addAll(Arrays.asList(names));
     }
 
     /**
@@ -163,7 +165,8 @@
      */
     public void setPropertyDefs(PropDef[] defs) {
         resetDependencies();
-        propDefs = defs;
+        propDefs.clear();
+        propDefs.addAll(Arrays.asList(defs));
     }
 
     /**
@@ -173,7 +176,8 @@
      */
     public void setChildNodeDefs(NodeDef[] defs) {
         resetDependencies();
-        nodeDefs = defs;
+        nodeDefs.clear();
+        nodeDefs.addAll(Arrays.asList(defs));
     }
 
     /**
@@ -194,7 +198,10 @@
      *         <code>null</code> if not set.
      */
     public QName[] getSupertypes() {
-        return supertypes;
+        if (supertypes.isEmpty()) {
+            return QName.EMPTY_ARRAY;
+        }
+        return (QName[]) supertypes.toArray(new QName[supertypes.size()]);
     }
 
     /**
@@ -233,7 +240,10 @@
      *         <code>null</code> if not set.
      */
     public PropDef[] getPropertyDefs() {
-        return propDefs;
+        if (propDefs.isEmpty()) {
+            return PropDef.EMPTY_ARRAY;
+        }
+        return (PropDef[]) propDefs.toArray(new PropDef[propDefs.size()]);
     }
 
     /**
@@ -244,7 +254,10 @@
      *         <code>null</code> if not set.
      */
     public NodeDef[] getChildNodeDefs() {
-        return nodeDefs;
+        if (nodeDefs.isEmpty()) {
+            return NodeDef.EMPTY_ARRAY;
+        }
+        return (NodeDef[]) nodeDefs.toArray(new NodeDef[nodeDefs.size()]);
     }
 
     //-------------------------------------------< java.lang.Object overrides >
@@ -252,11 +265,11 @@
         NodeTypeDef clone = new NodeTypeDef();
         clone.name = name;
         clone.primaryItemName = primaryItemName;
-        clone.supertypes = (QName[]) supertypes.clone();
+        clone.supertypes = (HashSet) supertypes.clone();
         clone.mixin = mixin;
         clone.orderableChildNodes = orderableChildNodes;
-        clone.nodeDefs = (NodeDef[]) nodeDefs.clone();
-        clone.propDefs = (PropDef[]) propDefs.clone();
+        clone.nodeDefs = (HashSet) nodeDefs.clone();
+        clone.propDefs = (HashSet) propDefs.clone();
         return clone;
     }
 
@@ -268,11 +281,11 @@
             NodeTypeDef other = (NodeTypeDef) obj;
             return (name == null ? other.name == null : name.equals(other.name))
                     && (primaryItemName == null ? other.primaryItemName == null :
primaryItemName.equals(other.primaryItemName))
-                    && Arrays.equals(supertypes, other.supertypes)
+                    && supertypes.equals(other.supertypes)
                     && mixin == other.mixin
                     && orderableChildNodes == other.orderableChildNodes
-                    && Arrays.equals(propDefs, other.propDefs)
-                    && Arrays.equals(nodeDefs, other.nodeDefs);
+                    && propDefs.equals(other.propDefs)
+                    && nodeDefs.equals(other.nodeDefs);
         }
         return false;
     }

Modified: jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java?rev=389555&r1=389554&r2=389555&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
Tue Mar 28 09:49:47 2006
@@ -18,7 +18,6 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
-import org.apache.jackrabbit.core.nodetype.ItemDef;
 import org.apache.jackrabbit.core.nodetype.NodeDef;
 import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
 import org.apache.jackrabbit.core.nodetype.PropDef;
@@ -90,13 +89,21 @@
      * Returns the named property definition from the named node type
      * definition. If either of the definitions do not exist, an assertion
      * failure is generated.
+     * <p>
+     * If the given property name is <code>null</code>, then the residual
+     * property definition (if one exists) is returned. 
      *
      * @param typeName node type name
-     * @param propertyName property name
+     * @param propertyName property name, or <code>null</code>
      * @return property definition
      */
     private PropDef getProperty(String typeName, String propertyName) {
-        QName name = new QName(TEST_NAMESPACE, propertyName);
+        QName name;
+        if (propertyName != null) {
+            name = new QName(TEST_NAMESPACE, propertyName);
+        } else {
+            name = PropDef.ANY_NAME;
+        }
 
         NodeTypeDef def = getNodeType(typeName);
         PropDef[] defs = def.getPropertyDefs();
@@ -198,8 +205,8 @@
                 def.getPrimaryItemName());
         assertEquals("itemNodeType propertyDefs",
                 10, def.getPropertyDefs().length);
-        PropDef[] defs = def.getPropertyDefs();
-        assertTrue("itemNodeType wildcard property", defs[0].definesResidual());
+        PropDef pdef = getProperty("itemNodeType", null);
+        assertTrue("itemNodeType wildcard property", pdef.definesResidual());
     }
 
     /** Test for the empty item definition. */
@@ -480,12 +487,12 @@
         NodeDef def = getChildNode("childNodeType", "requiredTypeNode");
         assertEquals("requiredTypeNode requiredPrimaryTypes",
                 2, def.getRequiredPrimaryTypes().length);
+        QName[] types = def.getRequiredPrimaryTypes();
+        Arrays.sort(types);
         assertEquals("requiredTypeNode requiredPrimaryTypes[0]",
-                new QName(TEST_NAMESPACE, "baseType"),
-                def.getRequiredPrimaryTypes()[0]);
+                new QName(TEST_NAMESPACE, "baseType"), types[0]);
         assertEquals("requiredTypeNode requiredPrimaryTypes[1]",
-                new QName(TEST_NAMESPACE, "testType"),
-                def.getRequiredPrimaryTypes()[1]);
+                new QName(TEST_NAMESPACE, "testType"), types[1]);
     }
 
     /**

Modified: jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/nodetype/PredefinedNodeTypeTest.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/nodetype/PredefinedNodeTypeTest.java?rev=389555&r1=389554&r2=389555&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/nodetype/PredefinedNodeTypeTest.java
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/nodetype/PredefinedNodeTypeTest.java
Tue Mar 28 09:49:47 2006
@@ -272,12 +272,12 @@
         writer.println("PrimaryItemName");
         writer.println("  " + type.getPrimaryItemName());
         NodeDefinition[] nodes = type.getDeclaredChildNodeDefinitions();
-        Arrays.sort(nodes, ITEM_DEF_COMPARATOR);
+        Arrays.sort(nodes, NODE_DEF_COMPARATOR);
         for (int i = 0; i < nodes.length; i++) {
             writer.print(getChildNodeDefSpec(nodes[i]));
         }
         PropertyDefinition[] properties = type.getDeclaredPropertyDefinitions();
-        Arrays.sort(properties, ITEM_DEF_COMPARATOR);
+        Arrays.sort(properties, PROPERTY_DEF_COMPARATOR);
         for (int i = 0; i < properties.length; i++) {
             writer.print(getPropertyDefSpec(properties[i]));
         }
@@ -385,20 +385,47 @@
     }
 
     /**
-     * Comparator for ordering property and node definition arrays. Item
-     * definitions are ordered by name, with the wildcard item definition
-     * ("*") ordered last.
+     * Comparator for ordering node definition arrays. Node definitions are
+     * ordered by name, with the wildcard item definition ("*") ordered last.
      */
-    private static final Comparator ITEM_DEF_COMPARATOR = new Comparator() {
+    private static final Comparator NODE_DEF_COMPARATOR = new Comparator() {
         public int compare(Object a, Object b) {
-            ItemDefinition ida = (ItemDefinition) a;
-            ItemDefinition idb = (ItemDefinition) b;
-            if (ida.getName().equals("*") && !idb.getName().equals("*")) {
+            NodeDefinition nda = (NodeDefinition) a;
+            NodeDefinition ndb = (NodeDefinition) b;
+            if (nda.getName().equals("*") && !ndb.getName().equals("*")) {
                 return 1;
-            } else if (!ida.getName().equals("*") && idb.getName().equals("*")) {
+            } else if (!nda.getName().equals("*") && ndb.getName().equals("*")) {
                 return -1;
             } else {
-                return ida.getName().compareTo(idb.getName());
+                return nda.getName().compareTo(ndb.getName());
+            }
+        }
+    };
+
+    /**
+     * Comparator for ordering property definition arrays. Property definitions
+     * are ordered by name, with the wildcard item definition ("*") ordered
+     * last, and isMultiple flag, with <code>isMultiple==true</code> ordered
last.
+     */
+    private static final Comparator PROPERTY_DEF_COMPARATOR = new Comparator() {
+        public int compare(Object a, Object b) {
+            PropertyDefinition pda = (PropertyDefinition) a;
+            PropertyDefinition pdb = (PropertyDefinition) b;
+            if (pda.getName().equals("*") && !pdb.getName().equals("*")) {
+                return 1;
+            } else if (!pda.getName().equals("*") && pdb.getName().equals("*")) {
+                return -1;
+            }
+            int result = pda.getName().compareTo(pdb.getName());
+            if (result != 0) {
+                return result;
+            }
+            if (pda.isMultiple() && !pdb.isMultiple()) {
+                return 1;
+            } else if (!pda.isMultiple() && pdb.isMultiple()) {
+                return -1;
+            } else {
+                return 0;
             }
         }
     };

Modified: jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/nodetype/spec/nt-unstructured.txt
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/nodetype/spec/nt-unstructured.txt?rev=389555&r1=389554&r2=389555&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/nodetype/spec/nt-unstructured.txt
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/nodetype/spec/nt-unstructured.txt
Tue Mar 28 09:49:47 2006
@@ -26,7 +26,7 @@
   Mandatory false
   OnParentVersion COPY
   Protected false
-  Multiple true
+  Multiple false
 PropertyDefinition
   Name "*"
   RequiredType UNDEFINED
@@ -36,4 +36,4 @@
   Mandatory false
   OnParentVersion COPY
   Protected false
-  Multiple false
+  Multiple true



Mime
View raw message