Package org.pipservices4.rpc.commands
Class InterceptedCommand
java.lang.Object
org.pipservices4.rpc.commands.InterceptedCommand
- All Implemented Interfaces:
org.pipservices4.components.exec.IExecutable,ICommand
Implements a
ICommand command wrapped by an interceptor.
It allows to build command call chains. The interceptor can alter execution
and delegate calls to a next command, which can be intercepted or concrete.
### Example ###
public class CommandLogger implements ICommandInterceptor {
public String getName(ICommand command) {
return command.getName();
}
public Object execute(IContext context, ICommand command, Parameters args) {
System.out.println("Executed command " + command.getName());
return command.execute(context, args);
}
private List<ValidationResult> validate(ICommand command, Parameters args) {
return command.validate(args);
}
}
CommandLogger logger = new CommandLogger();
InterceptedCommand loggedCommand = new InterceptedCommand(logger, command);
// Each called command will output: Executed command <command name>
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionInterceptedCommand(ICommandInterceptor interceptor, ICommand next) Creates a new InterceptedCommand, which serves as a link in an execution chain. -
Method Summary
Modifier and TypeMethodDescriptionexecute(org.pipservices4.components.context.IContext context, org.pipservices4.components.exec.Parameters args) Executes the next command in the execution chain using the given Parameters parameters (arguments).getName()Gets the command name.List<org.pipservices4.data.validate.ValidationResult>validate(org.pipservices4.components.exec.Parameters args) Validates the Parameters args that are to be passed to the command that is next in the execution chain.
-
Constructor Details
-
InterceptedCommand
Creates a new InterceptedCommand, which serves as a link in an execution chain. Contains information about the interceptor that is being used and the next command in the chain.- Parameters:
interceptor- the interceptor that is intercepting the command.next- (link to) the next command in the command's execution chain.
-
-
Method Details
-
getName
Gets the command name. -
execute
public Object execute(org.pipservices4.components.context.IContext context, org.pipservices4.components.exec.Parameters args) throws org.pipservices4.commons.errors.ApplicationException Executes the next command in the execution chain using the given Parameters parameters (arguments).- Specified by:
executein interfaceorg.pipservices4.components.exec.IExecutable- Parameters:
context- (optional) a context to trace execution through call chain.args- the parameters (arguments) to pass to the command for execution.- Returns:
- execution result.
- Throws:
org.pipservices4.commons.errors.ApplicationException- when execution fails for whatever reason.- See Also:
-
validate
public List<org.pipservices4.data.validate.ValidationResult> validate(org.pipservices4.components.exec.Parameters args) Validates the Parameters args that are to be passed to the command that is next in the execution chain.
-