01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.calendar.store;
19:
20: import java.io.File;
21: import java.util.Iterator;
22:
23: import org.columba.calendar.config.Config;
24: import org.columba.calendar.model.api.IComponent;
25: import org.columba.calendar.model.api.IComponentInfo;
26: import org.columba.calendar.model.api.IComponentInfoList;
27: import org.columba.calendar.model.api.IEventInfo;
28: import org.columba.calendar.store.api.ICalendarStore;
29: import org.columba.calendar.store.api.ICalendarStoreFactory; //import org.columba.calendar.store.api.StoreException;
30: import org.columba.calendar.ui.base.CalendarHelper;
31: import org.columba.core.io.DiskIO;
32: import org.python.modules.synchronize;
33:
34: import com.miginfocom.calendar.activity.Activity;
35: import com.miginfocom.calendar.activity.ActivityDepository;
36:
37: /**
38: * CalendarStoreFactory class
39: * @author fdietz
40: *
41: */
42: public class CalendarStoreFactory implements ICalendarStoreFactory {
43: private File parentDirectory;
44: private File storeDirectory;
45: private ICalendarStore store;
46: private static CalendarStoreFactory instance = new CalendarStoreFactory();
47:
48: /**
49: * CalendarStoreFactory default constructor
50: */
51: private CalendarStoreFactory() {
52: super ();
53:
54: parentDirectory = Config.getInstance().getConfigDirectory();
55: storeDirectory = new File(parentDirectory, "store");
56: DiskIO.ensureDirectory(storeDirectory);
57: initLocalStore();
58: }
59:
60: /**
61: * initLocalStore method
62: */
63: private void initLocalStore() {
64: store = new LocalCalendarStore(storeDirectory);
65:
66: IComponentInfoList list = store.getComponentInfoList();
67: Iterator<IComponentInfo> it = list.iterator();
68: while (it.hasNext()) {
69: IComponentInfo item = (IComponentInfo) it.next();
70:
71: if (item.getType() == IComponent.TYPE.EVENT) {
72: IEventInfo event = (IEventInfo) item;
73:
74: Activity act = CalendarHelper.createActivity(event);
75:
76: ActivityDepository.getInstance().addBrokedActivity(act,
77: this );
78: }
79: }
80: }
81:
82: /**
83: * getInstance method
84: * @return instance
85: */
86: public static synchronized CalendarStoreFactory getInstance() {
87: return instance;
88: }
89:
90: /* (non-Javadoc)
91: * @see org.columba.calendar.store.api.ICalendarStoreFactory#getLocaleStore()
92: */
93: public ICalendarStore getLocaleStore() {
94: return store;
95: }
96: }
|