1 5 package org.enhydra.snapper; 6 7 import java.util.HashMap ; 8 import java.util.Map ; 9 import java.util.Properties ; 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 20 public final class SnapperManager { 21 22 public static SnapperManager engineManager; 23 24 private Map threads = new HashMap (); 25 26 public LoggingManager logManager; 27 28 public IndexerFactory indexerFactory; 29 30 public SearcherFactory searcherFactory; 31 32 public ModuleManager parserManager; 33 34 private String logicalNameFromDatabase, documentLogicalName, tempdir; 35 36 private String relativePaths = "false"; 37 38 private String fileSeparator = "system-dependent"; 39 41 int fetchSize = 0; 42 43 private String 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 properties) { 53 54 String logClassName = properties.getProperty("LoggingManagerClassName"); 55 56 String indexerFactoryClassName = properties 57 .getProperty("IndexerFactoryClassName"); 58 59 String 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 96 ClassLoader cl = getClass().getClassLoader(); 97 98 try { 99 logManager = (LoggingManager) cl.loadClass(logClassName) 100 .newInstance(); 101 logManager.configure(properties); 102 } catch (Exception 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 e) { 111 } 113 114 try { 115 indexerFactory = (IndexerFactory) cl.loadClass( 116 indexerFactoryClassName).newInstance(); 117 indexerFactory.configure(logManager); 118 } catch (Exception ex) { 119 } 121 122 try { 123 parserManager = (ModuleManager) cl.loadClass( 124 "org.enhydra.snapper.parsers.ParserManager").newInstance(); 125 parserManager.configure(logManager); 126 } catch (Exception e) { 127 } 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 getLogicalNameFromDatabase() { 144 return logicalNameFromDatabase; 145 } 146 147 public String getDocumentLogicalName() { 148 return documentLogicalName; 149 } 150 151 public int getFetchSize() { 152 return fetchSize; 153 } 154 155 public String getTempDir() { 156 return tempDir; 157 } 158 159 public String getRelativeIndexPaths() { 160 return relativePaths; 161 } 162 163 public String getFileSeparatorConvention() { 164 return fileSeparator; 165 } 166 167 public Map getThreads(){ 168 return threads; 169 } 170 171 public void addThread(String siteOID, Object thread){ 172 threads.put(siteOID, thread); 173 } 174 175 public void removeThread(String siteOID){ 176 threads.remove(siteOID); 177 } 178 179 180 } | Popular Tags |