jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r795866 [2/2] - in /jackrabbit/trunk: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/
Date Mon, 20 Jul 2009 14:59:22 GMT
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java?rev=795866&r1=795865&r2=795866&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java Mon Jul 20 14:59:21 2009
@@ -16,30 +16,29 @@
  */
 package org.apache.jackrabbit.core.version;
 
-import org.apache.jackrabbit.core.NodeImpl;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.PropertyType;
+import javax.jcr.ReferentialIntegrityException;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.VersionException;
+
 import org.apache.jackrabbit.core.id.NodeId;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
-import org.apache.jackrabbit.core.state.ChildNodeEntry;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.PropertyType;
-import javax.jcr.ReferentialIntegrityException;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.version.VersionException;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
 /**
  * Implements a <code>InternalVersionHistory</code>
  */
@@ -400,7 +399,7 @@
             // Check if there is only root version and version labels nodes
             if (childNodes.length == 2) {
                 log.debug("Removing orphan version history as it contains only two children");
-                NodeStateEx parentNode = vMgr.getNodeStateEx(node.getParentId());
+                NodeStateEx parentNode = node.getParent();
                 // Remove version history node
                 parentNode.removeNode(node.getName());
                 // store changes for this node and his children
@@ -489,22 +488,21 @@
      * @return the newly created version
      * @throws RepositoryException if an error occurs
      */
-    InternalVersionImpl checkin(Name name, NodeImpl src)
+    InternalVersionImpl checkin(Name name, NodeStateEx src)
             throws RepositoryException {
 
         // copy predecessors from src node
         InternalValue[] predecessors;
         if (src.hasProperty(NameConstants.JCR_PREDECESSORS)) {
-            Value[] preds = src.getProperty(NameConstants.JCR_PREDECESSORS).getValues();
-            predecessors = new InternalValue[preds.length];
-            for (int i = 0; i < preds.length; i++) {
-                NodeId predId = new NodeId(preds[i].getString());
+            predecessors = src.getPropertyValues(NameConstants.JCR_PREDECESSORS);
+            // check all predecessors
+            for (InternalValue pred: predecessors) {
+                NodeId predId = pred.getNodeId();
                 // check if version exist
                 if (!nameCache.containsValue(predId)) {
                     throw new RepositoryException(
                             "Invalid predecessor in source node: " + predId);
                 }
-                predecessors[i] = InternalValue.create(predId);
             }
         } else {
             // with simple versioning, the node does not contain a predecessors
@@ -526,7 +524,7 @@
 
         // check for jcr:activity
         if (src.hasProperty(NameConstants.JCR_ACTIVITY)) {
-            InternalValue act = src.getProperty(NameConstants.JCR_ACTIVITY).internalGetValue();
+            InternalValue act = src.getPropertyValue(NameConstants.JCR_ACTIVITY);
             vNode.setPropertyValue(NameConstants.JCR_ACTIVITY, act);
         }
 
@@ -608,7 +606,7 @@
             InternalValue[] ivalues = new InternalValue[mixins.size()];
             Iterator<Name> iter = mixins.iterator();
             for (int i = 0; i < mixins.size(); i++) {
-                ivalues[i] = InternalValue.create((Name) iter.next());
+                ivalues[i] = InternalValue.create(iter.next());
             }
             node.setPropertyValues(NameConstants.JCR_FROZENMIXINTYPES, PropertyType.NAME, ivalues);
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java?rev=795866&r1=795865&r2=795866&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java Mon Jul 20 14:59:21 2009
@@ -17,9 +17,8 @@
 package org.apache.jackrabbit.core.version;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.version.Version;
-import javax.jcr.version.VersionException;
-import javax.jcr.version.VersionHistory;
+
+import org.apache.jackrabbit.spi.Name;
 
 /**
  * This Class implements a version selector that selects a version by label.
@@ -38,15 +37,15 @@
     /**
      * a versionlabel hint
      */
-    private String label = null;
+    private Name label = null;
 
     /**
      * Creates a <code>LabelVersionSelector</code> that will try to select a
      * version with the given label.
      *
-     * @param label
+     * @param label label hint
      */
-    public LabelVersionSelector(String label) {
+    public LabelVersionSelector(Name label) {
         this.label = label;
     }
 
@@ -55,28 +54,26 @@
      *
      * @return the label hint.
      */
-    public String getLabel() {
+    public Name getLabel() {
         return label;
     }
 
     /**
      * Sets the label hint
      *
-     * @param label
+     * @param label label hint
      */
-    public void setLabel(String label) {
+    public void setLabel(Name label) {
         this.label = label;
     }
 
     /**
+     * {@inheritDoc}
+     *
      * Selects a version from the given version history using the previously
      * assigned hint in the following order: name, label, date, latest.
-     *
-     * @param versionHistory
-     * @return
-     * @throws RepositoryException
      */
-    public Version select(VersionHistory versionHistory)
+    public InternalVersion select(InternalVersionHistory versionHistory)
             throws RepositoryException {
         return selectByLabel(versionHistory, label);
     }
@@ -84,18 +81,14 @@
     /**
      * Selects a version by label
      *
-     * @param history
-     * @param label
+     * @param history history to select from
+     * @param label desired label
      * @return the version with the given label or <code>null</code>
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs
      */
-    public static Version selectByLabel(VersionHistory history, String label)
+    public static InternalVersion selectByLabel(InternalVersionHistory history, Name label)
             throws RepositoryException {
-        try {
-            return history.getVersionByLabel(label);
-        } catch (VersionException e) {
-            return null;
-        }
+        return history.getVersionByLabel(label);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java?rev=795866&r1=795865&r2=795866&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java Mon Jul 20 14:59:21 2009
@@ -16,32 +16,34 @@
  */
 package org.apache.jackrabbit.core.version;
 
+import java.util.List;
+import java.util.Set;
+
+import javax.jcr.ItemExistsException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+
+import org.apache.jackrabbit.core.PropertyImpl;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.id.PropertyId;
-import org.apache.jackrabbit.core.PropertyImpl;
 import org.apache.jackrabbit.core.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.core.nodetype.NodeDef;
 import org.apache.jackrabbit.core.nodetype.NodeTypeConflictException;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.nodetype.PropDef;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
 import org.apache.jackrabbit.core.state.ItemState;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.state.UpdatableItemStateManager;
-import org.apache.jackrabbit.core.state.ChildNodeEntry;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 
-import java.util.List;
-import java.util.Set;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.PropertyType;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-
 /**
  * This Class provides some basic node operations directly on the node state.
  */
@@ -70,8 +72,10 @@
     /**
      * Creates a new persistent node
      *
-     * @param stateMgr
-     * @param nodeState
+     * @param stateMgr state manager
+     * @param ntReg node type registry
+     * @param nodeState underlying node state
+     * @param name name (can be null)
      */
     public NodeStateEx(UpdatableItemStateManager stateMgr,
                        NodeTypeRegistry ntReg,
@@ -82,6 +86,26 @@
         this.name = name;
     }
 
+    /**
+     * Creates a new persistent node
+     *
+     * @param stateMgr state manager
+     * @param ntReg node type registry
+     * @param nodeId node id
+     * @throws RepositoryException if the node state can't be loaded
+     */
+    public NodeStateEx(UpdatableItemStateManager stateMgr,
+                       NodeTypeRegistry ntReg,
+                       NodeId nodeId) throws RepositoryException {
+        try {
+            this.ntReg = ntReg;
+            this.stateMgr = stateMgr;
+            this.nodeState = (NodeState) stateMgr.getItemState(nodeId);
+        } catch (ItemStateException e) {
+            throw new RepositoryException(e);
+        }
+    }
+
 
     /**
      * returns the name of this node
@@ -95,7 +119,7 @@
                 NodeState parent = (NodeState) stateMgr.getItemState(parentId);
                 name = parent.getChildNodeEntry(nodeState.getNodeId()).getName();
             } catch (ItemStateException e) {
-                // should never occurr
+                // should never occur
                 throw new IllegalStateException(e.toString());
             }
         }
@@ -121,6 +145,19 @@
     }
 
     /**
+     * Returns the parent node of this node
+     *
+     * @return the parent node of this node or <code>null</code> if root node
+     * @throws RepositoryException if an error occurs
+     */
+    public NodeStateEx getParent() throws RepositoryException {
+        if (nodeState.getParentId() == null) {
+            return null;
+        }
+        return getNode(nodeState.getParentId());
+    }
+
+    /**
      * Returns the underlaying node state.
      * @return the underlaying node state.
      */
@@ -132,6 +169,7 @@
      * Returns the properties of this node
      *
      * @return the properties of this node
+     * @throws ItemStateException if an error occurs
      */
     public PropertyState[] getProperties() throws ItemStateException {
         Set<Name> set = nodeState.getPropertyNames();
@@ -147,7 +185,7 @@
     /**
      * Checks if the given property exists
      *
-     * @param name
+     * @param name name of the property
      * @return <code>true</code> if the given property exists.
      */
     public boolean hasProperty(Name name) {
@@ -158,7 +196,7 @@
     /**
      * Returns the values of the given property of <code>null</code>
      *
-     * @param name
+     * @param name name of the property
      * @return the values of the given property.
      */
     public InternalValue[] getPropertyValues(Name name) {
@@ -174,7 +212,7 @@
     /**
      * Returns the value of the given property or <code>null</code>
      *
-     * @param name
+     * @param name name of the property
      * @return the value of the given property.
      */
     public InternalValue getPropertyValue(Name name) {
@@ -190,9 +228,9 @@
     /**
      * Sets the property value
      *
-     * @param name
-     * @param value
-     * @throws RepositoryException
+     * @param name name of the property
+     * @param value value to set
+     * @throws RepositoryException if an error occurs
      */
     public void setPropertyValue(Name name, InternalValue value)
             throws RepositoryException {
@@ -202,10 +240,10 @@
     /**
      * Sets the property values
      *
-     * @param name
-     * @param type
-     * @param values
-     * @throws RepositoryException
+     * @param name name of the property
+     * @param type property type
+     * @param values values to set
+     * @throws RepositoryException if an error occurs
      */
     public void setPropertyValues(Name name, int type, InternalValue[] values)
             throws RepositoryException {
@@ -215,56 +253,43 @@
     /**
      * Sets the property values
      *
-     * @param name
-     * @param type
-     * @param values
-     * @throws RepositoryException
-     */
-    public void setPropertyValues(Name name, int type, InternalValue[] values, boolean multiple)
-            throws RepositoryException {
-
-        PropertyState prop = getOrCreatePropertyState(name, type, multiple);
-        prop.setValues(values);
-    }
-
-
-    /**
-     * Retrieves or creates a new property state as child property of this node
-     *
-     * @param name
-     * @param type
-     * @param multiValued
-     * @return the property state
-     * @throws RepositoryException
+     * @param name name of the property
+     * @param type type of the values
+     * @param values values to set
+     * @param multiple <code>true</code>for MV properties
+     * @return the modified property state
+     * @throws RepositoryException if an error occurs
      */
-    private PropertyState getOrCreatePropertyState(Name name, int type, boolean multiValued)
+    public PropertyState setPropertyValues(Name name, int type, InternalValue[] values, boolean multiple)
             throws RepositoryException {
-
         PropertyId propId = new PropertyId(nodeState.getNodeId(), name);
         if (stateMgr.hasItemState(propId)) {
             try {
                 PropertyState propState = (PropertyState) stateMgr.getItemState(propId);
-                // someone calling this method will always alter the property state, so set status to modified
                 if (propState.getStatus() == ItemState.STATUS_EXISTING) {
                     propState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
                 }
-                // although this is not quite correct, we mark node as modified aswell
+                // although this is not quite correct, we mark node as modified as well
                 if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
                     nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
                 }
+                propState.setType(type);
+                propState.setValues(values);
                 return propState;
             } catch (ItemStateException e) {
                 throw new RepositoryException("Unable to create property: " + e.toString());
             }
         } else {
+
+            PropDef pd = getEffectiveNodeType().getApplicablePropertyDef(name, type, multiple);
+
             PropertyState propState = stateMgr.createNew(name, nodeState.getNodeId());
             propState.setType(type);
-            propState.setMultiValued(multiValued);
-
-            PropDef pd = getEffectiveNodeType().getApplicablePropertyDef(name, type, multiValued);
+            propState.setMultiValued(multiple);
             propState.setDefinitionId(pd.getId());
+            propState.setValues(values);
 
-            // need to store nodestate
+            // need to store node state
             nodeState.addPropertyName(name);
             if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
                 nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
@@ -278,7 +303,7 @@
      * of this node's primary and mixin node types.
      *
      * @return the effective node type
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs
      */
     public EffectiveNodeType getEffectiveNodeType() throws RepositoryException {
         try {
@@ -293,7 +318,7 @@
     /**
      * checks if the given child node exists.
      *
-     * @param name
+     * @param name name of the node
      * @return <code>true</code> if the given child exists.
      */
     public boolean hasNode(Name name) {
@@ -303,30 +328,53 @@
     /**
      * removes the (first) child node with the given name.
      *
-     * @param name
+     * @param name name of hte node
      * @return <code>true</code> if the child was removed
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs
      */
     public boolean removeNode(Name name) throws RepositoryException {
         return removeNode(name, 1);
     }
 
     /**
+     * removes the given child node
+     *
+     * @param node child node to remove
+     * @return <code>true</code> if the child was removed
+     * @throws RepositoryException if an error occurs
+     */
+    public boolean removeNode(NodeStateEx node) throws RepositoryException {
+        // locate child node entry
+        return removeNode(nodeState.getChildNodeEntry(node.getNodeId()));
+    }
+
+
+    /**
      * removes the child node with the given name and 1-based index
      *
-     * @param name
-     * @param index
+     * @param name name of the child node
+     * @param index index of the child node
      * @return <code>true</code> if the child was removed.
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs
      */
     public boolean removeNode(Name name, int index) throws RepositoryException {
+        return removeNode(nodeState.getChildNodeEntry(name, index));
+    }
+
+    /**
+     * removes the child node with the given child node entry
+     *
+     * @param entry entry to remove
+     * @return <code>true</code> if the child was removed.
+     * @throws RepositoryException if an error occurs
+     */
+    public boolean removeNode(ChildNodeEntry entry) throws RepositoryException {
         try {
-            ChildNodeEntry entry = nodeState.getChildNodeEntry(name, index);
             if (entry == null) {
                 return false;
             } else {
                 removeNode(entry.getId());
-                nodeState.removeChildNodeEntry(name, index);
+                nodeState.removeChildNodeEntry(entry.getId());
                 nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
                 return true;
             }
@@ -338,8 +386,8 @@
     /**
      * removes recursively the node with the given id
      *
-     * @param id
-     * @throws ItemStateException
+     * @param id node id
+     * @throws ItemStateException if an error occurs
      */
     private void removeNode(NodeId id) throws ItemStateException {
         NodeState state = (NodeState) stateMgr.getItemState(id);
@@ -365,9 +413,9 @@
     /**
      * removes the property with the given name
      *
-     * @param name
+     * @param name name of the property
      * @return <code>true</code> if the property was removed.
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs
      */
     public boolean removeProperty(Name name) throws RepositoryException {
         try {
@@ -390,10 +438,10 @@
      * retrieves the child node with the given name and 1-base index or
      * <code>null</code> if the node does not exist.
      *
-     * @param name
-     * @param index
+     * @param name name of hte child node
+     * @param index index of thechild node
      * @return the node state.
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs
      */
     public NodeStateEx getNode(Name name, int index) throws RepositoryException {
         ChildNodeEntry entry = nodeState.getChildNodeEntry(name, index);
@@ -409,14 +457,57 @@
     }
 
     /**
+     * Returns the node with the given id.
+     * @param id node id
+     * @return the new node state
+     * @throws RepositoryException if an error occurs
+     */
+    public NodeStateEx getNode(NodeId id) throws RepositoryException {
+        try {
+            NodeState state = (NodeState) stateMgr.getItemState(id);
+            return new NodeStateEx(stateMgr, ntReg, state, name);
+        } catch (ItemStateException e) {
+            throw new RepositoryException("Unable to getNode: " + e.toString());
+        }
+    }
+
+    /**
+     * Checks if the given node state exists
+     * @param id node id
+     * @return <code>true</code> if the node state exists
+     */
+    public boolean hasNode(NodeId id) {
+        return stateMgr.hasItemState(id);
+    }
+
+    /**
      * Adds a new child node with the given name
      *
-     * @param nodeName
-     * @param nodeTypeName
+     * @param nodeName name of the new node
+     * @param nodeTypeName node type name
+     * @param id id of the new node
      * @return the node state
-     * @throws NoSuchNodeTypeException
-     * @throws ConstraintViolationException
-     * @throws RepositoryException
+     * @throws NoSuchNodeTypeException if the node type does not exist
+     * @throws ConstraintViolationException if there is a constraint violation
+     * @throws RepositoryException if an error occurs
+     */
+    public NodeStateEx addNode(Name nodeName, Name nodeTypeName, NodeId id)
+            throws NoSuchNodeTypeException, ConstraintViolationException, RepositoryException {
+        return addNode(nodeName, nodeTypeName, id,
+                ntReg.getEffectiveNodeType(nodeTypeName).includesNodeType(NameConstants.MIX_REFERENCEABLE));
+    }
+
+    /**
+     * Adds a new child node with the given name
+     *
+     * @param nodeName name of the new node
+     * @param nodeTypeName node type name
+     * @param id id of the new node
+     * @param referenceable if <code>true</code>, a UUID property is created
+     * @return the node state
+     * @throws NoSuchNodeTypeException if the node type does not exist
+     * @throws ConstraintViolationException if there is a constraint violation
+     * @throws RepositoryException if an error occurs
      */
     public NodeStateEx addNode(Name nodeName, Name nodeTypeName,
                                NodeId id, boolean referenceable)
@@ -445,9 +536,11 @@
     /**
      * creates a new child node
      *
-     * @param name
-     * @param id
+     * @param name name
+     * @param nodeTypeName node type name
+     * @param id id
      * @return the newly created node.
+     * @throws RepositoryException if an error occurs
      */
     private NodeStateEx createChildNode(Name name, Name nodeTypeName, NodeId id)
             throws RepositoryException {
@@ -475,10 +568,119 @@
     }
 
     /**
+     * Moves the source node to this node using the given name.
+     * @param src shareable source node
+     * @param name name of new node
+     * @param createShare if <code>true</code> a share is created instead.
+     * @return child node
+     * @throws RepositoryException if an error occurs
+     */
+    public NodeStateEx moveFrom(NodeStateEx src, Name name, boolean createShare)
+            throws RepositoryException {
+        if (name == null) {
+            name = src.getName();
+        }
+        // (4) check for name collisions
+        NodeDef def;
+        try {
+            def = getEffectiveNodeType().getApplicableChildNodeDef(name, nodeState.getNodeTypeName(), ntReg);
+        } catch (RepositoryException re) {
+            String msg = "no definition found in parent node's node type for new node";
+            throw new ConstraintViolationException(msg, re);
+        }
+        ChildNodeEntry cne = nodeState.getChildNodeEntry(name, 1);
+        if (cne != null) {
+            // there's already a child node entry with that name;
+            // check same-name sibling setting of new node
+            if (!def.allowsSameNameSiblings()) {
+                throw new ItemExistsException(getNodeId() + "/" + name);
+            }
+            NodeState existingChild;
+            try {
+                // check same-name sibling setting of existing node
+                existingChild = (NodeState) stateMgr.getItemState(cne.getId());
+            } catch (ItemStateException e) {
+                throw new RepositoryException(e);
+            }
+            if (!ntReg.getNodeDef(existingChild.getDefinitionId()).allowsSameNameSiblings()) {
+                throw new ItemExistsException(existingChild.toString());
+            }
+        } else {
+            // check if 'add' is allowed
+            if (getDefinition().isProtected()) {
+                String msg = "not allowed to modify a protected node";
+                throw new ConstraintViolationException(msg);
+            }
+        }
+
+        if (createShare) {
+            // (5) do clone operation
+            NodeId parentId = getNodeId();
+            src.addShareParent(parentId);
+            // attach to this parent
+            nodeState.addChildNodeEntry(name, src.getNodeId());
+            if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
+                nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
+            }
+            return new NodeStateEx(stateMgr, ntReg, src.getState(), name);
+        } else {
+            // detach from parent
+            NodeStateEx parent = getNode(src.getParentId());
+            parent.nodeState.removeChildNodeEntry(src.getNodeId());
+            if (parent.nodeState.getStatus() == ItemState.STATUS_EXISTING) {
+                parent.nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
+            }
+            // attach to this parent
+            nodeState.addChildNodeEntry(name, src.getNodeId());
+            if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
+                nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
+            }
+            NodeState srcState = src.getState();
+            srcState.setParentId(getNodeId());
+            srcState.setDefinitionId(def.getId());
+            
+            if (srcState.getStatus() == ItemState.STATUS_EXISTING) {
+                srcState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
+            }
+            return new NodeStateEx(stateMgr, ntReg, srcState, name);
+        }
+    }
+
+    /**
+     * Adds a share parent id
+     * @param parentId the parent id
+     * @throws RepositoryException if an error occurs
+     */
+    private void addShareParent(NodeId parentId) throws RepositoryException {
+        // verify that we're shareable
+        if (!nodeState.isShareable()) {
+            String msg = this + " is not shareable.";
+            throw new RepositoryException(msg);
+        }
+
+        // detect share cycle (TODO)
+        // NodeId srcId = getNodeId();
+        //HierarchyManager hierMgr = session.getHierarchyManager();
+        //if (parentId.equals(srcId) || hierMgr.isAncestor(srcId, parentId)) {
+        //    String msg = "This would create a share cycle.";
+        //    log.debug(msg);
+        //    throw new RepositoryException(msg);
+        //}
+
+        if (!nodeState.containsShare(parentId)) {
+            if (nodeState.addShare(parentId)) {
+                return;
+            }
+        }
+        String msg = "Adding a shareable node twice to the same parent is not supported.";
+        throw new UnsupportedRepositoryOperationException(msg);
+    }
+
+    /**
      * returns all child nodes
      *
      * @return the child nodes.
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs
      */
     public NodeStateEx[] getChildNodes() throws RepositoryException {
         try {
@@ -498,7 +700,7 @@
     /**
      * stores the persistent state recursively
      *
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs
      */
     public void store() throws RepositoryException {
         try {
@@ -511,8 +713,8 @@
     /**
      * stores the given persistent state recursively
      *
-     * @param state
-     * @throws ItemStateException
+     * @param state node state to store
+     * @throws ItemStateException if an error occurs
      */
     private void store(NodeState state)
             throws ItemStateException {
@@ -539,12 +741,12 @@
     /**
      * reloads the persistent state recursively
      *
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs
      */
     public void reload() throws RepositoryException {
         try {
             reload(nodeState);
-            // refetch nodestate if discarded
+            // refetch node state if discarded
             nodeState = (NodeState) stateMgr.getItemState(nodeState.getNodeId());
         } catch (ItemStateException e) {
             throw new RepositoryException(e);
@@ -554,8 +756,8 @@
     /**
      * reloads the given persistent state recursively
      *
-     * @param state
-     * @throws ItemStateException
+     * @param state node state
+     * @throws ItemStateException if an error occurs
      */
     private void reload(NodeState state) throws ItemStateException {
         if (state.getStatus() != ItemState.STATUS_EXISTING) {
@@ -580,8 +782,8 @@
     /**
      * copies a property
      *
-     * @param prop
-     * @throws RepositoryException
+     * @param prop source property
+     * @throws RepositoryException if an error occurs
      */
     public void copyFrom(PropertyImpl prop) throws RepositoryException {
         if (prop.getDefinition().isMultiple()) {
@@ -596,4 +798,36 @@
         }
     }
 
+    /**
+     * copies a property
+     *
+     * @param prop source property
+     * @throws RepositoryException if an error occurs
+     */
+    public void copyFrom(PropertyState prop) throws RepositoryException {
+        InternalValue[] values = prop.getValues();
+        InternalValue[] copiedValues = new InternalValue[values.length];
+        for (int i = 0; i < values.length; i++) {
+            copiedValues[i] = values[i].createCopy();
+        }
+        setPropertyValues(prop.getName(), prop.getType(), copiedValues, prop.isMultiValued());
+    }
+
+    /**
+     * Returns the NodeDef for this state
+     * @return the node def
+     */
+    public NodeDef getDefinition() {
+        return ntReg.getNodeDef(nodeState.getDefinitionId());
+    }
+
+    /**
+     * Returns the property definition for the property state
+     * @param prop the property state
+     * @return the prop def
+     */
+    public PropDef getDefinition(PropertyState prop) {
+        return ntReg.getPropDef(prop.getDefinitionId());
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java?rev=795866&r1=795865&r2=795866&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java Mon Jul 20 14:59:21 2009
@@ -164,7 +164,7 @@
             // check permissions
             checkVersionManagementPermission();
             session.getVersionManager().setVersionLabel(
-                    this, session.getQName(versionName),
+                    session, getInternalVersionHistory(), session.getQName(versionName),
                     session.getQName(label), move);
         } catch (NameException e) {
             throw new VersionException(e);
@@ -178,7 +178,8 @@
         try {
             // check permissions
             checkVersionManagementPermission();
-            javax.jcr.version.Version existing = session.getVersionManager().setVersionLabel(this, null, session.getQName(label), true);
+            InternalVersion existing = session.getVersionManager().setVersionLabel(
+                    session, getInternalVersionHistory(), null, session.getQName(label), true);
             if (existing == null) {
                 throw new VersionException("No version with label '" + label + "' exists in this version history.");
             }
@@ -249,7 +250,8 @@
         try {
             // check permissions
             checkVersionManagementPermission();
-            session.getVersionManager().removeVersion(this, session.getQName(versionName));
+            session.getVersionManager().removeVersion(session,
+                    getInternalVersionHistory(), session.getQName(versionName));
         } catch (NameException e) {
             throw new RepositoryException(e);
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java?rev=795866&r1=795865&r2=795866&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManager.java Mon Jul 20 14:59:21 2009
@@ -16,17 +16,14 @@
  */
 package org.apache.jackrabbit.core.version;
 
-import org.apache.jackrabbit.core.NodeImpl;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
 import org.apache.jackrabbit.spi.Name;
 
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.version.Version;
-import javax.jcr.version.VersionHistory;
-
 /**
  * This interface defines the version manager. It gives access to the underlying
  * persistence layer of the versioning.
@@ -62,28 +59,31 @@
      * invokes the checkin() on the persistent version manager and remaps the
      * newly created version objects.
      *
+     * @param session session that invokes the checkin
      * @param node node to checkin
      * @return the newly created version
      * @throws RepositoryException if an error occurs
      */
-    Version checkin(NodeImpl node) throws RepositoryException;
+    InternalVersion checkin(Session session, NodeStateEx node) throws RepositoryException;
 
     /**
      * invokes the checkout() on the persistent version manager.
      *
-     * @param node node to checkout
-     * @return the base version
+     * @param state node to checkout
+     * @param activityId node id if the current activity
+     * @return the base version id
      * @throws RepositoryException if an error occurs
      */
-    Version checkout(NodeImpl node) throws RepositoryException;
+    NodeId canCheckout(NodeStateEx state, NodeId activityId) throws RepositoryException;
 
     /**
      * Removes the specified version from the given version history.
+     * @param session the session that performs the remove
      * @param history version history to remove the version from
      * @param versionName name of the version
      * @throws RepositoryException if an error occurs
      */
-    void removeVersion(VersionHistory history, Name versionName)
+    void removeVersion(Session session, InternalVersionHistory history, Name versionName)
             throws RepositoryException;
 
     /**
@@ -94,6 +94,7 @@
      * In either case, the version the label was previously assigned is returned,
      * or <code>null</code> of the label was not moved.
      *
+     * @param session the session that performs the operation
      * @param history version history
      * @param version name of the version
      * @param label new label
@@ -101,8 +102,10 @@
      * @return the version that had the label or <code>null</code>
      * @throws RepositoryException if an error occurs
      */
-    Version setVersionLabel(VersionHistory history, Name version, Name label,
-                            boolean move)
+    InternalVersion setVersionLabel(Session session, 
+                                    InternalVersionHistory history,
+                                    Name version, Name label,
+                                    boolean move)
             throws RepositoryException;
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?rev=795866&r1=795865&r2=795866&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java Mon Jul 20 14:59:21 2009
@@ -24,12 +24,9 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.version.ActivityViolationException;
-import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
-import javax.jcr.version.VersionHistory;
 
 import org.apache.commons.collections.map.ReferenceMap;
-import org.apache.jackrabbit.core.NodeImpl;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.cluster.UpdateEventChannel;
 import org.apache.jackrabbit.core.cluster.UpdateEventListener;
@@ -427,10 +424,9 @@
      * checks if the checkout is valid in respect to a possible activity set on
      * the session
      */
-    public Version checkout(NodeImpl node) throws RepositoryException {
-        NodeId baseId = NodeId.valueOf(node.getProperty(NameConstants.JCR_BASEVERSION).getString());
-        NodeImpl activity = (NodeImpl) node.getSession().getWorkspace().getVersionManager().getActivity();
-        if (activity != null) {
+    public NodeId canCheckout(NodeStateEx state, NodeId activityId) throws RepositoryException {
+        NodeId baseId = state.getPropertyValue(NameConstants.JCR_BASEVERSION).getNodeId();
+        if (activityId != null) {
             // If there exists another workspace with node N' where N' also has version
             // history H, N' is checked out and the jcr:activity property of N'
             // references A, then the checkout fails with an
@@ -439,10 +435,9 @@
 
             // we're currently leverage the fact, that only references to "real"
             // workspaces are recorded.
-            NodeId nodeId = activity.getNodeId();
-            if (stateMgr.hasNodeReferences(nodeId)) {
+            if (stateMgr.hasNodeReferences(activityId)) {
                 try {
-                    NodeReferences refs = stateMgr.getNodeReferences(nodeId);
+                    NodeReferences refs = stateMgr.getNodeReferences(activityId);
                     if (refs.hasReferences()) {
                         throw new ActivityViolationException("Unable to checkout. " +
                                 "Activity is already used for the same node in " +
@@ -453,12 +448,11 @@
                 }
             }
 
-            // TODO:
             // If there is a version in H that is not an eventual predecessor of N but
             // whose jcr:activity references A, then the checkout fails with an
             // ActivityViolationException
-            InternalActivityImpl a = (InternalActivityImpl) getItem(nodeId);
-            NodeId historyId = NodeId.valueOf(node.getProperty(NameConstants.JCR_VERSIONHISTORY).getString());
+            InternalActivityImpl a = (InternalActivityImpl) getItem(activityId);
+            NodeId historyId = state.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
             InternalVersionHistory history = (InternalVersionHistory) getItem(historyId);
             InternalVersion version = a.getLatestVersion(history);
             if (version != null) {
@@ -472,8 +466,7 @@
                 }
             }
         }
-        return (VersionImpl)
-                ((SessionImpl) node.getSession()).getNodeById(baseId);
+        return baseId;
     }
 
     /**
@@ -482,16 +475,17 @@
      * This method must not be synchronized since it could cause deadlocks with
      * item-reading listeners in the observation thread.
      */
-    public Version checkin(final NodeImpl node) throws RepositoryException {
-        InternalVersion version = (InternalVersion)
-                escFactory.doSourced((SessionImpl) node.getSession(), new SourcedTarget() {
+    public InternalVersion checkin(final Session session, final NodeStateEx node)
+            throws RepositoryException {
+        return (InternalVersion)
+                escFactory.doSourced((SessionImpl) session, new SourcedTarget() {
             public Object run() throws RepositoryException {
                 InternalVersionHistory vh;
-                if (node.isNodeType(NameConstants.MIX_VERSIONABLE)) {
+                if (node.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE)) {
                     // in full versioning, the history id can be retrieved via
                     // the property
-                    String histUUID = node.getProperty(NameConstants.JCR_VERSIONHISTORY).getString();
-                    vh = getVersionHistory(NodeId.valueOf(histUUID));
+                    NodeId histId = node.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
+                    vh = getVersionHistory(histId);
                     return internalCheckin((InternalVersionHistoryImpl) vh, node, false);
                 } else {
                     // in simple versioning the history id needs to be calculated
@@ -500,9 +494,6 @@
                 }
             }
         });
-
-        return (VersionImpl)
-                ((SessionImpl) node.getSession()).getNodeById(version.getId());
     }
 
     /**
@@ -511,20 +502,19 @@
      * This method must not be synchronized since it could cause deadlocks with
      * item-reading listeners in the observation thread.
      */
-    public void removeVersion(VersionHistory history, final Name name)
+    public void removeVersion(Session session,
+                              final InternalVersionHistory history,
+                              final Name name)
             throws VersionException, RepositoryException {
 
-        final VersionHistoryImpl historyImpl = (VersionHistoryImpl) history;
-        if (!historyImpl.hasNode(name)) {
+        if (!history.hasVersion(name)) {
             throw new VersionException("Version with name " + name.toString()
                     + " does not exist in this VersionHistory");
         }
 
-        escFactory.doSourced((SessionImpl) history.getSession(), new SourcedTarget() {
+        escFactory.doSourced((SessionImpl) session, new SourcedTarget() {
             public Object run() throws RepositoryException {
-                InternalVersionHistoryImpl vh = (InternalVersionHistoryImpl)
-                        historyImpl.getInternalVersionHistory();
-                internalRemoveVersion(vh, name);
+                internalRemoveVersion((InternalVersionHistoryImpl) history, name);
                 return null;
             }
         });
@@ -536,26 +526,18 @@
      * This method must not be synchronized since it could cause deadlocks with
      * item-reading listeners in the observation thread.
      */
-    public Version setVersionLabel(final VersionHistory history,
-                                   final Name version, final Name label,
-                                   final boolean move)
+    public InternalVersion setVersionLabel(Session session,
+                                           final InternalVersionHistory history,
+                                           final Name version, final Name label,
+                                           final boolean move)
             throws RepositoryException {
 
-        InternalVersion v = (InternalVersion)
-                escFactory.doSourced((SessionImpl) history.getSession(), new SourcedTarget() {
+        return (InternalVersion)
+                escFactory.doSourced((SessionImpl) session, new SourcedTarget() {
             public Object run() throws RepositoryException {
-                InternalVersionHistoryImpl vh = (InternalVersionHistoryImpl)
-                        ((VersionHistoryImpl) history).getInternalVersionHistory();
-                return setVersionLabel(vh, version, label, move);
+                return setVersionLabel((InternalVersionHistoryImpl) history, version, label, move);
             }
         });
-
-        if (v == null) {
-            return null;
-        } else {
-            return (Version)
-                    ((SessionImpl) history.getSession()).getNodeById(v.getId());
-        }
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java?rev=795866&r1=795865&r2=795866&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java Mon Jul 20 14:59:21 2009
@@ -17,8 +17,6 @@
 package org.apache.jackrabbit.core.version;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.version.Version;
-import javax.jcr.version.VersionHistory;
 
 /**
  * This Interface defines the version selector that needs to provide a version,
@@ -42,10 +40,7 @@
  *
  * @see DateVersionSelector
  * @see LabelVersionSelector
- * @see org.apache.jackrabbit.core.NodeImpl#restore(String, boolean)
- * @see org.apache.jackrabbit.core.NodeImpl#restore(Version, boolean)
- * @see org.apache.jackrabbit.core.NodeImpl#restore(Version, String, boolean)
- * @see org.apache.jackrabbit.core.NodeImpl#restoreByLabel(String, boolean)
+ * @see javax.jcr.version.VersionManager#restore
  *
  */
 public interface VersionSelector {
@@ -59,6 +54,6 @@
      * @return A version or <code>null</code>.
      * @throws RepositoryException if an error occurs.
      */
-    Version select(VersionHistory versionHistory) throws RepositoryException;
+    InternalVersion select(InternalVersionHistory versionHistory) throws RepositoryException;
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java?rev=795866&r1=795865&r2=795866&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java Mon Jul 20 14:59:21 2009
@@ -21,21 +21,20 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
-import javax.jcr.version.VersionHistory;
 
 import org.apache.jackrabbit.core.InternalXAResource;
-import org.apache.jackrabbit.core.id.ItemId;
-import org.apache.jackrabbit.core.id.NodeId;
-import org.apache.jackrabbit.core.NodeImpl;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.TransactionContext;
 import org.apache.jackrabbit.core.TransactionException;
+import org.apache.jackrabbit.core.id.ItemId;
+import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.observation.EventStateCollection;
 import org.apache.jackrabbit.core.observation.EventStateCollectionFactory;
 import org.apache.jackrabbit.core.state.ChangeLog;
+import org.apache.jackrabbit.core.state.ISMLocking.ReadLock;
+import org.apache.jackrabbit.core.state.ISMLocking.WriteLock;
 import org.apache.jackrabbit.core.state.ItemState;
 import org.apache.jackrabbit.core.state.ItemStateCacheFactory;
 import org.apache.jackrabbit.core.state.ItemStateException;
@@ -44,8 +43,6 @@
 import org.apache.jackrabbit.core.state.NodeReferences;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.XAItemStateManager;
-import org.apache.jackrabbit.core.state.ISMLocking.ReadLock;
-import org.apache.jackrabbit.core.state.ISMLocking.WriteLock;
 import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
 import org.apache.jackrabbit.core.virtual.VirtualNodeState;
 import org.apache.jackrabbit.core.virtual.VirtualPropertyState;
@@ -225,66 +222,62 @@
     /**
      * {@inheritDoc}
      */
-    public Version checkout(NodeImpl node) throws RepositoryException {
-        return vMgr.checkout(node);
+    public NodeId canCheckout(NodeStateEx state, NodeId activityId) throws RepositoryException {
+        return vMgr.canCheckout(state, activityId);
     }
 
     /**
      * {@inheritDoc}
      */
-    public Version checkin(NodeImpl node) throws RepositoryException {
+    public InternalVersion checkin(Session session, NodeStateEx node) throws RepositoryException {
         if (isInXA()) {
             InternalVersionHistory vh;
             InternalVersion version;
-            if (node.isNodeType(NameConstants.MIX_VERSIONABLE)) {
+            if (node.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE)) {
                 // in full versioning, the history id can be retrieved via
                 // the property
-                String histUUID = node.getProperty(NameConstants.JCR_VERSIONHISTORY).getString();
-                vh = getVersionHistory(NodeId.valueOf(histUUID));
+                NodeId histId = node.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
+                vh = getVersionHistory(histId);
                 version = internalCheckin((InternalVersionHistoryImpl) vh, node, false);
             } else {
                 // in simple versioning the history id needs to be calculated
                 vh = getVersionHistoryOfNode(node.getNodeId());
                 version = internalCheckin((InternalVersionHistoryImpl) vh, node, true);
             }
-            return (Version) ((SessionImpl) node.getSession()).getNodeById(version.getId());
+            return version;
+        } else {
+            return vMgr.checkin(session, node);
         }
-        return vMgr.checkin(node);
     }
 
     /**
      * {@inheritDoc}
      */
-    public void removeVersion(VersionHistory history, Name versionName)
+    public void removeVersion(Session session, InternalVersionHistory history,
+                              Name versionName)
             throws RepositoryException {
-
         if (isInXA()) {
-            InternalVersionHistoryImpl vh = (InternalVersionHistoryImpl)
-                    ((VersionHistoryImpl) history).getInternalVersionHistory();
-            internalRemoveVersion(vh, versionName);
-            return;
+            internalRemoveVersion((InternalVersionHistoryImpl) history, versionName);
+        } else {
+            vMgr.removeVersion(session, history, versionName);
         }
-        vMgr.removeVersion(history, versionName);
     }
 
     /**
      * {@inheritDoc}
      */
-    public Version setVersionLabel(VersionHistory history, Name version,
-                                   Name label, boolean move)
+    public InternalVersion setVersionLabel(Session session,
+                                           InternalVersionHistory history,
+                                           Name version,
+                                           Name label, boolean move)
             throws RepositoryException {
 
         if (isInXA()) {
-            InternalVersionHistoryImpl vh = (InternalVersionHistoryImpl)
-                    ((VersionHistoryImpl) history).getInternalVersionHistory();
-            InternalVersion v = setVersionLabel(vh, version, label, move);
-            if (v == null) {
-                return null;
-            } else {
-                return (Version) ((SessionImpl) history.getSession()).getNodeById(v.getId());
-            }
+            return setVersionLabel((InternalVersionHistoryImpl) history,
+                    version, label, move);
+        } else {
+            return vMgr.setVersionLabel(session, history, version, label, move);
         }
-        return vMgr.setVersionLabel(history, version, label, move);
     }
 
     /**
@@ -466,7 +459,7 @@
      * Before modifying version history given, make a local copy of it.
      */
     protected InternalVersion internalCheckin(InternalVersionHistoryImpl history,
-                                      NodeImpl node, boolean simple)
+                                      NodeStateEx node, boolean simple)
             throws RepositoryException {
 
         if (history.getVersionManager() != this) {



Mime
View raw message