Class Validator

  • Direct Known Subclasses:
    GeometryValidator, MetadataValidator, NameValidator, ReferencingValidator

    public abstract class Validator
    extends java.lang.Object
    Base class of all GeoAPI validators. Validators can be configured on a case-by-case basis by changing the values of non-final public fields. If the same configuration needs to be applied on all validators, then ValidatorContainer.all provides a convenient way to make such change in a loop.

    Once the configuration is finished, all validators provided in GeoAPI are thread-safe provided that their configuration is not modified.

    Since:
    2.2
    Version:
    3.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected ValidatorContainer container
      The container of this validator.
      protected static double DEFAULT_TOLERANCE
      The default tolerance value for comparisons of floating point numbers.
      boolean enforceForbiddenAttributes
      true if forbidden attributes are required to be null, or false for tolerating non-null values.
      protected java.util.logging.Logger logger
      The logger for reporting non-fatal warnings.
      boolean requireMandatoryAttributes
      true if mandatory attributes are required to be non-null, or false for tolerating null values.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Validator​(ValidatorContainer container, java.lang.String packageName)
      Creates a new validator instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void forbidden​(java.lang.String message, java.lang.Object value)
      Invoked when the existence of a forbidden attribute needs to be checked.
      protected void mandatory​(java.lang.String message, java.lang.Object value)
      Invoked when the existence of a mandatory attribute needs to be verified.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_TOLERANCE

        protected static final double DEFAULT_TOLERANCE
        The default tolerance value for comparisons of floating point numbers.
        See Also:
        Constant Field Values
      • container

        protected final ValidatorContainer container
        The container of this validator.
      • logger

        protected final java.util.logging.Logger logger
        The logger for reporting non-fatal warnings.
      • requireMandatoryAttributes

        public boolean requireMandatoryAttributes
        true if mandatory attributes are required to be non-null, or false for tolerating null values. ISO specifications flags some attributes as mandatory, while some other are optional. Optional attributes are allowed to be null at any time, but mandatory attributes shall never be null - in theory. However implementors may choose to returns null on a temporary basis while they are developing their library. If this field is set to false, then missing mandatory attributes will be logged as warnings instead than causing a failure.

        The default value is true.

        See Also:
        mandatory(java.lang.String, java.lang.Object)
      • enforceForbiddenAttributes

        public boolean enforceForbiddenAttributes
        true if forbidden attributes are required to be null, or false for tolerating non-null values. In ISO specifications, some attributes are declared as optional in parent class and specialized in subclasses, either as mandatory or as forbidden. If this field is set to false, then forbidden attributes will be logged as warnings instead than causing a failure.

        The default value is true.

        See Also:
        forbidden(java.lang.String, java.lang.Object)
    • Constructor Detail

      • Validator

        protected Validator​(ValidatorContainer container,
                            java.lang.String packageName)
        Creates a new validator instance.
        Parameters:
        container - The container of this validator.
        packageName - The name of the package containing the classes to be validated.
    • Method Detail

      • mandatory

        protected void mandatory​(java.lang.String message,
                                 java.lang.Object value)
        Invoked when the existence of a mandatory attribute needs to be verified. If the given value is null, then there is a choice:
        • If requireMandatoryAttributes is true (which is the default), then the test fails with the given message.
        • Otherwise, the message is logged as a warning and the test continues.

        Subclasses can override this method if they want more control.

        Parameters:
        message - The message to send in case of failure.
        value - The value to test for non-nullity.
        See Also:
        requireMandatoryAttributes
      • forbidden

        protected void forbidden​(java.lang.String message,
                                 java.lang.Object value)
        Invoked when the existence of a forbidden attribute needs to be checked. If the given value is non-null, then there is a choice:
        • If enforceForbiddenAttributes is true (which is the default), then the test fails with the given message.
        • Otherwise, the message is logged as a warning and the test continues.

        Subclasses can override this method if they want more control.

        Parameters:
        message - The message to send in case of failure.
        value - The value to test for nullity.
        See Also:
        enforceForbiddenAttributes