jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r786319 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/nt-linkedFile.txt
Date Thu, 18 Jun 2009 22:25:35 GMT
Author: tripod
Date: Thu Jun 18 22:25:35 2009
New Revision: 786319

URL: http://svn.apache.org/viewvc?rev=786319&view=rev
Log:
JCR-2066 NodeTypeRegistry could auto-subtype from nt:base

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/nt-linkedFile.txt

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java?rev=786319&r1=786318&r2=786319&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
Thu Jun 18 22:25:35 2009
@@ -22,6 +22,7 @@
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.Reader;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -29,6 +30,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.Stack;
+import java.util.TreeSet;
 
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.PropertyType;
@@ -391,6 +393,7 @@
         /**
          * validate new node type definition
          */
+        checkNtBaseSubtyping(ntd, registeredNTDefs);
         validateNodeTypeDef(ntd, entCache, registeredNTDefs, nsReg, false);
 
         /**
@@ -1210,6 +1213,7 @@
             throw new InvalidNodeTypeDefException(msg);
         }
 
+        checkNtBaseSubtyping(ntd, registeredNTDefs);
         EffectiveNodeType ent =
                 validateNodeTypeDef(ntd, entCache, registeredNTDefs, nsReg, false);
 
@@ -1264,9 +1268,6 @@
     private void internalRegister(Collection<NodeTypeDef> ntDefs, boolean lenient)
             throws InvalidNodeTypeDefException, RepositoryException {
 
-        // create working copies of current ent & ntd caches:
-        // cache of pre-built aggregations of node types
-        EffectiveNodeTypeCache tmpENTCache = (EffectiveNodeTypeCache) entCache.clone();
         // map of node type names and node type definitions
         Map<Name, NodeTypeDef> tmpNTDefCache = new HashMap<Name, NodeTypeDef>(registeredNTDefs);
 
@@ -1283,6 +1284,14 @@
             tmpNTDefCache.put(ntd.getName(), ntd);
         }
 
+        // check if all node type defs have proper nt:base subtyping
+        for (NodeTypeDef ntd : ntDefs) {
+            checkNtBaseSubtyping(ntd, tmpNTDefCache);
+        }
+
+        // create working copies of current ent & ntd caches:
+        // cache of pre-built aggregations of node types
+        EffectiveNodeTypeCache tmpENTCache = (EffectiveNodeTypeCache) entCache.clone();
         for (NodeTypeDef ntd : ntDefs) {
             EffectiveNodeType ent = validateNodeTypeDef(ntd, tmpENTCache,
                     tmpNTDefCache, nsReg, lenient);
@@ -1356,6 +1365,57 @@
     }
 
     /**
+     * Checks if the given node type def has the correct supertypes in respect
+     * to nt:base. all mixin nodetypes must not have a nt:base, the primary
+     * ones only if they don't inherit it from another supertype.
+     *
+     * @param ntd the node type def to check
+     * @param ntdCache cache for lookup
+     * @return <code>true</code> if the ntd was modified
+     */
+    private static boolean checkNtBaseSubtyping(NodeTypeDef ntd, Map<Name, NodeTypeDef>
ntdCache) {
+        if (NameConstants.NT_BASE.equals(ntd.getName())) {
+            return false;
+        }
+        Set<Name> supertypes = new TreeSet<Name>(Arrays.asList(ntd.getSupertypes()));
+        if (supertypes.isEmpty()) {
+            return false;
+        }
+        boolean modified;
+        if (ntd.isMixin()) {
+            // if mixin, remove possible nt:base supertype
+            modified = supertypes.remove(NameConstants.NT_BASE);
+        } else {
+            // check if all supertypes (except nt:base) are mixins
+            boolean allMixins = true;
+            for (Name name: supertypes) {
+                if (!name.equals(NameConstants.NT_BASE)) {
+                    NodeTypeDef def = ntdCache.get(name);
+                    if (def != null && !def.isMixin()) {
+                        allMixins = false;
+                        break;
+                    }
+                }
+            }
+            if (allMixins) {
+                // ntd is a primary node type and has only mixins as supertypes,
+                // so it needs a nt:base
+                modified = supertypes.add(NameConstants.NT_BASE);
+            } else {
+                // ntd is a primary node type and at least one of the supertypes
+                // is too, so ensure that no nt:base is added. note that the
+                // trivial case, where there would be no supertype left is handled
+                // in the NodeTypeDef directly
+                modified = supertypes.remove(NameConstants.NT_BASE);
+            }
+        }
+        if (modified) {
+            ntd.setSupertypes(supertypes.toArray(new Name[supertypes.size()]));
+        }
+        return modified;
+    }
+
+    /**
      * Validates the specified <code>NodeTypeDef</code> within the context of
      * the two other given collections and returns an <code>EffectiveNodeType</code>.
      *
@@ -1448,16 +1508,6 @@
                     throw new InvalidNodeTypeDefException(msg);
 
                 }
-                // make sure that all primary types except nt:base extend from nt:base
-                if (!ntd.isMixin() && !NameConstants.NT_BASE.equals(ntd.getName())
-                        && !est.includesNodeType(NameConstants.NT_BASE)) {
-                    // auto-subtype from nt:base
-                    Name[] s = new Name[supertypes.length + 1];
-                    System.arraycopy(supertypes, 0 ,s, 1, supertypes.length);
-                    s[0] = NameConstants.NT_BASE;
-                    supertypes = s;
-                    ntd.setSupertypes(s);
-                }
             } catch (NodeTypeConflictException ntce) {
                 String msg = "[" + name + "] failed to validate supertypes";
                 log.debug(msg);
@@ -1676,6 +1726,10 @@
             Name[] reqTypes = cnd.getRequiredPrimaryTypes();
             if (reqTypes != null && reqTypes.length > 0) {
                 for (Name rpt : reqTypes) {
+                    // skip nt:base required types
+                    if (NameConstants.NT_BASE.equals(rpt)) {
+                        continue;
+                    }
                     checkNamespace(rpt, nsReg);
                     referenceToSelf = false;
                     /**

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/nt-linkedFile.txt
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/nt-linkedFile.txt?rev=786319&r1=786318&r2=786319&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/nt-linkedFile.txt
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/nt-linkedFile.txt
Thu Jun 18 22:25:35 2009
@@ -1,7 +1,6 @@
 NodeTypeName
   nt:linkedFile
 Supertypes
-  nt:base
   nt:hierarchyNode
 IsMixin
   false



Mime
View raw message