jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r780989 - in /jackrabbit/trunk: jackrabbit-core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/...
Date Tue, 02 Jun 2009 09:52:56 GMT
Author: angela
Date: Tue Jun  2 09:52:55 2009
New Revision: 780989

URL: http://svn.apache.org/viewvc?rev=780989&view=rev
Log:
JCR-1591: JSR 283 NodeType Management 
JCR-2105: JSR 283 NodeType Management 

- Node.addNode must check for nt being mixin or abstract
   core: moved to internalAddNode in order to have the check upon
   Node.addNode as well as upon SessionImport
   jcr2spi: delegated to effective node type 
- Node.canAddMixin should be symmetric to Node.addMixin
- NodeType.canAddNode should check for nt being mixin or abstract
   both in core and jcr2spi the check is delegated to the effective node
   type.
   jcr2spi in addition called by all every add-node incl;
   core: in addition called by workspace operations only)

- added and fixed TCK tests

Added:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeDefinitionProvider.java
Modified:
    jackrabbit/trunk/jackrabbit-core/pom.xml
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AddNodeTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeAddMixinTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeMixinUtil.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ManagerProvider.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
    jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml

Modified: jackrabbit/trunk/jackrabbit-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/pom.xml?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-core/pom.xml Tue Jun  2 09:52:55 2009
@@ -90,6 +90,7 @@
                 org.apache.jackrabbit.core.xml.DocumentViewTest#testMultiValue
                 org.apache.jackrabbit.test.api.BinaryPropertyTest#testRandomAccess
                 org.apache.jackrabbit.test.api.SetValueBinaryTest#testBinaryParentJcr2
+                org.apache.jackrabbit.test.api.NodeCanAddMixinTest#testAddMixinTwice
                 org.apache.jackrabbit.test.api.ShareableNodeTest#testSharedNodePath
                 org.apache.jackrabbit.test.api.version.VersionHistoryTest#testInitialNumberOfLinearVersions
                 org.apache.jackrabbit.test.api.version.VersionHistoryTest#testInitiallyGetAllLinearVersionsContainsTheRootAndTheBaseVersion

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Tue Jun  2 09:52:55 2009
@@ -758,12 +758,18 @@
             throw new RepositoryException(msg, e);
         }
 
+        Name nodeTypeName = null;
+        if (nodeType != null) {
+            nodeTypeName = nodeType.getQName();
+            if (nodeType.isMixin()) {
+                throw new ConstraintViolationException(session.getJCRName(nodeTypeName) +
": not a primary node type.");
+            }
+            if (nodeType.isAbstract()) {
+                throw new ConstraintViolationException(session.getJCRName(nodeTypeName) 
+ ": is an abstract node type.");
+            }
+        }
         NodeDefinitionImpl def;
         try {
-            Name nodeTypeName = null;
-            if (nodeType != null) {
-                nodeTypeName = nodeType.getQName();
-            }
             def = getApplicableChildNodeDefinition(nodeName, nodeTypeName);
         } catch (RepositoryException re) {
             String msg = "no definition found in parent node's node type for new node";
@@ -2075,10 +2081,6 @@
         sanityCheck();
 
         NodeTypeImpl nt = (NodeTypeImpl) session.getNodeTypeManager().getNodeType(nodeTypeName);
-        if (nt.isMixin()) {
-            throw new RepositoryException(nodeTypeName + ": not a primary node type");
-        }
-
         return internalAddNode(relPath, nt);
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java
Tue Jun  2 09:52:55 2009
@@ -652,6 +652,15 @@
     public void checkAddNodeConstraints(Name name, Name nodeTypeName,
                                         NodeTypeRegistry ntReg)
             throws ConstraintViolationException, NoSuchNodeTypeException {
+        if (nodeTypeName != null) {
+            NodeTypeDef ntDef = ntReg.getNodeTypeDef(nodeTypeName);
+            if (ntDef.isAbstract()) {
+                throw new ConstraintViolationException(nodeTypeName + " is abstract.");
+            }
+            if (ntDef.isMixin()) {
+                throw new ConstraintViolationException(nodeTypeName + " is mixin.");
+            }
+        }
         NodeDef nd = getApplicableChildNodeDef(name, nodeTypeName, ntReg);
         if (nd.isProtected()) {
             throw new ConstraintViolationException(name + " is protected");

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AddNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AddNodeTest.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AddNodeTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AddNodeTest.java
Tue Jun  2 09:52:55 2009
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.test.api;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Node;
@@ -24,6 +25,9 @@
 import javax.jcr.ItemExistsException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.Session;
 
 /**
@@ -92,6 +96,49 @@
     }
 
     /**
+     * Tests if addNode() throws a ConstraintViolationException in case
+     * of an abstract node type.
+     */
+    public void testAbstractNodeType() throws RepositoryException {
+        NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
+        NodeTypeIterator nts = ntMgr.getPrimaryNodeTypes();
+        while (nts.hasNext()) {
+            NodeType nt = nts.nextNodeType();
+            if (nt.isAbstract()) {
+                try {
+                    testRootNode.addNode(nodeName1, nt.getName());
+                    superuser.save();
+                    fail("Expected ConstraintViolationException.");
+                } catch (ConstraintViolationException e) {
+                    // correct.
+                } finally {
+                    superuser.refresh(false);
+                }
+            }
+        }
+    }
+
+    /**
+     * Tests if addNode() throws a ConstraintViolationException in case
+     * of an mixin node type.
+     */
+    public void testMixinNodeType() throws RepositoryException, NotExecutableException {
+        NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
+        NodeTypeIterator nts = ntMgr.getMixinNodeTypes();
+        if (nts.hasNext()) {
+            try {
+                testRootNode.addNode(nodeName1, nts.nextNodeType().getName());
+                superuser.save();
+                fail("Expected ConstraintViolationException.");
+            } catch (ConstraintViolationException e) {
+                // correct.
+            }
+        } else {
+            throw new NotExecutableException("no mixins.");
+        }
+    }
+
+    /**
      * Tests if the path of the created node is correct.
      */
     public void testPath() throws RepositoryException {

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeAddMixinTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeAddMixinTest.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeAddMixinTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeAddMixinTest.java
Tue Jun  2 09:52:55 2009
@@ -103,6 +103,60 @@
         }
     }
 
+    /**
+     * Test if adding the same mixin twice works as expected.
+     * 
+     * @throws RepositoryException
+     * @throws NotExecutableException
+     * @since JCR 2.0
+     */
+    public void testAddMixinTwice() throws RepositoryException, NotExecutableException {
+        Session session = testRootNode.getSession();
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        node.addMixin(mixinName);
+        // adding again must succeed
+        node.addMixin(mixinName);
+
+        session.save();
+        
+        node.addMixin(mixinName);
+        assertFalse(node.isModified());
+    }
+
+    /**
+     * Test if adding an inherited mixin type has no effect.
+     * 
+     * @throws RepositoryException
+     * @since JCR 2.0
+     */
+    public void testAddInheritedMixin() throws RepositoryException, NotExecutableException
{
+        Session session = testRootNode.getSession();
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        session.save();
+
+        String inheritedMixin = null;
+
+        NodeType nt = node.getPrimaryNodeType();
+        NodeType[] superTypes = nt.getSupertypes();
+        for (int i = 0; i < superTypes.length && inheritedMixin == null; i++)
{
+            if (superTypes[i].isMixin()) {
+                inheritedMixin = superTypes[i].getName();
+            }
+        }
+
+        if (inheritedMixin != null) {
+            node.addMixin(inheritedMixin);
+            assertFalse(node.isModified());
+        } else {
+            throw new NotExecutableException("Primary node type does not have a mixin supertype");
+        }
+    }
 
     /**
      * Tests if <code>Node.addMixin(String mixinName)</code> throws a

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java
Tue Jun  2 09:52:55 2009
@@ -25,6 +25,7 @@
 import javax.jcr.Repository;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeType;
 
 /**
  * <code>NodeCanAddMixinTest</code> contains the test cases for the method
@@ -146,4 +147,53 @@
         }
     }
 
+       /**
+     * Test if adding the same mixin twice would be allowed.
+     *
+     * @throws RepositoryException
+     * @throws NotExecutableException
+     * @since JCR 2.0
+     */
+    public void testAddMixinTwice() throws RepositoryException, NotExecutableException {
+        Session session = testRootNode.getSession();
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        assertTrue(node.canAddMixin(mixinName));
+        node.addMixin(mixinName);
+        // adding again must be possible (though it has no effect)
+        assertTrue(node.canAddMixin(mixinName));
+
+        session.save();
+
+        // adding again must be possible (though it has no effect)
+        assertTrue(node.canAddMixin(mixinName));
+    }
+
+    /**
+     * Test if an inherited mixin could be added.
+     *
+     * @throws RepositoryException
+     * @since JCR 2.0
+     */
+    public void testAddInheritedMixin() throws RepositoryException {
+        Session session = testRootNode.getSession();
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        session.save();
+
+        NodeType nt = node.getPrimaryNodeType();
+        NodeType[] superTypes = nt.getSupertypes();
+        for (int i = 0; i < superTypes.length; i++) {
+            if (superTypes[i].isMixin()) {
+                String mixinName = superTypes[i].getName();
+                // adding again must be possible (though it has no effect)
+                assertTrue(node.canAddMixin(mixinName));
+            }
+        }
+    }
+
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeMixinUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeMixinUtil.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeMixinUtil.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeMixinUtil.java
Tue Jun  2 09:52:55 2009
@@ -21,6 +21,9 @@
 import javax.jcr.Node;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeIterator;
+import javax.jcr.nodetype.NodeType;
+import java.util.List;
+import java.util.Arrays;
 
 /**
  * Utility class to locate mixins in the NodeTyeManager.
@@ -46,6 +49,20 @@
         return null;
     }
 
+    public static String getNotAssignedMixinName(Session session, Node node) throws RepositoryException
{
+        NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
+        NodeTypeIterator mixins = manager.getMixinNodeTypes();
+        List existingMixins = Arrays.asList(node.getMixinNodeTypes());
+
+        while (mixins.hasNext()) {
+            NodeType nt = mixins.nextNodeType();
+            if (!existingMixins.contains(nt)) {
+                return nt.getName();
+            }
+        }
+        return null;
+    }
+
     /**
      * @return a string that is not the name of a mixin type
      */

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java
Tue Jun  2 09:52:55 2009
@@ -112,7 +112,8 @@
         node.addMixin(mixinName);
         testRootNode.save();
 
-        String notAssignedMixin = NodeMixinUtil.getAddableMixinName(session, node);
+
+        String notAssignedMixin = NodeMixinUtil.getNotAssignedMixinName(session, node);
         if (notAssignedMixin == null) {
             throw new NotExecutableException("No testable mixin node type found");
         }

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
Tue Jun  2 09:52:55 2009
@@ -24,6 +24,7 @@
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeTypeIterator;
 
 /**
  * Tests <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
@@ -125,6 +126,65 @@
 
     /**
      * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
+     * returns false if <code>nodeTypeName</code> represents a mixin.
+     */
+    public void testCanAddMixinType()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No testable node type found.");
+        }
+
+        NodeType nodeType = nodeDef.getDeclaringNodeType();
+        String childNodeName = nodeDef.getName();
+        String mixinName;
+        NodeTypeIterator it = manager.getMixinNodeTypes();
+        if (it.hasNext()) {
+            mixinName = it.nextNodeType().getName();
+        } else {
+            throw new NotExecutableException("No mixin type found.");
+        }
+
+        assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName)
" +
+                "must return false if nodeTypeName represents a mixin type.",
+                nodeType.canAddChildNode(childNodeName, mixinName));
+    }
+
+    /**
+     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
+     * returns false if <code>nodeTypeName</code> represents an abstract node
type.
+     */
+    public void testCanAddAbstractType()
+    throws NotExecutableException, RepositoryException {
+
+        NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No testable node type found.");
+        }
+
+        NodeType nodeType = nodeDef.getDeclaringNodeType();
+        String childNodeName = nodeDef.getName();
+        String abstractName = null;
+        NodeTypeIterator it = manager.getPrimaryNodeTypes();
+        while (it.hasNext() && abstractName == null) {
+            NodeType nt = it.nextNodeType();
+            if (nt.isAbstract()) {
+                abstractName = nt.getName();
+            }
+        }
+        if (abstractName == null) {
+            throw new NotExecutableException("No abstract type found.");
+        }
+
+        assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName)
" +
+                "must return false if nodeTypeName represents an abstract node type.",
+                nodeType.canAddChildNode(childNodeName, abstractName));
+    }
+    /**
+     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
      * returns false if <code>childNodeName</code> does not match the <code>NodeDef</code>.
      */
     public void testUndefined()

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ManagerProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ManagerProvider.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ManagerProvider.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ManagerProvider.java
Tue Jun  2 09:52:55 2009
@@ -23,6 +23,7 @@
 import org.apache.jackrabbit.jcr2spi.version.VersionManager;
 import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider;
+import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeDefinitionProvider;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
 
@@ -67,6 +68,8 @@
 
     public ItemDefinitionProvider getItemDefinitionProvider();
 
+    public NodeTypeDefinitionProvider getNodeTypeDefinitionProvider();
+
     public EffectiveNodeTypeProvider getEffectiveNodeTypeProvider();
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
Tue Jun  2 09:52:55 2009
@@ -722,7 +722,7 @@
         // get mixin types present in the jcr:mixintypes property without
         // modifying the NodeState.
         List mixinValue = getMixinTypes();
-        if (!mixinValue.contains(mixinQName)) {
+        if (!mixinValue.contains(mixinQName) && !isNodeType(mixinQName)) {
             if (!canAddMixin(mixinQName)) {
                 throw new ConstraintViolationException("Cannot add '" + mixinName + "' mixin
type.");
             }
@@ -1626,11 +1626,6 @@
             log.error(mixin.getName() + ": not a mixin node type");
             return false;
         }
-        NodeTypeImpl primaryType = ntMgr.getNodeType(getPrimaryNodeTypeName());
-        if (primaryType.isNodeType(mixinName)) {
-            log.debug(mixin.getName() + ": already contained in primary node type");
-            return false;
-        }
 
         // get list of existing nodetypes
         Name[] existingNts = getNodeState().getNodeTypeNames();
@@ -1643,12 +1638,6 @@
             return false;
         }
 
-        // check if adding new mixin conflicts with existing nodetypes
-        if (entExisting.includesNodeType(mixinName)) {
-            log.debug(mixin.getName() + ": already contained in mixin types");
-            return false;
-        }
-
         // second, build new effective node type for nts including the new mixin
         // types, detecting eventual incompatibilities
         Name[] resultingNts = new Name[existingNts.length + 1];

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
Tue Jun  2 09:52:55 2009
@@ -62,6 +62,7 @@
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider;
 import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeDefinitionProvider;
 import org.apache.jackrabbit.jcr2spi.operation.Move;
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
 import org.apache.jackrabbit.jcr2spi.security.AccessManager;
@@ -753,6 +754,13 @@
     }
 
     /**
+     * @see ManagerProvider#getNodeTypeDefinitionProvider()
+     */
+    public NodeTypeDefinitionProvider getNodeTypeDefinitionProvider() {
+        return ntManager;
+    }
+
+    /**
      * @see ManagerProvider#getEffectiveNodeTypeProvider()
      */
     public EffectiveNodeTypeProvider getEffectiveNodeTypeProvider() {

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
Tue Jun  2 09:52:55 2009
@@ -24,6 +24,7 @@
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider;
 import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeDefinitionProvider;
 import org.apache.jackrabbit.jcr2spi.observation.ObservationManagerImpl;
 import org.apache.jackrabbit.jcr2spi.operation.Clone;
 import org.apache.jackrabbit.jcr2spi.operation.Copy;
@@ -467,14 +468,30 @@
         return wspManager.getItemDefinitionProvider();
     }
 
+    /**
+     * @see ManagerProvider#getNodeTypeDefinitionProvider()
+     */
+    public NodeTypeDefinitionProvider getNodeTypeDefinitionProvider() {
+        return session.getNodeTypeManager();
+    }
+
+    /**
+     * @see ManagerProvider#getEffectiveNodeTypeProvider()
+     */
     public EffectiveNodeTypeProvider getEffectiveNodeTypeProvider() {
         return wspManager.getEffectiveNodeTypeProvider();
     }
 
+    /**
+     * @see ManagerProvider#getJcrValueFactory()
+     */
     public ValueFactory getJcrValueFactory() throws RepositoryException {
         return session.getJcrValueFactory();
     }
 
+    /**
+     * @see ManagerProvider#getQValueFactory()
+     */
     public QValueFactory getQValueFactory() throws RepositoryException {
         return session.getQValueFactory();
     }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java
Tue Jun  2 09:52:55 2009
@@ -19,6 +19,7 @@
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -93,12 +94,10 @@
 
     /**
      * @param name
-     * @param nodeTypeName
-     * @param definitionProvider
-     * @throws ConstraintViolationException
-     * @throws NoSuchNodeTypeException
+     * @param nodeTypeDefinition
+     *@param definitionProvider  @throws ConstraintViolationException  @throws NoSuchNodeTypeException
      */
-    public void checkAddNodeConstraints(Name name, Name nodeTypeName, ItemDefinitionProvider
definitionProvider)
+    public void checkAddNodeConstraints(Name name, QNodeTypeDefinition nodeTypeDefinition,
ItemDefinitionProvider definitionProvider)
             throws ConstraintViolationException, NoSuchNodeTypeException;
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
Tue Jun  2 09:52:55 2009
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -406,13 +407,19 @@
 
     /**
      * @inheritDoc
-     * @see EffectiveNodeType#checkAddNodeConstraints(Name, ItemDefinitionProvider)
+     * @see EffectiveNodeType#checkAddNodeConstraints(org.apache.jackrabbit.spi.Name,QNodeTypeDefinition,
ItemDefinitionProvider)
      */
-    public void checkAddNodeConstraints(Name name, Name nodeTypeName, ItemDefinitionProvider
definitionProvider)
+    public void checkAddNodeConstraints(Name name, QNodeTypeDefinition nodeTypeDefinition,
ItemDefinitionProvider definitionProvider)
             throws ConstraintViolationException, NoSuchNodeTypeException {
-        QNodeDefinition nd = definitionProvider.getQNodeDefinition(this, name, nodeTypeName);
+        if (nodeTypeDefinition.isAbstract()) {
+            throw new ConstraintViolationException(name + " is abstract  be used as primary
node type.");
+        }
+        if (nodeTypeDefinition.isMixin()) {
+            throw new ConstraintViolationException(name + " is abstract and cannot be used
as primary node type.");
+        }
+        QNodeDefinition nd = definitionProvider.getQNodeDefinition(this, name, nodeTypeDefinition.getName());
         if (nd.isProtected()) {
-            throw new ConstraintViolationException(name + " is protected");
+            throw new ConstraintViolationException(name + " is protected.");
         }
         if (nd.isAutoCreated()) {
             throw new ConstraintViolationException(name + " is auto-created and can not be
manually added");

Added: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeDefinitionProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeDefinitionProvider.java?rev=780989&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeDefinitionProvider.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeDefinitionProvider.java
Tue Jun  2 09:52:55 2009
@@ -0,0 +1,31 @@
+/*
+ * 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.jcr2spi.nodetype;
+
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>NodeTypeDefinitionProvider</code>...
+ */
+public interface NodeTypeDefinitionProvider {
+
+    public QNodeTypeDefinition getNodeTypeDefinition(Name ntName) throws NoSuchNodeTypeException,
RepositoryException;
+}
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
Tue Jun  2 09:52:55 2009
@@ -129,7 +129,7 @@
      */
     private QPropertyDefinition getApplicablePropDef(Name propertyName, int type, boolean
multiValued)
             throws RepositoryException {
-        return definitionProvider().getQPropertyDefinition(getQName(), propertyName, type,
multiValued);
+        return definitionProvider().getQPropertyDefinition(ntd.getName(), propertyName, type,
multiValued);
     }
 
     /**
@@ -148,12 +148,12 @@
     }
 
     /**
-     * Returns the 'internal', i.e. the fully qualified name.
+     * Returns the node type definition.
      *
-     * @return the qualified name
+     * @return the qualified definition
      */
-    private Name getQName() {
-        return ntd.getName();
+    QNodeTypeDefinition getDefinition() {
+        return ntd;
     }
 
     /**
@@ -493,8 +493,9 @@
      */
     public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
         try {
-            ent.checkAddNodeConstraints(resolver().getQName(childNodeName),
-                resolver().getQName(nodeTypeName), definitionProvider());
+            Name ntName = resolver().getQName(nodeTypeName);
+            QNodeTypeDefinition def = ntMgr.getNodeTypeDefinition(ntName);
+            ent.checkAddNodeConstraints(resolver().getQName(childNodeName), def, definitionProvider());
             return true;
         } catch (NameException be) {
             // implementation specific exception, fall through

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java
Tue Jun  2 09:52:55 2009
@@ -60,7 +60,7 @@
  * A <code>NodeTypeManagerImpl</code> implements a session dependant
  * NodeTypeManager.
  */
-public class NodeTypeManagerImpl extends AbstractNodeTypeManager implements NodeTypeRegistryListener,
Dumpable {
+public class NodeTypeManagerImpl extends AbstractNodeTypeManager implements NodeTypeDefinitionProvider,
NodeTypeRegistryListener, Dumpable {
 
     /**
      * Logger instance for this class
@@ -207,7 +207,16 @@
     NodeTypeRegistry getNodeTypeRegistry() {
         return ntReg;
     }
-    
+
+    //-----------------------------------------< NodeTypeDefinitionProvider >---
+    /**
+     * @see NodeTypeDefinitionProvider#getNodeTypeDefinition(org.apache.jackrabbit.spi.Name)

+     */
+    public QNodeTypeDefinition getNodeTypeDefinition(Name ntName) throws NoSuchNodeTypeException,
RepositoryException {
+        NodeTypeImpl nt = getNodeType(ntName);
+        return nt.getDefinition();
+    }
+
     //-------------------------------------------< NodeTypeRegistryListener >---
     /**
      * {@inheritDoc}

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
Tue Jun  2 09:52:55 2009
@@ -28,6 +28,7 @@
 import org.apache.jackrabbit.spi.QItemDefinition;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -383,7 +384,8 @@
             // make sure there's an applicable definition for new child node
             Name[] ntNames = parentState.getAllNodeTypeNames();
             EffectiveNodeType entParent = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(ntNames);
-            entParent.checkAddNodeConstraints(nodeName, nodeTypeName, mgrProvider.getItemDefinitionProvider());
+            QNodeTypeDefinition def = mgrProvider.getNodeTypeDefinitionProvider().getNodeTypeDefinition(nodeTypeName);
+            entParent.checkAddNodeConstraints(nodeName, def, mgrProvider.getItemDefinitionProvider());
         }
         // collisions
         if ((options & CHECK_COLLISION) == CHECK_COLLISION) {

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml?rev=780989&r1=780988&r2=780989&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml Tue Jun  2 09:52:55 2009
@@ -84,7 +84,6 @@
                 org.apache.jackrabbit.test.api.observation.NodeMovedTest
                 org.apache.jackrabbit.test.api.observation.NodeReorderTest
                 org.apache.jackrabbit.test.api.observation.EventJournalTest
-                org.apache.jackrabbit.test.api.version.RestoreTest#testRestoreNameJcr2
               </value>
             </property>
           </systemProperties>



Mime
View raw message