jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r470475 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: NodeImpl.java state/ItemState.java state/NodeState.java state/entry/ChildNodeReference.java
Date Thu, 02 Nov 2006 19:02:41 GMT
Author: angela
Date: Thu Nov  2 11:02:39 2006
New Revision: 470475

URL: http://svn.apache.org/viewvc?view=rev&rev=470475
Log:
work in progress

- index if unresolved cne was always 1
- add NodeState.getIndex() and simplify Node.getIndex() and ItemState.getPath()

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/entry/ChildNodeReference.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java?view=diff&rev=470475&r1=470474&r2=470475
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
Thu Nov  2 11:02:39 2006
@@ -557,23 +557,7 @@
      */
     public int getIndex() throws RepositoryException {
         checkStatus();
-
-        if (getNodeState().getDefinition().allowsSameNameSiblings()) {
-            NodeState parentState = getItemState().getParent();
-            if (parentState == null) {
-                // the root node cannot have same-name siblings; always return the
-                // default index
-                return Path.INDEX_DEFAULT;
-            }
-            ChildNodeEntry entry = parentState.getChildNodeEntry(getNodeState());
-            if (entry == null) {
-                String msg = "Unable to retrieve index for: " + safeGetJCRPath();
-                throw new RepositoryException(msg);
-            }
-            return entry.getIndex();
-        } else {
-            return Path.INDEX_DEFAULT;
-        }
+        return getNodeState().getIndex();
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java?view=diff&rev=470475&r1=470474&r2=470475
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
Thu Nov  2 11:02:39 2006
@@ -23,7 +23,6 @@
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.jcr2spi.state.entry.ChildNodeEntry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -218,23 +217,17 @@
         // recursively build path of parent
         buildPath(builder, parentState);
 
+        QName name = state.getQName();
         if (state.isNode()) {
-            NodeState nodeState = (NodeState) state;
-            ChildNodeEntry entry = parentState.getChildNodeEntry(nodeState);
-            if (entry == null) {
-                String msg = "Failed to build path of " + state + ": parent has no such child
entry.";
-                log.debug(msg);
-                throw new ItemNotFoundException(msg);
-            }
+            int index = ((NodeState)state).getIndex();
             // add to path
-            if (entry.getIndex() == Path.INDEX_DEFAULT) {
-                builder.addLast(entry.getName());
+            if (index == Path.INDEX_DEFAULT) {
+                builder.addLast(name);
             } else {
-                builder.addLast(entry.getName(), entry.getIndex());
+                builder.addLast(name, index);
             }
         } else {
             PropertyState propState = (PropertyState) state;
-            QName name = propState.getQName();
             // add to path
             builder.addLast(name);
         }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?view=diff&rev=470475&r1=470474&r2=470475
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
Thu Nov  2 11:02:39 2006
@@ -33,6 +33,7 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.ItemExistsException;
+import javax.jcr.ItemNotFoundException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -280,6 +281,29 @@
     }
 
     /**
+     * Returns the index of this node state.
+     *
+     * @return the index.
+     */
+    public int getIndex() throws ItemNotFoundException {
+        if (parent == null) {
+            // the root state may never have siblings
+            return Path.INDEX_DEFAULT;
+        }
+
+        if (getDefinition().allowsSameNameSiblings()) {
+            ChildNodeEntry entry = getParent().getChildNodeEntry(this);
+            if (entry == null) {
+                String msg = "Unable to retrieve index for: " + this;
+                throw new ItemNotFoundException(msg);
+            }
+            return entry.getIndex();
+        } else {
+            return Path.INDEX_DEFAULT;
+        }
+    }
+
+    /**
      * Returns the name of this node's node type.
      *
      * @return the name of this node's node type.
@@ -393,7 +417,7 @@
      *         <code>NodeState</code> or <code>null</code> if there's
no
      *         matching entry.
      */
-    public synchronized ChildNodeEntry getChildNodeEntry(NodeState nodeState) {
+    private synchronized ChildNodeEntry getChildNodeEntry(NodeState nodeState) {
         return childNodeEntries.get(nodeState);
     }
 
@@ -581,27 +605,32 @@
      * Returns the index of the given <code>ChildNodeEntry</code> and with
      * <code>name</code>.
      *
-     * @param name the name of the child node.
      * @param cne  the <code>ChildNodeEntry</code> instance.
      * @return the index of the child node entry or <code>0</code> if it is not
      *         found in this <code>NodeState</code>.
      */
-    public int getChildNodeIndex(QName name, ChildNodeEntry cne) {
-        List sns = childNodeEntries.get(name);
+    public int getChildNodeIndex(ChildNodeEntry cne) {
+        List sns = childNodeEntries.get(cne.getName());
         // index is one based
         int index = 1;
         for (Iterator it = sns.iterator(); it.hasNext(); ) {
-            ChildNodeEntry e = (ChildNodeEntry) it.next();
-            if (e == cne) {
+            ChildNodeEntry entry = (ChildNodeEntry) it.next();
+            if (entry == cne) {
                 return index;
             }
-            // skip removed entries
-            try {
-                if (e.isAvailable() && e.getNodeState().isValid()) {
-                    index++;
+            // skip entries that belong to removed or invalidated states.
+            // NOTE, that in this case the nodestate must be available from the cne.
+            if (entry.isAvailable()) {
+                try {
+                    if (entry.getNodeState().isValid()) {
+                        index++;
+                    }
+                } catch (ItemStateException e) {
+                    // probably removed or stale
                 }
-            } catch (ItemStateException ex) {
-                // probably removed or stale
+            } else {
+                // cne has not been resolved yet -> increase counter.
+                index++;
             }
         }
         // not found

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/entry/ChildNodeReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/entry/ChildNodeReference.java?view=diff&rev=470475&r1=470474&r2=470475
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/entry/ChildNodeReference.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/entry/ChildNodeReference.java
Thu Nov  2 11:02:39 2006
@@ -100,7 +100,7 @@
      * @see ChildNodeEntry#getIndex()
      */
     public int getIndex() {
-        return parent.getChildNodeIndex(getName(), this);
+        return parent.getChildNodeIndex(this);
     }
 
     /**



Mime
View raw message