jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r328639 - in /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: CachingHierarchyManager.java PathMap.java
Date Wed, 26 Oct 2005 12:20:33 GMT
Author: stefan
Date: Wed Oct 26 05:20:29 2005
New Revision: 328639

URL: http://svn.apache.org/viewcvs?rev=328639&view=rev
Log:
JCR-261 iterative removal of same-name sibling nodes might under certain circumstances throw
unexpected exceptions

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/PathMap.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java?rev=328639&r1=328638&r2=328639&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
Wed Oct 26 05:20:29 2005
@@ -291,7 +291,7 @@
             while (iter.hasNext()) {
                 PathMap.Element child = (PathMap.Element) iter.next();
                 NodeState.ChildNodeEntry cne = modified.getChildNodeEntry(
-                        child.getName(), child.getIndex() + 1);
+                        child.getName(), child.getNormalizedIndex());
                 if (cne == null) {
                     // Item does not exist, remove
                     child.remove();

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/PathMap.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/PathMap.java?rev=328639&r1=328638&r2=328639&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/PathMap.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/PathMap.java Wed Oct 26
05:20:29 2005
@@ -154,7 +154,8 @@
         private QName name;
 
         /**
-         * index associated with this element
+         * 1-based index associated with this element where index=0 is
+         * equivalent to index=1)
          */
         private int index;
 
@@ -184,6 +185,7 @@
          * @param nameIndex position where child is inserted
          */
         public void insert(Path.PathElement nameIndex) {
+            // convert 1-based index value to 0-base value
             int index = getOneBasedIndex(nameIndex) - 1;
             if (children != null) {
                 ArrayList list = (ArrayList) children.get(nameIndex.getName());
@@ -206,6 +208,7 @@
          *         none exists.
          */
         private Element getChild(Path.PathElement nameIndex) {
+            // convert 1-based index value to 0-base value
             int index = getOneBasedIndex(nameIndex) - 1;
             Element element = null;
 
@@ -224,6 +227,7 @@
          * @param element element to add
          */
         public void put(Path.PathElement nameIndex, Element element) {
+            // convert 1-based index value to 0-base value
             int index = getOneBasedIndex(nameIndex) - 1;
             if (children == null) {
                 children = new HashMap();
@@ -259,6 +263,7 @@
          * @return removed child, may be <code>null</code>
          */
         public Element remove(Path.PathElement nameIndex) {
+            // convert 1-based index value to 0-base value
             int index = getOneBasedIndex(nameIndex) - 1;
             if (children != null) {
                 ArrayList list = (ArrayList) children.get(nameIndex.getName());
@@ -321,11 +326,27 @@
         }
 
         /**
-         * Return the index of this element
+         * Return the non-normalized 1-based index of this element. Note that
+         * this method can return a value of 0 which should be treated as 1.
          * @return index
+         * @see #getNormalizedIndex()
          */
         public int getIndex() {
             return index;
+        }
+
+        /**
+         * Return the 1-based index of this element.
+         * Same as {@link #getIndex()} except that an index value of 0
+         * is automatically converted to 1.
+         * @return 1-based index
+         */
+        public int getNormalizedIndex() {
+            if (index == 0) {
+                return 1;
+            } else {
+                return index;
+            }
         }
 
         /**



Mime
View raw message