jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r157172 - in incubator/jackrabbit/trunk: applications/test/repository/nodetypes/ src/test/org/apache/jackrabbit/test/api/nodetype/
Date Fri, 11 Mar 2005 23:03:39 GMT
Author: mreutegg
Date: Fri Mar 11 15:03:38 2005
New Revision: 157172

URL: http://svn.apache.org/viewcvs?view=rev&rev=157172
Log:
Test cases for NodeDef.canAddChildNode()

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
  (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithoutNodeTypeTest.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custom_nodetypes.xml
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java

Modified: incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custom_nodetypes.xml
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custom_nodetypes.xml?view=diff&r1=157171&r2=157172
==============================================================================
--- incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custom_nodetypes.xml
(original)
+++ incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custom_nodetypes.xml
Fri Mar 11 15:03:38 2005
@@ -183,6 +183,22 @@
     </propertyDef>
   </nodeType>
 
+  <!-- Defines a nodetype for testing NodeType.canAddChildNode() -->
+  <nodeType name="test:canAddChildNode" mixin="false" orderableChildNodes="false" primaryItemName="">
+    <supertypes>
+      <supertype>nt:base</supertype>
+    </supertypes>
+    <childNodeDef name="testChildWithDefaultType" defaultPrimaryType="nt:base" autoCreate="false"
mandatory="false" onParentVersion="COPY" protected="false" sameNameSibs="false">
+      <requiredPrimaryTypes>
+        <requiredPrimaryType>nt:base</requiredPrimaryType>
+      </requiredPrimaryTypes>
+    </childNodeDef>
+    <childNodeDef name="testChildWithoutDefaultType" defaultPrimaryType="" autoCreate="false"
mandatory="false" onParentVersion="COPY" protected="false" sameNameSibs="false">
+      <requiredPrimaryTypes>
+        <requiredPrimaryType>nt:base</requiredPrimaryType>
+      </requiredPrimaryTypes>
+    </childNodeDef>
+  </nodeType>
 
 </nodeTypes>
 

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java?view=auto&rev=157172
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
Fri Mar 11 15:03:38 2005
@@ -0,0 +1,200 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.test.api.nodetype;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.Session;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeDef;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
+
+/**
+ * Tests <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
+ * returns true if a node of name <code>childNodeName</code> and of node type
+ * <code>childNodeName</code> could be added to a node of type <code>NodeType</code>.
+ *
+ * @test
+ * @sources CanAddChildNodeCallWithNodeTypeTest.java
+ * @executeClass org.apache.jackrabbit.test.api.nodetype.CanAddChildNodeCallWithNodeTypeTest
+ * @keywords level1
+ */
+public class CanAddChildNodeCallWithNodeTypeTest extends AbstractJCRTest {
+    /**
+     * The session we use for the tests
+     */
+    private Session session;
+
+    /**
+     * The node type manager we use for the tests
+     */
+    private NodeTypeManager manager;
+
+    /**
+     * Sets up the fixture for the test cases.
+     */
+    protected void setUp() throws Exception {
+        isReadOnly = true;
+        super.setUp();
+
+        session = helper.getReadOnlySession();
+        manager = session.getWorkspace().getNodeTypeManager();
+    }
+
+    /**
+     * Releases the session aquired in {@link #setUp()}.
+     */
+    protected void tearDown() throws Exception {
+        if (session != null) {
+            session.logout();
+        }
+        super.tearDown();
+    }
+
+    /**
+     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
+     * returns true if <code>childNodeName</code> and <code>nodeTypeName</code>
+     * match the <code>ChildNodeDef</code>.
+     */
+    public void testDefinedAndLegalType()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDef nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No child node def with " +
+                                             "defaultPrimaryType found");
+        }
+
+        NodeType nodeType = nodeDef.getDeclaringNodeType();
+        String childNodeName = nodeDef.getName();
+        String nodeTypeName = nodeDef.getRequiredPrimaryTypes()[0].getName();
+
+        assertTrue("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) "
+
+                   "must return true if childNodeName and nodeTypeName match the " +
+                   "child node def of NodeType.",
+                   nodeType.canAddChildNode(childNodeName, nodeTypeName));
+    }
+
+    /**
+     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
+     * returns false if <code>childNodeName</code> does and <code>nodeTypeName</code>
+     * does not match the <code>ChildNodeDef</code>.
+     */
+    public void testDefinedAndIllegalType()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDef 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 legalType = nodeDef.getRequiredPrimaryTypes()[0].getName();
+        String illegalType = NodeTypeUtil.getIllegalChildNodeType(manager, legalType);
+        if (illegalType == null) {
+            throw new NotExecutableException("No illegal node type name found");
+        }
+
+        assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName)
" +
+                    "must return false if childNodeName does and nodeTypeName does not "
+
+                    "match the child node def of NodeType.",
+                    nodeType.canAddChildNode(childNodeName, illegalType));
+    }
+
+    /**
+     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
+     * returns false if <code>childNodeName</code> does not match the <code>ChildNodeDef</code>.
+     */
+    public void testUndefined()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDef nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, true, false);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No testable node type found.");
+        }
+
+        String type = nodeDef.getRequiredPrimaryTypes()[0].getName();
+        NodeType nodeType = nodeDef.getDeclaringNodeType();
+        String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
+
+        assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName)
" +
+                    "must return false if childNodeName does not match the " +
+                    "child node def of NodeType.",
+                    nodeType.canAddChildNode(undefinedName, type));
+    }
+
+    /**
+     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
+     * returns true if <code>childNodeName</code> does not match the <code>ChildNodeDef</code>
+     * but <code>nodeTypeName</code> matches the node type of a residual <code>ChildNodeDef</code>.
+     */
+    public void testResidualAndLegalType()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDef nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, true);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No testable residual child node def.");
+        }
+
+        String type = nodeDef.getRequiredPrimaryTypes()[0].getName();
+        NodeType nodeType = nodeDef.getDeclaringNodeType();
+        String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
+
+        assertTrue("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) "
+
+                   "must return true for a not defined childNodeName if nodeTypeName " +
+                   "matches the type of a residual child node def",
+                   nodeType.canAddChildNode(undefinedName, type));
+    }
+
+    /**
+     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
+     * returns false if <code>childNodeName</code> does not match the <code>ChildNodeDef</code>
+     * and <code>nodeTypeName</code> does not matches the node type of a residual
+     * <code>ChildNodeDef</code>.
+     */
+    public void testResidualAndIllegalType()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDef nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, true);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No testable residual child node def.");
+        }
+
+        NodeType nodeType = nodeDef.getDeclaringNodeType();
+        String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
+
+        String legalType = nodeDef.getRequiredPrimaryTypes()[0].getName();
+        String illegalType = NodeTypeUtil.getIllegalChildNodeType(manager, legalType);
+        if (illegalType == null) {
+            throw new NotExecutableException("No illegal node type name found");
+        }
+
+        assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName)
" +
+                    "must return false for a not defined childNodeName if nodeTypeName "
+
+                    "does not matches the type of a residual child node def",
+                    nodeType.canAddChildNode(undefinedName, illegalType));
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithoutNodeTypeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithoutNodeTypeTest.java?view=auto&rev=157172
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithoutNodeTypeTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithoutNodeTypeTest.java
Fri Mar 11 15:03:38 2005
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.test.api.nodetype;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+import javax.jcr.Session;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeDef;
+
+/**
+ * Tests <code>NodeType.canAddChildNode(String childNodeName)</code> returns
true if
+ * a node of name <code>childNodeName</code> could be added to a node of
+ * type <code>NodeType</code>.
+ *
+ * @test
+ * @sources CanAddChildNodeCallWithoutNodeTypeTest.java
+ * @executeClass org.apache.jackrabbit.test.api.nodetype.CanAddChildNodeCallWithoutNodeTypeTest
+ * @keywords level1
+ */
+public class CanAddChildNodeCallWithoutNodeTypeTest extends AbstractJCRTest {
+
+    /**
+     * The session we use for the tests
+     */
+    private Session session;
+
+    /**
+     * Sets up the fixture for the test cases.
+     */
+    protected void setUp() throws Exception {
+        isReadOnly = true;
+        super.setUp();
+
+        session = helper.getReadOnlySession();
+    }
+
+    /**
+     * Releases the session aquired in {@link #setUp()}.
+     */
+    protected void tearDown() throws Exception {
+        if (session != null) {
+            session.logout();
+        }
+        super.tearDown();
+    }
+
+    /**
+     * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns
+     * true if <code>NodeType</code> contains a <code>ChildNodeDef</code>
 named
+     * <code>childNodeName</code> with a default primary type.
+     */
+    public void testDefinedWithDefault()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDef nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, true, false);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No child node def with " +
+                                             "defaultPrimaryType found");
+        }
+
+        NodeType nodeType = nodeDef.getDeclaringNodeType();
+
+        assertTrue("NodeType.canAddChildNode(String childNodeName) must return " +
+                   "true if child node def 'childNodeName' defines a defaultPrimaryType.",
+                   nodeType.canAddChildNode(nodeDef.getName()));
+    }
+
+    /**
+     * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns
+     * true if <code>NodeType</code> contains a <code>ChildNodeDef</code>
 named
+     * <code>childNodeName</code> without a default primary type.
+     */
+    public void testDefinedWithoutDefault()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDef nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, false, false);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No child node def without " +
+                                             "defaultPrimaryType found");
+        }
+
+        NodeType nodeType = nodeDef.getDeclaringNodeType();
+
+        assertFalse("NodeType.canAddChildNode(String childNodeName) must return false " +
+                    "if child node def 'childNodeName' does not define a defaultPrimaryType.",
+                    nodeType.canAddChildNode(nodeDef.getName()));
+    }
+
+    /**
+     * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns
+     * true if <code>NodeType</code> nor does contain a <code>ChildNodeDef</code>
 named
+     * <code>childNodeName</code> nor a residual definition.
+     *
+     */
+    public void testUndefined()
+        throws NotExecutableException, RepositoryException {
+
+        NodeDef nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, true, false);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No testable node type found.");
+        }
+
+        NodeType nodeType = nodeDef.getDeclaringNodeType();
+        String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
+
+        assertFalse("NodeType.canAddChildNode(String childNodeName) must return " +
+                    "false if 'childNodeName' is a undefined child node def",
+                    nodeType.canAddChildNode(undefinedName));
+    }
+
+    /**
+     * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns
+     * true if <code>NodeType</code> contains a residual <code>ChildNodeDef</code>
+     * with a default primary type.
+     */
+    public void testResidualWithDefault()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDef nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, true, true);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No residual child node def " +
+                                             "without a defaultPrimaryType found.");
+        }
+
+        NodeType nodeType = nodeDef.getDeclaringNodeType();
+        String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
+
+        assertTrue("NodeType.canAddChildNode(String childNodeName) must return " +
+                   "true for a not defined childNodeName if NodeType has a residual child
node " +
+                   "definition with a defaultPrimaryType",
+                   nodeType.canAddChildNode(undefinedName));
+    }
+
+    /**
+     * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns
+     * true if <code>NodeType</code> contains a residual <code>ChildNodeDef</code>
+     * without a default primary type.
+     */
+    public void testResidualWithoutDefault()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDef nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, false, true);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No residual child node def " +
+                                             "with a defaultPrimaryType found.");
+        }
+
+        NodeType nodeType = nodeDef.getDeclaringNodeType();
+        String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
+
+        assertFalse("NodeType.canAddChildNode(String childNodeName) must return " +
+                    "false for a not defiend childNodeName if NodeType has a " +
+                    "residual child node definition without a defaultPrimaryType",
+                    nodeType.canAddChildNode(undefinedName));
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithoutNodeTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java?view=diff&r1=157171&r2=157172
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
Fri Mar 11 15:03:38 2005
@@ -16,10 +16,6 @@
  */
 package org.apache.jackrabbit.test.api.nodetype;
 
-import javax.jcr.nodetype.PropertyDef;
-import javax.jcr.nodetype.NodeTypeManager;
-import javax.jcr.nodetype.NodeTypeIterator;
-import javax.jcr.nodetype.NodeType;
 import javax.jcr.Session;
 import javax.jcr.RepositoryException;
 import javax.jcr.PropertyType;
@@ -33,6 +29,11 @@
 import javax.jcr.NameValue;
 import javax.jcr.PathValue;
 import javax.jcr.StringValue;
+import javax.jcr.nodetype.NodeDef;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeTypeIterator;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDef;
 import javax.jcr.util.ISO8601;
 import java.util.Calendar;
 import java.util.regex.Pattern;
@@ -44,6 +45,68 @@
  */
 class NodeTypeUtil {
 
+    public static NodeDef locateChildNodeDef(Session session,
+                                             boolean regardDefaultPrimaryType,
+                                             boolean defaultPrimaryType,
+                                             boolean residual)
+        throws RepositoryException {
+
+        NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
+        NodeTypeIterator types = manager.getAllNodeTypes();
+
+        boolean overjump = false;
+
+        while (types.hasNext()) {
+            NodeType type = types.nextNodeType();
+            NodeDef nodeDefs[] = type.getDeclaredChildNodeDefs();
+
+            for (int i = 0; i < nodeDefs.length; i++) {
+                NodeDef nodeDef = nodeDefs[i];
+
+                if (nodeDef.getRequiredPrimaryTypes().length > 1) {
+                    // behaviour of implementations that support multiple multiple inheritance
+                    // of primary node types is not specified
+                    continue;
+                }
+
+                if (regardDefaultPrimaryType) {
+
+                    if (defaultPrimaryType && nodeDef.getDefaultPrimaryType() ==
null) {
+                        continue;
+                    }
+
+                    if (!defaultPrimaryType && nodeDef.getDefaultPrimaryType() !=
null) {
+                        continue;
+                    }
+                }
+
+                if (residual && !nodeDef.getName().equals("*")) {
+                    continue;
+                }
+
+                if (!residual && i == 0) {
+                    // if another child node def is a residual definition
+                    // overjump the current node type
+                    NodeDef nodeDefsAll[] = type.getChildNodeDefs();
+                    for (int j = 0; j < nodeDefsAll.length; j++) {
+                        if (nodeDefsAll[j].getName().equals("*")) {
+                            overjump = true;
+                            break;
+                        }
+                    }
+                    if (overjump) {
+                        // break the loop of the current child not defs
+                        overjump = false;
+                        break;
+                    }
+                }
+
+                return nodeDef;
+            }
+        }
+        return null;
+    }
+
     /**
      * Locate a property def parsing all node types
      *
@@ -130,48 +193,78 @@
     }
 
     /**
+     * Returns a name that is not defined by the nodeType's child node def
+     */
+    public static String getUndefinedChildNodeName(NodeType nodeType) {
+
+        NodeDef nodeDefs[] = nodeType.getChildNodeDefs();
+        StringBuffer s = new StringBuffer("X");
+
+        for (int i = 0; i < nodeDefs.length; i++) {
+            s.append(nodeDefs[i].getName());
+        }
+        String undefinedName = s.toString();
+        undefinedName = undefinedName.replaceAll("\\*", "");
+        undefinedName = undefinedName.replaceAll(":", "");
+        return undefinedName;
+    }
+
+    /**
+     * Returns a node type that is nor legalType nor a sub type of of
+     */
+    public static String getIllegalChildNodeType(NodeTypeManager manager,
+                                                 String legalType)
+            throws RepositoryException {
+
+        NodeTypeIterator types = manager.getAllNodeTypes();
+        while (types.hasNext()) {
+            NodeType type = types.nextNodeType();
+            NodeType superTypes[] = type.getSupertypes();
+            boolean isSubType = false;
+            for (int i = 0; i < superTypes.length; i++) {
+                String name = superTypes[i].getName();
+                if (name.equals(legalType)) {
+                    isSubType = true;
+                    break;
+                }
+            }
+            if (!isSubType) {
+                return type.getName();
+            }
+        }
+        return null;
+    }
+
+    /**
      * Returns any value of the requested type
      */
     public static Value getValueOfType(int type) throws ValueFormatException {
         switch (type) {
             case (PropertyType.BINARY):
-                {
-                    // note: If binary is not UTF-8 behavior is implementation-specific
-                    return new BinaryValue("abc");
-                }
+                // note: If binary is not UTF-8 behavior is implementation-specific
+               return new BinaryValue("abc");
             case (PropertyType.BOOLEAN):
-                {
-                    return new BooleanValue(true);
-                }
+                return new BooleanValue(true);
             case (PropertyType.DATE):
-                {
-                    return new DateValue(Calendar.getInstance());
-                }
+                return new DateValue(Calendar.getInstance());
             case (PropertyType.DOUBLE):
-                {
-                    return new DoubleValue(1.0);
-                }
+                return new DoubleValue(1.0);
             case (PropertyType.LONG):
-                {
-                    return new LongValue(1);
-                }
+                return new LongValue(1);
             case (PropertyType.NAME):
-                {
-                    return NameValue.valueOf("abc");
-                }
+                return NameValue.valueOf("abc");
             case (PropertyType.PATH):
-                {
-                    return PathValue.valueOf("/abc");
-                }
+                return PathValue.valueOf("/abc");
             default:
-                {
-                    // STRING and UNDEFINED
-                    // note: REFERENCE is not testable since its format is implementation-specific
-                    return new StringValue("abc");
-                }
+                // STRING and UNDEFINED
+                // note: REFERENCE is not testable since its format is implementation-specific
+                return new StringValue("abc");
         }
     }
 
+    /**
+     * Returns a value out of the value constraints
+     */
     public static Value getValueOutOfContstraint(PropertyDef propDef)
             throws ValueFormatException, RepositoryException, ParseException {
 



Mime
View raw message