Author: angela
Date: Wed Oct 31 09:24:52 2012
New Revision: 1404049
URL: http://svn.apache.org/viewvc?rev=1404049&view=rev
Log:
OAK-411 : Validator for node type management (wip)
- add RegistrationValidator that is responsible for validating changes made to
node type definitions
- add the provider to the default set (JCR.java and Main.java)
- resolve TODO in ReadWriteNodeTypeManager
Added:
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/RegistrationValidatorProvider.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ValidatingNodeTypeManager.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadWriteNodeTypeManager.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidatorProvider.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadWriteNodeTypeManager.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadWriteNodeTypeManager.java?rev=1404049&r1=1404048&r2=1404049&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadWriteNodeTypeManager.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadWriteNodeTypeManager.java
Wed Oct 31 09:24:52 2012
@@ -354,13 +354,6 @@ public abstract class ReadWriteNodeTypeM
@Override
public void unregisterNodeType(String name) throws RepositoryException {
- // TODO: review again. added to make tck happy. (see also OAK-411)
- // TODO before refactoring the type-validation removing nt:based fail
with
- // TODO IllegalStateException: Inconsistent node type:
org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeImpl@55ab3cda
- if (NT_BASE.equals(name)) {
- throw new RepositoryException("nt:base cannot be removed.");
- }
-
Tree type = null;
Root root = getWriteRoot();
Tree types = root.getTree(NODE_TYPES_PATH);
@@ -390,13 +383,6 @@ public abstract class ReadWriteNodeTypeM
try {
for (String name : names) {
- // TODO: review again. added to make tck happy. (see also
OAK-411)
- // TODO before refactoring the type-validation removing
nt:based fail with
- // TODO IllegalStateException: Inconsistent node type:
org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeImpl@55ab3cda
- if (NT_BASE.equals(name)) {
- throw new RepositoryException("nt:base cannot be
removed.");
- }
-
Tree type = types.getChild(getOakName(name));
if (type == null) {
throw new NoSuchNodeTypeException("Node type " + name + "
can not be unregistered.");
Added:
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=1404049&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RegistrationValidator.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RegistrationValidator.java
Wed Oct 31 09:24:52 2012
@@ -0,0 +1,106 @@
+/*
+ * 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.nodetype;
+
+import javax.jcr.nodetype.ConstraintViolationException;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+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.Validator;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.apache.jackrabbit.util.Text;
+
+/**
+ * Validator implementation that is responsible for validating any modification
+ * made to node type definitions. This includes:
+ *
+ * <ul>
+ * <li>validate new definitions</li>
+ * <li>detect collisions,</li>
+ * <li>prevent circular inheritance,</li>
+ * <li>reject modifications to definitions that render existing content
invalid,</li>
+ * <li>prevent un-registration of built-in node types.</li>
+ * </ul>
+ */
+class RegistrationValidator implements Validator {
+
+ private final ReadOnlyNodeTypeManager beforeMgr;
+ private final ReadOnlyNodeTypeManager afterMgr;
+
+ private final ReadOnlyTree parentBefore;
+ private final ReadOnlyTree parentAfter;
+
+ RegistrationValidator(ReadOnlyNodeTypeManager beforeMgr,
ReadOnlyNodeTypeManager afterMgr,
+ ReadOnlyTree parentBefore, ReadOnlyTree parentAfter)
{
+ this.beforeMgr = beforeMgr;
+ this.afterMgr = afterMgr;
+ this.parentBefore = parentBefore;
+ this.parentAfter = parentAfter;
+ }
+
+ //----------------------------------------------------------< Validator
>---
+ @Override
+ public void propertyAdded(PropertyState after) throws
CommitFailedException {
+ // TODO
+ }
+
+ @Override
+ public void propertyChanged(PropertyState before, PropertyState after)
throws CommitFailedException {
+ // TODO
+ }
+
+ @Override
+ public void propertyDeleted(PropertyState before) throws
CommitFailedException {
+ // TODO
+ }
+
+ @Override
+ public Validator childNodeAdded(String name, NodeState after) throws
CommitFailedException {
+ // TODO
+ return null;
+ }
+
+ @Override
+ public Validator childNodeChanged(String name, NodeState before, NodeState
after) throws CommitFailedException {
+ // TODO
+ return null;
+ }
+
+ @Override
+ public Validator childNodeDeleted(String name, NodeState before) throws
CommitFailedException {
+ NodeUtil nodeBefore = new NodeUtil(new ReadOnlyTree(parentBefore,
name, before));
+ if (nodeBefore.hasPrimaryNodeTypeName(JcrConstants.NT_NODETYPE)) {
+ if (isBuiltInNodeType(name)) {
+ throw new CommitFailedException(new
ConstraintViolationException("Attempt to unregister a built-in node type"));
+ }
+ }
+ // TODO
+ return null;
+ }
+
+ //------------------------------------------------------------< private
>---
+
+ private static boolean isBuiltInNodeType(String name) {
+ // cheap way to determine if a given node type should be considered
built-in
+ String prefix = Text.getNamespacePrefix(name);
+ return NamespaceConstants.RESERVED_PREFIXES.contains(prefix);
+ }
+}
\ No newline at end of file
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RegistrationValidatorProvider.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RegistrationValidatorProvider.java?rev=1404049&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RegistrationValidatorProvider.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RegistrationValidatorProvider.java
Wed Oct 31 09:24:52 2012
@@ -0,0 +1,44 @@
+/*
+ * 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.nodetype;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.oak.core.ReadOnlyTree;
+import org.apache.jackrabbit.oak.spi.commit.SubtreeValidator;
+import org.apache.jackrabbit.oak.spi.commit.Validator;
+import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+/**
+ * ValidationProvider implementation that returns a {@code SubtreeValidator}
+ * that is looking for changes made to /jcr:system/jcr:nodeTypes and
+ * is responsible for making sure that any modifications made to node type
+ * definitions are valid.
+ */
+public class RegistrationValidatorProvider implements ValidatorProvider {
+
+ @Nonnull
+ @Override
+ public Validator getRootValidator(NodeState before, NodeState after) {
+ Validator validator = new RegistrationValidator(new
ValidatingNodeTypeManager(before),
+ new ValidatingNodeTypeManager(after),
+ new ReadOnlyTree(before), new ReadOnlyTree(after));
+ return new SubtreeValidator(validator, JcrConstants.JCR_SYSTEM,
NodeTypeConstants.JCR_NODE_TYPES);
+ }
+}
\ No newline at end of file
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidatorProvider.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidatorProvider.java?rev=1404049&r1=1404048&r2=1404049&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidatorProvider.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidatorProvider.java
Wed Oct 31 09:24:52 2012
@@ -18,8 +18,6 @@ package org.apache.jackrabbit.oak.plugin
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
-import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.core.ReadOnlyTree;
import org.apache.jackrabbit.oak.namepath.NameMapperImpl;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -28,39 +26,16 @@ import org.apache.jackrabbit.oak.spi.com
import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
import org.apache.jackrabbit.oak.spi.state.NodeState;
-import static
org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
-
@Component
@Service(ValidatorProvider.class)
public class TypeValidatorProvider implements ValidatorProvider {
@Override
public Validator getRootValidator(NodeState before, final NodeState after)
{
- ReadOnlyNodeTypeManager ntm = new ReadOnlyNodeTypeManager() {
- private final Tree types = getTypes(after);
-
- @Override
- protected Tree getTypes() {
- return types;
- }
-
- private Tree getTypes(NodeState after) {
- Tree tree = new ReadOnlyTree(after);
- for (String name : PathUtils.elements(NODE_TYPES_PATH)) {
- if (tree == null) {
- break;
- }
- else {
- tree = tree.getChild(name);
- }
- }
- return tree;
- }
- };
-
- Tree root = new ReadOnlyTree(after);
+ ReadOnlyNodeTypeManager ntm = new ValidatingNodeTypeManager(after);
+ ReadOnlyTree root = new ReadOnlyTree(after);
final NamePathMapper mapper = new NamePathMapperImpl(new
NameMapperImpl(root));
- return new TypeValidator(ntm, new ReadOnlyTree(after), mapper);
+ return new TypeValidator(ntm, root, mapper);
}
}
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ValidatingNodeTypeManager.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ValidatingNodeTypeManager.java?rev=1404049&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ValidatingNodeTypeManager.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ValidatingNodeTypeManager.java
Wed Oct 31 09:24:52 2012
@@ -0,0 +1,61 @@
+/*
+ * 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.nodetype;
+
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.core.ReadOnlyTree;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static
org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
+
+/**
+ * NodeTypeManager implementation based on a given {@code NodeState} in order
+ * to be used for the various node type related validators.
+ */
+class ValidatingNodeTypeManager extends ReadWriteNodeTypeManager {
+
+ /**
+ * logger instance
+ */
+ private static final Logger log =
LoggerFactory.getLogger(ValidatingNodeTypeManager.class);
+
+ private final Tree types;
+
+ ValidatingNodeTypeManager(NodeState nodeState) {
+ this.types = getTypes(nodeState);
+ }
+
+ @Override
+ protected Tree getTypes() {
+ return types;
+ }
+
+ private Tree getTypes(NodeState after) {
+ Tree tree = new ReadOnlyTree(after);
+ for (String name : PathUtils.elements(NODE_TYPES_PATH)) {
+ if (tree == null) {
+ break;
+ } else {
+ tree = tree.getChild(name);
+ }
+ }
+ return tree;
+ }
+}
\ No newline at end of file
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java?rev=1404049&r1=1404048&r2=1404049&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java
Wed Oct 31 09:24:52 2012
@@ -16,11 +16,8 @@
*/
package org.apache.jackrabbit.oak.jcr;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
-
import javax.annotation.Nonnull;
import javax.jcr.Repository;
@@ -38,6 +35,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.name.NamespaceValidatorProvider;
import org.apache.jackrabbit.oak.plugins.nodetype.DefaultTypeEditor;
import org.apache.jackrabbit.oak.plugins.nodetype.InitialContent;
+import
org.apache.jackrabbit.oak.plugins.nodetype.RegistrationValidatorProvider;
import org.apache.jackrabbit.oak.plugins.nodetype.TypeValidatorProvider;
import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
import org.apache.jackrabbit.oak.spi.commit.CommitHook;
@@ -48,6 +46,8 @@ import org.apache.jackrabbit.oak.spi.lif
import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
+import static com.google.common.base.Preconditions.checkNotNull;
+
public class Jcr {
private final Oak oak;
@@ -69,6 +69,7 @@ public class Jcr {
with(new NameValidatorProvider());
with(new NamespaceValidatorProvider());
with(new TypeValidatorProvider());
+ with(new RegistrationValidatorProvider());
with(new ConflictValidatorProvider());
with(new IndexHookManager(
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java?rev=1404049&r1=1404048&r2=1404049&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
Wed Oct 31 09:24:52 2012
@@ -36,6 +36,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.name.NameValidatorProvider;
import org.apache.jackrabbit.oak.plugins.name.NamespaceValidatorProvider;
import org.apache.jackrabbit.oak.plugins.nodetype.DefaultTypeEditor;
+import
org.apache.jackrabbit.oak.plugins.nodetype.RegistrationValidatorProvider;
import org.apache.jackrabbit.oak.plugins.nodetype.TypeValidatorProvider;
import org.apache.jackrabbit.oak.spi.commit.CommitHook;
import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
@@ -215,6 +216,7 @@ public class Main {
new NameValidatorProvider(),
new NamespaceValidatorProvider(),
new TypeValidatorProvider(),
+ new RegistrationValidatorProvider(),
new ConflictValidatorProvider());
}