View Javadoc
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  /**
30   * This filter hides specified tables from the filtered dataset. This
31   * implementation do not modify the original table order from the filtered
32   * dataset and support duplicate table names.
33   *
34   * @author Manuel Laflamme
35   * @since Mar 7, 2003
36   * @version $Revision$
37   */
38  public class ExcludeTableFilter extends AbstractTableFilter implements ITableFilter
39  {
40  
41      /**
42       * Logger for this class
43       */
44      private static final Logger logger = LoggerFactory.getLogger(ExcludeTableFilter.class);
45  
46      private final PatternMatcher _patternMatcher = new PatternMatcher();
47  
48      /**
49       * Create a new empty ExcludeTableFilter. Use {@link #excludeTable} to hide
50       * some tables.
51       */
52      public ExcludeTableFilter()
53      {
54      }
55  
56      /**
57       * Create a new ExcludeTableFilter which prevent access to specified tables.
58       */
59      public ExcludeTableFilter(String[] tableNames)
60      {
61          for (int i = 0; i < tableNames.length; i++)
62          {
63              String tableName = tableNames[i];
64              excludeTable(tableName);
65          }
66      }
67  
68      /**
69       * Add a new refused table pattern name.
70       * The following wildcard characters are supported:
71       * '*' matches zero or more characters,
72       * '?' matches one character.
73       */
74      public void excludeTable(String patternName)
75      {
76          logger.debug("excludeTable(patternName=" + patternName + ") - start");
77  
78          _patternMatcher.addPattern(patternName);
79      }
80  
81      public boolean isEmpty()
82      {
83          logger.debug("isEmpty() - start");
84  
85          return _patternMatcher.isEmpty();
86      }
87  
88      ////////////////////////////////////////////////////////////////////////////
89      // ITableFilter interface
90  
91      public boolean isValidName(String tableName) throws DataSetException
92      {
93          logger.debug("isValidName(tableName=" + tableName + ") - start");
94  
95          return !_patternMatcher.accept(tableName);
96      }
97  }