KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > example > AbstractCommand


1 package example;
2
3 import com.caucho.util.L10N;
4 import java.util.logging.Logger JavaDoc;
5 import java.util.logging.Level JavaDoc;
6
7 import java.io.IOException JavaDoc;
8
9 /**
10  * Abstract base class for commands.
11  */

12 abstract public class AbstractCommand {
13   static protected final Logger JavaDoc log =
14     Logger.getLogger(AbstractCommand.class.getName());
15   static final L10N L = new L10N(AbstractCommand.class);
16
17   private String JavaDoc _error = null;
18
19   public void init()
20   {
21     _error = null;
22   }
23
24   /**
25    * If a parse error is encountered then the implementing class calls
26    * setError().
27    */

28   abstract void parse(Parser p) throws IOException JavaDoc;
29
30   /**
31    * Perform the command.
32    *
33    * @return a String result to return to the client, or null if the
34    * command does not produce a result.
35    * If an error occurs then the implementing class calls setError().
36    */

37   abstract String JavaDoc act(Magic8Ball magic8ball);
38
39
40   public boolean isError()
41   {
42     return _error != null;
43   }
44
45   public String JavaDoc getError()
46   {
47     return _error;
48   }
49
50   protected void setError(String JavaDoc error)
51   {
52     _error = error;
53   }
54 }
55
56
Popular Tags