boolean hasNextAttribute = StringUtils.hasText(shortNextAttribute); if (hasNextAttribute) { list.add(getStateTransitionReference(parserContext, stateDef, null, shortNextAttribute)); List<Element> transitionElements = DomUtils.getChildElementsByTagName(element, transitionName); for (Element transitionElement : transitionElements) { verifyUniquePattern(transitionElement, patterns, element, parserContext); list.addAll(parseTransitionElement(transitionElement, stepId, stateDef, parserContext)); transitionElementExists = true; list.addAll(createTransition(FlowExecutionStatus.FAILED, FlowExecutionStatus.FAILED.getName(), null, null, stateDef, parserContext, false)); list.addAll(createTransition(FlowExecutionStatus.UNKNOWN, FlowExecutionStatus.UNKNOWN.getName(), null, null, stateDef, parserContext, false)); if (!hasNextAttribute) { list.addAll(createTransition(FlowExecutionStatus.COMPLETED, null, null, null, stateDef, parserContext, false));
/** * @param element the top level element containing a flow definition * @param parserContext the {@link ParserContext} */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { CoreNamespaceUtils.autoregisterBeansForNamespace(parserContext, element); String flowName = element.getAttribute(ID_ATTR); builder.getRawBeanDefinition().setAttribute("flowName", flowName); builder.addPropertyValue("name", flowName); builder.addPropertyValue("stateTransitionComparator", new RuntimeBeanReference(DefaultStateTransitionComparator.STATE_TRANSITION_COMPARATOR)); String abstractAttr = element.getAttribute(ABSTRACT_ATTR); if (StringUtils.hasText(abstractAttr)) { builder.setAbstract(abstractAttr.equals("true")); } super.doParse(element, parserContext, builder); }
reachableElementMap.put(child.getAttribute(ID_ATTR), findReachableElements(child)); if (startElement == null) { startElement = child.getAttribute(ID_ATTR); findAllReachableElements(startElement, reachableElementMap, allReachableElements); for (String elementId : reachableElementMap.keySet()) { if (!allReachableElements.contains(elementId)) {
/** * @param transitionElement The element to parse * @param stateDef The bean definition for the current state * @param parserContext the parser context for the bean factory * @return a collection of * {@link org.springframework.batch.core.job.flow.support.StateTransition} * references */ private static Collection<BeanDefinition> parseTransitionElement(Element transitionElement, String stateId, BeanDefinition stateDef, ParserContext parserContext) { FlowExecutionStatus status = getBatchStatusFromEndTransitionName(transitionElement.getNodeName()); String onAttribute = transitionElement.getAttribute(ON_ATTR); String restartAttribute = transitionElement.getAttribute(RESTART_ATTR); String nextAttribute = transitionElement.getAttribute(TO_ATTR); if (!StringUtils.hasText(nextAttribute)) { nextAttribute = restartAttribute; } boolean abandon = stateId != null && StringUtils.hasText(restartAttribute) && !restartAttribute.equals(stateId); String exitCodeAttribute = transitionElement.getAttribute(EXIT_CODE_ATTR); return createTransition(status, onAttribute, nextAttribute, exitCodeAttribute, stateDef, parserContext, abandon); }
/** * @param parserContext the parser context for the bean factory * @param stateDef The bean definition for the current state * @param element the <step/gt; element to parse * @return a collection of * {@link org.springframework.batch.core.job.flow.support.StateTransition} * references */ public static Collection<BeanDefinition> getNextElements(ParserContext parserContext, BeanDefinition stateDef, Element element) { return getNextElements(parserContext, null, stateDef, element); }
/** * Find all of the elements reachable from the startElement. * * @param startElement name of the element to start from * @param reachableElementMap Map of elements that can be reached from the startElement * @param accumulator a collection of reachable element names */ protected void findAllReachableElements(String startElement, Map<String, Set<String>> reachableElementMap, Set<String> accumulator) { Set<String> reachableIds = reachableElementMap.get(startElement); accumulator.add(startElement); if (reachableIds != null) { for (String reachable : reachableIds) { // don't explore a previously explored element; prevent loop if (!accumulator.contains(reachable)) { findAllReachableElements(reachable, reachableElementMap, accumulator); } } } }
/** * @param elementName An end transition element name * @return the BatchStatus corresponding to the transition name */ protected static FlowExecutionStatus getBatchStatusFromEndTransitionName(String elementName) { elementName = stripNamespace(elementName); if (STOP_ELE.equals(elementName)) { return FlowExecutionStatus.STOPPED; } else if (END_ELE.equals(elementName)) { return FlowExecutionStatus.COMPLETED; } else if (FAIL_ELE.equals(elementName)) { return FlowExecutionStatus.FAILED; } else { return FlowExecutionStatus.UNKNOWN; } }
endState = getStateTransitionReference(parserContext, endBuilder.getBeanDefinition(), null, nextOnEnd); next = endName; list.add(getStateTransitionReference(parserContext, stateDef, on, next)); if (endState != null) {
/** * @param transitionElement The element to parse * @param stateDef The bean definition for the current state * @param parserContext the parser context for the bean factory * @return a collection of * {@link org.springframework.batch.core.job.flow.support.StateTransition} * references */ private static Collection<BeanDefinition> parseTransitionElement(Element transitionElement, String stateId, BeanDefinition stateDef, ParserContext parserContext) { FlowExecutionStatus status = getBatchStatusFromEndTransitionName(transitionElement.getNodeName()); String onAttribute = transitionElement.getAttribute(ON_ATTR); String restartAttribute = transitionElement.getAttribute(RESTART_ATTR); String nextAttribute = transitionElement.getAttribute(TO_ATTR); if (!StringUtils.hasText(nextAttribute)) { nextAttribute = restartAttribute; } boolean abandon = stateId != null && StringUtils.hasText(restartAttribute) && !restartAttribute.equals(stateId); String exitCodeAttribute = transitionElement.getAttribute(EXIT_CODE_ATTR); return createTransition(status, onAttribute, nextAttribute, exitCodeAttribute, stateDef, parserContext, abandon); }
/** * @param parserContext the parser context for the bean factory * @param stateDef The bean definition for the current state * @param element the <step/gt; element to parse * @return a collection of * {@link org.springframework.batch.core.job.flow.support.StateTransition} * references */ protected static Collection<BeanDefinition> getNextElements(ParserContext parserContext, BeanDefinition stateDef, Element element) { return getNextElements(parserContext, null, stateDef, element); }
/** * Find all of the elements reachable from the startElement. * * @param startElement * @param reachableElementMap * @param accumulator a collection of reachable element names */ private void findAllReachableElements(String startElement, Map<String, Set<String>> reachableElementMap, Set<String> accumulator) { Set<String> reachableIds = reachableElementMap.get(startElement); accumulator.add(startElement); if (reachableIds != null) { for (String reachable : reachableIds) { // don't explore a previously explored element; prevent loop if (!accumulator.contains(reachable)) { findAllReachableElements(reachable, reachableElementMap, accumulator); } } } }
/** * @param elementName An end transition element name * @return the BatchStatus corresponding to the transition name */ protected static FlowExecutionStatus getBatchStatusFromEndTransitionName(String elementName) { elementName = stripNamespace(elementName); if (STOP_ELE.equals(elementName)) { return FlowExecutionStatus.STOPPED; } else if (END_ELE.equals(elementName)) { return FlowExecutionStatus.COMPLETED; } else if (FAIL_ELE.equals(elementName)) { return FlowExecutionStatus.FAILED; } else { return FlowExecutionStatus.UNKNOWN; } }
endState = getStateTransitionReference(parserContext, endBuilder.getBeanDefinition(), null, nextOnEnd); next = endName; list.add(getStateTransitionReference(parserContext, stateDef, on, next)); if (endState != null) {
boolean hasNextAttribute = StringUtils.hasText(shortNextAttribute); if (hasNextAttribute) { list.add(getStateTransitionReference(parserContext, stateDef, null, shortNextAttribute)); List<Element> transitionElements = DomUtils.getChildElementsByTagName(element, transitionName); for (Element transitionElement : transitionElements) { verifyUniquePattern(transitionElement, patterns, element, parserContext); list.addAll(parseTransitionElement(transitionElement, stepId, stateDef, parserContext)); transitionElementExists = true; list.addAll(createTransition(FlowExecutionStatus.FAILED, FlowExecutionStatus.FAILED.getName(), null, null, stateDef, parserContext, false)); if (!hasNextAttribute) { list.addAll(createTransition(FlowExecutionStatus.COMPLETED, null, null, null, stateDef, parserContext, false));
/** * @param transitionElement The element to parse * @param stateDef The bean definition for the current state * @param parserContext the parser context for the bean factory * @return a collection of * {@link org.springframework.batch.core.job.flow.support.StateTransition} * references */ private static Collection<BeanDefinition> parseTransitionElement(Element transitionElement, String stateId, BeanDefinition stateDef, ParserContext parserContext) { FlowExecutionStatus status = getBatchStatusFromEndTransitionName(transitionElement.getNodeName()); String onAttribute = transitionElement.getAttribute(ON_ATTR); String restartAttribute = transitionElement.getAttribute(RESTART_ATTR); String nextAttribute = transitionElement.getAttribute(TO_ATTR); if (!StringUtils.hasText(nextAttribute)) { nextAttribute = restartAttribute; } boolean abandon = stateId != null && StringUtils.hasText(restartAttribute) && !restartAttribute.equals(stateId); String exitCodeAttribute = transitionElement.getAttribute(EXIT_CODE_ATTR); return createTransition(status, onAttribute, nextAttribute, exitCodeAttribute, stateDef, parserContext, abandon); }
reachableElementMap.put(child.getAttribute(ID_ATTR), findReachableElements(child)); if (startElement == null) { startElement = child.getAttribute(ID_ATTR); findAllReachableElements(startElement, reachableElementMap, allReachableElements); for (String elementId : reachableElementMap.keySet()) { if (!allReachableElements.contains(elementId)) {
/** * @param element the top level element containing a flow definition * @param parserContext the {@link ParserContext} */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.getRawBeanDefinition().setAttribute("flowName", flowName); builder.addPropertyValue("name", flowName); builder.addPropertyValue("stateTransitionComparator", new RuntimeBeanReference(DefaultStateTransitionComparator.STATE_TRANSITION_COMPARATOR)); super.doParse(element, parserContext, builder); builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); parserContext.popAndRegisterContainingComponent(); } }
/** * @param parserContext the parser context for the bean factory * @param stateDef The bean definition for the current state * @param element the <step/gt; element to parse * @return a collection of * {@link org.springframework.batch.core.job.flow.support.StateTransition} * references */ public static Collection<BeanDefinition> getNextElements(ParserContext parserContext, BeanDefinition stateDef, Element element) { return getNextElements(parserContext, null, stateDef, element); }
/** * Find all of the elements reachable from the startElement. * * @param startElement * @param reachableElementMap * @param accumulator a collection of reachable element names */ protected void findAllReachableElements(String startElement, Map<String, Set<String>> reachableElementMap, Set<String> accumulator) { Set<String> reachableIds = reachableElementMap.get(startElement); accumulator.add(startElement); if (reachableIds != null) { for (String reachable : reachableIds) { // don't explore a previously explored element; prevent loop if (!accumulator.contains(reachable)) { findAllReachableElements(reachable, reachableElementMap, accumulator); } } } }
/** * @param elementName An end transition element name * @return the BatchStatus corresponding to the transition name */ private static FlowExecutionStatus getBatchStatusFromEndTransitionName(String elementName) { elementName = stripNamespace(elementName); if (STOP_ELE.equals(elementName)) { return FlowExecutionStatus.STOPPED; } else if (END_ELE.equals(elementName)) { return FlowExecutionStatus.COMPLETED; } else if (FAIL_ELE.equals(elementName)) { return FlowExecutionStatus.FAILED; } else { return FlowExecutionStatus.UNKNOWN; } }