jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1350957 - in /jackrabbit/oak/trunk: oak-core/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Sat, 16 Jun 2012 16:42:40 GMT
Author: mduerig
Date: Sat Jun 16 16:42:39 2012
New Revision: 1350957

URL: http://svn.apache.org/viewvc?rev=1350957&view=rev
Log:
OAK-143: Refactor conflict reconciliation from OAK-133: move inner classes to o.a.j.oak.plugins.value

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/AnnotatingConflictHandler.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidatorProvider.java
Modified:
    jackrabbit/oak/trunk/oak-core/pom.xml
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java

Modified: jackrabbit/oak/trunk/oak-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/pom.xml?rev=1350957&r1=1350956&r2=1350957&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-core/pom.xml Sat Jun 16 16:42:39 2012
@@ -44,6 +44,7 @@
               org.apache.jackrabbit.oak.util,
               org.apache.jackrabbit.oak.namepath,
               org.apache.jackrabbit.oak.plugins.name,
+              org.apache.jackrabbit.oak.plugins.value,
               org.apache.jackrabbit.oak.spi.state,
               org.apache.jackrabbit.oak.spi.security.authentication,
               org.apache.jackrabbit.oak.spi.security.principal,

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1350957&r1=1350956&r2=1350957&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
Sat Jun 16 16:42:39 2012
@@ -21,7 +21,6 @@ import java.util.List;
 
 import javax.annotation.Nonnull;
 import javax.jcr.Credentials;
-import javax.jcr.InvalidItemStateException;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
@@ -29,28 +28,23 @@ import javax.security.auth.login.LoginEx
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.mk.index.Indexer;
-import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.api.CoreValue;
-import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
 import org.apache.jackrabbit.oak.plugins.name.NameValidatorProvider;
 import org.apache.jackrabbit.oak.plugins.name.NamespaceValidatorProvider;
 import org.apache.jackrabbit.oak.plugins.type.TypeValidatorProvider;
+import org.apache.jackrabbit.oak.plugins.value.ConflictValidatorProvider;
 import org.apache.jackrabbit.oak.query.QueryEngineImpl;
 import org.apache.jackrabbit.oak.security.authentication.LoginContextProviderImpl;
 import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CompositeCommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CompositeValidatorProvider;
-import org.apache.jackrabbit.oak.spi.commit.DefaultValidator;
 import org.apache.jackrabbit.oak.spi.commit.ValidatingCommitHook;
-import org.apache.jackrabbit.oak.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.security.authentication.LoginContextProvider;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -151,49 +145,4 @@ public class ContentRepositoryImpl imple
 
     //------------------------------------------------------------< ConflictValidator
>---
 
-    private static class ConflictValidatorProvider implements ValidatorProvider {
-        @Override
-        public Validator getRootValidator(NodeState before, NodeState after) {
-            return new DefaultValidator() {
-                @Override
-                public void propertyAdded(PropertyState after) throws CommitFailedException
{
-                    failOnMergeConflict(after);
-                }
-
-                @Override
-                public void propertyChanged(PropertyState before, PropertyState after)
-                        throws CommitFailedException {
-                    failOnMergeConflict(after);
-                }
-
-                @Override
-                public Validator childNodeAdded(String name, NodeState after) {
-                    return this;
-                }
-
-                @Override
-                public Validator childNodeChanged(String name, NodeState before, NodeState
after) {
-                    return this;
-                }
-
-                @Override
-                public Validator childNodeDeleted(String name, NodeState before) {
-                    return this;
-                }
-
-                private void failOnMergeConflict(PropertyState property) throws CommitFailedException
{
-                    if ("jcr:mixinTypes".equals(property.getName())) {
-                        assert property.isArray();
-                        Iterable<CoreValue> mixins = property.getValues();
-                        for (CoreValue v : mixins) {
-                            if ("mix:mergeConflict".equals(v.getString())) {
-                                throw new CommitFailedException(new InvalidItemStateException("Item
has unresolved conflicts"));
-                            }
-                        }
-                    }
-                }
-            };
-        }
-    }
-
 }

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/AnnotatingConflictHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/AnnotatingConflictHandler.java?rev=1350957&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/AnnotatingConflictHandler.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/AnnotatingConflictHandler.java
Sat Jun 16 16:42:39 2012
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.value;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.PropertyType;
+
+import org.apache.jackrabbit.oak.api.ConflictHandler;
+import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.CoreValueFactory;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.util.Iterators;
+
+import static org.apache.jackrabbit.oak.util.Iterators.toList;
+
+/**
+ * This {@link ConflictHandler} implementation resolves conflicts to
+ * {@link Resolution#THEIRS} and in addition marks nodes where a conflict
+ * occurred with {@code mix:mergeConflict}:
+ *
+ * <pre>
+ * [mix:mergeConflict]
+ *   mixin
+ *   primaryitem jcr:ours
+ *   + jcr:ours (nt:unstructured)
+ * </pre>
+ *
+ * The {@code jcr:ours} sub node contains our version of the node prior to
+ * the conflict.
+ *
+ * @see ConflictValidator
+ */
+public class AnnotatingConflictHandler implements ConflictHandler {
+    private static final String JCR_MIXIN_TYPES = "jcr:mixinTypes";
+
+    // TODO: move these constants to some common location for repository internal node types
+    private static final String MIX_MERGE_CONFLICT = "mix:mergeConflict";
+    private static final String JCR_OURS = "jcr:ours";
+    private static final String ADD_EXISTING = "addExisting";
+    private static final String CHANGE_DELETED = "changeDeleted";
+    private static final String CHANGE_CHANGED = "changeChanged";
+    private static final String DELETE_CHANGED = "deleteChanged";
+    private static final String DELETE_DELETED = "deleteDeleted";
+
+    private final CoreValueFactory valueFactory;
+
+    public AnnotatingConflictHandler(CoreValueFactory valueFactory) {
+        this.valueFactory = valueFactory;
+    }
+
+    @Override
+    public Resolution addExistingProperty(Tree parent, PropertyState ours, PropertyState
theirs) {
+        Tree marker = addConflictMarker(parent);
+        setProperty(getOrCreateNode(marker, ADD_EXISTING), ours);
+        return Resolution.THEIRS;
+    }
+
+    @Override
+    public Resolution changeDeletedProperty(Tree parent, PropertyState ours) {
+        Tree marker = addConflictMarker(parent);
+        setProperty(getOrCreateNode(marker, CHANGE_DELETED), ours);
+        return Resolution.THEIRS;
+    }
+
+    @Override
+    public Resolution changeChangedProperty(Tree parent, PropertyState ours, PropertyState
theirs) {
+        Tree marker = addConflictMarker(parent);
+        setProperty(getOrCreateNode(marker, CHANGE_CHANGED), ours);
+        return Resolution.THEIRS;
+    }
+
+    @Override
+    public Resolution deleteChangedProperty(Tree parent, PropertyState theirs) {
+        Tree marker = addConflictMarker(parent);
+        setProperty(getOrCreateNode(marker, DELETE_CHANGED), theirs);
+        return Resolution.THEIRS;
+    }
+
+    @Override
+    public Resolution deleteDeletedProperty(Tree parent, PropertyState ours) {
+        Tree marker = addConflictMarker(parent);
+        setProperty(getOrCreateNode(marker, DELETE_DELETED), ours);
+        return Resolution.THEIRS;
+    }
+
+    @Override
+    public Resolution addExistingNode(Tree parent, String name, NodeState ours, NodeState
theirs) {
+        Tree marker = addConflictMarker(parent);
+        addChild(getOrCreateNode(marker, ADD_EXISTING), name, ours);
+        return Resolution.THEIRS;
+    }
+
+    @Override
+    public Resolution changeDeletedNode(Tree parent, String name, NodeState ours) {
+        Tree marker = addConflictMarker(parent);
+        addChild(getOrCreateNode(marker, CHANGE_DELETED), name, ours);
+        return Resolution.THEIRS;
+    }
+
+    @Override
+    public Resolution deleteChangedNode(Tree parent, String name, NodeState theirs) {
+        Tree marker = addConflictMarker(parent);
+        markChild(getOrCreateNode(marker, DELETE_CHANGED), name);
+        return Resolution.THEIRS;
+    }
+
+    @Override
+    public Resolution deleteDeletedNode(Tree parent, String name) {
+        Tree marker = addConflictMarker(parent);
+        markChild(getOrCreateNode(marker, DELETE_DELETED), name);
+        return Resolution.THEIRS;
+    }
+
+    private Tree addConflictMarker(Tree parent) {
+        PropertyState jcrMixin = parent.getProperty(JCR_MIXIN_TYPES);
+        List<CoreValue> mixins = new ArrayList<CoreValue>();
+        if (jcrMixin != null) {
+            assert jcrMixin.isArray();
+            mixins = Iterators.toList(jcrMixin.getValues(), mixins);
+        }
+        if (!mixins.contains(MIX_MERGE_CONFLICT)) {
+            mixins.add(valueFactory.createValue(MIX_MERGE_CONFLICT, PropertyType.NAME));
+            parent.setProperty(JCR_MIXIN_TYPES, mixins);
+        }
+
+        return getOrCreateNode(parent, JCR_OURS);
+    }
+
+    private static Tree getOrCreateNode(Tree parent, String name) {
+        Tree child = parent.getChild(name);
+        if (child == null) {
+            child = parent.addChild(name);
+        }
+        return child;
+    }
+
+    private static void addChild(Tree parent, String name, NodeState state) {
+        Tree child = parent.addChild(name);
+        for (PropertyState property : state.getProperties()) {
+            setProperty(child, property);
+        }
+        for (ChildNodeEntry entry : state.getChildNodeEntries()) {
+            addChild(child, entry.getName(), entry.getNodeState());
+        }
+    }
+
+    private static void markChild(Tree parent, String name) {
+        parent.addChild(name);
+    }
+
+    private static void setProperty(Tree parent, PropertyState property) {
+        if (property.isArray()) {
+            parent.setProperty(property.getName(),
+                    toList(property.getValues(), new ArrayList<CoreValue>()));
+        }
+        else {
+            parent.setProperty(property.getName(), property.getValue());
+        }
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidator.java?rev=1350957&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidator.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidator.java
Sat Jun 16 16:42:39 2012
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.value;
+
+import javax.jcr.InvalidItemStateException;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.spi.commit.DefaultValidator;
+import org.apache.jackrabbit.oak.spi.commit.Validator;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+/**
+ * {@link Validator} which checks the presence of conflict markers
+ * in the tree in fails the commit if any are found.
+ *
+ * @see AnnotatingConflictHandler
+ */
+public class ConflictValidator extends DefaultValidator {
+    @Override
+    public void propertyAdded(PropertyState after) throws CommitFailedException {
+        failOnMergeConflict(after);
+    }
+
+    @Override
+    public void propertyChanged(PropertyState before, PropertyState after)
+            throws CommitFailedException {
+        failOnMergeConflict(after);
+    }
+
+    @Override
+    public Validator childNodeAdded(String name, NodeState after) {
+        return this;
+    }
+
+    @Override
+    public Validator childNodeChanged(String name, NodeState before, NodeState after) {
+        return this;
+    }
+
+    @Override
+    public Validator childNodeDeleted(String name, NodeState before) {
+        return this;
+    }
+
+    private static void failOnMergeConflict(PropertyState property) throws CommitFailedException
{
+        if ("jcr:mixinTypes".equals(property.getName())) {
+            assert property.isArray();
+            Iterable<CoreValue> mixins = property.getValues();
+            for (CoreValue v : mixins) {
+                if ("mix:mergeConflict".equals(v.getString())) {
+                    throw new CommitFailedException(new InvalidItemStateException("Item has
unresolved conflicts"));
+                }
+            }
+        }
+    }
+}

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidatorProvider.java?rev=1350957&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidatorProvider.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidatorProvider.java
Sat Jun 16 16:42:39 2012
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.value;
+
+import org.apache.jackrabbit.oak.spi.commit.Validator;
+import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+public class ConflictValidatorProvider implements ValidatorProvider {
+    @Override
+    public Validator getRootValidator(NodeState before, NodeState after) {
+        return new ConflictValidator();
+    }
+
+}

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java?rev=1350957&r1=1350956&r2=1350957&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
Sat Jun 16 16:42:39 2012
@@ -18,9 +18,7 @@ package org.apache.jackrabbit.oak.jcr;
 
 import java.io.IOException;
 import java.text.ParseException;
-import java.util.ArrayList;
 import java.util.Collections;
-import java.util.List;
 import java.util.Map;
 
 import javax.annotation.CheckForNull;
@@ -28,8 +26,6 @@ import javax.annotation.Nonnull;
 import javax.jcr.ItemExistsException;
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
-import javax.jcr.Property;
-import javax.jcr.PropertyType;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -45,8 +41,6 @@ import org.apache.jackrabbit.oak.api.Com
 import org.apache.jackrabbit.oak.api.ConflictHandler;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.CoreValue;
-import org.apache.jackrabbit.oak.api.CoreValueFactory;
-import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.ResultRow;
@@ -59,14 +53,10 @@ import org.apache.jackrabbit.oak.namepat
 import org.apache.jackrabbit.oak.namepath.NameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
-import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.util.Iterators;
+import org.apache.jackrabbit.oak.plugins.value.AnnotatingConflictHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.jackrabbit.oak.util.Iterators.toList;
-
 public class SessionDelegate {
     static final Logger log = LoggerFactory.getLogger(SessionDelegate.class);
 
@@ -92,7 +82,7 @@ public class SessionDelegate {
         this.workspace = new WorkspaceImpl(this);
         this.session = new SessionImpl(this);
         this.root = contentSession.getCurrentRoot();
-        this.conflictHandler = new AnnotatingConflictHandler();
+        this.conflictHandler = new AnnotatingConflictHandler(contentSession.getCoreValueFactory());
     }
 
     public boolean isAlive() {
@@ -458,148 +448,4 @@ public class SessionDelegate {
 
     //------------------------------------------------------------< AnnotatingConflictHandler
>---
 
-    /**
-     * This {@link ConflictHandler} implementation resolves conflicts to
-     * {@link Resolution#THEIRS} and in addition marks nodes where a conflict
-     * occurred with {@code mix:mergeConflict}:
-     *
-     * <pre>
-     * [mix:mergeConflict]
-     *   mixin
-     *   primaryitem jcr:ours
-     *   + jcr:ours (nt:unstructured)
-     * </pre>
-     *
-     * The {@code jcr:ours} sub node contains our version of the node prior to
-     * the conflict.
-     */
-    private class AnnotatingConflictHandler implements ConflictHandler {
-        // TODO: move these constants to some common location for repository internal node
types
-        public static final String MIX_MERGE_CONFLICT = "mix:mergeConflict";
-        public static final String JCR_OURS = "jcr:ours";
-        public static final String ADD_EXISTING = "addExisting";
-        public static final String CHANGE_DELETED = "changeDeleted";
-        public static final String CHANGE_CHANGED = "changeChanged";
-        public static final String DELETE_CHANGED = "deleteChanged";
-        public static final String DELETE_DELETED = "deleteDeleted";
-
-        private final CoreValueFactory valueFactory;
-        private final String jcrMixinTypes;
-
-        AnnotatingConflictHandler() throws RepositoryException {
-            valueFactory = contentSession.getCoreValueFactory();
-            jcrMixinTypes = getOakPathOrThrow(Property.JCR_MIXIN_TYPES);
-        }
-
-        @Override
-        public Resolution addExistingProperty(Tree parent, PropertyState ours, PropertyState
theirs) {
-            Tree marker = addConflictMarker(parent);
-            setProperty(getOrCreateNode(marker, ADD_EXISTING), ours);
-            return Resolution.THEIRS;
-        }
-
-        @Override
-        public Resolution changeDeletedProperty(Tree parent, PropertyState ours) {
-            Tree marker = addConflictMarker(parent);
-            setProperty(getOrCreateNode(marker, CHANGE_DELETED), ours);
-            return Resolution.THEIRS;
-        }
-
-        @Override
-        public Resolution changeChangedProperty(Tree parent, PropertyState ours, PropertyState
theirs) {
-            Tree marker = addConflictMarker(parent);
-            setProperty(getOrCreateNode(marker, CHANGE_CHANGED), ours);
-            return Resolution.THEIRS;
-        }
-
-        @Override
-        public Resolution deleteChangedProperty(Tree parent, PropertyState theirs) {
-            Tree marker = addConflictMarker(parent);
-            setProperty(getOrCreateNode(marker, DELETE_CHANGED), theirs);
-            return Resolution.THEIRS;
-        }
-
-        @Override
-        public Resolution deleteDeletedProperty(Tree parent, PropertyState ours) {
-            Tree marker = addConflictMarker(parent);
-            setProperty(getOrCreateNode(marker, DELETE_DELETED), ours);
-            return Resolution.THEIRS;
-        }
-
-        @Override
-        public Resolution addExistingNode(Tree parent, String name, NodeState ours, NodeState
theirs) {
-            Tree marker = addConflictMarker(parent);
-            addChild(getOrCreateNode(marker, ADD_EXISTING), name, ours);
-            return Resolution.THEIRS;
-        }
-
-        @Override
-        public Resolution changeDeletedNode(Tree parent, String name, NodeState ours) {
-            Tree marker = addConflictMarker(parent);
-            addChild(getOrCreateNode(marker, CHANGE_DELETED), name, ours);
-            return Resolution.THEIRS;
-        }
-
-        @Override
-        public Resolution deleteChangedNode(Tree parent, String name, NodeState theirs) {
-            Tree marker = addConflictMarker(parent);
-            markChild(getOrCreateNode(marker, DELETE_CHANGED), name);
-            return Resolution.THEIRS;
-        }
-
-        @Override
-        public Resolution deleteDeletedNode(Tree parent, String name) {
-            Tree marker = addConflictMarker(parent);
-            markChild(getOrCreateNode(marker, DELETE_DELETED), name);
-            return Resolution.THEIRS;
-        }
-
-        private Tree addConflictMarker(Tree parent) {
-            PropertyState jcrMixin = parent.getProperty(jcrMixinTypes);
-            List<CoreValue> mixins = new ArrayList<CoreValue>();
-            if (jcrMixin != null) {
-                assert jcrMixin.isArray();
-                mixins = Iterators.toList(jcrMixin.getValues(), mixins);
-            }
-            if (!mixins.contains(MIX_MERGE_CONFLICT)) {
-                mixins.add(valueFactory.createValue(MIX_MERGE_CONFLICT, PropertyType.NAME));
-                parent.setProperty(jcrMixinTypes, mixins);
-            }
-
-            return getOrCreateNode(parent, JCR_OURS);
-        }
-
-        private Tree getOrCreateNode(Tree parent, String name) {
-            Tree child = parent.getChild(name);
-            if (child == null) {
-                child = parent.addChild(name);
-            }
-            return child;
-        }
-
-        private void addChild(Tree parent, String name, NodeState state) {
-            Tree child = parent.addChild(name);
-            for (PropertyState property : state.getProperties()) {
-                setProperty(child, property);
-            }
-            for (ChildNodeEntry entry : state.getChildNodeEntries()) {
-                addChild(child, entry.getName(), entry.getNodeState());
-            }
-        }
-
-        private void markChild(Tree parent, String name) {
-            parent.addChild(name);
-        }
-
-        private void setProperty(Tree parent, PropertyState property) {
-            if (property.isArray()) {
-                parent.setProperty(property.getName(),
-                        toList(property.getValues(), new ArrayList<CoreValue>()));
-            }
-            else {
-                parent.setProperty(property.getName(), property.getValue());
-            }
-        }
-
-    }
 }



Mime
View raw message