public StatementContext getContext(QName interactionUnitId) {
final Node<Scope> self = dialog.getScopeModel().findNode(interactionUnitId);
assert self!=null : "Unit not present in scopeModel: "+ interactionUnitId;
Scope scope = self.getData();
// lazy initialisation
if(!scope2context.containsKey(scope.getScopeId()))
{
// extract parent scopes
List<Node<Scope>> parentScopeNodes = self.collectParents(new NodePredicate<Scope>() {
Set<Integer> tracked = new HashSet<Integer>();
@Override
public boolean appliesTo(Node<Scope> candidate) {
if (self.getData().getScopeId() != candidate.getData().getScopeId()) {
if (!tracked.contains(candidate.getData().getScopeId())) {
tracked.add(candidate.getData().getScopeId());
return true;
}
return false;
}
return false;
}
});
// delegation scheme
List<Integer> parentScopeIds = new LinkedList<Integer>();
for(Node<Scope> parentNode : parentScopeNodes)
{
parentScopeIds.add(parentNode.getData().getScopeId());
}
scope2context.put(scope.getScopeId(),
new ParentDelegationContextImpl(scope, externalContext, parentScopeIds,
new Scopes() {
@Override
public StatementContext get(Integer scopeId) {
return scope2context.get(scopeId);
}
})
);
}
return scope2context.get(scope.getScopeId());
}