001: package com.calipso.reportgenerator.services;
002:
003: import com.calipso.reportgenerator.common.InfoException;
004: import com.calipso.reportgenerator.reportcalculator.IDataSource;
005: import com.calipso.reportgenerator.reportcalculator.Matrix;
006:
007: import java.util.Map;
008: import java.util.HashMap;
009: import com.calipso.reportgenerator.common.ReportGeneratorConfiguration;
010: import com.calipso.reportgenerator.common.ReportSpec;
011: import com.calipso.reportgenerator.common.ReportDataSourceSpec;
012: import com.calipso.reportgenerator.reportmanager.ReportDataSource;
013:
014: /**
015: * Clase para implementar los distintos resolvedores de SQL
016: */
017: public abstract class SQLDataSourceResolver implements
018: ISQLDataSourceResolver {
019:
020: private static Map resolvers;
021: private String sqlText;
022: private ReportGeneratorConfiguration reportGeneratorConfiguration;
023: private DataSourceDefinitionConnectionString dataSourceDefinitionConnectionString;
024: private ReportSpec reportSpec;
025: protected ReportDataSource dataSource;
026:
027: private static Map getResolvers() {
028: if (resolvers == null) {
029: resolvers = new HashMap();
030: resolvers.put(FramewokPlatform.Calipso,
031: DefaultSQLDataSourceResolver.class);
032: resolvers.put(FramewokPlatform.StandAlone,
033: DefaultSQLDataSourceResolver.class);
034: }
035: return resolvers;
036: }
037:
038: public static ISQLDataSourceResolver getResolver(
039: ReportGeneratorConfiguration reportGeneratorConfiguration,
040: DataSourceDefinitionConnectionString dataSourceDefinitionConnectionString,
041: ReportSpec reportSpec) throws InfoException {
042: Class resolverClass = (Class) getResolvers().get(
043: reportGeneratorConfiguration.getFrameworkPlatform());
044: try {
045: ISQLDataSourceResolver resolver = (ISQLDataSourceResolver) resolverClass
046: .newInstance();
047: resolver.init(reportGeneratorConfiguration,
048: dataSourceDefinitionConnectionString, reportSpec);
049: return resolver;
050: } catch (Exception e) {
051: throw new InfoException(
052: com.calipso.reportgenerator.common.LanguageTraslator
053: .traslate("206"), e);
054: }
055: }
056:
057: public IDataSource execute(String sqlText, Matrix matrix)
058: throws InfoException {
059: setSqlText(sqlText);
060: //setReportDataSourceSpec(this.getReportDataSourceSpec());
061: return execute(matrix);
062: }
063:
064: public String getSqlText() {
065: return sqlText;
066: }
067:
068: public void setSqlText(String sqlText) {
069: this .sqlText = sqlText;
070: }
071:
072: public void setReportDataSource(ReportDataSource dataSource) {
073: this .dataSource = dataSource;
074: }
075:
076: /*public ReportDataSourceSpec getReportDataSourceSpec() {
077: return dataSourceSpec;
078: }*/
079:
080: public void init(
081: ReportGeneratorConfiguration reportGeneratorConfiguration,
082: DataSourceDefinitionConnectionString dataSourceDefinitionConnectionString,
083: ReportSpec reportSpec) {
084: this .reportGeneratorConfiguration = reportGeneratorConfiguration;
085: this .dataSourceDefinitionConnectionString = dataSourceDefinitionConnectionString;
086: this .reportSpec = reportSpec;
087: }
088:
089: public ReportGeneratorConfiguration getReportGeneratorConfiguration() {
090: return reportGeneratorConfiguration;
091: }
092:
093: public DataSourceDefinitionConnectionString getDataSourceDefinitionConnectionString() {
094: return dataSourceDefinitionConnectionString;
095: }
096:
097: public ReportSpec getReportSpec() {
098: return reportSpec;
099: }
100: }
|