View Javadoc

1   /*
2    * ProtocolDbNode.java
3    *
4    * Created on 28 October 2003, 11:26
5    */
6   
7   package zeus.actors.event;
8   
9   import zeus.util.*; 
10  import zeus.concepts.*;
11  import java.util.*; 
12  
13  /***
14   *
15   * @author  thompss
16   */
17  public class  ProtocolDbNode {
18  
19      private String factType;
20      protected OrderedHashtable protocolIndex;
21  
22      public ProtocolDbNode () {
23      ;
24      }
25  
26  
27      public ProtocolDbNode(String factType){
28          this.factType = factType;
29          protocolIndex = new OrderedHashtable();
30      }
31  //-------------------------------------------------------------------------
32      public String getFactType() {  return factType; }
33  //-------------------------------------------------------------------------
34      public Vector getProtocols() {
35       Vector protocols = new Vector();
36       Enumeration  enum = protocolIndex.keys();
37       while (enum.hasMoreElements())
38          protocols.addElement(enum.nextElement());
39  
40       return protocols;
41      }
42  //-------------------------------------------------------------------------
43      public void addProtocol(String protocol, StrategyInfo info) {
44            if (protocolIndex.containsKey(protocol)) {
45               Vector infos = (Vector) protocolIndex.get(protocol);
46               infos.addElement(info);
47            }
48            else {
49               Vector infos = new Vector();
50               infos.addElement(info);
51               protocolIndex.put(protocol,infos);
52            }
53  
54      }
55  //-------------------------------------------------------------------------
56      public Vector getStrategy(String protocol){
57         return (Vector) protocolIndex.get(protocol);
58      }
59  //-------------------------------------------------------------------------
60      public boolean hasProtocol(String protocol){
61         return protocolIndex.containsKey(protocol);
62      }
63  //-------------------------------------------------------------------------
64      public void deleteProtocol(String protocol){
65         protocolIndex.remove(protocol);
66      }
67  //-------------------------------------------------------------------------
68      public String toString() {
69         String s = "(:fact " + factType + " ";
70         Enumeration enum = protocolIndex.keys();
71         String protocol;
72         Vector info;
73         while( enum.hasMoreElements() ) {
74            protocol = (String)enum.nextElement();
75            info = (Vector)protocolIndex.get(protocol);
76            s += ":protocol " + protocol + " " +
77                 ":strategy " + info + " ";
78         }
79         s = s.trim() + ")";
80         return s;
81      }
82  }
83  
84  
85