jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r426536 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: ./ state/
Date Fri, 28 Jul 2006 13:57:22 GMT
Author: mreutegg
Date: Fri Jul 28 06:57:21 2006
New Revision: 426536

URL: http://svn.apache.org/viewvc?rev=426536&view=rev
Log:
SPI
- replace ChildNodeEntryImpl with new implementations
- CachingItemStateManager now uses ItemStateFactory
- WorkspaceManager implements ItemStateFactory
- Retrieving an ItemState now forces loading all ancestors by design
- NodeState does not maintain indexes of child node entries anymore. They are calculated on
demand.
- ItemStateFactory methods do not require parent NodeState anymore. The parent NodeState is
retrieved using an ItemStateManager. Which in turn may lead to recursive retrieval of ancestors
if necessary.

Removed:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeEntryImpl.java
Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/CachingItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildItemReference.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeEntry.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.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/PathElementReference.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?rev=426536&r1=426535&r2=426536&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Fri Jul 28 06:57:21 2006
@@ -31,6 +31,7 @@
 import org.apache.jackrabbit.jcr2spi.state.NodeReferences;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateManager;
 import org.apache.jackrabbit.jcr2spi.state.CachingItemStateManager;
+import org.apache.jackrabbit.jcr2spi.state.ItemStateFactory;
 import org.apache.jackrabbit.jcr2spi.operation.OperationVisitor;
 import org.apache.jackrabbit.jcr2spi.operation.AddNode;
 import org.apache.jackrabbit.jcr2spi.operation.AddProperty;
@@ -112,7 +113,8 @@
 /**
  * <code>WorkspaceManager</code>...
  */
-public class WorkspaceManager implements UpdatableItemStateManager, NamespaceStorage, NodeTypeStorage,
AccessManager {
+public class WorkspaceManager implements UpdatableItemStateManager,
+        ItemStateFactory, NamespaceStorage, NodeTypeStorage, AccessManager {
 
     private static Logger log = LoggerFactory.getLogger(WorkspaceManager.class);
 
@@ -145,7 +147,7 @@
         this.service = service;
         this.sessionInfo = sessionInfo;
 
-        cache = new CachingItemStateManager(new WorkspaceItemStateManager());
+        cache = new CachingItemStateManager(this, service.getIdFactory());
         addEventListener(cache);
 
         nsRegistry = createNamespaceRegistry();
@@ -447,66 +449,41 @@
         service.unregisterNodeTypes(sessionInfo, nodeTypeNames);
     }
 
-    //--------------------------------------------------------------------------
-
-    /**
-     * Called when local or external events occured. This method is called after
-     * changes have been applied to the repository.
-     *
-     * @param changeLog
-     * @param events the events.
-     * @param isLocal <code>true</code> if changes were local.
-     */
-    private void onEventReceived(ChangeLog changeLog, EventIterator events, boolean isLocal)
{
-        if (changeLog != null) {
-            // use current change log for notification
-            changeLog.persisted();
-        }
-
-        // notify listener
-        // need to copy events into a list because we notify multiple listeners
-        List eventList = new ArrayList();
-        while (events.hasNext()) {
-            Event e = events.nextEvent();
-            eventList.add(e);
-        }
-
-        InternalEventListener[] lstnrs = (InternalEventListener[]) listeners.toArray(new
InternalEventListener[listeners.size()]);
-        for (int i = 0; i < lstnrs.length; i++) {
-           lstnrs[i].onEvent(new EventIteratorImpl(eventList), isLocal);
-        }
-    }
+    //---------------------------------------------------< ItemStateFactory >---
 
     /**
-     * Build a new <code>NodeState</code> from the information retrieved
-     * from the <code>RepositoryService</code>.
+     * Creates the node with information retrieved from the
+     * <code>RepositoryService</code>.
      *
-     * @param id node id
-     * @return node state
-     * @throws NoSuchItemStateException
-     * @throws ItemStateException
+     * @inheritDoc
+     * @see ItemStateFactory#createNodeState(NodeId, ItemStateManager)
      */
-    private NodeState getNodeState(NodeId id)
+    public NodeState createNodeState(NodeId nodeId, ItemStateManager ism)
             throws NoSuchItemStateException, ItemStateException {
         try {
-            NodeInfo info = service.getNodeInfo(sessionInfo, id);
+            NodeInfo info = service.getNodeInfo(sessionInfo, nodeId);
             QName ntName = info.getNodetype();
             NodeId parentId = (info.getParentId() != null) ? info.getParentId() : null;
 
+            // get parent
+            NodeState parent = (parentId != null) ? (NodeState) ism.getItemState(parentId)
: null;
+            // TODO pass parent in constructor of NodeState
+
             // build the node state
             // NOTE: unable to retrieve definitionId -> needs to be retrieved
             // by the itemManager upon Node creation.
             NodeState state = new NodeState(info.getId(), ntName, parentId, ItemState.STATUS_EXISTING,
false, getIdFactory());
             // set mixin nodetypes
             state.setMixinTypeNames(info.getMixins());
-            // references to child items
 
+            // references to child items
             for (IdIterator it = info.getNodeIds(); it.hasNext(); ) {
-                NodeInfo childInfo = service.getNodeInfo(sessionInfo, (org.apache.jackrabbit.spi.NodeId)it.nextId());
+                NodeInfo childInfo = service.getNodeInfo(sessionInfo, (NodeId) it.nextId());
                 NodeId childId = childInfo.getId();
                 state.addChildNodeEntry(childInfo.getQName(), childId);
             }
 
+            // references to properties
             for (IdIterator it = info.getPropertyIds(); it.hasNext(); ) {
                 PropertyId pId = (PropertyId) it.nextId();
                 state.addPropertyName(pId.getQName());
@@ -525,18 +502,21 @@
     }
 
     /**
-     * Build a new <code>PropertyState</code> from the information retrieved
-     * from the <code>RepositoryService</code>.
+     * Creates the property with information retrieved from the
+     * <code>RepositoryService</code>.
      *
-     * @param id property id
-     * @return property state
-     * @throws NoSuchItemStateException
-     * @throws ItemStateException
+     * @inheritDoc
+     * @see ItemStateFactory#createPropertyState(PropertyId, ItemStateManager)
      */
-    private PropertyState getPropertyState(PropertyId id)
+    public PropertyState createPropertyState(PropertyId propertyId,
+                                             ItemStateManager ism)
             throws NoSuchItemStateException, ItemStateException {
         try {
-            PropertyInfo info = service.getPropertyInfo(sessionInfo, id);
+            PropertyInfo info = service.getPropertyInfo(sessionInfo, propertyId);
+
+            // get parent
+            NodeState parent = (NodeState) ism.getItemState(info.getParentId());
+            // TODO: pass parent in constructor of PropertyState
 
             // build the PropertyState
             // NOTE: unable to retrieve definitionId -> needs to be retrieved
@@ -574,6 +554,36 @@
         }
     }
 
+    //--------------------------------------------------------------------------
+
+    /**
+     * Called when local or external events occured. This method is called after
+     * changes have been applied to the repository.
+     *
+     * @param changeLog
+     * @param events the events.
+     * @param isLocal <code>true</code> if changes were local.
+     */
+    private void onEventReceived(ChangeLog changeLog, EventIterator events, boolean isLocal)
{
+        if (changeLog != null) {
+            // use current change log for notification
+            changeLog.persisted();
+        }
+
+        // notify listener
+        // need to copy events into a list because we notify multiple listeners
+        List eventList = new ArrayList();
+        while (events.hasNext()) {
+            Event e = events.nextEvent();
+            eventList.add(e);
+        }
+
+        InternalEventListener[] lstnrs = (InternalEventListener[]) listeners.toArray(new
InternalEventListener[listeners.size()]);
+        for (int i = 0; i < lstnrs.length; i++) {
+           lstnrs[i].onEvent(new EventIteratorImpl(eventList), isLocal);
+        }
+    }
+
     /**
      * Executes a sequence of operations on the repository service within
      * a given <code>SessionInfo</code>.
@@ -761,7 +771,9 @@
                 NodeId nId = operation.getNodeId();
                 NodeId vId = operation.getVersionId();
 
-                PropertyState mergeFailedState = getPropertyState(getIdFactory().createPropertyId(nId,
QName.JCR_MERGEFAILED));
+                PropertyState mergeFailedState = (PropertyState) cache.getItemState(
+                        getIdFactory().createPropertyId(nId, QName.JCR_MERGEFAILED));
+
                 QValue[] vs = mergeFailedState.getValues();
 
                 NodeId[] mergeFailedIds = new NodeId[vs.length - 1];
@@ -775,7 +787,9 @@
                     // part of 'jcr:mergefailed' any more
                 }
 
-                PropertyState predecessorState = getPropertyState(getIdFactory().createPropertyId(nId,
QName.JCR_PREDECESSORS));
+                PropertyState predecessorState = (PropertyState) cache.getItemState(
+                        getIdFactory().createPropertyId(nId, QName.JCR_PREDECESSORS));
+
                 vs = predecessorState.getValues();
 
                 boolean resolveDone = operation.resolveDone();
@@ -904,56 +918,4 @@
         }
     }
 
-    public class WorkspaceItemStateManager implements ItemStateManager {
-
-        public ItemState getItemState(ItemId id) throws NoSuchItemStateException, ItemStateException
{
-            ItemState state;
-            if (id.denotesNode()) {
-                state = getNodeState((NodeId) id);
-            } else {
-                state = getPropertyState((PropertyId) id);
-            }
-            return state;
-        }
-
-        public boolean hasItemState(ItemId id) {
-            try {
-                return service.exists(sessionInfo, id);
-            } catch (RepositoryException e) {
-                log.error(e.getMessage());
-                return false;
-            }
-        }
-
-        public NodeReferences getNodeReferences(NodeId id)
-                throws NoSuchItemStateException, ItemStateException {
-            try {
-                NodeReferencesImpl nrefs = new NodeReferencesImpl(id);
-                NodeInfo info = service.getNodeInfo(sessionInfo, id);
-                PropertyId[] refs = info.getReferences();
-                for (int i = 0; i < refs.length; i++) {
-                    PropertyInfo pInfo = service.getPropertyInfo(sessionInfo, refs[i]);
-                    nrefs.addReference(pInfo.getId());
-                }
-                return nrefs;
-            } catch (PathNotFoundException e) {
-                log.error(e.getMessage());
-                throw new NoSuchItemStateException(e.getMessage(), e);
-            } catch (RepositoryException e) {
-                throw new ItemStateException(e.getMessage(), e);
-            }
-        }
-
-        public boolean hasNodeReferences(NodeId id) {
-            try {
-                NodeInfo info = service.getNodeInfo(sessionInfo, id);
-                return info.getReferences().length > 0;
-            } catch (PathNotFoundException e) {
-                log.error(e.getMessage());
-            } catch (RepositoryException e) {
-                log.error(e.getMessage());
-            }
-            return false;
-        }
-    }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/CachingItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/CachingItemStateManager.java?rev=426536&r1=426535&r2=426536&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/CachingItemStateManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/CachingItemStateManager.java
Fri Jul 28 06:57:21 2006
@@ -23,6 +23,8 @@
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.EventIterator;
 import org.apache.jackrabbit.spi.Event;
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.jcr2spi.observation.InternalEventListener;
 
 import java.util.Map;
@@ -40,9 +42,10 @@
 public class CachingItemStateManager implements ItemStateManager, InternalEventListener {
 
     /**
-     * The underlying item state manager.
+     * The item state factory to create <code>ItemState</code>s that are not
+     * present in the cache.
      */
-    private final ItemStateManager ism;
+    private final ItemStateFactory isf;
 
     /**
      * Maps a String uuid to a {@link NodeState}.
@@ -54,8 +57,14 @@
      */
     private final PathMap path2State;
 
-    public CachingItemStateManager(ItemStateManager ism) {
-        this.ism = ism;
+    /**
+     * The Id factory.
+     */
+    private final IdFactory idFactory;
+
+    public CachingItemStateManager(ItemStateFactory isf, IdFactory idFactory) {
+        this.isf = isf;
+        this.idFactory = idFactory;
         this.uuid2PathElement = new HashMap(); // TODO: must use weak references
         path2State = new PathMap();      // TODO: must use weak references
     }
@@ -88,8 +97,8 @@
      */
     public NodeReferences getNodeReferences(NodeId id)
             throws NoSuchItemStateException, ItemStateException {
-        // TODO: caching missing
-        return ism.getNodeReferences(id);
+        // TODO: implement
+        return null;
     }
 
     /**
@@ -97,8 +106,8 @@
      * @see ItemStateManager#hasNodeReferences(NodeId)
      */
     public boolean hasNodeReferences(NodeId id) {
-        // TODO: caching missing
-        return ism.hasNodeReferences(id);
+        // TODO: caching implement
+        return false;
     }
 
     //-------------------------------< InternalEventListener >------------------
@@ -224,8 +233,8 @@
             elem = (PathMap.Element) uuid2PathElement.get(uuid);
             if (elem == null || elem.get() == null) {
                 // state identified by the uuid is not yet cached -> get from ISM
-                ItemId refId = (relPath == null) ? id : new NodeIdImpl(uuid);
-                ItemState state = ism.getItemState(refId);
+                NodeId refId = (relPath == null) ? (NodeId) id : idFactory.createNodeId(uuid);
+                NodeState state = isf.createNodeState(refId, this);
 
                 // put this state to cache
                 // but first we have to make sure that the parent of this state
@@ -265,8 +274,13 @@
         if (relPath != null) {
             PathMap.Element tmp = elem.getDescendant(relPath, true);
             if (tmp == null || tmp.get() == null) {
-                // not yet cached, load from ism
-                ItemState state = ism.getItemState(id);
+                // not yet cached, load from isf
+                ItemState state;
+                if (id.denotesNode()) {
+                    state = isf.createNodeState((NodeId) id, this);
+                } else {
+                    state = isf.createPropertyState((PropertyId) id, this);
+                }
                 // put to cache
                 if (tmp == null) {
                     tmp = elem.getDescendant(relPath, false);
@@ -331,52 +345,6 @@
             }
         } else {
             return state.getId().getRelativePath().getNameElement();
-        }
-    }
-
-    //--------------------------------------------------------< Inner class >---
-    /**
-     * Simple implementation of the NodeId interface that always wraps around a
-     * UUID String only and never takes a relative path.
-     * Since the uuid is retrieved from an existing <code>ItemId</code> there
is
-     * no need to pass the IdFactory and using this simple implementation instead.
-     */
-    private static final class NodeIdImpl implements NodeId {
-
-        private final String uuid;
-
-        public NodeIdImpl(String uuid) {
-            if (uuid == null) {
-                throw new IllegalArgumentException("Expected non-null uuid.");
-            }
-            this.uuid = uuid;
-        }
-
-        /**
-         * Always return <code>true</code>.
-         *
-         * @return true
-         */
-        public boolean denotesNode() {
-            return true;
-        }
-
-        /**
-         * Always returns a non-null string.
-         *
-         * @return uuid passed to the constructor, which is never <code>null</code>.
-         */
-        public String getUUID() {
-            return uuid;
-        }
-
-        /**
-         * Always return <code>null</code>.
-         *
-         * @return <code>null</code>
-         */
-        public Path getRelativePath() {
-            return null;
         }
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildItemReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildItemReference.java?rev=426536&r1=426535&r2=426536&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildItemReference.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildItemReference.java
Fri Jul 28 06:57:21 2006
@@ -60,14 +60,15 @@
      * Resolves this <code>ChildItemReference</code> and returns the target
      * <code>ItemState</code> of this reference.
      *
-     * @param isf    the item state factory responsible for creating node
-     *               states.
+     * @param isf the item state factory responsible for creating node states.
+     * @param ism the item state manager to access already created / known
+     *            <code>ItemState</code>s.
      * @return the <code>ItemState</code> where this reference points to.
      * @throws NoSuchItemStateException if the referenced <code>ItemState</code>
      *                                  does not exist.
      * @throws ItemStateException       if an error occurs.
      */
-    public ItemState resolve(ItemStateFactory isf)
+    public ItemState resolve(ItemStateFactory isf, ItemStateManager ism)
             throws NoSuchItemStateException, ItemStateException {
         // check if cached
         if (target != null) {
@@ -77,7 +78,7 @@
             }
         }
         // not cached. retrieve and keep weak reference to state
-        ItemState state = doResolve(isf);
+        ItemState state = doResolve(isf, ism);
         target = new WeakReference(state);
         return state;
     }
@@ -96,13 +97,15 @@
      * Resolves this <code>ChildItemReference</code> and returns the target
      * <code>ItemState</code> of this reference.
      *
-     * @param isf    the item state factory responsible for creating node
-     *               states.
+     * @param isf the item state factory responsible for creating node states.
+     * @param ism the item state manager to access already created / known
+     *            <code>ItemState</code>s.
      * @return the <code>ItemState</code> where this reference points to.
      * @throws NoSuchItemStateException if the referenced <code>ItemState</code>
      *                                  does not exist.
      * @throws ItemStateException       if an error occurs.
      */
-    protected abstract ItemState doResolve(ItemStateFactory isf)
+    protected abstract ItemState doResolve(ItemStateFactory isf,
+                                           ItemStateManager ism)
             throws NoSuchItemStateException, ItemStateException;
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeEntry.java?rev=426536&r1=426535&r2=426536&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeEntry.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeEntry.java
Fri Jul 28 06:57:21 2006
@@ -39,4 +39,18 @@
      * @return the index of this child node entry to suppport same-name siblings.
      */
     public int getIndex();
+
+    /**
+     * TODO: move parameters isf and ism to constructor of implementations of this interface
+     * @param isf the item state factory to create the node state.
+     * @param ism the item state manager to access already created / known
+     *            <code>ItemState</code>s.
+     * @return the referenced <code>NodeState</code>.
+     * @throws NoSuchItemStateException if the <code>NodeState</code> does not
+     *                                  exist anymore.
+     * @throws ItemStateException       if an error occurs while retrieving the
+     *                                  <code>NodeState</code>.
+     */
+    public NodeState getNodeState(ItemStateFactory isf, ItemStateManager ism)
+            throws NoSuchItemStateException, ItemStateException;
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java?rev=426536&r1=426535&r2=426536&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java
Fri Jul 28 06:57:21 2006
@@ -51,4 +51,13 @@
     public QName getName() {
         return name;
     }
+
+    /**
+     * @inheritDoc
+     * @see ChildNodeEntry#getNodeState(ItemStateFactory, ItemStateManager)
+     */
+    public NodeState getNodeState(ItemStateFactory isf, ItemStateManager ism)
+            throws NoSuchItemStateException, ItemStateException {
+        return (NodeState) resolve(isf, ism);
+    }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java?rev=426536&r1=426535&r2=426536&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
Fri Jul 28 06:57:21 2006
@@ -16,8 +16,8 @@
  */
 package org.apache.jackrabbit.jcr2spi.state;
 
-import org.apache.jackrabbit.name.Path;
-import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.PropertyId;
 
 /**
  * <code>ItemStateFactory</code> provides methods to create child
@@ -28,48 +28,32 @@
 
     /**
      * Creates the child <code>NodeState</code> with the given
-     * <code>uuid</code>, which has the given <code>parent</code>.
+     * <code>nodeId</code>.
      *
-     * @param parent the parent of the <code>NodeState</code> to create.
-     * @param uuid   the uuid of the <code>NodeState</code> to create.
+     * @param nodeId the id of the <code>NodeState</code> to create.
+     * @param ism    the item state manager to retrievev the parent of the
+     *               <code>NodeState</code> to create.
      * @return the created <code>NodeState</code>.
      * @throws NoSuchItemStateException if there is no such <code>NodeState</code>.
      * @throws ItemStateException       if an error occurs while retrieving the
      *                                  <code>NodeState</code>.
      */
-    public NodeState createNodeState(NodeState parent, String uuid)
+    public NodeState createNodeState(NodeId nodeId, ItemStateManager ism)
             throws NoSuchItemStateException, ItemStateException;
 
     /**
-     * Creates the child <code>NodeState</code> with the given
-     * <code>nameElement</code>, which has the given <code>parent</code>.
-     *
-     * @param parent      the parent of the <code>NodeState</code> to create.
-     * @param nameElement the name element of the <code>NodeState</code> to
-     *                    create.
-     * @return the created <code>NodeState</code>.
-     * @throws NoSuchItemStateException if there is no such <code>NodeState</code>.
-     * @throws ItemStateException       if an error occurs while retrieving the
-     *                                  <code>NodeState</code>.
-     */
-    public NodeState createNodeState(NodeState parent,
-                                     Path.PathElement nameElement)
-            throws NoSuchItemStateException, ItemStateException;
-
-    /**
-     * Creates the <code>PropertyState</code> with the given <code>name</code>,
-     * which has the given <code>parent</code>.
+     * Creates the <code>PropertyState</code> with the given
+     * <code>propertyId</code>.
      *
-     * @param parent       the parent of the <code>PropertyState</code> to
-     *                     create.
-     * @param propertyName the name of the <code>PropertyState</code> to
-     *                     create.
+     * @param propertyId the id of the <code>PropertyState</code> to create.
+     * @param ism        the item state manager to retrievev the parent of the
+     *                   <code>NodeState</code> to create.
      * @return the created <code>PropertyState</code>.
      * @throws NoSuchItemStateException if there is no such <code>PropertyState</code>.
      * @throws ItemStateException       if an error occurs while retrieving the
      *                                  <code>PropertyState</code>.
      */
-    public PropertyState createPropertyState(NodeState parent,
-                                             QName propertyName)
+    public PropertyState createPropertyState(PropertyId propertyId,
+                                             ItemStateManager ism)
             throws NoSuchItemStateException, ItemStateException;
 }

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?rev=426536&r1=426535&r2=426536&view=diff
==============================================================================
--- 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
Fri Jul 28 06:57:21 2006
@@ -873,7 +873,7 @@
      * <code>ChildNodeEntries</code> also provides an unmodifiable
      * <code>List</code> view.
      */
-    private static class ChildNodeEntries implements List, Cloneable {
+    private class ChildNodeEntries implements List, Cloneable {
 
         // insertion-ordered map of entries (key=NodeId, value=entry)
         private LinkedMap entries;
@@ -930,7 +930,6 @@
 
         ChildNodeEntry add(QName nodeName, NodeId id) {
             List siblings = null;
-            int index = Path.INDEX_UNDEFINED;
             Object obj = nameMap.get(nodeName);
             if (obj != null) {
                 if (obj instanceof ArrayList) {
@@ -943,11 +942,9 @@
                     siblings.add(obj);
                     nameMap.put(nodeName, siblings);
                 }
-                index = siblings.size();
             }
-            index++;
 
-            ChildNodeEntry entry = new ChildNodeEntryImpl(nodeName, id, index);
+            ChildNodeEntry entry = createChildNodeEntry(nodeName, id);
             if (siblings != null) {
                 siblings.add(entry);
             } else {
@@ -999,16 +996,6 @@
             // remove from ordered entries map
             entries.remove(removedEntry.getId());
 
-            // update indices of subsequent same-name siblings
-            for (int i = index - 1; i < siblings.size(); i++) {
-                ChildNodeEntry oldEntry = (ChildNodeEntry) siblings.get(i);
-                ChildNodeEntry newEntry = new ChildNodeEntryImpl(nodeName, oldEntry.getId(),
oldEntry.getIndex() - 1);
-                // overwrite old entry with updated entry in siblings list
-                siblings.set(i, newEntry);
-                // overwrite old entry with updated entry in ordered entries map
-                entries.put(newEntry.getId(), newEntry);
-            }
-
             // clean up name lookup map if necessary
             if (siblings.size() == 0) {
                 // no more entries with that name left:
@@ -1126,6 +1113,22 @@
             }
 
             return result;
+        }
+
+        /**
+         * Creates a <code>ChildNodeEntry</code> instance based on
+         * <code>nodeName</code>, <code>id</code> and <code>index</code>.
+         *
+         * @param nodeName the name of the child node.
+         * @param id the id of the child node.
+         * @return
+         */
+        private ChildNodeEntry createChildNodeEntry(QName nodeName, NodeId id) {
+            if (id.getRelativePath() != null) {
+                return new PathElementReference(NodeState.this, nodeName, NodeState.this.idFactory);
+            } else {
+                return new UUIDReference(NodeState.this, id, nodeName);
+            }
         }
 
         //-------------------------------------------< unmodifiable List view >

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java?rev=426536&r1=426535&r2=426536&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java
Fri Jul 28 06:57:21 2006
@@ -47,13 +47,13 @@
 
     /**
      * @inheritDoc
-     * @see ChildItemReference#doResolve(ItemStateFactory)
+     * @see ChildItemReference#doResolve(ItemStateFactory, ItemStateManager)
      * <p/>
      * Returns a <code>NodeState</code>.
      */
-    protected ItemState doResolve(ItemStateFactory isf)
+    protected ItemState doResolve(ItemStateFactory isf, ItemStateManager ism)
             throws NoSuchItemStateException, ItemStateException {
-        return isf.createNodeState(parent, Path.create(getName(), getIndex()).getNameElement());
+        return isf.createNodeState(getId(), ism);
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java?rev=426536&r1=426535&r2=426536&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java
Fri Jul 28 06:57:21 2006
@@ -17,6 +17,8 @@
 package org.apache.jackrabbit.jcr2spi.state;
 
 import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.PropertyId;
 
 /**
  * <code>PropertyReference</code> implements a reference to a property state.
@@ -24,24 +26,31 @@
 public class PropertyReference extends ChildItemReference {
 
     /**
+     * IdFactory to create an ItemId based on the parent NodeId
+     */
+    private final IdFactory idFactory;
+
+    /**
      * Creates a new <code>PropertyReference</code>.
      *
      * @param parent the parent <code>NodeState</code> where the property
      *               belongs to.
      * @param name   the name of the property.
      */
-    public PropertyReference(NodeState parent, QName name) {
+    public PropertyReference(NodeState parent, QName name, IdFactory idFactory) {
         super(parent, name);
+        this.idFactory = idFactory;
     }
 
     /**
      * @inheritDoc
-     * @see ChildItemReference#doResolve(ItemStateFactory)
+     * @see ChildItemReference#doResolve(ItemStateFactory, ItemStateManager)
      * <p/>
      * Returns a <code>PropertyState</code>.
      */
-    protected ItemState doResolve(ItemStateFactory isf)
+    protected ItemState doResolve(ItemStateFactory isf, ItemStateManager ism)
             throws NoSuchItemStateException, ItemStateException {
-        return isf.createPropertyState(parent, name);
+        PropertyId id = idFactory.createPropertyId(parent.getNodeId(), name);
+        return isf.createPropertyState(id, ism);
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java?rev=426536&r1=426535&r2=426536&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java
Fri Jul 28 06:57:21 2006
@@ -50,13 +50,13 @@
 
     /**
      * @inheritDoc
-     * @see ChildItemReference#doResolve(ItemStateFactory)
+     * @see ChildItemReference#doResolve(ItemStateFactory, ItemStateManager)
      * <p/>
      * Returns a <code>NodeState</code>.
      */
-    protected ItemState doResolve(ItemStateFactory isf)
+    protected ItemState doResolve(ItemStateFactory isf, ItemStateManager ism)
             throws NoSuchItemStateException, ItemStateException {
-        return isf.createNodeState(parent, childId.getUUID());
+        return isf.createNodeState(childId, ism);
     }
 
     /**



Mime
View raw message