jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1402548 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Fri, 26 Oct 2012 15:27:35 GMT
Author: angela
Date: Fri Oct 26 15:27:34 2012
New Revision: 1402548

URL: http://svn.apache.org/viewvc?rev=1402548&view=rev
Log:
OAK-405 : Node/Property getDefinition() returns first residual definition instead of matching
named definition 
OAK-408 : Add Definition for the root node

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RootNodeDefinition.java
Modified:
    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

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RootNodeDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RootNodeDefinition.java?rev=1402548&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RootNodeDefinition.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/RootNodeDefinition.java
Fri Oct 26 15:27:34 2012
@@ -0,0 +1,112 @@
+/*
+ * 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.RepositoryException;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.version.OnParentVersionAction;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Node definition for the root node.
+ */
+public final class RootNodeDefinition implements NodeDefinition {
+
+    /**
+     * logger instance
+     */
+    private static final Logger log = LoggerFactory.getLogger(RootNodeDefinition.class);
+
+    private static final String REP_ROOT = "rep:root";
+
+    private final NodeTypeManager ntManager;
+
+    public RootNodeDefinition(NodeTypeManager ntManager) {
+        this.ntManager = ntManager;
+    }
+
+    @Override
+    public NodeType[] getRequiredPrimaryTypes() {
+        try {
+            return new NodeType[] {ntManager.getNodeType(REP_ROOT)};
+        } catch (RepositoryException e) {
+            return new NodeType[0];
+        }
+    }
+
+    @Override
+    public String[] getRequiredPrimaryTypeNames() {
+        return new String[] {REP_ROOT};
+    }
+
+    @Override
+    public NodeType getDefaultPrimaryType() {
+        try {
+            return ntManager.getNodeType(REP_ROOT);
+        } catch (RepositoryException e) {
+            return null;
+        }
+    }
+
+    @Override
+    public String getDefaultPrimaryTypeName() {
+        return REP_ROOT;
+    }
+
+    @Override
+    public boolean allowsSameNameSiblings() {
+        return false;
+    }
+
+    @Override
+    public NodeType getDeclaringNodeType() {
+        try {
+            return ntManager.getNodeType(REP_ROOT);
+        } catch (RepositoryException e) {
+            return null;
+        }
+    }
+
+    @Override
+    public String getName() {
+        return REP_ROOT;
+    }
+
+    @Override
+    public boolean isAutoCreated() {
+        return true;
+    }
+
+    @Override
+    public boolean isMandatory() {
+        return true;
+    }
+
+    @Override
+    public int getOnParentVersion() {
+        return OnParentVersionAction.VERSION;
+    }
+
+    @Override
+    public boolean isProtected() {
+        return false;
+    }
+}
\ No newline at end of file

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=1402548&r1=1402547&r2=1402548&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
Fri Oct 26 15:27:34 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.jcr;
 
 import java.io.InputStream;
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Collections;
@@ -73,6 +74,7 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
+import org.apache.jackrabbit.oak.plugins.nodetype.RootNodeDefinition;
 import org.apache.jackrabbit.oak.util.TODO;
 import org.apache.jackrabbit.value.ValueHelper;
 import org.slf4j.Logger;
@@ -998,16 +1000,16 @@ public class NodeImpl extends ItemImpl<N
     @Nonnull
     public NodeDefinition getDefinition() throws RepositoryException {
         if (getDepth() == 0) {
-            // TODO: What should be the root node definition?
-            return getPrimaryNodeType().getChildNodeDefinitions()[0];
+            return new RootNodeDefinition(dlg.sessionDelegate.getNodeTypeManager());
         }
 
         String name = getName();
+        List<NodeDefinition> residualDefs = new ArrayList<NodeDefinition>();
         // 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)) {
+                if (name.equals(defName)) {
                     boolean match = true;
                     for (String type : def.getRequiredPrimaryTypeNames()) {
                         if (!isNodeType(type)) {
@@ -1017,12 +1019,28 @@ public class NodeImpl extends ItemImpl<N
                     if (match) {
                         return def;
                     }
+                } else if ("*".equals(defName)) {
+                    residualDefs.add(def);
                 }
             }
         }
 
-        throw new RepositoryException(
-                "No matching node definition found for " + this);
+        for (NodeDefinition def : residualDefs) {
+            String defName = def.getName();
+            if ("*".equals(defName)) {
+                boolean match = true;
+                for (String type : def.getRequiredPrimaryTypeNames()) {
+                    if (!isNodeType(type)) {
+                        match = false;
+                    }
+                }
+                if (match) {
+                    return def;
+                }
+            }
+        }
+
+        throw new RepositoryException("No matching node definition found for " + this);
     }
 
     @Override

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=1402548&r1=1402547&r2=1402548&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
Fri Oct 26 15:27:34 2012
@@ -562,19 +562,31 @@ public class PropertyImpl extends ItemIm
         }
 
         // TODO: This may need to be optimized
+        List<PropertyDefinition> residualDefs = new ArrayList<PropertyDefinition>();
         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)
+                if ((name.equals(defName))
+                        && (type == defType || UNDEFINED == type || UNDEFINED ==
defType)
                         && isMultiple() == def.isMultiple()) {
                     return def;
+                } else if ("*".equals(defName)) {
+                    residualDefs.add(def);
                 }
             }
         }
 
+        for (PropertyDefinition def : residualDefs) {
+            String defName = def.getName();
+            int defType = def.getRequiredType();
+            if (("*".equals(defName))
+                    && (type == defType || UNDEFINED == type || UNDEFINED == defType)
+                    && isMultiple() == def.isMultiple()) {
+                return def;
+            }
+        }
+
         // FIXME: Shouldn't be needed
         for (NodeType nt : getAllNodeTypes(getParent())) {
             for (PropertyDefinition def : nt.getDeclaredPropertyDefinitions()) {



Mime
View raw message