Module dev.metaschema.core
Class DefaultConstraintValidator
java.lang.Object
dev.metaschema.core.model.constraint.DefaultConstraintValidator
- All Implemented Interfaces:
IConfiguration<ValidationFeature<?>>,IMutableConfiguration<ValidationFeature<?>>,IConstraintValidator,AutoCloseable
public class DefaultConstraintValidator
extends Object
implements IConstraintValidator, IMutableConfiguration<ValidationFeature<?>>
Used to perform constraint validation over one or more node items.
This class is thread-safe and can be used with parallel constraint validation.
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new constraint validation instance with sequential execution.DefaultConstraintValidator(IConstraintValidationHandler handler, ParallelValidationConfig parallelConfig) Construct a new constraint validation instance with configurable parallelism. -
Method Summary
Modifier and TypeMethodDescription@Owning DefaultConstraintValidatorapplyConfiguration(IConfiguration<ValidationFeature<?>> other) Replace this configuration with theotherconfiguration.voidclose()Release any resources held by this validator.@Owning DefaultConstraintValidatordisableFeature(ValidationFeature<?> feature) Turn off the provided feature.@Owning DefaultConstraintValidatorenableFeature(ValidationFeature<?> feature) Turn on the provided feature.voidfinalizeValidation(DynamicContext dynamicContext) Complete any validations that require full analysis of the content model.protected IMutableConfiguration<ValidationFeature<?>>Get the current configuration of the serializer/deserializer.protected IConstraintValidationHandlerGet the validation handler to use for handling constraint violations.Get the mapping of each feature mapped to its value.protected voidhandleAllowedValues(INodeItem targetItem, DynamicContext dynamicContext) Evaluate the value associated with thetargetItemand update the status tracker.booleanisFeatureEnabled(ValidationFeature<?> feature) Determines if a specific feature is enabled.@Owning DefaultConstraintValidatorset(ValidationFeature<?> feature, Object value) Set the value of the providedfeatureto the provided value.protected voidupdateValueStatus(INodeItem targetItem, IAllowedValuesConstraint allowedValues, IDefinitionNodeItem<?, ?> node) Add a new allowed value to the value status tracker.voidvalidate(INodeItem item, DynamicContext dynamicContext) Validate the provided item against any associated constraints.protected voidvalidateAssembly(IAssemblyNodeItem item, DynamicContext dynamicContext) Validate the provided assembly item against any associated constraints.protected voidvalidateField(IFieldNodeItem item, DynamicContext dynamicContext) Validate the provided field item against any associated constraints.protected voidvalidateFlag(IFlagNodeItem item, DynamicContext dynamicContext) Validate the provided flag item against any associated constraints.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.metaschema.core.configuration.IConfiguration
get
-
Constructor Details
-
DefaultConstraintValidator
Construct a new constraint validation instance with sequential execution.- Parameters:
handler- the validation handler to use for handling constraint violations
-
DefaultConstraintValidator
public DefaultConstraintValidator(@NonNull IConstraintValidationHandler handler, @NonNull ParallelValidationConfig parallelConfig) Construct a new constraint validation instance with configurable parallelism.- Parameters:
handler- the validation handler to use for handling constraint violationsparallelConfig- the parallel execution configuration
-
-
Method Details
-
getConfiguration
Get the current configuration of the serializer/deserializer.- Returns:
- the configuration
-
enableFeature
Description copied from interface:IMutableConfigurationTurn on the provided feature.- Specified by:
enableFeaturein interfaceIMutableConfiguration<ValidationFeature<?>>- Parameters:
feature- the feature to turn on- Returns:
- the updated configuration
- See Also:
-
disableFeature
Description copied from interface:IMutableConfigurationTurn off the provided feature.- Specified by:
disableFeaturein interfaceIMutableConfiguration<ValidationFeature<?>>- Parameters:
feature- the feature to turn off- Returns:
- the updated configuration
- See Also:
-
applyConfiguration
@Owning public @Owning DefaultConstraintValidator applyConfiguration(@NonNull IConfiguration<ValidationFeature<?>> other) Description copied from interface:IMutableConfigurationReplace this configuration with theotherconfiguration.- Specified by:
applyConfigurationin interfaceIMutableConfiguration<ValidationFeature<?>>- Parameters:
other- the new configuration- Returns:
- the updated configuration
-
set
Description copied from interface:IMutableConfigurationSet the value of the providedfeatureto the provided value.- Specified by:
setin interfaceIMutableConfiguration<ValidationFeature<?>>- Parameters:
feature- the feature to setvalue- the value to set- Returns:
- the updated configuration
- See Also:
-
isFeatureEnabled
Description copied from interface:IConfigurationDetermines if a specific feature is enabled.- Specified by:
isFeatureEnabledin interfaceIConfiguration<ValidationFeature<?>>- Parameters:
feature- the feature to check for- Returns:
trueif the feature is enabled, orfalseotherwise- See Also:
-
getFeatureValues
Description copied from interface:IConfigurationGet the mapping of each feature mapped to its value.- Specified by:
getFeatureValuesin interfaceIConfiguration<ValidationFeature<?>>- Returns:
- the mapping
-
getConstraintValidationHandler
Get the validation handler to use for handling constraint violations.- Returns:
- the handler
-
close
public void close()Description copied from interface:IConstraintValidatorRelease any resources held by this validator.This method should be called when the validator is no longer needed to release resources such as thread pools. For validators using sequential execution, this method does nothing.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceIConstraintValidator
-
validate
public void validate(@NonNull INodeItem item, @NonNull DynamicContext dynamicContext) throws ConstraintValidationException Description copied from interface:IConstraintValidatorValidate the provided item against any associated constraints.- Specified by:
validatein interfaceIConstraintValidator- Parameters:
item- the item to validatedynamicContext- the Metapath dynamic execution context to use for Metapath evaluation- Throws:
ConstraintValidationException- if a constraint violation is detected
-
validateFlag
Validate the provided flag item against any associated constraints.- Parameters:
item- the flag item to validatedynamicContext- the Metapath dynamic execution context to use for Metapath evaluation- Throws:
MetapathException- if an error occurred while evaluating a Metapath used in a constraint
-
validateField
Validate the provided field item against any associated constraints.- Parameters:
item- the field item to validatedynamicContext- the Metapath dynamic execution context to use for Metapath evaluation- Throws:
MetapathException- if an error occurred while evaluating a Metapath used in a constraint
-
validateAssembly
protected void validateAssembly(@NonNull IAssemblyNodeItem item, @NonNull DynamicContext dynamicContext) throws ConstraintValidationException Validate the provided assembly item against any associated constraints.- Parameters:
item- the assembly item to validatedynamicContext- the Metapath dynamic execution context to use for Metapath evaluation- Throws:
ConstraintValidationException- if an unexpected error occurred while validating a constraint
-
updateValueStatus
protected void updateValueStatus(@NonNull INodeItem targetItem, @NonNull IAllowedValuesConstraint allowedValues, @NonNull IDefinitionNodeItem<?, ?> node) throws ConstraintValidationExceptionAdd a new allowed value to the value status tracker.- Parameters:
targetItem- the item whose value is targeted by the constraintallowedValues- the allowed values constraintnode- the original focus of Metapath evaluation for identifying the targets- Throws:
ConstraintValidationException- if an unexpected error occurred while registering the allowed values
-
handleAllowedValues
protected void handleAllowedValues(@NonNull INodeItem targetItem, @NonNull DynamicContext dynamicContext) Evaluate the value associated with thetargetItemand update the status tracker.- Parameters:
targetItem- the item whose value will be validateddynamicContext- the Metapath dynamic execution context to use for Metapath evaluation
-
finalizeValidation
Description copied from interface:IConstraintValidatorComplete any validations that require full analysis of the content model.- Specified by:
finalizeValidationin interfaceIConstraintValidator- Parameters:
dynamicContext- the Metapath dynamic execution context to use for Metapath evaluation- Throws:
ConstraintValidationException- if a constraint violation is detected during finalization
-