Interface ValidatorFactory
public interface ValidatorFactory
Creates built-in
Validator
instances and Validator
instances loaded by name.-
Method Summary
Modifier and TypeMethodDescriptionstatic ValidatorFactory
createServiceFactory
(ClassLoader classLoader) Creates a ValidatorFactory that discovers service providers using the given ClassLoader.static ValidatorFactory
createServiceFactory
(Iterable<Validator> validators, Iterable<ValidatorService> services) Creates a ValidatorFactory that uses a collection of built-in validators and a collection of ValidatorService instances for configurable validators.createValidator
(String name, ObjectNode configuration) Creates and configures a Validator by name.Returns a list of built-in validators that are always applied to a Model regardless of if they are explicitly configured in the metadata of a model.
-
Method Details
-
loadBuiltinValidators
Returns a list of built-in validators that are always applied to a Model regardless of if they are explicitly configured in the metadata of a model. This is in contrast to validators returns from callingcreateValidator(java.lang.String, software.amazon.smithy.model.node.ObjectNode)
, which are only applied to a model if they are declared in the metadata section of a model.- Returns:
- Returns the loaded validators.
-
createValidator
Creates and configures a Validator by name.- Parameters:
name
- Name of the validator to create.configuration
- Configuration data used to create the validator.- Returns:
- Returns the created validator wrapped in an Optional.
- Throws:
SourceException
- on configuration error.RuntimeException
- if an error occurs while creating.
-
createServiceFactory
static ValidatorFactory createServiceFactory(Iterable<Validator> validators, Iterable<ValidatorService> services) Creates a ValidatorFactory that uses a collection of built-in validators and a collection of ValidatorService instances for configurable validators.The validators and services passed to this method are copied into a List before creating the actual factory to avoid holding on to
ServiceLoader
VM-wide instances that potentially utilize a Thread's context ClassLoader.- Parameters:
validators
- Built-in validators to provide from the factory.services
- ValidatorService instances to use to create validators.- Returns:
- Returns the created ValidatorFactory.
-
createServiceFactory
Creates a ValidatorFactory that discovers service providers using the given ClassLoader.- Parameters:
classLoader
- Class loader used to find ValidatorProviders.- Returns:
- Returns the created factory.
-