KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > examples > patterns > Multiplication


1 package Jt.examples.patterns;
2
3 import Jt.*;
4 import java.io.*;
5 import java.util.*;
6 import Jt.xml.*;
7 import java.beans.*;
8
9 /**
10  * Calculator implementation based on Strategy. Refer to Calculator3.java
11  */

12
13 public class Multiplication extends JtStrategy {
14
15
16   public Multiplication () {
17   }
18
19
20   /**
21     * Process object messages (Command requests).
22     */

23
24   public Object JavaDoc processMessage (Object JavaDoc message) {
25
26    String JavaDoc msgid = null;
27    JtMessage msg = (JtMessage) message;
28    Object JavaDoc content;
29
30      if (msg == null)
31     return null;
32
33      // Retrieve Message ID and content
34

35      msgid = (String JavaDoc) msg.getMsgId ();
36
37      if (msgid == null)
38     return null;
39
40      content = msg.getMsgContent();
41
42      // Let the superclass (JtStrategy) handle this message.
43
// Strategy will forward the message to its concrete strategy.
44

45
46      if (msgid.equals ("MULTIPLY")) {
47
48         return (super.processMessage (message));
49
50      }
51
52
53      // JtRemove message (Remove Object)
54

55      if (msgid.equals ("JtREMOVE")) {
56        return (null);
57      }
58
59      handleError ("Multiplication.processMessage: invalid message id:" + msgid);
60      return (null);
61   }
62
63
64 }
65
66
67
68
Popular Tags