jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r781054 - in /jackrabbit/trunk: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ob...
Date Tue, 02 Jun 2009 15:13:57 GMT
Author: angela
Date: Tue Jun  2 15:13:53 2009
New Revision: 781054

URL: http://svn.apache.org/viewvc?rev=781054&view=rev
Log:
JCR-2108: JSR 283 Observation   (work in progress)

- initial draft for simple 283 observation extensions
- TODO: eventjournal, iterator.getDate ....
- TODO: jcr-server still ignores 283 extensions

- in addition: removed tmp-dependency in spi2jcr/pom.xml

Modified:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/GetIdentifierTest.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/EventImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/FilteredEventIterator.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/SessionInfoImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/SessionInfoLogger.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/Event.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/SessionInfo.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventImpl.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
    jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/SessionInfoImpl.java

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/GetIdentifierTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/GetIdentifierTest.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/GetIdentifierTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/GetIdentifierTest.java
Tue Jun  2 15:13:53 2009
@@ -39,7 +39,6 @@
 
     public void testNodeMoved() throws RepositoryException {
         final Node n = testRootNode.addNode(nodeName1, testNodeType);
-        String id = n.getIdentifier();
         testRootNode.save();
         Event[] events = getEvents(new Callable(){
             public void call() throws RepositoryException {
@@ -47,21 +46,21 @@
             }
         }, Event.NODE_MOVED);
         String path = testRootNode.getNode(nodeName2).getPath();
-        assertEquals(id, getEventByPath(events, path).getIdentifier());
+        assertEquals(n.getIdentifier(), getEventByPath(events, path).getIdentifier());
     }
 
     public void testNodeRemoved() throws RepositoryException {
         final Node n = testRootNode.addNode(nodeName1, testNodeType);
         String path = n.getPath();
-        String id = n.getIdentifier();
         testRootNode.save();
+        String identifier = n.getIdentifier();
         Event[] events = getEvents(new Callable(){
             public void call() throws RepositoryException {
                 n.remove();
                 testRootNode.save();
             }
         }, Event.NODE_REMOVED);
-        assertEquals(id, getEventByPath(events, path).getIdentifier());
+        assertEquals(identifier, getEventByPath(events, path).getIdentifier());
     }
 
     public void testPropertyAdded() throws RepositoryException {
@@ -91,7 +90,6 @@
 
     public void testPropertyRemoved() throws RepositoryException {
         Node n = testRootNode.addNode(nodeName1, testNodeType);
-        String id = n.getIdentifier();
         final Property prop = n.setProperty(propertyName1, "test");
         String propPath = prop.getPath();
         testRootNode.save();
@@ -101,6 +99,6 @@
                 testRootNode.save();
             }
         }, Event.PROPERTY_REMOVED);
-        assertEquals(id, getEventByPath(events, propPath).getIdentifier());
+        assertEquals(n.getIdentifier(), getEventByPath(events, propPath).getIdentifier());
     }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
Tue Jun  2 15:13:53 2009
@@ -582,8 +582,9 @@
      * Create the <code>ObservationManager</code>. May be overridden by subclasses.
      *
      * @return a new <code>ObservationManager</code> instance
+     * @throws RepositoryException
      */
-    protected ObservationManager createObservationManager(NamePathResolver resolver, NodeTypeRegistry
ntRegistry) {
-        return new ObservationManagerImpl(wspManager, resolver, ntRegistry);
+    protected ObservationManager createObservationManager(NamePathResolver resolver, NodeTypeRegistry
ntRegistry) throws RepositoryException {
+        return new ObservationManagerImpl(wspManager, resolver, ntRegistry, session.getValueFactory());
     }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Tue Jun  2 15:13:53 2009
@@ -390,6 +390,14 @@
         return service.createEventFilter(sessionInfo, eventTypes, path, isDeep, uuids, nodeTypes,
noLocal);
     }
 
+    /**
+     *
+     * @param userData
+     * @throws RepositoryException
+     */
+    public void setUserData(String userData) throws RepositoryException {
+        sessionInfo.setUserData(userData);
+    }
     //--------------------------------------------------------------------------
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/EventImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/EventImpl.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/EventImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/EventImpl.java
Tue Jun  2 15:13:53 2009
@@ -17,13 +17,22 @@
 package org.apache.jackrabbit.jcr2spi.observation;
 
 import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
 
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.value.ValueFormat;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.PropertyId;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.ValueFactory;
 import javax.jcr.observation.Event;
 
 /**
@@ -43,6 +52,16 @@
     private final NamePathResolver resolver;
 
     /**
+     * The value factory of the session that created this event iterator.
+     */
+    private final ValueFactory valueFactory;
+
+    /**
+     * The IdFactory
+     */
+    private final IdFactory idFactory;
+    
+    /**
      * The underlying SPI event.
      */
     private final org.apache.jackrabbit.spi.Event event;
@@ -56,12 +75,17 @@
      * Creates a new {@link javax.jcr.observation.Event} instance based on an
      * {@link org.apache.jackrabbit.spi.Event SPI Event}.
      *
-     * @param resolver
      * @param event   the underlying SPI <code>Event</code>.
+     * @param resolver
+     * @param valueFactory
+     * @param idFactory
      */
-    EventImpl(NamePathResolver resolver, org.apache.jackrabbit.spi.Event event) {
-        this.resolver = resolver;
+    EventImpl(org.apache.jackrabbit.spi.Event event,
+              NamePathResolver resolver, ValueFactory valueFactory, IdFactory idFactory)
{
         this.event = event;
+        this.resolver = resolver;
+        this.valueFactory = valueFactory;
+        this.idFactory = idFactory;
     }
 
     //--------------------------------------------------------------< Event >---
@@ -90,32 +114,45 @@
      * @see javax.jcr.observation.Event#getIdentifier()
      */
     public String getIdentifier() throws RepositoryException {
-        // TODO
-        throw new UnsupportedRepositoryOperationException("JCR-2108");
+        ItemId itemId = event.getItemId();
+        if (itemId == null) {
+            return null;
+        } else {
+            NodeId nodeId = (itemId.denotesNode()) ? (NodeId) itemId : ((PropertyId) itemId).getParentId();
+            return idFactory.toJcrIdentifier(nodeId);
+        }
     }
 
     /**
      * @see javax.jcr.observation.Event#getInfo()
      */
     public Map getInfo() throws RepositoryException {
-        // TODO
-        throw new UnsupportedRepositoryOperationException("JCR-2108");
+        Map<String, String> jcrInfo = new HashMap();
+        Map<Name, QValue> infos = event.getInfo();
+        for (Iterator<Name> it = event.getInfo().keySet().iterator(); it.hasNext();
) {
+            Name key = it.next();
+            QValue value = infos.get(key);
+            String strValue = null;
+            if (value != null) {
+                strValue = ValueFormat.getJCRValue(value, resolver, valueFactory).getString();
+            }
+            jcrInfo.put(resolver.getJCRName(key), strValue);
+        }
+        return jcrInfo;
     }
 
     /**
      * @see javax.jcr.observation.Event#getUserData()
      */
     public String getUserData() throws RepositoryException {
-        // TODO
-        throw new UnsupportedRepositoryOperationException("JCR-2108");
+        return event.getUserData();
     }
 
     /**
      * @see javax.jcr.observation.Event#getDate()
      */
     public long getDate() throws RepositoryException {
-        // TODO
-        throw new UnsupportedRepositoryOperationException("JCR-2108");
+        return event.getDate();
     }
 
     //-------------------------------------------------------------< Object >---
@@ -160,6 +197,10 @@
             return "PropertyChanged";
         } else if (eventType == Event.PROPERTY_REMOVED) {
             return "PropertyRemoved";
+        } else if (eventType == Event.NODE_MOVED) {
+            return "NodeMoved";
+        } else if (eventType == Event.PERSIST) {
+            return "Persist";
         } else {
             return "UnknownEventType";
         }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/FilteredEventIterator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/FilteredEventIterator.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/FilteredEventIterator.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/FilteredEventIterator.java
Tue Jun  2 15:13:53 2009
@@ -22,9 +22,11 @@
 
 import javax.jcr.observation.Event;
 import javax.jcr.observation.EventIterator;
+import javax.jcr.ValueFactory;
 
 import org.apache.jackrabbit.spi.EventBundle;
 import org.apache.jackrabbit.spi.EventFilter;
+import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -60,6 +62,16 @@
     private final NamePathResolver resolver;
 
     /**
+     * The value factory of the session that created this event iterator.
+     */
+    private final ValueFactory valueFactory;
+
+    /**
+     * The IdFactory
+     */
+    private final IdFactory idFactory;
+
+    /**
      * The next {@link javax.jcr.observation.Event} in this iterator
      */
     private Event next;
@@ -75,16 +87,22 @@
      * @param events     the {@link org.apache.jackrabbit.spi.Event}s as a
      *                   bundle.
      * @param filter     only event that pass the filter will be dispatched to
-     *                   the event listener.
+ *                   the event listener.
      * @param resolver
+     * @param valueFactory
+     * @param idFactory
      */
     public FilteredEventIterator(EventBundle events,
                                  EventFilter filter,
-                                 NamePathResolver resolver) {
+                                 NamePathResolver resolver,
+                                 ValueFactory valueFactory,
+                                 IdFactory idFactory) {
         this.actualEvents = events.getEvents();
         this.filter = filter;
         this.isLocal = events.isLocal();
         this.resolver = resolver;
+        this.valueFactory = valueFactory;
+        this.idFactory = idFactory;
         fetchNext();
     }
 
@@ -170,7 +188,7 @@
         next = null;
         while (next == null && actualEvents.hasNext()) {
             event = (org.apache.jackrabbit.spi.Event) actualEvents.next();
-            next = filter.accept(event, isLocal) ? new EventImpl(resolver, event) : null;
+            next = filter.accept(event, isLocal) ? new EventImpl(event, resolver, valueFactory,
idFactory) : null;
         }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java
Tue Jun  2 15:13:53 2009
@@ -25,6 +25,7 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.ValueFactory;
 import javax.jcr.observation.EventJournal;
 import javax.jcr.observation.EventListener;
 import javax.jcr.observation.EventListenerIterator;
@@ -58,11 +59,18 @@
     private final WorkspaceManager wspManager;
 
     /**
-     * The session this observation manager belongs to.
+     * The name and path resolver associated with the session this observation
+     * manager belongs to.
      */
     private final NamePathResolver resolver;
 
     /**
+     * The ValueFactory associated with the session this observation
+     * manager belongs to.
+     */
+    private final ValueFactory valueFactory;
+
+    /**
      * The <code>NodeTypeRegistry</code> of the session.
      */
     private final NodeTypeRegistry ntRegistry;
@@ -82,12 +90,14 @@
      * @param wspManager the WorkspaceManager.
      * @param resolver
      * @param ntRegistry The <code>NodeTypeRegistry</code> of the session.
+     * @param valueFactory
      */
     public ObservationManagerImpl(WorkspaceManager wspManager, NamePathResolver resolver,
-                                  NodeTypeRegistry ntRegistry) {
+                                  NodeTypeRegistry ntRegistry, ValueFactory valueFactory)
{
         this.wspManager = wspManager;
         this.resolver = resolver;
         this.ntRegistry = ntRegistry;
+        this.valueFactory = valueFactory;
     }
 
     /**
@@ -179,8 +189,7 @@
      * @see javax.jcr.observation.ObservationManager#setUserData(String) 
      */
     public void setUserData(String userData) throws RepositoryException {
-        // TODO
-        throw new UnsupportedRepositoryOperationException("JCR-2108");
+        wspManager.setUserData(userData);
     }
 
     //-----------------------< InternalEventListener >--------------------------
@@ -205,7 +214,7 @@
             Map.Entry entry = (Map.Entry) it.next();
             EventListener listener = (EventListener) entry.getKey();
             EventFilter filter = (EventFilter) entry.getValue();
-            FilteredEventIterator eventIter = new FilteredEventIterator(eventBundle, filter,
resolver);
+            FilteredEventIterator eventIter = new FilteredEventIterator(eventBundle, filter,
resolver, valueFactory, wspManager.getIdFactory());
             if (eventIter.hasNext()) {
                 try {
                     listener.onEvent(eventIter);

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventImpl.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventImpl.java
Tue Jun  2 15:13:53 2009
@@ -21,8 +21,14 @@
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.QValue;
 
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
 import java.io.Serializable;
+import java.util.Map;
+import java.util.Collections;
+import java.util.HashMap;
 
 /**
  * <code>EventImpl</code> implements a serializable SPI
@@ -66,12 +72,27 @@
      */
     private final String userId;
 
+    private final String userData;
+    private final long timestamp;
+    private final Map<Name, QValue> info;
+
     /**
      * Creates a new serializable event.
+     * @deprecated
      */
     public EventImpl(int type, Path path, ItemId itemId, NodeId parentId,
                      Name primaryNodeTypeName, Name[] mixinTypeNames,
                      String userId) {
+        this(type, path, itemId, parentId, primaryNodeTypeName, mixinTypeNames, userId, null,
Long.MIN_VALUE, Collections.EMPTY_MAP);
+    }
+
+    /**
+     * Creates a new serializable event.
+     */
+    public EventImpl(int type, Path path, ItemId itemId, NodeId parentId,
+                     Name primaryNodeTypeName, Name[] mixinTypeNames,
+                     String userId, String userData, long timestamp,
+                     Map<Name, QValue> info) {
         this.type = type;
         this.path = path;
         this.itemId = itemId;
@@ -79,6 +100,10 @@
         this.primaryNodeTypeName = primaryNodeTypeName;
         this.mixinTypeNames = mixinTypeNames;
         this.userId = userId;
+
+        this.userData = userData;
+        this.info = new HashMap<Name, QValue>(info);
+        this.timestamp = timestamp;
     }
 
     /**
@@ -131,4 +156,29 @@
     public String getUserID() {
         return userId;
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Map<Name, QValue> getInfo() throws RepositoryException {
+        return info;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getUserData() {
+        return userData;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public long getDate() throws RepositoryException {
+        if (timestamp == Long.MIN_VALUE) {
+            throw new UnsupportedRepositoryOperationException("Event.getDate() not supported");
+        } else {
+            return timestamp;
+        }
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/SessionInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/SessionInfoImpl.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/SessionInfoImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/SessionInfoImpl.java
Tue Jun  2 15:13:53 2009
@@ -18,6 +18,7 @@
 
 import org.apache.jackrabbit.spi.SessionInfo;
 
+import javax.jcr.RepositoryException;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
@@ -34,6 +35,11 @@
     private String userId;
 
     /**
+     * The user data or <code>null</code>.
+     */
+    private String userData;
+
+    /**
      * The name of the workspace to connect to or <code>null</code> if this
      * session info refers to the default workspace.
      */
@@ -105,4 +111,11 @@
     public void removeLockToken(String s) {
         lockTokens.remove(s);
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setUserData(String userData) throws RepositoryException {
+        this.userData = userData;
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/SessionInfoLogger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/SessionInfoLogger.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/SessionInfoLogger.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/SessionInfoLogger.java
Tue Jun  2 15:13:53 2009
@@ -88,5 +88,14 @@
         }, "removeLockToken(String)", new Object[]{lockToken});
     }
 
+    public void setUserData(final String userData) throws RepositoryException {
+        execute(new Callable() {
+            public Object call() throws RepositoryException {
+                sessionInfo.setUserData(userData);
+                return null;
+            }
+        }, "setUserData(String)", new Object[]{userData});
+    }
+
 
 }

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/Event.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/Event.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/Event.java (original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/Event.java Tue
Jun  2 15:13:53 2009
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.spi;
 
+import javax.jcr.RepositoryException;
+import java.util.Map;
+
 /**
  * <code>Event</code> is similar to the regular JCR Event and adds additional
  * information about the affected item.
@@ -47,11 +50,28 @@
      */
     public static final int PROPERTY_CHANGED = javax.jcr.observation.Event.PROPERTY_CHANGED;
 
+
+    /**
+     * An event of this type is generated when a node is moved.
+     *
+     * @since JCR 2.0
+     */
+    public static final int NODE_MOVED = javax.jcr.observation.Event.NODE_MOVED;
+
+    /**
+     * If event bundling is supported, this event is used to indicate a
+     * bundle boundary within the event journal.
+     *
+     * @since JCR 2.0
+     */
+    public static final int PERSIST = javax.jcr.observation.Event.PERSIST;
+    
     /**
      * 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;
+            Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED |
+            Event.NODE_MOVED | Event.PERSIST;
 
     /**
      * Returns the type of this event: a constant defined by this interface.
@@ -62,6 +82,8 @@
      * <li><code>{@link #PROPERTY_ADDED}</code></li>
      * <li><code>{@link #PROPERTY_REMOVED}</code></li>
      * <li><code>{@link #PROPERTY_CHANGED}</code></li>
+     * <li><code>{@link #NODE_MOVED}</code></li>
+     * <li><code>{@link #PERSIST}</code></li>
      * </ul>
      *
      * @return the type of this event.
@@ -105,4 +127,33 @@
      * @return a <code>String</code>.
      */
     public String getUserID();
+
+    /**
+     * Returns the information map associated with this event.
+     *
+     * @return A <code>Map</code> containing parameter information.
+     * @throws RepositoryException if an error occurs.
+     * @see javax.jcr.observation.Event#getInfo()
+     * @since JCR 2.0
+     */
+    public Map<Name, QValue> getInfo() throws RepositoryException;
+
+    /**
+     * Returns the user data.
+     *
+     * @return the user data
+     * @see javax.jcr.observation.Event#getUserData()
+     * @since JCR 2.0
+     */
+    public String getUserData();
+
+    /**
+     * Returns the date when the change was persisted that caused this event.
+     *
+     * @return the date when the change was persisted that caused this event.
+     * @throws javax.jcr.RepositoryException if an error occurs.
+     * @see javax.jcr.observation.Event#getDate()
+     * @since JCR 2.0
+     */
+    public long getDate() throws RepositoryException;
 }

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/SessionInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/SessionInfo.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/SessionInfo.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/SessionInfo.java
Tue Jun  2 15:13:53 2009
@@ -87,4 +87,13 @@
      * @throws RepositoryException If another error occurs.
      */
     public void removeLockToken(String lockToken) throws UnsupportedRepositoryOperationException,
LockException, RepositoryException;
+
+    /**
+     * Sets the user data used for {@link org.apache.jackrabbit.spi.Event#getUserData()}.
+     *
+     * @param userData
+     * @throws RepositoryException
+     * @see javax.jcr.observation.ObservationManager#setUserData(String)
+     */
+    public void setUserData(String userData) throws RepositoryException;
 }

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventImpl.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/EventImpl.java
Tue Jun  2 15:13:53 2009
@@ -37,6 +37,7 @@
                 null, // TODO not available from XML_EVENT element
                 null, // TODO not available from XML_EVENT element
                 DomUtil.getChildTextTrim(eventElement, XML_EVENTUSERID, NAMESPACE));
+        // TODO: extend jcr-server to deliver jsr 283 event information
     }
 
     //--------------------------------------------------------------------------
@@ -52,6 +53,10 @@
                 return Event.PROPERTY_CHANGED;
             case javax.jcr.observation.Event.PROPERTY_REMOVED:
                 return Event.PROPERTY_REMOVED;
+            case javax.jcr.observation.Event.NODE_MOVED:
+                return Event.NODE_MOVED;
+            case javax.jcr.observation.Event.PERSIST:
+                return Event.PERSIST;
             default:
                 throw new IllegalArgumentException("Invalid event type: " + jcrEventType);
         }

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
Tue Jun  2 15:13:53 2009
@@ -16,20 +16,18 @@
  */
 package org.apache.jackrabbit.spi2dav;
 
-import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 
 import java.util.HashSet;
 import java.util.Set;
+import java.util.Arrays;
 
 /**
  * <code>SessionInfoImpl</code>...
  */
-public class SessionInfoImpl implements SessionInfo {
+public class SessionInfoImpl extends org.apache.jackrabbit.spi.commons.SessionInfoImpl {
 
     private final CredentialsWrapper credentials;
-    private final String workspaceName;
-    private final Set lockTokens = new HashSet();
     private final Set sessionScopedTokens = new HashSet();
 
     private String lastBatchId;
@@ -37,7 +35,8 @@
 
     SessionInfoImpl(CredentialsWrapper creds, String workspaceName) {
         this.credentials = creds;
-        this.workspaceName = workspaceName;
+
+        super.setWorkspacename(workspaceName);
     }
 
     //--------------------------------------------------------< SessionInfo >---
@@ -48,34 +47,6 @@
         return credentials.getUserId();
     }
 
-    /**
-     * @inheritDoc
-     */
-    public String getWorkspaceName() {
-        return workspaceName;
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public String[] getLockTokens() {
-        return (String[]) lockTokens.toArray(new String[lockTokens.size()]);
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public void addLockToken(String lockToken) {
-        lockTokens.add(lockToken);
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public void removeLockToken(String lockToken) {
-        lockTokens.remove(lockToken);
-    }
-
     //--------------------------------------------------------------------------
 
     CredentialsWrapper getCredentials() {
@@ -119,7 +90,7 @@
      * JCR API for they belong to session-scoped locks.
      */
     String[] getAllLockTokens() {
-        Set s = new HashSet(lockTokens);
+        Set s = new HashSet(Arrays.asList(getLockTokens()));
         s.addAll(sessionScopedTokens);
         return (String[]) s.toArray(new String[s.size()]);
     }
@@ -128,7 +99,7 @@
         if (sessionScoped) {
             sessionScopedTokens.add(token);
         } else {
-            lockTokens.add(token);
+            super.addLockToken(token);
         }
     }
 
@@ -136,7 +107,7 @@
         if (sessionScoped) {
             sessionScopedTokens.remove(token);
         } else {
-            lockTokens.remove(token);
+            super.removeLockToken(token);
         }
     }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml Tue Jun  2 15:13:53 2009
@@ -69,11 +69,6 @@
               <value>
                 org.apache.jackrabbit.jcr2spi.name.NamespaceRegistryTest#testReRegisteredNamespaceVisibility
                 org.apache.jackrabbit.jcr2spi.name.NamespaceRegistryTest#testRegisteredNamespaceVisibility
-                org.apache.jackrabbit.test.api.observation.GetDateTest
-                org.apache.jackrabbit.test.api.observation.GetIdentifierTest
-                org.apache.jackrabbit.test.api.observation.GetInfoTest
-                org.apache.jackrabbit.test.api.observation.GetUserDataTest
-                org.apache.jackrabbit.test.api.observation.NodeMovedTest
                 org.apache.jackrabbit.test.api.observation.NodeReorderTest
                 org.apache.jackrabbit.test.api.observation.EventJournalTest
               </value>
@@ -122,13 +117,6 @@
       <artifactId>jackrabbit-jcr-commons</artifactId>
       <version>2.0-SNAPSHOT</version>
     </dependency>
-    <!-- tmp dependency to jackrabbit-api until jsr 283 is released -->
-    <dependency>
-      <groupId>org.apache.jackrabbit</groupId>
-      <artifactId>jackrabbit-api</artifactId>
-      <version>2.0-SNAPSHOT</version>
-    </dependency>
-    <!-- end of tmp dependency -->
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java
Tue Jun  2 15:13:53 2009
@@ -25,6 +25,8 @@
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.Subscription;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.commons.EventImpl;
 import org.apache.jackrabbit.spi.commons.EventBundleImpl;
 import org.apache.jackrabbit.spi.commons.EventFilterImpl;
@@ -41,12 +43,15 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
+import javax.jcr.PropertyType;
 import javax.jcr.nodetype.NodeType;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Iterator;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * <code>EventSubscription</code> listens for JCR events and creates SPI event
@@ -66,12 +71,16 @@
             | javax.jcr.observation.Event.NODE_REMOVED
             | javax.jcr.observation.Event.PROPERTY_ADDED
             | javax.jcr.observation.Event.PROPERTY_CHANGED
-            | javax.jcr.observation.Event.PROPERTY_REMOVED;
+            | javax.jcr.observation.Event.PROPERTY_REMOVED
+            | javax.jcr.observation.Event.NODE_MOVED
+            | javax.jcr.observation.Event.PERSIST;
 
     private final List eventBundles = new ArrayList();
 
     private final IdFactory idFactory;
 
+    private final QValueFactory qValueFactory;
+
     private final SessionInfoImpl sessionInfo;
 
     /**
@@ -93,6 +102,7 @@
      * Creates a new subscription for the passed session.
      *
      * @param idFactory   the id factory.
+     * @param qValueFactory
      * @param sessionInfo the session info.
      * @param filters     the filters that should be applied to the generated
      *                    events.
@@ -100,9 +110,11 @@
      *                             registered with the session.
      */
     EventSubscription(IdFactory idFactory,
+                      QValueFactory qValueFactory,
                       SessionInfoImpl sessionInfo,
                       EventFilter[] filters) throws RepositoryException {
         this.idFactory = idFactory;
+        this.qValueFactory = qValueFactory;
         this.sessionInfo = sessionInfo;
         this.resolver = sessionInfo.getNamePathResolver();
         setFilters(filters);
@@ -228,23 +240,40 @@
                 javax.jcr.observation.Event e = events.nextEvent();
                 Path p = resolver.getQPath(e.getPath());
                 Path parent = p.getAncestor(1);
+                int type = e.getType();
+
                 NodeId parentId = idFactory.createNodeId((String) null, parent);
-                ItemId itemId = null;
+                String identifier = e.getIdentifier();
+                ItemId itemId;
                 Node node = null;
-                switch (e.getType()) {
-                    case Event.NODE_ADDED:
-                        node = session.getItem(e.getPath()).getParent();
-                    case Event.NODE_REMOVED:
-                        itemId = idFactory.createNodeId((String) null, p);
-                        break;
-                    case Event.PROPERTY_ADDED:
-                    case Event.PROPERTY_CHANGED:
+                if (identifier != null) {
+                    itemId = idFactory.fromJcrIdentifier(e.getIdentifier());
+                    try {
                         node = session.getItem(e.getPath()).getParent();
-                    case Event.PROPERTY_REMOVED:
-                        itemId = idFactory.createPropertyId(parentId,
-                                p.getNameElement().getName());
-                        break;
+                    } catch (RepositoryException re) {
+                        // ignore. TODO improve
+                    }
+                } else {
+                    switch (type) {
+                        case Event.NODE_ADDED:
+                        case Event.NODE_MOVED:
+                            node = session.getItem(e.getPath()).getParent();
+                        case Event.NODE_REMOVED:
+                            itemId = idFactory.createNodeId((String) null, p);
+                            break;
+                        case Event.PROPERTY_ADDED:
+                        case Event.PROPERTY_CHANGED:
+                            node = session.getItem(e.getPath()).getParent();
+                        case Event.PROPERTY_REMOVED:
+                            itemId = idFactory.createPropertyId(parentId,
+                                    p.getNameElement().getName());
+                            break;
+                        case Event.PERSIST:
+                        default:
+                            itemId = null;
+                    }
                 }
+
                 Name nodeTypeName = null;
                 Name[] mixinTypes = new Name[0];
                 if (node != null) {
@@ -256,8 +285,18 @@
                     nodeTypeName = resolver.getQName(node.getPrimaryNodeType().getName());
                     mixinTypes = getNodeTypeNames(node.getMixinNodeTypes(), resolver);
                 }
+                Map<Name, QValue> info = new HashMap();
+                Map jcrInfo = e.getInfo();
+                for (Iterator it = jcrInfo.keySet().iterator(); it.hasNext();) {
+                    String key = it.next().toString();
+                    Name name = resolver.getQName(key);
+                    // TODO: review again. how to determine value type?
+                    QValue v = qValueFactory.create(jcrInfo.get(key).toString(), PropertyType.STRING);
+                    info.put(name, v);
+
+                }
                 Event spiEvent = new EventImpl(e.getType(), p, itemId, parentId,
-                        nodeTypeName, mixinTypes, e.getUserID());
+                        nodeTypeName, mixinTypes, e.getUserID(), e.getUserData(), e.getDate(),
info);
                 spiEvents.add(spiEvent);
             } catch (Exception ex) {
                 log.warn("Unable to create SPI Event: " + ex);

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
Tue Jun  2 15:13:53 2009
@@ -1064,7 +1064,7 @@
     public Subscription createSubscription(SessionInfo sessionInfo,
                                            EventFilter[] filters)
             throws UnsupportedRepositoryOperationException, RepositoryException {
-        return getSessionInfoImpl(sessionInfo).createSubscription(idFactory, filters);
+        return getSessionInfoImpl(sessionInfo).createSubscription(idFactory, qValueFactory,
filters);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/SessionInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/SessionInfoImpl.java?rev=781054&r1=781053&r2=781054&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/SessionInfoImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/SessionInfoImpl.java
Tue Jun  2 15:13:53 2009
@@ -22,6 +22,7 @@
 import org.apache.jackrabbit.spi.Subscription;
 import org.apache.jackrabbit.spi.EventFilter;
 import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.conversion.ParsingNameResolver;
@@ -153,15 +154,16 @@
      * Creates a subscriptions for this session info.
      *
      * @param idFactory the id factory.
+     * @param qValueFactory
      * @param filters the initial list of filters.
      * @return a subscription.
      * @throws RepositoryException
      */
-    Subscription createSubscription(IdFactory idFactory, EventFilter[] filters)
+    Subscription createSubscription(IdFactory idFactory, QValueFactory qValueFactory, EventFilter[]
filters)
             throws RepositoryException {
         synchronized (subscriptionChange) {
             List tmp = new ArrayList(subscriptions);
-            EventSubscription s = new EventSubscription(idFactory, this, filters);
+            EventSubscription s = new EventSubscription(idFactory, qValueFactory, this, filters);
             tmp.add(s);
             subscriptions = Collections.unmodifiableList(tmp);
             return s;
@@ -244,4 +246,8 @@
     public void removeLockToken(String lockToken) throws UnsupportedRepositoryOperationException,
LockException, RepositoryException {
         session.getWorkspace().getLockManager().removeLockToken(lockToken);
     }
+
+    public void setUserData(String userData) throws RepositoryException {
+        session.getWorkspace().getObservationManager().setUserData(userData);
+    }
 }



Mime
View raw message