Author: mduerig
Date: Thu May 31 08:18:26 2012
New Revision: 1344592
URL: http://svn.apache.org/viewvc?rev=1344592&view=rev
Log:
OAK-68 - Extension point for commit validation
Add composite variants for CommitHook, Validator and ValidatorProvider
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeCommitHook.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidator.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeCommitHook.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeCommitHook.java?rev=1344592&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeCommitHook.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeCommitHook.java
Thu May 31 08:18:26 2012
@@ -0,0 +1,53 @@
+/*
+ * 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 org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+import java.util.List;
+
+public class CompositeCommitHook implements CommitHook {
+ private final List<CommitHook> hooks;
+
+ public CompositeCommitHook(List<CommitHook> hooks) {
+ this.hooks = hooks;
+ }
+
+ @Override
+ public NodeState beforeCommit(NodeStore store, NodeState before, NodeState
after)
+ throws CommitFailedException {
+
+ NodeState oldState = before;
+ NodeState newState = after;
+ for (CommitHook hook : hooks) {
+ NodeState newOldState = newState;
+ newState = hook.beforeCommit(store, oldState, newState);
+ oldState = newOldState;
+ }
+
+ return newState;
+ }
+
+ @Override
+ public void afterCommit(NodeStore store, NodeState before, NodeState
after) {
+ for (CommitHook hook : hooks) {
+ hook.afterCommit(store, before, after);
+ }
+ }
+}
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidator.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidator.java?rev=1344592&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidator.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidator.java
Thu May 31 08:18:26 2012
@@ -0,0 +1,82 @@
+/*
+ * 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 org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CompositeValidator implements Validator {
+ private final List<Validator> validators;
+
+ public CompositeValidator(List<Validator> validators) {
+ this.validators = validators;
+ }
+
+ @Override
+ public void propertyAdded(PropertyState after) throws
CommitFailedException {
+ for (Validator validator : validators) {
+ validator.propertyAdded(after);
+ }
+ }
+
+ @Override
+ public void propertyChanged(PropertyState before, PropertyState after)
+ throws CommitFailedException {
+
+ for (Validator validator : validators) {
+ validator.propertyChanged(before, after);
+ }
+ }
+
+ @Override
+ public void propertyDeleted(PropertyState before) throws
CommitFailedException {
+ for (Validator validator : validators) {
+ validator.propertyDeleted(before);
+ }
+ }
+
+ @Override
+ public Validator childNodeAdded(String name, NodeState after) throws
CommitFailedException {
+ List<Validator> childValidators = new
ArrayList<Validator>(validators.size());
+ for (Validator validator : validators) {
+ childValidators.add(
+ validator.childNodeAdded(name, after));
+ }
+ return new CompositeValidator(childValidators);
+ }
+
+ @Override
+ public Validator childNodeChanged(String name, NodeState before, NodeState
after) throws CommitFailedException {
+ List<Validator> childValidators = new
ArrayList<Validator>(validators.size());
+ for (Validator validator : validators) {
+ childValidators.add(
+ validator.childNodeChanged(name, before, after));
+ }
+ return new CompositeValidator(childValidators);
+ }
+
+ @Override
+ public void childNodeDeleted(String name, NodeState before) throws
CommitFailedException {
+ for (Validator validator : validators) {
+ validator.childNodeDeleted(name, before);
+ }
+ }
+}
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java?rev=1344592&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java
Thu May 31 08:18:26 2012
@@ -0,0 +1,42 @@
+/*
+ * 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 org.apache.jackrabbit.oak.spi.state.NodeState;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CompositeValidatorProvider implements ValidatorProvider {
+ private final List<ValidatorProvider> providers;
+
+ public CompositeValidatorProvider(List<ValidatorProvider> providers) {
+ this.providers = providers;
+ }
+
+ @Override
+ public Validator getRootValidator(NodeState before, NodeState after) {
+ List<Validator> rootValidators = new
ArrayList<Validator>(providers.size());
+
+ for (ValidatorProvider provider : providers) {
+ rootValidators.add(provider.getRootValidator(before, after));
+ }
+
+ return new CompositeValidator(rootValidators);
+ }
+
+}