private PredicateSemantic getActivePredicateFromWhenAsClauses( DelayedReference reference, IModelAdapter modelAdapter, Object contextElement, Object currentForeachElement) throws ModelAdapterException { for (PredicateSemantic nextPred : reference.getPredicateActionList()) { if (nextPred.getWhen() != null) { Collection<?> resultBool = modelAdapter.evaluateOCLQuery( currentForeachElement, reference.getKeyValue(), nextPred.getWhen(), contextElement); if (resultBool.size() == 1) { Iterator<?> resIt = resultBool.iterator(); Object nextBool = resIt.next(); if (nextBool instanceof Boolean && (Boolean) nextBool) { return nextPred; } } } else { return nextPred; // no when-clause means "handle always" } } return null; }