Class Validator
- Object
 - 
- Validator
 
 
- 
- Direct Known Subclasses:
 GeometryValidator,ImageValidator,MetadataValidator,NameValidator,ReferencingValidator
public abstract class Validator extends 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, thenValidatorContainer.allprovides a convenient way to make such change in a loop.Configurations available in this class and some subclasses are:
requireMandatoryAttributes- controls whether unexpected null values can be tolerated.enforceForbiddenAttributes- controls whether unexpected non-null values can be tolerated.CRSValidator.enforceStandardNames- controls whether axis names shall be restricted to ISO standards.
Once the configuration is finished, all validators provided in GeoAPI are thread-safe provided that their configuration is not modified.
- Since:
 - 2.2
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected ValidatorContainercontainerThe validators to use for every validations not defined in the concrete subclass.static doubleDEFAULT_TOLERANCEThe default tolerance value for comparisons of floating point numbers in validators.booleanenforceForbiddenAttributestrueif forbidden attributes are required to be null, orfalsefor tolerating non-null values.protected LoggerloggerThe logger for reporting non-fatal warnings.booleanrequireMandatoryAttributestrueif mandatory attributes are required to be non-null, orfalsefor tolerating null values. 
- 
Constructor Summary
Constructors Modifier Constructor Description protectedValidator(ValidatorContainer container, String packageName)Creates a new validator instance. 
- 
Method Summary
Modifier and Type Method Description protected voidconditional(String message, Object value, boolean condition)Delegates tomandatory(String, Object)orforbidden(String, Object)depending on a condition.protected voidforbidden(String message, Object value)Invoked when the existence of a forbidden attribute needs to be checked.protected voidmandatory(String message, Object value)Invoked when the existence of a mandatory attribute needs to be verified.protected voidvalidate(Collection<?> collection)Ensures that the elements in the given collection are compliant with theObjectequals(Object)andhashCode()contract. 
 - 
 
- 
- 
Field Detail
- 
DEFAULT_TOLERANCE
public static final double DEFAULT_TOLERANCE
The default tolerance value for comparisons of floating point numbers in validators. The current value is 1.0E-6. This value is relatively large because some implementations may store their values asfloatnumbers instead thandouble.Note that
TestCasesubclasses use smaller tolerance thresholds, typically centimetric. Test cases are stricter then validators because the tests control the objects they create, while validators need to work reasonably well for arbitrary objects.- See Also:
 GeometryValidator.tolerance, Constant Field Values
 
- 
container
protected final ValidatorContainer container
The validators to use for every validations not defined in the concrete subclass. For example ifCRSValidatorneeds to validate a datum, it will use theDatumValidatorinstance defined in this container.The container may contain this validator instance. For example if this validator is an instance of
CRSValidator, then theValidatorContainer.crsfield may be set tothis. Doing so ensure that the propervalidate(…)methods will be invoked in case of callback.Tip: if the other validators are not expected to callback the
validatemethods defined in thisValidatorinstance (for example a datum has no reason to validate a CRS), then it is safe to set this field toValidators.DEFAULT. 
- 
logger
protected final Logger logger
The logger for reporting non-fatal warnings. This logger is determined by the package name given at construction time. 
- 
requireMandatoryAttributes
public boolean requireMandatoryAttributes
trueif mandatory attributes are required to be non-null, orfalsefor 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 returnsnullon a temporary basis while they are developing their library. If this field is set tofalse, then missing mandatory attributes will be logged as warnings instead than causing a failure.The default value is
true.- See Also:
 mandatory(String, Object)
 
- 
enforceForbiddenAttributes
public boolean enforceForbiddenAttributes
trueif forbidden attributes are required to be null, orfalsefor 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 tofalse, then forbidden attributes will be logged as warnings instead than causing a failure.The default value is
true.- See Also:
 forbidden(String, Object)
 
 - 
 
- 
Constructor Detail
- 
Validator
protected Validator(ValidatorContainer container, String packageName)
Creates a new validator instance.- Parameters:
 container- the set of validators to use for validating other kinds of objects (see field javadoc).packageName- the name of the package containing the classes to be validated.
 
 - 
 
- 
Method Detail
- 
mandatory
protected void mandatory(String message, Object value)
Invoked when the existence of a mandatory attribute needs to be verified. If the given value isnullor is an empty collection, then there is a choice:- If 
requireMandatoryAttributesistrue(which is the default), then the test fails with the given message. - Otherwise, the message is logged as a warning and the test continues.
 
- Parameters:
 message- the message to send in case of failure.value- the value to test for non-nullity.- See Also:
 requireMandatoryAttributes,Obligation.MANDATORY
 - If 
 
- 
forbidden
protected void forbidden(String message, Object value)
Invoked when the existence of a forbidden attribute needs to be checked. If the given value is non-null and is not an empty collection, then there is a choice:- If 
enforceForbiddenAttributesistrue(which is the default), then the test fails with the given message. - Otherwise, the message is logged as a warning and the test continues.
 
- Parameters:
 message- the message to send in case of failure.value- the value to test for nullity.- See Also:
 enforceForbiddenAttributes,Obligation.FORBIDDEN
 - If 
 
- 
conditional
protected void conditional(String message, Object value, boolean condition)
Delegates tomandatory(String, Object)orforbidden(String, Object)depending on a condition.- Parameters:
 message- the message to send in case of failure.value- the value to test for (non)-nullity.condition-trueif the given value is mandatory, orfalseif it is forbidden.- See Also:
 Obligation.CONDITIONAL
 
- 
validate
protected void validate(Collection<?> collection)
Ensures that the elements in the given collection are compliant with theObjectequals(Object)andhashCode()contract. This method ensures that theequals(Object)methods implement reflexive, symmetric and transitive relations. It also ensures that ifA.equals(B), thenA.hashCode() == B.hashCode().If the given collection is null, then this method does nothing. If the given collection contains null elements, then those elements are ignored.
This method does not invoke any other
validatemethod on collection elements. It is caller responsibility to validates elements according their types.- Parameters:
 collection- the collection of elements to validate, ornull.- Since:
 - 3.1
 
 
 - 
 
 -