jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1370366 - in /jackrabbit/oak/trunk/oak-jcr: pom.xml src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
Date Tue, 07 Aug 2012 16:54:41 GMT
Author: jukka
Date: Tue Aug  7 16:54:41 2012
New Revision: 1370366

URL: http://svn.apache.org/viewvc?rev=1370366&view=rev
Log:
OAK-66: JCR Node Type Management

Implement Property.getDefinition() and Node.getDefinition().

Modified:
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1370366&r1=1370365&r2=1370366&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Tue Aug  7 16:54:41 2012
@@ -33,6 +33,7 @@
 
   <properties>
     <known.issues>
+org.apache.jackrabbit.test.api.AddNodeTest#testSameNameSiblings<!-- OAK-203 -->
 org.apache.jackrabbit.test.api.PathTest#testGetItem<!-- OAK-23 -->
 org.apache.jackrabbit.test.api.SessionTest#testMoveConstraintViolationExceptionSrc<!--OAK-132-->
 org.apache.jackrabbit.test.api.SessionTest#testMoveConstraintViolationExceptionDest<!--OAK-132-->
@@ -88,8 +89,10 @@ org.apache.jackrabbit.test.api.nodetype.
 org.apache.jackrabbit.test.api.nodetype.CanAddChildNodeCallWithoutNodeTypeTest
 org.apache.jackrabbit.test.api.nodetype.CanRemoveItemTest
 org.apache.jackrabbit.test.api.LifecycleTest
+org.apache.jackrabbit.test.api.query.ElementTest#testElementTestNameTestSomeNTWithSNS<!--
OAK-203 -->
 org.apache.jackrabbit.test.api.query.GetPropertyNamesTest#testGetPropertyNames
 org.apache.jackrabbit.test.api.query.SaveTest#testConstraintViolationException
+org.apache.jackrabbit.test.api.query.SaveTest#testItemExistsException<!-- OAK-203 -->
 org.apache.jackrabbit.test.api.query.SimpleSelectionTest#testSingleProperty
 org.apache.jackrabbit.test.api.query.qom.ColumnTest#testExpandColumnsForNodeType
 org.apache.jackrabbit.test.api.query.qom.SelectorTest#testUnknownNodeType

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java?rev=1370366&r1=1370365&r2=1370366&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
Tue Aug  7 16:54:41 2012
@@ -16,6 +16,10 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Queue;
+
 import javax.annotation.Nonnull;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.Item;
@@ -23,11 +27,15 @@ import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.ValueFactory;
+import javax.jcr.nodetype.NodeType;
 
 import org.apache.jackrabbit.commons.AbstractItem;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Maps;
+import com.google.common.collect.Queues;
+
 /**
  * {@code ItemImpl}...
  */
@@ -148,6 +156,37 @@ abstract class ItemImpl<T extends ItemDe
     //------------------------------------------------------------< internal >---
 
     /**
+     * Returns all the node types of the given node, in a breadth-first
+     * traversal order of the type hierarchy.
+     * <p>
+     * This utility method used by the getDefinition() methods in the
+     * {@link PropertyImpl} and {@link NodeImpl} subclasses.
+     *
+     * @param node node instance
+     * @return all types of the given node
+     * @throws RepositoryException if the type information can not be accessed
+     */
+    protected static Iterable<NodeType> getAllNodeTypes(Node node)
+            throws RepositoryException {
+        Map<String, NodeType> types = Maps.newHashMap();
+
+        Queue<NodeType> queue = Queues.newArrayDeque();
+        queue.add(node.getPrimaryNodeType());
+        queue.addAll(Arrays.asList(node.getMixinNodeTypes()));
+        while (!queue.isEmpty()) {
+            NodeType type = queue.remove();
+            String name = type.getName();
+            if (!types.containsKey(name)) {
+                types.put(name, type);
+                queue.addAll(Arrays.asList(type.getDeclaredSupertypes()));
+            }
+        }
+
+        return types.values();
+    }
+
+
+    /**
      * Performs a sanity check on this item and the associated session.
      *
      * @throws RepositoryException if this item has been rendered invalid for some reason

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=1370366&r1=1370365&r2=1370366&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 Aug  7 16:54:41 2012
@@ -50,7 +50,6 @@ import javax.jcr.nodetype.NoSuchNodeType
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
-import javax.jcr.version.OnParentVersionAction;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 
@@ -1013,72 +1012,34 @@ public class NodeImpl extends ItemImpl<N
     @Override
     @Nonnull
     public NodeDefinition getDefinition() throws RepositoryException {
-        checkStatus();
-
-
-        // TODO
-        return new NodeDefinition() {
-
-            // This is a workaround to make AbstractJCRTest.cleanup happy
-
-            @Override
-            public boolean isProtected() {
-                return false;
-            }
-
-            @Override
-            public boolean isMandatory() {
-                return false;
-            }
-
-            @Override
-            public boolean isAutoCreated() {
-                return false;
-            }
-
-            @Override
-            public int getOnParentVersion() {
-                return OnParentVersionAction.COPY;
-            }
-
-            @Override
-            public String getName() {
-                return "default";
-            }
-
-            @Override
-            public NodeType getDeclaringNodeType() {
-                return null;
-            }
-
-            @Override
-            public NodeType[] getRequiredPrimaryTypes() {
-                return null;
-            }
-
-            @Override
-            public String[] getRequiredPrimaryTypeNames() {
-                return null;
-            }
-
-            @Override
-            public String getDefaultPrimaryTypeName() {
-                return null;
-            }
+        if (getDepth() == 0) {
+            // TODO: What should be the root node definition?
+            return getPrimaryNodeType().getChildNodeDefinitions()[0];
+        }
 
-            @Override
-            public NodeType getDefaultPrimaryType() {
-                return null;
+        String name = getName();
+        // TODO: This may need to be optimized
+        for (NodeType nt : getAllNodeTypes(getParent())) {
+            for (NodeDefinition def : nt.getDeclaredChildNodeDefinitions()) {
+                String defName = def.getName();
+                if (name.equals(defName) || "*".equals(defName)) {
+                    boolean match = true;
+                    for (String type : def.getRequiredPrimaryTypeNames()) {
+                        if (!isNodeType(type)) {
+                            match = false;
+                        }
+                    }
+                    if (match) {
+                        return def;
+                    }
+                }
             }
+        }
 
-            @Override
-            public boolean allowsSameNameSiblings() {
-                return false;
-            }
-        };
+        throw new RepositoryException(
+                "No matching node definition found for " + this);
     }
 
-
     @Override
     @Nonnull
     public String getCorrespondingNodePath(String workspaceName) throws RepositoryException
{

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java?rev=1370366&r1=1370365&r2=1370366&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
Tue Aug  7 16:54:41 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
+import static javax.jcr.PropertyType.UNDEFINED;
+
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -33,6 +35,7 @@ import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
 
 import org.apache.jackrabbit.oak.api.Tree.Status;
@@ -542,12 +545,33 @@ public class PropertyImpl extends ItemIm
     @Override
     @Nonnull
     public PropertyDefinition getDefinition() throws RepositoryException {
-        return sessionDelegate.perform(new SessionOperation<PropertyDefinition>() {
-            @Override
-            public PropertyDefinition perform() {
-                return dlg.getDefinition();
+        String name = getName();
+        int type = UNDEFINED;
+        if (isMultiple()) {
+            Value[] values = getValues();
+            if (values.length > 0) {
+                type = values[0].getType();
             }
-        });
+        } else {
+            type = getValue().getType();
+        }
+
+        // TODO: This may need to be optimized
+        for (NodeType nt : getAllNodeTypes(getParent())) {
+            for (PropertyDefinition def : nt.getDeclaredPropertyDefinitions()) {
+                String defName = def.getName();
+                int defType = def.getRequiredType();
+                if ((name.equals(defName) || "*".equals(defName))
+                        && (type == defType
+                            || UNDEFINED == type || UNDEFINED == defType)
+                        && isMultiple() == def.isMultiple()) {
+                    return def;
+                }
+            }
+        }
+
+        throw new RepositoryException(
+                "No matching property definition found for " + this);
     }
 
     /**



Mime
View raw message