jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r451313 [1/2] - in /jackrabbit/trunk/contrib/spi: jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/ jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ jcr2spi/src/ma...
Date Fri, 29 Sep 2006 14:44:40 GMT
Author: angela
Date: Fri Sep 29 07:44:39 2006
New Revision: 451313

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

- ChangeLog: add target (item to be saved)
- TransientItemStateManager: changing itemstate from new to existing => needs to connect to overlayed state
- TransientISFactory move out of TransientISM
- RepositoryServiceImpl: simplify execution of wsp-operations
- Initial draft for observation
- WorkspaceManager: seperate notification of events resulting from transient modifications.
- WorkspaceManager: don't report events from wsp-operations as external mods.
- IteratorHelper; add EMPTY constant
- Event: add constant for ALL events

Added:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java   (with props)
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/CredentialsWrapper.java   (with props)
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SubscriptionManager.java   (with props)
Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/InternalEventListener.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java
    jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/Event.java
    jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventIteratorImpl.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IteratorHelper.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?view=diff&rev=451313&r1=451312&r2=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java Fri Sep 29 07:44:39 2006
@@ -74,6 +74,7 @@
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.spi.Batch;
 import org.apache.jackrabbit.value.QValue;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -116,7 +117,7 @@
     private final RepositoryService service;
     private final SessionInfo sessionInfo;
 
-    private final WorkspaceItemStateManager cache;
+    private final ItemStateManager cache;
 
     private final NamespaceRegistryImpl nsRegistry;
     private final NodeTypeRegistry ntRegistry;
@@ -138,9 +139,7 @@
         this.service = service;
         this.sessionInfo = sessionInfo;
 
-        ItemStateFactory isf = new WorkspaceItemStateFactory(service, sessionInfo, this);
-        cache = new WorkspaceItemStateManager(isf, service.getIdFactory());
-        addEventListener(cache);
+        cache = createItemStateManager();
 
         nsRegistry = createNamespaceRegistry();
         ntRegistry = createNodeTypeRegistry(nsRegistry);
@@ -241,6 +240,13 @@
     }
 
     //--------------------------------------------------------------------------
+    private ItemStateManager createItemStateManager() {
+        ItemStateFactory isf = new WorkspaceItemStateFactory(service, sessionInfo, this);
+        WorkspaceItemStateManager ism = new WorkspaceItemStateManager(isf, service.getIdFactory());
+        addEventListener(ism);
+        return ism;
+    }
+
     private NamespaceRegistryImpl createNamespaceRegistry() throws RepositoryException {
         return new NamespaceRegistryImpl(this, service.getRegisteredNamespaces(sessionInfo));
     }
@@ -268,18 +274,16 @@
         Properties descriptors = service.getRepositoryDescriptors();
         String desc = descriptors.getProperty(Repository.OPTION_OBSERVATION_SUPPORTED);
         EventListener l = null;
-        if (Boolean.getBoolean(desc)) {
+        if (Boolean.valueOf(desc).booleanValue()) {
             l = new EventListener() {
                 public void onEvent(EventIterator events) {
                     // external change
-                    onEventReceived(null, events);
+                    onEventReceived(events, false, null);
                 }
             };
-            int allTypes = Event.NODE_ADDED | Event.NODE_REMOVED |
-                Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED;
-            // register for all events
+            // register for all non-local events
             service.addEventListener(sessionInfo, service.getRootId(sessionInfo),
-                l, allTypes, true, null, null);
+                l, Event.ALL_TYPES, true, null, null);
         }
         return l;
     }
@@ -341,24 +345,22 @@
 
     //------ updatable -:>> review ---------------------------------------------
     /**
-     * Creates a new <code>Batch</code> from the single workspace operation and
-     * executes it.
+     * Creates a new batch from the single workspace operation and executes it.
      *
      * @see UpdatableItemStateManager#execute(Operation)
      */
     public void execute(Operation operation) throws RepositoryException {
-        new Batch(sessionInfo).execute(operation);
+        new OperationVisitorImpl(sessionInfo).execute(operation);
     }
 
     /**
-     * Creates a new <code>Batch</code> from the given <code>Batch</code> and
-     * executes it.
+     * Creates a new batch from the given <code>ChangeLog</code> and executes it.
      *
      * @param changes
      * @throws RepositoryException
      */
     public void execute(ChangeLog changes) throws RepositoryException {
-        new Batch(sessionInfo).execute(changes);
+        new OperationVisitorImpl(sessionInfo).execute(changes);
     }
 
     public void dispose() {
@@ -513,6 +515,7 @@
      * workspace). In this case <code>changeLog</code> is <code>null</code></li>
      * </ul>
      *
+     * @param events    the events generated by the repository service as a
      * @param changeLog the local <code>ChangeLog</code> which contains the
      *                  affected transient <code>ItemState</code>s and the
      *                  relevant {@link Operation}s that lead to the
@@ -520,17 +523,8 @@
      *                  called as a consequence of an external change or a call
      *                  of a workspace operation. In that case there are no
      *                  local transient changes.
-     * @param events    the events generated by the repository service as a
-     *                  response to the changes.
      */
-    private void onEventReceived(ChangeLog changeLog, EventIterator events) {
-        if (changeLog != null) {
-            // now we need to apply the transient changes in changeLog to
-            // the ItemStates in the workspace layer
-            changeLog.push();
-            changeLog.persisted();
-        }
-
+    private void onEventReceived(EventIterator events, boolean isLocal, ChangeLog changeLog) {
         // notify listener
         // need to copy events into a list because we notify multiple listeners
         List eventList = new ArrayList();
@@ -538,10 +532,19 @@
             Event e = events.nextEvent();
             eventList.add(e);
         }
+        if (eventList.isEmpty()) {
+            return;
+        }
 
         InternalEventListener[] lstnrs = (InternalEventListener[]) listeners.toArray(new InternalEventListener[listeners.size()]);
-        for (int i = 0; i < lstnrs.length; i++) {
-           lstnrs[i].onEvent(new EventIteratorImpl(eventList), changeLog != null);
+        if (changeLog == null) {
+            for (int i = 0; i < lstnrs.length; i++) {
+                lstnrs[i].onEvent(new EventIteratorImpl(eventList), isLocal);
+            }
+        } else {
+            for (int i = 0; i < lstnrs.length; i++) {
+                lstnrs[i].onEvent(new EventIteratorImpl(eventList), changeLog);
+            }
         }
     }
 
@@ -549,17 +552,17 @@
      * Executes a sequence of operations on the repository service within
      * a given <code>SessionInfo</code>.
      */
-    private final class Batch implements OperationVisitor {
+    private final class OperationVisitorImpl implements OperationVisitor {
 
         /**
          * The session info for all operations in this batch.
          */
         private final SessionInfo sessionInfo;
 
-        private org.apache.jackrabbit.spi.Batch batch;
+        private Batch batch;
         private EventIterator events;
 
-        private Batch(SessionInfo sessionInfo) {
+        private OperationVisitorImpl(SessionInfo sessionInfo) {
             this.sessionInfo = sessionInfo;
         }
 
@@ -568,7 +571,8 @@
          */
         private void execute(ChangeLog changeLog) throws RepositoryException, ConstraintViolationException, AccessDeniedException, ItemExistsException, NoSuchNodeTypeException, UnsupportedRepositoryOperationException, VersionException {
             try {
-                batch = service.createBatch(sessionInfo);
+                ItemState target = changeLog.getTarget().getOverlayedState();
+                batch = service.createBatch(target.getId(), sessionInfo);
                 Iterator it = changeLog.getOperations();
                 while (it.hasNext()) {
                     Operation op = (Operation) it.next();
@@ -577,8 +581,8 @@
                 }
             } finally {
                 if (batch != null) {
-                    EventIterator events = service.submit(batch);
-                    onEventReceived(changeLog, events);
+                    events = service.submit(batch);
+                    onEventReceived(events, true, changeLog);
                     // reset batch field
                     batch = null;
                 }
@@ -596,8 +600,10 @@
                 success = true;
             } finally {
                 if (success && events != null) {
-                    // a workspace operation is like an external change
-                    onEventReceived(null, events);
+                    // a workspace operation is like an external change: there
+                    // is no changelog to persist. but still the events must
+                    // be reported as local changes.
+                    onEventReceived(events, true, null);
                 }
             }
         }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java?view=diff&rev=451313&r1=451312&r2=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java Fri Sep 29 07:44:39 2006
@@ -26,6 +26,7 @@
 import org.apache.jackrabbit.jcr2spi.operation.LockRefresh;
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.state.ItemState;
+import org.apache.jackrabbit.jcr2spi.state.ChangeLog;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.spi.EventIterator;
 import org.apache.jackrabbit.spi.Event;
@@ -547,6 +548,10 @@
                     break;
                 }
             }
+        }
+
+        public void onEvent(EventIterator events, ChangeLog changeLog) {
+            // nothing to do. we are not interested in transient modifications
         }
 
         //----------------------------------------------< LockTokenListener >---

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/InternalEventListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/InternalEventListener.java?view=diff&rev=451313&r1=451312&r2=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/InternalEventListener.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/InternalEventListener.java Fri Sep 29 07:44:39 2006
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.jcr2spi.observation;
 
 import org.apache.jackrabbit.spi.EventIterator;
+import org.apache.jackrabbit.jcr2spi.state.ChangeLog;
 
 /**
  * <code>InternalEventListener</code> is similar to {@link org.apache.jackrabbit.spi.EventListener}
@@ -32,4 +33,6 @@
      * @param isLocal <code>true</code> if these are local changes.
      */
     public void onEvent(EventIterator events, boolean isLocal);
+
+    public void onEvent(EventIterator events, ChangeLog changeLog);
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java?view=diff&rev=451313&r1=451312&r2=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java Fri Sep 29 07:44:39 2006
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.jcr2spi.observation;
 
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.jcr2spi.state.ChangeLog;
 import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.name.NameException;
 import org.apache.jackrabbit.name.NameFormat;
@@ -156,6 +157,9 @@
         while (events.hasNext()) {
             eventList.add(events.nextEvent());
         }
+        if (eventList.isEmpty()) {
+            return;
+        }
         eventList = Collections.unmodifiableList(eventList);
 
         // get active listeners
@@ -178,6 +182,17 @@
                 }
             }
         }
+    }
+
+    /**
+     * Same as {@link #onEvent(EventIterator, boolean)} with the boolean flag
+     * set to <code>true</code>.
+     * 
+     * @param events
+     * @param changeLog
+     */
+    public void onEvent(EventIterator events, ChangeLog changeLog) {
+        onEvent(events, true);
     }
 
     //-------------------------< internal >-------------------------------------

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java?view=diff&rev=451313&r1=451312&r2=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java Fri Sep 29 07:44:39 2006
@@ -30,31 +30,40 @@
  */
 public class ChangeLog {
 
+    private final ItemState target;
     /**
      * Added states
      */
-    protected final Set addedStates = new LinkedHashSet();
+    final Set addedStates = new LinkedHashSet();
 
     /**
      * Modified states
      */
-    protected final Set modifiedStates = new LinkedHashSet();
+    final Set modifiedStates = new LinkedHashSet();
 
     /**
      * Deleted states
      */
-    protected final Set deletedStates = new LinkedHashSet();
+    final Set deletedStates = new LinkedHashSet();
 
     /**
      * Modified references
      */
-    protected final Set modifiedRefs = new LinkedHashSet();
+    final Set modifiedRefs = new LinkedHashSet();
 
     /**
      * Type of operation this changelog is collection state modifications for.
      */  
     private Set operations = new LinkedHashSet();
 
+    /**
+     *
+     * @param target
+     */
+    ChangeLog(ItemState target) {
+        this.target = target;
+    }
+
     //-----------------------------------------------< Inform the ChangeLog >---
     /**
      * Add the given operation to the list of operations to be recorded within
@@ -113,6 +122,14 @@
     }
 
     //----------------------< Retrieve information present in the ChangeLog >---
+    /**
+     *
+     * @return
+     */
+    public ItemState getTarget() {
+        return target;
+    }
+
     /**
      *
      * @return

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?view=diff&rev=451313&r1=451312&r2=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java Fri Sep 29 07:44:39 2006
@@ -280,7 +280,7 @@
      */
     public void undo(ItemState itemState) throws ItemStateException {
         // check if self contained
-        ChangeLog changeLog = new ChangeLog();
+        ChangeLog changeLog = new ChangeLog(itemState);
         collectTransientStates(itemState, changeLog, false);
         changeLog.checkIsSelfContained();
         changeLog.collectOperations(transientStateMgr.getOperations());
@@ -338,7 +338,7 @@
      */
     private ChangeLog getChangeLog(ItemState itemState) throws StaleItemStateException, ItemStateException {
         // build changelog for affected and decendant states only
-        ChangeLog changeLog = new ChangeLog();
+        ChangeLog changeLog = new ChangeLog(itemState);
         collectTransientStates(itemState, changeLog, true);
 
         changeLog.checkIsSelfContained();

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java?view=auto&rev=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java (added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java Fri Sep 29 07:44:39 2006
@@ -0,0 +1,140 @@
+/*
+ * 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.jcr2spi.state;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.name.QName;
+
+/**
+ * <code>TransientISFactory</code>...
+ */
+final class TransientISFactory implements TransientItemStateFactory {
+
+    private static Logger log = LoggerFactory.getLogger(TransientISFactory.class);
+
+    private final IdFactory idFactory;
+    private final ItemStateManager parent;
+
+    private ItemStateLifeCycleListener listener;
+
+    TransientISFactory(IdFactory idFactory, ItemStateManager parent) {
+        this.idFactory = idFactory;
+        this.parent = parent;
+    }
+
+    void setListener(ItemStateLifeCycleListener listener) {
+        this.listener = listener;
+    }
+    //------------------------------------------< TransientItemStateFactory >---
+    /**
+     * @inheritDoc
+     * @see TransientItemStateFactory#createNewNodeState(QName, String, NodeState, QName, QNodeDefinition)
+     */
+    public NodeState createNewNodeState(QName name, String uuid,
+                                        NodeState parent, QName nodetypeName,
+                                        QNodeDefinition definition) {
+        NodeState nodeState = new NodeState(name, uuid, parent, nodetypeName,
+            definition, ItemState.STATUS_NEW, this, idFactory);
+        // get a notification when this item state is saved or invalidated
+        nodeState.addListener(listener);
+        // notify listener that a node state has been created
+        listener.statusChanged(nodeState, ItemState.STATUS_NEW);
+        return nodeState;
+    }
+
+    /**
+     * @inheritDoc
+     * @see TransientItemStateFactory#createNewPropertyState(QName, NodeState, QPropertyDefinition)
+     */
+    public PropertyState createNewPropertyState(QName name, NodeState parent, QPropertyDefinition definition) {
+        PropertyState propState = new PropertyState(name, parent,
+            definition, ItemState.STATUS_NEW, idFactory);
+        // get a notification when this item state is saved or invalidated
+        propState.addListener(listener);
+        // notify listener that a property state has been created
+        listener.statusChanged(propState, ItemState.STATUS_NEW);
+        return propState;
+    }
+
+    //---------------------------------------------------< ItemStateFactory >---
+    /**
+     * @inheritDoc
+     * @see ItemStateFactory#createRootState(ItemStateManager)
+     */
+    public NodeState createRootState(ItemStateManager ism) throws ItemStateException {
+        // retrieve state to overlay
+        NodeState overlayedState = (NodeState) parent.getRootState();
+        NodeState nodeState = new NodeState(overlayedState, null,
+            ItemState.STATUS_EXISTING, this, idFactory);
+        nodeState.addListener(listener);
+        return nodeState;
+    }
+
+    /**
+     * @inheritDoc
+     * @see ItemStateFactory#createNodeState(NodeId, ItemStateManager)
+     */
+    public NodeState createNodeState(NodeId nodeId, ItemStateManager ism)
+        throws NoSuchItemStateException, ItemStateException {
+        // retrieve state to overlay
+        NodeState overlayedState = (NodeState) parent.getItemState(nodeId);
+        NodeState overlayedParent = overlayedState.getParent();
+        NodeState parentState = null;
+        if (overlayedParent != null) {
+            parentState = (NodeState) ism.getItemState(overlayedParent.getId());
+        }
+        NodeState nodeState = new NodeState(overlayedState, parentState,
+            ItemState.STATUS_EXISTING, this, idFactory);
+        nodeState.addListener(listener);
+        return nodeState;
+    }
+
+    /**
+     * @inheritDoc
+     * @see ItemStateFactory#createNodeState(NodeId, NodeState)
+     */
+    public NodeState createNodeState(NodeId nodeId, NodeState parentState)
+        throws NoSuchItemStateException, ItemStateException {
+        // retrieve state to overlay
+        NodeState overlayedState = (NodeState) parent.getItemState(nodeId);
+        NodeState nodeState = new NodeState(overlayedState, parentState,
+            ItemState.STATUS_EXISTING, this, idFactory);
+        nodeState.addListener(listener);
+        return nodeState;
+    }
+
+    /**
+     * @inheritDoc
+     * @see ItemStateFactory#createPropertyState(PropertyId, NodeState)
+     */
+    public PropertyState createPropertyState(PropertyId propertyId,
+                                             NodeState parentState)
+        throws NoSuchItemStateException, ItemStateException {
+        // retrieve state to overlay
+        PropertyState overlayedState = (PropertyState) parent.getItemState(propertyId);
+        PropertyState propState = new PropertyState(overlayedState, parentState,
+            ItemState.STATUS_EXISTING, idFactory);
+        propState.addListener(listener);
+        return propState;
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java?view=diff&rev=451313&r1=451312&r2=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java Fri Sep 29 07:44:39 2006
@@ -18,9 +18,7 @@
 
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
 import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.ItemId;
-import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
@@ -64,26 +62,18 @@
     private final ItemStateManager parent;
 
     /**
-     * The transient item state factory to create new and existing item state
-     * instances.
-     */
-    private final TransientISFactory isf;
-
-    /**
      * The root node state or <code>null</code> if it hasn't been retrieved yet.
      */
     private NodeState rootNodeState;
 
     TransientItemStateManager(IdFactory idFactory, ItemStateManager parent) {
         super(new TransientISFactory(idFactory, parent), idFactory);
-        this.changeLog = new ChangeLog();
         this.parent = parent;
-        this.isf = (TransientISFactory) getItemStateFactory();
-        this.isf.setListener(this);
+        this.changeLog = new ChangeLog(null);
+        ((TransientISFactory) getTransientFactory()).setListener(this);
     }
 
     //-----------------------< ItemStateManager >-------------------------------
-
     /**
      * Return the root node state.
      *
@@ -94,7 +84,7 @@
      */
     public NodeState getRootState() throws ItemStateException {
         if (rootNodeState == null) {
-            rootNodeState = isf.createRootState(this);
+            rootNodeState = getItemStateFactory().createRootState(this);
             rootNodeState.addListener(this);
         }
         return rootNodeState;
@@ -222,7 +212,7 @@
      */
     NodeState createNewNodeState(QName nodeName, String uuid, QName nodeTypeName,
                                  QNodeDefinition definition, NodeState parent) {
-        NodeState nodeState = isf.createNewNodeState(nodeName, uuid, parent, nodeTypeName, definition);
+        NodeState nodeState = getTransientFactory().createNewNodeState(nodeName, uuid, parent, nodeTypeName, definition);
 
         parent.addChildNodeState(nodeState, uuid);
         changeLog.added(nodeState);
@@ -243,7 +233,7 @@
      */
     PropertyState createNewPropertyState(QName propName, NodeState parent, QPropertyDefinition definition)
             throws ItemExistsException {
-        PropertyState propState = isf.createNewPropertyState(propName, parent, definition);
+        PropertyState propState = getTransientFactory().createNewPropertyState(propName, parent, definition);
 
         parent.addPropertyState(propState);
         changeLog.added(propState);
@@ -348,6 +338,14 @@
                 } else if (previousStatus == ItemState.STATUS_NEW) {
                     // was new and has been saved now
                     changeLog.addedStates.remove(state);
+                    // state needs to be connected to the overlayed-state now
+                    try {
+                        ItemState overlayedState = parent.getItemState(state.getId());
+                        state.connect(overlayedState);
+                    } catch (ItemStateException e) {
+                        // TODO, handle property
+                        log.error(e.getMessage());
+                    }
                 }
                 break;
             case ItemState.STATUS_EXISTING_MODIFIED:
@@ -385,115 +383,7 @@
         }
     }
 
-    //----------------------< TransientItemStateFactory >-----------------------
-
-    private final static class TransientISFactory implements TransientItemStateFactory {
-
-        private final IdFactory idFactory;
-
-        private ItemStateLifeCycleListener listener;
-
-        private final ItemStateManager parent;
-
-        private TransientISFactory(IdFactory idFactory,
-                                   ItemStateManager parent) {
-            this.idFactory = idFactory;
-            this.parent = parent;
-        }
-
-        private void setListener(ItemStateLifeCycleListener listener) {
-            this.listener = listener;
-        }
-
-        /**
-         * @inheritDoc
-         * @see TransientItemStateFactory#createNewNodeState(QName, String, NodeState, QName, QNodeDefinition)
-         */
-        public NodeState createNewNodeState(QName name, String uuid,
-                                            NodeState parent, QName nodetypeName,
-                                            QNodeDefinition definition) {
-            NodeState nodeState = new NodeState(name, uuid, parent, nodetypeName,
-                definition, ItemState.STATUS_NEW, this, idFactory);
-            // get a notification when this item state is saved or invalidated
-            nodeState.addListener(listener);
-            // notify listener that a node state has been created
-            listener.statusChanged(nodeState, ItemState.STATUS_NEW);
-            return nodeState;
-        }
-
-        /**
-         * @inheritDoc
-         * @see TransientItemStateFactory#createNewPropertyState(QName, NodeState, QPropertyDefinition)
-         */
-        public PropertyState createNewPropertyState(QName name, NodeState parent, QPropertyDefinition definition) {
-            PropertyState propState = new PropertyState(name, parent,
-                definition, ItemState.STATUS_NEW, idFactory);
-            // get a notification when this item state is saved or invalidated
-            propState.addListener(listener);
-            // notify listener that a property state has been created
-            listener.statusChanged(propState, ItemState.STATUS_NEW);
-            return propState;
-        }
-
-        /**
-         * @inheritDoc
-         * @see ItemStateFactory#createRootState(ItemStateManager)
-         */
-        public NodeState createRootState(ItemStateManager ism) throws ItemStateException {
-            // retrieve state to overlay
-            NodeState overlayedState = (NodeState) parent.getRootState();
-            NodeState nodeState = new NodeState(overlayedState, null,
-                    ItemState.STATUS_EXISTING, this, idFactory);
-            nodeState.addListener(listener);
-            return nodeState;
-        }
-
-        /**
-         * @inheritDoc
-         * @see ItemStateFactory#createNodeState(NodeId, ItemStateManager)
-         */
-        public NodeState createNodeState(NodeId nodeId, ItemStateManager ism)
-                throws NoSuchItemStateException, ItemStateException {
-            // retrieve state to overlay
-            NodeState overlayedState = (NodeState) parent.getItemState(nodeId);
-            NodeState overlayedParent = overlayedState.getParent();
-            NodeState parentState = null;
-            if (overlayedParent != null) {
-                parentState = (NodeState) ism.getItemState(overlayedParent.getId());
-            }
-            NodeState nodeState = new NodeState(overlayedState, parentState,
-                    ItemState.STATUS_EXISTING, this, idFactory);
-            nodeState.addListener(listener);
-            return nodeState;
-        }
-
-        /**
-         * @inheritDoc
-         * @see ItemStateFactory#createNodeState(NodeId, NodeState)
-         */
-        public NodeState createNodeState(NodeId nodeId, NodeState parentState)
-                throws NoSuchItemStateException, ItemStateException {
-            // retrieve state to overlay
-            NodeState overlayedState = (NodeState) parent.getItemState(nodeId);
-            NodeState nodeState = new NodeState(overlayedState, parentState,
-                    ItemState.STATUS_EXISTING, this, idFactory);
-            nodeState.addListener(listener);
-            return nodeState;
-        }
-
-        /**
-         * @inheritDoc
-         * @see ItemStateFactory#createPropertyState(PropertyId, NodeState)
-         */
-        public PropertyState createPropertyState(PropertyId propertyId,
-                                                 NodeState parentState)
-                throws NoSuchItemStateException, ItemStateException {
-            // retrieve state to overlay
-            PropertyState overlayedState = (PropertyState) parent.getItemState(propertyId);
-            PropertyState propState = new PropertyState(overlayedState, parentState,
-                    ItemState.STATUS_EXISTING, idFactory);
-            propState.addListener(listener);
-            return propState;
-        }
+    private TransientItemStateFactory getTransientFactory() {
+        return (TransientItemStateFactory) getItemStateFactory();
     }
 }

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=451313&r1=451312&r2=451313
==============================================================================
--- 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 Fri Sep 29 07:44:39 2006
@@ -32,9 +32,8 @@
 /**
  * <code>WorkspaceItemStateManager</code>
  */
-public class WorkspaceItemStateManager
-        extends CachingItemStateManager
-        implements InternalEventListener {
+public class WorkspaceItemStateManager extends CachingItemStateManager
+    implements InternalEventListener {
 
     public WorkspaceItemStateManager(ItemStateFactory isf, IdFactory idFactory) {
         super(isf, idFactory);
@@ -44,17 +43,14 @@
 
     /**
      * Processes <code>events</code> and invalidates cached <code>ItemState</code>s
-     * accordingly.
+     * accordingly. Note that this performed for both local and non-local changes,
+     * since workspace operations are reported as local changes as well and
+     * might have invoked changes (autocreated items etc.).
+     *
      * @param events
      * @param isLocal
      */
     public void onEvent(EventIterator events, boolean isLocal) {
-        // if events origin from local changes then
-        // cache does not need invalidation
-        if (isLocal) {
-            return;
-        }
-
         // collect set of removed node ids
         Set removedNodeIds = new HashSet();
         List eventList = new ArrayList();
@@ -62,6 +58,9 @@
             Event e = events.nextEvent();
             eventList.add(e);
         }
+        if (eventList.isEmpty()) {
+            return;
+        }
 
         for (Iterator it = eventList.iterator(); it.hasNext(); ) {
             Event e = (Event) it.next();
@@ -110,5 +109,15 @@
                     }
             }
         }
+    }
+
+    public void onEvent(EventIterator events, ChangeLog changeLog) {
+        if (changeLog == null) {
+            throw new IllegalArgumentException("ChangeLog must not be null.");
+        }
+        // now we need to apply the transient changes in changeLog to
+        // the ItemStates in the workspace layer
+        changeLog.push();
+        changeLog.persisted();
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java?view=diff&rev=451313&r1=451312&r2=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java Fri Sep 29 07:44:39 2006
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.jcr2spi.state.PropertyState;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateException;
 import org.apache.jackrabbit.jcr2spi.state.ItemState;
+import org.apache.jackrabbit.jcr2spi.state.ChangeLog;
 import org.apache.jackrabbit.jcr2spi.observation.InternalEventListener;
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
 import org.apache.jackrabbit.jcr2spi.operation.Checkout;
@@ -166,6 +167,9 @@
                         }
                     }
                 }
+            }
+            public void onEvent(EventIterator events, ChangeLog changeLog) {
+                // nothing to do. we are not interested in transient modifications
             }
         };
 

Modified: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/Event.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/Event.java?view=diff&rev=451313&r1=451312&r2=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/Event.java (original)
+++ jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/Event.java Fri Sep 29 07:44:39 2006
@@ -28,27 +28,33 @@
     /**
      * An event of this type is generated when a node is added.
      */
-     public static final int NODE_ADDED = javax.jcr.observation.Event.NODE_ADDED;
+    public static final int NODE_ADDED = javax.jcr.observation.Event.NODE_ADDED;
 
     /**
      * An event of this type is generated when a node is removed.
      */
-     public static final int NODE_REMOVED = javax.jcr.observation.Event.NODE_REMOVED;
+    public static final int NODE_REMOVED = javax.jcr.observation.Event.NODE_REMOVED;
 
     /**
      * An event of this type is generated when a property is added.
      */
-     public static final int PROPERTY_ADDED = javax.jcr.observation.Event.PROPERTY_ADDED;
+    public static final int PROPERTY_ADDED = javax.jcr.observation.Event.PROPERTY_ADDED;
 
     /**
      * An event of this type is generated when a property is removed.
      */
-     public static final int PROPERTY_REMOVED = javax.jcr.observation.Event.PROPERTY_REMOVED;
+    public static final int PROPERTY_REMOVED = javax.jcr.observation.Event.PROPERTY_REMOVED;
 
     /**
      * An event of this type is generated when a property is changed.
      */
-     public static final int PROPERTY_CHANGED = javax.jcr.observation.Event.PROPERTY_CHANGED;
+    public static final int PROPERTY_CHANGED = javax.jcr.observation.Event.PROPERTY_CHANGED;
+
+    /**
+     * Constant for observation listener interested in all types of events.
+     */
+    public static final int ALL_TYPES = Event.NODE_ADDED | Event.NODE_REMOVED |
+    Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED;
 
     /**
      * Returns the type of this event: a constant defined by this interface.

Modified: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java?view=diff&rev=451313&r1=451312&r2=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java (original)
+++ jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java Fri Sep 29 07:44:39 2006
@@ -181,10 +181,11 @@
      * on the underlaying persistence layer. All modification called on the
      * Batch must be executed at once or non must be executed.
      *
+     * @param itemId
      * @param sessionInfo
      * @return
      */
-    public Batch createBatch(SessionInfo sessionInfo) throws RepositoryException;
+    public Batch createBatch(ItemId itemId, SessionInfo sessionInfo) throws RepositoryException;
 
     /**
      * Completes the this Batch or discard all the previous modifications.
@@ -486,9 +487,7 @@
     /**
      * Registers a listener to receive events about changes that were applied
      * by other sessions. In contrast to {@link javax.jcr.observation.ObservationManager#addEventListener)}
-     * this method does not have a <code>noLocal</code> flag. Local changes
-     * are immediately reported and only remote changes are reported to the
-     * registered listener.
+     * this method does not have a <code>noLocal</code> flag.
      * </p>
      * The implementation must ensure that {@link EventIterator}s issued to
      * potential listeners and the ones returned by the individual methods

Added: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/CredentialsWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/CredentialsWrapper.java?view=auto&rev=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/CredentialsWrapper.java (added)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/CredentialsWrapper.java Fri Sep 29 07:44:39 2006
@@ -0,0 +1,59 @@
+/*
+ * 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.spi2dav;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+
+import javax.jcr.SimpleCredentials;
+
+/**
+ * <code>CredentialsWrapper</code>...
+ */
+class CredentialsWrapper {
+
+    private static Logger log = LoggerFactory.getLogger(CredentialsWrapper.class);
+
+    private final String userId;
+    private final UsernamePasswordCredentials credentials;
+
+    CredentialsWrapper(javax.jcr.Credentials creds) {
+
+        if (creds == null) {
+            // NOTE: null credentials only work if 'missing-auth-mapping' param is set on the server
+            userId = null;
+            this.credentials = null;
+        } else if (creds instanceof SimpleCredentials) {
+            SimpleCredentials sCred = (SimpleCredentials) creds;
+            userId = sCred.getUserID();
+            this.credentials = new UsernamePasswordCredentials(userId, String.valueOf(sCred.getPassword()));
+        } else {
+            userId = null;
+            this.credentials = new UsernamePasswordCredentials(creds.toString());
+        }
+    }
+
+    String getUserId() {
+        return userId;
+    }
+
+    Credentials getCredentials() {
+        return credentials;
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/CredentialsWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/CredentialsWrapper.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventIteratorImpl.java?view=diff&rev=451313&r1=451312&r2=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventIteratorImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventIteratorImpl.java Fri Sep 29 07:44:39 2006
@@ -38,20 +38,19 @@
 
     private final SessionInfo sessionInfo;
     private final URIResolver uriResolver;
-    private final ElementIterator eventElementIterator;
+    private ElementIterator bundleIterator;
+    private ElementIterator eventElementIterator;
 
     private Event next;
     private long pos;
 
-    public EventIteratorImpl(Element eventBundleElement, URIResolver uriResolver, SessionInfo sessionInfo) {
-        if (!DomUtil.matches(eventBundleElement, ObservationConstants.XML_EVENTBUNDLE, ObservationConstants.NAMESPACE)) {
-            throw new IllegalArgumentException("eventbundle element expected.");
-        }
+    public EventIteratorImpl(Element eventDiscoveryElem, URIResolver uriResolver, SessionInfo sessionInfo) {
 
         this.sessionInfo = sessionInfo;
         this.uriResolver = uriResolver;
-        eventElementIterator = DomUtil.getChildren(eventBundleElement, ObservationConstants.XML_EVENT, ObservationConstants.NAMESPACE);
-        retrieveNext();
+        bundleIterator = DomUtil.getChildren(eventDiscoveryElem, ObservationConstants.XML_EVENTBUNDLE, ObservationConstants.NAMESPACE);;
+        retrieveNextEventIterator();
+        retrieveNextEvent();
     }
 
     public Event nextEvent() {
@@ -59,14 +58,14 @@
             throw new NoSuchElementException();
         }
         Event event = next;
-        retrieveNext();
+        retrieveNextEvent();
         pos++;
         return event;
     }
 
     public void skip(long skipNum) {
         while (skipNum-- > 0) {
-            next();
+            nextEvent();
         }
     }
 
@@ -79,11 +78,11 @@
     }
 
     public void remove() {
-        eventElementIterator.remove();
+        throw new UnsupportedOperationException("Remove not implemented.");
     }
 
     public boolean hasNext() {
-        return eventElementIterator.hasNext();
+        return next != null;
     }
 
     public Object next() {
@@ -91,20 +90,31 @@
     }
 
     //------------------------------------------------------------< private >---
-    /**
-     *
-     */
-    private void retrieveNext() {
+    private void retrieveNextEvent() {
         next = null;
-        while (next == null && eventElementIterator.hasNext()) {
-            Element evElem = eventElementIterator.nextElement();
-            try {
-                next = new EventImpl(evElem, uriResolver, sessionInfo);
-            } catch (RepositoryException e) {
-                log.error("Unexpected error while creating event.", e);
-            } catch (DavException e) {
-                log.error("Unexpected error while creating event.", e);
+        if (eventElementIterator != null) {
+            while (next == null && eventElementIterator.hasNext()) {
+                Element evElem = eventElementIterator.nextElement();
+                try {
+                    next = new EventImpl(evElem, uriResolver, sessionInfo);
+                } catch (RepositoryException e) {
+                    log.error("Unexpected error while creating event.", e);
+                } catch (DavException e) {
+                    log.error("Unexpected error while creating event.", e);
+                }
+            }
+
+            if (!eventElementIterator.hasNext()) {
+                retrieveNextEventIterator();
             }
+        }
+    }
+
+    private void retrieveNextEventIterator() {
+        eventElementIterator = null;
+        if (bundleIterator.hasNext()) {
+            Element bundleElem = bundleIterator.nextElement();
+            eventElementIterator =  DomUtil.getChildren(bundleElem, ObservationConstants.XML_EVENT, ObservationConstants.NAMESPACE);
         }
     }
 }

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IteratorHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IteratorHelper.java?view=diff&rev=451313&r1=451312&r2=451313
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IteratorHelper.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IteratorHelper.java Fri Sep 29 07:44:39 2006
@@ -22,18 +22,23 @@
 import org.apache.jackrabbit.spi.QNodeTypeDefinitionIterator;
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.Event;
+import org.apache.jackrabbit.spi.EventIterator;
 
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.ArrayList;
 
 /**
  * <code>org.apache.jackrabbit.spi2dav.IteratorHelper</code>...
  */
 public class IteratorHelper extends org.apache.jackrabbit.util.IteratorHelper
-    implements IdIterator, QNodeTypeDefinitionIterator {
+    implements IdIterator, QNodeTypeDefinitionIterator, EventIterator {
 
     private static Logger log = LoggerFactory.getLogger(IteratorHelper.class);
 
+    public static final IteratorHelper EMPTY = new IteratorHelper(new ArrayList(0));
+
     public IteratorHelper(Collection c) {
         super(c);
     }
@@ -54,5 +59,12 @@
      */
     public QNodeTypeDefinition nextDefinition() {
         return (QNodeTypeDefinition) next();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Event nextEvent() {
+        return (Event) next();
     }
 }



Mime
View raw message