// Create new kernel state, if record doesn't carry one
if (kernelState == null || kernelState.isAfterProcessing()) {
kernelState = newKernelState();
}
Block currentBlock;
ExecutionFrame currentFrame = null;
// Iterate sequence
for (;;) {
try {
currentFrame = kernelState.getLastExecutionFrame();
if (currentFrame.getHostBlock().hasPosition(currentFrame.getPosition())) {
currentBlock = currentFrame.getHostBlock().getBlocks().get(currentFrame.getPosition());
// If compound, go into it
if (currentBlock instanceof CompoundBlock) {
ExecutionFrame childFrame =
new ExecutionFrame((CompoundBlock) currentBlock, currentFrame);
kernelState.addLastExecutionFrame(childFrame);
currentFrame = childFrame;
// Apply block changes
currentBlock.apply(record, currentFrame.getVariables());
// Startup changing record
if (currentFrame.isRecordchangehandler()) {
try {
record = ((RecordChangeHandler) currentFrame.getControl()).changeRecord(record);
} catch (NoMappingException e) {
// do nothing
/* Error if no mapping was added to the given blockreference.
* We don't consider this as error, we simply use the original records.
* If we need to sign this event this is the right place.
*/
}
}
// Startup handlers
if (currentFrame.isStartHandler()) {
try {
((StartHandler) currentFrame.getControl()).beforeChildren(kernelState, record);
} catch (RedirectException ex) {
handleRedirect(kernelState, ex);
}
}
}
else if (currentBlock instanceof BlockReference) {
ExecutionFrame childFrame = new ExecutionFrame(
(BlockReference) currentBlock, currentFrame);
kernelState.addLastExecutionFrame(childFrame);
currentFrame = childFrame;
// Startup changing record
if (currentFrame.isRecordchangehandler()) {
try {
record = ((RecordChangeHandler) currentFrame.getControl()).changeRecord(record);
} catch (NoMappingException e) {
// do nothing
/* Error if no mapping was added to the given blockreference.
* We don't consider this as error, we simply use the original records.
* If we need to sign this event this is the right place.
*/
}
}
// Startup handlers
if (currentFrame.isStartHandler()) {
try {
((StartHandler) currentFrame.getControl()).beforeChildren(kernelState, record);
} catch (RedirectException ex) {
handleRedirect(kernelState, ex);
}
}
} else {
// Atomic block processing
if (currentBlock instanceof CloneRecord) {
// Clone the record
Record clone = ((CloneRecord) currentBlock).getClonedRecord(
record, currentFrame.getVariables());
// Clone the current kernel state and increase getPosition()
KernelState cloneState = new KernelState(kernelState);
cloneState.increasePosition();
clone.setKernelState(cloneState);
localCloneQueue.add(clone);
} else {
// Apply block changes
currentBlock.apply(record, currentFrame.getVariables());
}
// Success handler for atomic blocks
if (currentFrame.isSuccessHandler() && currentBlock instanceof Atomic) {
try {