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  
24  /******************************************************************************
25  * SymBasicFactModel.java
26  *
27  * A basic fact model simulator
28  *****************************************************************************/
29  
30  package zeus.generator.task;
31  
32  import java.util.*;
33  import javax.swing.event.*;
34  
35  import zeus.util.*;
36  import zeus.concepts.*;
37  import zeus.generator.event.*;
38  import zeus.generator.util.*;
39  
40  public class SymBasicFactModel implements BasicFactModel, 
41                                 ChangeListener, RenameListener {
42  
43    protected EventListenerList listeners = new EventListenerList();
44    protected int               type;
45    protected SummaryTaskModel  taskModel;
46  
47    public SymBasicFactModel(int type, SummaryTaskModel taskModel) {
48       this.taskModel = taskModel;
49       this.type = type;
50       taskModel.addChangeListener(this);
51       taskModel.addRenameListener(this);
52    }
53  
54    public Fact[] getData() {
55       return taskModel.getConditions(type);
56    }
57  
58    public void stateChanged(ChangeEvent e) {
59       fireChanged();
60    }
61  
62   public void nameChanged(RenameEvent e) {
63      TaskNode node = (TaskNode)e.getObject();
64      if ( type == SummaryTaskModel.PRECONDITION &&
65           node.getName().equals(TaskNode.BEGIN) )
66         fireNameChanged(node,e.getOriginal(),e.getCurrent());
67      else if ( type == SummaryTaskModel.POSTCONDITION &&
68           node.getName().equals(TaskNode.END) )
69         fireNameChanged(node,e.getOriginal(),e.getCurrent());
70    }
71  
72    public void addChangeListener(ChangeListener x) {
73       listeners.add(ChangeListener.class, x);
74    }
75    public void removeChangeListener(ChangeListener x) {
76       listeners.remove(ChangeListener.class, x);
77    }
78    public void addRenameListener(RenameListener x) {
79       listeners.add(RenameListener.class, x);
80    }
81    public void removeRenameListener(RenameListener x) {
82       listeners.remove(RenameListener.class, x);
83    }
84  
85    protected void fireChanged() {
86       ChangeEvent c = new ChangeEvent(this);
87       Object[] list = listeners.getListenerList();
88       for(int i= list.length-2; i >= 0; i -=2) {
89          if (list[i] == ChangeListener.class) {
90             ChangeListener cl = (ChangeListener)list[i+1];
91             cl.stateChanged(c);
92          }
93       }
94    }
95  
96    protected void fireNameChanged(Object object, Object previous,
97                                   Object current) {
98       RenameEvent c = new RenameEvent(this,object,previous,current);
99       Object[] list = listeners.getListenerList();
100      for(int i= list.length-2; i >= 0; i -=2) {
101         if (list[i] == RenameListener.class) {
102            RenameListener cl = (RenameListener)list[i+1];
103            cl.nameChanged(c);
104         }
105      }
106   }
107 }