View Javadoc

1    
2   /*
3   * The contents of this file are subject to the BT "ZEUS" Open Source 
4   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
5   * except in compliance with the Licence. You may obtain a copy of the Licence
6   * from $ZEUS_INSTALL/licence.html or alternatively from
7   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
8   * 
9   * Except as stated in Clause 7 of the Licence, software distributed under the
10  * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
11  * implied. See the Licence for the specific language governing rights and 
12  * limitations under the Licence.
13  * 
14  * The Original Code is within the package zeus.*.
15  * The Initial Developer of the Original Code is British Telecommunications
16  * public limited company, whose registered office is at 81 Newgate Street, 
17  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
18  * public limited company are Copyright 1996-9. All Rights Reserved.
19  * 
20  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
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 }