1 package com.calipso.reportgenerator.reportmanager; 2 3 import com.calipso.reportgenerator.reportcalculator.*; 4 import com.calipso.reportgenerator.common.*; 5 import com.calipso.reportgenerator.common.InfoException; 7 import com.calipso.reportgenerator.reportdefinitions.types.ReportDataType; 8 import com.calipso.common.DateEx; 9 10 import java.util.*; 11 12 15 16 public abstract class ReportDataSource { 17 18 private ReportDataSourceSpec dataSourceSpec; 19 private ReportSpec reportSpec; 20 private Vector columnNames; 21 private ExpressionCubeFilter filter; 22 private ReportGeneratorConfiguration reportGeneratorConfiguration; 23 24 28 public ReportGeneratorConfiguration getReportGeneratorConfiguration() { 29 return reportGeneratorConfiguration; 30 } 31 32 36 public void setGeneratorConfiguration(ReportGeneratorConfiguration reportGeneratorConfiguration) { 37 this.reportGeneratorConfiguration = reportGeneratorConfiguration; 38 } 39 40 43 public ReportDataSource() { 44 45 } 46 47 52 public ReportDataSource(ReportSpec reportSpec, ReportDataSourceSpec reportDataSourceSpec) { 53 this.dataSourceSpec= reportDataSourceSpec; 54 this.reportSpec = reportSpec; 55 initialize(); 56 } 57 58 61 protected void initialize() { 62 } 63 64 68 public ReportSpec getReportSpec() { 69 return reportSpec; 70 } 71 72 76 public ReportDataSourceSpec getReportDataSourceSpec() { 77 return dataSourceSpec; 78 } 79 80 81 85 public abstract IDataSource getDataSource(Matrix matrix) throws InfoException; 86 87 93 public IDataSource newDataSource() throws InfoException { 94 try { 95 return new DataSource(getColumnNames()); 96 } catch (InfoException e) { 98 throw new InfoException(LanguageTraslator.traslate("79"), e); 99 } 100 } 101 102 106 protected Vector getColumnNames() { 107 if (columnNames == null) { 108 columnNames = new Vector(); 109 initializeColumnNames(columnNames); 110 } 111 return columnNames; 112 } 113 114 private void parseColumnNamesFrom(Collection names, Collection fieldSpecs){ 115 Iterator iterator = fieldSpecs.iterator(); 116 while (iterator.hasNext()) { 117 ReportFieldSpec fieldSpec = (ReportFieldSpec) iterator.next(); 118 if (!fieldSpec.getCalculated()){ 119 names.add(fieldSpec.getName()); 120 } 121 } 122 } 123 127 private void initializeColumnNames(Collection names) { 128 Collection dimensions = getReportSpec().getDimensionsByIndex(); 129 Collection metrics = getReportSpec().getMetricsByIndex(); 130 parseColumnNamesFrom(names, dimensions); 131 parseColumnNamesFrom(names, metrics); 132 } 133 134 138 public ExpressionCubeFilter getFilter() { 139 return filter; 140 } 141 142 146 public void setFilter(ExpressionCubeFilter filter) { 147 this.filter = filter; 148 } 149 150 153 public abstract int getFilterVarMode(); 154 155 public Object getValueForMetric(Object value, ReportMetricSpec metric, Object [] collection, int i) throws InfoException{ 156 collection[i] = value; 157 return metric.getValue(collection); 158 } 159 160 public Object getValueForDimension(Object value, ReportDimensionSpec dimension, Object [] collection, int i) throws InfoException{ 161 try{ 162 switch(dimension.getDataType().getType()){ 163 case ReportDataType.FLOAT_TYPE: 164 if (value != null){ 165 value = SharedFloat.newFrom(new Float (value.toString().trim())); 166 }else{ 167 value = null; 168 } 169 break; 170 case ReportDataType.INTEGER_TYPE: 171 value = SharedInteger.newFrom(new Integer (value.toString().trim())); 172 break; 173 case ReportDataType.STRING_TYPE: 174 value = value.toString().trim().intern(); break; 176 case ReportDataType.DATETIME_TYPE: 177 case ReportDataType.DATE_TYPE: 178 DateEx dateEx; 179 if(value instanceof Date){ 180 dateEx = new DateEx((Date)value); 181 } else { 182 dateEx = new DateEx(value, getReportDataSourceSpec().getPattern(getReportSpec().getDimensionFromIndex(i).getDataType().getType())); 183 } 184 value = SharedDate.newFrom(dateEx); 185 break; 186 default: 187 value = value.toString().trim().intern(); break; 189 } 190 }catch(Exception e){ 191 if(value==null){ 192 value = "".intern(); }else{ 194 value = value.toString().trim().intern(); } 196 } 197 collection[i] = value; 198 return dimension.getValue(collection, getReportDataSourceSpec()); 199 } 200 201 } 202 | Popular Tags |