Class InterceptedCommand

java.lang.Object
org.pipservices4.rpc.commands.InterceptedCommand
All Implemented Interfaces:
org.pipservices4.components.exec.IExecutable, ICommand

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(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

    Constructors
    Constructor
    Description
    Creates a new InterceptedCommand, which serves as a link in an execution chain.
  • Method Summary

    Modifier and Type
    Method
    Description
    execute(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).
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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(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:
      execute in interface org.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:
      • Parameters
    • 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.
      Specified by:
      validate in interface ICommand
      Parameters:
      args - the parameters (arguments) to validate for the next command.
      Returns:
      an list of ValidationResults.
      See Also:
      • Parameters
      • ValidationResult