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  
23  package zeus.rete.action;
24  import zeus.rete.*;
25  import zeus.actors.*; 
26  import zeus.concepts.*;
27  
28  /*** 
29      superclass  of the class that is called by all the ReteEngine handlers.
30      There is one abstract method here - executeAction (Action,Info) that needs to 
31      be implemented<p> 
32      @author Simon Thompson
33      @since 1.1
34      */
35  public abstract class ReteAction implements BasicAction {
36      
37      /***
38          context is stored by the superclass constructor for 
39          access by inhereted classes 
40          */
41      protected AgentContext context = null;
42      
43      
44      /*** 
45          engine is the reference to the ReteEngine, in some uses of the 
46          zeus.ReteEngine it is anticipated that no agent will be present
47          */
48      protected ReteEngine engine = null; 
49      
50      
51      /***
52          conflictHandler is the reference to the zeus.rete.ConflictHandler object
53          which (I think) decides which rule or action to fire next
54          */
55      protected ConflictSet conflictHandler = null; 
56      
57      
58      /*** 
59          ontologyDb is the reference to the ontology we are working in, again, this
60          package protected slot is provided because we need to remember to use case 
61          for Rete where it is not in an agent persay. <br>
62          @see getOntology() 
63          */
64      protected OntologyDb ontologyDb; 
65          
66      
67      
68      /*** 
69          Lame () class constructor forced by my compiler (I have no idea either...),
70          anyway, does nothing.
71          */
72        //  public ReteAction () { ;} 
73     
74      
75      
76      /*** 
77          this method is used to provide the Action objects with "actuators",
78          by which I mean some object references that allow the Action implementor 
79          to actually do something that effects the state of the agent<p>
80          @param context - our old friend the AgentContext interface gives us a reference
81          to the class which is implementing the agent's body. 
82          @param conflictHandler - reference to the ConflictSet object 
83          @author Simon Thompson
84          @since 1.1
85          */
86      public void setActuators (ConflictSet conflictHandler, AgentContext context) { 
87          this.conflictHandler = conflictHandler;
88          this.context = context; 
89      }
90      
91      
92          /*** 
93          this method is used to provide the Action objects with "actuators",
94          by which I mean some object references that allow the Action implementor 
95          to actually do something. In this case we are being called from a context that 
96          has a null context - so no agent, but a ReteEngine instead. <p> 
97          @param engine - the ReteEngine that we are using 
98          @param conflictHandler - reference to the ConflictSet object 
99          @author Simon Thompson
100         @since 1.1
101         */
102     public void setActuators (ConflictSet conflictHandler, ReteEngine engine) { 
103         this.conflictHandler = conflictHandler;
104         this.engine = engine; 
105     }
106     
107     
108     /***
109         return the ontology ref, if the ontologyDb slot is null then
110         get the current agent ontology, otherwise get the current ontology
111        <p>
112         Issues: <br>
113         ------<br>
114         If the context object and the rete object are both null should this then 
115          throw an exception - nice, but makes harder to use...
116         */
117     public OntologyDb getOntologyDb()  { 
118         if (ontologyDb == null)
119                 return context.getOntologyDb();
120             else 
121                 return ontologyDb; 
122     }
123     
124     
125     /***     
126         executeAction is a abstract method to be defined by implementing classes. <p>
127         This method will be called when the rete algorithm decides that this is 
128         the right action to fire right now.
129         */
130     public abstract void executeAction (Action a, Info info);
131     
132     
133     /*** 
134      *instantiated to return false, override this to produce service descriptions for rules
135      */
136     public String getServiceDescription(String language) {
137         return null; 
138     }
139     
140     
141 }