Index: b/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeDefinition.java =================================================================== --- a/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeDefinition.java (revision ) +++ b/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeDefinition.java (working copy) @@ -173,6 +173,13 @@ class JcrNodeDefinition extends JcrItemDefinition implements NodeDefinition { */ public NodeType[] getRequiredPrimaryTypes() { ensureRequiredPrimaryTypesLoaded(); + if (requiredPrimaryTypes.length == 0) { + // Per the JavaDoc, this method should never return null or an empty array; if there are no constraints, + // then this method should include an array with 'nt:base' as the required primary type. + NodeType[] result = new NodeType[1]; + result[0] = nodeTypeManager.getNodeType(JcrNtLexicon.BASE); + return result; + } // Make a copy so that the caller can't modify our content ... NodeType[] result = new NodeType[requiredPrimaryTypes.length]; for (int i = 0; i != requiredPrimaryTypes.length; ++i) { Index: b/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeDefinitionTemplate.java =================================================================== --- a/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeDefinitionTemplate.java (revision ) +++ b/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeDefinitionTemplate.java (working copy) @@ -49,6 +49,9 @@ class JcrNodeDefinitionTemplate extends JcrItemDefinitionTemplate implements Nod /** * {@inheritDoc} + *

+ * Passing a null or blank name is equivalent to "unsetting" (or removing) the primary item name. + *

* * @see org.modeshape.jcr.nodetype.NodeDefinitionTemplate#setDefaultPrimaryType(String) */ @@ -59,14 +62,18 @@ class JcrNodeDefinitionTemplate extends JcrItemDefinitionTemplate implements Nod /** * 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 + * @param defaultPrimaryType the default primary type for this child node, or null if there is to be no default primary type * @throws ConstraintViolationException */ public void setDefaultPrimaryTypeName( String defaultPrimaryType ) throws ConstraintViolationException { - try { - this.defaultPrimaryType = getContext().getValueFactories().getNameFactory().create(defaultPrimaryType); - } catch (ValueFormatException vfe) { - throw new ConstraintViolationException(vfe); + if (defaultPrimaryType == null || defaultPrimaryType.trim().length() == 0) { + this.defaultPrimaryType = null; + } else { + try { + this.defaultPrimaryType = getContext().getValueFactories().getNameFactory().create(defaultPrimaryType); + } catch (ValueFormatException vfe) { + throw new ConstraintViolationException(vfe); + } } } @@ -142,9 +149,15 @@ class JcrNodeDefinitionTemplate extends JcrItemDefinitionTemplate implements Nod * @see javax.jcr.nodetype.NodeDefinition#getRequiredPrimaryTypes() */ public NodeType[] getRequiredPrimaryTypes() { + // This method should return null since it's not attached to a registered node type ... return null; } + /** + * {@inheritDoc} + * + * @see javax.jcr.nodetype.NodeDefinition#getRequiredPrimaryTypeNames() + */ public String[] getRequiredPrimaryTypeNames() { if (requiredPrimaryTypes == null) return null; Index: b/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeTypeTemplate.java =================================================================== --- a/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeTypeTemplate.java (revision ) +++ b/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrNodeTypeTemplate.java (working copy) @@ -166,15 +166,22 @@ public class JcrNodeTypeTemplate implements NodeTypeDefinition, NodeTypeTemplate /** * {@inheritDoc} + *

+ * Passing a null or blank name is equivalent to "unsetting" (or removing) the primary item name. + *

* * @see org.modeshape.jcr.nodetype.NodeTypeDefinition#getPrimaryItemName() * type.NodeTypeTemplate#setPrimaryItemName(java.lang.String) */ public void setPrimaryItemName( String name ) throws ConstraintViolationException { - try { - this.primaryItemName = context.getValueFactories().getNameFactory().create(name); - } catch (ValueFormatException vfe) { - throw new ConstraintViolationException(vfe); + if (name == null || name.trim().length() == 0) { + this.primaryItemName = null; + } else { + try { + this.primaryItemName = context.getValueFactories().getNameFactory().create(name); + } catch (ValueFormatException vfe) { + throw new ConstraintViolationException(vfe); + } } } Index: b/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrPropertyDefinitionTemplate.java =================================================================== --- a/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrPropertyDefinitionTemplate.java (revision ) +++ b/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrPropertyDefinitionTemplate.java (working copy) @@ -52,15 +52,14 @@ class JcrPropertyDefinitionTemplate extends JcrItemDefinitionTemplate implements * @see org.modeshape.jcr.nodetype.PropertyDefinitionTemplate#setDefaultValues(java.lang.String[]) */ public void setDefaultValues( String[] defaultValues ) { - if (defaultValues == null) { + if (defaultValues != null) { + 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]); + } + } else { 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]); } } @@ -92,8 +91,8 @@ class JcrPropertyDefinitionTemplate extends JcrItemDefinitionTemplate implements || requiredType == PropertyType.DOUBLE || requiredType == PropertyType.DECIMAL || requiredType == PropertyType.LONG || requiredType == PropertyType.NAME || requiredType == PropertyType.PATH || requiredType == PropertyType.REFERENCE || requiredType == PropertyType.WEAKREFERENCE - || requiredType == PropertyType.URI - || requiredType == PropertyType.STRING || requiredType == PropertyType.UNDEFINED; + || requiredType == PropertyType.URI || requiredType == PropertyType.STRING + || requiredType == PropertyType.UNDEFINED; this.requiredType = requiredType; }