1 19 package org.openharmonise.rm.dsi; 20 21 import java.util.*; 22 23 import org.openharmonise.commons.dsi.*; 24 25 26 34 public class DatabaseInfo { 35 36 39 private Map m_mappings = null; 40 41 44 private static DatabaseInfo m_instance = null; 45 46 49 private DatabaseInfo() { 50 m_mappings = Collections.synchronizedMap(new HashMap()); 51 } 52 53 58 public static DatabaseInfo getInstance() { 59 if (m_instance == null) { 60 m_instance = new DatabaseInfo(); 61 } 62 63 return m_instance; 64 } 65 66 72 public void registerTableName(String sClassname, String sTableName) { 73 m_mappings.put(sClassname, sTableName); 74 75 } 76 77 86 public String getTableName(String sClassname) throws DataStoreException { 87 String sTableName = null; 88 89 sTableName = (String ) m_mappings.get(sClassname); 90 91 if (sTableName == null) { 92 try { 94 Class clss = Class.forName(sClassname); 95 96 sTableName = (String ) m_mappings.get(sClassname); 97 98 if (sTableName == null) { 99 if(DataStoreObject.class.isAssignableFrom(clss)) { 100 DataStoreObject dsObj = 101 (DataStoreObject) clss.newInstance(); 102 103 sTableName = dsObj.getDBTableName(); 104 105 registerTableName(sClassname, sTableName); 106 } 107 } 108 } catch (ClassNotFoundException e) { 109 throw new DataStoreException("Class not found", e); 110 } catch (InstantiationException e) { 111 throw new DataStoreException("instantiation error", e); 112 } catch (IllegalAccessException e) { 113 throw new DataStoreException("illegal access", e); 114 } 115 } 116 117 return sTableName; 118 } 119 120 } 121 | Popular Tags |