Description
The ICommandInterceptor interface is used for stackable command interceptors, which can extend and modify the command call chain.
Important points
- This technique can be used for authentication, logging, and several other functions.
Instance methods
getName
Gets the name of the wrapped command.
The interceptor can use this method to override the command name. Otherwise, it shall just delegate the call to the wrapped command.
String getName(ICommand command)
- command: ICommand - next command in the call chain.
- returns: String - name of the wrapped command.
execute
Executes the wrapped command with specified arguments.
The interceptor can use this method to intercept and alter the command execution. Otherwise, it shall just delete the call to the wrapped command.
Object execute(IContext context, ICommand command, Parameters args) throws ApplicationException
- context: IContext - (optional) a context to trace execution through a call chain.
- command: ICommand - next command in the call chain that is to be executed.
- args: Parameters - parameters (arguments) to pass to the command for execution.
- returns: Object - execution result.
validate
Validates the arguments of the wrapped command before its execution.
The interceptor can use this method to intercept and alter validation of the command arguments. Otherwise, it shall just delegate the call to the wrapped command.
List<ValidationResult> validate(ICommand command, Parameters args)
- command: ICommand - next command in the call chain to be validated against.
- args: Parameters - parameters (arguments) to validate.
- returns: List<ValidationResult> - array of ValidationResults.