KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > blackberry > listener > Sync4jContactListener


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.blackberry.listener;
20
21 import javax.microedition.pim.Contact;
22 import javax.microedition.pim.Event;
23 import javax.microedition.pim.PIMItem;
24 import net.rim.blackberry.api.pdap.PIMListListener;
25
26 import sync4j.syncclient.sps.ContactDataStore;
27
28 /**
29  * <code>Sync4jPIMListener</code> listens for changes to the BlackBerry
30  * contact database and records the changes to a persistent store. The stored
31  * information is used for syncing with sync4j subsequently
32  *
33  * @author Lavanya Nadimpalli email:lavanya@telibrahma.com
34  * @author Fabio Maggi @ Funambol
35  * $Id: Sync4jContactListener.java,v 1.5 2005/05/30 11:01:01 fabius Exp $
36  */

37 public class Sync4jContactListener implements PIMListListener{
38
39     //Data store object
40
private ContactDataStore contactDataStore ;
41    
42     /**
43      * Default Constructor for Sync4jPIMListener class
44      * that initializes the store object.
45      *
46      * @param void
47      *
48      */

49     public Sync4jContactListener() {
50         this.contactDataStore = new ContactDataStore();
51     }
52
53     /**
54      * This method is invoked when the item is added to blackberry addressbook.
55      * @param PIMItem ,item that was added to the address book
56      * @return void
57      */

58     public void itemAdded(PIMItem item) {
59         storeRecord(item, ContactDataStore.RECORD_STATE_NEW);
60     }
61
62     /**
63      * This method is invoked when the item is updated in blackberry addressbook.
64      * @param PIMItem oldItem, item that was changed from the address book
65      * @param PIMItem newItem, item that is changed from the address book
66      * @return void
67      */

68     public void itemUpdated(PIMItem oldItem, PIMItem newItem) {
69         storeRecord(newItem, ContactDataStore.RECORD_STATE_UPDATED);
70     }
71
72     /**
73      * This method is invoked when an item is removed from blackberry addressbook.
74      * @param PIMItem item that was removed from the address book
75      * @return void
76      */

77     public void itemRemoved(PIMItem item) {
78         storeRecord(item, ContactDataStore.RECORD_STATE_DELETED);
79     }
80
81     /**
82      * This method is invoked internally when any changes to the
83      * blackberry address book happen.It updates the information into
84      * persistant store.
85      *
86      * @param PIMItem item that was removed from the address book
87      * @return void
88      */

89     private void storeRecord(PIMItem item, char state) {
90         Contact contact = (Contact) item;
91         String JavaDoc uid = contact.getString(Contact.UID, 0);
92              
93         try{
94
95             contactDataStore.addRecord(uid,state, contact);
96
97         } catch(Exception JavaDoc e){
98             e.printStackTrace();
99         }
100
101     }
102 }
103
Popular Tags