01: package example;
02:
03: import com.caucho.util.L10N;
04: import java.util.logging.Logger;
05: import java.util.logging.Level;
06:
07: import java.io.IOException;
08:
09: /**
10: * Abstract base class for commands.
11: */
12: abstract public class AbstractCommand {
13: static protected final Logger log = Logger
14: .getLogger(AbstractCommand.class.getName());
15: static final L10N L = new L10N(AbstractCommand.class);
16:
17: private String _error = null;
18:
19: public void init() {
20: _error = null;
21: }
22:
23: /**
24: * If a parse error is encountered then the implementing class calls
25: * setError().
26: */
27: abstract void parse(Parser p) throws IOException;
28:
29: /**
30: * Perform the command.
31: *
32: * @return a String result to return to the client, or null if the
33: * command does not produce a result.
34: * If an error occurs then the implementing class calls setError().
35: */
36: abstract String act(Magic8Ball magic8ball);
37:
38: public boolean isError() {
39: return _error != null;
40: }
41:
42: public String getError() {
43: return _error;
44: }
45:
46: protected void setError(String error) {
47: _error = error;
48: }
49: }
|