org.javalid.core.validator
Class ValidatorSupport

java.lang.Object
  extended by org.javalid.core.validator.ValidatorSupport

public class ValidatorSupport
extends java.lang.Object

Contains a couple of shared methods used by the standard JavalidValidator implementation classes and some other core classes.

Changes for 1.1

Since:
1.0
Version:
1.1
Author:
M.Reuvers

Method Summary
static void checkIsSingleExpression(java.lang.String value, java.lang.String propertyName, java.lang.String currentPath)
          Checks if given value is a single expression, see ELSupport.isExpression(java.lang.String).
static void compareCalendars(int validationAnnotation, java.lang.String pattern, java.lang.String customCode, boolean globalMessage, java.util.Calendar calAnnotation, java.util.Calendar calValue, int mode, java.util.List<ValidationMessage> messages, java.lang.String validationPath)
          Compares two calendars according given mode (mode from @DateCheck).
static java.util.Calendar convertDateToCalendar(java.util.Date value, int convertType)
          Converts given date to a Calendar instance using given convertType (see DateCheck.TYPE_CONVERT_*)
static java.lang.String convertDateToString(java.util.Date date, java.lang.String pattern)
          Converts given date to a string, using given pattern.
static java.util.Date convertStringToDate(java.lang.String date, java.lang.String pattern)
          Converts given string to a date using given pattern, raises JavalidException if conversion fails
static java.math.BigDecimal getAsBigDecimal(java.lang.String value)
          Tries to convert value to BigDecimal, returns on success.
static java.math.BigInteger getAsBigInteger(java.lang.String value)
          Tries to convert value to BigInteger, returns on success.
static ValidatorCallInfo getValidatorCallInfo()
          Deprecated. Usage of this method is deprecated, if you need this info in your validator define it as a complex validator. In a next release this will be removed!
static double getValueAsDouble(java.lang.Object value)
          For given value, try to convert it to a double value and return it.
static boolean isBigMathNumber(java.lang.Object value)
          Returns true if given value is a big number (BigInteger or BigDecimal).
static boolean isEmptyString(java.lang.String value)
          Returns true if given string is either null or has a length of 0.
static boolean isNumericValue(java.lang.Object value)
          Returns true if given value is a numeric value (either as wrapper or as real primitive, which is now in a wrapper anyway).
static boolean validateForNotEmptyAnnotation(java.lang.Object value, boolean trim)
          This method validates for the @NotEmpty validation and for instance the EmptyOrNotEmpty annotation.
static boolean validationMustBeAppliedToGroup(java.lang.String[] applyToGroups, java.lang.String groupName, java.lang.String[] jvGroupNames)
          Checks given applyToGroups array on given group name or JvGroup.GROUP_APPLY_ALL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

validationMustBeAppliedToGroup

public static final boolean validationMustBeAppliedToGroup(java.lang.String[] applyToGroups,
                                                           java.lang.String groupName,
                                                           java.lang.String[] jvGroupNames)
Checks given applyToGroups array on given group name or JvGroup.GROUP_APPLY_ALL. If it matches returns true if groupName exists in the jvGroupNames array, false in all other cases.

Parameters:
applyToGroups - Contains the array of groups where to apply an annotation to
groupName - The name of the group to check for (note JvGroup.GROUP_APPLY_ALL found in the applyToGroups array will return true if groupName exists in jvGroupNames)
Returns:
True if match, false otherwise.

getValueAsDouble

public static final double getValueAsDouble(java.lang.Object value)
For given value, try to convert it to a double value and return it. Supports: If not supported raises a JvException.

Parameters:
value - The value to convert
Returns:
Value as double value

isNumericValue

public static final boolean isNumericValue(java.lang.Object value)
Returns true if given value is a numeric value (either as wrapper or as real primitive, which is now in a wrapper anyway). Valid wrappers are:

Parameters:
value - the value to check
Returns:
True if so, false otherwise.

isBigMathNumber

public static final boolean isBigMathNumber(java.lang.Object value)
Returns true if given value is a big number (BigInteger or BigDecimal).

Parameters:
value - The value to check
Returns:
True if BigInteger or BigDecimal

getAsBigInteger

public static final java.math.BigInteger getAsBigInteger(java.lang.String value)
Tries to convert value to BigInteger, returns on success. Raises JavalidException otherwise.

Parameters:
value - The value to convert
Returns:
BigInteger on success

getAsBigDecimal

public static final java.math.BigDecimal getAsBigDecimal(java.lang.String value)
Tries to convert value to BigDecimal, returns on success. Raises JavalidException otherwise.

Parameters:
value - The value to convert
Returns:
BigDecimal on success

isEmptyString

public static final boolean isEmptyString(java.lang.String value)
Returns true if given string is either null or has a length of 0.

Parameters:
value - The value to check
Returns:
True if string is null or length is 0.

getValidatorCallInfo

@Deprecated
public static final ValidatorCallInfo getValidatorCallInfo()
Deprecated. Usage of this method is deprecated, if you need this info in your validator define it as a complex validator. In a next release this will be removed!

Convenience method, which retrieves the current ValidatorInfo associated with this thread and clones it, then returns the value.

Returns:
Cloned ValidatorCallInfo instance

convertStringToDate

public static final java.util.Date convertStringToDate(java.lang.String date,
                                                       java.lang.String pattern)
Converts given string to a date using given pattern, raises JavalidException if conversion fails

Parameters:
date - The date to convert
pattern - The pattern to use
Returns:
Date
Since:
1.1

convertDateToString

public static final java.lang.String convertDateToString(java.util.Date date,
                                                         java.lang.String pattern)
Converts given date to a string, using given pattern.

Parameters:
date - Date to convert to string
pattern - The pattern to use
Returns:
Date converted as a string in given pattern

convertDateToCalendar

public static final java.util.Calendar convertDateToCalendar(java.util.Date value,
                                                             int convertType)
Converts given date to a Calendar instance using given convertType (see DateCheck.TYPE_CONVERT_*)

Parameters:
value - The value to convert to calendar
convertType - The convertType to use
Returns:
Calendar

compareCalendars

public static final void compareCalendars(int validationAnnotation,
                                          java.lang.String pattern,
                                          java.lang.String customCode,
                                          boolean globalMessage,
                                          java.util.Calendar calAnnotation,
                                          java.util.Calendar calValue,
                                          int mode,
                                          java.util.List<ValidationMessage> messages,
                                          java.lang.String validationPath)
Compares two calendars according given mode (mode from @DateCheck). Any ValidationMessages are added to the list.

Parameters:
validationAnnotation - Used to determine what error messages must be added: See AnnotationConstants.DATE_DATE_XXX
pattern - The conversion pattern to use for dates (when converting them to string on an error)
customCode - The customcode to add in a validation message (optional, can be empty)
globalMessage - Set to true if a global message must be added
calAnnotation - The annotation value that was ON the annotation
calValue - The actual value under validation (converted to a calendar)
mode - The mode to use (one of the constants on the annotation you call this method for)
messages - The messages to add to
validationPath - The current validation path

checkIsSingleExpression

public static final void checkIsSingleExpression(java.lang.String value,
                                                 java.lang.String propertyName,
                                                 java.lang.String currentPath)
Checks if given value is a single expression, see ELSupport.isExpression(java.lang.String). The 2 other parameters are information to make a sensible exception if not. Raises JavalidException if not.

Parameters:
value - The value that must be a single expression
propertyName - The name of the property
currentPath - The current path under validation

validateForNotEmptyAnnotation

public static final boolean validateForNotEmptyAnnotation(java.lang.Object value,
                                                          boolean trim)
This method validates for the @NotEmpty validation and for instance the EmptyOrNotEmpty annotation. It returns true if value is valid (non-empty), false otherwise.

Parameters:
value - The value to check
trim - True if trim must be applied to strings first
Returns:
True if non-empty, false otherwise.