static DataSource getDataSource ( Object rawDataSource , PageContext pc ) throws JspException { DataSource dataSource = null ; if ( rawDataSource == null ) { rawDataSource = Config . find ( pc , Config . SQL_DATA_SOURCE ) ; } if ( rawDataSource == null ) { return null ; } /* * If the 'dataSource' attribute's value resolves to a String * after rtexpr/EL evaluation, use the string as JNDI path to * a DataSource */ if ( rawDataSource instanceof String ) { try { Context ctx = new InitialContext ( ) ; // relative to standard JNDI root for J2EE app Context envCtx = ( Context ) ctx . lookup ( "java:comp/env" ) ; dataSource = ( DataSource ) envCtx . lookup ( ( String ) rawDataSource ) ; } catch ( NamingException ex ) { dataSource = getDataSource ( ( String ) rawDataSource ) ; } } else if ( rawDataSource instanceof DataSource ) { dataSource = ( DataSource ) rawDataSource ; } else { throw new JspException ( Resources . getMessage ( "SQL_DATASOURCE_INVALID_TYPE" ) ) ; } return dataSource ; }
If dataSource is a String first do JNDI lookup . If lookup fails parse String like it was a set of JDBC parameters Otherwise check to see if dataSource is a DataSource object and use as is