1 19 package org.openharmonise.rm.factory; 20 21 import java.lang.reflect.*; 22 import java.util.*; 23 import java.util.logging.*; 24 25 import org.openharmonise.commons.dsi.*; 26 27 28 36 public class ClassFinderFactory { 37 38 41 protected static ClassFinderFactory m_instance = null; 42 43 46 protected AbstractDataStoreInterface m_dsi = null; 47 48 52 protected Map m_finders; 53 54 57 private static final Logger m_logger = Logger.getLogger(ClassFinderFactory.class.getName()); 58 59 64 private ClassFinderFactory(AbstractDataStoreInterface dsi) { 65 m_dsi = dsi; 66 m_finders = Collections.synchronizedMap(new HashMap(50)); 67 } 68 69 75 public static ClassFinderFactory getInstance(AbstractDataStoreInterface dsi) { 76 if (m_instance == null) { 77 m_instance = new ClassFinderFactory(dsi); 78 } 79 80 return m_instance; 81 } 82 83 93 public ClassFinder getClassFinder(String sClassname) 94 throws ClassFinderException { 95 ClassFinder finder = null; 96 97 if (m_finders.containsKey(sClassname) == true) { 98 finder = (ClassFinder) m_finders.get(sClassname); 99 } else { 100 try { 101 Class [] initArgsClass = null; 102 Object [] initArgs = null; 103 104 initArgsClass = new Class [] { AbstractDataStoreInterface.class }; 105 initArgs = new Object [] { this.m_dsi }; 106 107 Class clss = Class.forName(sClassname); 108 Constructor initArgsConstructor = clss.getConstructor( 109 initArgsClass); 110 finder = (ClassFinder) initArgsConstructor.newInstance(initArgs); 111 112 m_finders.put(sClassname, finder); 113 } catch (Exception e) { 114 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 115 throw new ClassFinderException(e.getMessage()); 116 } 117 } 118 119 return finder; 120 } 121 } | Popular Tags |