IncludeTableFilter.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. /**
  25.  * This filter exposes only allowed tables from the filtered dataset. This
  26.  * implementation do not modify the original table sequence from the filtered
  27.  * dataset and support duplicate table names.
  28.  *
  29.  * @author Manuel Laflamme
  30.  * @since Mar 7, 2003
  31.  * @version $Revision$
  32.  */
  33. public class IncludeTableFilter extends AbstractTableFilter implements ITableFilter
  34. {

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

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

  40.     /**
  41.      * Create a new empty IncludeTableFilter. Use {@link #includeTable} to allow
  42.      * access to some tables.
  43.      */
  44.     public IncludeTableFilter()
  45.     {
  46.     }

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

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

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

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

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

  74.     ////////////////////////////////////////////////////////////////////////////
  75.     // ITableFilter interface

  76.     public boolean isValidName(String tableName)
  77.     {
  78.         logger.debug("isValidName(tableName={}) - start", tableName);

  79.         return _patternMatcher.accept(tableName);
  80.     }
  81. }