1 package org.apache.torque.engine.platform; 2 3 18 19 import java.util.HashMap ; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 32 public class PlatformFactory 33 { 34 private static HashMap platforms = new HashMap (); 35 private static Log log = LogFactory.getLog(PlatformFactory.class); 36 37 42 public static Platform getPlatformFor(String dbms) 43 { 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 = Class.forName(platformName); 54 result = (Platform) platformClass.newInstance(); 55 56 } 57 catch (Throwable t) 58 { 59 log.warn("problems with platform " + platformName 60 + ": " + t.getMessage()); 61 log.warn("Torque will use PlatformDefaultImpl instead"); 62 63 result = new PlatformDefaultImpl(); 64 } 65 getPlatforms().put(dbms, result); } 67 return result; 68 } 69 70 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.torque.engine.platform.Platform" + pf.substring(0, 1).toUpperCase() + pf.substring(1) + "Impl"; 84 } 85 86 91 private static HashMap getPlatforms() 92 { 93 return platforms; 94 } 95 } 96 | Popular Tags |