public class BeanValidationInterceptor extends Object implements CommandHandlerInterceptor, CommandDispatchInterceptor
CommandHandlerInterceptor
or as a CommandDispatchInterceptor
.Constructor and Description |
---|
BeanValidationInterceptor()
Initializes a validation interceptor using a default ValidatorFactory (see
Validation.buildDefaultValidatorFactory() ). |
BeanValidationInterceptor(javax.validation.ValidatorFactory validatorFactory)
Initializes a validation interceptor using the given ValidatorFactory.
|
Modifier and Type | Method and Description |
---|---|
CommandMessage<?> |
handle(CommandMessage<?> command)
Invoked each time a command is about to be dispatched on a Command Bus.
|
Object |
handle(CommandMessage<?> command,
UnitOfWork unitOfWork,
InterceptorChain interceptorChain)
The handle method is invoked each time a command is dispatched through the command bus that the
CommandHandlerInterceptor is declared on.
|
protected Set<javax.validation.ConstraintViolation<Object>> |
validateCommand(Object command,
javax.validation.Validator validator)
Validate the given
command using the given validator . |
public BeanValidationInterceptor()
Validation.buildDefaultValidatorFactory()
).public BeanValidationInterceptor(javax.validation.ValidatorFactory validatorFactory)
validatorFactory
- the factory providing Validator instances for this interceptor.public Object handle(CommandMessage<?> command, UnitOfWork unitOfWork, InterceptorChain interceptorChain) throws Throwable
CommandHandlerInterceptor
unitOfWork
.
The interceptor is responsible for the continuation of the dispatch process by invoking the InterceptorChain.proceed(CommandMessage)
method on the given
interceptorChain
.
Any information gathered by interceptors may be attached to the unitOfWork. This information is made
available to the CommandCallback provided by the dispatching component.
Interceptors are highly recommended not to change the type of the command handling result, as the dispatching
component might expect a result of a specific type.handle
in interface CommandHandlerInterceptor
command
- The command being dispatchedunitOfWork
- The UnitOfWork in whichinterceptorChain
- The interceptor chain that allows this interceptor to proceed the dispatch processThrowable
- any exception that occurs while handling the commandpublic CommandMessage<?> handle(CommandMessage<?> command)
CommandDispatchInterceptor
commandMessage
represents the command being dispatched.handle
in interface CommandDispatchInterceptor
command
- The command message intended to be dispatched on the Command Busprotected Set<javax.validation.ConstraintViolation<Object>> validateCommand(Object command, javax.validation.Validator validator)
command
using the given validator
. The default implementation
merely calls validator.validate(command)
.
Subclasses may override this method to alter the validation behavior in specific cases. Although the
null
is accepted as return value to indicate that there are no constraint violations,
implementations are encouraged to return an empty Set instead.command
- The command to validatevalidator
- The validator provided by the validator factorynull
.Copyright © 2010-2014. All Rights Reserved.