Index: modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeTypeManager.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeTypeManager.java (revision 1786) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeTypeManager.java (working copy) @@ -148,6 +148,29 @@ public class JcrNodeTypeManager implements NodeTypeManager { } /** + * Returns true if and only if the node type with the given name exists. + *

+ * This is equivalent to the following code: + * + *

+     * try {
+     *     getNodeType(nodeTypeName);
+     *     return true;
+     * } catch (NoSuchNodeTypeException nsnte) {
+     *     return false;
+     * }
+     * 
+ * However, the implementation is slightly more efficient that the approach listed above. + *

+ * + * @see RepositoryNodeTypeManager#hasNodeType(Name) + */ + public boolean hasNodeType( String nodeTypeName ) { + Name ntName = context().getValueFactories().getNameFactory().create(nodeTypeName); + return repositoryTypeManager.hasNodeType(ntName); + } + + /** * {@inheritDoc} * * @see javax.jcr.nodetype.NodeTypeManager#getPrimaryNodeTypes() Index: modeshape-jcr/src/main/java/org/modeshape/jcr/RepositoryNodeTypeManager.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/RepositoryNodeTypeManager.java (revision 1786) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/RepositoryNodeTypeManager.java (working copy) @@ -275,6 +275,25 @@ class RepositoryNodeTypeManager { } /** + * Tests if the named node type is registered. + *

+ * The return value of this method is equivalent to {@code getNodeType(nodeTypeName) != null}, although the implementation is + * marginally more efficient that this approach. + *

+ * + * @param nodeTypeName the name of the node type to check + * @return true if a node type with the given name is registered, false otherwise + */ + boolean hasNodeType( Name nodeTypeName ) { + try { + nodeTypeManagerLock.readLock().lock(); + return nodeTypes.containsKey(nodeTypeName); + } finally { + nodeTypeManagerLock.readLock().unlock(); + } + } + + /** * Searches the supplied primary node type and the mixin node types for a property definition that is the best match for the * given property name, property type, and value. *

Index: modeshape-jcr/src/test/java/org/modeshape/jcr/JcrNodeTypeManagerTest.java =================================================================== --- modeshape-jcr/src/test/java/org/modeshape/jcr/JcrNodeTypeManagerTest.java (revision 1786) +++ modeshape-jcr/src/test/java/org/modeshape/jcr/JcrNodeTypeManagerTest.java (working copy) @@ -206,4 +206,18 @@ public final class JcrNodeTypeManagerTest extends TestSuite { session.save(); } + + @Test + public void shouldReturnTrueForHasNodeTypeWithExistingNodeTypeName() throws Exception { + assertTrue(nodeTypeMgr.hasNodeType("nt:base")); + assertTrue(nodeTypeMgr.hasNodeType(HIERARCHY_NODE_TYPE)); + assertTrue(nodeTypeMgr.hasNodeType(MIXIN1)); + + } + + @Test + public void shouldReturnFalseForHasNodeTypeWithNonexistantNodeTypeName() throws Exception { + assertFalse(nodeTypeMgr.hasNodeType("someArgleBargle")); + assertFalse(nodeTypeMgr.hasNodeType(HIERARCHY_NODE_TYPE + "x")); + } }