jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1171176 - in /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: ./ hierarchy/ operation/ state/ version/
Date Thu, 15 Sep 2011 17:05:40 GMT
Author: mduerig
Date: Thu Sep 15 17:05:40 2011
New Revision: 1171176

URL: http://svn.apache.org/viewvc?rev=1171176&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP) 
refactor: use cast function instead of explicit cast wherever cast is provably correct

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemCache.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEntry.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEventListener.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/UniqueIdResolver.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Remove.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionImpl.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemCache.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemCache.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemCache.java
Thu Sep 15 17:05:40 2011
@@ -65,7 +65,7 @@ public class ItemCache implements ItemLi
      * or {@code null} if there's no corresponding cache entry.
      */
     public NodeImpl getNode(NodeState state) {
-        return (NodeImpl) cache.get(state);
+        return cast(cache.get(state));
     }
 
     /**
@@ -78,7 +78,7 @@ public class ItemCache implements ItemLi
      * or {@code null} if there's no corresponding cache entry.
      */
     public PropertyImpl getProperty(PropertyState state) {
-        return (PropertyImpl) cache.get(state);
+        return cast(cache.get(state));
     }
 
     /**

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
Thu Sep 15 17:05:40 2011
@@ -28,6 +28,7 @@ import org.apache.jackrabbit.jcr2spi.sta
 import org.apache.jackrabbit.jcr2spi.state.Status;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.commons.util.Unchecked;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,6 +41,8 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
 
+import static org.apache.jackrabbit.spi.commons.util.Unchecked.cast;
+
 /**
  * {@code ItemImpl}...
  */
@@ -107,7 +110,7 @@ public abstract class ItemImpl<STATE_TYP
         checkStatus();
 
         // special treatment for root node
-        if (state.isNode() && ((NodeState)state).isRoot()) {
+        if (state.isNode() && Unchecked.<NodeState>cast(state).isRoot()) {
             String msg = "Root node doesn't have a parent.";
             log.debug(msg);
             throw new ItemNotFoundException(msg);
@@ -120,7 +123,7 @@ public abstract class ItemImpl<STATE_TYP
     @Override
     public int getDepth() throws RepositoryException {
         checkStatus();
-        if (state.isNode() && ((NodeState)state).isRoot()) {
+        if (state.isNode() && Unchecked.<NodeState>cast(state).isRoot()) {
             // shortcut
             return Path.ROOT_DEPTH;
         }
@@ -158,7 +161,7 @@ public abstract class ItemImpl<STATE_TYP
             return false;
         }
         if (otherItem instanceof ItemImpl) {
-            ItemImpl<?> other = (ItemImpl<?>) otherItem;
+            ItemImpl<?> other = cast(otherItem);
             if (state == other.state) {
                 return true;
             }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java
Thu Sep 15 17:05:40 2011
@@ -30,6 +30,7 @@ import org.apache.jackrabbit.jcr2spi.ver
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.util.Unchecked;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -267,10 +268,11 @@ public class ItemManager implements Item
      * @throws RepositoryException
      */
     public ItemImpl<?> getItem(HierarchyEntry<?> hierarchyEntry) throws RepositoryException
{
+        //noinspection IfStatementWithIdenticalBranches
         if (hierarchyEntry.denotesNode()) {
-            return getItem((NodeEntry) hierarchyEntry);
+            return getItem(Unchecked.<NodeEntry>cast(hierarchyEntry));
         } else {
-            return getItem((PropertyEntry) hierarchyEntry);
+            return getItem(Unchecked.<PropertyEntry>cast(hierarchyEntry));
         }
     }
 
@@ -412,13 +414,13 @@ public class ItemManager implements Item
     public void created(ItemState<?> state) {
         if (state.isNode()) {
             try {
-                createNodeInstance((NodeState) state);
+                createNodeInstance(Unchecked.<NodeState>cast(state));
             } catch (RepositoryException e) {
                 // log warning and ignore
                 log.warn("Unable to create Node instance: " + e.getMessage());
             }
         } else {
-            createPropertyInstance((PropertyState) state);
+            createPropertyInstance(Unchecked.<PropertyState>cast(state));
         }
     }
 

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEntry.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEntry.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEntry.java
Thu Sep 15 17:05:40 2011
@@ -36,6 +36,8 @@ import javax.jcr.RepositoryException;
 import java.lang.ref.Reference;
 import java.lang.ref.SoftReference;
 
+import static org.apache.jackrabbit.spi.commons.util.Unchecked.cast;
+
 /**
  * {@code HierarchyEntryImpl} implements base functionality for child node
  * and property references.
@@ -422,10 +424,10 @@ public abstract class HierarchyEntry<STA
         try {
             ItemStateFactory isf = getItemStateFactory();
             if (denotesNode()) {
-                NodeEntry ne = (NodeEntry) this;
+                NodeEntry ne = cast(this);
                 isf.createNodeState(ne.getWorkspaceId(), ne);
             } else {
-                PropertyEntry pe = (PropertyEntry) this;
+                PropertyEntry pe = cast(this);
                 isf.createPropertyState(pe.getWorkspaceId(), pe);
             }
         } catch (ItemNotFoundException e) {

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEventListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEventListener.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEventListener.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/HierarchyEventListener.java
Thu Sep 15 17:05:40 2011
@@ -25,6 +25,7 @@ import org.apache.jackrabbit.spi.EventFi
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.commons.util.Unchecked;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,6 +38,8 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
+import static org.apache.jackrabbit.spi.commons.util.Unchecked.cast;
+
 /**
  * {@code HierarchyEventListener}...
  */
@@ -156,7 +159,7 @@ public class HierarchyEventListener impl
                     }
                 }
                 if (parent != null && parent.denotesNode()) {
-                    ((NodeEntry) parent).refresh(ev);
+                    Unchecked.<NodeEntry>cast(parent).refresh(ev);
                     it.remove();
                     progress = true;
                 }
@@ -168,7 +171,12 @@ public class HierarchyEventListener impl
             int type = event.getType();
 
             NodeId parentId = event.getParentId();
-            NodeEntry parent = parentId != null ? (NodeEntry) hierarchyMgr.lookup(parentId)
: null;
+            HierarchyEntry<?> parentEntry = parentId != null ? hierarchyMgr.lookup(parentId)
: null;
+            if (!parentEntry.denotesNode()) {
+                throw new IllegalArgumentException("Invalid parentId in event: " + parentId);
+            }
+
+            NodeEntry parent = cast(parentEntry);
             switch (type) {
                 case Event.NODE_REMOVED:
                 case Event.PROPERTY_REMOVED:

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java
Thu Sep 15 17:05:40 2011
@@ -46,6 +46,7 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.name.PathBuilder;
 import org.apache.jackrabbit.spi.commons.util.Arrays;
 import org.apache.jackrabbit.spi.commons.util.Function1;
+import org.apache.jackrabbit.spi.commons.util.Unchecked;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -1221,14 +1222,15 @@ public class NodeEntry extends Hierarchy
      */
     void internalRemoveChildEntry(HierarchyEntry<?> childEntry) {
         if (childEntry.denotesNode()) {
-            if (childNodeEntries.remove((NodeEntry) childEntry) == null) {
-                childNodeAttic.remove((NodeEntry) childEntry);
+            NodeEntry childNodeEntry = cast(childEntry);
+            if (childNodeEntries.remove(childNodeEntry) == null) {
+                childNodeAttic.remove(childNodeEntry);
             }
         } else {
             Name propName = childEntry.getName();
             PropertyEntry atticEntry = propertiesInAttic.get(propName);
             if (atticEntry == null) {
-                properties.remove((PropertyEntry) childEntry);
+                properties.remove(Unchecked.<PropertyEntry>cast(childEntry));
             } else if (atticEntry == childEntry) {
                 propertiesInAttic.remove(propName);
             } // else: no such prop-entry. should not get here

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/PropertyEntry.java
Thu Sep 15 17:05:40 2011
@@ -27,6 +27,8 @@ import org.apache.jackrabbit.spi.Propert
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.RepositoryException;
 
+import static org.apache.jackrabbit.spi.commons.util.Unchecked.cast;
+
 /**
  * {@code PropertyEntryImpl} implements a reference to a property state.
  */
@@ -117,7 +119,7 @@ public class PropertyEntry extends Hiera
             throw new IllegalArgumentException();
         }
 
-        SetPropertyValue op = (SetPropertyValue) operation;
+        SetPropertyValue op = cast(operation);
         if (op.getPropertyState().getHierarchyEntry() != this) {
             throw new IllegalArgumentException();
         }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/UniqueIdResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/UniqueIdResolver.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/UniqueIdResolver.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/UniqueIdResolver.java
Thu Sep 15 17:05:40 2011
@@ -93,7 +93,7 @@ public class UniqueIdResolver implements
         synchronized (lookUp) {
             if (Status.isTerminal(state.getStatus())) {
                 if (state.isNode()) {
-                    NodeEntry entry = (NodeEntry) state.getHierarchyEntry();
+                    NodeEntry entry = cast(state.getHierarchyEntry());
                     String uniqueID = entry.getUniqueID();
                     if (uniqueID != null) {
                         NodeEntry mapEntry = lookUp.get(uniqueID);
@@ -122,7 +122,7 @@ public class UniqueIdResolver implements
     @Override
     public void created(ItemState<?> state) {
         if (state.isNode()) {
-            NodeEntry entry = (NodeEntry) state.getHierarchyEntry();
+            NodeEntry entry = cast(state.getHierarchyEntry());
             String uniqueID = entry.getUniqueID();
             if (uniqueID != null) {
                 if (!lookUp.containsKey(uniqueID) || lookUp.get(uniqueID) != entry) {
@@ -163,10 +163,10 @@ public class UniqueIdResolver implements
     //------------------------------------------------------------< private >---
     
     private void putToLookup(String uniqueID, NodeEntry entry) {
-        Object previous = lookUp.put(uniqueID, entry);
+        NodeEntry previous = lookUp.put(uniqueID, entry);
         if (previous != null) {
             // some other entry existed before with the same uniqueID
-            if (sameEntry((NodeEntry) previous, entry)) {
+            if (sameEntry(previous, entry)) {
                 log.debug("Replacement of NodeEntry identified by UniqueID");
             } else {
                 // if the new entry represents the externally moved/renamed
@@ -177,7 +177,7 @@ public class UniqueIdResolver implements
                 // ancestors. in this case there is not need to 'remove'
                 // the previous entry. instead it is just removed from this
                 // cache and left for collection.
-                ((NodeEntry) previous).remove();
+                previous.remove();
             }
         }
     }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Remove.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Remove.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Remove.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Remove.java
Thu Sep 15 17:05:40 2011
@@ -20,6 +20,7 @@ import org.apache.jackrabbit.jcr2spi.sta
 import org.apache.jackrabbit.jcr2spi.state.ItemStateValidator;
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.commons.util.Unchecked;
 
 import javax.jcr.RepositoryException;
 
@@ -96,7 +97,7 @@ public class Remove extends TransientOpe
     //------------------------------------------------------------< Factory >---
 
     public static Operation create(ItemState<?> state) throws RepositoryException {
-        if (state.isNode() && ((NodeState) state).getDefinition().allowsSameNameSiblings())
{
+        if (state.isNode() && Unchecked.<NodeState>cast(state).getDefinition().allowsSameNameSiblings())
{
             // in case of SNS-siblings make sure the parent hierarchy entry has
             // its child entries loaded.
             assertChildNodeEntries(state.getParent());

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
Thu Sep 15 17:05:40 2011
@@ -28,6 +28,7 @@ import org.apache.jackrabbit.spi.QItemDe
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.commons.util.Unchecked;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -357,7 +358,7 @@ public class ItemStateValidator {
      * @throws RepositoryException
      */
     public void checkRemoveItem(ItemState<?> targetState, int options) throws RepositoryException
{
-        if (targetState.isNode() && ((NodeState)targetState).isRoot()) {
+        if (targetState.isNode() && Unchecked.<NodeState>cast(targetState).isRoot())
{
             // root node
             throw new ConstraintViolationException("Cannot remove root node.");
         }
@@ -400,7 +401,7 @@ public class ItemStateValidator {
      * @throws RepositoryException
      */
     private void checkIsCheckedOut(ItemState<?> itemState) throws RepositoryException
{
-        NodeState nodeState = itemState.isNode() ? (NodeState)itemState : itemState.getParent();
+        NodeState nodeState = itemState.isNode() ? Unchecked.<NodeState>cast(itemState)
: itemState.getParent();
         mgrProvider.getVersionStateManager().checkIsCheckedOut(nodeState);
     }
 
@@ -416,7 +417,7 @@ public class ItemStateValidator {
     private void checkLock(ItemState<?> itemState) throws RepositoryException {
         // make sure there's no foreign lock present the node (or the parent node
         // in case the state represents a PropertyState).
-        NodeState nodeState = itemState.isNode() ? (NodeState)itemState : itemState.getParent();
+        NodeState nodeState = itemState.isNode() ? Unchecked.<NodeState>cast(itemState)
: itemState.getParent();
         mgrProvider.getLockStateManager().checkLock(nodeState);
     }
 
@@ -432,9 +433,9 @@ public class ItemStateValidator {
     private static void checkProtection(ItemState<?> itemState) throws RepositoryException
{
         QItemDefinition def;
         if (itemState.isNode()) {
-            def = ((NodeState)itemState).getDefinition();
+            def = Unchecked.<NodeState>cast(itemState).getDefinition();
         } else {
-            def = ((PropertyState)itemState).getDefinition();
+            def = Unchecked.<PropertyState>cast(itemState).getDefinition();
         }
         checkProtection(def);
     }
@@ -462,9 +463,9 @@ public class ItemStateValidator {
     private static void checkRemoveConstraints(ItemState<?> itemState) throws RepositoryException
{
         QItemDefinition definition;
         if (itemState.isNode()) {
-            definition = ((NodeState)itemState).getDefinition();
+            definition = Unchecked.<NodeState>cast(itemState).getDefinition();
         } else {
-            definition = ((PropertyState)itemState).getDefinition();
+            definition = Unchecked.<PropertyState>cast(itemState).getDefinition();
         }
         checkProtection(definition);
     }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
Thu Sep 15 17:05:40 2011
@@ -36,6 +36,8 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
+import static org.apache.jackrabbit.spi.commons.util.Unchecked.cast;
+
 /**
  * {@code NodeState} represents the state of a {@code Node}.
  */
@@ -121,7 +123,7 @@ public class NodeState extends ItemState
                 throw new IllegalArgumentException("Attempt to merge node state with property
state.");
             }
             synchronized (another) {
-                NodeState nState = (NodeState) another;
+                NodeState nState = cast(another);
 
                 if (!nodeTypeName.equals(nState.nodeTypeName)) {
                     nodeTypeName = nState.nodeTypeName;

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
Thu Sep 15 17:05:40 2011
@@ -23,6 +23,7 @@ import org.apache.jackrabbit.spi.Propert
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint;
+import org.apache.jackrabbit.spi.commons.util.Unchecked;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -129,10 +130,11 @@ public class PropertyState extends ItemS
                 throw new IllegalArgumentException("Attempt to merge property state with
node state.");
             }
 
-            PropertyDiffer result = new PropertyDiffer(data, ((PropertyState) another).data);
+            PropertyData anotherData = Unchecked.<PropertyState>cast(another).data;
+            PropertyDiffer result = new PropertyDiffer(data, anotherData);
 
             // reset the pInfo to point to the pInfo of another state.
-            data = ((PropertyState) another).data;
+            data = anotherData;
             // if transient changes should be preserved OR if there are not
             // transient changes, return the differ and postpone the effort of
             // calculating the diff (the test if this state got internally changed)).

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
Thu Sep 15 17:05:40 2011
@@ -35,6 +35,7 @@ import org.apache.jackrabbit.spi.Propert
 import org.apache.jackrabbit.spi.RepositoryService;
 import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.util.Unchecked;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -148,7 +149,7 @@ public class WorkspaceItemStateFactory e
                 }
 
                 assertMatchingPath(info, entry);
-                return createNodeState((NodeInfo) info, (NodeEntry) entry);
+                return createNodeState((NodeInfo) info, Unchecked.<NodeEntry>cast(entry));
             }
         }
         catch (PathNotFoundException e) {
@@ -228,7 +229,7 @@ public class WorkspaceItemStateFactory e
                 }
 
                 assertMatchingPath(info, entry);
-                return createPropertyState((PropertyInfo) info, (PropertyEntry) entry);
+                return createPropertyState((PropertyInfo) info, Unchecked.<PropertyEntry>cast(entry));
             }
 
         } catch (PathNotFoundException e) {

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java
Thu Sep 15 17:05:40 2011
@@ -46,6 +46,8 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
+import static org.apache.jackrabbit.spi.commons.util.Unchecked.cast;
+
 /**
  * {@code VersionHistoryImpl}...
  */
@@ -253,7 +255,7 @@ public class VersionHistoryImpl extends 
         if (otherItem instanceof VersionHistoryImpl) {
             // since all version histories are referenceable, protected and live
             // in the same workspace, a simple comparison of the UUIDs is sufficient.
-            VersionHistoryImpl other = (VersionHistoryImpl) otherItem;
+            VersionHistoryImpl other = cast(otherItem);
             return vhEntry.getUniqueID().equals(other.vhEntry.getUniqueID());
         }
         return false;

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionImpl.java?rev=1171176&r1=1171175&r2=1171176&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionImpl.java
Thu Sep 15 17:05:40 2011
@@ -36,6 +36,8 @@ import javax.jcr.version.VersionHistory;
 import javax.jcr.version.VersionIterator;
 import java.util.Calendar;
 
+import static org.apache.jackrabbit.spi.commons.util.Unchecked.cast;
+
 /**
  * {@code VersionImpl}...
  */
@@ -118,7 +120,7 @@ public class VersionImpl extends NodeImp
         if (otherItem instanceof VersionImpl) {
             // since all versions are referenceable, protected and live
             // in the same workspace, a simple comparison of the UUIDs is sufficient
-            VersionImpl other = (VersionImpl) otherItem;
+            VersionImpl other = cast(otherItem);
             try {
                 return getUUID().equals(other.getUUID());
             } catch (RepositoryException e) {



Mime
View raw message