?
摘自c3p0.jar,方便查看
//c3p0.properties
#?
?
//c3p0-config.xml
<c3p0-config>?
?
//解析properties
?
 /*
/* *Distributedaspartofc3p0v.0.9.1.2
*Distributedaspartofc3p0v.0.9.1.2 *
* *Copyright(C)2005MachineryForChange,Inc.
*Copyright(C)2005MachineryForChange,Inc. *
* *Author:SteveWaldman<swaldman@mchange.com>
*Author:SteveWaldman<swaldman@mchange.com> *
* *Thislibraryisfreesoftware;youcanredistributeitand/ormodify
*Thislibraryisfreesoftware;youcanredistributeitand/ormodify *itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as
*itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as *publishedbytheFreeSoftwareFoundation.
*publishedbytheFreeSoftwareFoundation. *
* *Thissoftwareisdistributedinthehopethatitwillbeuseful,
*Thissoftwareisdistributedinthehopethatitwillbeuseful, *butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof *MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe *GNULesserGeneralPublicLicenseformoredetails.
*GNULesserGeneralPublicLicenseformoredetails. *
* *YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense *alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe
*alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe *FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330,
*FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330, *Boston,MA02111-1307,USA.
*Boston,MA02111-1307,USA. */
*/

 packagecom.mchange.v2.c3p0.cfg;
packagecom.mchange.v2.c3p0.cfg;
 importjava.io.*;
importjava.io.*; importjava.lang.reflect.*;
importjava.lang.reflect.*; importjava.util.*;
importjava.util.*; importcom.mchange.v2.cfg.*;
importcom.mchange.v2.cfg.*; importcom.mchange.v2.log.*;
importcom.mchange.v2.log.*; importcom.mchange.v2.c3p0.impl.*;
importcom.mchange.v2.c3p0.impl.*;
 publicfinalclassC3P0ConfigUtils
publicfinalclassC3P0ConfigUtils {
{ publicfinalstaticStringPROPS_FILE_RSRC_PATH="/c3p0.properties";
publicfinalstaticStringPROPS_FILE_RSRC_PATH="/c3p0.properties"; publicfinalstaticStringPROPS_FILE_PROP_PFX="c3p0.";
publicfinalstaticStringPROPS_FILE_PROP_PFX="c3p0."; publicfinalstaticintPROPS_FILE_PROP_PFX_LEN=5;
publicfinalstaticintPROPS_FILE_PROP_PFX_LEN=5;
 privatefinalstaticString[]MISSPELL_PFXS={"/c3pO","/c3po","/C3P0","/C3PO"};
privatefinalstaticString[]MISSPELL_PFXS={"/c3pO","/c3po","/C3P0","/C3PO"};
 finalstaticMLoggerlogger=MLog.getLogger(C3P0ConfigUtils.class);
finalstaticMLoggerlogger=MLog.getLogger(C3P0ConfigUtils.class);
 static
static {
{ if(logger.isLoggable(MLevel.WARNING)&&C3P0ConfigUtils.class.getResource(PROPS_FILE_RSRC_PATH)==null)
if(logger.isLoggable(MLevel.WARNING)&&C3P0ConfigUtils.class.getResource(PROPS_FILE_RSRC_PATH)==null) {
{ //warnonamisspelling...itsanuglywaytodothis,butsinceresourcesarenotlistable...
//warnonamisspelling...itsanuglywaytodothis,butsinceresourcesarenotlistable... for(inti=0;i<MISSPELL_PFXS.length;++i)
for(inti=0;i<MISSPELL_PFXS.length;++i) {
{ Stringtest=MISSPELL_PFXS[i]+".properties";
Stringtest=MISSPELL_PFXS[i]+".properties"; if(C3P0ConfigUtils.class.getResource(MISSPELL_PFXS[i]+".properties")!=null)
if(C3P0ConfigUtils.class.getResource(MISSPELL_PFXS[i]+".properties")!=null) {
{ logger.warning("POSSIBLYMISSPELLEDc3p0.propertiesCONFIGRESOURCEFOUND."+
logger.warning("POSSIBLYMISSPELLEDc3p0.propertiesCONFIGRESOURCEFOUND."+ "Pleaseensurethefilenameisc3p0.properties,alllowercase,"+
"Pleaseensurethefilenameisc3p0.properties,alllowercase,"+ "withthedigit0(NOTtheletterO)inc3p0.Itshouldbeplaced"+
"withthedigit0(NOTtheletterO)inc3p0.Itshouldbeplaced"+ "inthetoplevelofc3p0'seffectiveclasspath.");
"inthetoplevelofc3p0'seffectiveclasspath."); break;
break; }
} }
} }
} }
}
 publicstaticHashMapextractHardcodedC3P0Defaults(booleanstringify)
publicstaticHashMapextractHardcodedC3P0Defaults(booleanstringify) {
{ HashMapout=newHashMap();
HashMapout=newHashMap();
 try
try {
{ Method[]methods=C3P0Defaults.class.getMethods();
Method[]methods=C3P0Defaults.class.getMethods(); for(inti=0,len=methods.length;i<len;++i)
for(inti=0,len=methods.length;i<len;++i) {
{ Methodm=methods[i];
Methodm=methods[i]; intmods=m.getModifiers();
intmods=m.getModifiers(); if((mods&Modifier.PUBLIC)!=0&&(mods&Modifier.STATIC)!=0&&m.getParameterTypes().length==0)
if((mods&Modifier.PUBLIC)!=0&&(mods&Modifier.STATIC)!=0&&m.getParameterTypes().length==0) {
{ if(stringify)
if(stringify) {
{ Objectval=m.invoke(null,null);
Objectval=m.invoke(null,null); if(val!=null)
if(val!=null) out.put(m.getName(),String.valueOf(val));
out.put(m.getName(),String.valueOf(val)); }
} else
else out.put(m.getName(),m.invoke(null,null));
out.put(m.getName(),m.invoke(null,null)); }
} }
} }
} catch(Exceptione)
catch(Exceptione) {
{ logger.log(MLevel.WARNING,"Failedtoextracthardcodeddefaultconfig!?",e);
logger.log(MLevel.WARNING,"Failedtoextracthardcodeddefaultconfig!?",e); }
}
 returnout;
returnout; }
}
 publicstaticHashMapextractHardcodedC3P0Defaults()
publicstaticHashMapextractHardcodedC3P0Defaults() {returnextractHardcodedC3P0Defaults(true);}
{returnextractHardcodedC3P0Defaults(true);}
 publicstaticHashMapextractC3P0PropertiesResources()
publicstaticHashMapextractC3P0PropertiesResources() {
{ HashMapout=newHashMap();
HashMapout=newHashMap();
 //Propertiesprops=findResourceProperties();
//Propertiesprops=findResourceProperties(); //props.putAll(findAllC3P0Properties());
//props.putAll(findAllC3P0Properties());
 Propertiesprops=findAllC3P0Properties();
Propertiesprops=findAllC3P0Properties(); for(Iteratorii=props.keySet().iterator();ii.hasNext();)
for(Iteratorii=props.keySet().iterator();ii.hasNext();) {
{ Stringkey=(String)ii.next();
Stringkey=(String)ii.next(); Stringval=(String)props.get(key);
Stringval=(String)props.get(key); if(key.startsWith(PROPS_FILE_PROP_PFX))
if(key.startsWith(PROPS_FILE_PROP_PFX)) out.put(key.substring(PROPS_FILE_PROP_PFX_LEN).trim(),val.trim());
out.put(key.substring(PROPS_FILE_PROP_PFX_LEN).trim(),val.trim()); }
}
 returnout;
returnout; }
}
 publicstaticC3P0ConfigconfigFromFlatDefaults(HashMapflatDefaults)
publicstaticC3P0ConfigconfigFromFlatDefaults(HashMapflatDefaults) {
{ NamedScopedefaults=newNamedScope();
NamedScopedefaults=newNamedScope(); defaults.props.putAll(flatDefaults);
defaults.props.putAll(flatDefaults);
 HashMapconfigNamesToNamedScopes=newHashMap();
HashMapconfigNamesToNamedScopes=newHashMap();
 returnnewC3P0Config(defaults,configNamesToNamedScopes);
returnnewC3P0Config(defaults,configNamesToNamedScopes); }
}
 publicstaticStringgetPropFileConfigProperty(Stringprop)
publicstaticStringgetPropFileConfigProperty(Stringprop) {returnMultiPropertiesConfig.readVmConfig().getProperty(prop);}
{returnMultiPropertiesConfig.readVmConfig().getProperty(prop);}
 privatestaticPropertiesfindResourceProperties()
privatestaticPropertiesfindResourceProperties() {returnMultiPropertiesConfig.readVmConfig().getPropertiesByResourcePath(PROPS_FILE_RSRC_PATH);}
{returnMultiPropertiesConfig.readVmConfig().getPropertiesByResourcePath(PROPS_FILE_RSRC_PATH);}
 privatestaticPropertiesfindAllC3P0Properties()
privatestaticPropertiesfindAllC3P0Properties() {returnMultiPropertiesConfig.readVmConfig().getPropertiesByPrefix("c3p0");}
{returnMultiPropertiesConfig.readVmConfig().getPropertiesByPrefix("c3p0");}
 staticPropertiesfindAllC3P0SystemProperties()
staticPropertiesfindAllC3P0SystemProperties() {
{ Propertiesout=newProperties();
Propertiesout=newProperties();
 SecurityExceptionsampleExc=null;
SecurityExceptionsampleExc=null; try
try {
{ for(Iteratorii=C3P0Defaults.getKnownProperties().iterator();ii.hasNext();)
for(Iteratorii=C3P0Defaults.getKnownProperties().iterator();ii.hasNext();) {
{ Stringkey=(String)ii.next();
Stringkey=(String)ii.next(); StringprefixedKey="c3p0."+key;
StringprefixedKey="c3p0."+key; Stringvalue=System.getProperty(prefixedKey);
Stringvalue=System.getProperty(prefixedKey); if(value!=null&&value.trim().length()>0)
if(value!=null&&value.trim().length()>0) out.put(key,value);
out.put(key,value); }
} }
} catch(SecurityExceptione)
catch(SecurityExceptione) {sampleExc=e;}
{sampleExc=e;}
 returnout;
returnout; }
}
 privateC3P0ConfigUtils()
privateC3P0ConfigUtils() {}
{} }
}
 
?
?
//解析xml
?
 /*
/* *Distributedaspartofc3p0v.0.9.1.2
*Distributedaspartofc3p0v.0.9.1.2 *
* *Copyright(C)2005MachineryForChange,Inc.
*Copyright(C)2005MachineryForChange,Inc. *
* *Author:SteveWaldman<swaldman@mchange.com>
*Author:SteveWaldman<swaldman@mchange.com> *
* *Thislibraryisfreesoftware;youcanredistributeitand/ormodify
*Thislibraryisfreesoftware;youcanredistributeitand/ormodify *itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as
*itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as *publishedbytheFreeSoftwareFoundation.
*publishedbytheFreeSoftwareFoundation. *
* *Thissoftwareisdistributedinthehopethatitwillbeuseful,
*Thissoftwareisdistributedinthehopethatitwillbeuseful, *butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof *MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe *GNULesserGeneralPublicLicenseformoredetails.
*GNULesserGeneralPublicLicenseformoredetails. *
* *YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense *alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe
*alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe *FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330,
*FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330, *Boston,MA02111-1307,USA.
*Boston,MA02111-1307,USA. */
*/

 packagecom.mchange.v2.c3p0.cfg;
packagecom.mchange.v2.c3p0.cfg;
 importjava.io.*;
importjava.io.*; importjava.util.*;
importjava.util.*; importjavax.xml.parsers.*;
importjavax.xml.parsers.*; importorg.w3c.dom.*;
importorg.w3c.dom.*; importcom.mchange.v2.log.*;
importcom.mchange.v2.log.*;
 importcom.mchange.v1.xml.DomParseUtils;
importcom.mchange.v1.xml.DomParseUtils;
 publicfinalclassC3P0ConfigXmlUtils
publicfinalclassC3P0ConfigXmlUtils {
{ publicfinalstaticStringXML_CONFIG_RSRC_PATH="/c3p0-config.xml";
publicfinalstaticStringXML_CONFIG_RSRC_PATH="/c3p0-config.xml";
 finalstaticMLoggerlogger=MLog.getLogger(C3P0ConfigXmlUtils.class);
finalstaticMLoggerlogger=MLog.getLogger(C3P0ConfigXmlUtils.class);
 publicfinalstaticStringLINESEP;
publicfinalstaticStringLINESEP;
 privatefinalstaticString[]MISSPELL_PFXS={"/c3p0","/c3pO","/c3po","/C3P0","/C3PO"};
privatefinalstaticString[]MISSPELL_PFXS={"/c3p0","/c3pO","/c3po","/C3P0","/C3PO"}; privatefinalstaticchar[]MISSPELL_LINES={'-','_'};
privatefinalstaticchar[]MISSPELL_LINES={'-','_'}; privatefinalstaticString[]MISSPELL_CONFIG={"config","CONFIG"};
privatefinalstaticString[]MISSPELL_CONFIG={"config","CONFIG"}; privatefinalstaticString[]MISSPELL_XML={"xml","XML"};
privatefinalstaticString[]MISSPELL_XML={"xml","XML"};
 //itsanuglywaytodothis,butsinceresourcesarenotlistable...
//itsanuglywaytodothis,butsinceresourcesarenotlistable... //
// //thisisonlyexecutedonce,anddoesabout40tests(fornow)
//thisisonlyexecutedonce,anddoesabout40tests(fornow) //shouldIcareaboutthecostininitializationtime?
//shouldIcareaboutthecostininitializationtime? //
// //shouldonlyberunifwe'vecheckedforthecorrectfile,but
//shouldonlyberunifwe'vecheckedforthecorrectfile,but //notfoundit
//notfoundit privatefinalstaticvoidwarnCommonXmlConfigResourceMisspellings()
privatefinalstaticvoidwarnCommonXmlConfigResourceMisspellings() {
{ if(logger.isLoggable(MLevel.WARNING))
if(logger.isLoggable(MLevel.WARNING)) {
{ for(inta=0,lena=MISSPELL_PFXS.length;a<lena;++a)
for(inta=0,lena=MISSPELL_PFXS.length;a<lena;++a) {
{ StringBuffersb=newStringBuffer(16);
StringBuffersb=newStringBuffer(16); sb.append(MISSPELL_PFXS[a]);
sb.append(MISSPELL_PFXS[a]); for(intb=0,lenb=MISSPELL_LINES.length;b<lenb;++b)
for(intb=0,lenb=MISSPELL_LINES.length;b<lenb;++b) {
{ sb.append(MISSPELL_LINES[b]);
sb.append(MISSPELL_LINES[b]); for(intc=0,lenc=MISSPELL_CONFIG.length;c<lenc;++c)
for(intc=0,lenc=MISSPELL_CONFIG.length;c<lenc;++c) {
{ sb.append(MISSPELL_CONFIG[c]);
sb.append(MISSPELL_CONFIG[c]); sb.append('.');
sb.append('.'); for(intd=0,lend=MISSPELL_XML.length;d<lend;++d)
for(intd=0,lend=MISSPELL_XML.length;d<lend;++d) {
{ sb.append(MISSPELL_XML[d]);
sb.append(MISSPELL_XML[d]); Stringtest=sb.toString();
Stringtest=sb.toString(); if(!test.equals(XML_CONFIG_RSRC_PATH))
if(!test.equals(XML_CONFIG_RSRC_PATH)) {
{ ObjecthopefullyNull=C3P0ConfigXmlUtils.class.getResource(test);
ObjecthopefullyNull=C3P0ConfigXmlUtils.class.getResource(test); if(hopefullyNull!=null)
if(hopefullyNull!=null) {
{ logger.warning("POSSIBLYMISSPELLEDc3p0-conf.xmlRESOURCEFOUND."+
logger.warning("POSSIBLYMISSPELLEDc3p0-conf.xmlRESOURCEFOUND."+ "Pleaseensurethefilenameisc3p0-config.xml,alllowercase,"+
"Pleaseensurethefilenameisc3p0-config.xml,alllowercase,"+ "withthedigit0(NOTtheletterO)inc3p0.Itshouldbeplaced"+
"withthedigit0(NOTtheletterO)inc3p0.Itshouldbeplaced"+ "inthetoplevelofc3p0'seffectiveclasspath.");
"inthetoplevelofc3p0'seffectiveclasspath."); return;
return; }
} }
} }
} }
}
 }
} }
} }
} }
}
 static
static {
{ Stringls;
Stringls;
 try
try {ls=System.getProperty("line.separator","");}
{ls=System.getProperty("line.separator","");} catch(Exceptione)
catch(Exceptione) {ls="";}
{ls="";}
 LINESEP=ls;
LINESEP=ls;
 }
}
 publicstaticC3P0ConfigextractXmlConfigFromDefaultResource()throwsException
publicstaticC3P0ConfigextractXmlConfigFromDefaultResource()throwsException {
{ InputStreamis=null;
InputStreamis=null;
 try
try {
{ is=C3P0ConfigUtils.class.getResourceAsStream(XML_CONFIG_RSRC_PATH);
is=C3P0ConfigUtils.class.getResourceAsStream(XML_CONFIG_RSRC_PATH); if(is==null)
if(is==null) {
{ warnCommonXmlConfigResourceMisspellings();
warnCommonXmlConfigResourceMisspellings(); returnnull;
returnnull; }
} else
else returnextractXmlConfigFromInputStream(is);
returnextractXmlConfigFromInputStream(is); }
} finally
finally {
{ try{if(is!=null)is.close();}
try{if(is!=null)is.close();} catch(Exceptione)
catch(Exceptione) {
{ if(logger.isLoggable(MLevel.FINE))
if(logger.isLoggable(MLevel.FINE)) logger.log(MLevel.FINE,"ExceptiononresourceInputStreamclose.",e);
logger.log(MLevel.FINE,"ExceptiononresourceInputStreamclose.",e); }
} }
} }
}
 publicstaticC3P0ConfigextractXmlConfigFromInputStream(InputStreamis)throwsException
publicstaticC3P0ConfigextractXmlConfigFromInputStream(InputStreamis)throwsException {
{ DocumentBuilderFactoryfact=DocumentBuilderFactory.newInstance();
DocumentBuilderFactoryfact=DocumentBuilderFactory.newInstance(); DocumentBuilderdb=fact.newDocumentBuilder();
DocumentBuilderdb=fact.newDocumentBuilder(); Documentdoc=db.parse(is);
Documentdoc=db.parse(is);
 returnextractConfigFromXmlDoc(doc);
returnextractConfigFromXmlDoc(doc); }
}
 publicstaticC3P0ConfigextractConfigFromXmlDoc(Documentdoc)throwsException
publicstaticC3P0ConfigextractConfigFromXmlDoc(Documentdoc)throwsException {
{ ElementdocElem=doc.getDocumentElement();
ElementdocElem=doc.getDocumentElement(); if(docElem.getTagName().equals("c3p0-config"))
if(docElem.getTagName().equals("c3p0-config")) {
{ NamedScopedefaults;
NamedScopedefaults; HashMapconfigNamesToNamedScopes=newHashMap();
HashMapconfigNamesToNamedScopes=newHashMap();
 ElementdefaultConfigElem=DomParseUtils.uniqueChild(docElem,"default-config");
ElementdefaultConfigElem=DomParseUtils.uniqueChild(docElem,"default-config"); if(defaultConfigElem!=null)
if(defaultConfigElem!=null) defaults=extractNamedScopeFromLevel(defaultConfigElem);
defaults=extractNamedScopeFromLevel(defaultConfigElem); else
else defaults=newNamedScope();
defaults=newNamedScope(); NodeListnl=DomParseUtils.immediateChildElementsByTagName(docElem,"named-config");
NodeListnl=DomParseUtils.immediateChildElementsByTagName(docElem,"named-config"); for(inti=0,len=nl.getLength();i<len;++i)
for(inti=0,len=nl.getLength();i<len;++i) {
{ ElementnamedConfigElem=(Element)nl.item(i);
ElementnamedConfigElem=(Element)nl.item(i); StringconfigName=namedConfigElem.getAttribute("name");
StringconfigName=namedConfigElem.getAttribute("name"); if(configName!=null&&configName.length()>0)
if(configName!=null&&configName.length()>0) {
{ NamedScopenamedConfig=extractNamedScopeFromLevel(namedConfigElem);
NamedScopenamedConfig=extractNamedScopeFromLevel(namedConfigElem); configNamesToNamedScopes.put(configName,namedConfig);
configNamesToNamedScopes.put(configName,namedConfig); }
} else
else logger.warning("ConfigurationXMLcontainednamed-configelementwithoutnameattribute:"+namedConfigElem);
logger.warning("ConfigurationXMLcontainednamed-configelementwithoutnameattribute:"+namedConfigElem); }
} returnnewC3P0Config(defaults,configNamesToNamedScopes);
returnnewC3P0Config(defaults,configNamesToNamedScopes); }
} else
else thrownewException("Rootelementofc3p0configxmlshouldbe'c3p0-config',not'"+docElem.getTagName()+"'.");
thrownewException("Rootelementofc3p0configxmlshouldbe'c3p0-config',not'"+docElem.getTagName()+"'."); }
}
 privatestaticNamedScopeextractNamedScopeFromLevel(Elementelem)
privatestaticNamedScopeextractNamedScopeFromLevel(Elementelem) {
{ HashMapprops=extractPropertiesFromLevel(elem);
HashMapprops=extractPropertiesFromLevel(elem); HashMapuserNamesToOverrides=newHashMap();
HashMapuserNamesToOverrides=newHashMap();
 NodeListnl=DomParseUtils.immediateChildElementsByTagName(elem,"user-overrides");
NodeListnl=DomParseUtils.immediateChildElementsByTagName(elem,"user-overrides"); for(inti=0,len=nl.getLength();i<len;++i)
for(inti=0,len=nl.getLength();i<len;++i) {
{ ElementperUserConfigElem=(Element)nl.item(i);
ElementperUserConfigElem=(Element)nl.item(i); StringuserName=perUserConfigElem.getAttribute("user");
StringuserName=perUserConfigElem.getAttribute("user"); if(userName!=null&&userName.length()>0)
if(userName!=null&&userName.length()>0) {
{ HashMapuserProps=extractPropertiesFromLevel(perUserConfigElem);
HashMapuserProps=extractPropertiesFromLevel(perUserConfigElem); userNamesToOverrides.put(userName,userProps);
userNamesToOverrides.put(userName,userProps); }
} else
else logger.warning("ConfigurationXMLcontaineduser-overrideselementwithoutuserattribute:"+LINESEP+perUserConfigElem);
logger.warning("ConfigurationXMLcontaineduser-overrideselementwithoutuserattribute:"+LINESEP+perUserConfigElem); }
}
 returnnewNamedScope(props,userNamesToOverrides);
returnnewNamedScope(props,userNamesToOverrides); }
}
 privatestaticHashMapextractPropertiesFromLevel(Elementelem)
privatestaticHashMapextractPropertiesFromLevel(Elementelem) {
{ //System.err.println("extractPropertiesFromLevel()");
//System.err.println("extractPropertiesFromLevel()");
 HashMapout=newHashMap();
HashMapout=newHashMap();
 try
try {
{ NodeListnl=DomParseUtils.immediateChildElementsByTagName(elem,"property");
NodeListnl=DomParseUtils.immediateChildElementsByTagName(elem,"property"); intlen=nl.getLength();
intlen=nl.getLength(); for(inti=0;i<len;++i)
for(inti=0;i<len;++i) {
{ ElementpropertyElem=(Element)nl.item(i);
ElementpropertyElem=(Element)nl.item(i); StringpropName=propertyElem.getAttribute("name");
StringpropName=propertyElem.getAttribute("name"); if(propName!=null&&propName.length()>0)
if(propName!=null&&propName.length()>0) {
{ StringpropVal=DomParseUtils.allTextFromElement(propertyElem,true);
StringpropVal=DomParseUtils.allTextFromElement(propertyElem,true); out.put(propName,propVal);
out.put(propName,propVal); //System.err.println(propName+"->"+propVal);
//System.err.println(propName+"->"+propVal); }
} else
else logger.warning("ConfigurationXMLcontainedpropertyelementwithoutnameattribute:"+LINESEP+propertyElem);
logger.warning("ConfigurationXMLcontainedpropertyelementwithoutnameattribute:"+LINESEP+propertyElem); }
} }
} catch(Exceptione)
catch(Exceptione) {
{ logger.log(MLevel.WARNING,
logger.log(MLevel.WARNING, "AnexceptionoccurredwhilereadingconfigXML."+
"AnexceptionoccurredwhilereadingconfigXML."+ "Someconfigurationinformationhasprobablybeenignored.",
"Someconfigurationinformationhasprobablybeenignored.", e);
e); }
}
 returnout;
returnout; }
}
 privateC3P0ConfigXmlUtils()
privateC3P0ConfigXmlUtils() {}
{} }
}
 
?
?
 /*
/* *Distributedaspartofc3p0v.0.9.1.2
*Distributedaspartofc3p0v.0.9.1.2 *
* *Copyright(C)2005MachineryForChange,Inc.
*Copyright(C)2005MachineryForChange,Inc. *
* *Author:SteveWaldman<swaldman@mchange.com>
*Author:SteveWaldman<swaldman@mchange.com> *
* *Thislibraryisfreesoftware;youcanredistributeitand/ormodify
*Thislibraryisfreesoftware;youcanredistributeitand/ormodify *itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as
*itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as *publishedbytheFreeSoftwareFoundation.
*publishedbytheFreeSoftwareFoundation. *
* *Thissoftwareisdistributedinthehopethatitwillbeuseful,
*Thissoftwareisdistributedinthehopethatitwillbeuseful, *butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof *MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe *GNULesserGeneralPublicLicenseformoredetails.
*GNULesserGeneralPublicLicenseformoredetails. *
* *YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense *alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe
*alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe *FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330,
*FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330, *Boston,MA02111-1307,USA.
*Boston,MA02111-1307,USA. */
*/

 packagecom.mchange.v1.xml;
packagecom.mchange.v1.xml;
 importjava.util.*;
importjava.util.*; importorg.xml.sax.*;
importorg.xml.sax.*; importorg.w3c.dom.*;
importorg.w3c.dom.*; importcom.mchange.v1.util.DebugUtils;
importcom.mchange.v1.util.DebugUtils;
 publicfinalclassDomParseUtils
publicfinalclassDomParseUtils {
{ finalstaticbooleanDEBUG=true;
finalstaticbooleanDEBUG=true;
 /**
/** *@returnnullifchilddoesn'texist.
*@returnnullifchilddoesn'texist. */
*/ publicstaticStringallTextFromUniqueChild(Elementelem,StringchildTagName)
publicstaticStringallTextFromUniqueChild(Elementelem,StringchildTagName) throwsDOMException
throwsDOMException {returnallTextFromUniqueChild(elem,childTagName,false);}
{returnallTextFromUniqueChild(elem,childTagName,false);}
 /**
/** *@returnnullifchilddoesn'texist.
*@returnnullifchilddoesn'texist. */
*/ publicstaticStringallTextFromUniqueChild(Elementelem,StringchildTagName,booleantrim)
publicstaticStringallTextFromUniqueChild(Elementelem,StringchildTagName,booleantrim) throwsDOMException
throwsDOMException {
{ ElementuniqueChild=uniqueChildByTagName(elem,childTagName);
ElementuniqueChild=uniqueChildByTagName(elem,childTagName); if(uniqueChild==null)
if(uniqueChild==null) returnnull;
returnnull; else
else returnDomParseUtils.allTextFromElement(uniqueChild,trim);
returnDomParseUtils.allTextFromElement(uniqueChild,trim); }
}
 publicstaticElementuniqueChild(Elementelem,StringchildTagName)throwsDOMException
publicstaticElementuniqueChild(Elementelem,StringchildTagName)throwsDOMException {returnuniqueChildByTagName(elem,childTagName);}
{returnuniqueChildByTagName(elem,childTagName);}
 /**
/** *@deprecateduseuniqueChild(Elementelem,StringchildTagName)
*@deprecateduseuniqueChild(Elementelem,StringchildTagName) */
*/ publicstaticElementuniqueChildByTagName(Elementelem,StringchildTagName)throwsDOMException
publicstaticElementuniqueChildByTagName(Elementelem,StringchildTagName)throwsDOMException {
{ NodeListnl=elem.getElementsByTagName(childTagName);
NodeListnl=elem.getElementsByTagName(childTagName); intlen=nl.getLength();
intlen=nl.getLength(); if(DEBUG)
if(DEBUG) DebugUtils.myAssert(len<=1,
DebugUtils.myAssert(len<=1, "Thereismorethanone("+len+")childwithtagname:"+
"Thereismorethanone("+len+")childwithtagname:"+ childTagName+"!!!");
childTagName+"!!!"); return(len==1?(Element)nl.item(0):null);
return(len==1?(Element)nl.item(0):null); }
}
 publicstaticStringallText(Elementelem)throwsDOMException
publicstaticStringallText(Elementelem)throwsDOMException {returnallTextFromElement(elem);}
{returnallTextFromElement(elem);}
 publicstaticStringallText(Elementelem,booleantrim)throwsDOMException
publicstaticStringallText(Elementelem,booleantrim)throwsDOMException {returnallTextFromElement(elem,trim);}
{returnallTextFromElement(elem,trim);}
 /**@deprecateduseallText(Elementelem)*/
/**@deprecateduseallText(Elementelem)*/ publicstaticStringallTextFromElement(Elementelem)throwsDOMException
publicstaticStringallTextFromElement(Elementelem)throwsDOMException {returnallTextFromElement(elem,false);}
{returnallTextFromElement(elem,false);}
 /**@deprecateduseallText(Elementelem,booleantrim)*/
/**@deprecateduseallText(Elementelem,booleantrim)*/ publicstaticStringallTextFromElement(Elementelem,booleantrim)throwsDOMException
publicstaticStringallTextFromElement(Elementelem,booleantrim)throwsDOMException {
{ StringBuffertextBuf=newStringBuffer();
StringBuffertextBuf=newStringBuffer(); NodeListnl=elem.getChildNodes();
NodeListnl=elem.getChildNodes(); for(intj=0,len=nl.getLength();j<len;++j)
for(intj=0,len=nl.getLength();j<len;++j) {
{ Nodenode=nl.item(j);
Nodenode=nl.item(j); if(nodeinstanceofText)//includesTextandCDATA!
if(nodeinstanceofText)//includesTextandCDATA! textBuf.append(node.getNodeValue());
textBuf.append(node.getNodeValue()); }
} Stringout=textBuf.toString();
Stringout=textBuf.toString(); return(trim?out.trim():out);
return(trim?out.trim():out); }
}
 publicstaticString[]allTextFromImmediateChildElements(Elementparent,StringtagName)
publicstaticString[]allTextFromImmediateChildElements(Elementparent,StringtagName) throwsDOMException
throwsDOMException {returnallTextFromImmediateChildElements(parent,tagName,false);}
{returnallTextFromImmediateChildElements(parent,tagName,false);}
 publicstaticString[]allTextFromImmediateChildElements(Elementparent,StringtagName,booleantrim)
publicstaticString[]allTextFromImmediateChildElements(Elementparent,StringtagName,booleantrim) throwsDOMException
throwsDOMException {
{ NodeListnl=immediateChildElementsByTagName(parent,tagName);
NodeListnl=immediateChildElementsByTagName(parent,tagName); intlen=nl.getLength();
intlen=nl.getLength(); String[]out=newString[len];
String[]out=newString[len]; for(inti=0;i<len;++i)
for(inti=0;i<len;++i) out[i]=allText((Element)nl.item(i),trim);
out[i]=allText((Element)nl.item(i),trim); returnout;
returnout; }
}

 publicstaticNodeListimmediateChildElementsByTagName(Elementparent,StringtagName)
publicstaticNodeListimmediateChildElementsByTagName(Elementparent,StringtagName) throwsDOMException
throwsDOMException {returngetImmediateChildElementsByTagName(parent,tagName);}
{returngetImmediateChildElementsByTagName(parent,tagName);}
 /**
/** *@deprecateduseimmediateChildrenByTagName(Elementparent,StringtagName)
*@deprecateduseimmediateChildrenByTagName(Elementparent,StringtagName) */
*/ publicstaticNodeListgetImmediateChildElementsByTagName(Elementparent,StringtagName)
publicstaticNodeListgetImmediateChildElementsByTagName(Elementparent,StringtagName) throwsDOMException
throwsDOMException {
{ finalListnodes=newArrayList();
finalListnodes=newArrayList(); for(Nodechild=parent.getFirstChild();child!=null;child=child.getNextSibling())
for(Nodechild=parent.getFirstChild();child!=null;child=child.getNextSibling()) if(childinstanceofElement&&((Element)child).getTagName().equals(tagName))
if(childinstanceofElement&&((Element)child).getTagName().equals(tagName)) nodes.add(child);
nodes.add(child); returnnewNodeList()
returnnewNodeList() {
{ publicintgetLength()
publicintgetLength() {returnnodes.size();}
{returnnodes.size();}
 publicNodeitem(inti)
publicNodeitem(inti) {return(Node)nodes.get(i);}
{return(Node)nodes.get(i);} };
}; }
}
 publicstaticStringallTextFromUniqueImmediateChild(Elementelem,StringchildTagName)
publicstaticStringallTextFromUniqueImmediateChild(Elementelem,StringchildTagName) throwsDOMException
throwsDOMException {
{ ElementuniqueChild=uniqueImmediateChildByTagName(elem,childTagName);
ElementuniqueChild=uniqueImmediateChildByTagName(elem,childTagName); if(uniqueChild==null)
if(uniqueChild==null) returnnull;
returnnull; returnDomParseUtils.allTextFromElement(uniqueChild);
returnDomParseUtils.allTextFromElement(uniqueChild); }
}
 publicstaticElementuniqueImmediateChild(Elementelem,StringchildTagName)
publicstaticElementuniqueImmediateChild(Elementelem,StringchildTagName) throwsDOMException
throwsDOMException {returnuniqueImmediateChildByTagName(elem,childTagName);}
{returnuniqueImmediateChildByTagName(elem,childTagName);}
 /**
/** *@deprecateduseuniqueImmediateChild(Elementelem,StringchildTagName)
*@deprecateduseuniqueImmediateChild(Elementelem,StringchildTagName) */
*/ publicstaticElementuniqueImmediateChildByTagName(Elementelem,StringchildTagName)
publicstaticElementuniqueImmediateChildByTagName(Elementelem,StringchildTagName) throwsDOMException
throwsDOMException {
{ NodeListnl=getImmediateChildElementsByTagName(elem,childTagName);
NodeListnl=getImmediateChildElementsByTagName(elem,childTagName); intlen=nl.getLength();
intlen=nl.getLength(); if(DEBUG)
if(DEBUG) DebugUtils.myAssert(len<=1,
DebugUtils.myAssert(len<=1, "Thereismorethanone("+len+")childwithtagname:"+
"Thereismorethanone("+len+")childwithtagname:"+ childTagName+"!!!");
childTagName+"!!!"); return(len==1?(Element)nl.item(0):null);
return(len==1?(Element)nl.item(0):null); }
}
 /**
/** *@deprecateduseElement.getAttribute(Stringval)
*@deprecateduseElement.getAttribute(Stringval) */
*/ publicstaticStringattrValFromElement(Elementelement,StringattrName)
publicstaticStringattrValFromElement(Elementelement,StringattrName) throwsDOMException
throwsDOMException {
{ Attrattr=element.getAttributeNode(attrName);
Attrattr=element.getAttributeNode(attrName); return(attr==null?null:attr.getValue());
return(attr==null?null:attr.getValue()); }
}
 privateDomParseUtils()
privateDomParseUtils() {}
{} }
}
 
?
?
?
?
?
?