01: package org.objectweb.jonas.jtests.servlets.endpoint;
02:
03: import java.util.Hashtable;
04: import java.util.Map;
05:
06: public class AddressBookImpl implements AddressBook {
07:
08: /**
09: * Hack !! used to keep a state in this ws !
10: */
11: private static Map addresses = null;
12:
13: private static void initAddresses() {
14: addresses = new Hashtable();
15: Address a = new Address();
16: a.setName("JOnAS");
17: a.setCompany("ObjectWeb Consortium");
18: a.setVersion(4.0f);
19: addresses.put(a.getName(), a);
20: }
21:
22: public AddressBookImpl() {
23: if (addresses == null) {
24: initAddresses();
25: }
26: }
27:
28: public void addAddress(Address addr) throws AddressBookException {
29: if (isPresent(addr.getName())) {
30: throw new AddressBookException("Address " + addr
31: + " already present in Book");
32: }
33:
34: addresses.put(addr.getName(), addr);
35: }
36:
37: public Address getAddress(String name) {
38: return (Address) addresses.get(name);
39: }
40:
41: public Address[] getAddresses() {
42: Address[] exported = new Address[addresses.size()];
43: return (Address[]) addresses.values().toArray(exported);
44: }
45:
46: public boolean isPresent(String name) {
47: return (getAddress(name) != null);
48: }
49:
50: public void reset() {
51: addresses = null;
52: }
53: }
|