You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2009/09/18 17:20:56 UTC

svn commit: r816667 - /jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/

Author: reschke
Date: Fri Sep 18 15:20:55 2009
New Revision: 816667

URL: http://svn.apache.org/viewvc?rev=816667&view=rev
Log:
JCR-2087: parametrize generic types

Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java?rev=816667&r1=816666&r2=816667&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java Fri Sep 18 15:20:55 2009
@@ -26,7 +26,6 @@
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.ConstraintViolationException;
-import java.util.Iterator;
 import java.util.Set;
 import java.util.List;
 import java.util.ArrayList;
@@ -51,9 +50,9 @@
     /**
      * Set of operations
      */
-    private final Set operations;
+    private final Set<Operation> operations;
 
-    private final Set affectedStates;
+    private final Set<ItemState> affectedStates;
 
     /**
      * Create a new change log and populates it with operations and states
@@ -65,7 +64,7 @@
      * @throws InvalidItemStateException
      * @throws ConstraintViolationException
      */
-    ChangeLog(ItemState target, Set operations, Set affectedStates)
+    ChangeLog(ItemState target, Set<Operation> operations, Set<ItemState> affectedStates)
             throws InvalidItemStateException, ConstraintViolationException {
         this.target = target;
         this.operations = operations;
@@ -74,7 +73,7 @@
 
     //-----------------------------------------------< Inform the ChangeLog >---
     /**
-     * Call this method when this change log has been sucessfully persisted.
+     * Call this method when this change log has been successfully persisted.
      * This implementation will call {@link Operation#persisted() on the
      * individual operations followed by setting all remaining modified
      * states to EXISTING.
@@ -83,7 +82,7 @@
         List<NodeState> changedMixins = new ArrayList<NodeState>();
         List<NodeState> changedPrimaryTypes = new ArrayList<NodeState>();
 
-        Operation[] ops = (Operation[]) operations.toArray(new Operation[operations.size()]);
+        Operation[] ops = operations.toArray(new Operation[operations.size()]);
         for (int i = 0; i < ops.length; i++) {
             ops[i].persisted();
             if (ops[i] instanceof SetMixin) {
@@ -94,8 +93,7 @@
         }
         // process all remaining states that were not covered by the
         // operation persistence.
-        for (Iterator it = affectedStates.iterator(); it.hasNext();) {
-            ItemState state = (ItemState) it.next();
+        for (ItemState state : affectedStates) {
             HierarchyEntry he = state.getHierarchyEntry();
 
             switch (state.getStatus()) {
@@ -148,15 +146,14 @@
      * Revert the changes listed within this changelog
      */
     public void undo() throws RepositoryException {
-        Operation[] ops = (Operation[]) operations.toArray(new Operation[operations.size()]);
+        Operation[] ops = operations.toArray(new Operation[operations.size()]);
         for (int i = ops.length - 1; i >= 0; i--) {
             ops[i].undo();
         }
 
         // process all remaining states that were not covered by the
         // operation undo.
-        for (Iterator it = affectedStates.iterator(); it.hasNext();) {
-            ItemState state = (ItemState) it.next();
+        for (ItemState state : affectedStates) {
             switch (state.getStatus()) {
                 case Status.EXISTING_MODIFIED:
                 case Status.EXISTING_REMOVED:
@@ -200,14 +197,14 @@
     /**
      * @return set of operations.
      */
-    public Set getOperations() {
+    public Set<Operation> getOperations() {
         return operations;
     }
 
     /**
      * @return set of the affected states.
      */
-    public Set getAffectedStates() {
+    public Set<ItemState> getAffectedStates() {
         return affectedStates;
     }
 

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java?rev=816667&r1=816666&r2=816667&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java Fri Sep 18 15:20:55 2009
@@ -57,7 +57,7 @@
     /**
      * Listeners (weak references)
      */
-    private final transient Collection listeners = new WeakIdentityCollection(5);
+    private final transient Collection<ItemStateLifeCycleListener> listeners = new WeakIdentityCollection(5);
 
     /**
      * The <code>ItemStateFactory</code> which is used to create new
@@ -240,11 +240,11 @@
         } else {
             throw new IllegalArgumentException("Invalid new status " + Status.getName(newStatus) + " for state with status " + Status.getName(oldStatus));
         }
-        // notifiy listeners about status change
+        // Notify listeners about status change
         // copy listeners to array to avoid ConcurrentModificationException
         ItemStateLifeCycleListener[] la;
         synchronized (listeners) {
-            la = (ItemStateLifeCycleListener[]) listeners.toArray(new ItemStateLifeCycleListener[listeners.size()]);
+            la = listeners.toArray(new ItemStateLifeCycleListener[listeners.size()]);
         }
         for (int i = 0; i < la.length; i++) {
             if (la[i] != null) {
@@ -307,7 +307,7 @@
      *
      * @return iterator over <code>ItemStateLifeCycleListener</code>s.
      */
-    public Iterator getListeners() {
+    public Iterator<ItemStateLifeCycleListener> getListeners() {
         return Collections.unmodifiableCollection(listeners).iterator();
     }
 

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java?rev=816667&r1=816666&r2=816667&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java Fri Sep 18 15:20:55 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.jcr2spi.state;
 
+import org.apache.jackrabbit.spi.ChildInfo;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.spi.Name;
@@ -107,7 +108,7 @@
      * @throws ItemNotFoundException
      * @throws RepositoryException
      */
-    public Iterator getChildNodeInfos(NodeId nodeId) throws ItemNotFoundException, RepositoryException;
+    public Iterator<ChildInfo> getChildNodeInfos(NodeId nodeId) throws ItemNotFoundException, RepositoryException;
 
     /**
      * Returns the identifiers of all reference properties that  point to

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?rev=816667&r1=816666&r2=816667&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java Fri Sep 18 15:20:55 2009
@@ -145,7 +145,7 @@
 
                 // since 'mixinTypeNames' are modified upon save only, no special
                 // merging is required here. just reset the mixinTypeNames.
-                List mixN = Arrays.asList(nState.mixinTypeNames);
+                List<Name> mixN = Arrays.asList(nState.mixinTypeNames);
                 if (mixN.size() != mixinTypeNames.length || !mixN.containsAll(Arrays.asList(mixinTypeNames))) {
                     setMixinTypeNames(nState.mixinTypeNames);
                     modified = true;

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?rev=816667&r1=816666&r2=816667&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java Fri Sep 18 15:20:55 2009
@@ -178,9 +178,9 @@
      * @throws RepositoryException
      */
     public void adjustReferences(ReferenceChangeTracker refTracker) throws ConstraintViolationException, RepositoryException {
-        Iterator it = refTracker.getReferences();
+        Iterator<PropertyState> it = refTracker.getReferences();
         while (it.hasNext()) {
-            PropertyState propState = (PropertyState) it.next();
+            PropertyState propState = it.next();
             boolean modified = false;
             QValue[] values = propState.getValues();
             QValue[] newVals = new QValue[values.length];

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java?rev=816667&r1=816666&r2=816667&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java Fri Sep 18 15:20:55 2009
@@ -18,6 +18,7 @@
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.spi.ChildInfo;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.PropertyId;
@@ -33,6 +34,7 @@
 
 import java.util.Iterator;
 import java.util.Collections;
+import java.util.Set;
 
 /**
  * <code>TransientISFactory</code>...
@@ -134,7 +136,7 @@
      * @inheritDoc
      * @see ItemStateFactory#getChildNodeInfos(NodeId)
      */
-    public Iterator getChildNodeInfos(NodeId nodeId) throws ItemNotFoundException, RepositoryException {
+    public Iterator<ChildInfo> getChildNodeInfos(NodeId nodeId) throws ItemNotFoundException, RepositoryException {
         return workspaceStateFactory.getChildNodeInfos(nodeId);
     }
 
@@ -144,7 +146,8 @@
      */
     public Iterator<PropertyId> getNodeReferences(NodeState nodeState, Name propertyName, boolean weak) {
         if (nodeState.getStatus() == Status.NEW) {
-            return Collections.EMPTY_SET.iterator();
+            Set<PropertyId> t = Collections.emptySet();
+            return t.iterator();
         }
         return workspaceStateFactory.getNodeReferences(nodeState, propertyName, weak);
     }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java?rev=816667&r1=816666&r2=816667&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java Fri Sep 18 15:20:55 2009
@@ -56,26 +56,26 @@
     /**
      * Added states
      */
-    private final Set addedStates = new LinkedHashSet();
+    private final Set<ItemState> addedStates = new LinkedHashSet<ItemState>();
 
     /**
      * Modified states
      */
-    private final Set modifiedStates = new LinkedHashSet();
+    private final Set<ItemState> modifiedStates = new LinkedHashSet<ItemState>();
 
     /**
      * Removed states
      */
-    private final Set removedStates = new LinkedHashSet();
+    private final Set<ItemState> removedStates = new LinkedHashSet<ItemState>();
     /**
      * Stale states
      */
-    private final Set staleStates = new LinkedHashSet();
+    private final Set<ItemState> staleStates = new LinkedHashSet<ItemState>();
 
     /**
      * Set of operations
      */
-    private Set operations = new LinkedHashSet();
+    private Set<Operation> operations = new LinkedHashSet<Operation>();
 
     /**
      *
@@ -86,7 +86,7 @@
     /**
      * @return the operations that have been recorded until now.
      */
-    Iterator getOperations() {
+    Iterator<Operation> getOperations() {
         return operations.iterator();
     }
 
@@ -110,14 +110,14 @@
     /**
      * Create the change log for the tree starting at <code>target</code>. This
      * includes a  check if the ChangeLog to be created is totally 'self-contained'
-     * and independant; items within the scope of this update operation (i.e.
+     * and independent; items within the scope of this update operation (i.e.
      * below the target) must not have dependencies outside of this tree (e.g.
      * moving a node requires that the target node including both old and new
      * parents are saved).
      *
      * @param target
      * @param throwOnStale Throws InvalidItemStateException if either the given
-     * <code>ItemState</code> or any of its decendants is stale and the flag is true.
+     * <code>ItemState</code> or any of its descendants is stale and the flag is true.
      * @return
      * @throws InvalidItemStateException if a stale <code>ItemState</code> is
      * encountered while traversing the state hierarchy. The <code>changeLog</code>
@@ -138,8 +138,8 @@
             throw new InvalidItemStateException(msg);
         }
 
-        Set ops = new LinkedHashSet();
-        Set affectedStates = new LinkedHashSet();
+        Set<Operation> ops = new LinkedHashSet<Operation>();
+        Set<ItemState> affectedStates = new LinkedHashSet<ItemState>();
 
         HierarchyEntry he = target.getHierarchyEntry();
         if (he.getParent() == null) {
@@ -160,8 +160,7 @@
             // not root entry:
             // - check if there is a stale state in the scope (save only)
             if (throwOnStale) {
-                for (Iterator it = staleStates.iterator(); it.hasNext();) {
-                    ItemState state = (ItemState) it.next();
+                for (ItemState state : staleStates) {
                     if (containedInTree(target, state)) {
                         String msg = "Cannot save changes: States has been modified externally.";
                         log.debug(msg);
@@ -189,11 +188,9 @@
             //   check if the affected states listed by the operations are all
             //   listed in the modified,removed or added states collected by this
             //   changelog.
-            for (Iterator it = operations.iterator(); it.hasNext();) {
-                Operation op = (Operation) it.next();
-                Collection opStates = op.getAffectedItemStates();
-                for (Iterator osIt = opStates.iterator(); osIt.hasNext();) {
-                    ItemState state = (ItemState) osIt.next();
+            for (Operation op : operations) {
+                Collection<ItemState> opStates = op.getAffectedItemStates();
+                for (ItemState state : opStates) {
                     if (affectedStates.contains(state)) {
                         // operation needs to be included
                         if (!affectedStates.containsAll(opStates)) {
@@ -289,7 +286,7 @@
      * @param subChangeLog
      */
     void dispose(ChangeLog subChangeLog) {
-        Set affectedStates = subChangeLog.getAffectedStates();
+        Set<ItemState> affectedStates = subChangeLog.getAffectedStates();
         addedStates.removeAll(affectedStates);
         modifiedStates.removeAll(affectedStates);
         removedStates.removeAll(affectedStates);