ExcludeTableFilter.java

  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. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;

  24. import org.dbunit.dataset.DataSetException;


  25. /**
  26.  * This filter hides specified tables from the filtered dataset. This
  27.  * implementation do not modify the original table order from the filtered
  28.  * dataset and support duplicate table names.
  29.  *
  30.  * @author Manuel Laflamme
  31.  * @since Mar 7, 2003
  32.  * @version $Revision$
  33.  */
  34. public class ExcludeTableFilter extends AbstractTableFilter implements ITableFilter
  35. {

  36.     /**
  37.      * Logger for this class
  38.      */
  39.     private static final Logger logger = LoggerFactory.getLogger(ExcludeTableFilter.class);

  40.     private final PatternMatcher _patternMatcher = new PatternMatcher();

  41.     /**
  42.      * Create a new empty ExcludeTableFilter. Use {@link #excludeTable} to hide
  43.      * some tables.
  44.      */
  45.     public ExcludeTableFilter()
  46.     {
  47.     }

  48.     /**
  49.      * Create a new ExcludeTableFilter which prevent access to specified tables.
  50.      */
  51.     public ExcludeTableFilter(String[] tableNames)
  52.     {
  53.         for (int i = 0; i < tableNames.length; i++)
  54.         {
  55.             String tableName = tableNames[i];
  56.             excludeTable(tableName);
  57.         }
  58.     }

  59.     /**
  60.      * Add a new refused table pattern name.
  61.      * The following wildcard characters are supported:
  62.      * '*' matches zero or more characters,
  63.      * '?' matches one character.
  64.      */
  65.     public void excludeTable(String patternName)
  66.     {
  67.         logger.debug("excludeTable(patternName=" + patternName + ") - start");

  68.         _patternMatcher.addPattern(patternName);
  69.     }

  70.     public boolean isEmpty()
  71.     {
  72.         logger.debug("isEmpty() - start");

  73.         return _patternMatcher.isEmpty();
  74.     }

  75.     ////////////////////////////////////////////////////////////////////////////
  76.     // ITableFilter interface

  77.     public boolean isValidName(String tableName) throws DataSetException
  78.     {
  79.         logger.debug("isValidName(tableName=" + tableName + ") - start");

  80.         return !_patternMatcher.accept(tableName);
  81.     }
  82. }