Author: bcarothers
Date: 2010-01-07 09:39:17 -0500 (Thu, 07 Jan 2010)
New Revision: 1549
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
Log:
DNA-591
Applied patch that cleanly (i.e., with proper internationalization) corrects the NPE and
provides a reasonably useful error message instead.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2010-01-07 07:22:38 UTC
(rev 1548)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2010-01-07 14:39:17 UTC
(rev 1549)
@@ -160,6 +160,8 @@
public static I18n cannotRedefineProperty;
public static I18n autocreatedPropertyNeedsDefault;
public static I18n singleValuedPropertyNeedsSingleValuedDefault;
+ public static I18n couldNotFindDefinitionOfRequiredPrimaryType;
+ public static I18n cannotRedefineChildNodeWithIncompatibleDefinition;
public static I18n noDefinition;
public static I18n noSnsDefinition;
@@ -174,6 +176,7 @@
public static I18n cannotUnregisterSupertype;
public static I18n cannotUnregisterRequiredPrimaryType;
public static I18n cannotUnregisterDefaultPrimaryType;
+ public static I18n cannotUnregisterInUseType;
public static I18n cannotAddMixin;
public static I18n invalidMixinTypeForNode;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
===================================================================
---
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java 2010-01-07
07:22:38 UTC (rev 1548)
+++
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java 2010-01-07
14:39:17 UTC (rev 1549)
@@ -45,6 +45,7 @@
import javax.jcr.version.OnParentVersionAction;
import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.text.XmlNameEncoder;
import org.jboss.dna.common.util.CheckArg;
@@ -1922,23 +1923,32 @@
for (JcrNodeDefinition ancestor : ancestors) {
if (ancestor.isProtected()) {
throw new InvalidNodeTypeDefinitionException(
-
JcrI18n.cannotOverrideProtectedDefinition.text(ancestor.getDeclaringNodeType()
-
.getName(),
+
JcrI18n.cannotOverrideProtectedDefinition.text(ancestor.getDeclaringNodeType().getName(),
"child node"));
}
if (ancestor.isMandatory() && !node.isMandatory()) {
throw new InvalidNodeTypeDefinitionException(
-
JcrI18n.cannotMakeMandatoryDefinitionOptional.text(ancestor.getDeclaringNodeType()
-
.getName(),
+
JcrI18n.cannotMakeMandatoryDefinitionOptional.text(ancestor.getDeclaringNodeType().getName(),
"child node"));
}
- for (int i = 0; i < ancestor.getRequiredPrimaryTypes().length; i++) {
- NodeType apt = ancestor.getRequiredPrimaryTypes()[i];
+ Name[] requiredPrimaryTypeNames = ancestor.requiredPrimaryTypeNames();
+ for (int i = 0; i < requiredPrimaryTypeNames.length; i++) {
+ NodeType apt = findTypeInMapOrList(requiredPrimaryTypeNames[i],
pendingTypes);
+
+ if (apt == null) {
+ I18n msg = JcrI18n.couldNotFindDefinitionOfRequiredPrimaryType;
+ throw new
InvalidNodeTypeDefinitionException(msg.text(requiredPrimaryTypeNames[i],
+
node.getName(),
+
node.getDeclaringNodeType()));
+
+ }
+
boolean found = false;
- for (Name name : node.getRequiredPrimaryTypeNames()) {
+
+ for (Name name : node.requiredPrimaryTypeNames()) {
JcrNodeType npt = findTypeInMapOrList(name, pendingTypes);
if (npt.isNodeType(apt.getName())) {
@@ -1947,12 +1957,8 @@
}
}
if (!found) {
- throw new InvalidNodeTypeDefinitionException(
- "Cannot redefine
child node '"
- + nodeName
- + "' with
required type '"
- + apt.getName()
- + "' with new
child node that does not required that type or a subtype of that type.");
+ I18n msg =
JcrI18n.cannotRedefineChildNodeWithIncompatibleDefinition;
+ throw new InvalidNodeTypeDefinitionException(msg.text(nodeName,
apt.getName(), node.getDeclaringNodeType()));
}
}
@@ -1995,16 +2001,15 @@
Value[] defaultValues = prop.getDefaultValues();
if (prop.isAutoCreated() && !prop.isProtected() && (defaultValues
== null || defaultValues.length == 0)) {
- throw new
InvalidNodeTypeDefinitionException(JcrI18n.autocreatedPropertyNeedsDefault.text(prop.getName(),
-
prop.getDeclaringNodeType()
-
.getName()));
+ throw new InvalidNodeTypeDefinitionException(
+
JcrI18n.autocreatedPropertyNeedsDefault.text(prop.getName(),
+
prop.getDeclaringNodeType().getName()));
}
if (!prop.isMultiple() && (defaultValues != null &&
defaultValues.length > 1)) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.singleValuedPropertyNeedsSingleValuedDefault.text(prop.getName(),
-
prop.getDeclaringNodeType()
-
.getName()));
+
prop.getDeclaringNodeType().getName()));
}
Name propName =
context.getValueFactories().getNameFactory().create(prop.getName());
@@ -2018,15 +2023,13 @@
for (JcrPropertyDefinition ancestor : ancestors) {
if (ancestor.isProtected()) {
throw new InvalidNodeTypeDefinitionException(
-
JcrI18n.cannotOverrideProtectedDefinition.text(ancestor.getDeclaringNodeType()
-
.getName(),
+
JcrI18n.cannotOverrideProtectedDefinition.text(ancestor.getDeclaringNodeType().getName(),
"property"));
}
if (ancestor.isMandatory() && !prop.isMandatory()) {
throw new InvalidNodeTypeDefinitionException(
-
JcrI18n.cannotMakeMandatoryDefinitionOptional.text(ancestor.getDeclaringNodeType()
-
.getName(),
+
JcrI18n.cannotMakeMandatoryDefinitionOptional.text(ancestor.getDeclaringNodeType().getName(),
"property"));
}
@@ -2037,16 +2040,14 @@
&& !Arrays.equals(ancestor.getValueConstraints(),
prop.getValueConstraints())) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.constraintsChangedInSubtype.text(propName,
-
ancestor.getDeclaringNodeType()
-
.getName()));
+
ancestor.getDeclaringNodeType().getName()));
}
if (!isAlwaysSafeConversion(prop.getRequiredType(),
ancestor.getRequiredType())) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.cannotRedefineProperty.text(propName,
PropertyType.nameFromValue(prop.getRequiredType()),
-
ancestor.getDeclaringNodeType()
-
.getName(),
+
ancestor.getDeclaringNodeType().getName(),
PropertyType.nameFromValue(ancestor.getRequiredType())));
}
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2010-01-07
07:22:38 UTC (rev 1548)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2010-01-07
14:39:17 UTC (rev 1549)
@@ -144,6 +144,8 @@
cannotRedefineProperty=Cannot redefine property '{0}' with new type '{1}'
when existing property with same name in type '{2}' has incompatible type
'{3}'
autocreatedPropertyNeedsDefault=Auto-created property '{0}' in type '{1}'
must specify a default value
singleValuedPropertyNeedsSingleValuedDefault=Single-valued property '{0}' in type
'{1}' cannot have multiple default values
+couldNotFindDefinitionOfRequiredPrimaryType = Could not find node type definition for the
type of required primary type "{0}" while validating child node definition
"{1}" of node type "{2}"
+cannotRedefineChildNodeWithIncompatibleDefinition = Cannot redefine child node
"{0}" with required type "{1}" in node type "{2}" with new
child node that does not require that type or a subtype of that type.
noDefinition=Cannot find a definition for the {0} named '{1}' on the node at
'{2}' with primary type '{3}' and mixin types: {4}
noSnsDefinition=Cannot find a definition that allows same-name siblings for the child
node named '{0}' on the node at '{1}' with primary type '{2}' and
mixin types: {3} and a child node already exists with this name
@@ -158,6 +160,7 @@
cannotUnregisterSupertype=Cannot unregister type '{0}' which is supertype of type
'{1}'
cannotUnregisterRequiredPrimaryType=Cannot unregister type '{0}' which is the
required primary type for child node '{2}' on type '{1}'
cannotUnregisterDefaultPrimaryType=Cannot unregister type '{0}' which is the
default primary type for child node '{2}' of type '{1}'
+cannotUnregisterInUseType=Cannot unregister type '{0}' because it is currently
being used on at least one node
cannotAddMixin = This node does not allow adding the mixin type "{0}"
invalidMixinTypeForNode = "{0}" is not currently a mixin type for node
"{1}"