org.deduced.validation.validator.rule
Class IsStringValidRule

java.lang.Object
  extended by org.deduced.rule.DeductionRuleLibrary
      extended by org.deduced.validation.validator.rule.IsStringValidRule
All Implemented Interfaces:
DeductionRuleAnalyzer<java.lang.Object>

public class IsStringValidRule
extends DeductionRuleLibrary

IsStringValidRule is used to validate a string using a minimum length, a maximum length, a flag indicating if the string can be null, a must-match regular expression and a must-not-match regular expression.

Author:
Steve McDuff

Nested Class Summary
 
Nested classes/interfaces inherited from class org.deduced.rule.DeductionRuleLibrary
DeductionRuleLibrary.CompareResult
 
Field Summary
private static int ERROR_MESSAGE_SUBSTRING_LENGTH
          length of error substrings
 
Constructor Summary
IsStringValidRule()
           
 
Method Summary
 java.lang.Object analyzeRule(java.lang.Object[] inputs, RuleExecutionContext context, PropertyCollection collection, PropertyCollection rule)
          (non-Javadoc)
private static java.lang.String checkInvalidRegularExpression(java.lang.String invalidRegularExpression, java.lang.String stringValue)
          validate String doesn't match a invalid regular expression
private static java.lang.String checkValidRegularExpression(java.lang.String validRegularExpression, java.lang.String stringValue)
          validate String match a valid regular expression
static java.lang.String fetchSubString(java.lang.String value, int maxLength)
          Fetch a sub string used during error reporting to avoid error messages that are too long.
private static java.lang.String validateMultipleLinesAllowed(java.lang.Boolean isMultipleLinesAllowed, java.lang.String stringValue)
          validate String doesn't contain multiple lines if it's not allowed.
static java.lang.String validateString(java.lang.Object value, java.lang.Integer min, java.lang.Integer max, java.lang.Boolean canBeNull, java.lang.String validRegularExpression, java.lang.String invalidRegularExpression, java.lang.Boolean isMultipleLinesAllowed)
          validate a string
private static java.lang.String validateStringMaximumLength(java.lang.Integer max, java.lang.String stringValue)
          validate String Maximum Length
private static java.lang.String validateStringMinimumLength(java.lang.Integer min, java.lang.String stringValue)
          validate String Minimum Length
 
Methods inherited from class org.deduced.rule.DeductionRuleLibrary
addReferenceToList, and, bigger, biggerOrEqual, clearPropertyCollection, createDateIncrementList, createObject, createObjectsMatchingAllValues, createObjectsMatchingAllValues, createObjectsMatchingAllValuesInOrderedList, createObjectsMatchingAllValuesInOrderedList, createOrReuseListToMatchType, debug, equals, equalTo, fillList, fillListWithSpecifiedTypes, fillOrderedList, fillOrderedListExtractMatchesValues, fillOrderedListWithSpecifiedTypes, filter, filterList, filterList, filterList, findParentOfType, formatDate, formatDate, formatTime, getModelFromCollection, getPropertyCollectionController, instanceOf, maximumCollection, maximumValue, merge, minimumCollection, minimumValue, not, or, property, removeAlreadyMatchedOrderedListValues, same, smaller, smallerOrEqual, sum, sum
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_MESSAGE_SUBSTRING_LENGTH

private static final int ERROR_MESSAGE_SUBSTRING_LENGTH
length of error substrings

See Also:
Constant Field Values
Constructor Detail

IsStringValidRule

public IsStringValidRule()
Method Detail

analyzeRule

public java.lang.Object analyzeRule(java.lang.Object[] inputs,
                                    RuleExecutionContext context,
                                    PropertyCollection collection,
                                    PropertyCollection rule)
(non-Javadoc)

Parameters:
inputs - the array of inputs
context - the rule execution context
collection - the collection on which the rule is executed
rule - the rule being executed
Returns:
the rule result
See Also:
DeductionRuleAnalyzer.analyzeRule(java.lang.Object[], org.deduced.RuleExecutionContext, org.deduced.PropertyCollection, org.deduced.PropertyCollection)

validateString

public static java.lang.String validateString(java.lang.Object value,
                                              java.lang.Integer min,
                                              java.lang.Integer max,
                                              java.lang.Boolean canBeNull,
                                              java.lang.String validRegularExpression,
                                              java.lang.String invalidRegularExpression,
                                              java.lang.Boolean isMultipleLinesAllowed)
validate a string

Parameters:
value - the current string value
min - the string minimum length. If null, the string doesn't need to respect a minimum length.
max - the string maximum length. If null, the string doesn't need to respect a maximum length.
canBeNull - flag indicating if the string is allowed to be null.
validRegularExpression - the regular expression to match to be valid.
invalidRegularExpression - the regular expression that must not be matched to be valid.
isMultipleLinesAllowed - option to indicate if multiple lines are allowed
Returns:
the error message that occurred during string validation. Null if the string is considered valid.

validateMultipleLinesAllowed

private static java.lang.String validateMultipleLinesAllowed(java.lang.Boolean isMultipleLinesAllowed,
                                                             java.lang.String stringValue)
validate String doesn't contain multiple lines if it's not allowed.

Parameters:
isMultipleLinesAllowed - option if multiple lines are allowed
stringValue - the string value
Returns:
the error message if the validation check failed

checkInvalidRegularExpression

private static java.lang.String checkInvalidRegularExpression(java.lang.String invalidRegularExpression,
                                                              java.lang.String stringValue)
validate String doesn't match a invalid regular expression

Parameters:
invalidRegularExpression - the invalid regular expression
stringValue - the string value
Returns:
the error message if the validation check failed

checkValidRegularExpression

private static java.lang.String checkValidRegularExpression(java.lang.String validRegularExpression,
                                                            java.lang.String stringValue)
validate String match a valid regular expression

Parameters:
validRegularExpression - the valid regular expression
stringValue - the string value
Returns:
the error message if the validation check failed

validateStringMaximumLength

private static java.lang.String validateStringMaximumLength(java.lang.Integer max,
                                                            java.lang.String stringValue)
validate String Maximum Length

Parameters:
max - the Maximum length
stringValue - the string value
Returns:
the error message if the validation check failed

validateStringMinimumLength

private static java.lang.String validateStringMinimumLength(java.lang.Integer min,
                                                            java.lang.String stringValue)
validate String Minimum Length

Parameters:
min - the minimum length
stringValue - the string value
Returns:
the error message if the validation check failed

fetchSubString

public static java.lang.String fetchSubString(java.lang.String value,
                                              int maxLength)
Fetch a sub string used during error reporting to avoid error messages that are too long. If the string is too long, the maximum length is split in 2 and the resulting string will show the beginning and the ending of the string split by a "..."

Parameters:
value - the string value
maxLength - the maximum string length that can be returned
Returns:
the new string value respecting the maximum length.