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 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); } }
private Action parseRenderAction(RenderModel render) { String[] fragmentExpressionStrings = StringUtils.commaDelimitedListToStringArray(render.getFragments()); fragmentExpressionStrings = StringUtils.trimArrayElements(fragmentExpressionStrings); ParserContext context = new FluentParserContext().template().evaluate(RequestContext.class) .expectResult(String.class); Expression[] fragments = new Expression[fragmentExpressionStrings.length]; for (int i = 0; i < fragmentExpressionStrings.length; i++) { String fragment = fragmentExpressionStrings[i]; fragments[i] = getLocalContext().getExpressionParser().parseExpression(fragment, context); } return new RenderAction(fragments); }
private ViewFactory parseViewFactory(String view, String stateId, boolean endState, BinderModel binderModel) { if (!StringUtils.hasText(view)) { if (endState) { return null; } else { view = getLocalContext().getViewFactoryCreator().getViewIdByConvention(stateId); Expression viewId = getLocalContext().getExpressionParser().parseExpression(view, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return createViewFactory(viewId, binderModel); } } else if (view.startsWith("externalRedirect:")) { String encodedUrl = view.substring("externalRedirect:".length()); Expression externalUrl = getLocalContext().getExpressionParser().parseExpression(encodedUrl, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return new ActionExecutingViewFactory(new ExternalRedirectAction(externalUrl)); } else if (view.startsWith("flowRedirect:")) { String flowRedirect = view.substring("flowRedirect:".length()); Expression expression = getLocalContext().getExpressionParser().parseExpression(flowRedirect, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return new ActionExecutingViewFactory(new FlowDefinitionRedirectAction(expression)); } else { Expression viewId = getLocalContext().getExpressionParser().parseExpression(view, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return createViewFactory(viewId, binderModel); } }
private Expression parseSubflowExpression(String subflow) { Expression subflowId = getLocalContext().getExpressionParser().parseExpression(subflow, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return new SubflowExpression(subflowId, getLocalContext().getFlowDefinitionLocator()); }
private Action parseEvaluateAction(EvaluateModel evaluate) { FluentParserContext evaluateExpressionParserContext = new FluentParserContext().evaluate(RequestContext.class); if (StringUtils.hasText(evaluate.getResultType())) { evaluateExpressionParserContext.expectResult(toClass(evaluate.getResultType())); } Expression evaluateExpression = getLocalContext().getExpressionParser().parseExpression( evaluate.getExpression(), evaluateExpressionParserContext); Expression resultExpression = null; if (StringUtils.hasText(evaluate.getResult())) { resultExpression = getLocalContext().getExpressionParser().parseExpression(evaluate.getResult(), new FluentParserContext().evaluate(RequestContext.class)); } return new EvaluateAction(evaluateExpression, resultExpression); }
private Action parseSetAction(SetModel set) { Expression nameExpression = getLocalContext().getExpressionParser().parseExpression(set.getName(), new FluentParserContext().evaluate(RequestContext.class)); FluentParserContext valueParserContext = new FluentParserContext().evaluate(RequestContext.class); if (StringUtils.hasText(set.getType())) { valueParserContext.expectResult(toClass(set.getType())); } Expression valueExpression = getLocalContext().getExpressionParser().parseExpression(set.getValue(), valueParserContext); return new SetAction(nameExpression, valueExpression); }
private Transition parseThen(IfModel ifModel) { Expression test = getLocalContext().getExpressionParser().parseExpression(ifModel.getTest(), new FluentParserContext().evaluate(RequestContext.class).expectResult(Boolean.class)); TransitionCriteria matchingCriteria = new DefaultTransitionCriteria(test); TargetStateResolver targetStateResolver = (TargetStateResolver) fromStringTo(TargetStateResolver.class) .execute(ifModel.getThen()); return getLocalContext().getFlowArtifactFactory().createTransition(targetStateResolver, matchingCriteria, null, null); }
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); }
/** * Create expression expression. * * @param expression the expression * @param expectedType the expected type * @return the expression */ public Expression createExpression(final String expression, final Class expectedType) { val parserContext = new FluentParserContext().expectResult(expectedType); return getSpringExpressionParser().parseExpression(expression, parserContext); }
private Action parseRenderAction(RenderModel render) { String[] fragmentExpressionStrings = StringUtils.commaDelimitedListToStringArray(render.getFragments()); fragmentExpressionStrings = StringUtils.trimArrayElements(fragmentExpressionStrings); ParserContext context = new FluentParserContext().template().evaluate(RequestContext.class) .expectResult(String.class); Expression[] fragments = new Expression[fragmentExpressionStrings.length]; for (int i = 0; i < fragmentExpressionStrings.length; i++) { String fragment = fragmentExpressionStrings[i]; fragments[i] = getLocalContext().getExpressionParser().parseExpression(fragment, context); } return new RenderAction(fragments); }
public void testParseSimpleEvalExpressionNoEvalContextWithTypeCoersion() { String expressionString = "3 + 4"; Expression exp = parser.parseExpression(expressionString, new FluentParserContext().expectResult(Long.class)); assertEquals(7L, exp.getValue(null)); }
private Expression parseSubflowExpression(String subflow) { Expression subflowId = getLocalContext().getExpressionParser().parseExpression(subflow, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return new SubflowExpression(subflowId, getLocalContext().getFlowDefinitionLocator()); }
private Action parseEvaluateAction(EvaluateModel evaluate) { FluentParserContext evaluateExpressionParserContext = new FluentParserContext().evaluate(RequestContext.class); if (StringUtils.hasText(evaluate.getResultType())) { evaluateExpressionParserContext.expectResult(toClass(evaluate.getResultType())); } Expression evaluateExpression = getLocalContext().getExpressionParser().parseExpression( evaluate.getExpression(), evaluateExpressionParserContext); Expression resultExpression = null; if (StringUtils.hasText(evaluate.getResult())) { resultExpression = getLocalContext().getExpressionParser().parseExpression(evaluate.getResult(), new FluentParserContext().evaluate(RequestContext.class)); } return new EvaluateAction(evaluateExpression, resultExpression); }
public void testParseSimpleEvalExpressionNoEvalContextWithTypeCoersion() { String expressionString = "3 + 4"; Expression exp = parser .parseExpression(expressionString, new FluentParserContext().expectResult(Integer.class)); assertEquals(7, exp.getValue(null)); }
private Action parseSetAction(SetModel set) { Expression nameExpression = getLocalContext().getExpressionParser().parseExpression(set.getName(), new FluentParserContext().evaluate(RequestContext.class)); FluentParserContext valueParserContext = new FluentParserContext().evaluate(RequestContext.class); if (StringUtils.hasText(set.getType())) { valueParserContext.expectResult(toClass(set.getType())); } Expression valueExpression = getLocalContext().getExpressionParser().parseExpression(set.getValue(), valueParserContext); return new SetAction(nameExpression, valueExpression); }
public void testParseEvalExpressionWithContextTypeCoersion() { String expressionString = "maximum"; Expression exp = parser.parseExpression(expressionString, new FluentParserContext().expectResult(Long.class)); assertEquals(2L, exp.getValue(new TestBean())); }
public void testGetValueCoersionError() { String expressionString = "maximum"; Expression exp = parser.parseExpression(expressionString, new FluentParserContext().expectResult(TestBean.class)); TestBean context = new TestBean(); try { exp.getValue(context); fail("Should have failed with coersion"); } catch (ValueCoercionException e) { } }
private Transition parseThen(IfModel ifModel) { Expression test = getLocalContext().getExpressionParser().parseExpression(ifModel.getTest(), new FluentParserContext().evaluate(RequestContext.class).expectResult(Boolean.class)); TransitionCriteria matchingCriteria = new DefaultTransitionCriteria(test); TargetStateResolver targetStateResolver = (TargetStateResolver) fromStringTo(TargetStateResolver.class) .execute(ifModel.getThen()); return getLocalContext().getFlowArtifactFactory().createTransition(targetStateResolver, matchingCriteria, null, null); }
public void testVariablesWithCoersion() { Expression exp = parser.parseExpression("max", new FluentParserContext().variable(new ExpressionVariable("max", "maximum", new FluentParserContext().expectResult(Long.class)))); TestBean target = new TestBean(); assertEquals(2L, exp.getValue(target)); }