Parse JDBC parameters and setup dataSource appropriately
DataSourceWrapper dataSource = new DataSourceWrapper();
String[] paramString = new String[4];
int escCount = 0;
int aryCount = 0;
int begin = 0;
for(int index=0; index < params.length(); index++) {
char nextChar = params.charAt(index);
if (TOKEN.indexOf(nextChar) != -1) {
if (escCount == 0) {
paramString[aryCount] = params.substring(begin,index).trim();
begin = index + 1;
if (++aryCount > 4) {
throw new JspTagException(
Resources.getMessage("JDBC_PARAM_COUNT"));
}
}
}
if (ESCAPE.indexOf(nextChar) != -1) {
escCount++;
}
else {
escCount = 0;
}
}
paramString[aryCount] = params.substring(begin).trim();
// use the JDBC URL from the parameter string
dataSource.setJdbcURL(paramString[0]);
// try to load a driver if it's present
if (paramString[1] != null) {
try {
dataSource.setDriverClassName(paramString[1]);
} catch (Exception ex) {
throw new JspTagException(
Resources.getMessage("DRIVER_INVALID_CLASS",
ex.toString()), ex);
}
}
// set the username and password
dataSource.setUserName(paramString[2]);
dataSource.setPassword(paramString[3]);
return dataSource;