1 2 12 package com.versant.core.jdbc; 13 14 import com.versant.core.jdbc.metadata.JdbcColumn; 15 import com.versant.core.jdbc.sql.conv.TypeAsStringConverter; 16 import com.versant.core.jdbc.sql.conv.TypeAsBytesConverter; 17 import com.versant.core.util.classhelper.ClassHelper; 18 19 import com.versant.core.common.BindingSupportImpl; 20 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 29 public class JdbcConverterFactoryRegistry { 30 31 private ClassLoader loader; 32 private Map map = new HashMap (); 33 34 38 public static final JdbcConverterFactory NULL_CONVERTER = new JdbcConverterFactory() { 39 public Object createArgsBean() { 40 return null; 41 } 42 public JdbcConverter createJdbcConverter(JdbcColumn col, Object args, 43 JdbcTypeRegistry jdbcTypeRegistry) throws IllegalArgumentException { 44 return null; 45 } 46 }; 47 48 public static final String NULL_CONVERTER_NAME = "{none}"; 49 public static final String STRING_CONVERTER_NAME = "STRING"; 50 public static final String BYTES_CONVERTER_NAME = "BYTES"; 51 52 public JdbcConverterFactoryRegistry(ClassLoader loader) { 53 this.loader = loader; 54 map.put(NULL_CONVERTER_NAME, NULL_CONVERTER); 55 map.put(STRING_CONVERTER_NAME, new TypeAsStringConverter.Factory()); 56 map.put(BYTES_CONVERTER_NAME, new TypeAsBytesConverter.Factory()); 57 } 58 59 public ClassLoader getLoader() { 60 return loader; 61 } 62 63 66 public JdbcConverterFactory getFactory(String name) { 67 JdbcConverterFactory ans = (JdbcConverterFactory)map.get(name); 68 if (ans == null) { 69 Class t = null; 70 try { 71 t = ClassHelper.get().classForName(name, true, loader); 72 } catch (ClassNotFoundException e) { 73 throw BindingSupportImpl.getInstance().runtime( 74 "Unable to load JdbcConverterFactory class " + name, e); 75 } 76 try { 77 ans = (JdbcConverterFactory)t.newInstance(); 78 } catch (Exception x) { 79 throw BindingSupportImpl.getInstance().runtime( 80 "Unable to create JdbcConverterFactory instance " + 81 t.getName(), x); 82 } 83 map.put(name, ans); 84 } 85 return ans; 86 } 87 } 88 | Popular Tags |