jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r553547 - in /jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr: EventSubscription.java RepositoryServiceImpl.java
Date Thu, 05 Jul 2007 16:12:57 GMT
Author: mreutegg
Date: Thu Jul  5 09:12:57 2007
New Revision: 553547

URL: http://svn.apache.org/viewvc?view=rev&rev=553547
Log:
JCR-1010: Test failures with spi2jcr in AddEventListenerTest

Modified:
    jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java
    jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java

Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java?view=diff&rev=553547&r1=553546&r2=553547
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java
Thu Jul  5 09:12:57 2007
@@ -29,10 +29,17 @@
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.PathFormat;
 import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.NameFormat;
+import org.apache.jackrabbit.name.IllegalNameException;
+import org.apache.jackrabbit.name.UnknownPrefixException;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
 import javax.jcr.observation.EventListener;
+import javax.jcr.Session;
+import javax.jcr.Node;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.nodetype.NodeType;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Iterator;
@@ -61,11 +68,14 @@
 
     private final IdFactory idFactory;
 
+    private final SessionInfoImpl sessionInfo;
+
     private final NamespaceResolver nsResolver;
 
-    EventSubscription(IdFactory idFactory, NamespaceResolver nsResolver) {
+    EventSubscription(IdFactory idFactory, SessionInfoImpl sessionInfo) {
         this.idFactory = idFactory;
-        this.nsResolver = nsResolver;
+        this.sessionInfo = sessionInfo;
+        this.nsResolver = sessionInfo.getNamespaceResolver();
     }
 
     /**
@@ -135,25 +145,42 @@
         List spiEvents = new ArrayList();
         while (events.hasNext()) {
             try {
+                Session session = sessionInfo.getSession();
                 javax.jcr.observation.Event e = events.nextEvent();
                 Path p = PathFormat.parse(e.getPath(), nsResolver);
                 Path parent = p.getAncestor(1);
                 NodeId parentId = idFactory.createNodeId((String) null, parent);
                 ItemId itemId = null;
+                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:
+                        node = session.getItem(e.getPath()).getParent();
                     case Event.PROPERTY_REMOVED:
                         itemId = idFactory.createPropertyId(parentId,
                                 p.getNameElement().getName());
                         break;
                 }
+                QName nodeTypeName = null;
+                QName[] mixinTypes = new QName[0];
+                if (node != null) {
+                    try {
+                        parentId = idFactory.createNodeId(node.getUUID(), null);
+                    } catch (UnsupportedRepositoryOperationException ex) {
+                        // not referenceable
+                    }
+                    nodeTypeName = NameFormat.parse(
+                            node.getPrimaryNodeType().getName(), nsResolver);
+                    mixinTypes = getNodeTypeNames(
+                            node.getMixinNodeTypes(), nsResolver);
+                }
                 Event spiEvent = new EventImpl(e.getType(), p, itemId, parentId,
-                        null, new QName[0], e.getUserID());
+                        nodeTypeName, mixinTypes, e.getUserID());
                 spiEvents.add(spiEvent);
             } catch (Exception ex) {
                 log.warn("Unable to create SPI Event: " + ex);
@@ -165,5 +192,27 @@
             eventBundles.add(bundle);
             eventBundles.notify();
         }
+    }
+
+    /**
+     * Returns the qualified names of the passed node types using the namespace
+     * resolver to parse the names.
+     *
+     * @param nt         the node types
+     * @param nsResolver the namespace resolver.
+     * @return the qualified names of the node types.
+     * @throws IllegalNameException   if a node type returns an illegal name.
+     * @throws UnknownPrefixException if the nameo of a node type contains a
+     *                                prefix that is not known to <code>nsResolver</code>.
+     */
+    private static QName[] getNodeTypeNames(NodeType[] nt,
+                                     NamespaceResolver nsResolver)
+            throws IllegalNameException, UnknownPrefixException {
+        QName[] names = new QName[nt.length];
+        for (int i = 0; i < nt.length; i++) {
+            QName ntName = NameFormat.parse(nt[i].getName(), nsResolver);
+            names[i] = ntName;
+        }
+        return names;
     }
 }

Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java?view=diff&rev=553547&r1=553546&r2=553547
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
Thu Jul  5 09:12:57 2007
@@ -904,8 +904,7 @@
         // make sure there is an event subscription for this session info
         SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
         if (!subscriptions.containsKey(sInfo)) {
-            EventSubscription subscr = new EventSubscription(
-                    idFactory, sInfo.getNamespaceResolver());
+            EventSubscription subscr = new EventSubscription(idFactory, sInfo);
             ObservationManager obsMgr = sInfo.getSession().getWorkspace().getObservationManager();
             obsMgr.addEventListener(subscr, EventSubscription.ALL_EVENTS,
                     "/", true, null, null, true);



Mime
View raw message