public void registerFlowDefinition(FlowDefinition definition) { registerFlowDefinition(new StaticFlowDefinitionHolder(definition)); }
public FlowDefinition getFlowDefinition(String id) throws NoSuchFlowDefinitionException, FlowDefinitionConstructionException { Assert.hasText(id, "An id is required to lookup a FlowDefinition"); try { if (logger.isDebugEnabled()) { logger.debug("Getting FlowDefinition with id '" + id + "'"); } return getFlowDefinitionHolder(id).getFlowDefinition(); } catch (NoSuchFlowDefinitionException e) { if (parent != null) { // try parent return parent.getFlowDefinition(id); } throw e; } }
/** * Returns the identified flow definition holder. Throws an exception if it cannot be found. */ private FlowDefinitionHolder getFlowDefinitionHolder(String id) throws NoSuchFlowDefinitionException { FlowDefinitionHolder holder = flowDefinitions.get(id); if (holder == null) { throw new NoSuchFlowDefinitionException(id); } return holder; }
public Object getValue(Object context) throws EvaluationException { String subflowId = (String) this.subflowId.getValue(context); return flowDefinitionLocator.getFlowDefinition(subflowId); }
public void testGetFlowIds() { registry.registerFlowDefinition(new StaticFlowDefinitionHolder(fooFlow)); registry.registerFlowDefinition(new StaticFlowDefinitionHolder(barFlow)); assertEquals("bar", registry.getFlowDefinitionIds()[0]); assertEquals("foo", registry.getFlowDefinitionIds()[1]); }
public void testRegisterMultipleFlows() { registry.registerFlowDefinition(new StaticFlowDefinitionHolder(fooFlow)); registry.registerFlowDefinition(new StaticFlowDefinitionHolder(barFlow)); assertTrue(registry.containsFlowDefinition("foo")); assertTrue(registry.containsFlowDefinition("bar")); assertEquals(fooFlow, registry.getFlowDefinition("foo")); assertEquals(barFlow, registry.getFlowDefinition("bar")); }
public void registerFlowDefinition(FlowDefinitionHolder definitionHolder) { Assert.notNull(definitionHolder, "The holder of the flow definition to register is required"); if (logger.isDebugEnabled()) { logger.debug("Registering flow definition '" + definitionHolder.getFlowDefinitionResourceString() + "' under id '" + definitionHolder.getFlowDefinitionId() + "'"); } flowDefinitions.put(definitionHolder.getFlowDefinitionId(), definitionHolder); }
/** * Creates a new mock flow service locator. */ public MockFlowBuilderContext(String flowId, AttributeMap<Object> attributes) { super(flowId, attributes, new FlowDefinitionRegistryImpl(), TestFlowBuilderServicesFactory.getServices()); }
public boolean containsFlowDefinition(String flowId) { boolean containsFlow = flowDefinitions.containsKey(flowId); if (!containsFlow && parent != null) { containsFlow = parent.containsFlowDefinition(flowId); } return containsFlow; }
public void setParent(FlowDefinitionRegistry parent) { super.setParent(parent); if (parent instanceof DefaultFlowRegistry) { DefaultFlowRegistry parentFlowRegistry = (DefaultFlowRegistry) parent; // link so a flow in the child registry that extends from a flow in the parent registry can find its parent flowModelRegistry.setParent(parentFlowRegistry.getFlowModelRegistry()); } } }
public String toString() { return new ToStringCreator(this).append("flowIds", getFlowDefinitionIds()).append("parent", parent).toString(); } }
/** * Register a subflow definition in the backing flow registry, typically to support a flow execution test. For test * scenarios, the subflow is often a stub used to verify parent flow input and output mapping behavior. * @param subflow the subflow */ public void registerSubflow(Flow subflow) { ((FlowDefinitionRegistryImpl) getFlowDefinitionLocator()).registerFlowDefinition(subflow); }
private void assembleFlow() throws FlowDefinitionConstructionException { try { assembling = true; flowDefinition = assembler.assembleFlow(); } catch (FlowBuilderException e) { throw new FlowDefinitionConstructionException(assembler.getFlowBuilderContext().getFlowId(), e); } finally { assembling = false; } }
public void destroy() { for (FlowDefinitionHolder holder : flowDefinitions.values()) { holder.destroy(); } }
public FlowExecution restoreExecution(FlowExecutionSnapshot snapshot, String flowId, FlowExecutionKey key, MutableAttributeMap<Object> conversationScope, FlowExecutionKeyFactory keyFactory) throws FlowExecutionRestorationFailureException { SimpleFlowExecutionSnapshot snapshotImpl = (SimpleFlowExecutionSnapshot) snapshot; FlowDefinition def = flowDefinitionLocator.getFlowDefinition(flowId); FlowExecution execution = snapshotImpl.getFlowExecution(); flowExecutionFactory.restoreFlowExecution(execution, def, key, conversationScope, flowDefinitionLocator); return execution; }
protected Object getHandlerInternal(HttpServletRequest request) throws Exception { String flowId = flowUrlHandler.getFlowId(request); if (flowId == null) { return null; } if (getApplicationContext().containsBean(flowId)) { Object handler = getApplicationContext().getBean(flowId); if (handler instanceof FlowHandler) { if (logger.isDebugEnabled()) { logger.debug("Mapping request with URI '" + request.getRequestURI() + "' to flow with id '" + flowId + "'; custom FlowHandler " + handler + " will manage flow execution"); } return handler; } } if (flowRegistry.containsFlowDefinition(flowId)) { if (logger.isDebugEnabled()) { logger.debug("Mapping request with URI '" + request.getRequestURI() + "' to flow with id '" + flowId + "'"); } return createDefaultFlowHandler(flowId); } if (logger.isDebugEnabled()) { logger.debug("No flow mapping found for request with URI '" + request.getRequestURI() + "'"); } return null; }
private FlowDefinition buildFlowDefinition(FlowBuilderInfo builderInfo) { try { Class<?> flowBuilderClass = loadClass(builderInfo.getClassName()); FlowBuilder builder = (FlowBuilder) flowBuilderClass.newInstance(); AttributeMap<Object> flowAttributes = getFlowAttributes(builderInfo.getAttributes()); FlowBuilderContext builderContext = new FlowBuilderContextImpl(builderInfo.getId(), flowAttributes, flowRegistry, flowBuilderServices); FlowAssembler assembler = new FlowAssembler(builder, builderContext); return assembler.assembleFlow(); } catch (IllegalArgumentException e) { throw new FlowDefinitionConstructionException(builderInfo.getId(), e); } catch (InstantiationException e) { throw new FlowDefinitionConstructionException(builderInfo.getId(), e); } catch (IllegalAccessException e) { throw new FlowDefinitionConstructionException(builderInfo.getId(), e); } }
public FlowExecution restoreExecution(FlowExecutionSnapshot snapshot, String flowId, FlowExecutionKey key, MutableAttributeMap<Object> conversationScope, FlowExecutionKeyFactory keyFactory) throws FlowExecutionRestorationFailureException { SerializedFlowExecutionSnapshot snapshotImpl = (SerializedFlowExecutionSnapshot) snapshot; FlowDefinition def = flowDefinitionLocator.getFlowDefinition(flowId); FlowExecution execution; try { execution = snapshotImpl.unmarshal(def.getClassLoader()); } catch (SnapshotUnmarshalException e) { throw new FlowExecutionRestorationFailureException(key, e); } flowExecutionFactory.restoreFlowExecution(execution, def, key, conversationScope, flowDefinitionLocator); return execution; }
public FlowExecutionResult launchExecution(String flowId, MutableAttributeMap<?> input, ExternalContext context) throws FlowException { try { if (logger.isDebugEnabled()) { logger.debug("Launching new execution of flow '" + flowId + "' with input " + input); } ExternalContextHolder.setExternalContext(context); FlowDefinition flowDefinition = definitionLocator.getFlowDefinition(flowId); FlowExecution flowExecution = executionFactory.createFlowExecution(flowDefinition); flowExecution.start(input, context); if (!flowExecution.hasEnded()) { FlowExecutionLock lock = executionRepository.getLock(flowExecution.getKey()); lock.lock(); try { executionRepository.putFlowExecution(flowExecution); } finally { lock.unlock(); } return createPausedResult(flowExecution); } else { return createEndResult(flowExecution); } } finally { ExternalContextHolder.setExternalContext(null); } }
for (Iterator<FlowSessionImpl> it = execution.getSubflowSessionIterator(); it.hasNext();) { FlowSessionImpl subflowSession = it.next(); Flow subflowDef = (Flow) subflowDefinitionLocator.getFlowDefinition(subflowSession.getFlowId()); subflowSession.setFlow(subflowDef); subflowSession.setState(subflowDef.getStateInstance(subflowSession.getStateId()));