LOGGER.entering(invocation);
InvocationProcessingState resultingState = NO_STATE_CHANGE;
try {
switch (invocation.getMethodType()) {
case WRITE_START_ELEMENT:
if (filteringOn) {
depth++;
} else if (cmdBufferingOn) {
resultingState = RESTART_BUFFERING;
} else {
cmdBufferingOn = true;
resultingState = START_BUFFERING;
}
break;
case WRITE_END_ELEMENT:
if (filteringOn) {
if (depth == 0) {
filteringOn = false;
resultingState = STOP_FILTERING;
} else {
depth--;
}
} else if (cmdBufferingOn) {
cmdBufferingOn = false;
resultingState = STOP_BUFFERING;
}
break;
case WRITE_ATTRIBUTE:
if (!filteringOn && cmdBufferingOn && startFiltering(invocation, writer)) {
filteringOn = true;
cmdBufferingOn = false;
resultingState = START_FILTERING;
}
break;
case CLOSE:
if (filteringOn) {
filteringOn = false;
resultingState = STOP_FILTERING;
} else if (cmdBufferingOn) {
cmdBufferingOn = false;
resultingState = STOP_BUFFERING;
}
break;
default:
break;
}
return resultingState;
} finally {
LOGGER.exiting(resultingState);
}