jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1416949 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ oak...
Date Tue, 04 Dec 2012 14:12:58 GMT
Author: angela
Date: Tue Dec  4 14:12:57 2012
New Revision: 1416949

URL: http://svn.apache.org/viewvc?rev=1416949&view=rev
Log:
OAK-490 : Add EffectiveNodeTypeManager#isNodeType

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/OakAuthorizableProperties.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java?rev=1416949&r1=1416948&r2=1416949&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
Tue Dec  4 14:12:57 2012
@@ -21,10 +21,10 @@ import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
 import javax.jcr.query.Query;
 
 import com.google.common.base.Charsets;
@@ -43,12 +43,12 @@ import org.apache.jackrabbit.oak.api.Typ
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.memory.StringPropertyState;
+import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
 import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static org.apache.jackrabbit.oak.api.Type.STRING;
-import static org.apache.jackrabbit.oak.api.Type.STRINGS;
 
 /**
  * IdentifierManager...
@@ -58,9 +58,11 @@ public class IdentifierManager {
     private static final Logger log = LoggerFactory.getLogger(IdentifierManager.class);
 
     private final Root root;
+    private final ReadOnlyNodeTypeManager nodeTypeManager;
 
     public IdentifierManager(Root root) {
         this.root = root;
+        this.nodeTypeManager = ReadOnlyNodeTypeManager.getInstance(root);
     }
 
     @Nonnull
@@ -209,8 +211,12 @@ public class IdentifierManager {
                             Tree tree = root.getTree(PathUtils.getParentPath(path));
                             if (tree != null) {
                                 for (String ntName : nodeTypeNames) {
-                                    if (hasType(tree, ntName)) {
-                                        return true;
+                                    try {
+                                        if (nodeTypeManager.isNodeType(tree, ntName)) {
+                                            return true;
+                                        }
+                                    } catch (RepositoryException e) {
+                                        log.warn(e.getMessage());
                                     }
                                 }
                             }
@@ -251,31 +257,13 @@ public class IdentifierManager {
         return refProp.getName();
     }
 
-    private static boolean hasType(Tree tree, String ntName) {
-        // TODO use NodeType.isNodeType to determine type membership instead of equality
on type names
-        PropertyState pType = tree.getProperty(JcrConstants.JCR_PRIMARYTYPE);
-        if (pType != null) {
-            String primaryType = pType.getValue(STRING);
-            if (ntName.equals(primaryType)) {
-                return true;
-            }
-        }
-
-        PropertyState pMixin = tree.getProperty(JcrConstants.JCR_MIXINTYPES);
-        if (pMixin != null) {
-            for (String mixinType : pMixin.getValue(STRINGS)) {
-                if (ntName.equals(mixinType)) {
-                    return true;
-                }
-            }
-        }
-
-        return false;
-    }
-
     public boolean isReferenceable(Tree tree) {
-        // TODO add proper implementation include node type eval
-        return tree.hasProperty(JcrConstants.JCR_UUID);
+        try {
+            return nodeTypeManager.isNodeType(tree, JcrConstants.MIX_REFERENCEABLE);
+        } catch (RepositoryException e) {
+            log.warn(e.getMessage());
+            return false;
+        }
     }
 
     @CheckForNull

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeProvider.java?rev=1416949&r1=1416948&r2=1416949&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeProvider.java
Tue Dec  4 14:12:57 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeType;
 
 import org.apache.jackrabbit.oak.api.Tree;
@@ -30,24 +31,39 @@ import org.apache.jackrabbit.oak.api.Tre
 public interface EffectiveNodeTypeProvider {
 
     /**
-     * FIXME in contrast what the method name implies this method returns the transitive
closure of the super types
-     * TODO clarify contract, what is the difference between this method and NodeType.getSuperTypes()
+     * Returns {@code true} if this tree is of the specified primary node
+     * type or mixin type, or a subtype thereof respecting the effective node
+     * type of the {@code tree}. Returns {@code false} otherwise.
+     *
+     * @param tree The tree to be tested.
+     * @param nodeTypeName The name of the node type to be tested.
+     * @return true if the specified node is of the given node type.
+     * @throws NoSuchNodeTypeException If the specified node type name doesn't
+     * refer to an existing node type.
+     * @throws RepositoryException If the given node type name is invalid or if
+     * some other error occurs.
+     */
+    boolean isNodeType(Tree tree, String nodeTypeName) throws NoSuchNodeTypeException, RepositoryException;
+
+    /**
      * Calculates and returns all effective node types of the given node.
      *
      * @param targetNode the node for which the types should be calculated.
      * @return all types of the given node
      * @throws RepositoryException if the type information can not be accessed
+     * @see <a href="http://www.jcp.org/en/jsr/detail?id=283">JCR 2.0 Specification,
+     * Section 3.7.6.5</a> for the definition of the effective node type.
      */
     Iterable<NodeType> getEffectiveNodeTypes(Node targetNode) throws RepositoryException;
 
     /**
-     * FIXME in contrast what the method name implies this method returns the transitive
closure of the super types
-     * TODO clarify contract, what is the difference between this method and NodeType.getSuperTypes()
      * Calculates and returns all effective node types of the given tree.
      *
      * @param tree
      * @return all node types of the given tree
-     * @throws RepositoryException if the type information can not be accessed
+     * @throws RepositoryException if the type information can not be accessed,
+     * @see <a href="http://www.jcp.org/en/jsr/detail?id=283">JCR 2.0 Specification,
+     * Section 3.7.6.5</a> for the definition of the effective node type.
      */
     Iterable<NodeType> getEffectiveNodeTypes(Tree tree) throws RepositoryException;
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java?rev=1416949&r1=1416948&r2=1416949&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
Tue Dec  4 14:12:57 2012
@@ -22,7 +22,6 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Queue;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.Node;
@@ -46,8 +45,10 @@ import javax.jcr.nodetype.PropertyDefini
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Queues;
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.namepath.NameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
@@ -62,6 +63,7 @@ import static org.apache.jackrabbit.JcrC
 import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
 import static org.apache.jackrabbit.oak.api.Type.STRING;
 import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
 
 /**
  * Base implementation of a {@link NodeTypeManager} with support for reading
@@ -120,6 +122,24 @@ public abstract class ReadOnlyNodeTypeMa
         return NamePathMapperImpl.DEFAULT;
     }
 
+    //--------------------------------------------------------------------------
+    /**
+     * Return a new instance of {@code ReadOnlyNodeTypeManager} that reads node
+     * type information from the tree at {@link NodeTypeConstants#NODE_TYPES_PATH}.
+     *
+     * @param root The root to read node types from.
+     * @return a new instance of {@code ReadOnlyNodeTypeManager}.
+     */
+    @Nonnull
+    public static ReadOnlyNodeTypeManager getInstance(final Root root) {
+        return new ReadOnlyNodeTypeManager() {
+            @Override
+            protected Tree getTypes() {
+                return root.getTree(NODE_TYPES_PATH);
+            }
+        };
+    }
+
     //----------------------------------------------------< NodeTypeManager >---
 
     @Override
@@ -234,6 +254,24 @@ public abstract class ReadOnlyNodeTypeMa
     }
 
     //------------------------------------------< EffectiveNodeTypeProvider >---
+    @Override
+    public boolean isNodeType(Tree tree, String nodeTypeName) throws RepositoryException
{
+        if (!hasNodeType(nodeTypeName)) {
+            throw new NoSuchNodeTypeException(nodeTypeName);
+        }
+
+        NodeUtil node = new NodeUtil(tree);
+        String ntName = node.getPrimaryNodeTypeName();
+        if (nodeTypeName.equals(ntName) || getNodeType(ntName).isNodeType(nodeTypeName))
{
+            return true;
+        }
+        for (String mixinName : node.getNames(JcrConstants.JCR_MIXINTYPES, new String[0]))
{
+            if (nodeTypeName.equals(mixinName) || getNodeType(mixinName).isNodeType(nodeTypeName))
{
+                return true;
+            }
+        }
+        return false;
+    }
 
     /**
      * Returns all the node types of the given node, in a breadth-first

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/OakAuthorizableProperties.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/OakAuthorizableProperties.java?rev=1416949&r1=1416948&r2=1416949&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/OakAuthorizableProperties.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/OakAuthorizableProperties.java
Tue Dec  4 14:12:57 2012
@@ -44,8 +44,6 @@ import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
-
 /**
  * Oak level implementation of the internal {@code AuthorizableProperties} that
  * is used in those cases where no {@code Session} is associated with the
@@ -66,12 +64,7 @@ class OakAuthorizableProperties implemen
         this.userProvider = userProvider;
         this.id = id;
         this.namePathMapper = namePathMapper;
-        this.nodeTypeManager = new ReadOnlyNodeTypeManager() {
-            @Override
-            protected Tree getTypes() {
-                return root.getTree(NODE_TYPES_PATH);
-            }
-        };
+        this.nodeTypeManager = ReadOnlyNodeTypeManager.getInstance(root);
     }
 
     //---------------------------------------------< AuthorizableProperties >---

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1416949&r1=1416948&r2=1416949&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Tue Dec  4 14:12:57 2012
@@ -859,24 +859,8 @@ public class NodeImpl extends ItemImpl<N
     public boolean isNodeType(final String nodeTypeName) throws RepositoryException {
         checkStatus();
 
-        // TODO: figure out the right place for this check
-        NodeTypeManager ntm = sessionDelegate.getNodeTypeManager();
-        NodeType ntToCheck = ntm.getNodeType(nodeTypeName); // throws on not found
-        String nameToCheck = ntToCheck.getName();
-
-        NodeType currentPrimaryType = getPrimaryNodeType();
-        if (currentPrimaryType.isNodeType(nameToCheck)) {
-            return true;
-        }
-
-        for (NodeType mixin : getMixinNodeTypes()) {
-            if (mixin.isNodeType(nameToCheck)) {
-                return true;
-            }
-        }
-        // TODO: END
-
-        return false;
+        String oakName = sessionDelegate.getOakNameOrThrow(nodeTypeName);
+        return sessionDelegate.getEffectiveNodeTypeProvider().isNodeType(dlg.getTree(), oakName);
     }
 
     @Override



Mime
View raw message