KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > samples > contacts > ContactRepository


1
2 package org.objectweb.jac.samples.contacts;
3
4 import java.util.Vector JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import gnu.regexp.*;
8
9 public class ContactRepository {
10     List JavaDoc contacts = new Vector JavaDoc();
11
12     /**
13      * Get the value of contacts.
14      * @return value of contacts.
15      */

16     public List JavaDoc getContacts() {
17         return contacts;
18     }
19    
20     /**
21      * Add a contact to contacts.
22      * @param contact the contact added.
23      */

24     public void addContact(Person contact) {
25         contacts.add(contact);
26     }
27
28     /**
29      * Remove a contact from contacts.
30      * @param contact the contact removed.
31      */

32     public void removeContact(Person contact) {
33         contacts.remove(contact);
34     }
35
36     /**
37      * Find contacts in a company matching criteria.
38      * @param criteria the criteria to find contacts (regexp).
39      * @param company the company in where to find.
40      */

41     public List JavaDoc find(String JavaDoc criteria,String JavaDoc company) {
42         Vector JavaDoc result = new Vector JavaDoc();
43         Iterator JavaDoc it = contacts.iterator();
44         RE recrit = null;
45         try {
46             if (!criteria.equals(""))
47                 recrit = new RE(criteria,RE.REG_ICASE);
48         } catch(Exception JavaDoc e) {
49             e.printStackTrace();
50             return result;
51         }
52         while (it.hasNext()) {
53             Person contact = (Person) it.next();
54             //System.out.println("testing contact "+contact);
55
String JavaDoc companyName = "";
56             if (!company.equals("")) {
57                 if (contact.getCompany() != null) {
58                     companyName = contact.getCompany().getName();
59                     if (company.compareToIgnoreCase(companyName)!=0) {
60                         continue;
61                     }
62                 }
63             }
64             if (recrit==null ||
65                 recrit.getMatch(contact.getLastName())!=null ||
66                 recrit.getMatch(contact.getFirstName())!=null)
67             {
68                 result.add(contact);
69             }
70         }
71         return result;
72     }
73
74
75     /* public void disconnect() {
76          org.objectweb.jac.core.ApplicationRepository.get()
77          .unextend("contacts","remote-access");
78          org.objectweb.jac.aspects.tracing.Recorder.get().start();
79          }
80
81          public void reconnect() {
82          org.objectweb.jac.aspects.tracing.Recorder.get().stop();
83          org.objectweb.jac.core.ApplicationRepository.get()
84          .extend("contacts","remote-access");
85          org.objectweb.jac.aspects.tracing.Recorder.get().replay(
86          org.objectweb.jac.aspects.tracing.Recorder.get().getNewObjectsClasses(),
87          org.objectweb.jac.aspects.tracing.Recorder.get().getCalls());
88          }
89    
90          public void showLocalActions() {
91          org.objectweb.jac.aspects.tracing.Recorder.get().printRecordState();
92          }*/

93
94     /**
95      * Mail to all people in contact list.
96      */

97     public void mailing() {
98         String JavaDoc toMail = "mailto:";
99         Iterator JavaDoc it = contacts.iterator();
100         boolean first = true;
101         while (it.hasNext()) {
102             Person c = (Person)it.next();
103             if (c.getEmail()!=null && !c.getEmail().equals("") &&
104                c.isMailing())
105             {
106                 if (first) {
107                     toMail = toMail+c.getEmail();
108                     first = false;
109                 } else {
110                     toMail = toMail+","+c.getEmail();
111                 }
112             }
113         }
114         try {
115             String JavaDoc command = "mozilla -mail "+toMail;
116             System.out.println("launching "+command);
117             Runtime.getRuntime().exec(command);
118         } catch(Exception JavaDoc e) {
119             e.printStackTrace();
120         }
121     }
122
123 }
124
Popular Tags