jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r384271 - in /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype: NodeDefImpl.java NodeTypeDef.java
Date Wed, 08 Mar 2006 17:11:14 GMT
Author: stefan
Date: Wed Mar  8 09:11:12 2006
New Revision: 384271

URL: http://svn.apache.org/viewcvs?rev=384271&view=rev
Log:
JCR-333 NodeTypeDef depends on supertype ordering

Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java?rev=384271&r1=384270&r2=384271&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java
Wed Mar  8 09:11:12 2006
@@ -19,6 +19,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
@@ -29,29 +30,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;
     }
 
     /**
@@ -71,12 +77,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));
     }
 
     /**
@@ -172,7 +179,11 @@
      * {@inheritDoc}
      */
     public QName[] getRequiredPrimaryTypes() {
-        return requiredPrimaryTypes;
+        if (requiredPrimaryTypes.isEmpty()) {
+            return QName.EMPTY_ARRAY;
+        }
+        return (QName[]) requiredPrimaryTypes.toArray(
+                new QName[requiredPrimaryTypes.size()]);
     }
 
     /**
@@ -209,7 +220,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: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java?rev=384271&r1=384270&r2=384271&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
Wed Mar  8 09:11:12 2006
@@ -23,6 +23,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.
@@ -30,12 +31,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;
 
     /**
@@ -45,9 +46,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;
     }
@@ -68,18 +69,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]);
@@ -87,10 +87,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];
@@ -126,7 +127,8 @@
      */
     public void setSupertypes(QName[] names) {
         resetDependencies();
-        supertypes = names;
+        supertypes.clear();
+        supertypes.addAll(Arrays.asList(names));
     }
 
     /**
@@ -164,7 +166,8 @@
      */
     public void setPropertyDefs(PropDef[] defs) {
         resetDependencies();
-        propDefs = defs;
+        propDefs.clear();
+        propDefs.addAll(Arrays.asList(defs));
     }
 
     /**
@@ -174,7 +177,8 @@
      */
     public void setChildNodeDefs(NodeDef[] defs) {
         resetDependencies();
-        nodeDefs = defs;
+        nodeDefs.clear();
+        nodeDefs.addAll(Arrays.asList(defs));
     }
 
     /**
@@ -195,7 +199,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()]);
     }
 
     /**
@@ -234,7 +241,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()]);
     }
 
     /**
@@ -245,7 +255,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 >
@@ -253,11 +266,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;
     }
 
@@ -269,11 +282,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;
     }



Mime
View raw message