1 2 12 package com.versant.core.jdbc; 13 14 import com.versant.core.util.classhelper.ClassHelper; 15 16 import com.versant.core.common.BindingSupportImpl; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 26 public class JdbcKeyGeneratorFactoryRegistry { 27 28 private ClassLoader loader; 29 private Map map = new HashMap (); 30 31 public JdbcKeyGeneratorFactoryRegistry(ClassLoader loader) { 32 this.loader = loader; 33 } 34 35 public ClassLoader getLoader() { 36 return loader; 37 } 38 39 42 public JdbcKeyGeneratorFactory getFactory(String name) { 43 JdbcKeyGeneratorFactory ans = (JdbcKeyGeneratorFactory)map.get(name); 44 if (ans == null) { 45 Class t = null; 46 try { 47 t = ClassHelper.get().classForName(name, true, loader); 48 } catch (ClassNotFoundException e) { 49 throw BindingSupportImpl.getInstance().runtime( 50 "Unable to load JdbcKeyGeneratorFactory class " + name, e); 51 } 52 try { 53 ans = (JdbcKeyGeneratorFactory)t.newInstance(); 54 } catch (Exception x) { 55 throw BindingSupportImpl.getInstance().runtime( 56 "Unable to create JdbcKeyGeneratorFactory instance " + 57 t.getName(), x); 58 } 59 map.put(name, ans); 60 } 61 return ans; 62 } 63 64 67 public void add(String alias, JdbcKeyGeneratorFactory f) { 68 map.put(alias, f); 69 } 70 71 } 72 | Popular Tags |