KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > exchange > items > calendar > manager > CalendarManager


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.exchange.items.calendar.manager;
20
21 import java.io.IOException JavaDoc;
22
23 import sync4j.exchange.items.calendar.dao.CalendarDAO;
24 import sync4j.exchange.items.calendar.model.Calendar;
25 import sync4j.exchange.DataAccessException;
26 import sync4j.exchange.xml.XmlParser;
27 import java.util.Date JavaDoc;
28
29 /*
30  * This class defines methods to access calendars data
31  * in exchange server datastore
32  *
33  * @author Fabio Maggi @ Funambol
34  * @version $Id: CalendarManager.java,v 1.8 2005/06/20 14:02:34 fabius Exp $
35  *
36  **/

37 public class CalendarManager {
38
39     //------------------------------------------------------------- Constants
40

41     //------------------------------------------------------------- Private Data
42

43     CalendarDAO cd = null ;
44
45     //------------------------------------------------------------- Costructor
46

47     public CalendarManager(String JavaDoc exchangeServerHost ,
48                            int exchangeServerPort)
49         throws DataAccessException {
50
51         this.cd = new CalendarDAO (exchangeServerHost ,
52                                    exchangeServerPort);
53
54     }
55
56     //------------------------------------------------------------- Public methods
57

58     /**
59      * get all calendars
60      *
61      * @param username
62      * @param credentials
63      * @param exchangeFolder
64      *
65      * @return array of find calendars
66      *
67      * @throws sync4j.exchange.util.DataAccessException
68      **/

69     public Calendar[] getAllCalendars(String JavaDoc username ,
70                                       String JavaDoc credentials ,
71                                       String JavaDoc exchangeFolder )
72         throws DataAccessException {
73
74         return this.cd.getCalendars(username ,
75                                     credentials ,
76                                     new String JavaDoc[0] ,
77                                     exchangeFolder );
78     }
79
80     /**
81      * get calendar twin
82      *
83      * @param calendar the calendar object
84      * @param username
85      * @param credentials
86      * @param exchangeFolder
87      *
88      * @return find contact
89      *
90      * @throws sync4j.exchange.util.DataAccessException
91      **/

92     public Calendar getCalendarTwin(Calendar calendar ,
93                                     String JavaDoc username ,
94                                     String JavaDoc credentials ,
95                                     String JavaDoc exchangeFolder)
96     throws DataAccessException {
97
98         Calendar[] calendars = null;
99
100         Date JavaDoc dateStart = null;
101         Date JavaDoc dateEnd = null;
102
103         try {
104
105             dateStart = XmlParser.pdiToDate(calendar.getDtStart ().
106                                             getPropertyValueAsString());
107             dateEnd = XmlParser.pdiToDate(calendar.getDtEnd ().
108                                             getPropertyValueAsString());
109
110         } catch (Exception JavaDoc e) {
111             throw new DataAccessException(e.getMessage());
112         }
113
114         String JavaDoc location = calendar.getLocation().
115                                                 getPropertyValueAsString();
116
117         String JavaDoc[] fields = {
118                           CalendarDAO.TAG_DATESTART ,
119                           CalendarDAO.TAG_DATEEND ,
120                           CalendarDAO.TAG_LOCATION
121         };
122
123         Object JavaDoc[] values = {
124                           dateStart,
125                           dateEnd,
126                           location
127         };
128
129         calendars = this.cd.getCalendars(username,
130                                          credentials,
131                                          fields,
132                                          values,
133                                          exchangeFolder);
134
135         if (calendars == null || !(calendars.length > 0)) {
136             return null;
137         }
138
139         return calendars[0];
140     }
141
142
143     /**
144      * get calendars
145      *
146      * @param username
147      * @param credentials
148      * @param ids
149      * @param exchangeFolder
150      *
151      * @return array of find calendars
152      *
153      * @throws sync4j.exchange.util.DataAccessException
154      **/

155     public Calendar[] getCalendars(String JavaDoc username ,
156                                    String JavaDoc credentials ,
157                                    String JavaDoc[] ids ,
158                                    String JavaDoc exchangeFolder )
159         throws DataAccessException {
160
161          return this.cd.getCalendars(username ,
162                                      credentials ,
163                                      ids ,
164                                      exchangeFolder );
165
166     }
167
168     /**
169      * get calendar by key
170      *
171      * @param id
172      * @param username
173      * @param credentials
174      *
175      * @return find calendar
176      *
177      * @throws sync4j.exchange.util.DataAccessException
178      **/

179     public Calendar getCalendarById(String JavaDoc username ,
180                                     String JavaDoc credentials ,
181                                     String JavaDoc id ,
182                                     String JavaDoc exchangeFolder )
183         throws DataAccessException {
184
185         Calendar[] calendars = null;
186
187         calendars = this.cd.getCalendars(username ,
188                                          credentials ,
189                                          new String JavaDoc[] {id} ,
190                                          exchangeFolder);
191
192         if (calendars == null || !(calendars.length > 0)) {
193             return null;
194         }
195
196         return calendars[0];
197
198     }
199
200     /**
201      * add calendar
202      *
203      * @param calendar
204      * @param username
205      * @param credentials
206      * @param exchangeFolder
207      *
208      * @return new calendar
209      *
210      * @throws sync4j.exchange.util.DataAccessException
211      **/

212     public Calendar setCalendar(Calendar calendar ,
213                                 String JavaDoc username ,
214                                 String JavaDoc credentials ,
215                                 String JavaDoc exchangeFolder
216                               )
217         throws DataAccessException {
218
219         return this.cd.setCalendar(calendar ,
220                                    username ,
221                                    credentials ,
222                                    exchangeFolder );
223
224     }
225
226     /**
227      * remove calendar
228      *
229      * @param calendar
230      * @param username
231      * @param principal
232      * @param exchangeFolder
233      *
234      * @throws sync4j.exchange.util.DataAccessException
235      **/

236     public void removeCalendar(Calendar calendar ,
237                                String JavaDoc username ,
238                                String JavaDoc principal ,
239                                String JavaDoc exchangeFolder )
240         throws DataAccessException {
241
242         this.cd.removeCalendar(calendar, username, principal, exchangeFolder);
243
244     }
245
246 }
247
Popular Tags