diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/XmlFlowModelBuilder.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/XmlFlowModelBuilder.java index 78ea672a..5fd6f85d 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/XmlFlowModelBuilder.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/XmlFlowModelBuilder.java @@ -154,13 +154,12 @@ public class XmlFlowModelBuilder implements FlowModelBuilder { String flowId; String stateId; AbstractStateModel parentState = null; - if (parent.contains("#")) { - flowId = parent.substring(0, parent.indexOf("#")).trim(); - stateId = parent.substring(parent.indexOf("#") + 1).trim(); - } else { - flowId = parent.trim(); - stateId = childState.getId(); + if (!parent.contains("#")) { + throw new FlowModelBuilderException("Invalid parent syntax '" + parent + + "', should take form 'flowId#stateId'"); } + flowId = parent.substring(0, parent.indexOf("#")).trim(); + stateId = parent.substring(parent.indexOf("#") + 1).trim(); try { parentState = modelLocator.getFlowModel(flowId).getStateById(stateId); if (parentState == null) { diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/spring-webflow-2.0.xsd b/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/spring-webflow-2.0.xsd index b39b9dc5..92263077 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/spring-webflow-2.0.xsd +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/spring-webflow-2.0.xsd @@ -284,11 +284,9 @@ The unique identifier of this state; must be unique to this flow. -For example
<state id="state" parent="flow">
defaults to
<state id="state" parent="flow#state">
. -To inherit from a different identifier
<state id="state" parent="flow#other">
- +For example
<state id="state" parent="flowId#stateId">
]]>
@@ -449,11 +447,9 @@ The unique identifier of this state; must be unique to this flow. -For example
<state id="state" parent="flow">
defaults to
<state id="state" parent="flow#state">
. -To inherit from a different identifier
<state id="state" parent="flow#other">
- +For example
<state id="state" parent="flowId#stateId">
]]>
@@ -651,11 +647,9 @@ The unique identifier of this state; must be unique to this flow. -For example
<state id="state" parent="flow">
defaults to
<state id="state" parent="flow#state">
. -To inherit from a different identifier
<state id="state" parent="flow#other">
- +For example
<state id="state" parent="flowId#stateId">
]]>
@@ -770,11 +764,9 @@ The unique identifier of this state; must be unique to this flow. -For example
<state id="state" parent="flow">
defaults to
<state id="state" parent="flow#state">
. -To inherit from a different identifier
<state id="state" parent="flow#other">
- +For example
<state id="state" parent="flowId#stateId">
]]>
@@ -878,11 +870,9 @@ The unique identifier of this state; must be unique to this flow. -For example
<state id="state" parent="flow">
defaults to
<state id="state" parent="flow#state">
. -To inherit from a different identifier
<state id="state" parent="flow#other">
- +For example
<state id="state" parent="flowId#stateId">
]]>
diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/model/builder/xml/XmlFlowModelBuilderTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/model/builder/xml/XmlFlowModelBuilderTests.java index a890b3ef..36f51a9f 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/model/builder/xml/XmlFlowModelBuilderTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/model/builder/xml/XmlFlowModelBuilderTests.java @@ -172,7 +172,6 @@ public class XmlFlowModelBuilderTests extends TestCase { fail("A FlowModelConstructionException was expected"); } catch (FlowModelConstructionException e) { // we want this - e.printStackTrace(); } } @@ -197,16 +196,20 @@ public class XmlFlowModelBuilderTests extends TestCase { assertEquals("otherview", ((ViewStateModel) flow.getStates().get(0)).getView()); } - public void testStateMergeDefault() { - ClassPathResource resourceChild = new ClassPathResource("flow-inheritance-state-child-default.xml", getClass()); + public void testStateMergeInvalidParentSyntax() { + ClassPathResource resourceChild = new ClassPathResource("flow-inheritance-state-invalid-parent-syntax.xml", + getClass()); ClassPathResource resourceParent = new ClassPathResource("flow-inheritance-state-parent.xml", getClass()); registry .registerFlowModel(new DefaultFlowModelHolder(new XmlFlowModelBuilder(resourceChild, registry), "child")); registry.registerFlowModel(new DefaultFlowModelHolder(new XmlFlowModelBuilder(resourceParent, registry), "parent")); - FlowModel flow = registry.getFlowModel("child"); - assertEquals(1, flow.getStates().size()); - assertEquals("mainview", ((ViewStateModel) flow.getStates().get(0)).getView()); + try { + registry.getFlowModel("child"); + fail("A FlowModelConstructionException was expected"); + } catch (FlowModelConstructionException e) { + // we want this + } } public void testStateMergeParentFlowNotFound() { diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/model/builder/xml/flow-inheritance-state-child-default.xml b/spring-webflow/src/test/java/org/springframework/webflow/engine/model/builder/xml/flow-inheritance-state-invalid-parent-syntax.xml similarity index 100% rename from spring-webflow/src/test/java/org/springframework/webflow/engine/model/builder/xml/flow-inheritance-state-child-default.xml rename to spring-webflow/src/test/java/org/springframework/webflow/engine/model/builder/xml/flow-inheritance-state-invalid-parent-syntax.xml