batch = DomUtils.getChildElementByTagName(element,
"script");
}
if (batch != null) {
// we know there can only ever be one
ManagedList children = new ManagedList();
for (int i = 0, length = batch.getChildNodes().getLength(); i < length; i++) {
Node n = batch.getChildNodes().item(i);
if (n instanceof Element) {
Element e = (Element) n;
BeanDefinitionBuilder beanBuilder = null;
if ("insert-object".equals(e.getLocalName())) {
String ref = e.getAttribute("ref");
Element nestedElm = getFirstElement(e.getChildNodes());
beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(InsertObjectCommand.class);
if (StringUtils.hasText(ref)) {
beanBuilder.addConstructorArgReference(ref);
} else if (nestedElm != null) {
beanBuilder.addConstructorArgValue(parserContext.getDelegate().parsePropertySubElement(nestedElm,
null,
null));
} else {
throw new IllegalArgumentException("insert-object must either specify a 'ref' attribute or have a nested bean");
}
} else if ("set-global".equals(e.getLocalName())) {
String ref = e.getAttribute("ref");
Element nestedElm = getFirstElement(e.getChildNodes());
beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SetGlobalCommand.class);
beanBuilder.addConstructorArgValue(e.getAttribute("identifier"));
if (StringUtils.hasText(ref)) {
beanBuilder.addConstructorArgReference(ref);
} else if (nestedElm != null) {
beanBuilder.addConstructorArgValue(parserContext.getDelegate().parsePropertySubElement(nestedElm,
null,
null));
} else {
throw new IllegalArgumentException("set-global must either specify a 'ref' attribute or have a nested bean");
}
} else if ("fire-until-halt".equals(e.getLocalName())) {
beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireUntilHaltCommand.class);
} else if ("fire-all-rules".equals(e.getLocalName())) {
beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireAllRulesCommand.class);
String max = e.getAttribute("max");
if (StringUtils.hasText(max)) {
beanBuilder.addPropertyValue("max",
max);
}
} else if ("start-process".equals(e.getLocalName())) {
beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(StartProcessCommand.class);
String processId = e.getAttribute("process-id");
if (!StringUtils.hasText(processId)) {
throw new IllegalArgumentException("start-process must specify a process-id");
}
beanBuilder.addConstructorArgValue(processId);
List<Element> params = DomUtils.getChildElementsByTagName(e,
"parameter");
if (!params.isEmpty()) {
ManagedMap map = new ManagedMap();
for (Element param : params) {
String identifier = param.getAttribute("identifier");
if (!StringUtils.hasText(identifier)) {
throw new IllegalArgumentException("start-process paramaters must specify an identifier");
}
String ref = param.getAttribute("ref");
Element nestedElm = getFirstElement(param.getChildNodes());
if (StringUtils.hasText(ref)) {
map.put(identifier,
new RuntimeBeanReference(ref));
} else if (nestedElm != null) {
map.put(identifier,
parserContext.getDelegate().parsePropertySubElement(nestedElm,
null,
null));
} else {
throw new IllegalArgumentException("start-process paramaters must either specify a 'ref' attribute or have a nested bean");
}
}
beanBuilder.addPropertyValue("parameters",
map);
}
} else if ("signal-event".equals(e.getLocalName())) {
beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SignalEventCommand.class);
String processInstanceId = e.getAttribute("process-instance-id");
if (StringUtils.hasText(processInstanceId)) {
beanBuilder.addConstructorArgValue(processInstanceId);
}
beanBuilder.addConstructorArgValue(e.getAttribute("event-type"));
String ref = e.getAttribute("ref");
Element nestedElm = getFirstElement(e.getChildNodes());
if (StringUtils.hasText(ref)) {
beanBuilder.addConstructorArgReference(ref);
} else if (nestedElm != null) {
beanBuilder.addConstructorArgValue(parserContext.getDelegate().parsePropertySubElement(nestedElm,
null,
null));
} else {
throw new IllegalArgumentException("signal-event must either specify a 'ref' attribute or have a nested bean");
}
}
if (beanBuilder == null) {
throw new IllegalStateException("Unknow element: " + e.getLocalName());
}
children.add(beanBuilder.getBeanDefinition());
}
}
factory.addPropertyValue("batch",
children);
}