1 package org.sapia.soto.state.cocoon.example; 2 3 import org.sapia.soto.Service; 4 5 import java.util.Collection ; 6 import java.util.HashMap ; 7 import java.util.Map ; 8 9 10 18 public class AddressBookService implements Service { 19 private Map _contacts = new HashMap (); 20 21 public AddressBookService() { 22 } 23 24 public void addContact(Contact c) { 25 _contacts.put(c.getId(), c); 26 } 27 28 public Contact findContact(String id) throws AddrBookException { 29 return findContact(Integer.parseInt(id)); 30 } 31 32 public Contact findContact(int id) throws AddrBookException { 33 Contact c = (Contact) _contacts.get(new Integer (id)); 34 35 if (c == null) { 36 throw new AddrBookException("No contact found for: " + id); 37 } 38 39 return c; 40 } 41 42 public Collection getAllContacts() { 43 return _contacts.values(); 44 } 45 46 public void deleteContact(Contact c) { 47 deleteContact(c.getId().intValue()); 48 } 49 50 public void deleteContact(String id) { 51 deleteContact(Integer.parseInt(id)); 52 } 53 54 public void deleteContact(int id) { 55 _contacts.remove(new Integer (id)); 56 } 57 58 61 public void init() throws Exception { 62 } 63 64 67 public void start() throws Exception { 68 } 69 70 73 public void dispose() { 74 } 75 } 76 | Popular Tags |