jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1478210 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/api/ main/java/org/apache/jackrabbit/oak/core/ main/java/org/apache/jackrabbit/oak/security/authorization/ main/java/org/apache/jackrabbit/oak/security/au...
Date Wed, 01 May 2013 21:57:01 GMT
Author: mduerig
Date: Wed May  1 21:57:00 2013
New Revision: 1478210

URL: http://svn.apache.org/r1478210
Log:
OAK-798: Review / refactor TreeImpl and related classes
Replace usage of Tree.getParentOrNull with Tree.getParent

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlImporter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionProviderImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserValidator.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java?rev=1478210&r1=1478209&r2=1478210&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java Wed
May  1 21:57:00 2013
@@ -33,7 +33,7 @@ import javax.annotation.Nonnull;
  * {@link Tree} instances may become disconnected after a call to {@link #refresh()},
  * {@link #rebase()} or {@link #commit()}. Any access to disconnected tree instances
  * - except for  {@link Tree#getName()}, {@link Tree#isRoot()}, {@link Tree#getPath()},
- * {@link Tree#getParentOrNull()} and {@link Tree#exists()} - will cause an
+ * {@link Tree#getParent()} and {@link Tree#exists()} - will cause an
  * {@code InvalidStateException}.
  * TODO document iterability / existence (OAK-798)
  */

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java?rev=1478210&r1=1478209&r2=1478210&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java Wed
May  1 21:57:00 2013
@@ -60,7 +60,7 @@ import javax.annotation.Nullable;
  * {@link Tree} instances may become disconnected after a call to {@link Root#refresh()},
  * {@link Root#rebase()} or {@link Root#commit()}. Any access to disconnected tree instances
  * - except for {@link Tree#getName()}, {@link Tree#isRoot()}, {@link Tree#getPath()},
- * {@link Tree#getParentOrNull()} and {@link Tree#exists()} - will cause an
+ * {@link Tree#getParent()} and {@link Tree#exists()} - will cause an
  * {@code InvalidStateException}.
  * TODO document iterability / existence (OAK-798)
  */
@@ -135,16 +135,6 @@ public interface Tree {
     Tree getParent();
 
     /**
-     * @return the parent of this {@code Tree} instance. This method returns
-     *         {@code null} if the parent is not accessible or if no parent exists (root
-     *         node).
-     * @deprecated use {@link #getParent()} and {@link #exists()} instead.
-     */
-    @CheckForNull
-    @Deprecated
-    Tree getParentOrNull();
-
-    /**
      * Get a property state
      *
      * @param name The name of the property state.

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java?rev=1478210&r1=1478209&r2=1478210&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
Wed May  1 21:57:00 2013
@@ -161,20 +161,11 @@ public final class ImmutableTree extends
         return path;
     }
 
-    // FIXME this in contrast to @NonNull of the Tree contract this method might return null.
-    // revisit Tree contract and implementation
-    @CheckForNull
     @Override
     public ImmutableTree getParent() {
         return parentProvider.getParent();
     }
 
-    @Override
-    @Deprecated
-    public ImmutableTree getParentOrNull() {
-        return parentProvider.getParent();
-    }
-
     @Nonnull
     @Override
     public ImmutableTree getChild(@Nonnull String name) {
@@ -287,7 +278,7 @@ public final class ImmutableTree extends
         ParentProvider ROOTPROVIDER = new ParentProvider() {
             @Override
             public ImmutableTree getParent() {
-                return null;
+                throw new IllegalStateException("root tree does not have a parent");
             }
         };
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java?rev=1478210&r1=1478209&r2=1478210&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
Wed May  1 21:57:00 2013
@@ -102,12 +102,6 @@ public class ReadOnlyTree implements Tre
     }
 
     @Override
-    @Deprecated
-    public Tree getParentOrNull() {
-        return parent;
-    }
-
-    @Override
     public PropertyState getProperty(String name) {
         return state.getProperty(name);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1478210&r1=1478209&r2=1478210&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Wed May  1 21:57:00 2013
@@ -153,17 +153,6 @@ public class TreeImpl implements Tree {
     }
 
     @Override
-    @Deprecated
-    public Tree getParentOrNull() {
-        enter();
-        if (parent != null && parent.nodeBuilder.exists()) {
-            return parent;
-        } else {
-            return null;
-        }
-    }
-
-    @Override
     public PropertyState getProperty(String name) {
         enter();
         return getVisibleProperty(name);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlImporter.java?rev=1478210&r1=1478209&r2=1478210&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlImporter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlImporter.java
Wed May  1 21:57:00 2013
@@ -16,11 +16,14 @@
  */
 package org.apache.jackrabbit.oak.security.authorization;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+
 import javax.annotation.CheckForNull;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -37,9 +40,9 @@ import org.apache.jackrabbit.oak.api.Roo
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
-import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
 import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.apache.jackrabbit.oak.spi.security.authorization.AccessControlConfiguration;
+import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
 import org.apache.jackrabbit.oak.spi.xml.NodeInfo;
 import org.apache.jackrabbit.oak.spi.xml.PropInfo;
 import org.apache.jackrabbit.oak.spi.xml.ProtectedNodeImporter;
@@ -48,8 +51,6 @@ import org.apache.jackrabbit.oak.spi.xml
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 /**
  * AccessControlImporter... TODO
  */
@@ -189,9 +190,9 @@ class AccessControlImporter implements P
     @CheckForNull
     private JackrabbitAccessControlList getACL(Tree tree) throws RepositoryException {
         String nodeName = tree.getName();
-        Tree parent = tree.getParentOrNull();
 
-        if (parent != null) {
+        if (!tree.isRoot()) {
+            Tree parent = tree.getParent();
             if (AccessControlConstants.REP_POLICY.equals(nodeName)
                     && ntMgr.isNodeType(tree, AccessControlConstants.NT_REP_ACL))
{
                 return getACL(parent.getPath());

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java?rev=1478210&r1=1478209&r2=1478210&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java
Wed May  1 21:57:00 2013
@@ -220,7 +220,7 @@ class CompiledPermissionImpl implements 
         if (respectParent) {
             parentAllowBits = PrivilegeBits.getInstance();
             parentDenyBits = PrivilegeBits.getInstance();
-            parent = (tree != null) ? tree.getParentOrNull() : null;
+            parent = (tree != null) ? getParentOrNull(tree) : null;
             parentPath = (path != null) ? Strings.emptyToNull(Text.getRelativeParent(path,
1)) : null;
         } else {
             parentAllowBits = PrivilegeBits.EMPTY;
@@ -262,6 +262,11 @@ class CompiledPermissionImpl implements 
         return (allows | ~permissions) == -1;
     }
 
+    private static Tree getParentOrNull(Tree tree) {
+        Tree parent = tree.getParent();
+        return parent.exists() ? parent : null;
+    }
+
     private PrivilegeBits getPrivilegeBits(@Nullable Tree tree) {
         Iterator<PermissionEntry> entries = (tree == null) ?
                 repoEntries.values().iterator() :

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionProviderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionProviderImpl.java?rev=1478210&r1=1478209&r2=1478210&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionProviderImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionProviderImpl.java
Wed May  1 21:57:00 2013
@@ -241,7 +241,7 @@ public class PermissionProviderImpl impl
         String propName = (property == null) ? "" : property.getName();
         String versionablePath = null;
         Tree t = versionStoreTree;
-        while (t != null && !JcrConstants.JCR_VERSIONSTORAGE.equals(t.getName()))
{
+        while (t.exists() && !t.isRoot() && !JcrConstants.JCR_VERSIONSTORAGE.equals(t.getName()))
{
             String name = t.getName();
             String ntName = checkNotNull(TreeUtil.getPrimaryTypeName(t));
             if (VersionConstants.JCR_FROZENNODE.equals(name) && t != versionStoreTree)
{
@@ -253,7 +253,7 @@ public class PermissionProviderImpl impl
                 }
                 break;
             }
-            t = t.getParentOrNull();
+            t = t.getParent();
         }
 
         if (versionablePath == null || versionablePath.length() == 0) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java?rev=1478210&r1=1478209&r2=1478210&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
Wed May  1 21:57:00 2013
@@ -345,8 +345,8 @@ class UserImporter implements ProtectedP
     public boolean start(Tree protectedParent) throws RepositoryException {
         if (isMemberNode(protectedParent)) {
             Tree groupTree = protectedParent;
-            while (isMemberNode(groupTree)) {
-                groupTree = groupTree.getParentOrNull();
+            while (isMemberNode(groupTree) && !groupTree.isRoot()) {
+                groupTree = groupTree.getParent();
             }
             Authorizable auth = (groupTree == null) ? null : userManager.getAuthorizable(groupTree);
             if (auth == null) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserValidator.java?rev=1478210&r1=1478209&r2=1478210&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserValidator.java
Wed May  1 21:57:00 2013
@@ -195,13 +195,15 @@ class UserValidator extends DefaultValid
             String msg = "Attempt to create user/group outside of configured scope " + pathConstraint;
             throw constraintViolation(28, msg);
         }
-        Tree parent = tree.getParentOrNull();
-        while (parent != null && !parent.isRoot()) {
-            if (!NT_REP_AUTHORIZABLE_FOLDER.equals(TreeUtil.getPrimaryTypeName(parent)))
{
-                String msg = "Cannot create user/group: Intermediate folders must be of type
rep:AuthorizableFolder.";
-                throw constraintViolation(29, msg);
+        if (!tree.isRoot()) {
+            Tree parent = tree.getParent();
+            while (parent.exists() && !parent.isRoot()) {
+                if (!NT_REP_AUTHORIZABLE_FOLDER.equals(TreeUtil.getPrimaryTypeName(parent)))
{
+                    String msg = "Cannot create user/group: Intermediate folders must be
of type rep:AuthorizableFolder.";
+                    throw constraintViolation(29, msg);
+                }
+                parent = parent.getParent();
             }
-            parent = parent.getParentOrNull();
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java?rev=1478210&r1=1478209&r2=1478210&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java
Wed May  1 21:57:00 2013
@@ -20,8 +20,8 @@ package org.apache.jackrabbit.oak.core;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import org.apache.jackrabbit.oak.OakBaseTest;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -89,7 +89,11 @@ public class ImmutableTreeTest extends O
     public void testRoot() {
         ImmutableTree tree = ImmutableTree.createFromRoot(root, TreeTypeProvider.EMPTY);
         assertTrue(tree.isRoot());
-        assertNull(tree.getParent());
+        try {
+            tree.getParent();
+            fail();
+        }
+        catch (IllegalStateException expected) { }
         assertEquals("", tree.getName());
         assertEquals(TreeTypeProvider.TYPE_DEFAULT, tree.getType());
     }
@@ -97,7 +101,11 @@ public class ImmutableTreeTest extends O
     @Test
     public void testGetParent() {
         ImmutableTree tree = ImmutableTree.createFromRoot(root, TreeTypeProvider.EMPTY);
-        assertNull(tree.getParent());
+        try {
+            tree.getParent();
+            fail();
+        }
+        catch (IllegalStateException expected) { }
 
         ImmutableTree child = tree.getChild("x");
         assertNotNull(child.getParent());



Mime
View raw message