1 25 29 package org.jresearch.gossip.dao.file; 30 31 import java.io.IOException ; 32 import java.util.Collections ; 33 import java.util.HashMap ; 34 import java.util.Map ; 35 import java.util.Properties ; 36 37 import org.jresearch.gossip.exception.SystemException; 38 39 43 public class FileProcessorFactory { 44 45 private Map registry = Collections.synchronizedMap(new HashMap ()); 46 47 private Properties props = new Properties (); 48 49 private static FileProcessorFactory instance; 50 51 public final String SUFF_STORENAME = ".storename"; 52 53 public final String SUFF_CLASSNAME = ".processor.class"; 54 55 private FileProcessorFactory() throws SystemException { 56 try { 57 props.load(this.getClass().getClassLoader().getResourceAsStream( 59 "org/jresearch/gossip/dao/file/filedb.properties")); 60 } catch (IOException e) { 61 throw new SystemException(e); 62 } 63 64 } 65 66 70 public static synchronized FileProcessorFactory getInstance() 71 throws SystemException { 72 if (null == instance) { 73 instance = new FileProcessorFactory(); 74 } 75 return instance; 76 } 77 78 83 public IFileProcessor getFileProcessor(String name) throws SystemException { 84 IFileProcessor fp = null; 85 if (!registry.containsKey(name)) { 86 loadFileProcessor(name); 87 } 88 fp = (IFileProcessor) registry.get(name); 89 return fp; 90 } 91 92 96 private void loadFileProcessor(String name) throws SystemException { 97 String className = props.getProperty(name + SUFF_CLASSNAME); 98 String storeName = props.getProperty(name + SUFF_STORENAME); 99 try { 100 IFileProcessor fp = (IFileProcessor) Class.forName(className) 101 .newInstance(); 102 fp.setStoreName(storeName); 103 registry.put(name, fp); 104 105 } catch (InstantiationException e) { 106 throw new SystemException(e); 107 } catch (IllegalAccessException e) { 108 throw new SystemException(e); 109 } catch (ClassNotFoundException e) { 110 throw new SystemException(e); 111 } 112 } 113 } | Popular Tags |