class JndiJdbcReportDataSourceServiceFactory extends JdbcReportDataSourceServiceFactory {

	public ReportDataSourceService createService(ReportDataSource dataSource) {
        String jndiName;
        DataSource ds;
        JndiJdbcReportDataSource jndiDataSource = (JndiJdbcReportDataSource) dataSource;
		if (getProfileAttributesResolver() != null) jndiDataSource = getProfileAttributesResolver().mergeResource(jndiDataSource);
        TimeZone timeZone = getTimeZoneByDataSourceTimeZone(jndiDataSource.getTimezone());
        jndiName = jndiDataSource.getJndiName();
        if (disableJndi || ctx == null) {
        	return createServiceFromFallbackProperties(jndiName, timeZone);
        }
        try {
			ds = (DataSource) ctx.lookup("java:comp/env/" + jndiName);
			return new JdbcDataSourceService(ds, timeZone);
		} catch (NoInitialContextException e) {
			// there's no context provider available...fall back to prop lookup
			ctx = null;
			return createService(dataSource);
		} catch (NamingException e) {
            //Added as short time solution due of http://bugzilla.jaspersoft.com/show_bug.cgi?id=26570.
            //The main problem - this code executes in separate tread (non http).
            //Jboss 7 support team recommend that you use the non-component environment namespace for such situations.
            try {
                ds = (DataSource) ctx.lookup(jndiName);
                return new JdbcDataSourceService(ds, timeZone);
            } catch (NamingException ex) {
                if (log.isDebugEnabled())
                    log.debug(e, e);
                throw new JSDataSourceConnectionFailedException(e);
            }
		}
	}

	public  JndiJdbcReportDataSourceServiceFactory();

}