jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1454482 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/SubtreeEditor.java
Date Fri, 08 Mar 2013 18:17:59 GMT
Author: jukka
Date: Fri Mar  8 18:17:59 2013
New Revision: 1454482

URL: http://svn.apache.org/r1454482
Log:
OAK-673: Unified hook processing

Add a SubtreeEditor wrapper for editors that are only interested in changes to a particular
subtree

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/SubtreeEditor.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/SubtreeEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/SubtreeEditor.java?rev=1454482&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/SubtreeEditor.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/SubtreeEditor.java
Fri Mar  8 18:17:59 2013
@@ -0,0 +1,84 @@
+/*
+ * 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.spi.commit;
+
+import static com.google.common.base.Preconditions.checkElementIndex;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import javax.annotation.CheckForNull;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+public class SubtreeEditor implements Editor {
+
+    private final Editor editor;
+
+    private final String[] path;
+
+    private final int depth;
+
+    private SubtreeEditor(Editor editor, String[] path, int depth) {
+        this.editor = checkNotNull(editor);
+        this.path = checkNotNull(path);
+        checkElementIndex(depth, path.length);
+        this.depth = depth;
+    }
+
+    public SubtreeEditor(Editor editor, String... path) {
+        this(editor, path, 0);
+    }
+
+    private Editor descend(String name) {
+        if (!name.equals(path[depth])) {
+            return null;
+        } else if (depth + 1 < path.length) {
+            return new SubtreeEditor(editor, path, depth + 1);
+        } else {
+            return editor;
+        }
+    }
+
+    @Override
+    public void propertyAdded(PropertyState after) {
+    }
+
+    @Override
+    public void propertyChanged(PropertyState before, PropertyState after) {
+    }
+
+    @Override
+    public void propertyDeleted(PropertyState before) {
+    }
+
+    @Override @CheckForNull
+    public Editor childNodeAdded(String name, NodeState after) {
+        return descend(name);
+    }
+
+    @Override @CheckForNull
+    public Editor childNodeChanged(
+            String name, NodeState before, NodeState after) {
+        return descend(name);
+    }
+
+    @Override @CheckForNull
+    public Editor childNodeDeleted(String name, NodeState before) {
+        return descend(name);
+    }
+
+}



Mime
View raw message