boolean repeat = ((BooleanToken) repeatUntilFixpoint
.getToken()).booleanValue();
while (!_lastResults.isEmpty()) {
switch (mode) {
case REPLACE_FIRST:
MatchResult result = _lastResults.peek();
GraphTransformer.transform(this, result);
break;
case REPLACE_ANY:
result = _lastResults.get(_random
.nextInt(_lastResults.size()));
GraphTransformer.transform(this, result);
break;
case REPLACE_ALL:
GraphTransformer.transform(this, _lastResults);
break;
}
if (!repeat) {
break;
}
_lastResults.clear();
matcher.match(getPattern(), _lastModel);
}
}
modelOutput.send(0, new ActorToken(_lastModel));
modified.send(0, BooleanToken.getInstance(foundMatch));
return;
}
}
if (matchInput.getWidth() > 0 && matchInput.hasToken(0)
&& _lastModel != null) {
ObjectToken token = (ObjectToken) matchInput.get(0);
MatchResult match = (MatchResult) token.getValue();
if (match != null) {
CompositeEntity host = (CompositeEntity) match
.get(getPattern());
if (_lastModel != host && !_lastModel.deepContains(host)) {
throw new IllegalActionException(this,
"The match result cannot be used with the "
+ "current model.");
}
GraphTransformer.transform(this, match);
modelOutput.send(0, new ActorToken(_lastModel));
}
}
if (trigger.getWidth() > 0 && trigger.hasToken(0)
&& !_lastResults.isEmpty()) {
trigger.get(0);
_lastResultsOperation = LastResultsOperation.REMOVE_FIRST;
MatchResult result = _lastResults.peek();
matchOutput.send(0, new ObjectToken(result));
}
} catch (TransformationException e) {
throw new IllegalActionException(this, e,
"Unable to transform model.");