KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Set JavaDoc;
26
27 /**
28  * This filter exposes only allowed tables from the filtered dataset. This
29  * implementation do not modify the original table sequence from the filtered
30  * dataset and support duplicate table names.
31  *
32  * @author Manuel Laflamme
33  * @since Mar 7, 2003
34  * @version $Revision: 1.7 $
35  */

36 public class IncludeTableFilter extends AbstractTableFilter implements ITableFilter
37 {
38     private final PatternMatcher _patternMatcher = new PatternMatcher();
39
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     /**
49      * Create a new IncludeTableFilter which allow access to specified tables.
50      */

51     public IncludeTableFilter(String JavaDoc[] tableNames)
52     {
53         for (int i = 0; i < tableNames.length; i++)
54         {
55             String JavaDoc tableName = tableNames[i];
56             includeTable(tableName);
57         }
58     }
59
60     /**
61      * Add a new accepted table name pattern.
62      * The following wildcard characters are supported:
63      * '*' matches zero or more characters,
64      * '?' matches one character.
65      */

66     public void includeTable(String JavaDoc patternName)
67     {
68         _patternMatcher.addPattern(patternName);
69     }
70
71     public boolean isEmpty()
72     {
73         return _patternMatcher.isEmpty();
74     }
75
76     ////////////////////////////////////////////////////////////////////////////
77
// ITableFilter interface
78

79     public boolean isValidName(String JavaDoc tableName)
80     {
81         return _patternMatcher.accept(tableName);
82     }
83 }
84
Popular Tags