1 /*
2 *
3 * The DbUnit Database Testing Framework
4 * Copyright (C)2002-2004, DbUnit.org
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21 package org.dbunit.dataset.filter;
22
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import org.dbunit.dataset.DataSetException;
27
28 /**
29 * This filter exposes only tables matching include patterns and not matching
30 * exclude patterns. This implementation do not modify the original table
31 * sequence from the filtered dataset and support duplicate table names.
32 *
33 * @author Manuel Laflamme
34 * @since Apr 17, 2004
35 * @version $Revision: 554 $
36 */
37 public class DefaultTableFilter extends AbstractTableFilter implements ITableFilter
38 {
39
40 /**
41 * Logger for this class
42 */
43 private static final Logger logger = LoggerFactory.getLogger(DefaultTableFilter.class);
44
45 private final IncludeTableFilter _includeFilter = new IncludeTableFilter();
46 private final ExcludeTableFilter _excludeFilter = new ExcludeTableFilter();
47
48 /**
49 * Add a new accepted table name pattern.
50 * The following wildcard characters are supported:
51 * '*' matches zero or more characters,
52 * '?' matches one character.
53 */
54 public void includeTable(String patternName)
55 {
56 logger.debug("includeTable(patternName=" + patternName + ") - start");
57
58 _includeFilter.includeTable(patternName);
59 }
60
61 /**
62 * Add a new refused table pattern name.
63 * The following wildcard characters are supported:
64 * '*' matches zero or more characters,
65 * '?' matches one character.
66 */
67 public void excludeTable(String patternName)
68 {
69 logger.debug("excludeTable(patternName=" + patternName + ") - start");
70
71 _excludeFilter.excludeTable(patternName);
72 }
73
74 ////////////////////////////////////////////////////////////////////////////
75 // AbstractTableFilter interface
76
77 public boolean isValidName(String tableName) throws DataSetException
78 {
79 logger.debug("isValidName(tableName=" + tableName + ") - start");
80
81 if (_includeFilter.isEmpty() || _includeFilter.accept(tableName))
82 {
83 return _excludeFilter.accept(tableName);
84 }
85 return false;
86 }
87 }