jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r156034 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: ./ jndi/provider/ state/ version/ virtual/
Date Thu, 03 Mar 2005 12:54:22 GMT
Author: tripod
Date: Thu Mar  3 04:54:18 2005
New Revision: 156034

URL: http://svn.apache.org/viewcvs?view=rev&rev=156034
Log:
- moved virtual nodestate providers down to shared states (part of solving JCR-45)

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/jndi/provider/DummyInitialContextFactory.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.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/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=156033&r2=156034
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java Thu
Mar  3 04:54:18 2005
@@ -250,13 +250,6 @@
 
         ntReg = NodeTypeRegistry.create(nsReg, new BasedFileSystem(repStore, "/nodetypes"));
 
-        // initialize workspaces
-        iter = wspInfos.keySet().iterator();
-        while (iter.hasNext()) {
-            String wspName = (String) iter.next();
-            initWorkspace(wspName);
-        }
-
         // init version manager
         VersioningConfig vConfig = repConfig.getVersioningConfig();
         PersistenceManager pm = createPersistenceManager(vConfig.getHomeDir(),
@@ -266,7 +259,14 @@
                 nsReg,
                 ntReg);
         pvMgr = new NativePVM(pm, getNodeTypeRegistry());
-        vMgr = new VersionManagerImpl(pvMgr, VERSION_STORAGE_NODE_UUID);
+        vMgr = new VersionManagerImpl(pvMgr, ntReg, VERSION_STORAGE_NODE_UUID);
+
+        // initialize workspaces
+        iter = wspInfos.keySet().iterator();
+        while (iter.hasNext()) {
+            String wspName = (String) iter.next();
+            initWorkspace(wspName);
+        }
 
         // finally register shutdown hook
         Runtime.getRuntime().addShutdownHook(new Thread() {
@@ -882,6 +882,11 @@
                 // create item state manager
                 try {
                     itemStateMgr = new SharedItemStateManager(getPersistenceManager(config.getPersistenceManagerConfig()),
rootNodeUUID, ntReg);
+                    try {
+                        itemStateMgr.addVirtualItemStateProvider(vMgr.getVirtualItemStateProvider(itemStateMgr));
+                    } catch (Exception e) {
+                        log.error("Unable to add vmgr: " + e.toString(), e);
+                    }
                 } catch (ItemStateException ise) {
                     String msg = "failed to instantiate persistent item state manager";
                     log.debug(msg);

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=156033&r2=156034
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java Thu Mar
 3 04:54:18 2005
@@ -211,15 +211,6 @@
         itemMgr = createItemManager(itemStateMgr, hierMgr);
         accessMgr = createAccessManager(subject, hierMgr);
         versionMgr = rep.getVersionManager();
-
-        // add virtual item managers (only for non-system sessions)
-        if (!(this instanceof SystemSession)) {
-            try {
-                itemStateMgr.addVirtualItemStateProvider(versionMgr.getVirtualItemStateProvider(this,
itemStateMgr));
-            } catch (Exception e) {
-                log.error("Unable to add vmgr: " + e.toString(), e);
-            }
-        }
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/jndi/provider/DummyInitialContextFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/jndi/provider/DummyInitialContextFactory.java?view=diff&r1=156033&r2=156034
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/jndi/provider/DummyInitialContextFactory.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/jndi/provider/DummyInitialContextFactory.java
Thu Mar  3 04:54:18 2005
@@ -27,6 +27,9 @@
  */
 public class DummyInitialContextFactory implements InitialContextFactory {
 
+    /**
+     * map with all the contexts. key=provider-url, value=context
+     */
     private static HashMap contexts = new HashMap();
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java?view=diff&r1=156033&r2=156034
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
Thu Mar  3 04:54:18 2005
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.core.state;
 
 import org.apache.jackrabbit.core.*;
-import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
 import org.apache.log4j.Logger;
 
 import javax.jcr.InvalidItemStateException;
@@ -44,10 +43,13 @@
     private final UpdatableItemStateManager persistentStateMgr;
 
     /**
-     * Virtual item state providers
+     * State manager for the transient items
      */
-    private VirtualItemStateProvider[] virtualProviders = new VirtualItemStateProvider[0];
     private final TransientItemStateManager transientStateMgr;
+
+    /**
+     * Hierarchy manager
+     */
     private HierarchyManager hierMgr;
 
     /**
@@ -96,18 +98,6 @@
     }
 
     /**
-     * Adds a new virtual item state provider
-     *
-     * @param prov
-     */
-    public synchronized void addVirtualItemStateProvider(VirtualItemStateProvider prov) {
-        VirtualItemStateProvider[] provs = new VirtualItemStateProvider[virtualProviders.length
+ 1];
-        System.arraycopy(virtualProviders, 0, provs, 0, virtualProviders.length);
-        provs[virtualProviders.length] = prov;
-        virtualProviders = provs;
-    }
-
-    /**
      * Dumps the state of this <code>SessionItemStateManager</code> instance
      * (used for diagnostic purposes).
      *
@@ -153,13 +143,6 @@
             return transientStateMgr.getItemState(id);
         }
 
-        // check the virtual root ids (needed for overlay)
-        for (int i = 0; i < virtualProviders.length; i++) {
-            if (virtualProviders[i].isVirtualRoot(id)) {
-                return virtualProviders[i].getItemState(id);
-            }
-        }
-
         // check if there's transient state for the specified item
         if (transientStateMgr.hasItemState(id)) {
             return transientStateMgr.getItemState(id);
@@ -170,13 +153,6 @@
             return persistentStateMgr.getItemState(id);
         }
 
-        // check if there is a virtual state for the specified item
-        for (int i = 0; i < virtualProviders.length; i++) {
-            if (virtualProviders[i].hasItemState(id)) {
-                return virtualProviders[i].getItemState(id);
-            }
-        }
-
         throw new NoSuchItemStateException(id.toString());
     }
 
@@ -193,32 +169,12 @@
              */
             return transientStateMgr.hasItemState(id);
         }
-
-        // check the virtual root ids (needed for overlay)
-        for (int i = 0; i < virtualProviders.length; i++) {
-            if (virtualProviders[i].isVirtualRoot(id)) {
-                return true;
-            }
-        }
-
         // check if there's transient state for the specified item
         if (transientStateMgr.hasItemState(id)) {
             return true;
         }
-
         // check if there's persistent state for the specified item
-        if (persistentStateMgr.hasItemState(id)) {
-            return true;
-        }
-
-        // check if there is a virtual state for the specified item
-        for (int i = 0; i < virtualProviders.length; i++) {
-            if (virtualProviders[i].hasItemState(id)) {
-                return true;
-            }
-        }
-
-        return false;
+        return persistentStateMgr.hasItemState(id);
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?view=diff&r1=156033&r2=156034
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Thu Mar  3 04:54:18 2005
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.state;
 
 import org.apache.jackrabbit.core.*;
+import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
 import org.apache.jackrabbit.core.observation.ObservationManagerImpl;
 import org.apache.jackrabbit.core.observation.EventStateCollection;
 import org.apache.jackrabbit.core.nodetype.NodeDefId;
@@ -53,6 +54,11 @@
     private NodeState root;
 
     /**
+     * Virtual item state providers
+     */
+    private VirtualItemStateProvider[] virtualProviders = new VirtualItemStateProvider[0];
+
+    /**
      * Creates a new <code>SharedItemStateManager</code> instance.
      *
      * @param persistMgr
@@ -82,6 +88,18 @@
         evictAll();
     }
 
+    /**
+     * Adds a new virtual item state provider
+     *
+     * @param prov
+     */
+    public synchronized void addVirtualItemStateProvider(VirtualItemStateProvider prov) {
+        VirtualItemStateProvider[] provs = new VirtualItemStateProvider[virtualProviders.length
+ 1];
+        System.arraycopy(virtualProviders, 0, provs, 0, virtualProviders.length);
+        provs[virtualProviders.length] = prov;
+        virtualProviders = provs;
+    }
+
     private NodeState createRootNodeState(String rootNodeUUID,
                                           NodeTypeRegistry ntReg)
             throws ItemStateException {
@@ -141,7 +159,7 @@
      * @throws NoSuchItemStateException
      * @throws ItemStateException
      */
-    protected NodeState getNodeState(NodeId id)
+    private NodeState getNodeState(NodeId id)
             throws NoSuchItemStateException, ItemStateException {
 
         // check cache
@@ -167,7 +185,7 @@
      * @throws NoSuchItemStateException
      * @throws ItemStateException
      */
-    protected PropertyState getPropertyState(PropertyId id)
+    private PropertyState getPropertyState(PropertyId id)
             throws NoSuchItemStateException, ItemStateException {
 
         // check cache
@@ -194,7 +212,31 @@
      */
     public synchronized ItemState getItemState(ItemId id)
             throws NoSuchItemStateException, ItemStateException {
+        // check the virtual root ids (needed for overlay)
+        for (int i = 0; i < virtualProviders.length; i++) {
+            if (virtualProviders[i].isVirtualRoot(id)) {
+                return virtualProviders[i].getItemState(id);
+            }
+        }
+        // check internal first
+        if (hasNonVirtualItemState(id)) {
+            return getNonVirtualItemState(id);
+        }
+        // check if there is a virtual state for the specified item
+        for (int i = 0; i < virtualProviders.length; i++) {
+            if (virtualProviders[i].hasItemState(id)) {
+                return virtualProviders[i].getItemState(id);
+            }
+        }
+        throw new NoSuchItemStateException(id.toString());
+    }
 
+    /**
+     * returns the item state for the given id without considering virtual
+     * item state providers.
+     */
+    private ItemState getNonVirtualItemState(ItemId id)
+            throws NoSuchItemStateException, ItemStateException {
         if (id.denotesNode()) {
             return getNodeState((NodeId) id);
         } else {
@@ -209,6 +251,33 @@
         if (isCached(id)) {
             return true;
         }
+        // check the virtual root ids (needed for overlay)
+        for (int i = 0; i < virtualProviders.length; i++) {
+            if (virtualProviders[i].isVirtualRoot(id)) {
+                return true;
+            }
+        }
+        // check if this manager has the item state
+        if (hasNonVirtualItemState(id)) {
+            return true;
+        }
+        // otherwise check virtual ones
+        for (int i = 0; i < virtualProviders.length; i++) {
+            if (virtualProviders[i].hasItemState(id)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Checks if this itemstate manager has the given item state without
+     * considering the virtual item state managers.
+     */
+    private boolean hasNonVirtualItemState(ItemId id) {
+        if (isCached(id)) {
+            return true;
+        }
 
         try {
             if (id.denotesNode()) {
@@ -227,15 +296,24 @@
     public synchronized NodeReferences getNodeReferences(NodeReferencesId id)
             throws NoSuchItemStateException, ItemStateException {
 
-        NodeReferences refs;
+        // todo: add caching
 
+        // check persistence manager
         try {
-            refs = persistMgr.load(id);
-        } catch (NoSuchItemStateException nsise) {
-            refs = new NodeReferences(id);
+            return persistMgr.load(id);
+        } catch (NoSuchItemStateException e) {
+            // ignore
         }
-
-        return refs;
+        // check virtual providers
+        for (int i = 0; i < virtualProviders.length; i++) {
+            try {
+                return virtualProviders[i].getNodeReferences(id);
+            } catch (NoSuchItemStateException e) {
+                // ignore
+            }
+        }
+        // create new one
+        return new NodeReferences(id);
     }
 
     //-------------------------------------------------------- other operations

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=156033&r2=156034
==============================================================================
--- 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
Thu Mar  3 04:54:18 2005
@@ -43,7 +43,7 @@
     /**
      * the root node
      */
-    private final HistoryRootNodeState root;
+    private HistoryRootNodeState root;
     /**
      * the version manager
      */
@@ -51,7 +51,8 @@
     /**
      * the node type manager
      */
-    private final NodeTypeManagerImpl ntMgr;
+    private final NodeTypeRegistry ntReg;
+
     /**
      * the cache node states. key=ItemId, value=ItemState
      */
@@ -74,6 +75,12 @@
      */
     private NodeDefId NDEF_VERSION_LABELS;
 
+    /** the parent id */
+    private final String parentId;
+
+    /** the root node id */
+    private final String rootNodeId;
+
     /**
      * creates a new version item state provide
      *
@@ -82,16 +89,26 @@
      * @param parentId
      * @throws RepositoryException
      */
-    public VersionItemStateProvider(VersionManager vMgr, NodeTypeManagerImpl ntMgr, String
rootId, String parentId) throws RepositoryException {
+    public VersionItemStateProvider(VersionManager vMgr, NodeTypeRegistry ntReg, String rootId,
String parentId) throws RepositoryException {
         this.vMgr = vMgr;
-        this.ntMgr = ntMgr;
-        NDEF_VERSION = new NodeDefId(getNodeTypeManager().getNodeType(NT_VERSIONHISTORY).getApplicableChildNodeDef(JCR_ROOTVERSION,
NT_VERSION).unwrap());
-        NDEF_VERSION_HISTORY = new NodeDefId(getNodeTypeManager().getNodeType(NT_UNSTRUCTURED).getApplicableChildNodeDef(JCR_ROOTVERSION,
NT_VERSIONHISTORY).unwrap());
-        NDEF_VERSION_HISTORY_ROOT = new NodeDefId(getNodeTypeManager().getNodeType(REP_SYSTEM).getApplicableChildNodeDef(JCR_VERSIONSTORAGE,
REP_VERSIONSTORAGE).unwrap());
-        NDEF_VERSION_LABELS = new NodeDefId(getNodeTypeManager().getNodeType(NT_VERSIONHISTORY).getApplicableChildNodeDef(JCR_VERSIONLABELS,
NT_VERSIONLABELS).unwrap());
+        this.ntReg = ntReg;
+        this.rootNodeId = rootId;
+        this.parentId = parentId;
+        NDEF_VERSION = new NodeDefId(ntReg.getEffectiveNodeType(NT_VERSIONHISTORY).getApplicableChildNodeDef(JCR_ROOTVERSION,
NT_VERSION));
+        NDEF_VERSION_HISTORY = new NodeDefId(ntReg.getEffectiveNodeType(NT_UNSTRUCTURED).getApplicableChildNodeDef(JCR_ROOTVERSION,
NT_VERSIONHISTORY));
+        NDEF_VERSION_HISTORY_ROOT = new NodeDefId(ntReg.getEffectiveNodeType(REP_SYSTEM).getApplicableChildNodeDef(JCR_VERSIONSTORAGE,
REP_VERSIONSTORAGE));
+        NDEF_VERSION_LABELS = new NodeDefId(ntReg.getEffectiveNodeType(NT_VERSIONHISTORY).getApplicableChildNodeDef(JCR_VERSIONLABELS,
NT_VERSIONLABELS));
 
-        this.root = new HistoryRootNodeState(this, vMgr, parentId, rootId);
-        this.root.setDefinitionId(NDEF_VERSION_HISTORY_ROOT);
+        createRootNodeState();
+    }
+
+    /**
+     * Creates a new root node state
+     * @throws RepositoryException
+     */
+    private void createRootNodeState() throws RepositoryException {
+        root = new HistoryRootNodeState(this, vMgr, parentId, rootNodeId);
+        root.setDefinitionId(NDEF_VERSION_HISTORY_ROOT);
     }
 
     //-----------------------------------------------------< ItemStateManager >
@@ -275,11 +292,11 @@
                                                     QName name, int type,
                                                     boolean multiValued)
             throws RepositoryException {
-        PropertyDefImpl def = getApplicablePropertyDef(parent, name, type, multiValued);
+        PropDef def = getApplicablePropertyDef(parent, name, type, multiValued);
         VirtualPropertyState prop = new VirtualPropertyState(name, parent.getUUID());
         prop.setType(type);
         prop.setMultiValued(multiValued);
-        prop.setDefinitionId(new PropDefId(def.unwrap()));
+        prop.setDefinitionId(new PropDefId(def));
         return prop;
     }
 
@@ -290,20 +307,16 @@
                                             String uuid, QName nodeTypeName)
             throws RepositoryException {
 
-        NodeTypeImpl nodeType = getNodeTypeManager().getNodeType(nodeTypeName);
-        NodeDefImpl def;
+        NodeDefId def;
         try {
-            def = getApplicableChildNodeDef(parent, name, nodeType == null ? null : nodeType.getQName());
+            def = new NodeDefId(getApplicableChildNodeDef(parent, name, nodeTypeName));
         } catch (RepositoryException re) {
             // hack, use nt:unstructured as parent
-            NodeTypeRegistry ntReg = getNodeTypeManager().getNodeTypeRegistry();
+            NodeTypeRegistry ntReg = getNodeTypeRegistry();
             EffectiveNodeType ent = ntReg.getEffectiveNodeType(NT_UNSTRUCTURED);
             ChildNodeDef cnd = ent.getApplicableChildNodeDef(name, nodeTypeName);
-            def = getNodeTypeManager().getNodeDef(new NodeDefId(cnd));
-        }
-        if (nodeType == null) {
-            // use default node type
-            nodeType = (NodeTypeImpl) def.getDefaultPrimaryType();
+            ntReg.getNodeDef(new NodeDefId(cnd));
+            def = new NodeDefId(cnd);
         }
 
         // create a new node state
@@ -312,7 +325,7 @@
             uuid = UUID.randomUUID().toString();	// version 4 uuid
         }
         state = new VirtualNodeState(this, parent.getUUID(), uuid, nodeTypeName, new QName[0]);
-        state.setDefinitionId(new NodeDefId(def.unwrap()));
+        state.setDefinitionId(def);
 
         nodes.put(state.getId(), state);
         return state;
@@ -325,8 +338,8 @@
      *
      * @return
      */
-    private NodeTypeManagerImpl getNodeTypeManager() {
-        return ntMgr;
+    private NodeTypeRegistry getNodeTypeRegistry() {
+        return ntReg;
     }
 
     /**
@@ -382,11 +395,10 @@
      * @return
      * @throws RepositoryException
      */
-    protected PropertyDefImpl getApplicablePropertyDef(NodeState parent, QName propertyName,
-                                                       int type, boolean multiValued)
+    protected PropDef getApplicablePropertyDef(NodeState parent, QName propertyName,
+                                               int type, boolean multiValued)
             throws RepositoryException {
-        PropDef pd = getEffectiveNodeType(parent).getApplicablePropertyDef(propertyName,
type, multiValued);
-        return getNodeTypeManager().getPropDef(new PropDefId(pd));
+        return getEffectiveNodeType(parent).getApplicablePropertyDef(propertyName, type,
multiValued);
     }
 
     /**
@@ -397,10 +409,9 @@
      * @return
      * @throws RepositoryException
      */
-    protected NodeDefImpl getApplicableChildNodeDef(NodeState parent, QName nodeName, QName
nodeTypeName)
+    protected ChildNodeDef getApplicableChildNodeDef(NodeState parent, QName nodeName, QName
nodeTypeName)
             throws RepositoryException {
-        ChildNodeDef cnd = getEffectiveNodeType(parent).getApplicableChildNodeDef(nodeName,
nodeTypeName);
-        return getNodeTypeManager().getNodeDef(new NodeDefId(cnd));
+        return getEffectiveNodeType(parent).getApplicableChildNodeDef(nodeName, nodeTypeName);
     }
 
     /**
@@ -412,7 +423,7 @@
      */
     protected EffectiveNodeType getEffectiveNodeType(NodeState parent) throws RepositoryException
{
         // build effective node type of mixins & primary type
-        NodeTypeRegistry ntReg = getNodeTypeManager().getNodeTypeRegistry();
+        NodeTypeRegistry ntReg = getNodeTypeRegistry();
         // existing mixin's
         HashSet set = new HashSet(parent.getMixinTypeNames());
         // primary type
@@ -423,5 +434,47 @@
             String msg = "internal error: failed to build effective node type for node "
+ parent.getUUID();
             throw new RepositoryException(msg, ntce);
         }
+    }
+
+    /**
+     * @see ItemStateListener#stateCreated
+     */
+    public void stateCreated(ItemState created) {
+    }
+
+    /**
+     * @see ItemStateListener#stateModified
+     */
+    public void stateModified(ItemState modified) {
+    }
+
+    /**
+     * @see ItemStateListener#stateDestroyed
+     */
+    public void stateDestroyed(ItemState destroyed) {
+        destroyed.removeListener(this);
+        if (destroyed.isNode() && ((NodeState) destroyed).getUUID().equals(rootNodeId))
{
+            try {
+                createRootNodeState();
+            } catch (RepositoryException e) {
+                // ignore
+            }
+        }
+        nodes.remove(destroyed.getId());
+    }
+
+    /**
+     * @see ItemStateListener#stateDiscarded
+     */
+    public void stateDiscarded(ItemState discarded) {
+        discarded.removeListener(this);
+        if (discarded.isNode() && ((NodeState) discarded).getUUID().equals(rootNodeId))
{
+            try {
+                createRootNodeState();
+            } catch (RepositoryException e) {
+                // ignore
+            }
+        }
+        nodes.remove(discarded.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=156033&r2=156034
==============================================================================
--- 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
Thu Mar  3 04:54:18 2005
@@ -38,8 +38,7 @@
      * @param base
      * @return
      */
-    public VirtualItemStateProvider getVirtualItemStateProvider(SessionImpl session,
-                                                                ItemStateManager base);
+    public VirtualItemStateProvider getVirtualItemStateProvider(ItemStateManager base);
 
     /**
      * Creates a new version history. This action is needed either when creating

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=156033&r2=156034
==============================================================================
--- 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
Thu Mar  3 04:54:18 2005
@@ -17,9 +17,10 @@
 package org.apache.jackrabbit.core.version;
 
 import org.apache.jackrabbit.core.*;
-import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
 import org.apache.log4j.Logger;
 
@@ -56,7 +57,7 @@
     /**
      * the node type manager
      */
-    private NodeTypeManagerImpl ntMgr;
+    private NodeTypeRegistry ntReg;
 
 
     /**
@@ -64,8 +65,9 @@
      *
      * @param vMgr
      */
-    public VersionManagerImpl(PersistentVersionManager vMgr, String rootUUID) {
+    public VersionManagerImpl(PersistentVersionManager vMgr, NodeTypeRegistry ntReg, String
rootUUID) {
         this.vMgr = vMgr;
+        this.ntReg = ntReg;
         this.VERSION_STORAGE_NODE_UUID = rootUUID;
     }
 
@@ -76,13 +78,12 @@
      * @param base
      * @return
      */
-    public synchronized VirtualItemStateProvider getVirtualItemStateProvider(SessionImpl
session, ItemStateManager base) {
+    public synchronized VirtualItemStateProvider getVirtualItemStateProvider(ItemStateManager
base) {
         if (virtProvider == null) {
             try {
                 // init the definition id mgr
-                ntMgr = session.getNodeTypeManager();
                 NodeState virtRootState = (NodeState) base.getItemState(new NodeId(VERSION_STORAGE_NODE_UUID));
-                virtProvider = new VersionItemStateProvider(this, ntMgr, VERSION_STORAGE_NODE_UUID,
virtRootState.getParentUUID());
+                virtProvider = new VersionItemStateProvider(this, ntReg, VERSION_STORAGE_NODE_UUID,
virtRootState.getParentUUID());
             } catch (Exception e) {
                 // todo: better error handling
                 log.error("Error while initializing virtual items.", e);
@@ -102,15 +103,6 @@
     }
 
     /**
-     * returns the node type manager
-     *
-     * @return
-     */
-    NodeTypeManagerImpl getNodeTypeManager() {
-        return ntMgr;
-    }
-
-    /**
      * Creates a new version history. This action is needed either when creating
      * a new 'mix:versionable' node or when adding the 'mix:versionalbe' mixin
      * to a node.
@@ -121,6 +113,11 @@
      */
     public VersionHistory createVersionHistory(NodeImpl node) throws RepositoryException
{
         InternalVersionHistory history = vMgr.createVersionHistory(node);
+        try {
+            virtProvider.getItemState(new NodeId(VERSION_STORAGE_NODE_UUID)).discard();
+        } catch (ItemStateException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
         return (VersionHistory) node.getSession().getNodeByUUID(history.getId());
     }
 
@@ -217,6 +214,11 @@
      */
     public Version checkin(NodeImpl node) throws RepositoryException {
         InternalVersion version = vMgr.checkin(node);
+        try {
+            virtProvider.getItemState(new NodeId(version.getVersionHistory().getId())).discard();
+        } catch (ItemStateException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
         return (Version) node.getSession().getNodeByUUID(version.getId());
     }
 

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=156033&r2=156034
==============================================================================
--- 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
Thu Mar  3 04:54:18 2005
@@ -23,13 +23,14 @@
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.core.state.ItemStateListener;
 
 import javax.jcr.RepositoryException;
 
 /**
  * This Interface defines a virtual item state provider.
  */
-public interface VirtualItemStateProvider extends ItemStateManager {
+public interface VirtualItemStateProvider extends ItemStateManager, ItemStateListener {
 
     /**
      * Checks if the id refers to the root of a virtual tree.

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=156033&r2=156034
==============================================================================
--- 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
Thu Mar  3 04:54:18 2005
@@ -62,7 +62,7 @@
             throws RepositoryException {
         super(uuid, nodeTypeName, parentUUID, ItemState.STATUS_EXISTING, false);
         this.stateMgr = stateMgr;
-
+        addListener(stateMgr);
         // add default properties
         setPropertyValue(JCR_PRIMARYTYPE, InternalValue.create(nodeTypeName));
         setMixinNodeTypes(mixins);



Mime
View raw message