You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2006/08/08 12:03:28 UTC

svn commit: r429622 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state: ItemState.java ItemStateLifeCycleListener.java TransientChangeLog.java

Author: mreutegg
Date: Tue Aug  8 03:03:27 2006
New Revision: 429622

URL: http://svn.apache.org/viewvc?rev=429622&view=rev
Log:
- Introduce ItemStateLifeCycleListener to keep track of status changes of an ItemState.

Added:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateLifeCycleListener.java   (with props)
Modified:
    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/TransientChangeLog.java

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=429622&r1=429621&r2=429622&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 Tue Aug  8 03:03:27 2006
@@ -165,13 +165,13 @@
      * <code>LocalItemStateManager</code> when this item state has been disposed.
      */
     void onDisposed() {
+        disconnect();
+        overlayedState = null;
+        setStatus(STATUS_UNDEFINED);
         // prepare this instance so it can be gc'ed
         synchronized (listeners) {
             listeners.clear();
         }
-        disconnect();
-        overlayedState = null;
-        status = STATUS_UNDEFINED;
     }
 
     /**
@@ -314,6 +314,22 @@
         }
     }
 
+    /**
+     * 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 >
     /**
      * Determines if this item state represents a node.
@@ -374,11 +390,17 @@
     }
 
     /**
+     * TODO: this method should be at least protected. the outside should not
+     * TODO: control the status of an item state
      * Sets the new status of this item.
      *
      * @param newStatus the new status
      */
     public void setStatus(int newStatus) {
+        if (status == newStatus) {
+            return;
+        }
+        int oldStatus = status;
         switch (newStatus) {
             case STATUS_NEW:
             case STATUS_EXISTING:
@@ -388,12 +410,13 @@
             case STATUS_STALE_DESTROYED:
             case STATUS_UNDEFINED:
                 status = newStatus;
-                return;
+                break;
             default:
                 String msg = "illegal status: " + newStatus;
                 log.debug(msg);
                 throw new IllegalArgumentException(msg);
         }
+        notifyStatusChanged(oldStatus);
     }
 
     /**
@@ -429,7 +452,7 @@
             // notify listeners
             notifyStateDiscarded();
             // reset status
-            status = STATUS_UNDEFINED;
+            setStatus(STATUS_UNDEFINED);
         }
     }
 
@@ -484,7 +507,7 @@
      */
     public void stateCreated(ItemState created) {
         // underlying state has been permanently created
-        status = STATUS_EXISTING;
+        setStatus(STATUS_EXISTING); // TODO: shouldn't the status change happen after pull?
         pull();
     }
 
@@ -494,9 +517,9 @@
     public void stateDestroyed(ItemState destroyed) {
         // underlying state has been permanently destroyed
         if (isTransient) {
-            status = STATUS_STALE_DESTROYED;
+            setStatus(STATUS_STALE_DESTROYED);
         } else {
-            status = STATUS_EXISTING_REMOVED;
+            setStatus(STATUS_EXISTING_REMOVED);
             notifyStateDestroyed();
         }
     }
@@ -507,7 +530,7 @@
     public void stateModified(ItemState modified) {
         // underlying state has been modified
         if (isTransient) {
-            status = STATUS_STALE_MODIFIED;
+            setStatus(STATUS_STALE_MODIFIED);
         } else {
             synchronized (this) {
                 // this instance represents existing state, update it

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateLifeCycleListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateLifeCycleListener.java?rev=429622&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateLifeCycleListener.java (added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateLifeCycleListener.java Tue Aug  8 03:03:27 2006
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.jcr2spi.state;
+
+/**
+ * <code>ItemStateLifeCycleListener</code> allows an implementing class to get
+ * notifications about the life cycle of an item state.
+ */
+public interface ItemStateLifeCycleListener extends ItemStateListener {
+
+    /**
+     * Called after an <code>ItemState</code> has changed its status. The new
+     * status can be retrieved by calling {@link ItemState#getStatus()}.
+     *
+     * @param state          the item state, which changed its <code>status</code>.
+     * @param previousStatus the previous status of <code>state</code>.
+     */
+    public void statusChanged(ItemState state, int previousStatus);
+}

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateLifeCycleListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=429622&r1=429621&r2=429622&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 Tue Aug  8 03:03:27 2006
@@ -35,7 +35,7 @@
  * when added.
  */
 public class TransientChangeLog extends ChangeLog
-        implements TransientItemStateManager, TransientItemStateFactory, ItemStateListener {
+        implements TransientItemStateManager, TransientItemStateFactory, ItemStateLifeCycleListener {
 
     // TODO: TO-BE-FIXED. Usage of SPI_ItemId requries different handling
 
@@ -474,7 +474,7 @@
         return new PropertyState(overlayedState, parentState, ItemState.STATUS_EXISTING, true);
     }
 
-    //---------------------------< ItemStateListener >--------------------------
+    //-----------------------< ItemStateLifeCycleListener >---------------------
 
     /**
      * @inheritDoc
@@ -506,6 +506,18 @@
      */
     public void stateDiscarded(ItemState discarded) {
         // TODO: remove from modified (and deleted?) set of change log
+    }
+
+    /**
+     * @inheritDoc
+     * @see ItemStateLifeCycleListener#statusChanged(ItemState, int)
+     */
+    public void statusChanged(ItemState state, int previousStatus) {
+        // TODO: depending on status of state adapt change log
+        // e.g. a revert on states will reset the status from
+        // 'existing modified' to 'existing'.
+        // a state which changes from 'existing' to 'existing modified' will
+        // go into the modified set of the change log, etc.
     }
 
     //--------------------------------------------------------< inner classes >