jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1546983 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation: JcrFilterProvider.java filter/NodeTypeFilter.java filter/NodeTypePredicate.java filter/UuidFilter.java filter/UuidPredicate.java
Date Mon, 02 Dec 2013 12:41:55 GMT
Author: mduerig
Date: Mon Dec  2 12:41:54 2013
New Revision: 1546983

URL: http://svn.apache.org/r1546983
Log:
OAK-1133: Observation listener PLUS
Replace NodeTypeFilter and UuidFilter with UniversalFilter and respective predicate implementations

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypePredicate.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidPredicate.java
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypeFilter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidFilter.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/JcrFilterProvider.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/JcrFilterProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/JcrFilterProvider.java?rev=1546983&r1=1546982&r2=1546983&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/JcrFilterProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/JcrFilterProvider.java
Mon Dec  2 12:41:54 2013
@@ -43,8 +43,10 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider;
 import org.apache.jackrabbit.oak.plugins.observation.filter.Filters;
 import org.apache.jackrabbit.oak.plugins.observation.filter.GlobbingPathFilter;
-import org.apache.jackrabbit.oak.plugins.observation.filter.NodeTypeFilter;
-import org.apache.jackrabbit.oak.plugins.observation.filter.UuidFilter;
+import org.apache.jackrabbit.oak.plugins.observation.filter.NodeTypePredicate;
+import org.apache.jackrabbit.oak.plugins.observation.filter.Selectors;
+import org.apache.jackrabbit.oak.plugins.observation.filter.UniversalFilter;
+import org.apache.jackrabbit.oak.plugins.observation.filter.UuidPredicate;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider;
 import org.apache.jackrabbit.oak.spi.security.authorization.permission.TreePermission;
@@ -125,8 +127,8 @@ public class JcrFilterProvider implement
             if (uuids.length == 0) {
                 return Filters.excludeAll();
             } else {
-                filters.add(new UuidFilter(
-                        beforeTree.getNodeState(), afterTree.getNodeState(), uuids));
+                filters.add(new UniversalFilter(beforeTree, afterTree,
+                        Selectors.PARENT, new UuidPredicate(uuids)));
             }
         }
 
@@ -134,7 +136,8 @@ public class JcrFilterProvider implement
             if (ntNames.length == 0) {
                 return Filters.excludeAll();
             } else {
-                filters.add(new NodeTypeFilter(beforeTree, afterTree, ntManager, ntNames));
+                filters.add(new UniversalFilter(beforeTree, afterTree,
+                        Selectors.PARENT, new NodeTypePredicate(ntManager, ntNames)));
             }
         }
 

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypePredicate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypePredicate.java?rev=1546983&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypePredicate.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypePredicate.java
Mon Dec  2 12:41:54 2013
@@ -0,0 +1,60 @@
+/*
+ * 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.observation.filter;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import javax.annotation.Nonnull;
+
+import com.google.common.base.Predicate;
+import org.apache.jackrabbit.oak.core.ImmutableTree;
+import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
+
+/**
+ * A predicate for matching against a list of node types. This predicate
+ * holds whenever the tree passed to its apply functions is of the node type
+ * of any of the node types whose names has been passed to the predicate's
+ * constructor.
+ */
+public class NodeTypePredicate implements Predicate<ImmutableTree> {
+    private final ReadOnlyNodeTypeManager ntManager;
+    private final String[] ntNames;
+
+    /**
+     * @param ntManager  node type manager for determining whether the node types of {@code
Tree}s
+     * @param ntNames    names of node types
+     */
+    public NodeTypePredicate(
+            @Nonnull ReadOnlyNodeTypeManager ntManager,
+            @Nonnull String[] ntNames) {
+        this.ntManager = checkNotNull(ntManager);
+        this.ntNames = checkNotNull(ntNames);
+    }
+
+    @Override
+    public boolean apply(ImmutableTree tree) {
+        for (String ntName : ntNames) {
+            if (ntManager.isNodeType(tree, ntName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+}

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidPredicate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidPredicate.java?rev=1546983&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidPredicate.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidPredicate.java
Mon Dec  2 12:41:54 2013
@@ -0,0 +1,67 @@
+/*
+ * 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.observation.filter;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
+
+import javax.annotation.Nonnull;
+
+import com.google.common.base.Predicate;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.core.ImmutableTree;
+
+/**
+ * A predicate for matching against a list of UUIDs. This predicate holds
+ * whenever the tree passed to its apply functions has a {@code jcr:uuid}
+ * property and the value of that property matches any of the UUIDs that
+ * has been passed to the predicate's constructor.
+ */
+public class UuidPredicate implements Predicate<ImmutableTree> {
+    private final String[] uuids;
+
+    /**
+     * @param uuids    uuids
+     */
+    public UuidPredicate(@Nonnull String[] uuids) {
+        this.uuids = checkNotNull(uuids);
+    }
+
+    @Override
+    public boolean apply(ImmutableTree tree) {
+        if (uuids.length == 0) {
+            return false;
+        }
+
+        PropertyState uuidProperty = tree.getProperty(JCR_UUID);
+        if (uuidProperty == null) {
+            return false;
+        }
+
+        String parentUuid = uuidProperty.getValue(Type.STRING);
+        for (String uuid : uuids) {
+            if (parentUuid.equals(uuid)) {
+                return true;
+            }
+        }
+        return false;
+    }
+}



Mime
View raw message