extend processor with after returning/throwing
SHL-40
This commit is contained in:
@@ -37,9 +37,19 @@ public interface ExecutionProcessor extends CommandMarker {
|
|||||||
ParseResult beforeInvocation(ParseResult invocationContext);
|
ParseResult beforeInvocation(ParseResult invocationContext);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method called after invoking the target command (described by {@link ParseResult}).
|
* Method called after successfully invoking the target command (described by {@link ParseResult}).
|
||||||
*
|
*
|
||||||
* @param invocationContext target command context
|
* @param invocationContext target command context
|
||||||
|
* @param result the invocation result
|
||||||
*/
|
*/
|
||||||
void afterInvocation(ParseResult invocationContext);
|
void afterReturningInvocation(ParseResult invocationContext, Object result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method called after invoking the target command (described by {@link ParseResult}) had thrown an exception .
|
||||||
|
*
|
||||||
|
* @param invocationContext target command context
|
||||||
|
* @param thrown the thrown object
|
||||||
|
*/
|
||||||
|
void afterThrowingInvocation(ParseResult invocationContext, Throwable thrown);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,18 @@ public class SimpleExecutionStrategy implements ExecutionStrategy {
|
|||||||
ExecutionProcessor processor = ((ExecutionProcessor) target);
|
ExecutionProcessor processor = ((ExecutionProcessor) target);
|
||||||
parseResult = processor.beforeInvocation(parseResult);
|
parseResult = processor.beforeInvocation(parseResult);
|
||||||
try {
|
try {
|
||||||
return invoke(parseResult);
|
Object result = invoke(parseResult);
|
||||||
} finally {
|
processor.afterReturningInvocation(parseResult, result);
|
||||||
processor.afterInvocation(parseResult);
|
return result;
|
||||||
|
} catch (Throwable th) {
|
||||||
|
processor.afterThrowingInvocation(parseResult, th);
|
||||||
|
if (th instanceof Error) {
|
||||||
|
throw ((Error) th);
|
||||||
|
}
|
||||||
|
if (th instanceof RuntimeException) {
|
||||||
|
throw ((RuntimeException) th);
|
||||||
|
}
|
||||||
|
throw new RuntimeException(th);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -46,9 +46,13 @@ public class SimpleExecutionStrategyTest {
|
|||||||
return (beforeReturn == null ? invocationContext : beforeReturn);
|
return (beforeReturn == null ? invocationContext : beforeReturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterInvocation(ParseResult invocationContext) {
|
public void afterReturningInvocation(ParseResult invocationContext, Object result) {
|
||||||
after = invocationContext;
|
after = invocationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void afterThrowingInvocation(ParseResult invocationContext, Throwable thrown) {
|
||||||
|
//
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SimpleExecutionStrategy execution = new SimpleExecutionStrategy();
|
private SimpleExecutionStrategy execution = new SimpleExecutionStrategy();
|
||||||
|
|||||||
Reference in New Issue
Block a user