Class DefaultAnnotationValidator
- All Implemented Interfaces:
AnnotationValidatior
Implementation of AnnotationValidatior used by AnnotationValidationInterceptor2.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDescribes the result of a attempting to convert from a string to the generic type, and the field to receive it, successful or not.static classThread local execution state of algorithm about a field.static classThread local execution state of algorithm. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcategoriseFields(Collection<Field> formFields) Sets how form fields should be converted (InterceptorContext setting property set 4).protected <T> voidChecks if collection conversion results means a message must be written and writes appropriate type if needed.protected <T> voidChecks if conversion results means a message must be written and writes appropriate type if needed.protected <T> voidChecks if conversion results means a message must be written and writes appropriate type if needed.protected <T> voidChecks if non-conversion validation results means a message must be written and writes appropriate type if needed.protected <T> voidChecks if conversion results means a message must be written and writes appropriate type if needed.protected <T> voidCalled when processing of a form field is complete.protected voidCalled when this interceptor completes (and is not disabled).protected voidDoes not nothing and is a placeholder called aftercategoriseFields.protected Collection<Field> filterFormFieldsPreCategorise(Collection<Field> formFields) Returns form fields except those that should be skipped before any policy annotations are analysed.protected voidRemoves rejected request parameters from the allowed request parameters (property set 3), which are those that exceed max parameter length or fail filter if Action implements ParameterNameAware.protected StringgetDefaultMessage(String recipientFieldName, Class<?> recipientClass) Returns error message if a default converter fails.Returns default target for writing or logging conversion and validation failures.protected Collection<Field> getFormFields(Collection<Field> allFields) Returns form member fields that can plausibly receive form data.booleanReturns whether form fields with no recognised annotations are ignored..protected StringgetMessage(TextProvider textProvider, String messageKey, String message) Returns message to use, extracted from text provider if required.protected Required.MessageTypeReturns target type for conversion and validation failures if annotation uses default type.intReturns maximum length of parameters that can be accepted.Returns policy lookup by annotation helper used in validation.protected Collection<Field> getProperties(Class<?> type) Returns all form fields of defined by form class.protected Fieldprotected org.apache.logging.log4j.LoggergetValidationLogger(ActionInvocation invocation, Object action) Returns Log4j2 logger to use for conversion and validation failures.protected voidignoreMessage(org.apache.logging.log4j.Logger logger, String message) Called when an error message is to be ignored.protected voidlogDebugMessage(org.apache.logging.log4j.Logger validationLogger, String message) Logs message to Action's logger at DEBUG level.protected voidlogErrorMessage(org.apache.logging.log4j.Logger validationLogger, String message) Logs message to Action's logger at ERROR level.protected voidlogInfoMessage(org.apache.logging.log4j.Logger validationLogger, String message) Logs message to Action's logger at INFO level.protected voidlogTraceMessage(org.apache.logging.log4j.Logger validationLogger, String message) Logs message to Action's logger at TRACE level.protected voidlogWarnMessage(org.apache.logging.log4j.Logger validationLogger, String message) Logs message to Action's logger at WARN level.protected <T> Collection<T> makeCollectionForRecipient(Class<?> recipientFieldClass) Returns an empty collection to set the recipient field and will accept converted values.protected <T> DefaultAnnotationValidator.FieldContext<T> Returns an initial execution state about a field.Returns an initial execution state.protected <T> voidInvokes adjuster, updates FieldContext formattedValue property, and updates form field for no conversion and pair conversion modes.protected <T> voidHandles aftermath of a form field failing the conversion step, which is writing a conversion error for auto and default conversion mode, or leaving the field as is for no conversion and pair conversion mode.protected <T> voidInvokes collection converter, sets field (non-string collection for pair conversion), sets FieldContext conversionResult property and writes error message if needed; or sets FieldContext conversionResult property to skipped collection if the adjusted formatted value is empty string.protected <T> voidInvokes post-conversion adjuster, sets field (non-string for pair conversion), and sets FieldContext parsedCollectionValue property; or does nothing if the converted value is null and adjuster skips them.protected <T> voidHandles aftermath of a form field that failed the post-conversion validation step, which is nothing as error messages are already written.protected <T> voidInvokes collection post-conversion validator, sets FieldContext validationResult property and writes error message if needed; or sets FieldContext validationResult property to success if the converted value is null and validator skips them.protected <T> voidHandles aftermath of a form field failing the conversion step, which is writing a conversion error for auto and default conversion mode, or leaving the field as is for no conversion and pair conversion mode.protected <T> voidInvokes converter, sets field (non-string for pair conversion), sets FieldContext conversionResult property and writes error message if needed; or sets FieldContext conversionResult property to skipped if the adjusted formatted value is empty string.protected voidSets File form field from special file parameter created by FileUplodIntereceptor, for file conversion mode.protected <T> voidSets, adjusts, converts and validates a form field from a request parameter according to its conversion mode.protected voidCalls form to process request parameters not handled by other form fields and writes parameters that failed as conversion errors.protected <T> voidHandles aftermath of a form field failing the non-conversion validation step, which is writing a conversion error for auto and default conversion mode, or leaving the field as is for no conversion and pair conversion mode.protected <T> voidInvokes non-conversion validator, sets FieldContext validationResult property and writes error message if needed; or sets FieldContext validationResult property to success if the adjusted formatted value is empty string and validator skips them.protected <T> voidInvokes post-conversion adjuster, sets field (non-string for pair conversion), and sets FieldContext parsedValue property; or does nothing if the converted value is null and adjuster skips them.protected <T> voidHandles aftermath of a form field that failed the post-conversion validation step, which is nothing as error messages are already written.protected <T> voidInvokes post-conversion validator, sets FieldContext validationResult property and writes error message if needed; or sets FieldContext validationResult property to success if the converted value is null and validator skips them.protected voidSets string field, string array or string collection form field for set only conversion mode.voidsetDefaultMessageType(Required.MessageType defaultMessageType) voidsetIgnoreNonAnnotatedFields(boolean ignoreNonAnnotatedFields) voidsetParamNameMaxLength(int paramNameMaxLength) voidsetPolicyLookup(PolicyLookup policyLookup) protected <T> voidstartFieldContext(DefaultAnnotationValidator.FieldContext.ConversionMode conversionMode, Parameter parameter, InterceptorCommonLibrary.FieldUsage<T> fieldUsage, InterceptorCommonLibrary.PairFieldUsage<T> pairFieldUsage) Called when algorithm is about to start for a field in earnest and sets FieldContext property set 2.protected voidstartInterceptorContext(ActionInvocation invocation) Called when algorithm is about to start in earnest and sets InterceptorContext property set 2.protected voidSets interceptor context's request parameters as a mutable copy.voidvalidate()Entry point called byAnnotationValidationInterceptor2.protected voidInitialisation that needs to be done before main logic of validate is run.protected voidwriteFieldError(ValidationAware validationAware, String fieldName, String message) Writes message to Action's field errors for field.protected voidwriteGeneralError(ValidationAware validationAware, String message) Writes message to Action's action errors.protected voidwriteInfoMessage(ValidationAware validationAware, String message) Writes message to Action's action messages.protected voidwriteWarningMessage(ValidationAware validationAware, String message) Writes message to Action's action warnings.
-
Constructor Details
-
DefaultAnnotationValidator
public DefaultAnnotationValidator()
-
-
Method Details
-
categoriseFields
Sets how form fields should be converted (InterceptorContext setting property set 4).
Can access InterceptorContext property set 3 and lower.
-
checkCollectionConversionMessage
protected <T> void checkCollectionConversionMessage()Checks if collection conversion results means a message must be written and writes appropriate type if needed.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
checkCollectionPostConversionMessage
protected <T> void checkCollectionPostConversionMessage()Checks if conversion results means a message must be written and writes appropriate type if needed.Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
checkConversionMessage
protected <T> void checkConversionMessage()Checks if conversion results means a message must be written and writes appropriate type if needed.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
checkNonConversionMessage
protected <T> void checkNonConversionMessage()Checks if non-conversion validation results means a message must be written and writes appropriate type if needed.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
checkPostConversionMessage
protected <T> void checkPostConversionMessage()Checks if conversion results means a message must be written and writes appropriate type if needed.Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
endFieldContext
protected <T> void endFieldContext()Called when processing of a form field is complete. Just sets end state and really exists for extending subclasses. -
endInterceptorContext
protected void endInterceptorContext()Called when this interceptor completes (and is not disabled). Does nothing and really exists for extending subclasses. -
filterFormFieldsPreCategorise
Returns form fields except those that should be skipped before any policy annotations are analysed. Skips none and exists for extending subclasses.
Can access InterceptorContext property set 3 and lower.
-
filterFormFieldsPostCategorise
protected void filterFormFieldsPostCategorise()Does not nothing and is a placeholder called after
categoriseFields.Can access InterceptorContext property set 4 and lower.
-
filterRequestParameters
protected void filterRequestParameters()Removes rejected request parameters from the allowed request parameters (property set 3), which are those that exceed max parameter length or fail filter if Action implements ParameterNameAware.
Can access InterceptorContext property set 3 and lower.
-
getDefaultMessage
Returns error message if a default converter fails.Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
getFormFields
Returns form member fields that can plausibly receive form data. This excludes static and final fields.
Can access InterceptorContext property set 3 and lower.
-
getMessage
Returns message to use, extracted from text provider if required. textProvider can be null if Action does not implement it.Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
getMessageTypeForDefault
Returns target type for conversion and validation failures if annotation uses default type.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
getProperties
Returns all form fields of defined by form class.
Can access InterceptorContext property set 3 and lower.
-
getRecipientFieldForConversionMode
-
getValidationLogger
protected org.apache.logging.log4j.Logger getValidationLogger(ActionInvocation invocation, Object action) Returns Log4j2 logger to use for conversion and validation failures. Uses Action's
AbstractActionSupport.getLogger()if it exists, otherwise this classes logger. Cannot return null.Can access InterceptorContext property set 1.
-
ignoreMessage
Called when an error message is to be ignored. -
logDebugMessage
Logs message to Action's logger at DEBUG level. -
logErrorMessage
Logs message to Action's logger at ERROR level. -
logInfoMessage
Logs message to Action's logger at INFO level. -
logTraceMessage
Logs message to Action's logger at TRACE level. -
logWarnMessage
Logs message to Action's logger at WARN level. -
makeCollectionForRecipient
Returns an empty collection to set the recipient field and will accept converted values.Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
makeFieldContext
Returns an initial execution state about a field. -
makeInterceptorContext
Returns an initial execution state. -
processAdjuster
Invokes adjuster, updates FieldContext formattedValue property, and updates form field for no conversion and pair conversion modes.
Can access all InterceptorContext properties and FieldContext property set 3 and lower.
-
processCollectionConverter
protected <T> void processCollectionConverter()Invokes collection converter, sets field (non-string collection for pair conversion), sets FieldContext conversionResult property and writes error message if needed; or sets FieldContext conversionResult property to skipped collection if the adjusted formatted value is empty string.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
processCollectionConversionRejection
protected <T> void processCollectionConversionRejection()Handles aftermath of a form field failing the conversion step, which is writing a conversion error for auto and default conversion mode, or leaving the field as is for no conversion and pair conversion mode.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
processCollectionPostConversionAdjuster
protected <T> void processCollectionPostConversionAdjuster()Invokes post-conversion adjuster, sets field (non-string for pair conversion), and sets FieldContext parsedCollectionValue property; or does nothing if the converted value is null and adjuster skips them.
Can access all InterceptorContext properties and FieldContext property set 5 and lower.
-
processCollectionPostConversionValidator
protected <T> void processCollectionPostConversionValidator()Invokes collection post-conversion validator, sets FieldContext validationResult property and writes error message if needed; or sets FieldContext validationResult property to success if the converted value is null and validator skips them.
Can access all InterceptorContext properties and FieldContext property set 5 and lower.
-
processCollectionPostConversionRejection
protected <T> void processCollectionPostConversionRejection()Handles aftermath of a form field that failed the post-conversion validation step, which is nothing as error messages are already written.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
processConverter
protected <T> void processConverter()Invokes converter, sets field (non-string for pair conversion), sets FieldContext conversionResult property and writes error message if needed; or sets FieldContext conversionResult property to skipped if the adjusted formatted value is empty string.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
processConversionRejection
protected <T> void processConversionRejection()Handles aftermath of a form field failing the conversion step, which is writing a conversion error for auto and default conversion mode, or leaving the field as is for no conversion and pair conversion mode.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
processFileFormField
Sets File form field from special file parameter created by FileUplodIntereceptor, for file conversion mode.
Can access all InterceptorContext properties and FieldContext property set 2 and lower.
-
processFormField
Sets, adjusts, converts and validates a form field from a request parameter according to its conversion mode. Not called for set only conversion mode.
Can access all InterceptorContext properties and FieldContext property set 2 and lower.
-
processManualConversionFormFields
protected void processManualConversionFormFields()Calls form to process request parameters not handled by other form fields and writes parameters that failed as conversion errors. Does nothing if the form doesn't implement
Form.Can access all InterceptorContext properties.
-
processNonConversionRejection
protected <T> void processNonConversionRejection()Handles aftermath of a form field failing the non-conversion validation step, which is writing a conversion error for auto and default conversion mode, or leaving the field as is for no conversion and pair conversion mode.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
processNonConversionValidator
protected <T> void processNonConversionValidator()Invokes non-conversion validator, sets FieldContext validationResult property and writes error message if needed; or sets FieldContext validationResult property to success if the adjusted formatted value is empty string and validator skips them.
Can access all InterceptorContext properties and FieldContext property set 3 and lower.
-
processPostConversionRejection
protected <T> void processPostConversionRejection()Handles aftermath of a form field that failed the post-conversion validation step, which is nothing as error messages are already written.
Can access all InterceptorContext properties and FieldContext property set 4 and lower.
-
processPostConversionAdjuster
protected <T> void processPostConversionAdjuster()Invokes post-conversion adjuster, sets field (non-string for pair conversion), and sets FieldContext parsedValue property; or does nothing if the converted value is null and adjuster skips them.
Can access all InterceptorContext properties and FieldContext property set 5 and lower.
-
processPostConversionValidator
protected <T> void processPostConversionValidator()Invokes post-conversion validator, sets FieldContext validationResult property and writes error message if needed; or sets FieldContext validationResult property to success if the converted value is null and validator skips them.
Can access all InterceptorContext properties and FieldContext property set 5 and lower.
-
processSetOnlyFormField
Sets string field, string array or string collection form field for set only conversion mode.
Can access all InterceptorContext properties and FieldContext property set 2 and lower.
-
startFieldContext
protected <T> void startFieldContext(DefaultAnnotationValidator.FieldContext.ConversionMode conversionMode, Parameter parameter, InterceptorCommonLibrary.FieldUsage<T> fieldUsage, InterceptorCommonLibrary.PairFieldUsage<T> pairFieldUsage) Called when algorithm is about to start for a field in earnest and sets FieldContext property set 2. -
startInterceptorContext
Called when algorithm is about to start in earnest and sets InterceptorContext property set 2. -
updateRequestParameters
protected void updateRequestParameters()Sets interceptor context's request parameters as a mutable copy.
Can access InterceptorContext property set 2 and lower.
-
validateInit
protected void validateInit()Initialisation that needs to be done before main logic of validate is run. -
writeFieldError
Writes message to Action's field errors for field. ValidationAware can be null if Action does not implement it. -
writeGeneralError
Writes message to Action's action errors. ValidationAware can be null if Action does not implement it. -
writeInfoMessage
Writes message to Action's action messages. ValidationAware can be null if Action does not implement it. -
writeWarningMessage
Writes message to Action's action warnings. ValidationAware can be null if Action does not implement it. -
getDefaultMessageType
Returns default target for writing or logging conversion and validation failures. Cannot return DEFAULT or null. -
setDefaultMessageType
-
getIgnoreNonAnnotatedFields
public boolean getIgnoreNonAnnotatedFields()Returns whether form fields with no recognised annotations are ignored.. -
setIgnoreNonAnnotatedFields
public void setIgnoreNonAnnotatedFields(boolean ignoreNonAnnotatedFields) -
getParamNameMaxLength
public int getParamNameMaxLength()Returns maximum length of parameters that can be accepted. Defaults to 100. -
setParamNameMaxLength
public void setParamNameMaxLength(int paramNameMaxLength) -
getPolicyLookup
Returns policy lookup by annotation helper used in validation. -
setPolicyLookup
-
validate
public void validate()Entry point called byAnnotationValidationInterceptor2.- Specified by:
validatein interfaceAnnotationValidatior
-