Package org.exolab.castor.xml.validators
Class StringValidator
- java.lang.Object
-
- org.exolab.castor.xml.validators.PatternValidator
-
- org.exolab.castor.xml.validators.StringValidator
-
- All Implemented Interfaces:
TypeValidator
- Direct Known Subclasses:
IdValidator,NameValidator
public class StringValidator extends PatternValidator implements TypeValidator
The String Validation class.- Version:
- $Revision: 6587 $ $Date: 2004-12-11 02:13:52 -0700 (Sat, 11 Dec 2004) $
- Author:
- Keith Visco
-
-
Field Summary
-
Fields inherited from class org.exolab.castor.xml.validators.PatternValidator
resourceBundle
-
-
Constructor Summary
Constructors Constructor Description StringValidator()Creates a new StringValidator with no restrictions.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclearFixed()Clears the fixed value for this ShortValidator.java.lang.Stringnormalize(java.lang.String value)Normalizes the given string according to the whiteSpace facet used.voidsetFixed(java.lang.String fixedValue)Sets the fixed value in which all valid Strings must match.voidsetFixedValue(java.lang.String fixedValue)Deprecated.since 0.9.4_betavoidsetLength(int length)Sets the required string length for String validation.voidsetMaxLength(int maxLength)Sets the maximum string length for String validation.voidsetMinLength(int minLength)Sets the minimum string length for String validation.voidsetRequired(boolean required)Sets whether or not a String is required (non null).voidsetWhiteSpace(java.lang.String value)Sets the whiteSpace facet of the validator.voidvalidate(java.lang.Object object)Validates the given Object.voidvalidate(java.lang.Object object, ValidationContext context)Validates the given Object.voidvalidate(java.lang.String value, ValidationContext context)Validates the given Object.-
Methods inherited from class org.exolab.castor.xml.validators.PatternValidator
addPattern, clearPatterns, getPatterns, hasPattern, isNillable, setNillable
-
-
-
-
Method Detail
-
clearFixed
public void clearFixed()
Clears the fixed value for this ShortValidator.
-
setFixed
public void setFixed(java.lang.String fixedValue)
Sets the fixed value in which all valid Strings must match.- Parameters:
fixedValue- the fixed value that all Strings must match
-
setFixedValue
public void setFixedValue(java.lang.String fixedValue)
Deprecated.since 0.9.4_betaOnly used for backward compatibility for object model generated with an old version of Castor.- Parameters:
fixedValue- the fixed value that all Strings must match
-
setMaxLength
public void setMaxLength(int maxLength)
Sets the maximum string length for String validation. To pass validation, a String must be shorter than or equal to this length. To remove this facet, set a negative value.- Parameters:
maxLength- the maximum length for valid Strings
-
setMinLength
public void setMinLength(int minLength)
Sets the minimum string length for String validation. To pass validation, a String must be longer than or equal to this length. To remove this facet, set a negative value.- Parameters:
minLength- the minimum length for valid Strings
-
setLength
public void setLength(int length)
Sets the required string length for String validation. To pass validation, a String must be exactly this many characters long. To remove this facet, set a negative value.- Parameters:
length- the required length for valid Strings
-
setRequired
public void setRequired(boolean required)
Sets whether or not a String is required (non null).- Parameters:
required- the flag indicating whether this string must be non-null.
-
setWhiteSpace
public void setWhiteSpace(java.lang.String value)
Sets the whiteSpace facet of the validator.The value of the whiteSpace facet must be one of the following:
- preserve
- replace
- collapse
FIXME: This is not really a function of validation, but of XML processing before the string is returned from the XML processor. This should be moved to the FieldHandler, or somewhere else, but not here.
- Parameters:
value- the whiteSpace value
-
normalize
public java.lang.String normalize(java.lang.String value)
Normalizes the given string according to the whiteSpace facet used.FIXME: THIS METHOD SHOULD NOT BE HERE..SHOULD BE MOVED TO A FieldHandler or to the Unmarshaller...but not here!!! (kvisco 20030125)
- Parameters:
value- the String to normalize- Returns:
- the normalized string.
-
validate
public void validate(java.lang.String value, ValidationContext context) throws ValidationExceptionValidates the given Object.- Overrides:
validatein classPatternValidator- Parameters:
value- the string to validatecontext- the ValidationContext- Throws:
ValidationException- if the object fails validation.- See Also:
#setPattern
-
validate
public void validate(java.lang.Object object) throws ValidationExceptionValidates the given Object.- Parameters:
object- the Object to validate- Throws:
ValidationException- if the object fails validation.
-
validate
public void validate(java.lang.Object object, ValidationContext context) throws ValidationExceptionValidates the given Object.- Specified by:
validatein interfaceTypeValidator- Overrides:
validatein classPatternValidator- Parameters:
object- the Object to validatecontext- the ValidationContext- Throws:
ValidationException- if the object fails validation.
-
-