return new OForEach(_context.getOProcess(), _context.getCurrent());
}
public void compile(OActivity output, Activity src) {
if (__log.isDebugEnabled()) __log.debug("Compiling ForEach activity.");
OForEach oforEach = (OForEach) output;
ForEachActivity forEach = (ForEachActivity) src;
oforEach.parallel = forEach.isParallel();
oforEach.startCounterValue = _context.compileExpr(forEach.getStartCounter());
oforEach.finalCounterValue = _context.compileExpr(forEach.getFinalCounter());
if (forEach.getCompletionCondition() != null) {
oforEach.completionCondition =
new OForEach.CompletionCondition(_context.getOProcess());
oforEach.completionCondition.successfulBranchesOnly
= forEach.getCompletionCondition().getBranch().isSuccessfulBranchesOnly();
oforEach.completionCondition.branchCount = _context.compileExpr(forEach.getCompletionCondition().getBranch());
}
// ForEach 'adds' a counter variable in inner scope
if (__log.isDebugEnabled()) __log.debug("Adding the forEach counter variable to inner scope.");
if (forEach.getChild() == null) {
throw new CompilationException(__cmsgs.errMissingScopeinForeach().setSource(forEach));
}
Scope s = forEach.getChild().getScope();
// Checking if a variable using the same name as our counter is already defined.
// The spec requires a static analysis error to be thrown in that case.
if (s.getVariableDecl(forEach.getCounterName()) != null)
throw new CompilationException(__cmsgs.errForEachAndScopeVariableRedundant(forEach.getCounterName()).setSource(src));
OXsdTypeVarType counterType = new OXsdTypeVarType(oforEach.getOwner());
counterType.simple = true;
counterType.xsdType = new QName(Namespaces.XML_SCHEMA, "int");
OScope.Variable counterVar = new OScope.Variable(oforEach.getOwner(), counterType);
counterVar.name = forEach.getCounterName();
if (__log.isDebugEnabled()) __log.debug("Compiling forEach inner scope.");
oforEach.innerScope = _context.compileSLC(forEach.getChild(), new OScope.Variable[]{counterVar});