1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package zeus.concepts;
26
27 import java.util.*;
28 import zeus.util.*;
29 /***
30 A message rule is set in the zeus.actors.MsgHandler of an agent (look for the set method!)
31 basically you define a pattern, which the rule will match to any incomming messages, and an action
32 which is a call to a method.
33 Use this to get the agent to act in a particular way when it receives a message from a source
34 Change Log
35 ----------
36 06/06/01 - MessageRule() init added to allow graceful subclassing
37 06/06/01 - changed to MessageRuleImpl to allow returned types to be ok.
38 */
39
40
41
42 public class MessageRuleImpl implements MessageRule{
43 protected MessageAction action = null;
44 protected MessagePattern pattern = null;
45 protected String name = null;
46
47 public MessageRuleImpl () {
48 }
49
50
51 public MessageRuleImpl(String name) {
52 Assert.notNull(name);
53 this.name = name;
54 }
55
56
57 public MessageRuleImpl(String name, String[] patterns,
58 int type, Object object, String method) {
59 this(name);
60 setPattern(new MessagePatternImpl(patterns));
61 setAction(new MessageActionImpl(type,object,method));
62 }
63
64
65 public MessageRuleImpl(String name, String[] patterns,
66 Object object, String method) {
67 this(name);
68 setPattern(new MessagePatternImpl(patterns));
69 setAction(new MessageActionImpl(object,method));
70 }
71
72
73 public MessageRuleImpl(String name, MessagePattern pattern,
74 MessageAction action) {
75 this(name);
76 setPattern(pattern);
77 setAction(action);
78 }
79
80
81 public String getName() { return name; }
82 public MessagePattern getPattern() { return pattern; }
83 public MessageAction getAction() { return action; }
84
85
86 public void setPattern(MessagePattern pattern) {
87 this.pattern = pattern;
88 }
89
90
91 public void setAction(MessageAction action) {
92 this.action = action;
93 }
94
95
96 public String toString() {
97 return "(:message_rule " + name + " :pattern " + pattern +
98 " :action " + action + ")";
99 }
100 }