Author: jukka Date: Mon Mar 18 15:02:29 2013 New Revision: 1457791 URL: http://svn.apache.org/r1457791 Log: OAK-673: Unified hook processing
Add enter/leave methods in Editor to allow pre-/postprocessing of changes before/after the content diff Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RegistrationValidator.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidator.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionStoreValidatorProvider.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidator.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidator.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultEditor.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidator.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/Editor.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorHook.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/FailingValidator.java 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/plugins/name/NameValidator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java Mon Mar 18 15:02:29 2013 @@ -20,6 +20,7 @@ import java.util.Set; import org.apache.jackrabbit.oak.api.CommitFailedException; 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; @@ -29,7 +30,7 @@ import static org.apache.jackrabbit.oak. /** * TODO document */ -class NameValidator implements Validator { +class NameValidator extends DefaultValidator { private final Set<String> prefixes; Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RegistrationValidator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RegistrationValidator.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RegistrationValidator.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RegistrationValidator.java Mon Mar 18 15:02:29 2013 @@ -23,6 +23,7 @@ import org.apache.jackrabbit.oak.api.Com import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.core.ReadOnlyTree; import org.apache.jackrabbit.oak.plugins.name.NamespaceConstants; +import org.apache.jackrabbit.oak.spi.commit.DefaultValidator; import org.apache.jackrabbit.oak.spi.commit.Validator; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.apache.jackrabbit.oak.util.NodeUtil; @@ -40,7 +41,7 @@ import org.apache.jackrabbit.util.Text; * <li>prevent un-registration of built-in node types.</li> * </ul> */ -class RegistrationValidator implements Validator { +class RegistrationValidator extends DefaultValidator { private final ReadOnlyNodeTypeManager beforeMgr; private final ReadOnlyNodeTypeManager afterMgr; Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java Mon Mar 18 15:02:29 2013 @@ -26,6 +26,7 @@ import org.apache.jackrabbit.oak.api.Com import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.core.ReadOnlyTree; import org.apache.jackrabbit.oak.namepath.NamePathMapper; +import org.apache.jackrabbit.oak.spi.commit.DefaultValidator; import org.apache.jackrabbit.oak.spi.commit.Validator; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.apache.jackrabbit.oak.spi.state.NodeStateUtils; @@ -46,7 +47,7 @@ import static org.apache.jackrabbit.oak. * cannot and should not check whether the value of the protected jcr:uuid * is unique. */ -class TypeValidator implements Validator { +class TypeValidator extends DefaultValidator { private static final Logger log = LoggerFactory.getLogger(TypeValidator.class); private final ReadOnlyNodeTypeManager ntm; Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidator.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidator.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidator.java Mon Mar 18 15:02:29 2013 @@ -29,6 +29,7 @@ import org.apache.jackrabbit.oak.api.Pro import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.core.TreeImpl; import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager; +import org.apache.jackrabbit.oak.spi.commit.DefaultValidator; import org.apache.jackrabbit.oak.spi.commit.Validator; import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider; import org.apache.jackrabbit.oak.spi.state.NodeState; @@ -40,7 +41,7 @@ import static com.google.common.base.Pre /** * AccessControlValidator... TODO */ -class AccessControlValidator implements Validator, AccessControlConstants { +class AccessControlValidator extends DefaultValidator implements AccessControlConstants { private final Tree parentBefore; private final Tree parentAfter; Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionStoreValidatorProvider.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionStoreValidatorProvider.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionStoreValidatorProvider.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionStoreValidatorProvider.java Mon Mar 18 15:02:29 2013 @@ -18,8 +18,7 @@ package org.apache.jackrabbit.oak.securi import javax.annotation.Nonnull; -import org.apache.jackrabbit.oak.api.CommitFailedException; -import org.apache.jackrabbit.oak.api.PropertyState; +import org.apache.jackrabbit.oak.spi.commit.FailingValidator; import org.apache.jackrabbit.oak.spi.commit.SubtreeValidator; import org.apache.jackrabbit.oak.spi.commit.Validator; import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider; @@ -33,41 +32,9 @@ public class PermissionStoreValidatorPro @Nonnull @Override public Validator getRootValidator(NodeState before, NodeState after) { - return new SubtreeValidator(new PermissionStoreValidator(), PERMISSIONS_STORE_PATH); + FailingValidator validator = + new FailingValidator("Attempt to modify permission store."); + return new SubtreeValidator(validator, PERMISSIONS_STORE_PATH); } - private final static class PermissionStoreValidator implements Validator { - - private static final String errorMsg = "Attempt to modify permission store."; - - @Override - public void propertyAdded(PropertyState after) throws CommitFailedException { - throw new CommitFailedException(errorMsg); - } - - @Override - public void propertyChanged(PropertyState before, PropertyState after) throws CommitFailedException { - throw new CommitFailedException(errorMsg); - } - - @Override - public void propertyDeleted(PropertyState before) throws CommitFailedException { - throw new CommitFailedException(errorMsg); - } - - @Override - public Validator childNodeAdded(String name, NodeState after) throws CommitFailedException { - throw new CommitFailedException(errorMsg); - } - - @Override - public Validator childNodeChanged(String name, NodeState before, NodeState after) throws CommitFailedException { - throw new CommitFailedException(errorMsg); - } - - @Override - public Validator childNodeDeleted(String name, NodeState before) throws CommitFailedException { - throw new CommitFailedException(errorMsg); - } - } } Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidator.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidator.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidator.java Mon Mar 18 15:02:29 2013 @@ -27,6 +27,7 @@ import org.apache.jackrabbit.oak.api.Pro import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.core.TreeImpl; import org.apache.jackrabbit.oak.plugins.version.VersionConstants; +import org.apache.jackrabbit.oak.spi.commit.DefaultValidator; import org.apache.jackrabbit.oak.spi.commit.Validator; import org.apache.jackrabbit.oak.spi.security.authorization.PermissionProvider; import org.apache.jackrabbit.oak.spi.security.authorization.Permissions; @@ -40,7 +41,7 @@ import static com.google.common.base.Pre * Validator implementation that checks for sufficient permission for all * write operations executed by a given content session. */ -class PermissionValidator implements Validator { +class PermissionValidator extends DefaultValidator { /* TODO * - Renaming nodes or Move with same parent are reflected as remove+add -> needs special handling Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidator.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidator.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidator.java Mon Mar 18 15:02:29 2013 @@ -29,6 +29,7 @@ import org.apache.jackrabbit.oak.api.Tre import org.apache.jackrabbit.oak.core.ImmutableRoot; import org.apache.jackrabbit.oak.core.ImmutableTree; import org.apache.jackrabbit.oak.plugins.name.NamespaceConstants; +import org.apache.jackrabbit.oak.spi.commit.DefaultValidator; import org.apache.jackrabbit.oak.spi.commit.Validator; import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition; import org.apache.jackrabbit.oak.spi.state.NodeState; @@ -39,7 +40,7 @@ import org.apache.jackrabbit.util.Text; * Validator implementation that is responsible for validating any modifications * made to privileges stored in the repository. */ -class PrivilegeValidator implements PrivilegeConstants, Validator { +class PrivilegeValidator extends DefaultValidator implements PrivilegeConstants { private final Root rootBefore; private final Root rootAfter; Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java Mon Mar 18 15:02:29 2013 @@ -60,6 +60,23 @@ public class CompositeEditor implements } @Override + public void enter(NodeState before, NodeState after) + throws CommitFailedException { + for (Editor editor : editors) { + editor.enter(before, after); + } + } + + @Override + public void leave(NodeState before, NodeState after) + throws CommitFailedException { + for (Editor editor : editors) { + editor.leave(before, after); + } + } + + + @Override public void propertyAdded(PropertyState after) throws CommitFailedException { for (Editor editor : editors) { Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultEditor.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultEditor.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultEditor.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultEditor.java Mon Mar 18 15:02:29 2013 @@ -31,6 +31,18 @@ public class DefaultEditor implements Ed public static final Editor INSTANCE = new DefaultEditor(); @Override + public void enter(NodeState before, NodeState after) + throws CommitFailedException { + // do nothing + } + + @Override + public void leave(NodeState before, NodeState after) + throws CommitFailedException { + // do nothing + } + + @Override public void propertyAdded(PropertyState after) throws CommitFailedException { // do nothing Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidator.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidator.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidator.java Mon Mar 18 15:02:29 2013 @@ -31,6 +31,18 @@ public class DefaultValidator implements public static final Validator INSTANCE = new DefaultValidator(); @Override + public void enter(NodeState before, NodeState after) + throws CommitFailedException { + // do nothing + } + + @Override + public void leave(NodeState before, NodeState after) + throws CommitFailedException { + // do nothing + } + + @Override public void propertyAdded(PropertyState after) throws CommitFailedException { // do nothing Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/Editor.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/Editor.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/Editor.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/Editor.java Mon Mar 18 15:02:29 2013 @@ -36,6 +36,10 @@ import javax.annotation.CheckForNull; */ public interface Editor { + void enter(NodeState before, NodeState after) throws CommitFailedException; + + void leave(NodeState before, NodeState after) throws CommitFailedException; + /** * Processes an added property. * Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorHook.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorHook.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorHook.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorHook.java Mon Mar 18 15:02:29 2013 @@ -77,8 +77,7 @@ public class EditorHook implements Commi checkNotNull(after); if (editor != null) { EditorDiff diff = new EditorDiff(editor); - after.compareAgainstBaseState(before, diff); - return diff.exception; + return diff.process(before, after); } else { return null; } @@ -99,6 +98,28 @@ public class EditorHook implements Commi this.editor = editor; } + public CommitFailedException process( + NodeState before, NodeState after) { + try { + editor.enter(before, after); + } catch (CommitFailedException e) { + return e; + } + + after.compareAgainstBaseState(before, this); + if (exception != null) { + return exception; + } + + try { + editor.leave(before, after); + } catch (CommitFailedException e) { + return e; + } + + return null; + } + //-------------------------------------------------< NodeStateDiff >-- @Override @@ -139,7 +160,7 @@ public class EditorHook implements Commi if (exception == null) { try { Editor e = editor.childNodeAdded(name, after); - exception = process(e, EMPTY_NODE, after); + exception = EditorHook.process(e, EMPTY_NODE, after); } catch (CommitFailedException e) { exception = e; } @@ -152,7 +173,7 @@ public class EditorHook implements Commi if (exception == null) { try { Editor e = editor.childNodeChanged(name, before, after); - exception = process(e, before, after); + exception = EditorHook.process(e, before, after); } catch (CommitFailedException e) { exception = e; } @@ -164,7 +185,7 @@ public class EditorHook implements Commi if (exception == null) { try { Editor e = editor.childNodeDeleted(name, before); - exception = process(e, before, EMPTY_NODE); + exception = EditorHook.process(e, before, EMPTY_NODE); } catch (CommitFailedException e) { exception = e; } Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/FailingValidator.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/FailingValidator.java?rev=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/FailingValidator.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/FailingValidator.java Mon Mar 18 15:02:29 2013 @@ -39,6 +39,18 @@ public class FailingValidator implements } @Override + public void enter(NodeState before, NodeState after) + throws CommitFailedException { + throw new CommitFailedException(message); + } + + @Override + public void leave(NodeState before, NodeState after) + throws CommitFailedException { + throw new CommitFailedException(message); + } + + @Override public void propertyAdded(PropertyState after) throws CommitFailedException { throw new CommitFailedException(message); Modified: 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=1457791&r1=1457790&r2=1457791&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/VisibleEditor.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/VisibleEditor.java Mon Mar 18 15:02:29 2013 @@ -31,7 +31,7 @@ import org.apache.jackrabbit.oak.spi.sta * * @since Oak 0.7 */ -public class VisibleEditor implements Editor { +public class VisibleEditor extends DefaultEditor { @CheckForNull public static Editor wrap(@CheckForNull Editor editor) {