KickJava   Java API By Example, From Geeks To Geeks.

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


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.EventDataStore;
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 Fabio Maggi @ Funambol
34  * $Id
35  */

36 public class Sync4jEventListener implements PIMListListener{
37
38     public static final char RECORD_STATE_DELETED = 'D' ;
39
40     //Data store object
41
private EventDataStore eventDataStore ;
42
43     /**
44      * Default Constructor for Sync4jPIMListener class
45      * that initializes the store object.
46      *
47      * @param void
48      *
49      */

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

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

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

78     public void itemRemoved(PIMItem item) {
79
80         //
81
// this code is disable because
82
// blackberry bug in calendar event
83
//
84
//storeRecord(item, EventDataStore.RECORD_STATE_DELETED);
85

86     }
87
88     /**
89      * This method is invoked internally when any changes to the
90      * blackberry address book happen.It updates the information into
91      * persistant store.
92      *
93      * @param PIMItem item that was removed from the address book
94      * @return void
95      */

96     private void storeRecord(PIMItem item, char state) {
97
98         Event event = (Event) item ;
99         String JavaDoc uid = null ;
100
101         try {
102
103             uid = event.getString(Event.UID, 0);
104
105             eventDataStore.addRecord(uid, state, event);
106
107         } catch(Exception JavaDoc e){
108             e.printStackTrace();
109         }
110
111     }
112 }
113
Popular Tags