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 md...@apache.org on 2013/11/18 17:47:04 UTC
svn commit: r1543079 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter:
EventTypeFilter.java NodeTypeFilter.java PathFilter.java UuidFilter.java
Author: mduerig
Date: Mon Nov 18 16:47:03 2013
New Revision: 1543079
URL: http://svn.apache.org/r1543079
Log:
OAK-1133: Observation listener PLUS
Add JCR specific filter implementations
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventTypeFilter.java
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/PathFilter.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidFilter.java
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventTypeFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventTypeFilter.java?rev=1543079&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventTypeFilter.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventTypeFilter.java Mon Nov 18 16:47:03 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.plugins.observation.filter;
+
+import javax.jcr.observation.Event;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.plugins.observation.filter.EventGenerator.Filter;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+/**
+ * TODO EventTypeFilter...
+ */
+public class EventTypeFilter implements Filter {
+ private final int eventTypes;
+
+ public EventTypeFilter(int eventTypes) {
+ this.eventTypes = eventTypes;
+ }
+
+ @Override
+ public boolean includeAdd(PropertyState after) {
+ return includeByEvent(Event.PROPERTY_ADDED);
+ }
+
+ @Override
+ public boolean includeChange(PropertyState before, PropertyState after) {
+ return includeByEvent(Event.PROPERTY_CHANGED);
+ }
+
+ @Override
+ public boolean includeDelete(PropertyState before) {
+ return includeByEvent(Event.PROPERTY_REMOVED);
+ }
+
+ @Override
+ public boolean includeAdd(String name, NodeState after) {
+ return includeByEvent(Event.NODE_ADDED);
+ }
+
+ @Override
+ public boolean includeDelete(String name, NodeState before) {
+ return includeByEvent(Event.NODE_REMOVED);
+ }
+
+ @Override
+ public boolean includeChange(String name, NodeState before, NodeState after) {
+ return true;
+ }
+
+ @Override
+ public boolean includeMove(String sourcePath, String destPath, NodeState moved) {
+ return includeByEvent(Event.NODE_MOVED);
+ }
+
+ @Override
+ public Filter create(String name, NodeState before, NodeState after) {
+ return this;
+ }
+
+ //------------------------------------------------------------< internal >---
+
+ private boolean includeByEvent(int eventType) {
+ return (this.eventTypes & eventType) != 0;
+ }
+
+}
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypeFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypeFilter.java?rev=1543079&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypeFilter.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypeFilter.java Mon Nov 18 16:47:03 2013
@@ -0,0 +1,105 @@
+/*
+ * 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 org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.core.ImmutableTree;
+import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
+import org.apache.jackrabbit.oak.plugins.observation.filter.EventGenerator.Filter;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+/**
+ * TODO NodeTypeFilter...
+ * TODO Clarify: filter applies to parent
+ */
+public class NodeTypeFilter implements Filter {
+ private final ImmutableTree afterTree;
+ private final ReadOnlyNodeTypeManager ntManager;
+ private final String[] ntNames;
+
+ public NodeTypeFilter(ImmutableTree afterTree, ReadOnlyNodeTypeManager ntManager, String[] ntNames) {
+ this.afterTree = afterTree;
+ this.ntManager = ntManager;
+ this.ntNames = ntNames;
+ }
+
+ @Override
+ public boolean includeAdd(PropertyState after) {
+ return includeByType();
+ }
+
+ @Override
+ public boolean includeChange(PropertyState before, PropertyState after) {
+ return includeByType();
+ }
+
+ @Override
+ public boolean includeDelete(PropertyState before) {
+ return includeByType();
+ }
+
+ @Override
+ public boolean includeAdd(String name, NodeState after) {
+ return includeByType();
+ }
+
+ @Override
+ public boolean includeChange(String name, NodeState before, NodeState after) {
+ return true;
+ }
+
+ @Override
+ public boolean includeDelete(String name, NodeState before) {
+ return includeByType();
+ }
+
+ @Override
+ public boolean includeMove(String sourcePath, String destPath, NodeState moved) {
+ return includeByType();
+ }
+
+ @Override
+ public Filter create(String name, NodeState before, NodeState after) {
+ return new NodeTypeFilter(afterTree.getChild(name), ntManager, ntNames);
+ }
+
+ //------------------------------------------------------------< private >---
+
+ /**
+ * Checks whether to include an event based on the type of the associated
+ * parent node and the node type filter.
+ *
+ * @return whether to include the event based on the type of the associated
+ * parent node.
+ */
+ private boolean includeByType() {
+ if (ntNames == null) {
+ return true;
+ } else {
+ for (String ntName : ntNames) {
+ if (ntManager.isNodeType(afterTree, ntName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+}
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PathFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PathFilter.java?rev=1543079&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PathFilter.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PathFilter.java Mon Nov 18 16:47:03 2013
@@ -0,0 +1,113 @@
+/*
+ * 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 org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.core.ImmutableTree;
+import org.apache.jackrabbit.oak.plugins.observation.filter.EventGenerator.Filter;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+/**
+ * TODO PathFilter...
+ * TODO Clarify: filter applies to parent
+ */
+public class PathFilter implements Filter {
+ private final ImmutableTree afterTree;
+ private final String path;
+ private final boolean deep;
+
+ public PathFilter(ImmutableTree afterTree, String path, boolean deep) {
+ this.afterTree = afterTree;
+ this.path = path;
+ this.deep = deep;
+ }
+
+ @Override
+ public boolean includeAdd(PropertyState after) {
+ return includeByPath(afterTree.getPath());
+ }
+
+ @Override
+ public boolean includeChange(PropertyState before, PropertyState after) {
+ return includeByPath(afterTree.getPath());
+ }
+
+ @Override
+ public boolean includeDelete(PropertyState before) {
+ return includeByPath(afterTree.getPath());
+ }
+
+ @Override
+ public boolean includeAdd(String name, NodeState after) {
+ return includeByPath(afterTree.getPath());
+ }
+
+ @Override
+ public boolean includeChange(String name, NodeState before, NodeState after) {
+ return includeByPath(afterTree.getPath());
+ }
+
+ @Override
+ public boolean includeDelete(String name, NodeState before) {
+ return includeByPath(afterTree.getPath());
+ }
+
+ @Override
+ public boolean includeMove(String sourcePath, String destPath, NodeState moved) {
+ return includeByPath(afterTree.getPath());
+ }
+
+ @Override
+ public Filter create(String name, NodeState before, NodeState after) {
+ if (includeChildren(afterTree.getPath())) {
+ return new PathFilter(afterTree.getChild(name), path, deep);
+ } else {
+ return null;
+ }
+ }
+
+ //------------------------------------------------------------< private >---
+
+ private boolean includeByPath(String path) {
+ boolean equalPaths = this.path.equals(path);
+ if (!deep && !equalPaths) {
+ return false;
+ }
+
+ if (deep && !(PathUtils.isAncestor(this.path, path) || equalPaths)) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Determine whether the children of a {@code path} would be matched by this filter
+ * @param path path whose children to test
+ * @return {@code true} if the children of {@code path} could be matched by this filter
+ */
+ public boolean includeChildren(String path) {
+ return PathUtils.isAncestor(path, this.path) ||
+ path.equals((this.path)) ||
+ deep && PathUtils.isAncestor(this.path, path);
+ }
+
+
+}
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidFilter.java?rev=1543079&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidFilter.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidFilter.java Mon Nov 18 16:47:03 2013
@@ -0,0 +1,105 @@
+/*
+ * 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 org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.observation.filter.EventGenerator.Filter;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+/**
+ * TODO UuidFilter
+ * TODO Clarify: filter applies to parent
+ */
+public class UuidFilter implements Filter {
+ private final NodeState after;
+ private final String[] uuids;
+
+ public UuidFilter(NodeState after, String[] uuids) {
+ this.after = after;
+ this.uuids = uuids;
+ }
+
+ @Override
+ public boolean includeAdd(PropertyState after) {
+ return includeByUuid();
+ }
+
+ @Override
+ public boolean includeChange(PropertyState before, PropertyState after) {
+ return includeByUuid();
+ }
+
+ @Override
+ public boolean includeDelete(PropertyState before) {
+ return includeByUuid();
+ }
+
+ @Override
+ public boolean includeAdd(String name, NodeState after) {
+ return includeByUuid();
+ }
+
+ @Override
+ public boolean includeChange(String name, NodeState before, NodeState after) {
+ return true;
+ }
+
+ @Override
+ public boolean includeDelete(String name, NodeState before) {
+ return includeByUuid();
+ }
+
+ @Override
+ public boolean includeMove(String sourcePath, String destPath, NodeState moved) {
+ return includeByUuid();
+ }
+
+ @Override
+ public Filter create(String name, NodeState before, NodeState after) {
+ return new UuidFilter(after, uuids);
+ }
+
+ //------------------------------------------------------------< private >---
+
+ private boolean includeByUuid() {
+ if (uuids == null) {
+ return true;
+ }
+ if (uuids.length == 0) {
+ return false;
+ }
+
+ PropertyState uuidProperty = after.getProperty(JcrConstants.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;
+ }
+
+}