KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > snapper > SnapperManager


1 /*
2  * Created on Apr 6, 2005
3  *
4  */

5 package org.enhydra.snapper;
6
7 import java.util.HashMap JavaDoc;
8 import java.util.Map JavaDoc;
9 import java.util.Properties JavaDoc;
10
11 import org.enhydra.snapper.api.ModuleManager;
12 import org.enhydra.snapper.api.indexing.*;
13 import org.enhydra.snapper.api.searching.*;
14 import org.enhydra.snapper.api.logging.LoggingManager;
15
16 /**
17  * @author Igor Smirnov
18  *
19  */

20 public final class SnapperManager {
21
22     public static SnapperManager engineManager;
23     
24     private Map JavaDoc threads = new HashMap JavaDoc();
25
26     public LoggingManager logManager;
27
28     public IndexerFactory indexerFactory;
29
30     public SearcherFactory searcherFactory;
31
32     public ModuleManager parserManager;
33     
34     private String JavaDoc logicalNameFromDatabase, documentLogicalName, tempdir;
35     
36     private String JavaDoc relativePaths = "false";
37     
38     private String JavaDoc fileSeparator = "system-dependent";
39     //private int metaIndexing, metaRAMIndexing;
40

41     int fetchSize = 0;
42
43     private String JavaDoc tempDir;
44
45     public static SnapperManager getInstance() {
46         if (engineManager == null) {
47             engineManager = new SnapperManager();
48         }
49         return engineManager;
50     }
51
52     public void init(Properties JavaDoc properties) {
53
54         String JavaDoc logClassName = properties.getProperty("LoggingManagerClassName");
55
56         String JavaDoc indexerFactoryClassName = properties
57                 .getProperty("IndexerFactoryClassName");
58
59         String JavaDoc searcherFactoryClassName = properties
60                 .getProperty("SearcherFactoryClassName");
61         
62         
63         if (properties.getProperty("LogicalNameFromDatabase") != null)
64             logicalNameFromDatabase = properties.getProperty("LogicalNameFromDatabase");
65         else logicalNameFromDatabase = "0";
66         if (properties.getProperty("DocumentLogicalName") != null)
67             documentLogicalName = properties.getProperty("DocumentLogicalName");
68         else documentLogicalName = "";
69         if (properties.getProperty("DBFetchSize") != null)
70             fetchSize = Integer.parseInt(properties.getProperty("DBFetchSize"));
71         
72         if (properties.getProperty("TempDir") != null)
73         {
74            tempDir = properties.getProperty("TempDir");
75         if (tempDir.endsWith("/"))
76            tempDir = tempDir.substring(0, tempDir.length()-2);
77         }
78         if (properties.getProperty("RelativeIndexPath") != null)
79         {
80            relativePaths = properties.getProperty("RelativeIndexPath");
81         }
82
83         if (properties.getProperty("FileSeparator") != null)
84         {
85            if (properties.getProperty("FileSeparator").equalsIgnoreCase("unix"))
86                   fileSeparator = properties.getProperty("FileSeparator");
87            else
88                   fileSeparator = "system-dependent";
89         }
90         
91
92 // if (properties.getProperty("MetaIndexing") != null)
93
// metaIndexing = Integer.parseInt(properties.getProperty("MataIndexing"));
94
//
95

96         ClassLoader JavaDoc cl = getClass().getClassLoader();
97
98         try {
99             logManager = (LoggingManager) cl.loadClass(logClassName)
100                     .newInstance();
101             logManager.configure(properties);
102         } catch (Exception JavaDoc ex) {
103             System.out.println("Logger could not be initialized!");
104         }
105
106         try {
107             searcherFactory = (SearcherFactory) cl.loadClass(
108                     searcherFactoryClassName).newInstance();
109             searcherFactory.configure(logManager);
110         } catch (Exception JavaDoc e) {
111             //System.out.println("SearcherFactory could not be initialized!");
112
}
113
114         try {
115             indexerFactory = (IndexerFactory) cl.loadClass(
116                     indexerFactoryClassName).newInstance();
117             indexerFactory.configure(logManager);
118         } catch (Exception JavaDoc ex) {
119             //System.out.println("IndexerFactory could not be initialized!");
120
}
121
122       try {
123             parserManager = (ModuleManager) cl.loadClass(
124                     "org.enhydra.snapper.parsers.ParserManager").newInstance();
125             parserManager.configure(logManager);
126         } catch (Exception JavaDoc e) {
127            // System.out.println("ParserManager could not be initialized!");
128
}
129         }
130
131     public LoggingManager getLoggingManager() {
132         return logManager;
133     }
134
135     public IndexerFactory getIndexerFactory() {
136         return indexerFactory;
137     }
138     
139     public SearcherFactory getSearcherFactory() {
140         return searcherFactory;
141     }
142     
143     public String JavaDoc getLogicalNameFromDatabase() {
144         return logicalNameFromDatabase;
145     }
146     
147     public String JavaDoc getDocumentLogicalName() {
148         return documentLogicalName;
149     }
150     
151     public int getFetchSize() {
152         return fetchSize;
153     }
154     
155     public String JavaDoc getTempDir() {
156         return tempDir;
157     }
158     
159     public String JavaDoc getRelativeIndexPaths() {
160         return relativePaths;
161     }
162
163     public String JavaDoc getFileSeparatorConvention() {
164         return fileSeparator;
165     }
166
167     public Map JavaDoc getThreads(){
168         return threads;
169     }
170     
171     public void addThread(String JavaDoc siteOID, Object JavaDoc thread){
172         threads.put(siteOID, thread);
173     }
174     
175     public void removeThread(String JavaDoc siteOID){
176         threads.remove(siteOID);
177     }
178
179     
180 // public int getMetaIndexing(){
181
// return metaIndexing;
182
// }
183
//
184
// public String getTempdir(){
185
// return tempdir;
186
// }
187
}
Popular Tags