protected static DataSource getDataSourceFromJndi( String dsName, Context ctx ) throws NamingException {
    if ( Utils.isEmpty( dsName ) ) {
      throw new NamingException( BaseMessages.getString( PKG, "DatabaseUtil.DSNotFound", String.valueOf( dsName ) ) );
    }
    Object foundDs = FoundDS.get( dsName );
    if ( foundDs != null ) {
      return (DataSource) foundDs;
    }
    Object lkup = null;
    DataSource rtn = null;
    NamingException firstNe = null;
    // First, try what they ask for...
    try {
      lkup = ctx.lookup( dsName );
      if ( lkup instanceof DataSource ) {
        rtn = (DataSource) lkup;
        FoundDS.put( dsName, rtn );
        return rtn;
      }
    } catch ( NamingException ignored ) {
      firstNe = ignored;
    }
    try {
      // Needed this for Jboss
      lkup = ctx.lookup( "java:" + dsName );
      if ( lkup instanceof DataSource ) {
        rtn = (DataSource) lkup;
        FoundDS.put( dsName, rtn );
        return rtn;
      }
    } catch ( NamingException ignored ) {
      // ignore
    }
    try {
      // Tomcat
      lkup = ctx.lookup( "java:comp/env/jdbc/" + dsName );
      if ( lkup instanceof DataSource ) {
        rtn = (DataSource) lkup;
        FoundDS.put( dsName, rtn );
        return rtn;
      }
    } catch ( NamingException ignored ) {
      // ignore
    }
    try {
      // Others?
      lkup = ctx.lookup( "jdbc/" + dsName );
      if ( lkup instanceof DataSource ) {
        rtn = (DataSource) lkup;
        FoundDS.put( dsName, rtn );
        return rtn;
      }
    } catch ( NamingException ignored ) {
      // ignore
    }
    if ( firstNe != null ) {
      throw firstNe;
    }
    throw new NamingException( BaseMessages.getString( PKG, "DatabaseUtil.DSNotFound", dsName ) );
  }
@Test( expected = NamingException.class )
  public void testNullName() throws NamingException {
    DatabaseUtil.getDataSourceFromJndi( null, context );
  }