jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r462717 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state: ItemState.java Status.java WorkspaceItemStateManager.java
Date Wed, 11 Oct 2006 06:57:24 GMT
Author: angela
Date: Tue Oct 10 23:57:24 2006
New Revision: 462717

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

- more todos
- revert tmp status 'modified' immediately after notifying overlaying state.
- setStatus: delegate validation to Status

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/Status.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateManager.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?view=diff&rev=462717&r1=462716&r2=462717
==============================================================================
--- 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 Oct 10 23:57:24 2006
@@ -272,45 +272,11 @@
         if (Status.isTerminalStatus(oldStatus)) {
             throw new IllegalStateException("State is already in terminal status " + oldStatus);
         }
-
-        if (isWorkspaceState()) {
-            switch (newStatus) {
-                case Status.EXISTING:
-                case Status.MODIFIED:
-                case Status.REMOVED:
-                    status = newStatus;
-                    break;
-
-                case Status.NEW:
-                case Status.EXISTING_REMOVED:
-                case Status.EXISTING_MODIFIED:
-                case Status.STALE_MODIFIED:
-                case Status.STALE_DESTROYED:
-                default:
-                    String msg = "Illegal status " + newStatus + " for 'workspace' state.";
-                    log.debug(msg);
-                    throw new IllegalArgumentException(msg);
-            }
+        if (Status.isValidStatusChange(oldStatus, newStatus, isWorkspaceState)) {
+            status = newStatus;
         } else {
-            switch (newStatus) {
-                case Status.NEW:
-                case Status.EXISTING:
-                case Status.EXISTING_REMOVED:
-                case Status.EXISTING_MODIFIED:
-                case Status.STALE_MODIFIED:
-                case Status.STALE_DESTROYED:
-                case Status.REMOVED:
-                    status = newStatus;
-                    break;
-
-                case Status.MODIFIED:
-                default:
-                    String msg = "Illegal status " + newStatus + " for 'session' state.";
-                    log.debug(msg);
-                    throw new IllegalArgumentException(msg);
-            }
+            throw new IllegalArgumentException("Invalid new status " + newStatus + " for
state with status " + oldStatus);
         }
-
         // notifiy listeners about status change
         // copy listeners to array to avoid ConcurrentModificationException
         ItemStateLifeCycleListener[] la;
@@ -322,6 +288,13 @@
                 ((ItemStateLifeCycleListener) la[i]).statusChanged(this, oldStatus);
             }
         }
+        if (status == Status.MODIFIED) {
+            // change back tmp MODIFIED status, that is used only to have a marker
+            // to inform the overlaying state, that it needs to synchronize with
+            // its overlayed state again
+            // TODO: improve...
+            status = Status.EXISTING;
+        }
     }
 
     /**
@@ -515,8 +488,6 @@
                 break;
             case Status.MODIFIED:
                 if (previousStatus == Status.EXISTING) {
-                    // change back // TODO: improve...
-                    state.status = Status.EXISTING;
                     // underlying state has been modified
                     if (isTransient()) {
                         setStatus(Status.STALE_MODIFIED);
@@ -527,9 +498,6 @@
                             setStatus(Status.EXISTING);
                         }
                     }
-                } else {
-                    // ILLEGAL
-                    throw new IllegalArgumentException();
                 }
                 break;
             case Status.REMOVED:

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java?view=diff&rev=462717&r1=462716&r2=462717
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java
Tue Oct 10 23:57:24 2006
@@ -67,4 +67,57 @@
         return status == REMOVED || status == STALE_DESTROYED;
     }
 
+    public static boolean isValidStatusChange(int oldStatus, int newStatus,
+                                              boolean isWorkspaceState) {
+        if (oldStatus == newStatus) {
+            return true;
+        }
+        boolean isValid = false;
+        if (isWorkspaceState) {
+            switch (newStatus) {
+                case EXISTING:
+                    isValid = (oldStatus == MODIFIED);
+                    break;
+                case MODIFIED:
+                    isValid = (oldStatus == EXISTING);
+                    break;
+                case REMOVED:
+                    isValid = (oldStatus == EXISTING);
+                    break;
+                // default: no other status possible : -> false
+            }
+        } else {
+            switch (newStatus) {
+               case EXISTING:
+                   switch (oldStatus) {
+                       case NEW: /* save */
+                       case EXISTING_MODIFIED: /* save, revert */
+                       case EXISTING_REMOVED:  /* revert */
+                       case STALE_MODIFIED:    /* revert */
+                           isValid = true;
+                           break;
+                       /* REMOVED, STALE_DESTROYED -> false */
+                   }
+                   break;
+               case EXISTING_MODIFIED:
+                   isValid = (oldStatus == EXISTING);
+                   break;
+               case EXISTING_REMOVED:
+                   isValid = (oldStatus == EXISTING || oldStatus == EXISTING_MODIFIED);
+                   break;
+               case STALE_MODIFIED:
+               case STALE_DESTROYED:
+                   isValid = (oldStatus == EXISTING_MODIFIED);
+                   break;
+               case REMOVED:
+                   isValid = (oldStatus == NEW || oldStatus == EXISTING || oldStatus == EXISTING_REMOVED);
+                   break;
+               /* default:
+                  NEW cannot change state to NEW -> false
+                  MODIFIED never applicable to session state -> false */
+
+            }
+        }
+        return isValid;
+    }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateManager.java?view=diff&rev=462717&r1=462716&r2=462717
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateManager.java
Tue Oct 10 23:57:24 2006
@@ -63,6 +63,7 @@
         }
         // inform all transient states, that they have been persisted and must
         // connect to their workspace state (and eventually reload the data).
+        // TODO: TOBEFIXED. only used to set status to EXISTING in order (which is probably
wrong)
         changeLog.persisted();
 
         // inform all existing workspace states about the transient modifications



Mime
View raw message