You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ju...@apache.org on 2013/03/08 19:28:35 UTC

svn commit: r1454486 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit: SubtreeEditor.java VisibleEditor.java

Author: jukka
Date: Fri Mar  8 18:28:35 2013
New Revision: 1454486

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

Add VisibleEditor to help reduce the number of isHidden() conditionals spread across the codebase

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

Modified: 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=1454486&r1=1454485&r2=1454486&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/SubtreeEditor.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/SubtreeEditor.java Fri Mar  8 18:28:35 2013
@@ -23,6 +23,12 @@ import javax.annotation.CheckForNull;
 
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
+/**
+ * Editor wrapper that passes only changes in the specified subtree to
+ * the given delegate editor.
+ *
+ * @since Oak 0.7
+ */
 public class SubtreeEditor extends DefaultEditor {
 
     private final Editor editor;

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/VisibleEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/VisibleEditor.java?rev=1454486&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/VisibleEditor.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/VisibleEditor.java Fri Mar  8 18:28:35 2013
@@ -0,0 +1,109 @@
+/*
+ * 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.checkNotNull;
+
+import javax.annotation.CheckForNull;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+/**
+ * Editor wrapper that passes only changes to non-hidden nodes and properties
+ * (i.e. ones whose names don't start with a colon) to the given delegate
+ * editor.
+ *
+ * @since Oak 0.7
+ */
+public class VisibleEditor implements Editor {
+
+    @CheckForNull
+    public static Editor wrap(@CheckForNull Editor editor) {
+        if (editor != null) {
+            return new VisibleEditor(editor);
+        } else {
+            return null;
+        }
+    }
+
+    private final Editor editor;
+
+    public VisibleEditor(Editor editor) {
+        this.editor = checkNotNull(editor);
+    }
+
+    private boolean isVisible(String name) {
+        return name.charAt(0) != ':';
+    }
+
+    @Override
+    public void propertyAdded(PropertyState after) throws CommitFailedException {
+        if (isVisible(after.getName())) {
+            editor.propertyAdded(after);
+        }
+    }
+
+    @Override
+    public void propertyChanged(PropertyState before, PropertyState after)
+            throws CommitFailedException {
+        if (isVisible(after.getName())) {
+            editor.propertyChanged(before, after);
+        }
+    }
+
+    @Override
+    public void propertyDeleted(PropertyState before)
+            throws CommitFailedException {
+        if (isVisible(before.getName())) {
+            editor.propertyDeleted(before);
+        }
+    }
+
+    @Override @CheckForNull
+    public Editor childNodeAdded(String name, NodeState after)
+            throws CommitFailedException {
+        if (isVisible(name)) {
+            return wrap(editor.childNodeAdded(name, after));
+        } else {
+            return null;
+        }
+    }
+
+    @Override @CheckForNull
+    public Editor childNodeChanged(
+            String name, NodeState before, NodeState after)
+            throws CommitFailedException {
+        if (isVisible(name)) {
+            return wrap(editor.childNodeChanged(name, before, after));
+        } else {
+            return null;
+        }
+    }
+
+    @Override @CheckForNull
+    public Editor childNodeDeleted(String name, NodeState before)
+            throws CommitFailedException {
+        if (isVisible(name)) {
+            return wrap(editor.childNodeDeleted(name, before));
+        } else {
+            return null;
+        }
+    }
+
+}