1 package org.apache.ojb.broker.platforms; 2 3 17 18 import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor; 19 import org.apache.ojb.broker.util.logging.LoggerFactory; 20 import org.apache.ojb.broker.util.ClassHelper; 21 22 import java.util.HashMap ; 23 24 30 public class PlatformFactory 31 { 32 private static HashMap platforms = new HashMap (); 33 34 41 public static Platform getPlatformFor(JdbcConnectionDescriptor jcd) 42 { 43 String dbms = jcd.getDbms(); 44 Platform result = null; 45 String platformName = null; 46 47 result = (Platform) getPlatforms().get(dbms); 48 if (result == null) 49 { 50 try 51 { 52 platformName = getClassnameFor(dbms); 53 Class platformClass = ClassHelper.getClass(platformName); 54 result = (Platform) platformClass.newInstance(); 55 56 } 57 catch (Throwable t) 58 { 59 LoggerFactory.getDefaultLogger().warn( 60 "[PlatformFactory] problems with platform " + platformName, t); 61 LoggerFactory.getDefaultLogger().warn( 62 "[PlatformFactory] OJB will use PlatformDefaultImpl instead"); 63 64 result = new PlatformDefaultImpl(); 65 } 66 getPlatforms().put(dbms, result); } 68 return result; 69 } 70 71 76 private static String getClassnameFor(String platform) 77 { 78 String pf = "Default"; 79 if (platform != null) 80 { 81 pf = platform; 82 } 83 return "org.apache.ojb.broker.platforms.Platform" + pf.substring(0, 1).toUpperCase() + pf.substring(1) + "Impl"; 84 } 85 86 90 private static HashMap getPlatforms() 91 { 92 return platforms; 93 } 94 } 95 | Popular Tags |