private Expression parseFieldExpression(String field, boolean useResultTypeHint) { FluentParserContext parserContext = new FluentParserContext().evaluate(boundObject.getClass()); if (useResultTypeHint) { parserContext.expectResult(String.class); } return expressionParser.parseExpression(field, parserContext); }
public boolean isDelimitedExpression(String expressionString) { return getDefaultExpressionParser().isDelimitedExpression(expressionString); }
public SettableExpression parseSettableExpression(String expressionString) throws ParserException, UnsupportedOperationException { return getDefaultExpressionParser().parseSettableExpression(expressionString); } };
protected Object doConvert(Object source, Class targetClass, ConversionContext context) throws Exception { String expressionString = (String) source; if (getExpressionParser().isDelimitedExpression(expressionString)) { return getExpressionParser().parseExpression((String) source); } else { return new StaticExpression(expressionString); } } }
private Action parseSetAction(Element element) { String attributeExpressionString = element.getAttribute(ATTRIBUTE_ATTRIBUTE); SettableExpression attributeExpression = getLocalFlowServiceLocator().getExpressionParser() .parseSettableExpression(attributeExpressionString); Expression valueExpression = getLocalFlowServiceLocator().getExpressionParser().parseExpression( element.getAttribute(VALUE_ATTRIBUTE)); return new SetAction(attributeExpression, parseScope(element, ScopeType.REQUEST), valueExpression); }
protected Object doConvert(Object source, Class targetClass, ConversionContext context) throws Exception { String targetStateId = (String) source; if (flowServiceLocator.getExpressionParser().isDelimitedExpression(targetStateId)) { Expression expression = flowServiceLocator.getExpressionParser().parseExpression(targetStateId); return new DefaultTargetStateResolver(expression); } else if (targetStateId.startsWith(BEAN_PREFIX)) { return flowServiceLocator.getTargetStateResolver(targetStateId.substring(BEAN_PREFIX.length())); } else { return new DefaultTargetStateResolver(targetStateId); } } }
private void parseMappings(DefaultAttributeMapper mapper, Element element) { ExpressionParser parser = getLocalFlowServiceLocator().getExpressionParser(); List mappingElements = DomUtils.getChildElementsByTagName(element, MAPPING_ELEMENT); for (Iterator it = mappingElements.iterator(); it.hasNext();) { Element mappingElement = (Element) it.next(); Expression source = parser.parseExpression(mappingElement.getAttribute(SOURCE_ATTRIBUTE)); SettableExpression target = null; if (StringUtils.hasText(mappingElement.getAttribute(TARGET_ATTRIBUTE))) { target = parser.parseSettableExpression(mappingElement.getAttribute(TARGET_ATTRIBUTE)); } else if (StringUtils.hasText(mappingElement.getAttribute(TARGET_COLLECTION_ATTRIBUTE))) { target = new CollectionAddingExpression(parser.parseSettableExpression(mappingElement .getAttribute(TARGET_COLLECTION_ATTRIBUTE))); } if (getRequired(mappingElement, false)) { mapper.addMapping(new RequiredMapping(source, target, parseTypeConverter(mappingElement))); } else { mapper.addMapping(new Mapping(source, target, parseTypeConverter(mappingElement))); } } }
/** * Adds a {@link DefaultMapping} between the given request parameter name and a matching model field. * * @param mapper the mapper to add the mapping to * @param parameter the request parameter name * @param model the model */ protected void addDefaultMapping(DefaultMapper mapper, String parameter, Object model) { Expression source = new RequestParameterExpression(parameter); ParserContext parserContext = new SimpleParserContext(model.getClass()); if (expressionParser instanceof BeanWrapperExpressionParser || checkModelProperty(parameter, model)) { Expression target = expressionParser.parseExpression(parameter, parserContext); DefaultMapping mapping = new DefaultMapping(source, target); if (logger.isDebugEnabled()) { logger.debug("Adding default mapping for parameter '" + parameter + "'"); } mapper.addMapping(mapping); } }
protected Object doConvert(Object source, Class targetClass, ConversionContext context) throws Exception { String encodedCriteria = (String) source; if (!StringUtils.hasText(encodedCriteria) || WildcardTransitionCriteria.WILDCARD_EVENT_ID.equals(encodedCriteria)) { return WildcardTransitionCriteria.INSTANCE; } else if (flowServiceLocator.getExpressionParser().isDelimitedExpression(encodedCriteria)) { Expression expression = flowServiceLocator.getExpressionParser().parseExpression(encodedCriteria); return createBooleanExpressionTransitionCriteria(expression); } else if (encodedCriteria.startsWith(BEAN_PREFIX)) { return flowServiceLocator.getTransitionCriteria(encodedCriteria.substring(BEAN_PREFIX.length())); } else { return createEventIdTransitionCriteria(encodedCriteria); } }
/** * Sets the target collection of the mapping built by this builder. * @param expressionString the expression string, resolving a collection * @return this, to support call-chaining */ public MappingBuilder targetCollection(String expressionString) { targetExpression = new CollectionAddingExpression(expressionParser.parseSettableExpression(expressionString)); return this; }
/** * Adds a special {@link DefaultMapping} that results in setting the target field on the model to an empty value * (typically null). * * @param mapper the mapper to add the mapping to * @param field the field for which a mapping is to be added * @param model the model */ protected void addEmptyValueMapping(DefaultMapper mapper, String field, Object model) { ParserContext parserContext = new SimpleParserContext(model.getClass()); Expression target = emptyValueExpressionParser.parseExpression(field, parserContext); try { Class<?> propertyType = target.getValueType(model); Expression source = new StaticExpression(getEmptyValue(propertyType)); DefaultMapping mapping = new DefaultMapping(source, target); if (logger.isDebugEnabled()) { logger.debug("Adding empty value mapping for parameter '" + field + "'"); } mapper.addMapping(mapping); } catch (EvaluationException e) { } }
/** * Parses the expression string into a settable {@link Expression} object. * @param expressionString the expression string, e.g. flowScope.order.number * @return the evaluatable expression * @since 1.0.2 */ protected SettableExpression settableExpression(String expressionString) { return getFlowServiceLocator().getExpressionParser().parseSettableExpression(expressionString); }
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception { String targetStateId = (String) source; if (!StringUtils.hasText(targetStateId)) { return null; } ExpressionParser parser = flowBuilderContext.getExpressionParser(); Expression expression = parser.parseExpression(targetStateId, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return new DefaultTargetStateResolver(expression); } }
/** * Adds an input mapping that maps a single attribute in parent <i>flow scope</i> into the subflow input map. For * instance: "x" will result in the "x" attribute in parent flow scope being mapped into the subflow input map as * "x". * @param attributeName the attribute in flow scope to map into the subflow * @return this, to support call chaining */ public ConfigurableFlowAttributeMapper addInputAttribute(String attributeName) { SettableExpression attribute = expressionParser.parseSettableExpression(attributeName); Expression scope = new AttributeExpression(attribute, ScopeType.FLOW); addInputMapping(new Mapping(scope, attribute, null)); return this; }
/** * Hook method subclasses can override to return a specialized expression evaluating transition criteria * implementation. * @param encodedCriteria the encoded transition criteria expression * @param parser the parser that should parse the expression * @return the transition criteria object * @throws ConversionExecutionException when something goes wrong */ protected TransitionCriteria createBooleanExpressionTransitionCriteria(String encodedCriteria, ExpressionParser parser) throws ConversionExecutionException { Expression expression = parser.parseExpression(encodedCriteria, new FluentParserContext().template().evaluate(RequestContext.class)); return new DefaultTransitionCriteria(expression); } }
private void parseSimpleAttributeMappings(DefaultAttributeMapper mapper, List elements) { ExpressionParser parser = getLocalFlowServiceLocator().getExpressionParser(); for (Iterator it = elements.iterator(); it.hasNext();) { Element element = (Element) it.next(); SettableExpression attribute = parser.parseSettableExpression(element.getAttribute(NAME_ATTRIBUTE)); SettableExpression expression = new AttributeExpression(attribute, parseScope(element, ScopeType.FLOW)); if (getRequired(element, false)) { mapper.addMapping(new RequiredMapping(expression, expression, null)); } else { mapper.addMapping(new Mapping(expression, expression, null)); } } }
private DefaultMapping parseSubflowInputMapping(InputModel input) { ExpressionParser parser = getLocalContext().getExpressionParser(); String name = input.getName(); String value = null; if (StringUtils.hasText(input.getValue())) { value = input.getValue(); } else { value = name; } Expression source = parser.parseExpression(value, new FluentParserContext().evaluate(RequestContext.class)); Expression target = parser.parseExpression(name, new FluentParserContext().evaluate(MutableAttributeMap.class)); DefaultMapping mapping = new DefaultMapping(source, target); parseAndSetMappingConversionExecutor(input, mapping); parseAndSetMappingRequired(input, mapping); return mapping; }
private DefaultMapping parseFlowInputMapping(InputModel input) { ExpressionParser parser = getLocalContext().getExpressionParser(); String name = input.getName(); String value = null; if (StringUtils.hasText(input.getValue())) { value = input.getValue(); } else { value = "flowScope." + name; } Expression source = parser.parseExpression(name, new FluentParserContext().evaluate(MutableAttributeMap.class)); Expression target = parser.parseExpression(value, new FluentParserContext().evaluate(RequestContext.class)); DefaultMapping mapping = new DefaultMapping(source, target); parseAndSetMappingConversionExecutor(input, mapping); parseAndSetMappingRequired(input, mapping); return mapping; }
private DefaultMapping parseFlowOutputMapping(OutputModel output) { ExpressionParser parser = getLocalContext().getExpressionParser(); String name = output.getName(); String value = null; if (StringUtils.hasText(output.getValue())) { value = output.getValue(); } else { value = name; } Expression source = parser.parseExpression(value, new FluentParserContext().evaluate(RequestContext.class)); Expression target = parser.parseExpression(name, new FluentParserContext().evaluate(MutableAttributeMap.class)); DefaultMapping mapping = new DefaultMapping(source, target); parseAndSetMappingConversionExecutor(output, mapping); parseAndSetMappingRequired(output, mapping); return mapping; }
private DefaultMapping parseSubflowOutputMapping(OutputModel output) { ExpressionParser parser = getLocalContext().getExpressionParser(); String name = output.getName(); String value = null; if (StringUtils.hasText(output.getValue())) { value = output.getValue(); } else { value = "flowScope." + name; } Expression source = parser.parseExpression(name, new FluentParserContext().evaluate(MutableAttributeMap.class)); Expression target = parser.parseExpression(value, new FluentParserContext().evaluate(RequestContext.class)); DefaultMapping mapping = new DefaultMapping(source, target); parseAndSetMappingConversionExecutor(output, mapping); parseAndSetMappingRequired(output, mapping); return mapping; }