jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1183266 - /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
Date Fri, 14 Oct 2011 09:43:27 GMT
Author: mduerig
Date: Fri Oct 14 09:43:27 2011
New Revision: 1183266

URL: http://svn.apache.org/viewvc?rev=1183266&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
cleanup, simplification

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java?rev=1183266&r1=1183265&r2=1183266&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
Fri Oct 14 09:43:27 2011
@@ -78,37 +78,27 @@ public abstract class ItemState<ENTRY_TY
     /**
      * Constructs an item state
      *
-     * @param entry
+     * @param hierarchyEntry
      * @param isf
      * @param definitionProvider
      */
-    protected ItemState(Status initialStatus, ENTRY_TYPE entry, ItemStateFactory isf,
+    protected ItemState(Status status, ENTRY_TYPE hierarchyEntry, ItemStateFactory isf,
             ItemDefinitionProvider definitionProvider) {
         
-        if (entry == null) {
+        if (hierarchyEntry == null) {
             IllegalArgumentException e = new IllegalArgumentException("Cannot build ItemState
from 'null' HierarchyEntry");
             log.error(e.getMessage(), e);
             throw e;
         }
-        switch (initialStatus) {
-            case EXISTING:
-            case NEW:
-            case EXISTING_REMOVED:
-                status = initialStatus;
-                break;
-            case _UNDEFINED_:
-            case INVALIDATED:
-            case EXISTING_MODIFIED:
-            case STALE_MODIFIED:
-            case STALE_DESTROYED:
-            case MODIFIED:
-            case REMOVED:
-                IllegalArgumentException e = new IllegalArgumentException("illegal status:
" + initialStatus);
-                log.error(e.getMessage(), e);
-                throw e;
 
+        if (status != Status.EXISTING && status != Status.NEW && status !=
Status.EXISTING_REMOVED) {
+            IllegalArgumentException e = new IllegalArgumentException("illegal status: "
+ status);
+            log.error(e.getMessage(), e);
+            throw e;
         }
-        hierarchyEntry = entry;
+
+        this.status = status;
+        this.hierarchyEntry = hierarchyEntry;
         this.isf = isf;
         this.definitionProvider = definitionProvider;
     }
@@ -220,8 +210,7 @@ public abstract class ItemState<ENTRY_TY
      * @return the status of this item.
      */
     public final Status getStatus() {
-        // Call calculateStatus to apply a possible pending invalidation
-        // in the entry hierarchy.
+        // Call calculateStatus to apply a possible pending invalidation in the entry hierarchy.
         hierarchyEntry.calculateStatus();
         return status;
     }
@@ -242,6 +231,7 @@ public abstract class ItemState<ENTRY_TY
             log.error(e.getMessage(), e);
             throw e;
         }
+
         if (Status.isValidStatusChange(oldStatus, newStatus)) {
             status = Status.getNewStatus(oldStatus, newStatus);
         } else {
@@ -250,6 +240,7 @@ public abstract class ItemState<ENTRY_TY
             log.error(e.getMessage(), e);
             throw e;
         }
+
         // Notify listeners about status change
         // copy listeners to array to avoid ConcurrentModificationException
         ItemStateLifeCycleListener[] la;
@@ -261,6 +252,7 @@ public abstract class ItemState<ENTRY_TY
                 aLa.statusChanged(this, oldStatus);
             }
         }
+
         if (status == Status.MODIFIED) {
             // change back tmp MODIFIED status, that is used as marker only
             // inform listeners about (external) changes.
@@ -324,28 +316,12 @@ public abstract class ItemState<ENTRY_TY
      * Marks this item state as modified.
      */
     void markModified() throws InvalidItemStateException {
-        switch (status) {
-            case EXISTING:
-                setStatus(Status.EXISTING_MODIFIED);
-                break;
-            case EXISTING_MODIFIED:
-                // already modified, do nothing
-                break;
-            case NEW:
-                // still new, do nothing
-                break;
-            case STALE_DESTROYED:
-            case STALE_MODIFIED:
-                // should actually not get here because item should check before
-                // it modifies an item state.
-                throw new InvalidItemStateException("Cannot mark stale state modified.");
-            case EXISTING_REMOVED:
-            case _UNDEFINED_:
-            case INVALIDATED:
-            case MODIFIED:
-            case REMOVED:
-                String msg = "Cannot mark item state with status '" + status + "' modified.";
-                throw new InvalidItemStateException(msg);
+        if (status == Status.EXISTING) {
+            setStatus(Status.EXISTING_MODIFIED);
+        }
+        else if (status != Status.EXISTING_MODIFIED && status != Status.NEW) {
+            // Do nothing if already modified or new, otherwise throw
+            throw new InvalidItemStateException("Cannot mark item state with status '" +
status + "' modified.");
         }
     }
 



Mime
View raw message