Class InterceptedCommand

java.lang.Object
org.pipservices3.commons.commands.InterceptedCommand
All Implemented Interfaces:
ICommand, IExecutable

public class InterceptedCommand extends Object implements 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(String correlationId, ICommand command, Parameters args) {
     System.out.println("Executed command " + command.getName());
     return command.execute(correlationId, 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 Details

    • InterceptedCommand

      public InterceptedCommand(ICommandInterceptor interceptor, ICommand next)
      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

      public String getName()
      Gets the command name.
      Specified by:
      getName in interface ICommand
      Returns:
      the name of the command that is being intercepted.
    • execute

      public Object execute(String correlationId, Parameters args) throws ApplicationException
      Executes the next command in the execution chain using the given Parameters parameters (arguments).
      Specified by:
      execute in interface IExecutable
      Parameters:
      correlationId - unique transaction id to trace calls across components.
      args - the parameters (arguments) to pass to the command for execution.
      Returns:
      execution result.
      Throws:
      ApplicationException - when execution fails for whatever reason.
      See Also:
    • validate

      public List<ValidationResult> validate(Parameters args)
      Validates the Parameters args that are to be passed to the command that is next in the execution chain.
      Specified by:
      validate in interface ICommand
      Parameters:
      args - the parameters (arguments) to validate for the next command.
      Returns:
      an list of ValidationResults.
      See Also: