1 21 package org.dbunit.dataset.filter; 22 23 import org.dbunit.dataset.*; 24 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 37 public abstract class AbstractTableFilter implements ITableFilter 38 { 39 40 45 public abstract boolean isValidName(String tableName) throws DataSetException; 46 47 50 public boolean accept(String tableName) throws DataSetException 51 { 52 return isValidName(tableName); 53 } 54 55 public String [] getTableNames(IDataSet dataSet) throws DataSetException 56 { 57 String [] tableNames = dataSet.getTableNames(); 58 List nameList = new ArrayList (); 59 for (int i = 0; i < tableNames.length; i++) 60 { 61 String tableName = tableNames[i]; 62 if (accept(tableName)) 63 { 64 nameList.add(tableName); 65 } 66 } 67 return (String [])nameList.toArray(new String [0]); 68 } 69 70 public ITableIterator iterator(IDataSet dataSet, boolean reversed) 71 throws DataSetException 72 { 73 return new FilterIterator(reversed ? 74 dataSet.reverseIterator() : dataSet.iterator()); 75 } 76 77 80 private class FilterIterator implements ITableIterator 81 { 82 private final ITableIterator _iterator; 83 84 public FilterIterator(ITableIterator iterator) 85 { 86 _iterator = iterator; 87 } 88 89 92 public boolean next() throws DataSetException 93 { 94 while(_iterator.next()) 95 { 96 if (accept(_iterator.getTableMetaData().getTableName())) 97 { 98 return true; 99 } 100 } 101 return false; 102 } 103 104 public ITableMetaData getTableMetaData() throws DataSetException 105 { 106 return _iterator.getTableMetaData(); 107 } 108 109 public ITable getTable() throws DataSetException 110 { 111 return _iterator.getTable(); 112 } 113 } 114 } 115 | Popular Tags |