jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r766747 - in /jackrabbit/branches/1.5/jackrabbit-jcr2spi/src: main/java/org/apache/jackrabbit/jcr2spi/nodetype/ test/java/org/apache/jackrabbit/jcr2spi/nodetype/
Date Mon, 20 Apr 2009 16:41:30 GMT
Author: mduerig
Date: Mon Apr 20 16:41:29 2009
New Revision: 766747

URL: http://svn.apache.org/viewvc?rev=766747&view=rev
Log:
1.5: Backported revision 741509 (JCR-1967)

Added:
    jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImplTest.java
  (with props)
Modified:
    jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
    jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/TestAll.java

Modified: jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java?rev=766747&r1=766746&r2=766747&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
(original)
+++ jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
Mon Apr 20 16:41:29 2009
@@ -45,7 +45,7 @@
 import java.util.ArrayList;
 
 /**
- * A <code>NodeTypeImpl</code> ...
+ * <code>NodeTypeImpl</code> ...
  */
 public class NodeTypeImpl implements NodeType {
 
@@ -66,7 +66,7 @@
      * @param ent        the effective (i.e. merged and resolved) node type representation
      * @param ntd        the definition of this node type
      * @param ntMgr      the node type manager associated with this node type
-     * @param mgrProvider
+     * @param mgrProvider the manager provider
      */
     NodeTypeImpl(EffectiveNodeType ent, QNodeTypeDefinition ntd,
                  NodeTypeManagerImpl ntMgr, ManagerProvider mgrProvider) {
@@ -89,11 +89,14 @@
     }
 
     /**
-     * ValueFactory used to convert JCR values to qualified ones in order to
-     * determine whether a property specified by name and value(s) would be allowed.
+     * ValueFactory used to convert JCR values from one type to another in order
+     * to determine whether a property specified by name and value(s) would be
+     * allowed.
      *
      * @see NodeType#canSetProperty(String, Value)
      * @see NodeType#canSetProperty(String, Value[])
+     * @return ValueFactory used to convert JCR values.
+     * @throws javax.jcr.RepositoryException If an error occurs.
      */
     private ValueFactory valueFactory() throws RepositoryException {
         return mgrProvider.getJcrValueFactory();
@@ -102,6 +105,9 @@
     /**
      * ValueFactory used to convert JCR values to qualified ones in order to
      * determine value constraints within the NodeType interface.
+     *
+     * @return ValueFactory used to convert JCR values to qualified ones.
+     * @throws javax.jcr.RepositoryException If an error occurs.
      */
     private QValueFactory qValueFactory() throws RepositoryException {
         return mgrProvider.getQValueFactory();
@@ -124,15 +130,27 @@
     }
 
     /**
-     * Checks if this node type's name equals the given name or if this nodetype
-     * is directly or indirectly derived from the specified node type.
+     * Test if this nodetype equals or is directly or indirectly derived from
+     * the node type with the specified <code>nodeTypeName</code>, without
+     * checking of a node type of that name really exists.
      *
-     * @param nodeTypeName
-     * @return true if this node type is equal or directly or indirectly derived
-     * from the specified node type, otherwise false.
+     * @param nodeTypeName A node type name.
+     * @return true if this node type represents the type with the given
+     * <code>nodeTypeName</code> or if it is directly or indirectly derived
+     * from it; otherwise <code>false</code>. If no node type exists with the
+     * specified name this method will also return <code>false</code>.
      */
     public boolean isNodeType(Name nodeTypeName) {
-        return getName().equals(nodeTypeName) ||  ent.includesNodeType(nodeTypeName);
+        return ent.includesNodeType(nodeTypeName);
+    }
+
+    /**
+     * Returns the 'internal', i.e. the fully qualified name.
+     *
+     * @return the qualified name
+     */
+    private Name getQName() {
+        return ntd.getName();
     }
 
     /**
@@ -145,27 +163,18 @@
      *
      * @param def    The definiton of the property
      * @param values An array of <code>QValue</code> objects.
-     * @throws ConstraintViolationException
-     * @throws RepositoryException
+     * @throws ConstraintViolationException If a constraint is violated.
+     * @throws RepositoryException If another error occurs.
      */
     private static void checkSetPropertyValueConstraints(QPropertyDefinition def,
                                                         QValue[] values)
             throws ConstraintViolationException, RepositoryException {
         ValueConstraint.checkValueConstraints(def, values);
     }
-
-    /**
-     * Returns the 'internal', i.e. the fully qualified name.
-     *
-     * @return the qualified name
-     */
-    private Name getQName() {
-        return ntd.getName();
-    }
-
+    
     //-----------------------------------------------------------< NodeType >---
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#getName()
      */
     public String getName() {
         try {
@@ -178,7 +187,7 @@
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#getPrimaryItemName()
      */
     public String getPrimaryItemName() {
         try {
@@ -196,14 +205,14 @@
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#isMixin()
      */
     public boolean isMixin() {
         return ntd.isMixin();
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#isNodeType(String)
      */
     public boolean isNodeType(String nodeTypeName) {
         Name ntName;
@@ -220,14 +229,14 @@
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#hasOrderableChildNodes()
      */
     public boolean hasOrderableChildNodes() {
         return ntd.hasOrderableChildNodes();
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#getSupertypes()
      */
     public NodeType[] getSupertypes() {
         Name[] ntNames = ent.getInheritedNodeTypes();
@@ -245,7 +254,7 @@
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#getChildNodeDefinitions()
      */
     public NodeDefinition[] getChildNodeDefinitions() {
         QNodeDefinition[] cnda = ent.getAllQNodeDefinitions();
@@ -257,7 +266,7 @@
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#getPropertyDefinitions()
      */
     public PropertyDefinition[] getPropertyDefinitions() {
         QPropertyDefinition[] pda = ent.getAllQPropertyDefinitions();
@@ -269,7 +278,19 @@
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#getDeclaredPropertyDefinitions()
+     */
+    public PropertyDefinition[] getDeclaredPropertyDefinitions() {
+        QPropertyDefinition[] pda = ntd.getPropertyDefs();
+        PropertyDefinition[] propDefs = new PropertyDefinition[pda.length];
+        for (int i = 0; i < pda.length; i++) {
+            propDefs[i] = ntMgr.getPropertyDefinition(pda[i]);
+        }
+        return propDefs;
+    }
+
+    /**
+     * @see javax.jcr.nodetype.NodeType#getDeclaredSupertypes()
      */
     public NodeType[] getDeclaredSupertypes() {
         Name[] ntNames = ntd.getSupertypes();
@@ -287,7 +308,7 @@
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#getDeclaredChildNodeDefinitions()
      */
     public NodeDefinition[] getDeclaredChildNodeDefinitions() {
         QNodeDefinition[] cnda = ntd.getChildNodeDefs();
@@ -299,7 +320,7 @@
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#canSetProperty(String, Value)
      */
     public boolean canSetProperty(String propertyName, Value value) {
         if (value == null) {
@@ -344,7 +365,7 @@
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#canSetProperty(String, Value[])
      */
     public boolean canSetProperty(String propertyName, Value[] values) {
         if (values == null) {
@@ -416,7 +437,7 @@
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#canAddChildNode(String)
      */
     public boolean canAddChildNode(String childNodeName) {
         try {
@@ -431,7 +452,7 @@
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#canAddChildNode(String, String) 
      */
     public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
         try {
@@ -447,7 +468,7 @@
     }
 
     /**
-     * {@inheritDoc}
+     * @see javax.jcr.nodetype.NodeType#canRemoveItem(String) 
      */
     public boolean canRemoveItem(String itemName) {
         try {
@@ -460,16 +481,4 @@
         }
         return false;
     }
-
-    /**
-     * {@inheritDoc}
-     */
-    public PropertyDefinition[] getDeclaredPropertyDefinitions() {
-        QPropertyDefinition[] pda = ntd.getPropertyDefs();
-        PropertyDefinition[] propDefs = new PropertyDefinition[pda.length];
-        for (int i = 0; i < pda.length; i++) {
-            propDefs[i] = ntMgr.getPropertyDefinition(pda[i]);
-        }
-        return propDefs;
-    }
 }

Added: jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImplTest.java?rev=766747&view=auto
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImplTest.java
(added)
+++ jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImplTest.java
Mon Apr 20 16:41:29 2009
@@ -0,0 +1,72 @@
+/*
+ * 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.commons.conversion.NameResolver;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
+
+/**
+ * <code>NodeTypeImplTest</code>...
+ */
+public class NodeTypeImplTest extends AbstractJCRTest {
+
+    private NodeTypeManager ntMgr;
+    private NodeTypeImpl nodeType;
+    private NameResolver resolver;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        ntMgr = superuser.getWorkspace().getNodeTypeManager();
+        NodeType nt = ntMgr.getNodeType(testNodeType);
+        if (nt instanceof NodeTypeImpl) {
+            nodeType = (NodeTypeImpl) nt;
+        } else {
+            throw new NotExecutableException("NodeTypeImpl expected.");
+        }
+
+        if (superuser instanceof NameResolver) {
+            resolver = (NameResolver) superuser;
+        } else {
+             throw new NotExecutableException();
+        }
+    }
+
+    public void testIsNodeType() throws RepositoryException {
+        NodeType[] superTypes = nodeType.getSupertypes();
+
+        for (int i = 0; i < superTypes.length; i++) {
+            String name = superTypes[i].getName();
+            assertTrue(nodeType.isNodeType(resolver.getQName(name)));
+        }
+
+        // unknown nt
+        String unknownName = "unknown";
+        assertFalse(nodeType.isNodeType(unknownName));
+
+        // all non-mixin node types must be derived from nt base.
+        if (!nodeType.isMixin()) {
+            assertTrue(nodeType.isNodeType("nt:base"));
+        }
+    }
+
+}

Propchange: jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/TestAll.java?rev=766747&r1=766746&r2=766747&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/TestAll.java
(original)
+++ jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/TestAll.java
Mon Apr 20 16:41:29 2009
@@ -32,6 +32,8 @@
         suite.addTestSuite(RemoveMixinTest.class);
         suite.addTestSuite(MandatoryItemTest.class);
 
+        suite.addTestSuite(NodeTypeImplTest.class);
+
         return suite;
     }
 }



Mime
View raw message