jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r430020 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: ./ state/
Date Wed, 09 Aug 2006 10:13:54 GMT
Author: mreutegg
Date: Wed Aug  9 03:13:49 2006
New Revision: 430020

URL: http://svn.apache.org/viewvc?rev=430020&view=rev
Log:
- Remove TransientItemStateListener
- Create property states and child node states on NodeState

Removed:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateListener.java
Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
    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/ChildItemReference.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/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/NodeStateListener.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/PropertyState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientChangeLog.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.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/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java?rev=430020&r1=430019&r2=430020&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
Wed Aug  9 03:13:49 2006
@@ -19,12 +19,12 @@
 import org.apache.commons.collections.map.ReferenceMap;
 import org.apache.jackrabbit.jcr2spi.state.ItemState;
 import org.apache.jackrabbit.jcr2spi.state.SessionItemStateManager;
-import org.apache.jackrabbit.jcr2spi.state.TransientItemStateListener;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateException;
 import org.apache.jackrabbit.jcr2spi.state.StaleItemStateException;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateValidator;
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.state.PropertyState;
+import org.apache.jackrabbit.jcr2spi.state.ItemStateListener;
 import org.apache.jackrabbit.jcr2spi.operation.Remove;
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
 import org.apache.jackrabbit.jcr2spi.util.LogUtil;
@@ -58,8 +58,9 @@
 
 /**
  * <code>ItemImpl</code>...
+ * TODO: remove status in ItemImpl and ask item state for status!
  */
-public abstract class ItemImpl implements Item, TransientItemStateListener {
+public abstract class ItemImpl implements Item, ItemStateListener {
 
     private static Logger log = LoggerFactory.getLogger(ItemImpl.class);
 
@@ -295,7 +296,7 @@
         itemStateMgr.execute(rm);
     }
 
-    //--------------------------------------------< TransientItemStateListener >
+    //-----------------------------------------------------< ItemStateListener >
     /**
      * {@inheritDoc}
      */
@@ -412,26 +413,6 @@
         notifyInvalidated();
         // now render this instance 'invalid'
         status = STATUS_INVALIDATED;
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public void stateOverlaid(ItemState overlayer) {
-        state.removeListener(this);
-        state = overlayer;
-        state.addListener(this);
-        status = STATUS_MODIFIED;
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public void stateUncovering(ItemState overlayer) {
-        state.removeListener(this);
-        state = overlayer.getOverlayedState();
-        state.addListener(this);
-        status = STATUS_NORMAL;
     }
 
     //----------------------------------------------------------< LiveCycle >---

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=430020&r1=430019&r2=430020&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
Wed Aug  9 03:13:49 2006
@@ -621,7 +621,7 @@
                 }
             }
 
-            state.setValues(qValues);
+            state.internalSetValues(qValues);
 
             // register as listener
             // TODO check if needed

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=430020&r1=430019&r2=430020&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
Wed Aug  9 03:13:49 2006
@@ -64,6 +64,23 @@
     }
 
     /**
+     * Creates a new <code>ChildItemReference</code> with the given parent
+     * <code>NodeState</code> and an already initialized child item state.
+     *
+     * @param parent the <code>NodeState</code> that owns this child node
+     *               reference.
+     * @param child  the child item state.
+     * @param name   the name of the child item.
+     * @param isf    the item state factory to re-create the item state.
+     */
+    public ChildItemReference(NodeState parent, ItemState child, QName name, ItemStateFactory
isf) {
+        this.parent = parent;
+        this.name = name;
+        this.isf = isf;
+        this.target = new WeakReference(child);
+    }
+
+    /**
      * Resolves this <code>ChildItemReference</code> and returns the target
      * <code>ItemState</code> of this reference. This method may return a
      * cached <code>ItemState</code> if this method was called before already

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=430020&r1=430019&r2=430020&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
Wed Aug  9 03:13:49 2006
@@ -38,6 +38,17 @@
     }
 
     /**
+     * Creates a new <code>ChildNodeReference</code> with the given parent
+     * <code>NodeState</code> and an already initialized child node state.
+     *
+     * @param child  the child node state.
+     * @param isf    the item state factory to re-create the node state.
+     */
+    public ChildNodeReference(NodeState child, ItemStateFactory isf) {
+        super(child.getParent(), child, null, isf); // TODO: get name from child instead
of null
+    }
+
+    /**
      * @inheritDoc
      * @see ChildNodeEntry#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?rev=430020&r1=430019&r2=430020&view=diff
==============================================================================
--- 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
Wed Aug  9 03:13:49 2006
@@ -278,57 +278,50 @@
     }
 
     /**
-     * Notify the transient state listeners that this state has overlayed
-     * another state.
-     *
-     * @param overlayer the state that now overlays the state that the listener
-     *                  is registered to.
+     * Notify the life cycle listeners that this state has changed its status.
      */
-    protected void notifyStateOverlaid(ItemState overlayer) {
+    protected void notifyStatusChanged(int oldStatus) {
         // copy listeners to array to avoid ConcurrentModificationException
         ItemStateListener[] la;
         synchronized (listeners) {
             la = (ItemStateListener[]) listeners.toArray(new ItemStateListener[listeners.size()]);
         }
         for (int i = 0; i < la.length; i++) {
-            if (la[i] instanceof TransientItemStateListener) {
-                ((TransientItemStateListener) la[i]).stateOverlaid(overlayer);
+            if (la[i] instanceof ItemStateLifeCycleListener) {
+                ((ItemStateLifeCycleListener) la[i]).statusChanged(this, oldStatus);
             }
         }
     }
 
     /**
-     * Notify the transient state listeners that this state no longer overlays
-     * another state.
+     * Marks this item state as modified.
      */
-    protected void notifyStateUncovering() {
-        // copy listeners to array to avoid ConcurrentModificationException
-        ItemStateListener[] la;
-        synchronized (listeners) {
-            la = (ItemStateListener[]) listeners.toArray(new ItemStateListener[listeners.size()]);
-        }
-        for (int i = 0; i < la.length; i++) {
-            if (la[i] instanceof TransientItemStateListener) {
-                ((TransientItemStateListener) la[i]).stateUncovering(this);
-            }
+    protected void markModified() {
+        switch (status) {
+            case STATUS_EXISTING:
+                setStatus(STATUS_EXISTING_MODIFIED);
+                break;
+            case STATUS_EXISTING_MODIFIED:
+                // already modified, do nothing
+                break;
+            case STATUS_NEW:
+                // still new, do nothing
+                break;
+            case STATUS_STALE_DESTROYED:
+            case STATUS_STALE_MODIFIED:
+                // should actually get here because item should check before
+                // it modifies an item state. do nothing because item state
+                // is stale anyway.
+                break;
+            case STATUS_EXISTING_REMOVED:
+            case STATUS_UNDEFINED:
+            default:
+                String msg = "Cannot mark item state with status " +
+                        status + " modified.";
+                throw new IllegalStateException(msg);
         }
     }
 
-    /**
-     * Notify the life cycle listeners that this state has changed its status.
-     */
-    protected void notifyStatusChanged(int oldStatus) {
-        // copy listeners to array to avoid ConcurrentModificationException
-        ItemStateListener[] la;
-        synchronized (listeners) {
-            la = (ItemStateListener[]) listeners.toArray(new ItemStateListener[listeners.size()]);
-        }
-        for (int i = 0; i < la.length; i++) {
-            if (la[i] instanceof ItemStateLifeCycleListener) {
-                ((ItemStateLifeCycleListener) la[i]).statusChanged(this, oldStatus);
-            }
-        }
-    }
 
     //-------------------------------------------------------< public methods >
     /**

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=430020&r1=430019&r2=430020&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
Wed Aug  9 03:13:49 2006
@@ -29,6 +29,7 @@
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
+import javax.jcr.ItemExistsException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -57,6 +58,7 @@
     private QName[] mixinTypeNames = new QName[0];
 
     /**
+     * TODO: id is not stable unless sole uuid.
      * The id of this node state.
      */
     private NodeId id;
@@ -399,6 +401,31 @@
     }
 
     /**
+     * TODO: move this method to a node state implementation which contains all transient
related methods?
+     *
+     * Adds a child node state to this node state.
+     *
+     * @param child the node state to add.
+     * @param uuid  the uuid of the child node state or <code>null</code> if
+     *              <code>child</code> cannot be identified with a uuid.
+     * @throws IllegalArgumentException if <code>this</code> is not the parent
+     *                                  of <code>child</code>.
+     */
+    synchronized void addChildNodeState(NodeState child, String uuid) {
+        if (child.getParent() != this) {
+            throw new IllegalArgumentException("This NodeState is not the parent of child");
+        }
+        ChildNodeEntry cne;
+        if (uuid != null) {
+            cne = new UUIDReference(child, isf);
+        } else {
+            cne = new PathElementReference(child, isf, idFactory);
+        }
+        childNodeEntries.add(cne);
+        markModified();
+    }
+
+    /**
      * Renames a new <code>ChildNodeEntry</code>.
      *
      * @param oldName <code>QName</code> object specifying the entry's old name
@@ -495,7 +522,7 @@
     }
 
     /**
-     * Adds a property name entry.
+     * Adds a property name entry. This method will not create a property!
      *
      * @param propName <code>QName</code> object specifying the property name
      */
@@ -504,6 +531,30 @@
     }
 
     /**
+     * TODO: move this method to a node state implementation which contains all transient
related methods?
+     *
+     * Adds a property state to this node state.
+     *
+     * @param propState the property state to add.
+     * @throws ItemExistsException      if <code>this</code> node state already
+     *                                  contains a property state with the same
+     *                                  name as <code>propState</code>.
+     * @throws IllegalArgumentException if <code>this</code> is not the parent
+     *                                  of <code>propState</code>.
+     */
+    synchronized void addPropertyState(PropertyState propState) throws ItemExistsException
{
+        if (propState.getParent() != this) {
+            throw new IllegalArgumentException("This NodeState is not the parent of propState");
+        }
+        QName propertyName = propState.getQName();
+        if (properties.containsKey(propertyName)) {
+            throw new ItemExistsException(propertyName.toString());
+        }
+        properties.put(propertyName, new PropertyReference(propState, isf, idFactory));
+        markModified();
+    }
+
+    /**
      * Removes a property name entry.
      *
      * @param propName <code>QName</code> object specifying the property name
@@ -868,6 +919,7 @@
      */
     private class ChildNodeEntries implements List, Cloneable {
 
+        // TODO: turn this into a linked set. NodeId cannot be use as key!
         // insertion-ordered map of entries (key=NodeId, value=entry)
         private LinkedMap entries;
         // map used for lookup by name
@@ -946,6 +998,31 @@
             entries.put(id, entry);
 
             return entry;
+        }
+
+        void add(ChildNodeEntry cne) {
+            QName nodeName = cne.getName();
+            List siblings = null;
+            Object obj = nameMap.get(nodeName);
+            if (obj != null) {
+                if (obj instanceof ArrayList) {
+                    // map entry is a list of siblings
+                    siblings = (ArrayList) obj;
+                } else {
+                    // map entry is a single child node entry,
+                    // convert to siblings list
+                    siblings = new ArrayList();
+                    siblings.add(obj);
+                    nameMap.put(nodeName, siblings);
+                }
+            }
+
+            if (siblings != null) {
+                siblings.add(cne);
+            } else {
+                nameMap.put(nodeName, cne);
+            }
+            entries.put(cne.getId(), cne);
         }
 
         void addAll(List entriesList) {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeStateListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeStateListener.java?rev=430020&r1=430019&r2=430020&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeStateListener.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeStateListener.java
Wed Aug  9 03:13:49 2006
@@ -25,7 +25,7 @@
  *
  * @see NodeState#addListener
  */
-public interface NodeStateListener extends TransientItemStateListener {
+public interface NodeStateListener extends ItemStateListener {
 
     /**
      * Called when a child node has been added

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=430020&r1=430019&r2=430020&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
Wed Aug  9 03:13:49 2006
@@ -48,6 +48,20 @@
     }
 
     /**
+     * Creates a new <code>PathElementReference</code> with the given parent
+     * <code>NodeState</code> and an already initialized child node state.
+     *
+     * @param child  the child node state.
+     * @param isf    the item state factory to re-create the node state.
+     * @param idFactory the <code>IdFactory</code> to create new ItemIds
+     */
+    public PathElementReference(NodeState child, ItemStateFactory isf,
+                                IdFactory idFactory) {
+        super(child, isf);
+        this.idFactory = idFactory;
+    }
+
+    /**
      * @inheritDoc
      * @see ChildItemReference#doResolve()
      * <p/>

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=430020&r1=430019&r2=430020&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
Wed Aug  9 03:13:49 2006
@@ -36,11 +36,24 @@
      * @param parent    the parent <code>NodeState</code> where the property
      *                  belongs to.
      * @param name      the name of the property.
-     * @param isf       the item state factory to create the node state.
+     * @param isf       the item state factory to create the property state.
      * @param idFactory the id factory to create new ids.
      */
     public PropertyReference(NodeState parent, QName name, ItemStateFactory isf, IdFactory
idFactory) {
         super(parent, name, isf);
+        this.idFactory = idFactory;
+    }
+
+    /**
+     * Creates a new <code>PropertyReference</code> for an property state that
+     * already exists.
+     *
+     * @param propState the property state.
+     * @param isf       the item state factory to re-create the property state.
+     * @param idFactory the id factory to create new ids.
+     */
+    public PropertyReference(PropertyState propState, ItemStateFactory isf, IdFactory idFactory)
{
+        super(propState.getParent(), propState, propState.getQName(), isf);
         this.idFactory = idFactory;
     }
 

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java?rev=430020&r1=430019&r2=430020&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
Wed Aug  9 03:13:49 2006
@@ -210,6 +210,19 @@
      * @param values the new values
      */
     public void setValues(QValue[] values) {
+        internalSetValues(values);
+        markModified();
+    }
+
+    /**
+     * TODO: rather separate PropertyState into interface and implementation
+     * TODO: and move internalSetValues to implementation only.
+     * Sets the value(s) of this property without marking this property state
+     * as modified.
+     *
+     * @param values the new values
+     */
+    public void internalSetValues(QValue[] values) {
         this.values = values;
     }
 

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?rev=430020&r1=430019&r2=430020&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
Wed Aug  9 03:13:49 2006
@@ -293,8 +293,6 @@
         Iterator it = new IteratorChain(changeLog.addedStates(), changeLog.modifiedStates());
         while (it.hasNext()) {
             ItemState transientState = (ItemState) it.next();
-            // notify uncovering of transient state
-            transientState.notifyStateUncovering();
             // dispose the transient state, it is no longer used
             transientStateMgr.disposeItemState(transientState);
         }
@@ -398,12 +396,6 @@
             // this will indirectly (through stateDiscarded listener method)
             // either restore or permanently invalidate the wrapping Item instances
             ItemState transientState = (ItemState) transIter.next();
-            switch (transientState.getStatus()) {
-                case ItemState.STATUS_STALE_MODIFIED:
-                case ItemState.STATUS_STALE_DESTROYED:
-                case ItemState.STATUS_EXISTING_MODIFIED:
-                    transientState.notifyStateUncovering();
-            }
             transientStateMgr.disposeItemState(transientState);
         }
         // process list of deleted states
@@ -951,10 +943,10 @@
     public void visit(Move operation) throws LockException, ConstraintViolationException,
AccessDeniedException, ItemExistsException, UnsupportedRepositoryOperationException, VersionException,
RepositoryException {
 
         // retrieve states and assert they are modifiable
-        NodeState srcState = create(getNodeState(operation.getNodeId()));
-        NodeState srcParent = create(getNodeState(operation.getSourceParentId()));
+        NodeState srcState = getNodeState(operation.getNodeId());
+        NodeState srcParent = getNodeState(operation.getSourceParentId());
 
-        NodeState destParent = create(getNodeState(operation.getDestinationParentId()));
+        NodeState destParent = getNodeState(operation.getDestinationParentId());
 
         // state validation: move-Source can be removed from old/added to new parent
         validator.checkRemoveItem(srcState,
@@ -993,15 +985,6 @@
         // change definition of target node
         srcState.setDefinition(newDefinition);
 
-        // store states
-        store(srcState);
-        if (renameOnly) {
-            store(srcParent);
-        } else {
-            store(srcParent);
-            store(destParent);
-        }
-
         // remember operation
         transientStateMgr.addOperation(operation);
     }
@@ -1037,7 +1020,7 @@
         boolean anyRemoved;
 
         QName[] mixinNames = operation.getMixinNames();
-        NodeState nState = create(getNodeState(operation.getNodeId()));
+        NodeState nState = getNodeState(operation.getNodeId());
 
         // mixin-names to be execute on the nodestate (and corresponding property state)
         if (mixinNames != null && mixinNames.length > 0) {
@@ -1082,9 +1065,6 @@
                     // should not occur, since existance has been asserted before
                     throw new RepositoryException(e);
                 }
-            } else {
-                // alternative: make sure changes on nodeState are reflected in state manager.
-                store(nState);
             }
         }
 
@@ -1161,8 +1141,7 @@
      * @inheritDoc
      */
     public void visit(ReorderNodes operation) throws ConstraintViolationException, AccessDeniedException,
UnsupportedRepositoryOperationException, VersionException, RepositoryException {
-        // make sure the parent state is modifiable
-        NodeState parent = create(getNodeState(operation.getParentId()));
+        NodeState parent = getNodeState(operation.getParentId());
 
         NodeId srcId = operation.getInsertNodeId();
         NodeId beforeId = operation.getBeforeNodeId();
@@ -1216,9 +1195,9 @@
         }
 
         // modify the the parent node state ...
+        // TODO: do not set whole list but rather implement a proper reorder on NodeState!
+        // TODO: then remove NodeState.setChildNodeEntries()
         parent.setChildNodeEntries(list);
-        // ... and mark it as modified on the stateMgr.
-        store(parent);
 
         // remember the operation
         transientStateMgr.addOperation(operation);
@@ -1295,23 +1274,14 @@
         // given property definition.
         validator.validate(propertyType, values, pDef);
 
-        // assert transient parent state
-        NodeState parentState = create(parent);
         // create property state
-        PropertyState propState = createNew(propertyName, parentState);
+        PropertyState propState = transientStateMgr.createPropertyState(parent, propertyName);
         propState.setDefinition(pDef);
 
         // NOTE: callers must make sure, the property type is not 'undefined'
         propState.setType(propertyType);
         propState.setMultiValued(pDef.isMultiple());
         propState.setValues(values);
-
-        // now add new property entry to parent
-        parentState.addPropertyName(propertyName);
-        // store parent
-        store(parentState);
-        // store property
-        store(propState);
     }
 
     private void addNodeState(NodeState parent, QName nodeName, QName nodeTypeName, String
uuid, QNodeDefinition definition, int options) throws RepositoryException, ConstraintViolationException,
AccessDeniedException, UnsupportedRepositoryOperationException, NoSuchNodeTypeException, ItemExistsException,
VersionException {
@@ -1338,16 +1308,9 @@
             }
         }
 
-        // assert parent state is transient
-        NodeState parentState = create(parent);
-        // ev. create new id
-        NodeId newId = (uuid == null) ? idFactory.createNodeId(UUID.randomUUID().toString())
: idFactory.createNodeId(uuid);
-        NodeState nodeState = createNew(newId, nodeTypeName, parentState);
+        NodeState nodeState = transientStateMgr.createNodeState(nodeName, uuid, nodeTypeName,
parent);
         nodeState.setDefinition(definition);
 
-        // now add new child node entry to parent
-        parentState.addChildNodeEntry(nodeName, newId);
-
         EffectiveNodeType ent = validator.getEffectiveNodeType(nodeState);
         // add 'auto-create' properties defined in node type
         QPropertyDefinition[] pda = ent.getAutoCreatePropDefs();
@@ -1367,11 +1330,6 @@
             int opt = ItemStateValidator.CHECK_LOCK | ItemStateValidator.CHECK_COLLISION;
             addNodeState(nodeState, nd.getQName(), nd.getDefaultPrimaryType(), null, nd,
opt);
         }
-
-        // store node
-        store(nodeState);
-        // store parent
-        store(parentState);
     }
 
     // TODO: TO-BE-FIXED. removal of same-name-sibling node must include reordering
@@ -1382,16 +1340,12 @@
         // recursively remove the complete tree including the given node state.
         boolean success = false;
         try {
-            // assert parent is transient state
-            NodeState parent = create(itemState.getParent());
+            NodeState parent = itemState.getParent();
             if (itemState.isNode()) {
                 removeNodeState(parent, (NodeState)itemState);
             } else {
                 removePropertyState(parent, (PropertyState)itemState);
             }
-            // store parent
-            // DIFF JR: only store parent if removal is successful... check if correct.
-            store(parent);
             success = true;
         } finally {
             if (!success) {
@@ -1412,11 +1366,11 @@
      * @param target
      */
     private void removeNodeState(NodeState parent, NodeState target) throws ItemNotFoundException,
RepositoryException {
-        NodeState modifiableTarget = create(target);
+        // TODO: implement this functionality in NodeState. i.e. target.remove()
         // remove child node entry from parent
-        parent.removeChildNodeEntry(modifiableTarget.getNodeId());
+        parent.removeChildNodeEntry(target.getNodeId());
         // remove target
-        recursiveRemoveNodeState(modifiableTarget);
+        recursiveRemoveNodeState(target);
     }
 
     /**
@@ -1425,11 +1379,11 @@
      * @param target
      */
     private void removePropertyState(NodeState parent, PropertyState target) {
-        PropertyState modifiableTarget = create(target);
+        // TODO: implement this functionality in PropertyState. i.e. target.remove()
         // remove property entry
-        parent.removePropertyName(modifiableTarget.getQName());
+        parent.removePropertyName(target.getQName());
         // destroy property state
-        destroy(modifiableTarget);
+        destroy(target);
     }
 
     /**
@@ -1512,11 +1466,8 @@
         // make sure property is valid according to its definition
         validator.validate(valueType, iva, propState.getDefinition());
 
-        // make sure the state is modifiable
-        PropertyState propertyState = create(propState);
-
         // free old values as necessary
-        QValue[] oldValues = propertyState.getValues();
+        QValue[] oldValues = propState.getValues();
         if (oldValues != null) {
             for (int i = 0; i < oldValues.length; i++) {
                 QValue old = oldValues[i];
@@ -1528,108 +1479,8 @@
             }
         }
 
-        propertyState.setValues(iva);
-        propertyState.setType(valueType);
-
-        // store property
-        store(propertyState);
-    }
-
-    /**
-     * Creates a {@link NodeState} instance representing new,
-     * i.e. not yet existing state. Call {@link #store}
-     * on the returned object to make it persistent.
-     *
-     * @param id           the id of the node
-     * @param nodeTypeName qualified node type name
-     * @param parent     parent node's id
-     * @return a node state
-     * @throws IllegalStateException if the manager is not in edit mode.
-     */
-    private NodeState createNew(NodeId id, QName nodeTypeName, NodeState parent)
-            throws IllegalStateException {
-        // DIFF JACKRABBIT: return workspaceItemStateMgr.createNew(id, nodeTypeName, parentId);
-        return transientStateMgr.createNodeState(id, nodeTypeName, parent);
-    }
-
-    /**
-     * Creates a modifiable {@link NodeState} instances representing an existing
-     * <code>state</code>. Call {@link #store(ItemState)} on the returned
-     * object to make it persistent.
-     * <p/>
-     * If <code>state</code> is a transient state, it is immediately returned.
-     * Otherwise, after a transient state has been created that overlays
-     * <code>state</code> {@link TransientItemStateListener} registered on
-     * <code>state</code> are notified about the overlay via the the callback
-     * {@link TransientItemStateListener#stateOverlaid(ItemState)}.
-     *
-     * @param state the node as retrieved with {@link #getItemState(ItemId)}
-     * @return a modifiable {@link NodeState}.
-     */
-    private NodeState create(NodeState state) {
-        if (state.isTransient()) {
-            // already transient state
-            return state;
-        }
-        NodeState transientState = transientStateMgr.createNodeState(state);
-        state.notifyStateOverlaid(transientState);
-        return transientState;
-    }
-
-    /**
-     * Creates a {@link PropertyState} instance representing new,
-     * i.e. not yet existing state. Call {@link #store}
-     * on the returned object to make it persistent.
-     *
-     * @param propName   qualified property name
-     * @param parent   parent node state
-     * @return a property state
-     */
-    private PropertyState createNew(QName propName, NodeState parent) {
-        // DIFF JACKRABBIT: return workspaceItemStateMgr.createNew(propName, parentId);
-        return transientStateMgr.createPropertyState(parent, propName);
-    }
-
-    /**
-     * Creates a modifiable {@link PropertyState} instances representing an existing
-     * <code>state</code>. Call {@link #store(ItemState)} on the returned
-     * object to make it persistent.
-     * <p/>
-     * If <code>state</code> is a transient state, it is immediately returned.
-     * Otherwise, after a transient state has been created that overlays
-     * <code>state</code> {@link TransientItemStateListener} registered on
-     * <code>state</code> are notified about the overlay via the the callback
-     * {@link TransientItemStateListener#stateOverlaid(ItemState)}.
-     *
-     * @param state the node as retrieved with {@link #getItemState(ItemId)}
-     * @return a modifiable {@link PropertyState}.
-     */
-    private PropertyState create(PropertyState state) {
-        if (state.isTransient()) {
-            // already transient state
-            return state;
-        }
-        PropertyState transientState = transientStateMgr.createPropertyState(state);
-        state.notifyStateOverlaid(transientState);
-        return transientState;
-    }
-
-    /**
-     * Store the given item state, which may be a new one previously created by
-     * calling <code>createNew</code> or a modified existing state.
-     *
-     * @param state item state that should be stored
-     */
-    private void store(ItemState state) throws IllegalStateException {
-        // DIFF JACKRABBIT: workspaceItemStateMgr.store(state);
-        if (state.getStatus() == ItemState.STATUS_EXISTING_MODIFIED) {
-            transientStateMgr.modified(state);
-        } else if (state.getStatus() == ItemState.STATUS_NEW) {
-            transientStateMgr.added(state);
-        } else {
-            // todo throw InvalidItemStateException?
-            throw new IllegalStateException("invalid state: " + state.getStatus());
-        }
+        propState.setValues(iva);
+        propState.setType(valueType);
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientChangeLog.java?rev=430020&r1=430019&r2=430020&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientChangeLog.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientChangeLog.java
Wed Aug  9 03:13:49 2006
@@ -26,6 +26,8 @@
 import org.apache.commons.collections.iterators.IteratorChain;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
+
+import javax.jcr.ItemExistsException;
 import java.util.Iterator;
 
 /**
@@ -228,30 +230,20 @@
     }
 
     /**
-     * TODO: remove this method
+     * TODO: throw ItemExistsException? how to check?
      * @inheritDoc
+     * @see TransientItemStateManager#createNodeState(QName, String, QName, NodeState)
      */
-    public NodeState createNodeState(NodeId id,
+    public NodeState createNodeState(QName nodeName,
+                                     String uuid,
                                      QName nodeTypeName,
                                      NodeState parent) {
-        // DIFF JACKRABBIT: not needed anymore
-        // check map; synchronized to ensure an entry is not created twice.
-//        synchronized (addedStates) {
-//            if (addedStates.containsKey(id) || modifiedStates.containsKey(id)) {
-//                String msg = "there's already a node state instance with id " + id;
-//                log.debug(msg);
-//                throw new ItemStateException(msg);
-//            }
-//
-//            NodeState state = new NodeState(id, nodeTypeName, parentId,
-//                    initialStatus, true);
-//            // put transient state in the map
-//            addedStates.put(id, state);
-//            return state;
-//        }
-
-        // TODO: replace with call to createNewNodeState() and finally remove method
-        return new NodeState(id, parent, nodeTypeName, ItemState.STATUS_NEW, true, this);
+        NodeState nodeState = createNewNodeState(nodeName, uuid, parent);
+        nodeState.setNodeTypeName(nodeTypeName);
+        parent.addChildNodeState(nodeState, uuid);
+        addedStates.add(nodeState);
+        nodeState.addListener(this);
+        return nodeState;
     }
 
     /**
@@ -279,12 +271,16 @@
     }
 
     /**
-     * TODO: remove this method
      * @inheritDoc
+     * @see TransientItemStateManager#createPropertyState(NodeState, QName)
      */
-    public PropertyState createPropertyState(NodeState parentState, QName propName) {
-        PropertyId id = idFactory.createPropertyId(parentState.getNodeId(), propName);
-        return new PropertyState(id, parentState, ItemState.STATUS_NEW, true);
+    public PropertyState createPropertyState(NodeState parentState, QName propName)
+            throws ItemExistsException {
+        PropertyState propState = createNewPropertyState(propName, parentState);
+        parentState.addPropertyState(propState);
+        addedStates.add(propState);
+        propState.addListener(this);
+        return propState;
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java?rev=430020&r1=430019&r2=430020&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
Wed Aug  9 03:13:49 2006
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.name.QName;
 
+import javax.jcr.ItemExistsException;
 import java.util.Iterator;
 
 /**
@@ -60,16 +61,20 @@
     //----------------< methods for creating & discarding ItemState instances >
 
     /**
-     * DIFF JACKRABBIT: does not throw ItemStateException
      * Creates a new transient {@link NodeState} that does not overlay any other
      * {@link NodeState}.
      *
-     * @param id the <code>NodeId</code> of the new node state.
+     * @param name         the name of the <code>NodeState</code> to create.
+     * @param uuid         the uuid of the <code>NodeState</code> to create or
+     *                     <code>null</code> if the created <code>NodeState</code>
+     *                     cannot be identified by a UUID.
      * @param nodeTypeName name of the node type of the new node state.
-     * @param parent the parent of the new node state.
+     * @param parent       the parent of the new node state.
      * @return a new transient {@link NodeState}.
      */
-    NodeState createNodeState(NodeId id, QName nodeTypeName,
+    NodeState createNodeState(QName name,
+                              String uuid,
+                              QName nodeTypeName,
                               NodeState parent);
 
     /**
@@ -80,12 +85,17 @@
     NodeState createNodeState(NodeState overlayedState);
 
     /**
-     * DIFF JACKRABBIT: does not throw ItemStateException
-     * @param parent
-     * @param propName
-     * @return
+     * Creates a new transient property state for a given <code>parent</code>
+     * node state.
+     *
+     * @param parent   the node state where to the new property is added.
+     * @param propName the name of the property state to create.
+     * @return the created property state.
+     * @throws ItemExistsException if <code>parent</code> already has a property
+     *                             with the given name.
      */
-    PropertyState createPropertyState(NodeState parent, QName propName);
+    PropertyState createPropertyState(NodeState parent, QName propName)
+            throws ItemExistsException;
 
     /**
      * DIFF JACKRABBIT: does not throw ItemStateException

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=430020&r1=430019&r2=430020&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
Wed Aug  9 03:13:49 2006
@@ -51,6 +51,23 @@
     }
 
     /**
+     * Creates a new <code>UUIDReference</code> with the given parent
+     * <code>NodeState</code> and an already initialized child node state.
+     *
+     * @param child     the child node state.
+     * @param isf       the item state factory to re-create the node state.
+     * @throws IllegalArgumentException if the id of <code>child</code> has a
+     *                                  relative path component.
+     */
+    public UUIDReference(NodeState child, ItemStateFactory isf) {
+        super(child, isf);
+        this.childId = child.getNodeId();
+        if (childId.getRelativePath() == null) {
+            throw new IllegalArgumentException("id of child must not contain a relative path");
+        }
+    }
+
+    /**
      * @inheritDoc
      * @see ChildItemReference#doResolve()
      * <p/>



Mime
View raw message