KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > calendar > store > CalendarStoreFactory


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//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 JavaDoc;
21 import java.util.Iterator JavaDoc;
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;
30 //import org.columba.calendar.store.api.StoreException;
31
import org.columba.calendar.ui.base.CalendarHelper;
32 import org.columba.core.io.DiskIO;
33 import org.python.modules.synchronize;
34
35 import com.miginfocom.calendar.activity.Activity;
36 import com.miginfocom.calendar.activity.ActivityDepository;
37
38 /**
39  * CalendarStoreFactory class
40  * @author fdietz
41  *
42  */

43 public class CalendarStoreFactory implements ICalendarStoreFactory {
44     private File JavaDoc parentDirectory;
45     private File JavaDoc storeDirectory;
46     private ICalendarStore store;
47     private static CalendarStoreFactory instance = new CalendarStoreFactory();
48
49     /**
50      * CalendarStoreFactory default constructor
51      */

52     private CalendarStoreFactory() {
53         super();
54
55         parentDirectory = Config.getInstance().getConfigDirectory();
56         storeDirectory = new File JavaDoc(parentDirectory, "store");
57         DiskIO.ensureDirectory(storeDirectory);
58         initLocalStore();
59     }
60
61     /**
62      * initLocalStore method
63      */

64     private void initLocalStore() {
65         store = new LocalCalendarStore(storeDirectory);
66
67         IComponentInfoList list = store.getComponentInfoList();
68         Iterator JavaDoc<IComponentInfo> it = list.iterator();
69         while (it.hasNext()) {
70             IComponentInfo item = (IComponentInfo) it.next();
71
72             if (item.getType() == IComponent.TYPE.EVENT) {
73                 IEventInfo event = (IEventInfo) item;
74
75                 Activity act = CalendarHelper.createActivity(event);
76
77                 ActivityDepository.getInstance().addBrokedActivity(act, 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 }
97
Popular Tags