Index: modeshape-jcr/src/main/java/org/modeshape/jcr/JcrItemDefinitionTemplate.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/JcrItemDefinitionTemplate.java (revision 1813) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/JcrItemDefinitionTemplate.java (working copy) @@ -27,7 +27,9 @@ import javax.jcr.nodetype.ItemDefinition; import javax.jcr.nodetype.NodeType; import javax.jcr.version.OnParentVersionAction; import net.jcip.annotations.NotThreadSafe; +import org.modeshape.common.util.CheckArg; import org.modeshape.graph.ExecutionContext; +import org.modeshape.graph.property.Name; /** * ModeShape convenience implementation to support the JCR 2 NodeDefinitionTemplate and PropertyDefinitionTemplate classes. @@ -39,8 +41,8 @@ abstract class JcrItemDefinitionTemplate implements ItemDefinition { private boolean autoCreated = false; private boolean mandatory = false; private boolean isProtected = false; - private String name; - private int onParentVersion = OnParentVersionAction.IGNORE; + private Name name; + private int onParentVersion = OnParentVersionAction.COPY; JcrItemDefinitionTemplate( ExecutionContext context ) { assert context != null; @@ -67,7 +69,8 @@ abstract class JcrItemDefinitionTemplate implements ItemDefinition { * @see javax.jcr.nodetype.ItemDefinition#getName() */ public String getName() { - return name; + if (name == null) return null; + return name.getString(context.getNamespaceRegistry()); } /** @@ -123,7 +126,8 @@ abstract class JcrItemDefinitionTemplate implements ItemDefinition { } public void setName( String name ) { - this.name = name; + CheckArg.isNotEmpty(name, "name"); + this.name = context.getValueFactories().getNameFactory().create(name); } public void setOnParentVersion( int onParentVersion ) { Index: modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeDefinitionTemplate.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeDefinitionTemplate.java (revision 1813) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeDefinitionTemplate.java (working copy) @@ -25,7 +25,6 @@ package org.modeshape.jcr; import javax.jcr.nodetype.NodeType; import net.jcip.annotations.NotThreadSafe; -import org.modeshape.common.util.CheckArg; import org.modeshape.graph.ExecutionContext; import org.modeshape.jcr.nodetype.NodeDefinitionTemplate; @@ -49,6 +48,15 @@ class JcrNodeDefinitionTemplate extends JcrItemDefinitionTemplate implements Nod * @see org.modeshape.jcr.nodetype.NodeDefinitionTemplate#setDefaultPrimaryType(String) */ public void setDefaultPrimaryType( String defaultPrimaryType ) { + setDefaultPrimaryTypeName(defaultPrimaryType); + } + + /** + * Set the name of the primary type that should be used by default when creating children using this node definition + * + * @param defaultPrimaryType the default primary type for this child node + */ + public void setDefaultPrimaryTypeName( String defaultPrimaryType ) { this.defaultPrimaryType = defaultPrimaryType; } @@ -56,9 +64,19 @@ class JcrNodeDefinitionTemplate extends JcrItemDefinitionTemplate implements Nod * {@inheritDoc} * * @see org.modeshape.jcr.nodetype.NodeDefinitionTemplate#setRequiredPrimaryTypes(java.lang.String[]) + * @deprecated Use {@link #setRequiredPrimaryTypeNames(String[])} instead */ public void setRequiredPrimaryTypes( String[] requiredPrimaryTypes ) { - CheckArg.isNotNull(requiredPrimaryTypes, "requiredPrimaryTypes"); + setRequiredPrimaryTypeNames(requiredPrimaryTypes); + } + + /** + * SSet the names of the primary types that must appear on the child(ren) described by this definition + * + * @param requiredPrimaryTypes the names of the required primary types, or null or empty if there are no requirements for the + * primary types of the children described by this definition + */ + public void setRequiredPrimaryTypeNames( String[] requiredPrimaryTypes ) { this.requiredPrimaryTypes = requiredPrimaryTypes; } Index: modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeTypeManager.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeTypeManager.java (revision 1813) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeTypeManager.java (working copy) @@ -25,6 +25,7 @@ package org.modeshape.jcr; import java.security.AccessControlException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -525,6 +526,43 @@ public class JcrNodeTypeManager implements NodeTypeManager { } /** + * Registers or updates the specified array of {@code NodeTypeDefinition} objects. This method is used to register or update a + * set of node types with mutual dependencies. Returns an iterator over the resulting {@code NodeType} objects. + *

+ * The effect of the method is "all or nothing"; if an error occurs, no node types are registered or updated. + *

+ * + * @param ntds the new node types to register + * @param allowUpdate must be {@code false}; ModeShape does not allow updating node types at this time + * @return the {@code newly created node types} + * @throws InvalidNodeTypeDefinitionException if a {@code NodeTypeDefinition} within the collection is invalid + * @throws NodeTypeExistsException if {@code allowUpdate} is false and a {@code NodeTypeDefinition} within the collection + * specifies a node type name that already exists + * @throws UnsupportedRepositoryOperationException if {@code allowUpdate} is true; ModeShape does not allow updating node + * types at this time. + * @throws AccessDeniedException if the current session does not have the {@link ModeShapePermissions#REGISTER_TYPE register + * type permission}. + * @throws RepositoryException if another error occurs + */ + public NodeTypeIterator registerNodeTypes( NodeTypeDefinition[] ntds, + boolean allowUpdate ) + throws InvalidNodeTypeDefinitionException, NodeTypeExistsException, UnsupportedRepositoryOperationException, + RepositoryException { + + try { + session.checkPermission((Path)null, ModeShapePermissions.REGISTER_TYPE); + } catch (AccessControlException ace) { + throw new AccessDeniedException(ace); + } + + try { + return new JcrNodeTypeIterator(this.repositoryTypeManager.registerNodeTypes(Arrays.asList(ntds), allowUpdate)); + } finally { + schemata = null; + } + } + + /** * Unregisters the named node type if it is not referenced by other node types as a supertype, a default primary type of a * child node (or nodes), or a required primary type of a child node (or nodes). * @@ -538,7 +576,7 @@ public class JcrNodeTypeManager implements NodeTypeManager { */ public void unregisterNodeType( String nodeTypeName ) throws NoSuchNodeTypeException, InvalidNodeTypeDefinitionException, RepositoryException { - unregisterNodeType(Collections.singleton(nodeTypeName)); + unregisterNodeTypes(Collections.singleton(nodeTypeName)); } /** @@ -554,7 +592,7 @@ public class JcrNodeTypeManager implements NodeTypeManager { * type permission}. * @throws RepositoryException if any other error occurs */ - public void unregisterNodeType( Collection nodeTypeNames ) + public void unregisterNodeTypes( Collection nodeTypeNames ) throws NoSuchNodeTypeException, InvalidNodeTypeDefinitionException, RepositoryException { NameFactory nameFactory = context().getValueFactories().getNameFactory(); @@ -573,6 +611,23 @@ public class JcrNodeTypeManager implements NodeTypeManager { } /** + * Allows the collection of node types to be unregistered if they are not referenced by other node types as supertypes, + * default primary types of child nodes, or required primary types of child nodes. + * + * @param names the names of the node types to be unregistered + * @throws NoSuchNodeTypeException if any of the node type names do not correspond to a registered node type + * @throws InvalidNodeTypeDefinitionException if any of the node types with the given names cannot be unregistered because + * they are the supertype, one of the required primary types, or a default primary type of a node type that is not + * being unregistered. + * @throws AccessDeniedException if the current session does not have the {@link ModeShapePermissions#REGISTER_TYPE register + * type permission}. + * @throws RepositoryException if any other error occurs + */ + public void unregisterNodeTypes( String[] names ) throws NoSuchNodeTypeException, RepositoryException { + unregisterNodeTypes(Arrays.asList(names)); + } + + /** * Returns an empty {@code NodeTypeTemplate} which can then be used to define a node type and passed to * {@link JcrNodeTypeManager#registerNodeType(NodeTypeDefinition, boolean)} * @@ -585,6 +640,33 @@ public class JcrNodeTypeManager implements NodeTypeManager { } /** + * Returns a {@code NodeTypeTemplate} based on the definition given in {@code ntd}. This template can then be used to define a + * node type and passed to {@link JcrNodeTypeManager#registerNodeType(NodeTypeDefinition, boolean)} + * + * @param ntd an existing node type definition; null values will be ignored + * @return an empty {@code NodeTypeTemplate} which can then be used to define a node type and passed to + * {@link JcrNodeTypeManager#registerNodeType(NodeTypeDefinition, boolean)}. + * @throws RepositoryException if another error occurs + */ + public NodeTypeTemplate createNodeTypeTemplate( NodeTypeDefinition ntd ) throws RepositoryException { + NodeTypeTemplate ntt = createNodeTypeTemplate(); + + if (ntd != null) { + ntt.setName(ntd.getName()); + ntt.setAbstract(ntd.isAbstract()); + ntt.setDeclaredSuperTypeNames(ntd.getDeclaredSupertypeNames()); + ntt.setMixin(ntd.isMixin()); + ntt.setOrderableChildNodes(ntd.hasOrderableChildNodes()); + ntt.setPrimaryItemName(ntd.getPrimaryItemName()); + ntt.setQueryable(ntd.isQueryable()); + + // copy child nodes and props + } + + return ntt; + } + + /** * Returns an empty {@code PropertyDefinitionTemplate} which can then be used to create a property definition and attached to * a {@code NodeTypeTemplate}. * Index: modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeTypeTemplate.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeTypeTemplate.java (revision 1813) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeTypeTemplate.java (working copy) @@ -30,6 +30,7 @@ import javax.jcr.nodetype.PropertyDefinition; import net.jcip.annotations.NotThreadSafe; import org.modeshape.common.util.CheckArg; import org.modeshape.graph.ExecutionContext; +import org.modeshape.graph.property.Name; import org.modeshape.jcr.nodetype.NodeDefinitionTemplate; import org.modeshape.jcr.nodetype.NodeTypeTemplate; import org.modeshape.jcr.nodetype.PropertyDefinitionTemplate; @@ -47,9 +48,9 @@ public class JcrNodeTypeTemplate implements NodeTypeTemplate { private boolean queryable = true; private boolean mixin; private boolean orderableChildNodes; - private String[] declaredSupertypeNames; - private String name; - private String primaryItemName; + private Name[] declaredSupertypeNames; + private Name name; + private Name primaryItemName; JcrNodeTypeTemplate( ExecutionContext context ) { assert context != null; @@ -61,6 +62,12 @@ public class JcrNodeTypeTemplate implements NodeTypeTemplate { return context; } + + private String string( Name name ) { + if (name == null) return null; + return name.getString(context.getNamespaceRegistry()); + } + /** * {@inheritDoc} * @@ -106,7 +113,14 @@ public class JcrNodeTypeTemplate implements NodeTypeTemplate { */ public void setDeclaredSuperTypeNames( String[] names ) { CheckArg.isNotNull(names, "names"); - this.declaredSupertypeNames = names; + + Name[] supertypeNames = new Name[names.length]; + + for (int i = 0; i < names.length; i++) { + CheckArg.isNotEmpty(names[i], "names[" + i + ""); + supertypeNames[i] = context.getValueFactories().getNameFactory().create(names[i]); + } + this.declaredSupertypeNames = supertypeNames; } /** @@ -124,7 +138,8 @@ public class JcrNodeTypeTemplate implements NodeTypeTemplate { * @see org.modeshape.jcr.nodetype.NodeTypeTemplate#setName(java.lang.String) */ public void setName( String name ) { - this.name = name; + CheckArg.isNotEmpty(name, "name"); + this.name = context.getValueFactories().getNameFactory().create(name); } /** @@ -143,42 +158,49 @@ public class JcrNodeTypeTemplate implements NodeTypeTemplate { * type.NodeTypeTemplate#setPrimaryItemName(java.lang.String) */ public void setPrimaryItemName( String name ) { - this.primaryItemName = name; + this.primaryItemName = context.getValueFactories().getNameFactory().create(name); } /** * {@inheritDoc} * * @see org.modeshape.jcr.nodetype.NodeTypeDefinition#getDeclaredNodeDefinitions() + * @deprecated use {@link #getDeclaredChildNodeDefinitions()} instead */ public NodeDefinition[] getDeclaredNodeDefinitions() { return getDeclaredChildNodeDefinitions(); } + /** + * Get the array of child node definition templates for this node type. This method always returns null from a {@code + * JcrNodeTypeTemplate}, as the method is only meaningful for registered types. + * + * @return null always + */ public NodeDefinition[] getDeclaredChildNodeDefinitions() { - if (this.nodeDefinitionTemplates == null) return null; - return nodeDefinitionTemplates.toArray(new NodeDefinition[nodeDefinitionTemplates.size()]); + return null; } /** - * {@inheritDoc} + * {@inheritDoc} This method always returns null from a {@code JcrNodeTypeTemplate}, as the method is only meaningful for + * registered types. * + * @return null always * @see org.modeshape.jcr.nodetype.NodeTypeDefinition#getDeclaredPropertyDefinitions() */ public PropertyDefinition[] getDeclaredPropertyDefinitions() { - if (this.propertyDefinitionTemplates == null) return null; - return propertyDefinitionTemplates.toArray(new PropertyDefinition[propertyDefinitionTemplates.size()]); + return null; } /** * {@inheritDoc} * * @see org.modeshape.jcr.nodetype.NodeTypeDefinition#getDeclaredSupertypes() - * @deprecated Use {@link #getDeclaredSuperTypeNames()} instead + * @deprecated Use {@link #getDeclaredSupertypeNames()} instead */ @Deprecated public String[] getDeclaredSupertypes() { - return getDeclaredSuperTypeNames(); + return getDeclaredSupertypeNames(); } /** @@ -186,8 +208,14 @@ public class JcrNodeTypeTemplate implements NodeTypeTemplate { * * @return the names of the direct supertypes, or an empty array if there are none */ - public String[] getDeclaredSuperTypeNames() { - return declaredSupertypeNames; + public String[] getDeclaredSupertypeNames() { + if (declaredSupertypeNames == null) return new String[0]; + String[] names = new String[declaredSupertypeNames.length]; + + for (int i = 0; i < declaredSupertypeNames.length; i++) { + names[i] = declaredSupertypeNames[i].getString(context.getNamespaceRegistry()); + } + return names; } /** @@ -196,7 +224,7 @@ public class JcrNodeTypeTemplate implements NodeTypeTemplate { * @see org.modeshape.jcr.nodetype.NodeTypeDefinition#getName() */ public String getName() { - return name; + return string(name); } /** @@ -205,7 +233,7 @@ public class JcrNodeTypeTemplate implements NodeTypeTemplate { * @see org.modeshape.jcr.nodetype.NodeTypeDefinition#getPrimaryItemName() */ public String getPrimaryItemName() { - return primaryItemName; + return string(primaryItemName); } /** Index: modeshape-jcr/src/main/java/org/modeshape/jcr/JcrPropertyDefinitionTemplate.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/JcrPropertyDefinitionTemplate.java (revision 1813) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/JcrPropertyDefinitionTemplate.java (working copy) @@ -24,10 +24,9 @@ package org.modeshape.jcr; import javax.jcr.PropertyType; -import javax.jcr.RepositoryException; import javax.jcr.Value; -import org.modeshape.common.util.CheckArg; import org.modeshape.graph.ExecutionContext; +import org.modeshape.graph.property.ValueFactories; import org.modeshape.jcr.nodetype.PropertyDefinitionTemplate; /** @@ -36,9 +35,9 @@ import org.modeshape.jcr.nodetype.PropertyDefinitionTemplate; class JcrPropertyDefinitionTemplate extends JcrItemDefinitionTemplate implements PropertyDefinitionTemplate { private boolean multiple = false; - private String[] defaultValues; + private Value[] defaultValues = null; private int requiredType = PropertyType.STRING; - private String[] valueConstraints = new String[0]; + private String[] valueConstraints = null; private boolean fullTextSearchable = true; private boolean queryOrderable = true; private String[] availableQueryOperators; @@ -53,8 +52,16 @@ class JcrPropertyDefinitionTemplate extends JcrItemDefinitionTemplate implements * @see org.modeshape.jcr.nodetype.PropertyDefinitionTemplate#setDefaultValues(java.lang.String[]) */ public void setDefaultValues( String[] defaultValues ) { - CheckArg.isNotNull(defaultValues, "defaultValues"); - this.defaultValues = defaultValues; + if (defaultValues == null) { + this.defaultValues = null; + return; + } + + this.defaultValues = new Value[defaultValues.length]; + ValueFactories factories = getExecutionContext().getValueFactories(); + for (int i = 0; i < defaultValues.length; i++) { + this.defaultValues[i] = new JcrValue(factories, null, PropertyType.STRING, defaultValues[i]); + } } /** @@ -63,16 +70,7 @@ class JcrPropertyDefinitionTemplate extends JcrItemDefinitionTemplate implements * @see org.modeshape.jcr.nodetype.PropertyDefinitionTemplate#setDefaultValues(Value[]) */ public void setDefaultValues( Value[] defaultValues ) { - CheckArg.isNotNull(defaultValues, "defaultValues"); - this.defaultValues = new String[defaultValues.length]; - - try { - for (int i = 0; i < defaultValues.length; i++) { - this.defaultValues[i] = defaultValues[i].getString(); - } - } catch (RepositoryException re) { - throw new IllegalStateException(re); - } + this.defaultValues = defaultValues; } /** @@ -103,7 +101,6 @@ class JcrPropertyDefinitionTemplate extends JcrItemDefinitionTemplate implements * @see org.modeshape.jcr.nodetype.PropertyDefinitionTemplate#setValueConstraints(java.lang.String[]) */ public void setValueConstraints( String[] constraints ) { - CheckArg.isNotNull(constraints, "constraints"); this.valueConstraints = constraints; } @@ -113,11 +110,7 @@ class JcrPropertyDefinitionTemplate extends JcrItemDefinitionTemplate implements * @see javax.jcr.nodetype.PropertyDefinition#getDefaultValues() */ public Value[] getDefaultValues() { - return null; - } - - String[] getInternalDefaultValues() { - return defaultValues; + return this.defaultValues; } /** Index: modeshape-jcr/src/main/java/org/modeshape/jcr/NodeTemplateNodeTypeSource.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/NodeTemplateNodeTypeSource.java (revision 1813) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/NodeTemplateNodeTypeSource.java (working copy) @@ -26,6 +26,8 @@ package org.modeshape.jcr; import java.util.Arrays; import java.util.List; import javax.jcr.PropertyType; +import javax.jcr.RepositoryException; +import javax.jcr.Value; import javax.jcr.nodetype.NodeDefinition; import javax.jcr.nodetype.PropertyDefinition; import javax.jcr.version.OnParentVersionAction; @@ -213,7 +215,7 @@ class NodeTemplateNodeTypeSource implements JcrNodeTypeSource { Path parentPath ) { Name name = nameFrom(propDefn.getName()); String requiredType = PropertyType.nameFromValue(propDefn.getRequiredType()).toUpperCase(); - String[] defaultValues = propDefn.getInternalDefaultValues(); + Value[] rawValues = propDefn.getDefaultValues(); boolean multiple = booleanFrom(propDefn.isMultiple(), false); boolean mandatory = booleanFrom(propDefn.isMandatory(), false); boolean autoCreated = booleanFrom(propDefn.isAutoCreated(), false); @@ -228,11 +230,26 @@ class NodeTemplateNodeTypeSource implements JcrNodeTypeSource { if (name == null) name = JcrNodeType.RESIDUAL_NAME; Path path = pathFactory.create(parentPath, JcrLexicon.PROPERTY_DEFINITION); + String defaultValues[]; + + if (rawValues == null) { + defaultValues = new String[0]; + } else { + try { + defaultValues = new String[rawValues.length]; + for (int i = 0; i < rawValues.length; i++) { + defaultValues[i] = rawValues[i].getString(); + } + } catch (RepositoryException re) { + throw new IllegalStateException(re); + } + } + PropertyFactory factory = propDefn.getExecutionContext().getPropertyFactory(); destination.create(path, factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.PROPERTY_DEFINITION), factory.create(JcrLexicon.REQUIRED_TYPE, requiredType), - factory.create(JcrLexicon.DEFAULT_VALUES, (Object[])defaultValues), + factory.create(JcrLexicon.DEFAULT_VALUES, defaultValues), factory.create(JcrLexicon.MULTIPLE, multiple), factory.create(JcrLexicon.MANDATORY, mandatory), factory.create(JcrLexicon.NAME, name), Index: modeshape-jcr/src/main/java/org/modeshape/jcr/nodetype/NodeTypeDefinition.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/nodetype/NodeTypeDefinition.java (revision 1813) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/nodetype/NodeTypeDefinition.java (working copy) @@ -49,6 +49,13 @@ public interface NodeTypeDefinition { public String[] getDeclaredSupertypes(); /** + * Get the direct supertypes for this node type. + * + * @return the names of the direct supertypes, or an empty array if there are none + */ + public String[] getDeclaredSupertypeNames(); + + /** * Get whether this node type is abstract. * * @return true if this node type is abstract, or false if it is concrete Index: modeshape-jcr/src/main/java/org/modeshape/jcr/nodetype/NodeTypeTemplate.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/nodetype/NodeTypeTemplate.java (revision 1813) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/nodetype/NodeTypeTemplate.java (working copy) @@ -49,6 +49,13 @@ public interface NodeTypeTemplate extends NodeTypeDefinition { public void setDeclaredSupertypeNames( String[] names ); /** + * Set the direct supertypes for this node type. + * + * @param names the names of the direct supertypes, or empty or null if there are none. + */ + public void setDeclaredSuperTypeNames( String[] names ); + + /** * Set whether this node type is abstract. * * @param isAbstract true if this node type is to be abstract, or false if it is concrete Index: modeshape-jcr/src/test/java/org/modeshape/jcr/JcrQueryManagerTest.java =================================================================== --- modeshape-jcr/src/test/java/org/modeshape/jcr/JcrQueryManagerTest.java (revision 1813) +++ modeshape-jcr/src/test/java/org/modeshape/jcr/JcrQueryManagerTest.java (working copy) @@ -669,7 +669,7 @@ public class JcrQueryManagerTest { adminSession.setNamespacePrefix("cars", "http://www.modeshape.org/examples/cars/1.0"); JcrNodeTypeManager nodeTypeManager = (JcrNodeTypeManager)adminSession.getWorkspace().getNodeTypeManager(); - nodeTypeManager.unregisterNodeType(Collections.singletonList("cars:Car")); + nodeTypeManager.unregisterNodeTypes(Collections.singletonList("cars:Car")); } finally { if (adminSession != null) adminSession.logout(); } Index: modeshape-jcr/src/test/java/org/modeshape/jcr/ModeShapeTckTest.java =================================================================== --- modeshape-jcr/src/test/java/org/modeshape/jcr/ModeShapeTckTest.java (revision 1813) +++ modeshape-jcr/src/test/java/org/modeshape/jcr/ModeShapeTckTest.java (working copy) @@ -139,7 +139,7 @@ public class ModeShapeTckTest extends AbstractJCRTest { String nodeTypeName = session.getUserID() + "Type"; newType.setName(nodeTypeName); nodeTypes.registerNodeType(newType, false); - nodeTypes.unregisterNodeType(Collections.singleton(nodeTypeName)); + nodeTypes.unregisterNodeTypes(Collections.singleton(nodeTypeName)); } private void testWrite( Session session ) throws Exception { Index: modeshape-jcr/src/test/java/org/modeshape/jcr/TypeRegistrationTest.java =================================================================== --- modeshape-jcr/src/test/java/org/modeshape/jcr/TypeRegistrationTest.java (revision 1813) +++ modeshape-jcr/src/test/java/org/modeshape/jcr/TypeRegistrationTest.java (working copy) @@ -35,6 +35,7 @@ import javax.jcr.nodetype.NoSuchNodeTypeException; import javax.jcr.nodetype.NodeDefinition; import javax.jcr.nodetype.PropertyDefinition; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.modeshape.graph.property.Name; import org.modeshape.graph.property.NameFactory; @@ -67,17 +68,57 @@ public class TypeRegistrationTest extends AbstractSessionTest { nameFactory = context.getValueFactories().getNameFactory(); } - @Test( expected = InvalidNodeTypeDefinitionException.class ) + @Ignore + @Test( expected = IllegalArgumentException.class ) + public void shouldNotAllowNodeTypeWithInvalidName() throws Exception { + ntTemplate.setName("nt-name"); + } + + @Ignore + @Test( expected = IllegalArgumentException.class ) + public void shouldNotAllowPropertyWithInvalidName() throws Exception { + JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); + prop.setName(":foo[2]"); + System.out.println(prop.getName()); + } + + @Ignore + @Test( expected = IllegalArgumentException.class ) + public void shouldNotAllowChildNodeWithInvalidName() throws Exception { + JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); + child.setName(":foo[2]"); + } + + @Ignore + @Test( expected = IllegalArgumentException.class ) + public void shouldNotAllowChildNodeWithInvalidRequiredPrimaryTypeName() throws Exception { + JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); + child.setRequiredPrimaryTypeNames(new String[] {"nt-Name"}); + } + + @Ignore + @Test( expected = IllegalArgumentException.class ) + public void shouldNotAllowChildNodeWithInvalidDefaultPrimaryTypeName() throws Exception { + JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); + child.setDefaultPrimaryTypeName("nt-Name"); + } + + @Test( expected = IllegalArgumentException.class ) public void shouldNotAllowNodeTypeWithNoName() throws Exception { ntTemplate.setName(null); - repoTypeManager.registerNodeType(ntTemplate, false); + } + + @Test + public void shouldTranslateNameImmediately() throws Exception { + ntTemplate.setName("{" + ModeShapeLexicon.Namespace.URI + "}foo"); + assertThat(ntTemplate.getName(), is("mode:foo")); } @Test public void shouldAllowNewDefinitionWithNoChildNodesOrProperties() throws Exception { Name testTypeName = nameFactory.create(TEST_TYPE_NAME); ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base"}); JcrNodeType testNodeType = repoTypeManager.registerNodeType(ntTemplate, false); @@ -97,7 +138,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { public void shouldNotAllowRedefinitionOfNewTypeIfAllowUpdatesIsFalse() throws Exception { Name testTypeName = nameFactory.create(TEST_TYPE_NAME); ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base"}); JcrNodeType testNodeType = repoTypeManager.registerNodeType(ntTemplate, false); @@ -113,7 +154,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { public void shouldAllowDefinitionWithExistingSupertypes() throws Exception { Name testTypeName = nameFactory.create(TEST_TYPE_NAME); ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrNodeType testNodeType = repoTypeManager.registerNodeType(ntTemplate, false); @@ -127,11 +168,11 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test public void shouldAllowDefinitionWithSupertypesFromTypesRegisteredInSameCall() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrNodeTypeTemplate ntTemplate2 = new JcrNodeTypeTemplate(context); ntTemplate2.setName(TEST_TYPE_NAME2); - ntTemplate2.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + ntTemplate2.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); List templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate, ntTemplate2}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates, false)); @@ -141,11 +182,11 @@ public class TypeRegistrationTest extends AbstractSessionTest { public void shouldNotAllowDefinitionWithSupertypesFromTypesRegisteredInSameCallInWrongOrder() throws Exception { // Try to register the supertype AFTER the class that registers it ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrNodeTypeTemplate ntTemplate2 = new JcrNodeTypeTemplate(context); ntTemplate2.setName(TEST_TYPE_NAME2); - ntTemplate2.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + ntTemplate2.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); repoTypeManager.registerNodeTypes(Arrays.asList(new NodeTypeDefinition[] {ntTemplate2, ntTemplate}), false); } @@ -153,7 +194,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test public void shouldAllowDefinitionWithAProperty() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setRequiredType(PropertyType.LONG); @@ -167,7 +208,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test public void shouldAllowDefinitionWithProperties() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setRequiredType(PropertyType.LONG); @@ -190,7 +231,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test( expected = InvalidNodeTypeDefinitionException.class ) public void shouldNotAllowAutocreatedPropertyWithNoDefault() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -205,9 +246,10 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test( expected = InvalidNodeTypeDefinitionException.class ) public void shouldNotAllowAutocreatedResidualProperty() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); + prop.setName(JcrNodeType.RESIDUAL_ITEM_NAME); prop.setRequiredType(PropertyType.UNDEFINED); prop.setAutoCreated(true); ntTemplate.getPropertyDefinitionTemplates().add(prop); @@ -219,7 +261,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test public void shouldAllowAutocreatedNamedPropertyWithDefault() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -235,7 +277,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test( expected = InvalidNodeTypeDefinitionException.class ) public void shouldNotAllowSingleValuedPropertyWithMultipleDefaults() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -251,9 +293,10 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test( expected = InvalidNodeTypeDefinitionException.class ) public void shouldNotAllowMandatoryResidualProperty() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); + prop.setName(JcrNodeType.RESIDUAL_ITEM_NAME); prop.setRequiredType(PropertyType.UNDEFINED); prop.setMandatory(true); ntTemplate.getPropertyDefinitionTemplates().add(prop); @@ -265,11 +308,11 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test public void shouldAllowTypeWithChildNode() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); - child.setRequiredPrimaryTypes(new String[] {"nt:base"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); child.setSameNameSiblings(true); ntTemplate.getNodeDefinitionTemplates().add(child); @@ -281,23 +324,23 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test public void shouldAllowTypeWithMultipleChildNodes() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); - child.setRequiredPrimaryTypes(new String[] {"nt:base"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); child.setSameNameSiblings(true); ntTemplate.getNodeDefinitionTemplates().add(child); child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); - child.setRequiredPrimaryTypes(new String[] {"nt:unstructured"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:unstructured"}); child.setSameNameSiblings(false); ntTemplate.getNodeDefinitionTemplates().add(child); child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME + "2"); - child.setRequiredPrimaryTypes(new String[] {"nt:base"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); child.setSameNameSiblings(true); ntTemplate.getNodeDefinitionTemplates().add(child); @@ -308,11 +351,11 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test( expected = InvalidNodeTypeDefinitionException.class ) public void shouldNotAllowAutocreatedChildNodeWithNoDefaultPrimaryType() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); - child.setRequiredPrimaryTypes(new String[] {"nt:base"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); child.setAutoCreated(true); ntTemplate.getNodeDefinitionTemplates().add(child); @@ -323,10 +366,11 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test( expected = InvalidNodeTypeDefinitionException.class ) public void shouldNotAllowMandatoryResidualChildNode() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); - child.setRequiredPrimaryTypes(new String[] {"nt:base"}); + child.setName(JcrNodeType.RESIDUAL_ITEM_NAME); + child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); child.setMandatory(true); ntTemplate.getNodeDefinitionTemplates().add(child); @@ -337,7 +381,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test( expected = InvalidNodeTypeDefinitionException.class ) public void shouldNotAllowOverridingProtectedProperty() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base", "mix:referenceable"}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(JcrLexicon.PRIMARY_TYPE.getString(registry)); @@ -351,11 +395,11 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test( expected = InvalidNodeTypeDefinitionException.class ) public void shouldNotAllowOverridingProtectedChildNode() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"mode:root", "mix:referenceable"}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"mode:root", "mix:referenceable"}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(JcrLexicon.SYSTEM.getString(registry)); - child.setRequiredPrimaryTypes(new String[] {"nt:base"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); ntTemplate.getNodeDefinitionTemplates().add(child); List templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); @@ -365,11 +409,11 @@ public class TypeRegistrationTest extends AbstractSessionTest { @Test( expected = InvalidNodeTypeDefinitionException.class ) public void shouldNotAllowOverridingMandatoryChildNodeWithOptionalChildNode() throws Exception { ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"jcr:versionHistory",}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"jcr:versionHistory",}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(JcrLexicon.SYSTEM.getString(registry)); - child.setRequiredPrimaryTypes(new String[] {"nt:base"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); ntTemplate.getNodeDefinitionTemplates().add(child); List templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate}); @@ -385,7 +429,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { * testNodeD extends testNodeB and testNodeC and overrides testProperty --> LEGAL */ ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base",}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base",}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -394,15 +438,15 @@ public class TypeRegistrationTest extends AbstractSessionTest { JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); - nodeBTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); JcrNodeTypeTemplate nodeCTemplate = new JcrNodeTypeTemplate(this.context); nodeCTemplate.setName(TEST_TYPE_NAME + "C"); - nodeCTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeCTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); JcrNodeTypeTemplate nodeDTemplate = new JcrNodeTypeTemplate(this.context); nodeDTemplate.setName(TEST_TYPE_NAME + "D"); - nodeDTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME + "B", TEST_TYPE_NAME + "C"}); + nodeDTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME + "B", TEST_TYPE_NAME + "C"}); prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -423,11 +467,11 @@ public class TypeRegistrationTest extends AbstractSessionTest { * testNodeD extends testNodeB and testNodeC and overrides testProperty --> ILLEGAL */ ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base",}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base",}); JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); - nodeBTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -436,7 +480,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { JcrNodeTypeTemplate nodeCTemplate = new JcrNodeTypeTemplate(this.context); nodeCTemplate.setName(TEST_TYPE_NAME + "C"); - nodeCTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeCTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -445,7 +489,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { JcrNodeTypeTemplate nodeDTemplate = new JcrNodeTypeTemplate(this.context); nodeDTemplate.setName(TEST_TYPE_NAME + "D"); - nodeDTemplate.setDeclaredSupertypeNames(new String[] {nodeBTemplate.getName(), nodeCTemplate.getName()}); + nodeDTemplate.setDeclaredSuperTypeNames(new String[] {nodeBTemplate.getName(), nodeCTemplate.getName()}); List templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate, nodeBTemplate, nodeCTemplate, nodeDTemplate}); @@ -461,28 +505,28 @@ public class TypeRegistrationTest extends AbstractSessionTest { * testNodeD extends testNodeB and testNodeC and overrides testChildNode --> LEGAL */ ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base",}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base",}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(JcrLexicon.SYSTEM.getString(registry)); - child.setRequiredPrimaryTypes(new String[] {"nt:base"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); ntTemplate.getNodeDefinitionTemplates().add(child); JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); - nodeBTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); JcrNodeTypeTemplate nodeCTemplate = new JcrNodeTypeTemplate(this.context); nodeCTemplate.setName(TEST_TYPE_NAME + "C"); - nodeCTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeCTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); JcrNodeTypeTemplate nodeDTemplate = new JcrNodeTypeTemplate(this.context); nodeDTemplate.setName(TEST_TYPE_NAME + "D"); - nodeDTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME + "B", TEST_TYPE_NAME + "C"}); + nodeDTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME + "B", TEST_TYPE_NAME + "C"}); child = new JcrNodeDefinitionTemplate(this.context); child.setName(JcrLexicon.SYSTEM.getString(registry)); - child.setRequiredPrimaryTypes(new String[] {"nt:unstructured"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:unstructured"}); nodeDTemplate.getNodeDefinitionTemplates().add(child); List templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate, nodeBTemplate, nodeCTemplate, @@ -499,29 +543,29 @@ public class TypeRegistrationTest extends AbstractSessionTest { * testNodeD extends testNodeB and testNodeC and overrides testChildNode --> ILLEGAL */ ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base",}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base",}); JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); - nodeBTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(JcrLexicon.SYSTEM.getString(registry)); - child.setRequiredPrimaryTypes(new String[] {"nt:base"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); nodeBTemplate.getNodeDefinitionTemplates().add(child); JcrNodeTypeTemplate nodeCTemplate = new JcrNodeTypeTemplate(this.context); nodeCTemplate.setName(TEST_TYPE_NAME + "C"); - nodeCTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeCTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); child = new JcrNodeDefinitionTemplate(this.context); child.setName(JcrLexicon.SYSTEM.getString(registry)); - child.setRequiredPrimaryTypes(new String[] {"nt:base"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); nodeCTemplate.getNodeDefinitionTemplates().add(child); JcrNodeTypeTemplate nodeDTemplate = new JcrNodeTypeTemplate(this.context); nodeDTemplate.setName(TEST_TYPE_NAME + "D"); - nodeDTemplate.setDeclaredSupertypeNames(new String[] {nodeBTemplate.getName(), nodeCTemplate.getName()}); + nodeDTemplate.setDeclaredSuperTypeNames(new String[] {nodeBTemplate.getName(), nodeCTemplate.getName()}); List templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate, nodeBTemplate, nodeCTemplate, nodeDTemplate}); @@ -536,7 +580,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { * testNodeC extends testNode, testNodeB -> LEGAL */ ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base",}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base",}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -546,7 +590,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); - nodeBTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -556,7 +600,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { JcrNodeTypeTemplate nodeCTemplate = new JcrNodeTypeTemplate(this.context); nodeCTemplate.setName(TEST_TYPE_NAME + "C"); - nodeCTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME, nodeBTemplate.getName()}); + nodeCTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME, nodeBTemplate.getName()}); List templates = Arrays.asList(new NodeTypeDefinition[] {ntTemplate, nodeBTemplate, nodeCTemplate}); compareTemplatesToNodeTypes(templates, repoTypeManager.registerNodeTypes(templates, false)); @@ -569,7 +613,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { * testNodeB extends testNode with SV property testProperty of type STRING -> LEGAL */ ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base",}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base",}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -579,7 +623,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); - nodeBTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -598,7 +642,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { * testNodeB extends testNode with SV property testProperty of type DOUBLE -> ILLEGAL */ ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base",}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base",}); JcrPropertyDefinitionTemplate prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -608,7 +652,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); - nodeBTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); prop = new JcrPropertyDefinitionTemplate(this.context); prop.setName(TEST_PROPERTY_NAME); @@ -627,21 +671,21 @@ public class TypeRegistrationTest extends AbstractSessionTest { * testNodeB extends testNode with No-SNS childNode testChildNode requiring type nt:file -> LEGAL */ ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base",}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base",}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); - child.setRequiredPrimaryTypes(new String[] {"nt:hierarchyNode"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:hierarchyNode"}); child.setSameNameSiblings(false); ntTemplate.getNodeDefinitionTemplates().add(child); JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); - nodeBTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); - child.setRequiredPrimaryTypes(new String[] {"nt:file"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:file"}); child.setSameNameSiblings(false); nodeBTemplate.getNodeDefinitionTemplates().add(child); @@ -656,21 +700,21 @@ public class TypeRegistrationTest extends AbstractSessionTest { * testNodeB extends testNode with No-SNS childNode testChildNode requiring type nt:base -> ILLEGAL */ ntTemplate.setName(TEST_TYPE_NAME); - ntTemplate.setDeclaredSupertypeNames(new String[] {"nt:base",}); + ntTemplate.setDeclaredSuperTypeNames(new String[] {"nt:base",}); JcrNodeDefinitionTemplate child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); - child.setRequiredPrimaryTypes(new String[] {"nt:hierarchyNode"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:hierarchyNode"}); child.setSameNameSiblings(false); ntTemplate.getNodeDefinitionTemplates().add(child); JcrNodeTypeTemplate nodeBTemplate = new JcrNodeTypeTemplate(this.context); nodeBTemplate.setName(TEST_TYPE_NAME + "B"); - nodeBTemplate.setDeclaredSupertypeNames(new String[] {TEST_TYPE_NAME}); + nodeBTemplate.setDeclaredSuperTypeNames(new String[] {TEST_TYPE_NAME}); child = new JcrNodeDefinitionTemplate(this.context); child.setName(TEST_CHILD_NODE_NAME); - child.setRequiredPrimaryTypes(new String[] {"nt:base"}); + child.setRequiredPrimaryTypeNames(new String[] {"nt:base"}); child.setSameNameSiblings(false); nodeBTemplate.getNodeDefinitionTemplates().add(child); @@ -868,7 +912,7 @@ public class TypeRegistrationTest extends AbstractSessionTest { // Had to match on name to even get to the definition // assertThat(template.getName(), is(definition.getName())); - assertThat(template.getValueConstraints(), is(definition.getValueConstraints())); + assertThat(emptyIfNull(template.getValueConstraints()), is(definition.getValueConstraints())); assertThat(template.getOnParentVersion(), is(definition.getOnParentVersion())); assertThat(template.getRequiredType(), is(definition.getRequiredType())); assertThat(template.isAutoCreated(), is(definition.isAutoCreated())); @@ -896,4 +940,8 @@ public class TypeRegistrationTest extends AbstractSessionTest { } + private String[] emptyIfNull( String[] incoming ) { + if (incoming != null) return incoming; + return new String[0]; + } }