KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > exchange > items > note > manager > NoteManager


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.note.manager;
20
21 import sync4j.exchange.items.note.dao.NoteDAO;
22 import sync4j.exchange.items.note.model.Note;
23 import sync4j.exchange.DataAccessException;
24
25 /*
26  * This class defines methods to access notes data
27  * in exchange server datastore
28  *
29  * @author Fabio Maggi @ Funambol
30  * @version $Id: NoteManager.java,v 1.6 2005/06/26 18:35:11 nichele Exp $
31  *
32  **/

33 public class NoteManager {
34
35     //------------------------------------------------------------- Constants
36

37     //------------------------------------------------------------- Private Data
38

39     NoteDAO nd = null ;
40
41     //------------------------------------------------------------- Costructor
42

43     public NoteManager(String JavaDoc exchangeServerHost ,
44                        int exchangeServerPort )
45         throws DataAccessException {
46
47         this.nd = new NoteDAO (exchangeServerHost ,
48                                exchangeServerPort );
49
50     }
51
52     //------------------------------------------------------------- Public methods
53

54     /**
55      * get all notes
56      *
57      * @param username
58      * @param credentials
59      * @param exchangeFolder
60      *
61      * @return array of find notes
62      *
63      * @throws sync4j.exchange.util.DataAccessException
64      **/

65     public Note[] getAllNotes(String JavaDoc username ,
66                               String JavaDoc credentials ,
67                               String JavaDoc exchangeFolder )
68         throws DataAccessException {
69
70         return this.nd.getNotes(username ,
71                                 credentials ,
72                                 new String JavaDoc[0] ,
73                                 exchangeFolder );
74     }
75
76     /**
77      * get notes
78      *
79      * @param username
80      * @param credentials
81      * @param ids
82      * @param exchangeFolder
83      *
84      * @return array of find notes
85      *
86      * @throws sync4j.exchange.util.DataAccessException
87      **/

88     public Note[] getNotes(String JavaDoc username ,
89                            String JavaDoc credentials ,
90                            String JavaDoc[] ids ,
91                            String JavaDoc exchangeFolder )
92         throws DataAccessException {
93
94          return this.nd.getNotes(username ,
95                                  credentials ,
96                                  ids ,
97                                  exchangeFolder );
98
99     }
100
101     /**
102      * get note by id
103      *
104      * @param id
105      * @param username
106      * @param credentials
107      *
108      * @return find note
109      *
110      * @throws sync4j.exchange.util.DataAccessException
111      **/

112     public Note getNoteById(String JavaDoc username ,
113                             String JavaDoc credentials ,
114                             String JavaDoc id ,
115                             String JavaDoc exchangeFolder)
116         throws DataAccessException {
117
118         Note[] notes = null;
119
120         notes = this.nd.getNotes(username ,
121                                  credentials ,
122                                  new String JavaDoc[] {id} ,
123                                  exchangeFolder );
124
125         if (notes == null || !(notes.length > 0)) {
126             return null;
127         }
128
129         return notes[0];
130
131     }
132
133     /**
134      * add / update note
135      *
136      * @param note
137      * @param username
138      * @param credentials
139      * @param exchangeFolder
140      *
141      * @return new note
142      *
143      * @throws sync4j.exchange.util.DataAccessException
144      **/

145     public Note setNote(Note note ,
146                         String JavaDoc username ,
147                         String JavaDoc credentials ,
148                         String JavaDoc exchangeFolder )
149         throws DataAccessException {
150
151         return this.nd.setNote(note ,
152                                username ,
153                                credentials ,
154                                exchangeFolder );
155
156     }
157
158     /**
159      * remove note
160      *
161      * @param note
162      * @param username
163      * @param principal
164      * @param exchangeFolder
165      *
166      * @throws sync4j.exchange.util.DataAccessException
167      **/

168     public void removeNote(Note note ,
169                            String JavaDoc username ,
170                            String JavaDoc principal ,
171                            String JavaDoc exchangeFolder )
172         throws DataAccessException {
173
174         this.nd.removeNote(note, username, principal, exchangeFolder);
175
176     }
177
178     /**
179      * get note twin
180      *
181      * @param note the note object
182      * @param username
183      * @param credentials
184      * @param exchangeFolder
185      *
186      * @return find contact
187      *
188      * @throws sync4j.exchange.util.DataAccessException
189      **/

190     public Note getNoteTwin(Note note,
191                             String JavaDoc username,
192                             String JavaDoc credentials,
193                             String JavaDoc exchangeFolder)
194     throws DataAccessException {
195
196         Note[] notes = null;
197
198         String JavaDoc subject = null;
199
200         try {
201
202             subject = note.getSubject();
203
204         } catch (Exception JavaDoc e) {
205             throw new DataAccessException(e.getMessage());
206         }
207
208         String JavaDoc[] fields = {
209                           NoteDAO.TAG_SUBJECT
210         };
211
212         Object JavaDoc[] values = {
213                           subject
214         };
215
216         notes = this.nd.getNotes(username,
217                                  credentials,
218                                  fields,
219                                  values,
220                                  exchangeFolder);
221
222         if (notes == null || !(notes.length > 0)) {
223             return null;
224         }
225
226         return notes[0];
227     }
228
229 }
230
Popular Tags