Class DefaultAnnotationValidatior

java.lang.Object
name.matthewgreet.strutscommons.util.DefaultAnnotationValidatior
All Implemented Interfaces:
AnnotationValidatior

public class DefaultAnnotationValidatior extends Object implements AnnotationValidatior
  • Constructor Details

    • DefaultAnnotationValidatior

      public DefaultAnnotationValidatior()
  • Method Details

    • categoriseFields

      protected void categoriseFields(Collection<Field> formFields)

      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

      protected Collection<Field> filterFormFieldsPreCategorise(Collection<Field> formFields)

      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

      protected String getDefaultMessage(String recipientFieldName, Class<?> recipientClass)
      Returns error message if a default converter fails.

      Can access all InterceptorContext properties and FieldContext property set 4 and lower.

    • getFormFields

      protected Collection<Field> getFormFields(Collection<Field> allFields)

      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(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

      protected Collection<Field> getProperties(Class<?> type)

      Returns all form fields of defined by form class.

      Can access InterceptorContext property set 3 and lower.

    • getRecipientFieldForConversionMode

      protected Field getRecipientFieldForConversionMode()
    • makeCollectionForRecipient

      protected <T> Collection<T> makeCollectionForRecipient(Class<?> recipientFieldClass)
      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

      protected <T> DefaultAnnotationValidatior.FieldContext<T> makeFieldContext()
      Returns an initial execution state about a field.
    • makeInterceptorContext

      protected DefaultAnnotationValidatior.InterceptorContext makeInterceptorContext()
      Returns an initial execution state.
    • processAdjuster

      protected <T> void processAdjuster() throws IllegalArgumentException, IllegalAccessException

      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.

      Throws:
      IllegalArgumentException
      IllegalAccessException
    • 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

      protected void processFileFormField() throws IllegalArgumentException, IllegalAccessException

      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.

      Throws:
      IllegalArgumentException
      IllegalAccessException
    • processFormField

      protected <T> void processFormField() throws IllegalArgumentException, IllegalAccessException

      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.

      Throws:
      IllegalArgumentException
      IllegalAccessException
    • 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

      protected void processSetOnlyFormField() throws IllegalArgumentException, IllegalAccessException

      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.

      Throws:
      IllegalArgumentException
      IllegalAccessException
    • startFieldContext

      protected <T> void startFieldContext(DefaultAnnotationValidatior.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

      protected void startInterceptorContext(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.

    • validateInit

      protected void validateInit()
      Initialisation that needs to be done before main logic of validate is run.
    • writeFieldError

      protected void writeFieldError(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(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(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(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)
    • getPolicyLookup

      public PolicyLookup getPolicyLookup()
      Returns policy lookup by annotation helper used in validation.
    • setPolicyLookup

      public void setPolicyLookup(PolicyLookup policyLookup)
    • 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 by AnnotationValidationInterceptor2.
      Specified by:
      validate in interface AnnotationValidatior