View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  package zeus.rete.action;
23  import zeus.rete.*;
24  
25  /*** 
26      this class was written a an attempted response to the difficulties of 
27      understanding what is going on in the rete engine, and also in an 
28      attempt to provide a mechanism that can be used to easily extend the 
29      language without having to edit, like, 1000 files
30      @author Simon Thompson
31      @see zeus.rete.action.ActionFactory
32      @see zeus.rete.action.AbstractActionFactory
33      @see zeus.rete.ReteEngine
34      @since 1.1
35      */
36  public class ReteActionFactory implements ActionFactory {
37     
38      
39     public static final int ASSERT    = 0;
40     public static final int RETRACT   = 1;
41     public static final int MODIFY    = 2;
42     public static final int PRINT     = 3;
43     public static final int MESSAGE   = 4;
44     public static final int ACHIEVE   = 5;
45     public static final int BUY       = 6;
46     public static final int SELL      = 7;
47     public static final int EXECUTE   = 8;
48  
49     public static final int BIND      = 9;
50     public static final int IF        = 10;
51     public static final int WHILE     = 11;
52     public static final int OPEN      = 12;
53     public static final int CLOSE     = 13;
54     public static final int READ      = 14;
55     public static final int READLN    = 15;
56     public static final int SYSTEM    = 16;
57     public static final int CALL      = 17;
58     public static final int PRINTLN   = 18;
59  
60      
61      /*** 
62          return an action of the appropriate type, if the type is not supported then 
63          throw a NoSuchActionException and hope it gets handled!
64          */
65      public BasicAction getAction (int type) throws NoSuchActionException { 
66          switch (type) { 
67              case ASSERT: 
68              return (BasicAction) new AssertAction(); 
69              case RETRACT: 
70              return (BasicAction) new RetractAction(); 
71              case MODIFY: 
72              return (BasicAction) new ModifyAction(); 
73              case PRINT: 
74              return (BasicAction) new PrintAction(); 
75              case MESSAGE:
76              return (BasicAction) new MessageAction(); 
77              case ACHIEVE: 
78              return (BasicAction) new AchieveAction(); 
79              case BUY: 
80              return (BasicAction) new BuyAction(); 
81              case SELL: 
82              return (BasicAction) new SellAction(); 
83              case EXECUTE: 
84              return (BasicAction) new ExecuteAction(); 
85              case BIND: 
86              return (BasicAction) new BindAction(); 
87              case IF : 
88              return (BasicAction) new IfAction(); 
89              case WHILE:
90              return (BasicAction) new WhileAction(); 
91              case OPEN:  
92              return (BasicAction) new OpenAction(); 
93              case CLOSE: 
94              return (BasicAction) new CloseAction(); 
95              case READ:
96              return (BasicAction) new ReadAction();
97              case READLN: 
98              return (BasicAction) new ReadlnAction(); 
99              case SYSTEM: 
100             return (BasicAction) new SystemAction(); 
101             case CALL:
102             return (BasicAction) new CallAction (); 
103             case PRINTLN:
104             return (BasicAction) new PrintlnAction ();
105             default :
106                     throw new NoSuchActionException("ReteActionFactory does not support that type of action"); 
107         }
108             
109     
110 }
111 }