1 package jimm.datavision.source; 2 import jimm.datavision.*; 3 import jimm.util.XMLWriter; 4 import jimm.util.I18N; 5 import java.io.IOException ; 6 import java.io.FileNotFoundException ; 7 import java.util.Iterator ; 8 import java.util.ArrayList ; 9 import org.xml.sax.InputSource ; 10 11 19 public abstract class DataSource implements Writeable { 20 21 protected Report report; 22 protected Query query; 23 protected String metadataURL; 24 25 public DataSource(Report r, Query q) { 26 report = r; 27 query = q; 28 } 29 30 36 public abstract boolean canJoinTables(); 37 38 44 public abstract boolean isSQLGenerated(); 45 46 52 public abstract boolean isConnectionEditable(); 53 54 60 public abstract boolean areRecordsSelectable(); 61 62 68 public abstract boolean areRecordsSortable(); 69 70 76 public abstract boolean canGroupRecords(); 77 78 85 public boolean canRunReports() { return true; } 86 87 94 public boolean needsSourceFile() { return false; } 95 96 102 public void setSourceFile(String filePath) throws FileNotFoundException { } 103 104 108 public void reuseSourceFile() throws FileNotFoundException { } 109 110 public Report getReport() { return report; } 111 112 public Query getQuery() { return query; } 113 114 public abstract DataCursor execute() throws Exception ; 115 116 124 public void addColumn(Column col) {} 125 126 136 public void reloadColumns() { 137 if (query != null) 138 query.reloadColumns(this); 139 } 140 141 148 public void readMetadataFrom(String urlString) throws Exception { 149 try { 150 metadataURL = urlString; 151 new MetadataReader(this).read(new InputSource (urlString)); 152 } 153 catch (IOException ioe) { 154 ErrorHandler.error(I18N.get("DataSource.metadata_err"), ioe, 155 I18N.get("DataSource.metadata_err_title")); 156 } 157 } 158 159 166 public abstract Column findColumn(Object id); 167 168 173 public int indexOfSelectable(Selectable sel) { 174 return query.indexOfSelectable(sel); 175 } 176 177 184 public abstract Iterator tables(); 185 186 194 public abstract Iterator tablesUsedInReport(); 195 196 201 public abstract Iterator columns(); 202 203 210 public Iterator columnsInTablesUsedInReport() { 211 Iterator iter = tablesUsedInReport(); 212 if (iter == null) 213 return columns(); 214 215 ArrayList list = new ArrayList (); 217 while (iter.hasNext()) { 218 Table t = (Table)iter.next(); 219 list.addAll(t.columns.values()); 220 } 221 return list.iterator(); 222 } 223 224 public void removeSort(Selectable s) { 225 query.removeSort(s); 226 } 227 228 237 public boolean containsReferenceTo(Parameter p) { 238 return query.containsReferenceTo(p); 239 } 240 241 246 public void writeXML(XMLWriter out) { 247 out.startElement("source"); 248 doWriteXML(out); 249 query.writeXML(out); 250 out.endElement(); 251 } 252 253 protected abstract void doWriteXML(XMLWriter out); 254 255 } 256 | Popular Tags |