1 22 23 24 package com.mchange.v2.c3p0.cfg; 25 26 import java.io.*; 27 import java.util.HashMap ; 28 import java.util.Properties ; 29 import com.mchange.v2.cfg.MultiPropertiesConfig; 30 31 public class DefaultC3P0ConfigFinder implements C3P0ConfigFinder 32 { 33 final static String XML_CFG_FILE_KEY = "com.mchange.v2.c3p0.cfg.xml"; 34 35 public C3P0Config findConfig() throws Exception 36 { 37 C3P0Config out; 38 39 HashMap flatDefaults = C3P0ConfigUtils.extractHardcodedC3P0Defaults(); 40 41 flatDefaults.putAll( C3P0ConfigUtils.extractC3P0PropertiesResources() ); 45 46 String cfgFile = MultiPropertiesConfig.readVmConfig().getProperty( XML_CFG_FILE_KEY ); 47 if (cfgFile == null) 48 { 49 C3P0Config xmlConfig = C3P0ConfigXmlUtils.extractXmlConfigFromDefaultResource(); 50 if (xmlConfig != null) 51 { 52 insertDefaultsUnderNascentConfig( flatDefaults, xmlConfig ); 53 out = xmlConfig; 54 } 55 else 56 out = C3P0ConfigUtils.configFromFlatDefaults( flatDefaults ); 57 } 58 else 59 { 60 InputStream is = new BufferedInputStream( new FileInputStream( cfgFile ) ); 61 try 62 { 63 C3P0Config xmlConfig = C3P0ConfigXmlUtils.extractXmlConfigFromInputStream( is ); 64 insertDefaultsUnderNascentConfig( flatDefaults, xmlConfig ); 65 out = xmlConfig; 66 } 67 finally 68 { 69 try {is.close();} 70 catch (Exception e) 71 { e.printStackTrace(); } 72 } 73 } 74 75 Properties sysPropConfig = C3P0ConfigUtils.findAllC3P0SystemProperties(); 78 out.defaultConfig.props.putAll( sysPropConfig ); 79 80 return out; 81 } 82 83 private void insertDefaultsUnderNascentConfig(HashMap flatDefaults, C3P0Config config) 84 { 85 flatDefaults.putAll( config.defaultConfig.props ); 86 config.defaultConfig.props = flatDefaults; 87 } 88 } | Popular Tags |