You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2009/09/08 18:09:45 UTC

svn commit: r812570 [15/24] - in /jackrabbit/sandbox/JCR-1456: ./ jackrabbit-api/ jackrabbit-api/src/main/appended-resources/ jackrabbit-api/src/main/appended-resources/META-INF/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/ jackrabb...

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFreezeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFreezeImpl.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFreezeImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFreezeImpl.java Tue Sep  8 16:09:28 2009
@@ -33,7 +33,7 @@
      * @param vMgr
      * @param parent
      */
-    protected InternalFreezeImpl(AbstractVersionManager vMgr, NodeStateEx node, InternalVersionItem parent) {
+    protected InternalFreezeImpl(InternalVersionManagerBase vMgr, NodeStateEx node, InternalVersionItem parent) {
         super(vMgr, node);
         this.parent = parent;
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNode.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNode.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNode.java Tue Sep  8 16:09:28 2009
@@ -16,11 +16,16 @@
  */
 package org.apache.jackrabbit.core.version;
 
+import java.util.Set;
+import java.util.List;
+
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
 import org.apache.jackrabbit.spi.Name;
 
 import javax.jcr.version.VersionException;
+import javax.jcr.RepositoryException;
 
 /**
  * The InternalFrozenNode interface represents the frozen node that was generated
@@ -36,7 +41,7 @@
      * @return an array of internal freezes
      * @throws VersionException if the freezes cannot be retrieved
      */
-    InternalFreeze[] getFrozenChildNodes() throws VersionException;
+    List<ChildNodeEntry> getFrozenChildNodes() throws VersionException;
 
     /**
      * Returns the list of frozen properties.
@@ -64,14 +69,22 @@
      *
      * @return the list of names of the frozen mixin types.
      */
-    Name[] getFrozenMixinTypes();
+    Set<Name> getFrozenMixinTypes();
 
     /**
-     * Checks if this frozen node has the frozen version history
-     * @param id
-     * @return <code>true</code> if this node has the history;
-     *         <code>false</code> otherwise.
+     * Checks if this frozen node had the inidcated child node.
+     * @param name name of the childnode
+     * @param idx 1-based index
+     * @return <code>true</code> if the child node exists
      */
-    boolean hasFrozenHistory(NodeId id);
+    boolean hasFrozenChildNode(Name name, int idx);
 
+    /**
+     * Returns the frozen child node or <code>null</code>
+     * @param name name of the childnode
+     * @param idx 1-based index
+     * @return the child node
+     * @throws RepositoryException if an error occurs
+     */
+    InternalFreeze getFrozenChildNode(Name name, int idx) throws RepositoryException;
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java Tue Sep  8 16:09:28 2009
@@ -16,27 +16,25 @@
  */
 package org.apache.jackrabbit.core.version;
 
-import org.apache.jackrabbit.core.NodeImpl;
-import org.apache.jackrabbit.core.PropertyImpl;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collections;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.OnParentVersionAction;
+import javax.jcr.version.VersionException;
+
 import org.apache.jackrabbit.core.id.NodeId;
-import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
 import org.apache.jackrabbit.core.state.ItemStateException;
 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 javax.jcr.NodeIterator;
-import javax.jcr.PropertyIterator;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.nodetype.NodeType;
-import javax.jcr.version.OnParentVersionAction;
-import javax.jcr.version.VersionException;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * Implements a <code>InternalFrozenNode</code>
  */
@@ -44,32 +42,11 @@
         implements InternalFrozenNode {
 
     /**
-     * checkin mode version.
-     */
-    private static final int MODE_VERSION = 0;
-
-    /**
-     * checkin mode copy. specifies, that the items are always copied.
-     */
-    private static final int MODE_COPY = 1;
-
-    /**
-     * mode flag specifies, that the mode should be recursed. otherwise i
-     * will be redetermined by the opv.
-     */
-    private static final int MODE_COPY_RECURSIVE = 3;
-
-    /**
      * the list of frozen properties
      */
     private PropertyState[] frozenProperties;
 
     /**
-     * the frozen child nodes
-     */
-    private InternalFreeze[] frozenNodes = null;
-
-    /**
      * the frozen id of the original node
      */
     private NodeId frozenUUID = null;
@@ -82,15 +59,17 @@
     /**
      * the frozen list of mixin types of the original node
      */
-    private Name[] frozenMixinTypes = null;
+    private Set<Name> frozenMixinTypes = null;
 
     /**
      * Creates a new frozen node based on the given persistance node.
      *
-     * @param node
-     * @throws javax.jcr.RepositoryException
+     * @param vMgr version manager
+     * @param node underlying node
+     * @param parent parent item
+     * @throws RepositoryException if an error occurs
      */
-    public InternalFrozenNodeImpl(AbstractVersionManager vMgr, NodeStateEx node,
+    public InternalFrozenNodeImpl(InternalVersionManagerBase vMgr, NodeStateEx node,
                                   InternalVersionItem parent)
             throws RepositoryException {
         super(vMgr, node, parent);
@@ -104,6 +83,7 @@
         }
         List<PropertyState> propList = new ArrayList<PropertyState>();
 
+        Set<Name> mixins = new HashSet<Name>();
         for (PropertyState prop : props) {
             if (prop.getName().equals(NameConstants.JCR_FROZENUUID)) {
                 // special property
@@ -124,12 +104,9 @@
             } else if (prop.getName().equals(NameConstants.JCR_FROZENMIXINTYPES)) {
                 // special property
                 InternalValue[] values = node.getPropertyValues(NameConstants.JCR_FROZENMIXINTYPES);
-                if (values == null) {
-                    frozenMixinTypes = new Name[0];
-                } else {
-                    frozenMixinTypes = new Name[values.length];
-                    for (int j = 0; j < values.length; j++) {
-                        frozenMixinTypes[j] = values[j].getName();
+                if (values != null) {
+                    for (InternalValue value : values) {
+                        mixins.add(value.getName());
                     }
                 }
             } else if (prop.getName().equals(NameConstants.JCR_PRIMARYTYPE)) {
@@ -140,12 +117,10 @@
                 propList.add(prop);
             }
         }
-        frozenProperties = (PropertyState[]) propList.toArray(new PropertyState[propList.size()]);
+        frozenProperties = propList.toArray(new PropertyState[propList.size()]);
+        frozenMixinTypes = Collections.unmodifiableSet(mixins);
 
         // do some checks
-        if (frozenMixinTypes == null) {
-            frozenMixinTypes = new Name[0];
-        }
         if (frozenPrimaryType == null) {
             throw new RepositoryException("Illegal frozen node. Must have 'frozenPrimaryType'");
         }
@@ -168,42 +143,27 @@
     /**
      * {@inheritDoc}
      */
-    public synchronized InternalFreeze[] getFrozenChildNodes()
+    public List<ChildNodeEntry> getFrozenChildNodes()
             throws VersionException {
-        if (frozenNodes == null) {
-            try {
-                // maybe add iterator?
-                List<ChildNodeEntry> entries =
-                    node.getState().getChildNodeEntries();
-                frozenNodes = new InternalFreeze[entries.size()];
-                int i = 0;
-                for (ChildNodeEntry entry : entries) {
-                    frozenNodes[i++] = (InternalFreeze) vMgr.getItem(entry.getId());
-                }
-            } catch (RepositoryException e) {
-                throw new VersionException("Unable to retrieve frozen child nodes", e);
-            }
-        }
-        return frozenNodes;
+        return node.getState().getChildNodeEntries();
     }
 
     /**
      * {@inheritDoc}
      */
-    public boolean hasFrozenHistory(NodeId id) {
-        try {
-            InternalFreeze[] frozen = getFrozenChildNodes();
-            for (int i = 0; i < frozen.length; i++) {
-                if (frozen[i] instanceof InternalFrozenVersionHistory
-                        && ((InternalFrozenVersionHistory) frozen[i])
-                            .getVersionHistoryId().equals(id)) {
-                    return true;
-                }
-            }
-        } catch (RepositoryException e) {
-            // ignore
-        }
-        return false;
+    public boolean hasFrozenChildNode(Name name, int idx) {
+        return node.getState().hasChildNodeEntry(name, idx);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public InternalFreeze getFrozenChildNode(Name name, int idx) 
+            throws RepositoryException {
+        ChildNodeEntry e = node.getState().getChildNodeEntry(name, idx);
+        return e == null
+                ? null
+                : (InternalFreeze) vMgr.getItem(e.getId());
     }
 
     /**
@@ -230,7 +190,7 @@
     /**
      * {@inheritDoc}
      */
-    public Name[] getFrozenMixinTypes() {
+    public Set<Name> getFrozenMixinTypes() {
         return frozenMixinTypes;
     }
 
@@ -241,16 +201,20 @@
      * list of frozen properties. It creates frozen child nodes for each child
      * node of <code>src</code> according to its OPV value.
      *
-     * @param parent
-     * @param name
-     * @param src
-     * @return
-     * @throws RepositoryException
+     * @param parent destination parent
+     * @param name new node name
+     * @param src source node state
+     * @return the node node state
+     * @throws RepositoryException if an error occurs
      */
     protected static NodeStateEx checkin(NodeStateEx parent, Name name,
-                                         NodeImpl src)
+                                         NodeStateEx src)
             throws RepositoryException {
-        return checkin(parent, name, src, MODE_VERSION);
+        try {
+            return checkin(parent, name, src, false);
+        } catch (ItemStateException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     /**
@@ -260,15 +224,17 @@
      * list of frozen properties. It creates frozen child nodes for each child
      * node of <code>src</code> according to its OPV value.
      *
-     * @param parent
-     * @param name
-     * @param src
-     * @return
-     * @throws RepositoryException
+     * @param parent destination parent
+     * @param name new node name
+     * @param src source node state
+     * @param forceCopy if <code>true</code> the OPV is ignored and a COPY is performed
+     * @return the nde node state
+     * @throws RepositoryException if an error occurs
+     * @throws ItemStateException if an error during reading the items occurs
      */
     private static NodeStateEx checkin(NodeStateEx parent, Name name,
-                                       NodeImpl src, int mode)
-            throws RepositoryException {
+                                       NodeStateEx src, boolean forceCopy)
+            throws RepositoryException, ItemStateException {
 
         // create new node
         NodeStateEx node = parent.addNode(name, NameConstants.NT_FROZENNODE, null, true);
@@ -277,47 +243,41 @@
         node.setPropertyValue(NameConstants.JCR_FROZENUUID,
                 InternalValue.create(src.getNodeId().toString()));
         node.setPropertyValue(NameConstants.JCR_FROZENPRIMARYTYPE,
-                InternalValue.create(((NodeTypeImpl) src.getPrimaryNodeType()).getQName()));
+                InternalValue.create(src.getState().getNodeTypeName()));
         if (src.hasProperty(NameConstants.JCR_MIXINTYPES)) {
-            NodeType[] mixins = src.getMixinNodeTypes();
-            InternalValue[] ivalues = new InternalValue[mixins.length];
-            for (int i = 0; i < mixins.length; i++) {
-                ivalues[i] = InternalValue.create(((NodeTypeImpl) mixins[i]).getQName());
-            }
-            node.setPropertyValues(NameConstants.JCR_FROZENMIXINTYPES, PropertyType.NAME, ivalues);
+            node.setPropertyValues(NameConstants.JCR_FROZENMIXINTYPES,
+                    PropertyType.NAME, src.getPropertyValues(NameConstants.JCR_MIXINTYPES));
         }
 
         // add the properties
-        PropertyIterator piter = src.getProperties();
-        while (piter.hasNext()) {
-            PropertyImpl prop = (PropertyImpl) piter.nextProperty();
+        for (PropertyState prop: src.getProperties()) {
             int opv;
-            if ((mode & MODE_COPY) > 0) {
+            if (forceCopy) {
                 opv = OnParentVersionAction.COPY;
             } else {
-                opv = prop.getDefinition().getOnParentVersion();
+                opv = src.getDefinition(prop).getOnParentVersion();
             }
 
+            Name propName = prop.getName();
             if (opv == OnParentVersionAction.ABORT) {
                 parent.reload();
-                throw new VersionException("Checkin aborted due to OPV in " + prop);
+                throw new VersionException("Checkin aborted due to OPV abort in " + propName);
             } else if (opv == OnParentVersionAction.VERSION
                     || opv == OnParentVersionAction.COPY) {
                 // ignore frozen properties
-                if (!prop.getQName().equals(NameConstants.JCR_PRIMARYTYPE)
-                        && !prop.getQName().equals(NameConstants.JCR_MIXINTYPES)
-                        && !prop.getQName().equals(NameConstants.JCR_UUID)) {
+                if (!propName.equals(NameConstants.JCR_PRIMARYTYPE)
+                        && !propName.equals(NameConstants.JCR_MIXINTYPES)
+                        && !propName.equals(NameConstants.JCR_UUID)) {
                     node.copyFrom(prop);
                 }
             }
         }
 
         // add the frozen children and histories
-        NodeIterator niter = src.getNodes();
-        while (niter.hasNext()) {
-            NodeImpl child = (NodeImpl) niter.nextNode();
+        boolean isFull = src.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE);
+        for (NodeStateEx child: src.getChildNodes()) {
             int opv;
-            if ((mode & MODE_COPY_RECURSIVE) > 0) {
+            if (forceCopy) {
                 opv = OnParentVersionAction.COPY;
             } else {
                 opv = child.getDefinition().getOnParentVersion();
@@ -326,22 +286,19 @@
             if (opv == OnParentVersionAction.ABORT) {
                 throw new VersionException("Checkin aborted due to OPV in " + child);
             } else if (opv == OnParentVersionAction.VERSION) {
-                if (child.isNodeType(NameConstants.MIX_SIMPLE_VERSIONABLE)) {
+                if (isFull && child.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE)) {
                     // create frozen versionable child
-                    NodeStateEx newChild = node.addNode(child.getQName(), NameConstants.NT_VERSIONEDCHILD, null, false);
+                    NodeId histId = child.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
+                    NodeStateEx newChild = node.addNode(child.getName(), NameConstants.NT_VERSIONEDCHILD, null, false);
                     newChild.setPropertyValue(
                             NameConstants.JCR_CHILDVERSIONHISTORY,
-                            InternalValue.create(new NodeId(child.getVersionHistory().getUUID())));
-                    /*
-                        newChild.setPropertyValue(JCR_BASEVERSION,
-                                InternalValue.create(child.getBaseVersion().getUUID()));
-                     */
+                            InternalValue.create(histId));
                 } else {
-                    // else copy but do not recurse
-                    checkin(node, child.getQName(), child, MODE_COPY);
+                    // else copy
+                    checkin(node, child.getName(), child, true);
                 }
             } else if (opv == OnParentVersionAction.COPY) {
-                checkin(node, child.getQName(), child, MODE_COPY_RECURSIVE);
+                checkin(node, child.getName(), child, true);
             }
         }
         return node;

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenVHImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenVHImpl.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenVHImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenVHImpl.java Tue Sep  8 16:09:28 2009
@@ -34,7 +34,7 @@
      *
      * @param node
      */
-    public InternalFrozenVHImpl(AbstractVersionManager vMgr, NodeStateEx node,
+    public InternalFrozenVHImpl(InternalVersionManagerBase vMgr, NodeStateEx node,
                                 InternalVersionItem parent) {
         super(vMgr, node, parent);
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionHistoryImpl.java Tue Sep  8 16:09:28 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>
  */
@@ -108,7 +107,7 @@
      * @param node version history node state
      * @throws RepositoryException if an error occurs
      */
-    public InternalVersionHistoryImpl(AbstractVersionManager vMgr, NodeStateEx node)
+    public InternalVersionHistoryImpl(InternalVersionManagerBase vMgr, NodeStateEx node)
             throws RepositoryException {
         super(vMgr, node);
         init();
@@ -227,7 +226,18 @@
         if (v != null) {
             v.clear();
         } else {
-            v = new InternalVersionImpl(this, child, child.getName());
+            // check if baseline
+            try {
+                NodeStateEx frozen = child.getNode(NameConstants.JCR_FROZENNODE, 1);
+                Name frozenType = frozen.getPropertyValue(NameConstants.JCR_FROZENPRIMARYTYPE).getName();
+                if (NameConstants.NT_CONFIGURATION.equals(frozenType)) {
+                    v = new InternalBaselineImpl(this, child, child.getName());
+                } else {
+                    v = new InternalVersionImpl(this, child, child.getName());
+                }
+            } catch (RepositoryException e) {
+                throw new InternalError("Version does not have a jcr:frozenNode: " + child.getNodeId());
+            }
         }
         return v;
     }
@@ -400,7 +410,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
@@ -486,25 +496,25 @@
      *
      * @param name new version name
      * @param src source node to version
+     * @param created optional created date
      * @return the newly created version
      * @throws RepositoryException if an error occurs
      */
-    InternalVersionImpl checkin(Name name, NodeImpl src)
+    InternalVersionImpl checkin(Name name, NodeStateEx src, Calendar created)
             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,12 +536,15 @@
 
         // 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);
         }
 
         // initialize 'created', 'predecessors' and 'successors'
-        vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(getCurrentTime()));
+        if (created == null) {
+            created = getCurrentTime();
+        }
+        vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(created));
         vNode.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, predecessors);
         vNode.setPropertyValues(NameConstants.JCR_SUCCESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
 
@@ -539,7 +552,10 @@
         InternalFrozenNodeImpl.checkin(vNode, NameConstants.JCR_FROZENNODE, src);
 
         // update version graph
-        InternalVersionImpl version = new InternalVersionImpl(this, vNode, name);
+        boolean isConfiguration = src.getEffectiveNodeType().includesNodeType(NameConstants.NT_CONFIGURATION);
+        InternalVersionImpl version = isConfiguration
+                ? new InternalBaselineImpl(this, vNode, name)
+                : new InternalVersionImpl(this, vNode, name);
         version.internalAttach();
 
         // and store
@@ -567,7 +583,7 @@
      * @throws RepositoryException if an error occurs
      */
     static NodeStateEx create(
-            AbstractVersionManager vMgr, NodeStateEx parent, Name name,
+            InternalVersionManagerBase vMgr, NodeStateEx parent, Name name,
             NodeState nodeState, NodeId copiedFrom) throws RepositoryException {
 
         // create history node
@@ -585,7 +601,7 @@
         if (copiedFrom != null) {
             pNode.setPropertyValue(NameConstants.JCR_COPIEDFROM, InternalValue.create(copiedFrom, true));
         }
-        
+
         // create root version
         NodeId versionId = new NodeId();
         NodeStateEx vNode = pNode.addNode(NameConstants.JCR_ROOTVERSION, NameConstants.NT_VERSION, versionId, true);
@@ -608,7 +624,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/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionImpl.java Tue Sep  8 16:09:28 2009
@@ -260,10 +260,9 @@
             throws RepositoryException {
         InternalValue[] values = new InternalValue[cessors.size()];
         for (int i = 0; i < values.length; i++) {
-            values[i] = InternalValue.create(
-                    ((InternalVersion) cessors.get(i)).getId());
+            values[i] = InternalValue.create((cessors.get(i)).getId());
         }
-        node.setPropertyValues(propname, PropertyType.STRING, values);
+        node.setPropertyValues(propname, PropertyType.REFERENCE, values);
         if (store) {
             node.store();
         }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionItemImpl.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionItemImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionItemImpl.java Tue Sep  8 16:09:28 2009
@@ -31,14 +31,14 @@
     /**
      * the version manager
      */
-    protected final AbstractVersionManager vMgr;
+    protected final InternalVersionManagerBase vMgr;
 
     /**
      * Creates a new Internal version item impl
      *
      * @param vMgr
      */
-    protected InternalVersionItemImpl(AbstractVersionManager vMgr, NodeStateEx node) {
+    protected InternalVersionItemImpl(InternalVersionManagerBase vMgr, NodeStateEx node) {
         this.vMgr = vMgr;
         this.node = node;
     }
@@ -48,7 +48,7 @@
      *
      * @return the version manager.
      */
-    protected AbstractVersionManager getVersionManager() {
+    protected InternalVersionManagerBase getVersionManager() {
         return vMgr;
     }
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java Tue Sep  8 16:09:28 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/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java Tue Sep  8 16:09:28 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,66 @@
     }
 
     /**
+     * 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);
+    }
+
+    /**
+     * Checks if the given property state exists
+     * @param id property id
+     * @return <code>true</code> if the property state exists
+     */
+    public boolean hasProperty(PropertyId 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 +545,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 +577,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 +709,7 @@
     /**
      * stores the persistent state recursively
      *
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs
      */
     public void store() throws RepositoryException {
         try {
@@ -511,8 +722,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 +750,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 +765,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,11 +791,11 @@
     /**
      * 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()) {
+        if (prop.isMultiple()) {
             InternalValue[] values = prop.internalGetValues();
             InternalValue[] copiedValues = new InternalValue[values.length];
             for (int i = 0; i < values.length; i++) {
@@ -596,4 +807,49 @@
         }
     }
 
+    /**
+     * 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());
+    }
+
+    /**
+     * Checks if this state has the inidcated ancestor
+     * @param nodeId the node id of the ancestor
+     * @return <code>true</code> if it has the inidicated ancestor
+     * @throws RepositoryException if an error occurs
+     */
+    public boolean hasAncestor(NodeId nodeId) throws RepositoryException {
+        if (nodeId.equals(nodeState.getParentId())) {
+            return true;
+        }
+        NodeStateEx parent = getParent();
+        return parent != null && parent.hasAncestor(nodeId);
+    }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionHistoryImpl.java Tue Sep  8 16:09:28 2009
@@ -72,7 +72,7 @@
     protected InternalVersionHistory getInternalVersionHistory()
             throws RepositoryException {
         InternalVersionHistory history =
-                session.getVersionManager().getVersionHistory((NodeId) id);
+                session.getInternalVersionManager().getVersionHistory((NodeId) id);
         if (history == null) {
             throw new InvalidItemStateException(id + ": the item does not exist anymore");
         }
@@ -163,8 +163,8 @@
         try {
             // check permissions
             checkVersionManagementPermission();
-            session.getVersionManager().setVersionLabel(
-                    this, session.getQName(versionName),
+            session.getInternalVersionManager().setVersionLabel(
+                    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.getInternalVersionManager().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.getInternalVersionManager().removeVersion(session,
+                    getInternalVersionHistory(), session.getQName(versionName));
         } catch (NameException e) {
             throw new RepositoryException(e);
         }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionImpl.java Tue Sep  8 16:09:28 2009
@@ -61,7 +61,7 @@
      */
     protected InternalVersion getInternalVersion() throws RepositoryException {
         InternalVersion version =
-                session.getVersionManager().getVersion((NodeId) id);
+                session.getInternalVersionManager().getVersion((NodeId) id);
         if (version == null) {
             throw new InvalidItemStateException(id + ": the item does not exist anymore");
         }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateProvider.java Tue Sep  8 16:09:28 2009
@@ -43,6 +43,11 @@
     private final NodeId historyRootId;
 
     /**
+     * The root node UUID for the activity storage
+     */
+    private final NodeId activitiesRootId;
+
+    /**
      * The item state manager directly on the version persistence mgr
      */
     private final VersionItemStateManager stateMgr;
@@ -57,8 +62,10 @@
      *
      */
     public VersionItemStateProvider(NodeId historyRootId,
+                                    NodeId activitiesRootId,
                                     VersionItemStateManager stateMgr) {
         this.historyRootId = historyRootId;
+        this.activitiesRootId = activitiesRootId;
         this.stateMgr = stateMgr;
 
         stateMgr.addListener(this);
@@ -70,7 +77,7 @@
      * @inheritDoc
      */
     public boolean isVirtualRoot(ItemId id) {
-        return id.equals(historyRootId);
+        return id.equals(historyRootId) || id.equals(activitiesRootId);
     }
 
     /**
@@ -83,11 +90,18 @@
     /**
      * @inheritDoc
      */
+    public NodeId[] getVirtualRootIds() {
+        return new NodeId[]{historyRootId, activitiesRootId};
+    }
+
+    /**
+     * @inheritDoc
+     */
     public VirtualPropertyState createPropertyState(VirtualNodeState parent,
                                                     Name name, int type,
                                                     boolean multiValued)
             throws RepositoryException {
-        throw new IllegalStateException("VersionManager should never create a VirtualPropertyState");
+        throw new IllegalStateException("InternalVersionManager should never create a VirtualPropertyState");
     }
 
     /**
@@ -96,7 +110,7 @@
     public VirtualNodeState createNodeState(VirtualNodeState parent, Name name,
                                             NodeId id, Name nodeTypeName)
             throws RepositoryException {
-        throw new IllegalStateException("VersionManager should never create a VirtualNodeState");
+        throw new IllegalStateException("InternalVersionManager should never create a VirtualNodeState");
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java Tue Sep  8 16:09:28 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/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java Tue Sep  8 16:09:28 2009
@@ -169,6 +169,13 @@
     }
 
     /**
+     * {@inheritDoc}
+     */
+    public NodeId[] getVirtualRootIds() {
+        return new NodeId[]{rootNodeId};
+    }
+
+    /**
      * Returns the root state
      *
      * @return the root state

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java Tue Sep  8 16:09:28 2009
@@ -43,10 +43,18 @@
      * Returns the id of the root node of the virtual tree.
      *
      * @return the id of the root node of the virtual tree.
+     * @deprecated use {@link #getVirtualRootIds()} instead.
      */
     NodeId getVirtualRootId();
 
     /**
+     * Returns the ids of the root nodes of the virtual tree.
+     *
+     * @return the ids of the roots node of the virtual tree.
+     */
+    NodeId[] getVirtualRootIds();
+
+    /**
      * Creats a new virtual property state
      *
      * @param parent

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java Tue Sep  8 16:09:28 2009
@@ -16,28 +16,31 @@
  */
 package org.apache.jackrabbit.core.xml;
 
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
+
 import org.apache.jackrabbit.core.id.NodeId;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.commons.conversion.NameParser;
-import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
-import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.util.ISO9075;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.NamespaceException;
-import javax.jcr.ValueFactory;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.Stack;
-
 /**
  * <code>DocViewImportHandler</code> processes Document View XML SAX events
  * and 'translates' them into <code>{@link Importer}</code> method calls.
@@ -58,7 +61,8 @@
     /**
      * Constructs a new <code>DocViewImportHandler</code>.
      *
-     * @param importer
+     * @param importer the importer
+     * @param valueFactory a value factory
      */
     DocViewImportHandler(Importer importer, ValueFactory valueFactory) {
         super(importer, valueFactory);
@@ -211,7 +215,7 @@
     /**
      * {@inheritDoc}
      * <p/>
-     * See also {@link DocViewSAXEventGenerator#leavingProperties(javax.jcr.Node, int)}
+     * See also {@link org.apache.jackrabbit.commons.xml.Exporter#exportProperties(Node)}
      * regarding special handling of multi-valued properties on export.
      */
     public void startElement(String namespaceURI, String localName,
@@ -230,7 +234,7 @@
             Name nodeTypeName = null;
             Name[] mixinTypes = null;
 
-            ArrayList<PropInfo> props = new ArrayList<PropInfo>(atts.getLength());
+            List<PropInfo> props = new ArrayList<PropInfo>(atts.getLength());
             for (int i = 0; i < atts.getLength(); i++) {
                 if (atts.getURI(i).equals(Name.NS_XMLNS_URI)) {
                     // skip namespace declarations reported as attributes
@@ -320,7 +324,7 @@
         // process buffered character data
         processCharacters();
 
-        NodeInfo node = (NodeInfo) stack.peek();
+        NodeInfo node = stack.peek();
         try {
             // call Importer
             importer.endNode(node);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/PropInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/PropInfo.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/PropInfo.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/PropInfo.java Tue Sep  8 16:09:28 2009
@@ -16,23 +16,15 @@
  */
 package org.apache.jackrabbit.core.xml;
 
-import javax.jcr.ItemExistsException;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
 import javax.jcr.nodetype.ConstraintViolationException;
 
-import org.apache.jackrabbit.core.BatchedItemOperations;
 import org.apache.jackrabbit.core.NodeImpl;
-import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.nodetype.EffectiveNodeType;
-import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.nodetype.PropDef;
 import org.apache.jackrabbit.core.state.NodeState;
-import org.apache.jackrabbit.core.state.PropertyState;
-import org.apache.jackrabbit.core.util.ReferenceChangeTracker;
-import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.slf4j.Logger;
@@ -51,11 +43,6 @@
 public class PropInfo {
 
     /**
-     * Logger instance.
-     */
-    private static Logger log = LoggerFactory.getLogger(PropInfo.class);
-
-    /**
      * Name of the property being imported.
      */
     private final Name name;
@@ -87,12 +74,12 @@
      * Disposes all values contained in this property.
      */
     public void dispose() {
-        for (int i = 0; i < values.length; i++) {
-            values[i].dispose();
+        for (TextValue value : values) {
+            value.dispose();
         }
     }
 
-    private int getTargetType(PropDef def) {
+    public int getTargetType(PropDef def) {
         int target = def.getRequiredType();
         if (target != PropertyType.UNDEFINED) {
             return target;
@@ -103,7 +90,7 @@
         }
     }
 
-    private PropDef getApplicablePropertyDef(EffectiveNodeType ent)
+    public PropDef getApplicablePropertyDef(EffectiveNodeType ent)
             throws ConstraintViolationException {
         if (values.length == 1) {
             // could be single- or multi-valued (n == 1)
@@ -114,116 +101,23 @@
         }
     }
 
-    public void apply(
-            NodeImpl node, NamePathResolver resolver,
-            ReferenceChangeTracker refTracker) throws RepositoryException {
-        // find applicable definition
-        PropDef def = getApplicablePropertyDef(node.getEffectiveNodeType());
-        if (def.isProtected()) {
-            // skip protected property
-            log.debug("skipping protected property " + name);
-            return;
-        }
-
-        // convert serialized values to Value objects
-        Value[] va = new Value[values.length];
-        int targetType = getTargetType(def);
-        for (int i = 0; i < values.length; i++) {
-            va[i] = values[i].getValue(targetType, resolver);
-        }
-
-        // multi- or single-valued property?
-        if (va.length == 1 && !def.isMultiple()) {
-            Exception e = null;
-            try {
-                // set single-value
-                node.setProperty(name, va[0]);
-            } catch (ValueFormatException vfe) {
-                e = vfe;
-            } catch (ConstraintViolationException cve) {
-                e = cve;
-            }
-            if (e != null) {
-                // setting single-value failed, try setting value array
-                // as a last resort (in case there are ambiguous property
-                // definitions)
-                node.setProperty(name, va, type);
-            }
-        } else {
-            // can only be multi-valued (n == 0 || n > 1)
-            node.setProperty(name, va, type);
-        }
-        if (type == PropertyType.REFERENCE
-                || type == PropertyType.WEAKREFERENCE) {
-            // store reference for later resolution
-            refTracker.processedReference(node.getProperty(name));
-        }
+    public Name getName() {
+        return name;
     }
 
-    public void apply(
-            NodeState node, BatchedItemOperations itemOps,
-            NodeTypeRegistry ntReg, ReferenceChangeTracker refTracker)
-            throws RepositoryException {
-        PropertyState prop = null;
-        PropDef def = null;
-
-        if (node.hasPropertyName(name)) {
-            // a property with that name already exists...
-            PropertyId idExisting = new PropertyId(node.getNodeId(), name);
-            prop = (PropertyState) itemOps.getItemState(idExisting);
-            def = ntReg.getPropDef(prop.getDefinitionId());
-            if (def.isProtected()) {
-                // skip protected property
-                log.debug("skipping protected property "
-                        + itemOps.safeGetJCRPath(idExisting));
-                return;
-            }
-            if (!def.isAutoCreated()
-                    || (prop.getType() != type && type != PropertyType.UNDEFINED)
-                    || def.isMultiple() != prop.isMultiValued()) {
-                throw new ItemExistsException(itemOps.safeGetJCRPath(prop.getPropertyId()));
-            }
-        } else {
-            // there's no property with that name,
-            // find applicable definition
-            def = getApplicablePropertyDef(itemOps.getEffectiveNodeType(node));
-            if (def.isProtected()) {
-                // skip protected property
-                log.debug("skipping protected property " + name);
-                return;
-            }
-
-            // create new property
-            prop = itemOps.createPropertyState(node, name, type, def);
-        }
+    public int getType() {
+        return type;
+    }
 
-        // check multi-valued characteristic
-        if (values.length != 1 && !def.isMultiple()) {
-            throw new ConstraintViolationException(itemOps.safeGetJCRPath(prop.getPropertyId())
-                    + " is not multi-valued");
-        }
+    public TextValue[] getTextValues() {
+        return values;        
+    }
 
-        // convert serialized values to InternalValue objects
-        int targetType = getTargetType(def);
-        InternalValue[] iva = new InternalValue[values.length];
+    public Value[] getValues(int targetType, NamePathResolver resolver) throws RepositoryException {
+        Value[] va = new Value[values.length];
         for (int i = 0; i < values.length; i++) {
-            iva[i] = values[i].getInternalValue(targetType);
-        }
-
-        // set values
-        prop.setValues(iva);
-
-        // make sure property is valid according to its definition
-        itemOps.validate(prop);
-
-        if (prop.getType() == PropertyType.REFERENCE
-                || prop.getType() == PropertyType.WEAKREFERENCE) {
-            // store reference for later resolution
-            refTracker.processedReference(prop);
+            va[i] = values[i].getValue(targetType, resolver);
         }
-
-        // store property
-        itemOps.store(prop);
+        return va;
     }
-
 }