01: /*
02: * This is free software, licensed under the Gnu Public License (GPL)
03: * get a copy from <http://www.gnu.org/licenses/gpl.html>
04: * $Id: EchoCommandProperty.java,v 1.4 2004/03/07 14:22:02 hzeller Exp $
05: * author: Henner Zeller <H.Zeller@acm.org>
06: */
07: package henplus;
08:
09: import henplus.event.ExecutionListener;
10:
11: import henplus.property.BooleanPropertyHolder;
12:
13: /**
14: * The Property echo-commands that simply registers itself at the
15: * command dispatcher to echo the commands it is executing.
16: */
17: public final class EchoCommandProperty extends BooleanPropertyHolder
18: implements ExecutionListener {
19: private CommandDispatcher _dispatcher;
20:
21: public EchoCommandProperty(CommandDispatcher disp) {
22: super (false);
23: _dispatcher = disp;
24: }
25:
26: public String getDefaultValue() {
27: return "off";
28: }
29:
30: public void booleanPropertyChanged(boolean echoCommands) {
31: if (echoCommands) {
32: _dispatcher.addExecutionListener(this );
33: } else {
34: _dispatcher.removeExecutionListener(this );
35: }
36: }
37:
38: public String getShortDescription() {
39: return "echo commands prior to execution.";
40: }
41:
42: //-- Execution listener
43:
44: public void beforeExecution(SQLSession session, String command) {
45: HenPlus.msg().println(command.trim());
46: }
47:
48: public void afterExecution(SQLSession session, String command,
49: int result) {
50: /* don't care */
51: }
52: }
|