KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > cocoon > example > AddressBookService


1 package org.sapia.soto.state.cocoon.example;
2
3 import org.sapia.soto.Service;
4
5 import java.util.Collection JavaDoc;
6 import java.util.HashMap JavaDoc;
7 import java.util.Map JavaDoc;
8
9
10 /**
11  * @author Yanick Duchesne
12  * <dl>
13  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
14  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
15  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
16  * </dl>
17  */

18 public class AddressBookService implements Service {
19   private Map JavaDoc _contacts = new HashMap JavaDoc();
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 JavaDoc 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 JavaDoc(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 JavaDoc 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 JavaDoc id) {
51     deleteContact(Integer.parseInt(id));
52   }
53
54   public void deleteContact(int id) {
55     _contacts.remove(new Integer JavaDoc(id));
56   }
57
58   /**
59    * @see org.sapia.soto.Service#init()
60    */

61   public void init() throws Exception JavaDoc {
62   }
63
64   /**
65    * @see org.sapia.soto.Service#start()
66    */

67   public void start() throws Exception JavaDoc {
68   }
69
70   /**
71    * @see org.sapia.soto.Service#dispose()
72    */

73   public void dispose() {
74   }
75 }
76
Popular Tags