Package org.crsh.shell.impl.command.spi

Examples of org.crsh.shell.impl.command.spi.CommandException


    try {
      PipeLineFactory factory = token2.createFactory();
      return factory.create(session);
    }
    catch (CommandNotFoundException e) {
      throw new CommandException(ErrorKind.SYNTAX, e.getMessage(), e);
    }
  }
View Full Code Here


      CommandInvokerAdapter filterContext = new CommandInvokerAdapter(invoker, consumed, produced);
      try {
        filterContext.open(next);
      }
      catch (Exception e) {
        throw new CommandException(ErrorKind.EVALUATION, e);
      }

      // Save current filter in field
      // so if anything wrong happens it will be closed
      current = filterContext;
View Full Code Here

  public void close() throws IOException, CommandException {
    try {
      current.close();
    }
    catch (Exception e) {
      throw new CommandException(ErrorKind.EVALUATION, e);
    }
  }
View Full Code Here

      if ("mycommand".equals(name)) {
        try {
          return new ClassShellCommand<mycommand>(mycommand.class);
        }
        catch (IntrospectionException e) {
          throw new CommandException(ErrorKind.EVALUATION, "Invalid cli annotations", e);
        }
      }
      return null;
    }
View Full Code Here

    try {
      command = clazz.newInstance();
    }
    catch (Exception e) {
      String name = clazz.getSimpleName();
      throw new CommandException(ErrorKind.INTERNAL, "Could not create command " + name + " instance", e);
    }
    return command;
  }
View Full Code Here

              context.provide(ret);
            }
          }
        }
        catch (Exception t) {
          throw new CommandException(ErrorKind.EVALUATION, GroovyCommand.unwrap(t));
        }
      }

      public void provide(Void element) {
        // Should never be called
View Full Code Here

      if (ret != null) {
        try {
          consumer.provide(ret);
        }
        catch (Exception e) {
          throw new CommandException(ErrorKind.EVALUATION, e);
        }
      }
    }
  }
View Full Code Here

    try {
      shellCommand = new ClassShellCommand<C>(commandClass);
      description = shellCommand.describe(commandClass.getSimpleName(), Format.DESCRIBE);
    }
    catch (IntrospectionException e) {
      throw new CommandException(ErrorKind.SYNTAX, "Invalid cli annotation in command " + commandClass.getSimpleName(), e);
    }
    return new CommandResolution() {
      @Override
      public String getDescription() {
        return description;
View Full Code Here

        PC ret;
        try {
          ret = invoker.invoke(this);
        }
        catch (org.crsh.cli.impl.SyntaxException e) {
          throw new CommandException(ErrorKind.SYNTAX, "Syntax exception when executing command " + name, e);
        } catch (InvocationException e) {
          throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e.getCause());
        }

        // It's a pipe command
        if (ret != null) {
          real = ret;
          try {
            real.open(invocationContext);
          }
          catch (Exception e) {
            throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e);
          }
        }
      }

      public void provide(C element) throws IOException, CommandException {
        if (real != null) {
          try {
            real.provide(element);
          }
          catch (Exception e) {
            throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e);
          }
        }
      }

      public void flush() throws IOException {
        if (real != null) {
          real.flush();
        } else {
          invocationContext.flush();
        }
      }

      public void close() throws IOException, CommandException {
        try {
          try {
            if (real != null) {
              real.close();
            }
          }
          catch (Exception e) {
            throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e);
          } finally {
            try {
              invocationContext.close();
            }
            catch (Exception e) {
              throw new CommandException(ErrorKind.EVALUATION, e);
            }
          }
        } finally {
          command.popContext();
          command.unmatched = null;
View Full Code Here

          Object ret;
          try {
            ret = invoker.invoke(this);
          }
          catch (org.crsh.cli.impl.SyntaxException e) {
            throw new CommandException(ErrorKind.SYNTAX, "Syntax exception when executing command " + name, e);
          } catch (InvocationException e) {
            throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e.getCause());
          }

          // Anything returned compatible is then produced
          if (ret != null && producedType.isInstance(ret)) {
            P produced = producedType.cast(ret);
            try {
              invocationContext.provide(produced);
            }
            catch (Exception e) {
              throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e);
            }
          }
        } finally {
          try {
            invocationContext.flush();
          }
          finally {
            try {
              invocationContext.close();
            }
            catch (Exception e) {
              throw new CommandException(ErrorKind.EVALUATION, "Command " + name + " failed", e);
            } finally {
              command.unmatched = null;
              invocationContext = null;
            }
          }
View Full Code Here

TOP

Related Classes of org.crsh.shell.impl.command.spi.CommandException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.