org.exolab.castor.xml.validators

Class PatternValidator

Known Direct Subclasses:
BigIntegerValidator, BooleanValidator, ByteValidator, DateTimeValidator, DecimalValidator, DoubleValidator, DurationValidator, FloatValidator, IntegerValidator, IntValidator, LongValidator, ShortValidator, StringValidator

public abstract class PatternValidator
extends java.lang.Object

A simple abstract class used for validating types which allow the pattern facet.
Version:
$Revision: 7273 $ $Date: 2004-12-11 02:13:52 -0700 (Sat, 11 Dec 2004) $
Authors:
Keith Visco
Edward Kuns

Nested Class Summary

(package private) class
PatternValidator.DefaultRegExpEvaluator
A simple implementation of a regular expression validator which always returns false.

Constructor Summary

PatternValidator()
Creates a new PatternValidator with no initial regular expression.
PatternValidator(String pattern)
Creates a new PatternValidator with the given initial regular expression.

Method Summary

void
addPattern(String pattern)
Sets the regular expression to validate against.
void
clearPatterns()
Clear all configured patterns.
String
getPattern()
Deprecated. since Castor 1.1, use getPatterns()
List
getPatterns()
Returns the collection of regular expression patterns.
boolean
hasPattern()
Returns true if a regular expression has been set for this PatternValidator.
boolean
isNillable()
Returns whether or not objects validated by this Validator are nillable (are allowed to be null).
void
setNillable(boolean nillable)
Sets whether or not objects validated by this Validator are allowed to be null (nillable).
void
setPattern(String pattern)
Deprecated. since Castor 1.1, use addPattern(String)
void
validate(Object object, ValidationContext context)
Validates the given Object.
void
validate(String str, ValidationContext context)
Validates the given String against the regular expression pattern of this PatternValidator.

Constructor Details

PatternValidator

public PatternValidator()
Creates a new PatternValidator with no initial regular expression.

PatternValidator

public PatternValidator(String pattern)
Creates a new PatternValidator with the given initial regular expression.
Parameters:
pattern - the regular expression to validate against

Method Details

addPattern

public void addPattern(String pattern)
Sets the regular expression to validate against.
Parameters:
pattern - the regular expression to use when validating

clearPatterns

public void clearPatterns()
Clear all configured patterns.

getPattern

public String getPattern()

Deprecated. since Castor 1.1, use getPatterns()

Returns the first regular expression pattern for this PatternValidator, or null if no pattern has been set.
Returns:
the regular expression pattern

getPatterns

public List getPatterns()
Returns the collection of regular expression patterns.
Returns:
the collection of regular expression patterns.

hasPattern

public boolean hasPattern()
Returns true if a regular expression has been set for this PatternValidator.
Returns:
true if a regular expression has been set for this PatternValidator

isNillable

public boolean isNillable()
Returns whether or not objects validated by this Validator are nillable (are allowed to be null).
Returns:
true if null is a valid value

setNillable

public void setNillable(boolean nillable)
Sets whether or not objects validated by this Validator are allowed to be null (nillable).
Parameters:
nillable - a boolean that when true indicates null values pass validation

setPattern

public void setPattern(String pattern)

Deprecated. since Castor 1.1, use addPattern(String)

Sets the regular expression to validate against. Deprecated since Castor 1.1, supports only one pattern to preserve old behavior. Use addPattern(String).
Parameters:
pattern - the regular expression to use when validating

validate

public void validate(Object object,
                     ValidationContext context)
            throws ValidationException
Validates the given Object.
Parameters:
object - the Object to validate
context - the ValidationContext
Throws:
ValidationException - if the given String is not matched by the regular expression pattern

validate

public void validate(String str,
                     ValidationContext context)
            throws ValidationException
Validates the given String against the regular expression pattern of this PatternValidator.
Parameters:
str - the string to validate
context - the validation context
Throws:
ValidationException - if the given String is not matched by the regular expression pattern

Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com