net.sourceforge.sqlunit
Class MatchPattern

java.lang.Object
  extended by net.sourceforge.sqlunit.MatchPattern

public class MatchPattern
extends java.lang.Object

MatchPattern fills a role in SQLUnit similar to Regular Expressions in text pattern matching. It is instantiated from the data supplied in the Match tag using the MatchHandler class. Unlike an user-defined object which implements the IMatcher interface, this class will not only know the algorithm to apply for matching (using the IMatcher object), but also where in the result object to apply the algorithm. The MatchHandler class builds a list of MatchPattern objects which is successively matched by DatabaseResult to determine whether to apply the pattern, and if so, return the results of the match. If no MatchPattern object is found to match against for the particular DatabaseResultKey, then the default matching (exact equality) is used. Multiple values may be specified as regular expression filters similar to that used in the Unix cut.

Version:
$Revision: 1.5 $
Author:
Sujit Pal (spal@users.sourceforge.net)

Constructor Summary
MatchPattern(java.lang.String resultSetIdFilter, java.lang.String rowIdFilter, java.lang.String colIdFilter, java.lang.String matcherClass, java.util.Map args)
          Builds a MatchPattern object with the supplied input parameters.
 
Method Summary
 boolean applyMatcher(java.lang.String source, java.lang.String target)
          Returns true or false as a result of applying the matching algorithm specified by the IMatcher object.
 boolean canApply(int resultSetId, int rowId, int colId)
          Returns true if this MatchPattern object can be applied to the DatabaseResult element specified by the [resultSetId, rowId, colId] tuple.
 java.lang.String getMatcherClass()
          Returns the full name of the Matcher class invoked by this MatchPattern.
static boolean matchPattern(java.lang.String p, int s)
          Matches a pattern filter against the supplied String s.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatchPattern

public MatchPattern(java.lang.String resultSetIdFilter,
                    java.lang.String rowIdFilter,
                    java.lang.String colIdFilter,
                    java.lang.String matcherClass,
                    java.util.Map args)
Builds a MatchPattern object with the supplied input parameters.

Parameters:
resultSetIdFilter - a regular expression.
rowIdFilter - a regular expression.
colIdFilter - a regular expression.
matcherClass - the full java class name of the IMatcher object.
args - a Map of name value pairs representing additional parameters to the IMatcher object to determine matching.
Method Detail

getMatcherClass

public final java.lang.String getMatcherClass()
Returns the full name of the Matcher class invoked by this MatchPattern.

Returns:
the Matcher class name.

canApply

public final boolean canApply(int resultSetId,
                              int rowId,
                              int colId)
                       throws SQLUnitException
Returns true if this MatchPattern object can be applied to the DatabaseResult element specified by the [resultSetId, rowId, colId] tuple. May return false if the conclusion is indeterminate.

Parameters:
resultSetId - the resultSet id.
rowId - the row id.
colId - the column id.
Returns:
true if the MatchPattern can be applied here.
Throws:
SQLUnitException - if a regular expression was incorrect.

applyMatcher

public final boolean applyMatcher(java.lang.String source,
                                  java.lang.String target)
                           throws SQLUnitException
Returns true or false as a result of applying the matching algorithm specified by the IMatcher object.

Parameters:
source - the source value of the DatabaseResult element.
target - the target value of the DatabaseResult element.
Returns:
true if matching algorithm matches, else false.
Throws:
SQLUnitException - if an underlying match operation failed.

matchPattern

public static boolean matchPattern(java.lang.String p,
                                   int s)
                            throws SQLUnitException
Matches a pattern filter against the supplied String s. The pattern filter can be composed of a combination of ranges and comma-separated enumerations. For example, the pattern "m-n,p,q" would mean any number x which satisfies the following condition: (m <= x <= n or x == p or x == q).

Parameters:
p - the pattern filter to match against.
s - the integer id to match.
Returns:
true if the String s matches the pattern p.
Throws:
SQLUnitException - if the pattern could not be parsed.