01: /*
02: This file is part of BORG.
03:
04: BORG is free software; you can redistribute it and/or modify
05: it under the terms of the GNU General Public License as published by
06: the Free Software Foundation; either version 2 of the License, or
07: (at your option) any later version.
08:
09: BORG 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 BORG; if not, write to the Free Software
16: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17:
18: Copyright 2003 by Mike Berger
19: */
20:
21: package net.sf.borg.model.db.file;
22:
23: import net.sf.borg.model.beans.Address;
24: import net.sf.borg.model.beans.Appointment;
25: import net.sf.borg.model.beans.Task;
26: import net.sf.borg.model.db.BeanDB;
27: import net.sf.borg.model.db.IBeanDataFactory;
28: import net.sf.borg.model.db.MemoDB;
29:
30: /**
31: * A singleton instance which creates class-specific {@link BeanDB BeanDB}
32: * instances.
33: */
34: public class FileBeanDataFactory implements IBeanDataFactory {
35: /**
36: * Singleton.
37: */
38: public static FileBeanDataFactory getInstance() {
39: return instance;
40: }
41:
42: // IBeanDataFactory overrides
43: public final BeanDB create(Class cls, String url, String username)
44: throws Exception {
45:
46: boolean shared = false;
47: String file = url;
48: try {
49: String[] fileArray = url.split("::");
50: file = fileArray[0];
51: shared = Boolean.valueOf(fileArray[1]).booleanValue();
52: } catch (java.lang.NoSuchMethodError e) {
53: // the Palm conduits run in JRE 1.3
54: // so we must ignore that split() does not exist
55: int idx = url.indexOf("::");
56: file = url.substring(0, idx);
57: }
58:
59: FileDBCreator creator = null;
60: if (cls == Address.class)
61: creator = new AddrFileDB();
62: else if (cls == Task.class)
63: creator = new TaskFileDB();
64: else if (cls == Appointment.class)
65: creator = new ApptFileDB();
66: else
67: return null;
68:
69: creator.init(file, shared);
70: return creator;
71: }
72:
73: // private //
74: private static final FileBeanDataFactory instance = new FileBeanDataFactory();
75:
76: private FileBeanDataFactory() {
77: }
78:
79: public MemoDB createMemoDB(String url, String username)
80: throws Exception {
81: // TODO Auto-generated method stub
82: return null;
83: }
84: }
|