From 76aa1aeab09560e214ca4398612ce55c6806d0e3 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Sun, 13 Apr 2008 04:38:14 +0000 Subject: [PATCH] flow location pattern element for wildcard paths --- .../FlowRegistryBeanDefinitionParser.java | 19 ++++++++++ .../config/FlowRegistryFactoryBean.java | 36 +++++++++++++++++-- .../config/spring-webflow-config-2.0.xsd | 34 ++++++++++++++---- ...FlowRegistryBeanDefinitionParserTests.java | 7 ++++ .../webflow/config/flow-executor.xml | 2 +- .../webflow/config/flow-registry.xml | 1 + .../webflow/config/flows/flow1.xml | 7 ++++ .../webflow/config/flows/flow2.xml | 7 ++++ 8 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 spring-webflow/src/test/java/org/springframework/webflow/config/flows/flow1.xml create mode 100644 spring-webflow/src/test/java/org/springframework/webflow/config/flows/flow2.xml diff --git a/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryBeanDefinitionParser.java b/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryBeanDefinitionParser.java index e5422750..081c1551 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryBeanDefinitionParser.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryBeanDefinitionParser.java @@ -43,6 +43,8 @@ class FlowRegistryBeanDefinitionParser extends AbstractSingleBeanDefinitionParse private static final String FLOW_LOCATION_ELEMENT = "flow-location"; + private static final String FLOW_LOCATION_PATTERN_ELEMENT = "flow-location-pattern"; + private static final String FLOW_BUILDER_ELEMENT = "flow-builder"; private static final String ID_ATTRIBUTE = "id"; @@ -63,6 +65,8 @@ class FlowRegistryBeanDefinitionParser extends AbstractSingleBeanDefinitionParse private static final String FLOW_LOCATIONS_PROPERTY = "flowLocations"; + private static final String FLOW_LOCATION_PATTERNS_PROPERTY = "flowLocationPatterns"; + private static final String FLOW_BUILDERS_PROPERTY = "flowBuilders"; private static final String FLOW_BUILDER_SERVICES_PROPERTY = "flowBuilderServices"; @@ -87,6 +91,7 @@ class FlowRegistryBeanDefinitionParser extends AbstractSingleBeanDefinitionParse definitionBuilder.addPropertyReference(PARENT_PROPERTY, parent); } definitionBuilder.addPropertyValue(FLOW_LOCATIONS_PROPERTY, parseLocations(element)); + definitionBuilder.addPropertyValue(FLOW_LOCATION_PATTERNS_PROPERTY, parseLocationPatterns(element)); definitionBuilder.addPropertyValue(FLOW_BUILDERS_PROPERTY, parseFlowBuilders(element)); } @@ -105,6 +110,20 @@ class FlowRegistryBeanDefinitionParser extends AbstractSingleBeanDefinitionParse return locations; } + private List parseLocationPatterns(Element element) { + List locationPatternElements = DomUtils.getChildElementsByTagName(element, FLOW_LOCATION_PATTERN_ELEMENT); + if (locationPatternElements.isEmpty()) { + return Collections.EMPTY_LIST; + } + List locationPatterns = new ArrayList(locationPatternElements.size()); + for (Iterator it = locationPatternElements.iterator(); it.hasNext();) { + Element locationPatternElement = (Element) it.next(); + String value = locationPatternElement.getAttribute(VALUE_ATTRIBUTE); + locationPatterns.add(value); + } + return locationPatterns; + } + private Set parseAttributes(Element element) { Element definitionAttributesElement = DomUtils.getChildElementByTagName(element, DEFINITION_ATTRIBUTES_ELEMENT); if (definitionAttributesElement != null) { diff --git a/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryFactoryBean.java b/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryFactoryBean.java index 8e9e0151..e9ff76fb 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryFactoryBean.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryFactoryBean.java @@ -15,6 +15,7 @@ */ package org.springframework.webflow.config; +import java.io.IOException; import java.util.Iterator; import java.util.Set; @@ -56,6 +57,8 @@ class FlowRegistryFactoryBean implements FactoryBean, InitializingBean { private FlowLocation[] flowLocations; + private String[] flowLocationPatterns; + private FlowBuilderInfo[] flowBuilders; private FlowBuilderServices flowBuilderServices; @@ -85,6 +88,13 @@ class FlowRegistryFactoryBean implements FactoryBean, InitializingBean { this.flowLocations = flowLocations; } + /** + * Resolvable path patterns to flows to register in the registry produced by this factory bean. + */ + public void setFlowLocationPatterns(String[] flowLocationPatterns) { + this.flowLocationPatterns = flowLocationPatterns; + } + /** * Java {@link FlowBuilder flow builder} classes that should be registered in the registry produced by this factory * bean. @@ -113,6 +123,7 @@ class FlowRegistryFactoryBean implements FactoryBean, InitializingBean { flowRegistry.setParent(parent); flowModelRegistry = new FlowModelRegistryImpl(); registerFlowLocations(); + registerFlowLocationPatterns(); registerFlowBuilders(); } @@ -132,7 +143,27 @@ class FlowRegistryFactoryBean implements FactoryBean, InitializingBean { if (flowLocations != null) { for (int i = 0; i < flowLocations.length; i++) { FlowLocation location = flowLocations[i]; - flowRegistry.registerFlowDefinition(createFlowDefinitionHolder(location)); + flowRegistry.registerFlowDefinition(createFlowDefinitionHolder(createResource(location))); + } + } + } + + private void registerFlowLocationPatterns() { + if (flowLocationPatterns != null) { + for (int i = 0; i < flowLocationPatterns.length; i++) { + String pattern = flowLocationPatterns[i]; + FlowDefinitionResource[] resources; + try { + resources = flowResourceFactory.createResources(pattern); + } catch (IOException e) { + IllegalStateException ise = new IllegalStateException( + "An I/O Exception occurred resolving the flow location pattern '" + pattern + "'"); + ise.initCause(e); + throw ise; + } + for (int j = 0; j < resources.length; j++) { + flowRegistry.registerFlowDefinition(createFlowDefinitionHolder(resources[j])); + } } } } @@ -146,8 +177,7 @@ class FlowRegistryFactoryBean implements FactoryBean, InitializingBean { } } - private FlowDefinitionHolder createFlowDefinitionHolder(FlowLocation location) { - FlowDefinitionResource flowResource = createResource(location); + private FlowDefinitionHolder createFlowDefinitionHolder(FlowDefinitionResource flowResource) { FlowBuilder builder = createFlowBuilder(flowResource); FlowBuilderContext builderContext = new FlowBuilderContextImpl(flowResource.getId(), flowResource .getAttributes(), flowRegistry, flowBuilderServices); diff --git a/spring-webflow/src/main/java/org/springframework/webflow/config/spring-webflow-config-2.0.xsd b/spring-webflow/src/main/java/org/springframework/webflow/config/spring-webflow-config-2.0.xsd index 1d1b4861..2c6311ab 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/config/spring-webflow-config-2.0.xsd +++ b/spring-webflow/src/main/java/org/springframework/webflow/config/spring-webflow-config-2.0.xsd @@ -36,26 +36,46 @@ would index those definitions by "orderitem-flow" and "shipping-flow" by default - - + + - + + + + + + + + + + + + + + + + + - + @@ -379,7 +399,7 @@ Example: 'flow1,flow2,flow3'. - + - + diff --git a/spring-webflow/src/test/java/org/springframework/webflow/config/flow-registry.xml b/spring-webflow/src/test/java/org/springframework/webflow/config/flow-registry.xml index 8fec330f..14255bf9 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/config/flow-registry.xml +++ b/spring-webflow/src/test/java/org/springframework/webflow/config/flow-registry.xml @@ -16,6 +16,7 @@ + diff --git a/spring-webflow/src/test/java/org/springframework/webflow/config/flows/flow1.xml b/spring-webflow/src/test/java/org/springframework/webflow/config/flows/flow1.xml new file mode 100644 index 00000000..00011745 --- /dev/null +++ b/spring-webflow/src/test/java/org/springframework/webflow/config/flows/flow1.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/spring-webflow/src/test/java/org/springframework/webflow/config/flows/flow2.xml b/spring-webflow/src/test/java/org/springframework/webflow/config/flows/flow2.xml new file mode 100644 index 00000000..00011745 --- /dev/null +++ b/spring-webflow/src/test/java/org/springframework/webflow/config/flows/flow2.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file