1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package zeus.concepts;
24
25 import java.util.*;
26 import zeus.actors.outtrays.*;
27 /***
28 FIPA_AddressBook is an extention of the addressbook that can cope with fipa
29 AID addresses, the intention is that this should be used to implement an
30 ACC agent that can act as a gateway from Zeus agencies to the FIPA world. <p>
31 The objective of this class is to provide something that can store agent aliases
32 so that when the ACC gets a message that is addressed to <i> testForwardACCiioptbtoledofuturesbtcom</i>
33 it can lookup the appropriate aid to construct a fipa performative which can be
34 sent to the target agent
35 */
36 public class FIPA_AddressBook extends zeus.concepts.AddressBook {
37
38 private Hashtable FIPA_Addresses= new Hashtable();
39
40
41 /***
42 add an address to the book
43 */
44 public boolean add(FIPA_AID_Address fipa_address) {
45 FIPA_Addresses.put (fipa_address.getAlias(), fipa_address);
46 return true;
47 }
48
49
50
51 /***
52 find a proper address from a name of an agent
53 */
54 public FIPA_AID_Address lookupFIPA(String name) {
55 Enumeration allNames = FIPA_Addresses.keys();
56 while (allNames.hasMoreElements()) {
57 String current = (String) allNames.nextElement();
58 if (current.equals(name)) {
59 return ((FIPA_AID_Address)FIPA_Addresses.get(current)); }
60 }
61
62 return (null);
63 }
64
65
66 /***
67 find a proper address from a name of an agent
68 */
69 public FIPA_AID_Address lookupAlias(String alias) {
70 Enumeration allAddresses = FIPA_Addresses.elements();
71 while (allAddresses.hasMoreElements()) {
72 try {
73 FIPA_AID_Address current = (FIPA_AID_Address) allAddresses.nextElement();
74 String currentAlias = current.getAlias();
75
76 if (currentAlias.equals(alias)) {
77 return current; }}
78 catch (ClassCastException cce) {
79
80
81
82 }
83 }
84
85 return (null);
86 }
87
88
89
90 /***
91 determine if the address for this agent is in the address book, return
92 the correct address object if it is...
93 */
94 public FIPA_AID_Address checkAddress(Address addr ) {
95 String name = makeAlias(addr);
96 FIPA_AID_Address lookedUp = lookupFIPA(name);
97 if (lookedUp!= null)
98 return lookedUp;
99 else
100 try {
101 return (FIPA_AID_Address) addr; }
102 catch (Exception e) {
103 e.printStackTrace ();
104 System.out.println("Probably class cast problem in checkAddress");
105 System.out.println("You may have tried to check to see if a Zeus format");
106 System.out.println("address is a FIPA_AID_Address - sorry, this causes an Exception ");
107 return null;
108 }
109
110 }
111
112 /***
113 *utility method to be used to reconsitute local platform name from an
114 *external name/host combo
115 */
116 public static String makeAlias (Address addr) {
117 String host = addr.getHost();
118 host.replace(':','X');
119 host.replace('/','X');
120 return (addr.getName() + host);
121 }
122
123
124
125
126 }