/** * Adds an exception-to-target state mapping to this handler. * @param exceptionClass the type of exception to map * @param targetStateId the id of the state to transition to if the specified type of exception is handled * @return this handler, to allow for adding multiple mappings in a single statement */ public TransitionExecutingFlowExecutionExceptionHandler add(Class<? extends Throwable> exceptionClass, String targetStateId) { return add(exceptionClass, new DefaultTargetStateResolver(targetStateId)); }
private String getEventId() { if (eventId == null) { eventId = determineEventId(requestContext); } return this.eventId; }
/** * Create a transition criteria chain chaining given list of actions. * @param actions the actions (and their execution properties) to chain together */ public static TransitionCriteria criteriaChainFor(Action... actions) { if (actions == null || actions.length == 0) { return WildcardTransitionCriteria.INSTANCE; } TransitionCriteriaChain chain = new TransitionCriteriaChain(); for (Action action : actions) { chain.add(new ActionTransitionCriteria(action)); } return chain; } }
private FlowExecutionExceptionHandler parseTransitionExecutingExceptionHandler(TransitionModel transition) { TransitionExecutingFlowExecutionExceptionHandler handler = new TransitionExecutingFlowExecutionExceptionHandler(); Class<Throwable> exceptionClass = toClass(transition.getOnException(), Throwable.class); TargetStateResolver targetStateResolver = (TargetStateResolver) fromStringTo(TargetStateResolver.class) .execute(transition.getTo()); handler.add(exceptionClass, targetStateResolver); handler.getActionList().addAll(parseActions(transition.getActions())); return handler; }
/** * Find the mapped target state resolver for given exception. Returns <code>null</code> if no mapping can be found * for given exception. Will try all exceptions in the exception cause chain. */ protected TargetStateResolver getTargetStateResolver(Throwable e) { TargetStateResolver targetStateResolver; if (isRootCause(e)) { return findTargetStateResolver(e.getClass()); } else { targetStateResolver = exceptionTargetStateMappings.get(e.getClass()); if (targetStateResolver != null) { return targetStateResolver; } else { return getTargetStateResolver(e.getCause()); } } }
public void handle(FlowExecutionException exception, RequestControlContext context) { if (logger.isDebugEnabled()) { logger.debug("Handling flow execution exception " + exception, exception); } exposeException(context, exception, findRootCause(exception)); actionList.execute(context); context.execute(new Transition(getTargetStateResolver(exception))); }
/** * 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); } }
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); } }
public boolean test(RequestContext context) { Event result = ActionExecutor.execute(getAction(), context); return result != null && isTrueEvent(result.getId()); }
private FlowVariable parseFlowVariable(VarModel var) { Class<?> clazz = toClass(var.getClassName()); VariableValueFactory valueFactory = new BeanFactoryVariableValueFactory(clazz, getFlow() .getApplicationContext().getAutowireCapableBeanFactory()); return new FlowVariable(var.getName(), valueFactory); }
private SubflowAttributeMapper parseSubflowAttributeMapper(SubflowStateModel state) { if (StringUtils.hasText(state.getSubflowAttributeMapper())) { String beanId = state.getSubflowAttributeMapper(); return getLocalContext().getApplicationContext().getBean(beanId, SubflowAttributeMapper.class); } else { Mapper inputMapper = parseSubflowInputMapper(state.getInputs()); Mapper outputMapper = parseSubflowOutputMapper(state.getOutputs()); return new GenericSubflowAttributeMapper(inputMapper, outputMapper); } }
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); } }
public View getView(RequestContext context) { return new ActionExecutingView(action, context); }
public boolean canHandle(FlowExecutionException e) { return getTargetStateResolver(e) != null; }
/** * Find the root cause of given throwable. For use on JDK 1.4 or later. */ private Throwable findRootCause(Throwable e) { Throwable cause = e.getCause(); if (cause == null) { return e; } else { return findRootCause(cause); } }
public Event getFlowEvent() { if (!hasFlowEvent()) { return null; } return new Event(this, eventId); }
public boolean userEventQueued() { return getEventId() != null; }
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 ViewVariable parseViewVariable(VarModel var) { Class<?> clazz = toClass(var.getClassName()); VariableValueFactory valueFactory = new BeanFactoryVariableValueFactory(clazz, getFlow() .getApplicationContext().getAutowireCapableBeanFactory()); return new ViewVariable(var.getName(), valueFactory); }
public boolean hasFlowEvent() { return userEventProcessed && getEventId() != null; }