[dna-commits] DNA SVN: r760 - in trunk/dna-jcr/src: main/resources/org/jboss/dna/jcr and 1 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Mar 5 13:20:34 EST 2009


Author: rhauch
Date: 2009-03-05 13:20:33 -0500 (Thu, 05 Mar 2009)
New Revision: 760

Added:
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNodeTypeSource.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java
Modified:
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeSource.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
   trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
Log:
DNA-292 System View Creates Nodes With Primary Type That Is Not Defined in Type Load

Applied the patch that builds in the dna:namespace type and adds support for chaining of node type sources.

Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNodeTypeSource.java	                        (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNodeTypeSource.java	2009-03-05 18:20:33 UTC (rev 760)
@@ -0,0 +1,161 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.property.Name;
+
+/**
+ * Implementation of {@link JcrNodeTypeSource} that supports chaining of node type sources.
+ */
+abstract class AbstractJcrNodeTypeSource implements JcrNodeTypeSource {
+
+    // Convenience constants to help improve readability
+    protected static final Value[] NO_DEFAULT_VALUES = new Value[0];
+    protected static final String[] NO_CONSTRAINTS = new String[0];
+    protected static final List<NodeType> NO_SUPERTYPES = Collections.<NodeType>emptyList();
+    protected static final List<JcrNodeDefinition> NO_CHILD_NODES = Collections.<JcrNodeDefinition>emptyList();
+    protected static final List<JcrPropertyDefinition> NO_PROPERTIES = Collections.<JcrPropertyDefinition>emptyList();
+
+    // Indicates that the node type has no primary item name - added for readability
+    protected static final Name NO_PRIMARY_ITEM_NAME = null;
+    // Indicates that the definition should apply to all property definition or child node definitions - added for readability
+    protected static final Name ALL_NODES = null;
+
+    // Indicates whether or not the node type is a mixin - added for readability
+    protected static final boolean IS_A_MIXIN = true;
+    protected static final boolean NOT_MIXIN = false;
+
+    // Indicates whether or not the node type has orderable children - added for readability
+    protected static final boolean ORDERABLE_CHILD_NODES = true;
+    protected static final boolean UNORDERABLE_CHILD_NODES = false;
+
+    /** The predecessor node type source. */
+    private final JcrNodeTypeSource predecessor;
+
+    AbstractJcrNodeTypeSource() {
+        this(null);
+    }
+
+    AbstractJcrNodeTypeSource( JcrNodeTypeSource parent ) {
+        this.predecessor = parent;
+    }
+
+    /**
+     * Returns the list of mixin node types declared in this type source.
+     * 
+     * @return the list of mixin node types declared in this type source.
+     * @see org.jboss.dna.jcr.JcrNodeTypeSource#getMixinNodeTypes()
+     */
+    public abstract Collection<JcrNodeType> getDeclaredMixinNodeTypes();
+
+    /**
+     * Returns the list of primary node types declared in this type source.
+     * 
+     * @return the list of primary node types declared in this type source.
+     * @see org.jboss.dna.jcr.JcrNodeTypeSource#getMixinNodeTypes()
+     */
+    public abstract Collection<JcrNodeType> getDeclaredPrimaryNodeTypes();
+
+    /**
+     * Returns the list of mixin node types returned by this and any predecessor source.
+     * 
+     * @return the list of mixin node types returned by this and any predecessor source.
+     * @see org.jboss.dna.jcr.JcrNodeTypeSource#getMixinNodeTypes()
+     */
+    public Collection<JcrNodeType> getMixinNodeTypes() {
+        if (predecessor == null) {
+            return getDeclaredMixinNodeTypes();
+        }
+
+        Collection<JcrNodeType> declaredMixins = getDeclaredMixinNodeTypes();
+        Collection<JcrNodeType> predecessorMixins = predecessor.getMixinNodeTypes();
+
+        List<JcrNodeType> mixins = new ArrayList<JcrNodeType>(declaredMixins.size() + predecessorMixins.size());
+        mixins.addAll(predecessorMixins);
+        mixins.addAll(declaredMixins);
+
+        return mixins;
+    }
+
+    /**
+     * Returns the list of primary node types returned by this and any predecessor source.
+     * 
+     * @return the list of primary node types returned by this and any predecessor source.
+     * @see org.jboss.dna.jcr.JcrNodeTypeSource#getPrimaryNodeTypes()
+     */
+    public Collection<JcrNodeType> getPrimaryNodeTypes() {
+        if (predecessor == null) {
+            return getDeclaredPrimaryNodeTypes();
+        }
+
+        Collection<JcrNodeType> declaredPrimaries = getDeclaredPrimaryNodeTypes();
+        Collection<JcrNodeType> predecessorPrimaries = predecessor.getPrimaryNodeTypes();
+
+        List<JcrNodeType> primaries = new ArrayList<JcrNodeType>(declaredPrimaries.size() + predecessorPrimaries.size());
+        primaries.addAll(predecessorPrimaries);
+        primaries.addAll(declaredPrimaries);
+
+        return primaries;
+    }
+
+    /**
+     * Finds the type with the given name and returns its definition.
+     * <p>
+     * This implementation delegates to the <code>predecessor</code> (if it exists) if the type is not found within the declareded
+     * primary and mixin types.
+     * </p>
+     * 
+     * @param typeName the name of the type to return
+     * @return the type named <code>typeName</code> if it exists, otherwise <code>null</code>.
+     * @throw IllegalArgumentException if <code>typeName</code> is <code>null</code>.
+     * @see org.jboss.dna.jcr.JcrNodeTypeSource#findType(org.jboss.dna.graph.property.Name)
+     */
+    public JcrNodeType findType( Name typeName ) {
+        CheckArg.isNotNull(typeName, "typeName");
+        for (JcrNodeType type : getDeclaredPrimaryNodeTypes()) {
+            if (typeName.equals(type.getInternalName())) {
+                return type;
+            }
+        }
+
+        for (JcrNodeType type : getDeclaredMixinNodeTypes()) {
+            if (typeName.equals(type.getInternalName())) {
+                return type;
+            }
+        }
+
+        if (predecessor != null) {
+            return predecessor.findType(typeName);
+        }
+
+        return null;
+    }
+}


Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNodeTypeSource.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java	                        (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java	2009-03-05 18:20:33 UTC (rev 760)
@@ -0,0 +1,93 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import javax.jcr.PropertyType;
+import javax.jcr.nodetype.NodeType;
+import net.jcip.annotations.Immutable;
+
+/**
+ * {@link JcrNodeTypeSource} that provides built-in node types provided by DNA.
+ */
+ at Immutable
+class DnaBuiltinNodeTypeSource extends AbstractJcrNodeTypeSource {
+
+    /** The list of primary node types. */
+    private final List<JcrNodeType> primaryNodeTypes;
+    /** The list of mixin node types. */
+    private final List<JcrNodeType> mixinNodeTypes;
+
+    DnaBuiltinNodeTypeSource( JcrSession session,
+                              JcrNodeTypeSource predecessor ) {
+        super(predecessor);
+
+        primaryNodeTypes = new ArrayList<JcrNodeType>();
+        mixinNodeTypes = new ArrayList<JcrNodeType>();
+
+        JcrNodeType base = findType(JcrNtLexicon.BASE);
+
+        if (base == null) {
+            String baseTypeName = JcrNtLexicon.BASE.getString(session.getExecutionContext().getNamespaceRegistry());
+            String namespaceTypeName = DnaLexicon.NAMESPACE.getString(session.getExecutionContext().getNamespaceRegistry());
+            throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName));
+        }
+
+        // Stubbing in child node and property definitions for now
+        JcrNodeType namespace = new JcrNodeType(session, DnaLexicon.NAMESPACE, Arrays.asList(new NodeType[] {base}),
+                                                DnaLexicon.URI, NO_CHILD_NODES, Arrays.asList(new JcrPropertyDefinition[] {
+                                                    new JcrPropertyDefinition(session, null, DnaLexicon.URI,
+                                                                              OnParentVersionBehavior.VERSION.getJcrValue(),
+                                                                              true, true, true, NO_DEFAULT_VALUES,
+                                                                              PropertyType.STRING, NO_CONSTRAINTS, false)}),
+                                                NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+        primaryNodeTypes.addAll(Arrays.asList(new JcrNodeType[] {namespace}));
+
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.jcr.JcrNodeTypeSource#getMixinNodeTypes()
+     */
+    @Override
+    public Collection<JcrNodeType> getDeclaredMixinNodeTypes() {
+        return mixinNodeTypes;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.jcr.JcrNodeTypeSource#getPrimaryNodeTypes()
+     */
+    @Override
+    public Collection<JcrNodeType> getDeclaredPrimaryNodeTypes() {
+        return primaryNodeTypes;
+    }
+
+}


Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaBuiltinNodeTypeSource.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java	2009-03-05 18:14:56 UTC (rev 759)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java	2009-03-05 18:20:33 UTC (rev 760)
@@ -33,5 +33,6 @@
 
     public static final Name NAMESPACES = new BasicName(Namespace.URI, "namespaces");
     public static final Name NAMESPACE = new BasicName(Namespace.URI, "namespace");
+    public static final Name URI = new BasicName(Namespace.URI, "uri");
 
 }

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java	2009-03-05 18:14:56 UTC (rev 759)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java	2009-03-05 18:20:33 UTC (rev 760)
@@ -26,7 +26,6 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 import javax.jcr.PropertyType;
 import javax.jcr.Value;
@@ -39,34 +38,21 @@
  * {@link JcrNodeTypeSource} that provides built-in node types per the 1.0 specification.
  */
 @Immutable
-class JcrBuiltinNodeTypeSource implements JcrNodeTypeSource {
+class JcrBuiltinNodeTypeSource extends AbstractJcrNodeTypeSource {
 
-    // Convenience constants to help improve readability
-    private static final Value[] NO_DEFAULT_VALUES = new Value[0];
-    private static final String[] NO_CONSTRAINTS = new String[0];
-    private static final List<NodeType> NO_SUPERTYPES = Collections.<NodeType>emptyList();
-    private static final List<JcrNodeDefinition> NO_CHILD_NODES = Collections.<JcrNodeDefinition>emptyList();
-    private static final List<JcrPropertyDefinition> NO_PROPERTIES = Collections.<JcrPropertyDefinition>emptyList();
-
-    // Indicates that the node type has no primary item name - added for readability
-    private static final Name NO_PRIMARY_ITEM_NAME = null;
-    // Indicates that the definition should apply to all property definition or child node definitions - added for readability
-    private static final Name ALL_NODES = null;
-
-    // Indicates whether or not the node type is a mixin - added for readability
-    private static final boolean IS_A_MIXIN = true;
-    private static final boolean NOT_MIXIN = false;
-
-    // Indicates whether or not the node type has orderable children - added for readability
-    private static final boolean ORDERABLE_CHILD_NODES = true;
-    private static final boolean UNORDERABLE_CHILD_NODES = false;
-
     /** The list of primary node types. */
     private final List<JcrNodeType> primaryNodeTypes;
     /** The list of mixin node types. */
     private final List<JcrNodeType> mixinNodeTypes;
 
     JcrBuiltinNodeTypeSource( JcrSession session ) {
+        this(session, null);
+    }
+
+    JcrBuiltinNodeTypeSource( JcrSession session,
+                              JcrNodeTypeSource predecessor ) {
+        super(predecessor);
+
         primaryNodeTypes = new ArrayList<JcrNodeType>();
 
         Value trueValue = new JcrValue(session.getExecutionContext().getValueFactories(), PropertyType.BOOLEAN, Boolean.TRUE);
@@ -620,7 +606,8 @@
      * 
      * @see org.jboss.dna.jcr.JcrNodeTypeSource#getMixinNodeTypes()
      */
-    public Collection<JcrNodeType> getMixinNodeTypes() {
+    @Override
+    public Collection<JcrNodeType> getDeclaredMixinNodeTypes() {
         return mixinNodeTypes;
     }
 
@@ -629,7 +616,8 @@
      * 
      * @see org.jboss.dna.jcr.JcrNodeTypeSource#getPrimaryNodeTypes()
      */
-    public Collection<JcrNodeType> getPrimaryNodeTypes() {
+    @Override
+    public Collection<JcrNodeType> getDeclaredPrimaryNodeTypes() {
         return primaryNodeTypes;
     }
 

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java	2009-03-05 18:14:56 UTC (rev 759)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java	2009-03-05 18:20:33 UTC (rev 760)
@@ -65,6 +65,7 @@
     public static I18n errorWhileFindingNodeWithUuid;
 
     public static I18n typeNotFound;
+    public static I18n supertypeNotFound;
 
     // Used in AbstractJcrNode#getAncestor
     public static I18n noNegativeDepth;

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeSource.java	2009-03-05 18:14:56 UTC (rev 759)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeSource.java	2009-03-05 18:20:33 UTC (rev 760)
@@ -2,6 +2,7 @@
 
 import java.util.Collection;
 import javax.jcr.nodetype.NodeType;
+import org.jboss.dna.graph.property.Name;
 
 /**
  * Interface for any potential provider of {@link JcrNodeType} definitions, the DNA implementation of {@link NodeType}. Possible
@@ -25,4 +26,10 @@
      */
     public Collection<JcrNodeType> getMixinNodeTypes();
 
+    /**
+     * Finds the type with the given name and returns its definition.
+     * @param typeName the name of the type to return
+     * @return the type named <code>typeName</code> if it exists, otherwise <code>null</code>.
+     */
+    public JcrNodeType findType(Name typeName);
 }

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java	2009-03-05 18:14:56 UTC (rev 759)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java	2009-03-05 18:20:33 UTC (rev 760)
@@ -156,7 +156,8 @@
         this.session = new JcrSession(this.repository, this, this.context, sessionAttributes);
 
         // This must be initialized after the session
-        this.nodeTypeManager = new JcrNodeTypeManager(new JcrBuiltinNodeTypeSource(this.session));
+        this.nodeTypeManager = new JcrNodeTypeManager(new DnaBuiltinNodeTypeSource(this.session,
+                                                                                   new JcrBuiltinNodeTypeSource(this.session)));
 
     }
 

Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties	2009-03-05 18:14:56 UTC (rev 759)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties	2009-03-05 18:20:33 UTC (rev 760)
@@ -63,6 +63,7 @@
 workspaceNameIsInvalid = "{1}" is not a valid workspace name for the "{0}" repository
 errorVerifyingWorkspaceName =Error validating the workspace name "{1}" for the "{0}" repository\: {2}
 typeNotFound=No type exists with name "{0}"
+supertypeNotFound=Could not find type "{0}" which is a required supertype of type "{1}"
 
 noNegativeDepth=Depth parameter ({0}) cannot be negative
 tooDeep=Depth parameter ({0}) cannot be greater than the result of getDepth() for this node

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java	2009-03-05 18:14:56 UTC (rev 759)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java	2009-03-05 18:20:33 UTC (rev 760)
@@ -127,7 +127,7 @@
             // addTestSuite(org.apache.jackrabbit.test.api.query.SimpleSelectionTest.class);
 
             // The tests in this suite are level one
-            // addTest(org.apache.jackrabbit.test.api.nodetype.TestAll.suite());
+            addTest(org.apache.jackrabbit.test.api.nodetype.TestAll.suite());
         }
     }
 




More information about the dna-commits mailing list