@SuppressWarnings("unchecked")
public static ChainControl executeChain (Chain chain, ChainControl control) throws DotDataException, DotRuntimeException, DotCacheException, ChainLinkCodeCompilationException {
try {
ChainAPI api = APILocator.getChainAPI();
if(chain == null || control == null) {
throw new DotRuntimeException("Unable to execute a null chain/control");
}
List<ChainState> states = chain.getStates();
HibernateUtil.startTransaction();
boolean exceptionOcurred = false;
boolean lastLinkResult = true;
if(control.getRequest() != null) {
HttpServletRequest req = control.getRequest();
Enumeration<String> parameterNames = req.getParameterNames();
while(parameterNames.hasMoreElements()) {
String e = parameterNames.nextElement();
control.putChainProperty(e, req.getParameter(e));
}
}
for (ChainState state : states) {
//Resetting default control properties
control.putChainProperty(ChainControl.ROLLBACK_ON_ERROR, true);
control.putChainProperty(ChainControl.ROLLBACK_ONLY, false);
control.putChainProperty(ChainControl.CONTINUE_ON_EXCEPTION, false);
control.putChainProperty(ChainControl.CONTINUE_ON_FAILURE, false);
control.putChainProperty(ChainControl.RESTART_TRANS, false);
ChainLink link = api.instanciateChainLink(state.getLinkCodeId());
List<ChainStateParameter> params = state.getParameters();
for(ChainStateParameter p : params) {
//Pattern substitution of variables block
//If a chain state parameter contains a variable value like myEmail={emailAddress}