Sample Demonstrating a Custom Token Validator with an Interface
Sample
The following sample demonstrates a custom token validator with an interface. It returns true if the generated token begins with two digits; otherwise, false. This sample demonstrates a custom token validator with an interface.
// This code returns true if the generated token begins
// with two digits.
// If it returns false, CT-V will generate a new token.
public class ValidateToken implements ITokenValidator
{
@Override
public Boolean isValid( String value ) throws TokenException
{
int digit = value.charAt( 0 ) - '0';
boolean even = digit % 2 == 0;
if( even )
{
digit = value.charAt( 1 ) - '0';
even = digit % 2 == 0;
if( !even )
{
System.out.println( "First is even, second is odd. Really not okay." );
return false;
}
System.out.println( "Yeah, it's ok." );
return true;
}
else
{
System.out.println( "No, it's not even." );
return false;
}
}
}