You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by md...@apache.org on 2009/08/25 15:50:06 UTC

svn commit: r807632 - in /jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch: AbstractChangeLog.java ChangeLogImpl.java ConsolidatingChangeLog.java

Author: mduerig
Date: Tue Aug 25 13:50:06 2009
New Revision: 807632

URL: http://svn.apache.org/viewvc?rev=807632&view=rev
Log:
JCR-2087: Upgrade to Java 5 as the base platform - use generics, annotations 

Added:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/AbstractChangeLog.java   (with props)
Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ChangeLogImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/AbstractChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/AbstractChangeLog.java?rev=807632&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/AbstractChangeLog.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/AbstractChangeLog.java Tue Aug 25 13:50:06 2009
@@ -0,0 +1,99 @@
+/*
+ * 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.spi.commons.batch;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.spi.Batch;
+
+/**
+ * This base class for {@link ChangeLog} implementations maintains a list of operations
+ * of type type <code>T</code>.
+ * @param <T>
+ */
+public abstract class AbstractChangeLog<T extends Operation> implements ChangeLog {
+
+    /**
+     * {@link Operation}s kept in this change log.
+     */
+    protected final List<T> operations = new LinkedList<T>();
+
+    /**
+     * Added an operation to the list of {@link #operations}.
+     * @param op  {@link Operation} to add
+     * @throws RepositoryException
+     */
+    public void addOperation(T op) throws RepositoryException {
+        operations.add(op);
+    }
+
+    /**
+     * This implementation applies each of the operation maintained by
+     * this change log to the passed <code>batch</code>.
+     * {@inheritDoc}
+     */
+    public Batch apply(Batch batch) throws RepositoryException {
+        if (batch == null) {
+            throw new IllegalArgumentException("Batch must not be null");
+        }
+        for (Iterator<T> it = operations.iterator(); it.hasNext(); ) {
+            Operation op = it.next();
+            op.apply(batch);
+        }
+        return batch;
+    }
+
+    @Override
+    public String toString() {
+        StringBuffer b = new StringBuffer();
+        for (Iterator<T> it = operations.iterator(); it.hasNext(); ) {
+            b.append(it.next());
+            if (it.hasNext()) {
+                b.append(", ");
+            }
+        }
+        return b.toString();
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if (null == other) {
+            return false;
+        }
+        if (this == other) {
+            return true;
+        }
+        if (other instanceof AbstractChangeLog<?>) {
+            return equals((AbstractChangeLog<?>) other);
+        }
+        return false;
+    }
+
+    public boolean equals(AbstractChangeLog<?> other) {
+        return operations.equals(other.operations);
+    }
+
+    @Override
+    public int hashCode() {
+        throw new IllegalArgumentException("Not hashable");
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/AbstractChangeLog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ChangeLogImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ChangeLogImpl.java?rev=807632&r1=807631&r2=807632&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ChangeLogImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ChangeLogImpl.java Tue Aug 25 13:50:06 2009
@@ -16,9 +16,6 @@
  */
 package org.apache.jackrabbit.spi.commons.batch;
 
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
 
 import javax.jcr.RepositoryException;
 
@@ -35,12 +32,7 @@
  * applied} to a batch, all operations in the list are {@link Operation#apply(Batch) applied} to that
  * batch.
  */
-public class ChangeLogImpl implements ChangeLog {
-
-    /**
-     * {@link Operation}s kept in this change log.
-     */
-    protected final List<Operation> operations = new LinkedList<Operation>();
+public class ChangeLogImpl extends AbstractChangeLog<Operation> {
 
     public void addNode(NodeId parentId, Name nodeName, Name nodetypeName, String uuid)
             throws RepositoryException {
@@ -88,63 +80,5 @@
         addOperation(Operations.setValue(propertyId, values));
     }
 
-    public Batch apply(Batch batch) throws RepositoryException {
-        if (batch == null) {
-            throw new IllegalArgumentException("Batch must not be null");
-        }
-        for (Iterator<Operation> it = operations.iterator(); it.hasNext(); ) {
-            Operation op = it.next();
-            op.apply(batch);
-        }
-        return batch;
-    }
-
-    /**
-     * This method is called when an operation is added to the list of {@link #operations}
-     * kept by this change log.
-     * @param op  {@link Operation} to add
-     * @throws RepositoryException
-     */
-    protected void addOperation(Operation op) throws RepositoryException {
-        operations.add(op);
-    }
-
-    // -----------------------------------------------------< Object >---
-
-    @Override
-    public String toString() {
-        StringBuffer b = new StringBuffer();
-        for (Iterator<Operation> it = operations.iterator(); it.hasNext(); ) {
-            b.append(it.next());
-            if (it.hasNext()) {
-                b.append(", ");
-            }
-        }
-        return b.toString();
-    }
-
-    @Override
-    public boolean equals(Object other) {
-        if (null == other) {
-            return false;
-        }
-        if (this == other) {
-            return true;
-        }
-        if (other instanceof ChangeLogImpl) {
-            return equals((ChangeLogImpl) other);
-        }
-        return false;
-    }
-
-    public boolean equals(ChangeLogImpl other) {
-        return operations.equals(other.operations);
-    }
-
-    @Override
-    public int hashCode() {
-        throw new IllegalArgumentException("Not hashable");
-    }
-
 }
 

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java?rev=807632&r1=807631&r2=807632&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java Tue Aug 25 13:50:06 2009
@@ -39,7 +39,7 @@
  * {@link CancelableOperation CancelableOperation} implementations document their behavior
  * concerning cancellation.
  */
-public class ConsolidatingChangeLog extends ChangeLogImpl {
+public class ConsolidatingChangeLog extends AbstractChangeLog<ConsolidatingChangeLog.CancelableOperation> {
     private static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance();
 
     /**
@@ -81,54 +81,44 @@
 
     // -----------------------------------------------------< ChangeLog >---
 
-    @Override
     public void addNode(NodeId parentId, Name nodeName, Name nodetypeName, String uuid)
             throws RepositoryException {
 
         addOperation(CancelableOperations.addNode(parentId, nodeName, nodetypeName, uuid));
     }
 
-    @Override
     public void addProperty(NodeId parentId, Name propertyName, QValue value) throws RepositoryException {
         addOperation(CancelableOperations.addProperty(parentId, propertyName, value));
     }
 
-    @Override
     public void addProperty(NodeId parentId, Name propertyName, QValue[] values) throws RepositoryException {
         addOperation(CancelableOperations.addProperty(parentId, propertyName, values));
     }
 
-    @Override
     public void move(NodeId srcNodeId, NodeId destParentNodeId, Name destName) throws RepositoryException {
         addOperation(CancelableOperations.move(srcNodeId, destParentNodeId, destName));
     }
 
-    @Override
     public void remove(ItemId itemId) throws RepositoryException {
         addOperation(CancelableOperations.remove(itemId));
     }
 
-    @Override
     public void reorderNodes(NodeId parentId, NodeId srcNodeId, NodeId beforeNodeId) throws RepositoryException {
         addOperation(CancelableOperations.reorderNodes(parentId, srcNodeId, beforeNodeId));
     }
 
-    @Override
     public void setMixins(NodeId nodeId, Name[] mixinNodeTypeNames) throws RepositoryException {
         addOperation(CancelableOperations.setMixins(nodeId, mixinNodeTypeNames));
     }
 
-    @Override
     public void setPrimaryType(NodeId nodeId, Name primaryNodeTypeName) throws RepositoryException {
         addOperation(CancelableOperations.setPrimaryType(nodeId, primaryNodeTypeName));
     }
 
-    @Override
     public void setValue(PropertyId propertyId, QValue value) throws RepositoryException {
         addOperation(CancelableOperations.setValue(propertyId, value));
     }
 
-    @Override
     public void setValue(PropertyId propertyId, QValue[] values) throws RepositoryException {
         addOperation(CancelableOperations.setValue(propertyId, values));
     }
@@ -147,15 +137,10 @@
      * </ul>
      */
     @Override
-    protected void addOperation(Operation op) throws RepositoryException {
-        if (!(op instanceof CancelableOperation)) {
-            throw new IllegalArgumentException("Operation not instance of "
-                    + CancelableOperation.class.getName());
-        }
-
-        CancelableOperation otherOp = (CancelableOperation) op;
-        for (Iterator<Operation> it = new OperationsBackwardWithSentinel(); it.hasNext(); ) {
-            CancelableOperation thisOp = (CancelableOperation) it.next();
+    public void addOperation(CancelableOperation op) throws RepositoryException {
+        CancelableOperation otherOp = op;
+        for (OperationsBackwardWithSentinel it = new OperationsBackwardWithSentinel(); it.hasNext(); ) {
+            CancelableOperation thisOp = it.next();
             switch (thisOp.cancel(otherOp)) {
                 case CancelableOperation.CANCEL_THIS:
                     it.remove();
@@ -176,8 +161,8 @@
 
     // -----------------------------------------------------< private >---
 
-    private class OperationsBackwardWithSentinel implements Iterator<Operation> {
-        private final ListIterator<Operation> it = operations.listIterator(operations.size());
+    private class OperationsBackwardWithSentinel implements Iterator<CancelableOperation> {
+        private final ListIterator<CancelableOperation> it = operations.listIterator(operations.size());
         private boolean last = !it.hasPrevious();
         private boolean done;
 
@@ -185,13 +170,13 @@
             return it.hasPrevious() || last;
         }
 
-        public Operation next() {
+        public CancelableOperation next() {
             if (last) {
                 done = true;
                 return CancelableOperations.empty();
             }
             else {
-                Operation o = it.previous();
+                CancelableOperation o = it.previous();
                 last = !it.hasPrevious();
                 return o;
             }