jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r159669 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: ./ nodetype/ nodetype/virtual/ search/lucene/ state/ version/ version/persistence/ virtual/
Date Fri, 01 Apr 2005 09:23:24 GMT
Author: tripod
Date: Fri Apr  1 01:23:19 2005
New Revision: 159669

URL: http://svn.apache.org/viewcvs?view=rev&rev=159669
Log:
- adding indexing of nodetype 
- fixing indexing of versioning

Added:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateManager.java   (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionLabels.java   (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionLabelsImpl.java   (with props)
Removed:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionItemListener.java
Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.xml
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ItemState.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionHistory.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionItem.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryNodeState.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionItemImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java Fri Apr  1 01:23:19 2005
@@ -30,7 +30,7 @@
 import org.apache.jackrabbit.core.lock.LockManagerImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
-import org.apache.jackrabbit.core.nodetype.virtual.VirtualNodeTypeStateProvider;
+import org.apache.jackrabbit.core.nodetype.virtual.VirtualNodeTypeStateManager;
 import org.apache.jackrabbit.core.observation.ObservationManagerFactory;
 import org.apache.jackrabbit.core.observation.DelegatingObservationDispatcher;
 import org.apache.jackrabbit.core.security.CredentialsCallbackHandler;
@@ -107,6 +107,7 @@
     private final NodeTypeRegistry ntReg;
     private final PersistentVersionManager pvMgr;
     private final VersionManager vMgr;
+    private final VirtualNodeTypeStateManager virtNTMgr;
 
     // configuration of the repository
     private final RepositoryConfig repConfig;
@@ -277,7 +278,12 @@
                 nsReg,
                 ntReg);
         pvMgr = new NativePVM(pm, getNodeTypeRegistry());
-        vMgr = new VersionManagerImpl(pvMgr, ntReg, delegatingDispatcher, VERSION_STORAGE_NODE_UUID, SYSTEM_ROOT_NODE_UUID);
+        vMgr = new VersionManagerImpl(pvMgr, ntReg, delegatingDispatcher,
+                VERSION_STORAGE_NODE_UUID, SYSTEM_ROOT_NODE_UUID);
+
+        // init virtual nodetype manager
+        virtNTMgr = new VirtualNodeTypeStateManager(getNodeTypeRegistry(),
+                delegatingDispatcher, NODETYPES_NODE_UUID, SYSTEM_ROOT_NODE_UUID);
 
         // initialize workspaces
         iter = wspInfos.keySet().iterator();
@@ -286,6 +292,10 @@
             initWorkspace(wspName);
         }
 
+        // after the workspaces are initialized, we setup a system session for
+        // the virtual nodetype manager
+        virtNTMgr.setSession(getSystemSession(repConfig.getDefaultWorkspaceName()));
+
         // finally register shutdown hook
         Runtime.getRuntime().addShutdownHook(new Thread() {
             public void run() {
@@ -1017,9 +1027,7 @@
                     itemStateMgr = new SharedItemStateManager(getPersistenceManager(config.getPersistenceManagerConfig()), rootNodeUUID, ntReg);
                     try {
                         itemStateMgr.addVirtualItemStateProvider(vMgr.getVirtualItemStateProvider(itemStateMgr));
-                        itemStateMgr.addVirtualItemStateProvider(
-                                new VirtualNodeTypeStateProvider(ntReg, NODETYPES_NODE_UUID, SYSTEM_ROOT_NODE_UUID)
-                        );
+                        itemStateMgr.addVirtualItemStateProvider(virtNTMgr.getVirtualItemStateProvider());
                     } catch (Exception e) {
                         log.error("Unable to add vmgr: " + e.toString(), e);
                     }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java Fri Apr  1 01:23:19 2005
@@ -382,7 +382,7 @@
      *
      * @return the <code>VersionManager</code> associated with this session
      */
-    protected VersionManager getVersionManager() {
+    public VersionManager getVersionManager() {
         return versionMgr;
     }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.xml
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.xml?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.xml (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.xml Fri Apr  1 01:23:19 2005
@@ -346,8 +346,14 @@
             </requiredPrimaryTypes>
         </childNodeDef>
     </nodeType>
+
     <!-- internal node types for persistent version manager -->
     <nodeType name="rep:versionHistory" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+        <supertypes>
+            <supertype>nt:unstructured</supertype>
+        </supertypes>
+    </nodeType>
+    <nodeType name="rep:versionLabels" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
         <supertypes>
             <supertype>nt:unstructured</supertype>
         </supertypes>

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateManager.java?view=auto&rev=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateManager.java (added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateManager.java Fri Apr  1 01:23:19 2005
@@ -0,0 +1,225 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.core.nodetype.virtual;
+
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistryListener;
+import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
+import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.NodeImpl;
+import org.apache.jackrabbit.core.PropertyImpl;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
+import org.apache.jackrabbit.core.observation.DelegatingObservationDispatcher;
+import org.apache.jackrabbit.core.observation.EventState;
+import org.apache.log4j.Logger;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.PropertyIterator;
+import javax.jcr.NodeIterator;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * This Class implements a workaround helper for populating observation
+ * events for the virtual node states of the jcr:nodeTypes upon nodetype
+ * registry changes.
+ */
+public class VirtualNodeTypeStateManager implements NodeTypeRegistryListener {
+
+    /**
+     * the default logger
+     */
+    private static Logger log = Logger.getLogger(VirtualNodeTypeStateManager.class);
+
+
+    /**
+     * an item state provider for the virtual nodetype states
+     */
+    private VirtualNodeTypeStateProvider virtProvider;
+
+    /**
+     * the node type registry
+     */
+    private final NodeTypeRegistry ntReg;
+
+    /**
+     * the root node id (usually the id of /jcr:system/jcr:nodeTypes)
+     */
+    private final String rootNodeId;
+
+    /**
+     * the id of the roots parent (usually id of /jcr:system)
+     */
+    private final String parentId;
+
+    /**
+     * the system session to generate the observation events
+     */
+    private SessionImpl systemSession;
+
+    /**
+     * the delegtating observation manager, that dispatches the events to
+     * all underlaying ones.
+     */
+    private DelegatingObservationDispatcher obsDispatcher;
+
+    /**
+     * Creates a new virtual node type state manager
+     *
+     * @param ntReg
+     * @param obs
+     * @param rootNodeId
+     * @param parentId
+     */
+    public VirtualNodeTypeStateManager(NodeTypeRegistry ntReg, DelegatingObservationDispatcher obs, String rootNodeId, String parentId) {
+        this.ntReg = ntReg;
+        this.obsDispatcher = obs;
+        this.rootNodeId = rootNodeId;
+        this.parentId = parentId;
+        ntReg.addListener(this);
+    }
+
+    /**
+     * returns the virtual node state provider for the node type states.
+     * @return
+     */
+    public synchronized VirtualItemStateProvider getVirtualItemStateProvider() {
+        if (virtProvider == null) {
+            virtProvider = new VirtualNodeTypeStateProvider(ntReg, rootNodeId, parentId);
+        }
+        return virtProvider;
+    }
+
+    /**
+     * Sets the system session. This is needed, since the session should be
+     * set, after the workspaces are initialzed.
+     *
+     * @param systemSession
+     */
+    public void setSession(SessionImpl systemSession) {
+        this.systemSession = systemSession;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void nodeTypeRegistered(QName ntName) {
+        try {
+            // allow provider to update
+            virtProvider.onNodeTypeAdded(ntName);
+
+            NodeImpl root = (NodeImpl) systemSession.getItemManager().getItem(new NodeId(rootNodeId));
+            NodeImpl child = root.getNode(ntName);
+            List events = new ArrayList();
+            recursiveAdd(events, root, child);
+            obsDispatcher.dispatch(events, systemSession);
+        } catch (RepositoryException e) {
+            log.error("Unable to index new nodetype: " + e.toString());
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void nodeTypeReRegistered(QName ntName) {
+        // lazy implementation
+        nodeTypeUnregistered(ntName);
+        nodeTypeRegistered(ntName);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void nodeTypeUnregistered(QName ntName) {
+        try {
+            NodeImpl root = (NodeImpl) systemSession.getItemManager().getItem(new NodeId(rootNodeId));
+            NodeImpl child = root.getNode(ntName);
+            List events = new ArrayList();
+            recursiveRemove(events, root, child);
+            obsDispatcher.dispatch(events, systemSession);
+            virtProvider.onNodeTypeRemoved(ntName);
+        } catch (RepositoryException e) {
+            log.error("Unable to index removed nodetype: " + e.toString());
+        }
+    }
+
+    /**
+     * Adds a subtree of itemstates as 'added' to a list of events
+     *
+     * @param events
+     * @param parent
+     * @param node
+     * @throws RepositoryException
+     */
+    private void recursiveAdd(List events, NodeImpl parent, NodeImpl node)
+            throws RepositoryException {
+
+        events.add(EventState.childNodeAdded(
+                parent.internalGetUUID(),
+                parent.getPrimaryPath(),
+                node.internalGetUUID(),
+                node.getPrimaryPath().getNameElement(),
+                (NodeTypeImpl) parent.getPrimaryNodeType(),
+                node.getSession()
+        ));
+
+        PropertyIterator iter = node.getProperties();
+        while (iter.hasNext()) {
+            PropertyImpl prop = (PropertyImpl) iter.nextProperty();
+            events.add(EventState.propertyAdded(
+                    node.internalGetUUID(),
+                    node.getPrimaryPath(),
+                    prop.getPrimaryPath().getNameElement(),
+                    (NodeTypeImpl) node.getPrimaryNodeType(),
+                    node.getSession()
+            ));
+        }
+        NodeIterator niter = node.getNodes();
+        while (niter.hasNext()) {
+            NodeImpl n = (NodeImpl) niter.nextNode();
+            recursiveAdd(events, node, n);
+        }
+    }
+
+    /**
+     * Adds a subtree of itemstates as 'removed' to a list of events
+     *
+     * @param events
+     * @param parent
+     * @param node
+     * @throws RepositoryException
+     */
+    private void recursiveRemove(List events, NodeImpl parent, NodeImpl node)
+            throws RepositoryException {
+
+        events.add(EventState.childNodeRemoved(
+                parent.internalGetUUID(),
+                parent.getPrimaryPath(),
+                node.internalGetUUID(),
+                node.getPrimaryPath().getNameElement(),
+                (NodeTypeImpl) parent.getPrimaryNodeType(),
+                node.getSession()
+        ));
+        NodeIterator niter = node.getNodes();
+        while (niter.hasNext()) {
+            NodeImpl n = (NodeImpl) niter.nextNode();
+            recursiveRemove(events, node, n);
+        }
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateManager.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java Fri Apr  1 01:23:19 2005
@@ -21,24 +21,27 @@
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.QName;
 import org.apache.jackrabbit.core.InternalValue;
+import org.apache.jackrabbit.core.util.uuid.UUID;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
 import org.apache.jackrabbit.core.nodetype.PropDef;
 import org.apache.jackrabbit.core.nodetype.ChildNodeDef;
 import org.apache.jackrabbit.core.nodetype.ValueConstraint;
-import org.apache.jackrabbit.core.nodetype.NodeTypeRegistryListener;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.PropertyType;
 import javax.jcr.version.OnParentVersionAction;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.io.UnsupportedEncodingException;
 
 /**
  * This Class implements a virtual item state provider that exposes the
  * registered nodetypes.
  */
-public class VirtualNodeTypeStateProvider extends AbstractVISProvider implements NodeTypeRegistryListener {
+public class VirtualNodeTypeStateProvider extends AbstractVISProvider {
 
     /**
      * the parent id
@@ -54,7 +57,6 @@
     public VirtualNodeTypeStateProvider(NodeTypeRegistry ntReg, String rootNodeId, String parentId) {
         super(ntReg, new NodeId(rootNodeId));
         this.parentId = parentId;
-        ntReg.addListener(this);
     }
 
     /**
@@ -92,36 +94,42 @@
     /**
      * {@inheritDoc}
      */
-    public void nodeTypeRegistered(QName ntName) {
-        // todo: do more efficient reloading
+    public void onNodeTypeAdded(QName ntName) throws RepositoryException {
         try {
-            getRootState().discard();
+            VirtualNodeState root = (VirtualNodeState) getRootState();
+            NodeTypeDef ntDef = ntReg.getNodeTypeDef(ntName);
+            VirtualNodeState ntState = createNodeTypeState(root, ntDef);
+            root.addChildNodeEntry(ntName, ntState.getUUID());
+
+            // add as hard reference
+            root.addStateReference(ntState);
+            root.notifyStateUpdated();
         } catch (ItemStateException e) {
-            // ignore
+            throw new RepositoryException(e);
         }
     }
 
     /**
      * {@inheritDoc}
      */
-    public void nodeTypeReRegistered(QName ntName) {
+    public void onNodeTypeModified(QName ntName) throws RepositoryException {
         // todo: do more efficient reloading
         try {
             getRootState().discard();
         } catch (ItemStateException e) {
-            // ignore
+            throw new RepositoryException(e);
         }
     }
 
     /**
      * {@inheritDoc}
      */
-    public void nodeTypeUnregistered(QName ntName) {
+    public void onNodeTypeRemoved(QName ntName) throws RepositoryException {
         // todo: do more efficient reloading
         try {
             getRootState().discard();
         } catch (ItemStateException e) {
-            // ignore
+            throw new RepositoryException(e);
         }
     }
 
@@ -133,7 +141,8 @@
      * @throws RepositoryException
      */
     private VirtualNodeState createNodeTypeState(VirtualNodeState parent, NodeTypeDef ntDef) throws RepositoryException {
-        VirtualNodeState ntState = createNodeState(parent, ntDef.getName(), null, NT_NODETYPE);
+        String uuid = calculateStableUUID(ntDef.getName().toString());
+        VirtualNodeState ntState = createNodeState(parent, ntDef.getName(), uuid, NT_NODETYPE);
 
         // add properties
         ntState.setPropertyValue(JCR_NODETYPENAME, InternalValue.create(ntDef.getName()));
@@ -147,7 +156,7 @@
         // add property defs
         PropDef[] propDefs = ntDef.getPropertyDefs();
         for (int i=0; i<propDefs.length; i++) {
-            VirtualNodeState pdState = createPropertyDefState(ntState, propDefs[i]);
+            VirtualNodeState pdState = createPropertyDefState(ntState, propDefs[i], ntDef, i);
             ntState.addChildNodeEntry(JCR_PROPERTYDEF, pdState.getUUID());
             // add as hard reference
             ntState.addStateReference(pdState);
@@ -156,7 +165,7 @@
         // add child node defs
         ChildNodeDef[] cnDefs = ntDef.getChildNodeDefs();
         for (int i=0; i<cnDefs.length; i++) {
-            VirtualNodeState cnState = createChildNodeDefState(ntState, cnDefs[i]);
+            VirtualNodeState cnState = createChildNodeDefState(ntState, cnDefs[i], ntDef, i);
             ntState.addChildNodeEntry(JCR_CHILDNODEDEF, cnState.getUUID());
             // add as hard reference
             ntState.addStateReference(cnState);
@@ -172,8 +181,12 @@
      * @return
      * @throws RepositoryException
      */
-    private VirtualNodeState createPropertyDefState(VirtualNodeState parent, PropDef propDef) throws RepositoryException {
-        VirtualNodeState pState = createNodeState(parent, JCR_PROPERTYDEF, null, NT_PROPERTYDEF);
+    private VirtualNodeState createPropertyDefState(VirtualNodeState parent,
+                                                    PropDef propDef,
+                                                    NodeTypeDef ntDef, int n)
+            throws RepositoryException {
+        String uuid = calculateStableUUID(ntDef.getName().toString() + "/" + JCR_PROPERTYDEF.toString() + "/" + n);
+        VirtualNodeState pState = createNodeState(parent, JCR_PROPERTYDEF, uuid, NT_PROPERTYDEF);
         // add properties
         pState.setPropertyValue(JCR_NAME, InternalValue.create(propDef.getName()));
         pState.setPropertyValue(JCR_AUTOCREATE, InternalValue.create(propDef.isAutoCreate()));
@@ -199,8 +212,12 @@
      * @return
      * @throws RepositoryException
      */
-    private VirtualNodeState createChildNodeDefState(VirtualNodeState parent, ChildNodeDef cnDef) throws RepositoryException {
-        VirtualNodeState pState = createNodeState(parent, JCR_CHILDNODEDEF, null, NT_CHILDNODEDEF);
+    private VirtualNodeState createChildNodeDefState(VirtualNodeState parent,
+                                                     ChildNodeDef cnDef,
+                                                     NodeTypeDef ntDef, int n)
+            throws RepositoryException {
+        String uuid = calculateStableUUID(ntDef.getName().toString() + "/" + JCR_CHILDNODEDEF.toString() + "/" + n);
+        VirtualNodeState pState = createNodeState(parent, JCR_CHILDNODEDEF, uuid, NT_CHILDNODEDEF);
         // add properties
         pState.setPropertyValue(JCR_NAME, InternalValue.create(cnDef.getName()));
         pState.setPropertyValue(JCR_AUTOCREATE, InternalValue.create(cnDef.isAutoCreate()));
@@ -213,5 +230,25 @@
         }
         pState.setPropertyValue(JCR_SAMENAMESIBS, InternalValue.create(cnDef.allowSameNameSibs()));
         return pState;
+    }
+    
+    /**
+     * Calclulates a stable uuid out of the given string. The alogrith does a
+     * MD5 digest from the string an converts it into the uuid format.
+     * 
+     * @param name
+     * @return
+     * @throws RepositoryException
+     */ 
+    private static String calculateStableUUID(String name) throws RepositoryException {
+        try {
+            MessageDigest md = MessageDigest.getInstance("MD5");
+            byte[] digest = md.digest(name.getBytes("utf-8"));
+            return new UUID(digest).toString();
+        } catch (NoSuchAlgorithmException e) {
+            throw new RepositoryException(e);
+        } catch (UnsupportedEncodingException e) {
+            throw new RepositoryException(e);
+        }
     }
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java Fri Apr  1 01:23:19 2005
@@ -363,11 +363,7 @@
         for (Iterator it = children.iterator(); it.hasNext();) {
             NodeState.ChildNodeEntry child = (NodeState.ChildNodeEntry) it.next();
             NodeState childState = (NodeState) isMgr.getItemState(new NodeId(child.getUUID()));
-            // only traverse if node is not a virtual node state
-            if (!(childState instanceof VirtualNodeState)
-                    && !(childState.getOverlayedState() instanceof VirtualNodeState)) {
-                createIndex(childState);
-            }
+            createIndex(childState);
         }
     }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ItemState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ItemState.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ItemState.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ItemState.java Fri Apr  1 01:23:19 2005
@@ -251,7 +251,7 @@
      * Notify the listeners that the persistent state this object is
      * representing has been updated.
      */
-    protected void notifyStateUpdated() {
+    public void notifyStateUpdated() {
         // copy listeners to array to avoid ConcurrentModificationException
         ItemStateListener[] la = new ItemStateListener[listeners.size()];
         Iterator iter = listeners.values().iterator();

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionHistory.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionHistory.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionHistory.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionHistory.java Fri Apr  1 01:23:19 2005
@@ -20,6 +20,7 @@
 
 import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
+import javax.jcr.RepositoryException;
 import java.util.Iterator;
 
 /**
@@ -86,36 +87,28 @@
      * version node and all its subnodes are removed.
      *
      * @param versionName the name of the version to be removed
-     * @throws VersionException if an error occurrs.
+     * @throws RepositoryException if an error occurrs.
      */
-    public void removeVersion(QName versionName) throws VersionException;
+    public void removeVersion(QName versionName) throws RepositoryException;
 
     /**
-     * Adds a label to a version. If the given label is already assigned to
-     * another version in this version history, a VersionException is thrown,
-     * unless <code>move</code> is set to <code>true</code>. in this case, the
-     * label is removed from the previously assigned version and added to the
-     * specified one.
+     * Sets the version <code>label</code> to the given <code>version</code>.
+     * If the label is already assigned to another version, a VersionException is
+     * thrown unless <code>move</code> is <code>true</code>. If <code>version</code>
+     * is <code>null</code>, the label is removed from the respective version.
+     * In either case, the version the label was previously assigned to is returned,
+     * or <code>null</code> of the label was not moved.
      *
-     * @param name  the name of the version
+     * @param version the name of the version
      * @param label the label to assgign
      * @param move  flag what to do by collisions
      * @return the version that was previously assigned by this label or <code>null</code>.
      * @throws VersionException
      */
-    public InternalVersion addVersionLabel(QName name, QName label, boolean move)
+    public InternalVersion setVersionLabel(QName version, QName label, boolean move)
             throws VersionException;
 
     /**
-     * Removes the label from the respective version.
-     *
-     * @param label the label to be removed
-     * @return the version that had the label assigned
-     * @throws VersionException if the label does not exist
-     */
-    public InternalVersion removeVersionLabel(QName label) throws VersionException;
-
-    /**
      * Returns an iterator over all versions (not ordered yet), including the
      * root version.
      *
@@ -147,7 +140,7 @@
 
     /**
      * Returns the UUID of the version labels node
-     * 
+     *
      * @return
      */
     public String getVersionLabelsUUID();

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionItem.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionItem.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionItem.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionItem.java Fri Apr  1 01:23:19 2005
@@ -38,10 +38,4 @@
      */
     public InternalVersionItem getParent();
 
-    /**
-     * Adds a vesion item state listener to this item
-     *
-     * @param listener
-     */
-    public void addListener(InternalVersionItemListener listener);
 }

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionLabels.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionLabels.java?view=auto&rev=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionLabels.java (added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionLabels.java Fri Apr  1 01:23:19 2005
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.core.version;
+
+/**
+ * This Interface defines...
+ *
+ * @author tripod
+ * @version $Revision:$, $Date:$
+ */
+public interface InternalVersionLabels extends InternalVersionItem {
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionLabels.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/InternalVersionLabels.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java Fri Apr  1 01:23:19 2005
@@ -22,11 +22,9 @@
 import org.apache.jackrabbit.core.NoPrefixDeclaredException;
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.NodeImpl;
-import org.apache.jackrabbit.core.PropertyImpl;
 import org.apache.jackrabbit.core.QName;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.UnknownPrefixException;
-import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.state.NodeState;
 
 import javax.jcr.Item;
@@ -123,12 +121,15 @@
     /**
      * @see VersionHistory#addVersionLabel(String, String, boolean)
      */
-    public void addVersionLabel(String version, String label, boolean move)
+    public void addVersionLabel(String versionName, String label, boolean move)
             throws VersionException, RepositoryException {
         try {
-            QName name = QName.fromJCRName(version, session.getNamespaceResolver());
-            QName qLabel = QName.fromJCRName(label, session.getNamespaceResolver());
-            history.addVersionLabel(name, qLabel, move);
+            session.getVersionManager().setVersionLabel(
+                    this,
+                    QName.fromJCRName(versionName, session.getNamespaceResolver()),
+                    QName.fromJCRName(label, session.getNamespaceResolver()),
+                    move
+            );
         } catch (IllegalNameException e) {
             throw new RepositoryException(e);
         } catch (UnknownPrefixException e) {
@@ -141,8 +142,12 @@
      */
     public void removeVersionLabel(String label) throws RepositoryException {
         try {
-            QName qLabel = QName.fromJCRName(label, session.getNamespaceResolver());
-            history.removeVersionLabel(qLabel);
+            session.getVersionManager().setVersionLabel(
+                    this,
+                    null,
+                    QName.fromJCRName(label, session.getNamespaceResolver()),
+                    true
+            );
         } catch (IllegalNameException e) {
             throw new RepositoryException(e);
         } catch (UnknownPrefixException e) {
@@ -222,8 +227,10 @@
             throws UnsupportedRepositoryOperationException, VersionException,
             RepositoryException {
         try {
-            QName name = QName.fromJCRName(versionName, session.getNamespaceResolver());
-            history.removeVersion(name);
+            session.getVersionManager().removeVersion(
+                    this,
+                    QName.fromJCRName(versionName, session.getNamespaceResolver())
+            );
         } catch (IllegalNameException e) {
             throw new RepositoryException(e);
         } catch (UnknownPrefixException e) {
@@ -282,5 +289,14 @@
      */
     public PropertyIterator getReferences() throws RepositoryException {
         return getReferences(true);
+    }
+
+
+    /**
+     * Returns the internal version history
+     * @return
+     */
+    public InternalVersionHistory getInternalVersionHistory() {
+        return history;
     }
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryNodeState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryNodeState.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryNodeState.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionHistoryNodeState.java Fri Apr  1 01:23:19 2005
@@ -19,6 +19,7 @@
 import org.apache.jackrabbit.core.Constants;
 import org.apache.jackrabbit.core.InternalValue;
 import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.util.uuid.UUID;
 import org.apache.jackrabbit.core.virtual.VirtualNodeState;
 
 import javax.jcr.RepositoryException;
@@ -52,6 +53,9 @@
 
         // version history is referenceable
         setPropertyValue(JCR_UUID, InternalValue.create(vh.getId()));
+
+        // enable for spec 0.16.3
+        // setPropertyValue(JCR_VERSIONABLEUUID, InternalValue.create(vh.getVersionableUUID()));
 
         this.vh = vh;
     }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java Fri Apr  1 01:23:19 2005
@@ -182,6 +182,12 @@
                 state.addStateReference(vlns);
                 cache(vlns);
 
+            } else if (vi instanceof InternalVersionLabels) {
+                // load parent, that must be a version history
+                getItemState(new NodeId(vi.getParent().getId()));
+                // this is a bit dangerous
+                state = (VirtualNodeState) getItemState(id);
+
             } else if (vi instanceof InternalVersion) {
                 InternalVersion v = (InternalVersion) vi;
                 state = new VersionNodeState(this, v, vi.getParent().getId());

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManager.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManager.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManager.java Fri Apr  1 01:23:19 2005
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.version;
 
 import org.apache.jackrabbit.core.NodeImpl;
+import org.apache.jackrabbit.core.QName;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
 
@@ -60,6 +61,33 @@
      * @throws RepositoryException
      */
     public Version checkin(NodeImpl node) throws RepositoryException;
+
+    /**
+     * Removes the specified version from the given version history.
+     * @param history
+     * @param versionName
+     * @throws RepositoryException
+     */
+    public void removeVersion(VersionHistory history, QName versionName)
+            throws RepositoryException;
+
+    /**
+     * Sets the version <code>label</code> to the given <code>version</code>.
+     * If the label is already assigned to another version, a VersionException is
+     * thrown unless <code>move</code> is <code>true</code>. If <code>version</code>
+     * is <code>null</code>, the label is removed from the respective version.
+     * In either case, the version the label was previously assigned is returned,
+     * or <code>null</code> of the label was not moved.
+     * 
+     * @param history
+     * @param version
+     * @param label
+     * @param move
+     * @return
+     * @throws RepositoryException
+     */
+    public Version setVersionLabel(VersionHistory history, QName version, QName label, boolean move)
+            throws RepositoryException;
 
     //-----------------------------------------------------< internal stuff >---
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java Fri Apr  1 01:23:19 2005
@@ -16,17 +16,18 @@
  */
 package org.apache.jackrabbit.core.version;
 
-import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.NodeImpl;
 import org.apache.jackrabbit.core.Constants;
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.PropertyImpl;
+import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.Path;
+import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.observation.DelegatingObservationDispatcher;
 import org.apache.jackrabbit.core.observation.EventState;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
-import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
 import org.apache.log4j.Logger;
@@ -34,6 +35,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.PropertyIterator;
 import javax.jcr.NodeIterator;
+import javax.jcr.Session;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 import java.util.Iterator;
@@ -46,7 +48,7 @@
  * version storage ({@link VersionItemStateProvider}) and the persistent
  * version manager.
  */
-public class VersionManagerImpl implements VersionManager, Constants, InternalVersionItemListener {
+public class VersionManagerImpl implements VersionManager, Constants {
 
     /**
      * the default logger
@@ -140,11 +142,10 @@
      */
     public VersionHistory createVersionHistory(NodeImpl node) throws RepositoryException {
         InternalVersionHistory history = vMgr.createVersionHistory(node);
-        history.addListener(this);
-        onVersionStorageChanged();
+        virtProvider.invalidateItem(new NodeId(VERSION_STORAGE_NODE_UUID));
         VersionHistoryImpl vh = (VersionHistoryImpl) node.getSession().getNodeByUUID(history.getId());
 
-        // now generate observation events
+        // generate observation events
         List events = new ArrayList();
         recursiveAdd(events, (NodeImpl) vh.getParent(), vh);
         obsMgr.dispatch(events, (SessionImpl) node.getSession());
@@ -170,11 +171,7 @@
      * @throws RepositoryException
      */
     public InternalVersionHistory getVersionHistory(String id) throws RepositoryException {
-        InternalVersionHistory hist = vMgr.getVersionHistory(id);
-        if (hist != null) {
-            hist.addListener(this);
-        }
-        return hist;
+        return vMgr.getVersionHistory(id);
     }
 
     /**
@@ -215,11 +212,7 @@
      * @throws RepositoryException
      */
     public InternalVersion getVersion(String id) throws RepositoryException {
-        InternalVersion vers = vMgr.getVersion(id);
-        if (vers != null) {
-            vers.addListener(this);
-        }
-        return vers;
+        return vMgr.getVersion(id);
     }
 
     /**
@@ -240,11 +233,7 @@
      * @throws RepositoryException
      */
     public InternalVersionItem getItem(String id) throws RepositoryException {
-        InternalVersionItem item = vMgr.getItem(id);
-        if (item != null) {
-            item.addListener(this);
-        }
-        return item;
+        return vMgr.getItem(id);
     }
 
     /**
@@ -258,10 +247,10 @@
     public Version checkin(NodeImpl node) throws RepositoryException {
         SessionImpl session = (SessionImpl) node.getSession();
         InternalVersion version = vMgr.checkin(node);
-        version.addListener(this);
+        virtProvider.invalidateItem(new NodeId(version.getVersionHistory().getId()));
         VersionImpl v = (VersionImpl) session.getNodeByUUID(version.getId());
 
-        // now generate observation events
+        // generate observation events
         List events = new ArrayList();
         recursiveAdd(events, (NodeImpl) v.getParent(), v);
         obsMgr.dispatch(events, session);
@@ -270,6 +259,72 @@
     }
 
     /**
+     * Removes the specified version from the history
+     * @param history
+     * @param name
+     */
+    public void removeVersion(VersionHistory history, QName name)
+            throws RepositoryException {
+        // generate observation events
+        VersionImpl version = (VersionImpl) ((VersionHistoryImpl) history).getNode(name);
+        List events = new ArrayList();
+        recursiveRemove(events, (NodeImpl) history, version);
+
+        InternalVersionHistory vh = ((VersionHistoryImpl) history).getInternalVersionHistory();
+        vh.removeVersion(name);
+
+        virtProvider.invalidateItem(new NodeId(vh.getId()));
+        obsMgr.dispatch(events, (SessionImpl) history.getSession());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Version setVersionLabel(VersionHistory history, QName version,
+                                   QName label, boolean move)
+            throws RepositoryException {
+        Session session = history.getSession();
+
+        InternalVersionHistory vh = ((VersionHistoryImpl) history).getInternalVersionHistory();
+        NodeImpl labelNode = ((VersionHistoryImpl) history).getNode(JCR_VERSIONLABELS);
+        InternalVersion v = vh.setVersionLabel(version, label, move);
+
+        // collect observation events
+        List events = new ArrayList();
+        if (version == null && v != null) {
+            // label removed
+            events.add(EventState.propertyRemoved(
+                    labelNode.internalGetUUID(),
+                    labelNode.getPrimaryPath(),
+                    Path.PathElement.fromString(label.toString()),
+                    (NodeTypeImpl) labelNode.getPrimaryNodeType(),
+                    labelNode.getSession()
+            ));
+        } else if (v == null) {
+            // label added
+            events.add(EventState.propertyAdded(
+                    labelNode.internalGetUUID(),
+                    labelNode.getPrimaryPath(),
+                    Path.PathElement.fromString(label.toString()),
+                    (NodeTypeImpl) labelNode.getPrimaryNodeType(),
+                    labelNode.getSession()
+            ));
+        } else {
+            // label modified
+            events.add(EventState.propertyChanged(
+                    labelNode.internalGetUUID(),
+                    labelNode.getPrimaryPath(),
+                    Path.PathElement.fromString(label.toString()),
+                    (NodeTypeImpl) labelNode.getPrimaryNodeType(),
+                    labelNode.getSession()
+            ));
+        }
+        virtProvider.invalidateItem(new NodeId(vh.getId()));
+        obsMgr.dispatch(events, (SessionImpl) history.getSession());
+        return v == null ? null : (VersionImpl) session.getNodeByUUID(v.getId());
+    }
+
+    /**
      * Adds a subtree of itemstates as 'added' to a list of events
      *
      * @param events
@@ -308,6 +363,32 @@
     }
 
     /**
+     * Adds a subtree of itemstates as 'removed' to a list of events
+     *
+     * @param events
+     * @param parent
+     * @param node
+     * @throws RepositoryException
+     */
+    private void recursiveRemove(List events, NodeImpl parent, NodeImpl node)
+            throws RepositoryException {
+
+        events.add(EventState.childNodeRemoved(
+                parent.internalGetUUID(),
+                parent.getPrimaryPath(),
+                node.internalGetUUID(),
+                node.getPrimaryPath().getNameElement(),
+                (NodeTypeImpl) parent.getPrimaryNodeType(),
+                node.getSession()
+        ));
+        NodeIterator niter = node.getNodes();
+        while (niter.hasNext()) {
+            NodeImpl n = (NodeImpl) niter.nextNode();
+            recursiveRemove(events, node, n);
+        }
+    }
+
+    /**
      * {@inheritDoc}
      */
     public List getItemReferences(InternalVersionItem item) {
@@ -328,33 +409,5 @@
             }
         }
         vMgr.setItemReferences(item, refs);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void itemModifed(InternalVersionItem item) {
-        try {
-            NodeId id = new NodeId(item.getId());
-            if (virtProvider.hasItemState(id)) {
-                virtProvider.getItemState(id).discard();
-            }
-        } catch (ItemStateException e) {
-            log.error("Error while refreshing virtual item.", e);
-        }
-    }
-
-    /**
-     * Flushes the virtual node state information of the version storage
-     */
-    public void onVersionStorageChanged() {
-        try {
-            NodeId id = new NodeId(VERSION_STORAGE_NODE_UUID);
-            if (virtProvider.hasItemState(id)) {
-                virtProvider.getItemState(id).discard();
-            }
-        } catch (ItemStateException e) {
-            log.error("Error while refreshing virtual version storage.", e);
-        }
     }
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java Fri Apr  1 01:23:19 2005
@@ -32,6 +32,7 @@
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
+import javax.jcr.ReferentialIntegrityException;
 import javax.jcr.version.VersionException;
 import java.util.Calendar;
 import java.util.HashMap;
@@ -235,7 +236,7 @@
      * @param versionName
      * @throws VersionException
      */
-    public void removeVersion(QName versionName) throws VersionException {
+    public void removeVersion(QName versionName) throws RepositoryException {
 
         InternalVersionImpl v = (InternalVersionImpl) getVersion(versionName);
         if (v.equals(rootVersion)) {
@@ -246,7 +247,7 @@
         // check if any references (from outside the version storage) exist on this version
         List refs = getVersionManager().getItemReferences(v);
         if (!refs.isEmpty()) {
-            throw new VersionException("Unable to remove version. At least once referenced.");
+            throw new ReferentialIntegrityException("Unable to remove version. At least once referenced.");
         }
 
         try {
@@ -275,7 +276,6 @@
 
                 stateMgr.update();
                 succeeded = true;
-                notifyModifed();
             } finally {
                 if (!succeeded) {
                     // update operation failed, cancel all modifications
@@ -292,83 +292,60 @@
     /**
      * {@inheritDoc}
      */
-    public InternalVersion addVersionLabel(QName versionName, QName label, boolean move)
+    public InternalVersion setVersionLabel(QName versionName, QName label, boolean move)
             throws VersionException {
 
-        InternalVersion version = getVersion(versionName);
-        if (version == null) {
+        InternalVersion version = versionName == null ? null : getVersion(versionName);
+        if (versionName !=null && version == null) {
             throw new VersionException("Version " + versionName + " does not exist in this version history.");
         }
-
         InternalVersionImpl prev = (InternalVersionImpl) labelCache.get(label);
-        if (version.equals(prev)) {
-            // ignore
-            return version;
-        } else if (prev != null && !move) {
-            // already defined elsewhere, throw
-            throw new VersionException("Version label " + label + " already defined for version " + prev.getName());
-        } else if (prev != null) {
-            // if already defined, but move, remove old label first
-            removeVersionLabel(label);
+        if (prev == null) {
+            if (version == null) {
+                return null;
+            }
+        } else {
+            if (prev.equals(version)) {
+                return version;
+            } else if (!move) {
+                // already defined elsewhere, throw
+                throw new VersionException("Version label " + label + " already defined for version " + prev.getName());
+            }
         }
-        labelCache.put(label, version);
-        ((InternalVersionImpl) version).internalAddLabel(label);
+
+        // update persistence
         UpdatableItemStateManager stateMgr = getVersionManager().getItemStateMgr();
-        boolean succeeded = false;
         try {
             stateMgr.edit();
-            PersistentNode lNode = labelNode.addNode(label, NT_UNSTRUCTURED, null);
-            lNode.setPropertyValue(NativePVM.PROPNAME_NAME, InternalValue.create(label));
-            lNode.setPropertyValue(NativePVM.PROPNAME_VERSION, InternalValue.create(version.getId()));
-            labelNode.store();
 
+            if (prev != null) {
+                labelNode.removeNode(label);
+            }
+            if (version != null) {
+                PersistentNode lNode = labelNode.addNode(label, NT_UNSTRUCTURED, null);
+                lNode.setPropertyValue(NativePVM.PROPNAME_NAME, InternalValue.create(label));
+                lNode.setPropertyValue(NativePVM.PROPNAME_VERSION, InternalValue.create(version.getId()));
+            }
+            labelNode.store();
             stateMgr.update();
-            succeeded = true;
         } catch (ItemStateException e) {
+            stateMgr.cancel();
             throw new VersionException("Error while storing modifications", e);
         } catch (RepositoryException e) {
+            stateMgr.cancel();
             throw new VersionException("Error while storing modifications", e);
-        } finally {
-            if (!succeeded) {
-                // update operation failed, cancel all modifications
-                stateMgr.cancel();
-            }
         }
-        notifyModifed();
-        return prev;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public InternalVersion removeVersionLabel(QName label) throws VersionException {
-
 
-        InternalVersionImpl v = (InternalVersionImpl) labelCache.remove(label);
-        if (v == null) {
-            throw new VersionException("Version label " + label + " is not in version history.");
-        }
-        v.internalRemoveLabel(label);
-        UpdatableItemStateManager stateMgr = getVersionManager().getItemStateMgr();
-        boolean succeeded = false;
-        try {
-            stateMgr.edit();
-            labelNode.removeNode(label);
-            labelNode.store();
-            stateMgr.update();
-            succeeded = true;
-        } catch (ItemStateException e) {
-            throw new VersionException("Unable to store modifications", e);
-        } catch (RepositoryException e) {
-            throw new VersionException("Unable to store modifications", e);
-        } finally {
-            if (!succeeded) {
-                // update operation failed, cancel all modifications
-                stateMgr.cancel();
-            }
+        // update internal structures
+        if (prev != null) {
+            prev.internalRemoveLabel(label);
+            labelCache.remove(label);
+        }
+        if (version != null) {
+            labelCache.put(label, version);
+            ((InternalVersionImpl) version).internalAddLabel(label);
         }
-        notifyModifed();
-        return v;
+        return prev;
     }
 
     /**
@@ -484,7 +461,7 @@
         pNode.setPropertyValue(NativePVM.PROPNAME_VERSIONABLE_ID, InternalValue.create(src.internalGetUUID()));
 
         // create label node
-        pNode.addNode(NativePVM.NODENAME_VERSION_LABELS, NT_UNSTRUCTURED, null);
+        pNode.addNode(NativePVM.NODENAME_VERSION_LABELS, NativePVM.NT_REP_VERSION_LABELS, null);
 
         // create root version
         String versionId = UUID.randomUUID().toString();

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionItemImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionItemImpl.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionItemImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionItemImpl.java Fri Apr  1 01:23:19 2005
@@ -18,7 +18,8 @@
 
 import org.apache.jackrabbit.core.version.InternalVersionItem;
 import org.apache.jackrabbit.core.version.PersistentVersionManager;
-import org.apache.jackrabbit.core.version.InternalVersionItemListener;
+import org.apache.jackrabbit.core.version.InternalVersionHistory;
+import org.apache.jackrabbit.core.version.InternalVersion;
 
 import java.util.HashSet;
 import java.util.Set;
@@ -35,11 +36,6 @@
     private final PersistentVersionManager vMgr;
 
     /**
-     * the item listeners
-     */
-    private final Set listeners = new HashSet();
-
-    /**
      * Creates a new Internal version item impl
      *
      * @param vMgr
@@ -58,29 +54,11 @@
     }
 
     /**
-     * {@inheritDoc}
-     */
-    public void addListener(InternalVersionItemListener listener) {
-        listeners.add(listener);
-    }
-
-    /**
-     * notifys the listeners that this item was modified
-     */
-    protected void notifyModifed() {
-        Iterator iter = listeners.iterator();
-        while (iter.hasNext()) {
-            ((InternalVersionItemListener) iter.next()).itemModifed(this);
-        }
-    }
-
-    /**
      * Returns the external id of this item
      *
      * @return
      */
     public abstract String getId();
-
 
     /**
      * returns the parent version item or null

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionLabelsImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionLabelsImpl.java?view=auto&rev=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionLabelsImpl.java (added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionLabelsImpl.java Fri Apr  1 01:23:19 2005
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.core.version.persistence;
+
+import org.apache.jackrabbit.core.version.InternalVersionItem;
+import org.apache.jackrabbit.core.version.InternalVersionLabels;
+import org.apache.jackrabbit.core.version.PersistentVersionManager;
+
+/**
+ * This Class represents a version labels
+ */
+public class InternalVersionLabelsImpl extends InternalVersionItemImpl implements InternalVersionLabels {
+
+    private final InternalVersionItem parent;
+
+    private final PersistentNode node;
+
+    protected InternalVersionLabelsImpl(PersistentVersionManager vMgr,
+                                        PersistentNode node,
+                                        InternalVersionItem parent) {
+        super(vMgr);
+        this.node = node;
+        this.parent = parent;
+    }
+
+    public InternalVersionItem getParent() {
+        return parent;
+    }
+
+    public String getId() {
+        return node.getUUID();
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionLabelsImpl.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionLabelsImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java Fri Apr  1 01:23:19 2005
@@ -111,6 +111,11 @@
     protected static final QName NT_REP_VERSION_HISTORY = new QName(NS_REP_URI, "versionHistory");
 
     /**
+     * The nodetype name of a presistent version label
+     */
+    protected static final QName NT_REP_VERSION_LABELS = new QName(NS_REP_URI, "versionLabels");
+
+    /**
      * the nodetype name of a persistent frozen node
      */
     protected static final QName NT_REP_FROZEN = new QName(NS_REP_URI, "frozen");
@@ -261,7 +266,7 @@
         }
 
         versionedUUIDs.put(hist.getVersionableUUID(), hist.getId());
-        
+
         log.info("Created new version history " + hist.getId() + " for " + node.safeGetJCRPath() + ". NumHistories=" + versionedUUIDs.size());
         return hist;
     }
@@ -383,6 +388,8 @@
                     item = ((InternalVersionHistory) parent).getVersion(uuid);
                 } else if (ntName.equals(NT_REP_VERSION_HISTORY)) {
                     item = new InternalVersionHistoryImpl(this, pNode);
+                } else if (ntName.equals(NT_REP_VERSION_LABELS)) {
+                    item = new InternalVersionLabelsImpl(this, pNode, parent);
                 } else {
                     //return null;
                 }
@@ -453,9 +460,6 @@
             InternalVersionImpl v = history.checkin(new QName("", versionName), node);
             stateMgr.update();
             succeeded = true;
-
-            // notify listeners
-            history.notifyModifed();
 
             return v;
         } catch (ItemStateException e) {

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java Fri Apr  1 01:23:19 2005
@@ -42,6 +42,7 @@
 import javax.jcr.RepositoryException;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Iterator;
 
 /**
  * This Class implements a virtual item state provider, in order to expose the
@@ -124,9 +125,6 @@
             } else {
                 s = cache(internalGetNodeState((NodeId) id));
             }
-            if (s instanceof VersionHistoryNodeState) {
-                s.getId();
-            }
             return s;
         } else {
             return internalGetPropertyState((PropertyId) id);
@@ -304,6 +302,36 @@
      */
     protected NodeState evict(NodeId id) {
         return (NodeState) nodes.remove(id);
+    }
+
+    /**
+     * Removes the item and all hard refernces from the cache and discards the
+     * states.
+     * @param id
+     */
+    public void invalidateItem(ItemId id) {
+        if (id.equals(rootNodeId)) {
+            if (root != null) {
+                root.discard();
+                try {
+                    root = createRootNodeState();
+                } catch (RepositoryException e) {
+                    // ignore
+                }
+            }
+            return;
+        }
+        VirtualNodeState state = (VirtualNodeState) nodes.remove(id);
+        if (state != null) {
+            HashSet set = state.removeAllStateReferences();
+            if (set != null) {
+                Iterator iter = set.iterator();
+                while (iter.hasNext()) {
+                    invalidateItem(((NodeState) iter.next()).getId());
+                }
+            }
+            state.discard();
+        }
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java Fri Apr  1 01:23:19 2005
@@ -82,4 +82,6 @@
      * @return <code>true</code> if the reference target is one of its items.
      */
     public boolean setNodeReferences(NodeReferences refs);
+
+
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java?view=diff&r1=159668&r2=159669
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java Fri Apr  1 01:23:19 2005
@@ -256,4 +256,14 @@
             stateRefs.remove(state);
         }
     }
+
+    /**
+     * Returns the hard references of this state
+     */
+    public HashSet removeAllStateReferences() {
+        HashSet set = stateRefs;
+        stateRefs = null;
+        return set;
+    }
+
 }



Mime
View raw message