Class DefaultAnnotationValidatior
- All Implemented Interfaces:
AnnotationValidatior
Implementation of AnnotationValidatior
used by AnnotationValidationInterceptor2
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Describes the result of a attempting to convert from a string to the generic type, and the field to receive it, successful or not.static class
Thread local execution state of algorithm about a field.static class
Thread local execution state of algorithm. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
categoriseFields
(Collection<Field> formFields) Sets how form fields should be converted (InterceptorContext setting property set 4).protected <T> void
Checks if collection conversion results means a message must be written and writes appropriate type if needed.protected <T> void
Checks if conversion results means a message must be written and writes appropriate type if needed.protected <T> void
Checks if conversion results means a message must be written and writes appropriate type if needed.protected <T> void
Checks if non-conversion validation results means a message must be written and writes appropriate type if needed.protected <T> void
Checks if conversion results means a message must be written and writes appropriate type if needed.protected <T> void
Called when processing of a form field is complete.protected void
Called when this interceptor completes (and is not disabled).protected void
Removes form fields that should be skipped due to policy annotations, which, if processUnreferencedFields is not set, are any not set by a parameter and have no policy annotations.protected Collection
<Field> filterFormFieldsPreCategorise
(Collection<Field> formFields) Returns form fields except those that should be skipped before any policy annotations are analysed.protected void
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.protected String
getDefaultMessage
(String recipientFieldName, Class<?> recipientClass) Returns error message if a default converter fails.protected Collection
<Field> getFormFields
(Collection<Field> allFields) Returns form member fields that can plausibly receive form data.protected String
getMessage
(com.opensymphony.xwork2.TextProvider textProvider, String messageKey, String message) Returns message to use, extracted from text provider if required.int
Returns maximum length of parameters that can be accepted.boolean
Returns whether fields with no policy annotations and not set by a parameter are processed, rather than skipped.protected Collection
<Field> getProperties
(Class<?> type) Returns all form fields of defined by form class.protected Field
protected <T> Collection
<T> makeCollectionForRecipient
(Class<?> recipientFieldClass) Returns an empty collection to set the recipient field and will accept converted values.protected <T> DefaultAnnotationValidatior.FieldContext
<T> Returns an initial execution state about a field.Returns an initial execution state.protected <T> void
Invokes adjuster, updates FieldContext formattedValue property, and updates form field for no conversion and pair conversion modes.protected <T> void
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.protected <T> void
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.protected <T> void
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.protected <T> void
Handles aftermath of a form field that failed the post-conversion validation step, which is nothing as error messages are already written.protected <T> void
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.protected <T> void
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.protected <T> void
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.protected void
Sets File form field from special file parameter created by FileUplodIntereceptor, for file conversion mode.protected <T> void
Sets, adjusts, converts and validates a form field from a request parameter according to its conversion mode.protected void
Calls form to process request parameters not handled by other form fields and writes parameters that failed as conversion errors.protected <T> void
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.protected <T> void
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.protected <T> void
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.protected <T> void
Handles aftermath of a form field that failed the post-conversion validation step, which is nothing as error messages are already written.protected <T> void
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.protected void
Sets string field, string array or string collection form field for set only conversion mode.void
setParamNameMaxLength
(int paramNameMaxLength) void
setProcessUnreferencedFields
(boolean processUnreferencedFields) protected <T> void
startFieldContext
(DefaultAnnotationValidatior.FieldContext.ConversionMode conversionMode, org.apache.struts2.dispatcher.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 void
startInterceptorContext
(com.opensymphony.xwork2.ActionInvocation invocation) Called when algorithm is about to start in earnest and sets InterceptorContext property set 2.protected void
Sets interceptor context's request parameters as a mutable copy.void
validate()
Entry point called byAnnotationValidationInterceptor2
.protected void
writeFieldError
(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String fieldName, String message) Writes message to Action's field errors for field.protected void
writeGeneralError
(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String message) Writes message to Action's action errors.protected void
writeInfoMessage
(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String message) Writes message to Action's action messages.protected void
writeWarningMessage
(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String message) Writes message to Action's action warnings.
-
Constructor Details
-
DefaultAnnotationValidatior
public DefaultAnnotationValidatior()
-
-
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()Removes form fields that should be skipped due to policy annotations, which, if processUnreferencedFields is not set, are any not set by a parameter and have no policy annotations.
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
protected String getMessage(com.opensymphony.xwork2.TextProvider textProvider, String messageKey, String message) 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.
-
getProperties
Returns all form fields of defined by form class.
Can access InterceptorContext property set 3 and lower.
-
getRecipientFieldForConversionMode
-
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(DefaultAnnotationValidatior.FieldContext.ConversionMode conversionMode, org.apache.struts2.dispatcher.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
protected void startInterceptorContext(com.opensymphony.xwork2.ActionInvocation invocation) 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.
-
writeFieldError
protected void writeFieldError(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String fieldName, String message) Writes message to Action's field errors for field. ValidationAware can be null if Action does not implement it. -
writeGeneralError
protected void writeGeneralError(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String message) Writes message to Action's action errors. ValidationAware can be null if Action does not implement it. -
writeInfoMessage
protected void writeInfoMessage(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String message) Writes message to Action's action messages. ValidationAware can be null if Action does not implement it. -
writeWarningMessage
protected void writeWarningMessage(com.opensymphony.xwork2.interceptor.ValidationAware validationAware, String message) Writes message to Action's action warnings. ValidationAware can be null if Action does not implement it. -
getParamNameMaxLength
public int getParamNameMaxLength()Returns maximum length of parameters that can be accepted. Defaults to 100. -
setParamNameMaxLength
public void setParamNameMaxLength(int paramNameMaxLength) -
getProcessUnreferencedFields
public boolean getProcessUnreferencedFields()Returns whether fields with no policy annotations and not set by a parameter are processed, rather than skipped. -
setProcessUnreferencedFields
public void setProcessUnreferencedFields(boolean processUnreferencedFields) -
validate
public void validate()Entry point called byAnnotationValidationInterceptor2
.- Specified by:
validate
in interfaceAnnotationValidatior
-