jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r786003 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/ jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/ap...
Date Thu, 18 Jun 2009 10:17:26 GMT
Author: tripod
Date: Thu Jun 18 10:17:23 2009
New Revision: 786003

URL: http://svn.apache.org/viewvc?rev=786003&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-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/resources/org/apache/jackrabbit/test/api/nodetype/spec/nt-folder.txt
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefWriter.java

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=786003&r1=786002&r2=786003&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 10:17:23 2009
@@ -1460,14 +1460,6 @@
         if (supertypes.length > 0) {
             try {
                 EffectiveNodeType est = getEffectiveNodeType(supertypes, entCache, ntdCache);
-                // 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)) {
-                    String msg = "[" + name + "] all primary node types except"
-                            + " nt:base itself must be (directly or indirectly) derived from
nt:base";
-                    log.debug(msg);
-                    throw new InvalidNodeTypeDefException(msg);
-                }
                 // check whether specified node type definition overrides
                 // a supertypes's primaryItem -> illegal (JCR-1947)
                 if (ntd.getPrimaryItemName() != null
@@ -1477,6 +1469,16 @@
                     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);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd?rev=786003&r1=786002&r2=786003&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd
Thu Jun 18 10:17:23 2009
@@ -43,7 +43,7 @@
  * This abstract node type serves as the supertype of nt:file and nt:folder.
  * @since 1.0
  */
-[nt:hierarchyNode] > nt:base, mix:created
+[nt:hierarchyNode] > mix:created
   // abstract (currently fails due to JCR-2159)
 
 /**
@@ -70,7 +70,7 @@
  *
  * @since 1.0
  */
-[nt:linkedFile] > nt:base, nt:hierarchyNode
+[nt:linkedFile] > nt:hierarchyNode
   primaryitem jcr:content
   - jcr:content (REFERENCE) mandatory
 
@@ -83,7 +83,7 @@
  *
  * @since 1.0
  */
-[nt:folder] > nt:base, nt:hierarchyNode
+[nt:folder] > nt:hierarchyNode
   + * (nt:hierarchyNode) VERSION
 
 /**
@@ -92,7 +92,7 @@
  *
  * @since 1.0
  */
-[nt:resource] > nt:base, mix:mimeType, mix:lastModified
+[nt:resource] > mix:mimeType, mix:lastModified
   primaryitem jcr:data
   - jcr:data (BINARY) mandatory
   
@@ -331,7 +331,7 @@
 /**
  * @since 1.0
  */
-[nt:versionHistory] > nt:base, mix:referenceable
+[nt:versionHistory] > mix:referenceable
   - jcr:versionableUuid (STRING) mandatory autocreated protected ABORT
     /** @since 2.0 */
   - jcr:copiedFrom (WEAKREFERENCE) protected ABORT < 'nt:version'
@@ -348,7 +348,7 @@
 /**
  * @since 1.0
  */
-[nt:version] > nt:base, mix:referenceable
+[nt:version] > mix:referenceable
   - jcr:created (DATE) mandatory autocreated protected ABORT
   - jcr:predecessors (REFERENCE) protected multiple ABORT < 'nt:version'
   - jcr:successors (REFERENCE) protected multiple ABORT < 'nt:version'
@@ -359,7 +359,7 @@
 /**
  * @since 1.0
  */
-[nt:frozenNode] > nt:base, mix:referenceable
+[nt:frozenNode] > mix:referenceable
   orderable
   - jcr:frozenPrimaryType (NAME) mandatory autocreated protected ABORT
   - jcr:frozenMixinTypes (NAME) protected multiple ABORT
@@ -377,13 +377,13 @@
 /**
  * @since 2.0
  */
-[nt:activity] > nt:base, mix:referenceable
+[nt:activity] > mix:referenceable
   - jcr:activityTitle (STRING) mandatory autocreated PROTECTED
 
 /**
  * @since 2.0
  */
-[nt:configuration] > nt:base, mix:versionable
+[nt:configuration] > mix:versionable
   - jcr:root (REFERENCE) mandatory autocreated protected
 
 //------------------------------------------------------------------------------
@@ -557,7 +557,7 @@
 // User Management 
 // -----------------------------------------------------------------------------
 
-[rep:Authorizable] > nt:base, mix:referenceable
+[rep:Authorizable] > mix:referenceable
   abstract
   + * (rep:Authorizable) = rep:Authorizable protected VERSION
   + * (rep:AuthorizableFolder) = rep:AuthorizableFolder protected VERSION
@@ -577,7 +577,7 @@
 
 [rep:Group] > rep:Authorizable
 
-[rep:AuthorizableFolder] > nt:base, mix:referenceable
+[rep:AuthorizableFolder] > mix:referenceable
   + * (rep:Authorizable) = rep:User protected VERSION
   + * (rep:AuthorizableFolder) = rep:AuthorizableFolder protected VERSION
 

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

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefWriter.java?rev=786003&r1=786002&r2=786003&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefWriter.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefWriter.java
Thu Jun 18 10:17:23 2009
@@ -26,10 +26,13 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
+import java.util.TreeSet;
 
 import javax.jcr.NamespaceException;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NodeTypeDefinition;
 import javax.jcr.query.qom.QueryObjectModelConstants;
 import javax.jcr.version.OnParentVersionAction;
 
@@ -39,12 +42,16 @@
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueConstraint;
+import org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
+import org.apache.jackrabbit.spi.commons.namespace.SessionNamespaceResolver;
 import org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException;
 import org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint;
 import org.apache.jackrabbit.spi.commons.query.qom.Operator;
+import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
 import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 import org.apache.jackrabbit.util.ISO9075;
 
@@ -62,8 +69,6 @@
  */
 public class CompactNodeTypeDefWriter {
 
-    // TODO: valueFactory not needed any more -> remove from constructor and write calls...
-
     /**
      * the indention string
      */
@@ -95,6 +100,30 @@
     private final Set<String> usedNamespaces = new HashSet<String>();
 
     /**
+     * Creates a new nodetype writer based on a session
+     *
+     * @param out the underlaying writer
+     * @param s repository session
+     * @param includeNS if <code>true</code> all used namespace decl. are also
+     *                  written to the writer
+     */
+    public CompactNodeTypeDefWriter(Writer out, Session s, boolean includeNS) {
+        this(out, new SessionNamespaceResolver(s), new DefaultNamePathResolver(s), includeNS);
+    }
+
+    /**
+     * Creates a new nodetype writer based on a namespace resolver
+     *
+     * @param out the underlaying writer
+     * @param r the naespace resolver
+     * @param includeNS if <code>true</code> all used namespace decl. are also
+     *                  written to the writer
+     */
+    public CompactNodeTypeDefWriter(Writer out, NamespaceResolver r, boolean includeNS) {
+        this(out, r, new DefaultNamePathResolver(r), includeNS);
+    }
+
+    /**
      * Creates a new nodetype writer that does not include namepsaces.
      *
      * @param out the underlaying writer
@@ -114,6 +143,7 @@
      * @param r the naespace resolver
      * @param npResolver name-path resolver
      * @param includeNS if <code>true</code> all used namespace decl. are also
+     *                  written to the writer
      */
     public CompactNodeTypeDefWriter(Writer out,
                                     NamespaceResolver r,
@@ -168,7 +198,7 @@
     }
 
     /**
-     * Write one QNodeTypeDefinition to this writer
+     * Write a collection of QNodeTypeDefinitions to this writer
      *
      * @param defs node type definitions
      * @throws IOException if an I/O error occurs
@@ -180,6 +210,20 @@
     }
 
     /**
+     * Write one NodeTypeDefinition to this writer
+     *
+     * @param nt node type definition
+     * @throws IOException if an I/O error occurs
+     */
+    public void write(NodeTypeDefinition nt) throws IOException {
+        try {
+            write(new QNodeTypeDefinitionImpl(nt, npResolver, QValueFactoryImpl.getInstance()));
+        } catch (RepositoryException e) {
+            throw new IOException("Error during internal conversion of nodetype definition:"
+ e.toString());
+        }
+    }
+
+    /**
      * Flushes all pending write operations and Closes this writer. please note,
      * that the underlying writer remains open.
      *
@@ -214,11 +258,20 @@
      * @throws IOException if an I/O error occurs
      */
     private void writeSupertypes(QNodeTypeDefinition ntd) throws IOException {
-        String delim = " > ";
+        // get ordered list of supertypes, omitting nt:Base
+        TreeSet<Name> supertypes = new TreeSet<Name>();
         for (Name name : ntd.getSupertypes()) {
-            out.write(delim);
-            out.write(resolve(name));
-            delim = ", ";
+            if (!name.equals(NameConstants.NT_BASE)) {
+                supertypes.add(name);
+            }
+        }
+        if (!supertypes.isEmpty()) {
+            String delim = " > ";
+            for (Name name : supertypes) {
+                out.write(delim);
+                out.write(resolve(name));
+                delim = ", ";
+            }
         }
     }
 



Mime
View raw message