KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > dataset > filter > DefaultTableFilter


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.dbunit.dataset.DataSetException;
24
25 /**
26  * This filter exposes only tables matching include patterns and not matching
27  * exclude patterns. This implementation do not modify the original table
28  * sequence from the filtered dataset and support duplicate table names.
29  *
30  * @author Manuel Laflamme
31  * @since Apr 17, 2004
32  * @version $Revision: 1.1 $
33  */

34 public class DefaultTableFilter extends AbstractTableFilter implements ITableFilter
35 {
36     private final IncludeTableFilter _includeFilter = new IncludeTableFilter();
37     private final ExcludeTableFilter _excludeFilter = new ExcludeTableFilter();
38
39     /**
40      * Add a new accepted table name pattern.
41      * The following wildcard characters are supported:
42      * '*' matches zero or more characters,
43      * '?' matches one character.
44      */

45     public void includeTable(String JavaDoc patternName)
46     {
47         _includeFilter.includeTable(patternName);
48     }
49
50     /**
51      * Add a new refused table pattern name.
52      * The following wildcard characters are supported:
53      * '*' matches zero or more characters,
54      * '?' matches one character.
55      */

56     public void excludeTable(String JavaDoc patternName)
57     {
58         _excludeFilter.excludeTable(patternName);
59     }
60
61     ////////////////////////////////////////////////////////////////////////////
62
// AbstractTableFilter interface
63

64     public boolean isValidName(String JavaDoc tableName) throws DataSetException
65     {
66         if (_includeFilter.isEmpty() || _includeFilter.accept(tableName))
67         {
68             return _excludeFilter.accept(tableName);
69         }
70         return false;
71     }
72 }
73
Popular Tags