KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > database > Database


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
20 package sync4j.framework.database;
21
22 import java.security.Principal JavaDoc;
23
24 import org.apache.commons.lang.builder.ToStringBuilder;
25
26 import sync4j.framework.core.*;
27
28 /**
29  * This class represents a synchronizable database.
30  *
31  * @author Stefano Fornari @ Funambol
32  * @version $Id: Database.java,v 1.11 2005/03/02 20:57:37 harrie Exp $
33  */

34 public class Database {
35     
36     // -------------------------------------------------------------- Properties
37

38     /**
39      * The database name
40      */

41     private String JavaDoc name = null;
42     
43     public String JavaDoc getName() {
44         return this.name;
45     }
46     
47     /**
48      * Sets the database name, but deletes the parameters part.
49      *
50      * @param name the reference name - NULL
51      */

52     public void setName(String JavaDoc name) {
53         if (name == null) {
54             throw new NullPointerException JavaDoc("name cannot be null");
55         }
56         int qMark = name.indexOf('?');
57         if (qMark == -1) {
58             this.name = name;
59         } else {
60             this.name = name.substring(0, qMark);
61         }
62     }
63     
64     /**
65      * The database type (e.g. text/x-vcard)
66      */

67     private String JavaDoc type = null;
68     
69     public String JavaDoc getType() {
70         return this.type;
71     }
72     
73     public void setType(String JavaDoc type) {
74         this.type = type;
75     }
76     
77     /**
78      * The target of the database
79      */

80     private Target target = null;
81     
82     public Target getTarget() {
83         return this.target;
84     }
85     
86     public void setTarget(Target target) {
87         this.target = target;
88     }
89     
90     /**
91      * The source of the database
92      */

93     private Source source = null;
94     
95     public Source getSource() {
96         return this.source;
97     }
98     
99     public void setSource(Source source) {
100         this.source = source;
101     }
102     
103     /**
104      * Client synchronization anchor
105      */

106     private Anchor anchor = null;
107     
108     public Anchor getAnchor() {
109         return anchor;
110     }
111     
112     public void setAnchor(Anchor anchor) {
113         this.anchor = anchor;
114     }
115     
116     /**
117      * Server synchronization anchor
118      */

119     private Anchor serverAnchor = null;
120     
121     public Anchor getServerAnchor() {
122         return serverAnchor;
123     }
124     
125     public void setServerAnchor(Anchor serverAnchor) {
126         this.serverAnchor = serverAnchor;
127     }
128     
129     /**
130      * Synchronization method
131      */

132     private int method = AlertCode.SLOW;
133     
134     public int getMethod() {
135         return this.method;
136     }
137     
138     public void setMethod(int method) {
139         this.method = method;
140     }
141     
142     /**
143      * Database status
144      */

145     private int statusCode = StatusCode.OK;
146     
147     public int getStatusCode() {
148         return statusCode;
149     }
150     
151     public void setStatusCode(int statusCode) {
152         this.statusCode = statusCode;
153     }
154     
155     /**
156      * Database status message
157      */

158     private String JavaDoc statusMessage = null;
159     
160     public String JavaDoc getStatusMessage() {
161         return statusMessage;
162     }
163     
164     public void setStatusMessage(String JavaDoc statusMessage) {
165         this.statusMessage = statusMessage;
166     }
167     
168     /**
169      * The alert command used to request the sychronization of this database
170      */

171     private Alert alertCommand = null;
172     
173     public Alert getAlertCommand() {
174         return this.alertCommand;
175     }
176     
177     public void setAlertCommand(Alert alertCommand) {
178         this.alertCommand = alertCommand;
179     }
180     
181     /**
182      * The associated principal
183      */

184     private Principal JavaDoc principal = null;
185     
186     /** Getter for property principal.
187      * @return Value of property principal.
188      *
189      */

190     public Principal JavaDoc getPrincipal() {
191         return principal;
192     }
193     
194     /** Setter for property principal.
195      * @param principal New value of property principal.
196      *
197      */

198     public void setPrincipal(Principal JavaDoc principal) {
199         this.principal = principal;
200     }
201             
202     // -------------------------------------------------------------------------
203

204     /**
205      * The items of the database to be added, copied, deleted, executed, replaced
206      */

207     private Item[] addItems = null;
208     private Item[] copyItems = null;
209     private Item[] deleteItems = null;
210     private Item[] execItems = null;
211     private Item[] replaceItems = null;
212     private Item[] existingItems = null;
213     
214     public void setAddItems(Item[] items) {
215         this.addItems = items;
216     }
217     
218     public Item[] getAddItems() {
219         return this.addItems;
220     }
221     
222     public void setCopyItems(Item[] items) {
223         this.copyItems = items;
224     }
225     
226     public Item[] getCopyItems() {
227         return this.copyItems;
228     }
229     
230     public void setDeleteItems(Item[] items) {
231         this.deleteItems = items;
232     }
233     
234     public Item[] getDeleteItems() {
235         return this.deleteItems;
236     }
237     
238     public void setExecItems(Item[] items) {
239         this.execItems = items;
240     }
241     
242     public Item[] getExecItems() {
243         return this.execItems;
244     }
245     
246     public void setReplaceItems(Item[] items) {
247         this.replaceItems = items;
248     }
249     
250     public Item[] getReplaceItems() {
251         return this.replaceItems;
252     }
253     
254     public void setExistingItems(Item[] items) {
255         this.existingItems = items;
256     }
257     
258     public Item[] getExistingItems() {
259         return this.existingItems;
260     }
261     
262     // ------------------------------------------------------------ Constructors
263

264     /**
265      * Creates a new instance of Database
266      *
267      * @param name database idenfier - NOT NULL
268      * @param type database type (e.g. text/x-vcard) - NULL
269      * @param target database target - NULL
270      * @param source database source - NULL
271      * @param anchor database last/next anchor tags NULL
272      * @param principal the associated Principal. NULL means no associated principal
273      */

274     public Database(String JavaDoc name ,
275                     String JavaDoc type ,
276                     Target target ,
277                     Source source ,
278                     Anchor anchor ,
279                     Principal JavaDoc principal) {
280         setName(name);
281         this.type = type ;
282         this.target = target;
283         this.source = source;
284         this.anchor = anchor;
285         this.principal = principal;
286     }
287     
288     /**
289      * Creates a new instance of Database
290      *
291      * @param name database idenfier - NOT NULL
292      */

293     public Database(String JavaDoc name) {
294         this(name, null, null, null, null, null);
295     }
296     
297     // ---------------------------------------------------------- Public methods
298

299     public String JavaDoc getLast() {
300         return (anchor != null) ? anchor.getLast() : null;
301     }
302     
303     public String JavaDoc getNext() {
304         return (anchor != null) ? anchor.getNext() : null;
305     }
306     
307     /**
308      * Is the store status code a OK status code (as opposed to an error code)?
309      *
310      * @return true if the current status code does not represent an error,
311      * false otherwise
312      */

313     public boolean isOkStatusCode() {
314         return (statusCode == StatusCode.OK) ||
315                (statusCode == StatusCode.REFRESH_REQUIRED);
316     }
317     
318     public String JavaDoc toString() {
319         ToStringBuilder sb = new ToStringBuilder(this);
320         
321         sb.append("name", name ).
322            append("type", type ).
323            append("statusCode", statusCode).
324            append("target", target ).
325            append("source", source ).
326            append("anchor", anchor ).
327            append("principal", principal );
328         
329         return sb.toString();
330     }
331 }
332
Popular Tags