From 29b14ef58bd6ed2d3c2db2bf3ca314ce2cd0e32a Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Thu, 20 Mar 2008 06:11:48 +0000 Subject: [PATCH] no bind action anymore --- .../webflow/action/BindAction.java | 79 ----------- .../engine/builder/xml/XmlFlowBuilder.java | 12 +- .../engine/builder/xml/spring-webflow-2.0.xsd | 23 --- .../webflow/action/BindActionTests.java | 134 ------------------ 4 files changed, 1 insertion(+), 247 deletions(-) delete mode 100644 spring-webflow/src/main/java/org/springframework/webflow/action/BindAction.java delete mode 100644 spring-webflow/src/test/java/org/springframework/webflow/action/BindActionTests.java diff --git a/spring-webflow/src/main/java/org/springframework/webflow/action/BindAction.java b/spring-webflow/src/main/java/org/springframework/webflow/action/BindAction.java deleted file mode 100644 index 2a0b31b9..00000000 --- a/spring-webflow/src/main/java/org/springframework/webflow/action/BindAction.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.springframework.webflow.action; - -import java.util.Iterator; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.binding.convert.ConversionService; -import org.springframework.binding.expression.Expression; -import org.springframework.binding.expression.ExpressionParser; -import org.springframework.binding.expression.support.ParserContextImpl; -import org.springframework.binding.mapping.MappingResult; -import org.springframework.binding.mapping.MappingResults; -import org.springframework.binding.mapping.MappingResultsCriteria; -import org.springframework.binding.mapping.impl.DefaultMapper; -import org.springframework.binding.mapping.impl.DefaultMapping; -import org.springframework.binding.mapping.results.TargetAccessError; -import org.springframework.webflow.core.collection.AttributeMap; -import org.springframework.webflow.execution.Event; -import org.springframework.webflow.execution.RequestContext; - -public class BindAction extends AbstractAction { - - private static final Log logger = LogFactory.getLog(BindAction.class); - - private static final MappingResultsCriteria PROPERTY_NOT_FOUND_ERRORS = new PropertyNotFoundErrors(); - - private Expression target; - - private ExpressionParser expressionParser; - - private ConversionService conversionService; - - public BindAction(Expression target, ExpressionParser expressionParser, ConversionService conversionService) { - this.target = target; - this.expressionParser = expressionParser; - this.conversionService = conversionService; - } - - protected Event doExecute(final RequestContext context) throws Exception { - Object target = this.target.getValue(context); - if (target == null) { - throw new IllegalStateException( - "The bind target cannot be null - check your expression. Bind target expression = " + target); - } - DefaultMapper mapper = new DefaultMapper(); - mapper.setConversionService(conversionService); - AttributeMap eventAttributes = context.getLastEvent().getAttributes(); - if (logger.isDebugEnabled()) { - logger.debug("Binding event '" + context.getLastEvent().getId() + "' attributes " + eventAttributes - + " to target " + target); - } - for (Iterator it = eventAttributes.asMap().keySet().iterator(); it.hasNext();) { - String name = (String) it.next(); - Expression sourceAttribute = expressionParser.parseExpression(name, new ParserContextImpl() - .eval(AttributeMap.class)); - Expression targetAttribute = expressionParser.parseExpression(name, new ParserContextImpl().eval(target - .getClass())); - mapper.addMapping(new DefaultMapping(sourceAttribute, targetAttribute)); - } - MappingResults results = mapper.map(context.getLastEvent().getAttributes(), target); - if (!results.hasErrorResults()) { - return success(); - } else { - if (results.getResults(PROPERTY_NOT_FOUND_ERRORS).size() == results.getErrorResults().size()) { - // all errors are 'property not found' -- acceptable - return success(); - } else { - return error(); - } - } - } - - private static class PropertyNotFoundErrors implements MappingResultsCriteria { - public boolean test(MappingResult result) { - return result.getResult() instanceof TargetAccessError - && result.getResult().getErrorCode().equals("propertyNotFound"); - } - } -} diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/xml/XmlFlowBuilder.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/xml/XmlFlowBuilder.java index 8ff3f899..12747f0b 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/xml/XmlFlowBuilder.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/xml/XmlFlowBuilder.java @@ -55,7 +55,6 @@ import org.springframework.util.xml.DomUtils; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.GenericWebApplicationContext; import org.springframework.webflow.action.ActionResultExposer; -import org.springframework.webflow.action.BindAction; import org.springframework.webflow.action.EvaluateAction; import org.springframework.webflow.action.ExternalRedirectAction; import org.springframework.webflow.action.FlowDefinitionRedirectAction; @@ -676,9 +675,7 @@ public class XmlFlowBuilder extends AbstractFlowBuilder implements ResourceHolde if (!(childNode instanceof Element)) { continue; } - if (DomUtils.nodeNameEquals(childNode, "bind")) { - actions.add(parseBindAction((Element) childNode)); - } else if (DomUtils.nodeNameEquals(childNode, "evaluate")) { + if (DomUtils.nodeNameEquals(childNode, "evaluate")) { actions.add(parseEvaluateAction((Element) childNode)); } else if (DomUtils.nodeNameEquals(childNode, "render")) { actions.add(parseRenderAction((Element) childNode)); @@ -689,13 +686,6 @@ public class XmlFlowBuilder extends AbstractFlowBuilder implements ResourceHolde return (Action[]) actions.toArray(new Action[actions.size()]); } - private Action parseBindAction(Element element) { - String targetString = element.getAttribute("target"); - ExpressionParser parser = getExpressionParser(); - Expression target = parser.parseExpression(targetString, new ParserContextImpl().eval(RequestContext.class)); - return new BindAction(target, parser, getConversionService()); - } - private Action parseEvaluateAction(Element element) { String expressionString = element.getAttribute("expression"); Expression expression = getExpressionParser().parseExpression(expressionString, diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/xml/spring-webflow-2.0.xsd b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/xml/spring-webflow-2.0.xsd index d92cbb9e..73cada43 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/xml/spring-webflow-2.0.xsd +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/xml/spring-webflow-2.0.xsd @@ -121,15 +121,6 @@ Goes out of scope when the governing conversation ends. - - - - - - - @@ -659,20 +650,6 @@ Handles exceptions that occur within this state. - - - - - - - - - - - - diff --git a/spring-webflow/src/test/java/org/springframework/webflow/action/BindActionTests.java b/spring-webflow/src/test/java/org/springframework/webflow/action/BindActionTests.java deleted file mode 100644 index 39bda3a8..00000000 --- a/spring-webflow/src/test/java/org/springframework/webflow/action/BindActionTests.java +++ /dev/null @@ -1,134 +0,0 @@ -package org.springframework.webflow.action; - -import junit.framework.TestCase; - -import org.springframework.binding.convert.ConversionService; -import org.springframework.binding.convert.support.DefaultConversionService; -import org.springframework.binding.expression.Expression; -import org.springframework.binding.expression.ExpressionParser; -import org.springframework.binding.expression.support.ParserContextImpl; -import org.springframework.webflow.core.collection.LocalAttributeMap; -import org.springframework.webflow.execution.Event; -import org.springframework.webflow.execution.RequestContext; -import org.springframework.webflow.expression.DefaultExpressionParserFactory; -import org.springframework.webflow.test.MockRequestContext; - -public class BindActionTests extends TestCase { - private ExpressionParser expressionParser = DefaultExpressionParserFactory.getExpressionParser(); - private ConversionService conversionService = new DefaultConversionService(); - - private BindAction action; - - public void testSuccessfulBind() throws Exception { - MockRequestContext context = new MockRequestContext(); - context.getFlowScope().put("bindTarget", new BindBean()); - - Expression target = expressionParser.parseExpression("bindTarget", new ParserContextImpl() - .eval(RequestContext.class)); - action = new BindAction(target, expressionParser, conversionService); - - LocalAttributeMap eventData = new LocalAttributeMap(); - eventData.put("stringProperty", "foo"); - eventData.put("integerProperty", "3"); - Event event = new Event(this, "submit", eventData); - context.setLastEvent(event); - - Event result = action.execute(context); - assertEquals("success", result.getId()); - - BindBean bean = (BindBean) context.getFlowScope().get("bindTarget"); - assertEquals("foo", bean.getStringProperty()); - assertEquals(new Integer(3), bean.getIntegerProperty()); - } - - public void testBindNonexistantProperties() throws Exception { - MockRequestContext context = new MockRequestContext(); - context.getFlowScope().put("bindTarget", new BindBean()); - - Expression target = expressionParser.parseExpression("bindTarget", new ParserContextImpl() - .eval(RequestContext.class)); - action = new BindAction(target, expressionParser, conversionService); - - LocalAttributeMap eventData = new LocalAttributeMap(); - eventData.put("stringProperty", "foo"); - eventData.put("bogusProperty", "bar"); - eventData.put("integerProperty", "3"); - Event event = new Event(this, "submit", eventData); - context.setLastEvent(event); - - Event result = action.execute(context); - assertEquals("success", result.getId()); - - BindBean bean = (BindBean) context.getFlowScope().get("bindTarget"); - assertEquals("foo", bean.getStringProperty()); - assertEquals(new Integer(3), bean.getIntegerProperty()); - assertEquals(0, context.getMessageContext().getMessages().length); - } - - public void testBindWithTypeConversionErrors() throws Exception { - MockRequestContext context = new MockRequestContext(); - context.getFlowScope().put("bindTarget", new BindBean()); - - Expression target = expressionParser.parseExpression("bindTarget", new ParserContextImpl() - .eval(RequestContext.class)); - action = new BindAction(target, expressionParser, conversionService); - - LocalAttributeMap eventData = new LocalAttributeMap(); - eventData.put("stringProperty", "foo"); - eventData.put("integerProperty", "malformed"); - Event event = new Event(this, "submit", eventData); - context.setLastEvent(event); - - Event result = action.execute(context); - assertEquals("error", result.getId()); - - BindBean bean = (BindBean) context.getFlowScope().get("bindTarget"); - assertEquals("foo", bean.getStringProperty()); - assertEquals(new Integer(3), bean.getIntegerProperty()); - } - - public void testBindWithEmptyAttributes() throws Exception { - MockRequestContext context = new MockRequestContext(); - context.getFlowScope().put("bindTarget", new BindBean()); - - Expression target = expressionParser.parseExpression("bindTarget", new ParserContextImpl() - .eval(RequestContext.class)); - action = new BindAction(target, expressionParser, conversionService); - - LocalAttributeMap eventData = new LocalAttributeMap(); - eventData.put("stringProperty", ""); - eventData.put("integerProperty", null); - Event event = new Event(this, "submit", eventData); - context.setLastEvent(event); - - Event result = action.execute(context); - System.out.println(context.getMessageContext()); - assertEquals("success", result.getId()); - - BindBean bean = (BindBean) context.getFlowScope().get("bindTarget"); - assertEquals("", bean.getStringProperty()); - assertEquals(null, bean.getIntegerProperty()); - assertEquals(0, context.getMessageContext().getMessages().length); - } - - public static class BindBean { - private String stringProperty; - private Integer integerProperty = new Integer(3); - - public String getStringProperty() { - return stringProperty; - } - - public void setStringProperty(String stringProperty) { - this.stringProperty = stringProperty; - } - - public Integer getIntegerProperty() { - return integerProperty; - } - - public void setIntegerProperty(Integer integerProperty) { - this.integerProperty = integerProperty; - } - } -}