Package org.com.tatu.helper.parameter

Examples of org.com.tatu.helper.parameter.ConsoleParameters


   * @param args
   */
  public static void main(String[] args) {
    HPIClientProtocol clientProtocol = null;
    try {
      ConsoleParameters consoleParameters = ConsoleParameters.getInstance(args);
     
      // -server[-s]
      String serverParam = null;
      if (!GeneralsHelper.isStringOk(serverParam = consoleParameters.getValue("-server")) &&
          !GeneralsHelper.isStringOk(serverParam = consoleParameters.getValue("-s"))) {
        throw new HPIUsageException();
      }
     
      // -user[-u]
      String userParam = null;
      if (!GeneralsHelper.isStringOk(userParam = consoleParameters.getValue("-user")) &&
          !GeneralsHelper.isStringOk(userParam = consoleParameters.getValue("-u"))) {
        throw new HPIUsageException();
      }
     
      // -password[-p]
      String passwordParam = null;
      if (!GeneralsHelper.isStringOk(passwordParam = consoleParameters.getValue("-password")) &&
          !GeneralsHelper.isStringOk(passwordParam = consoleParameters.getValue("-p"))) {
        throw new HPIUsageException();
      }
     
      // create the client protocol instance and tries do login
      clientProtocol = connectClientProtocol(serverParam.trim());
      LoginResponse loginResponse = clientProtocol.doLogin(new User(userParam, passwordParam));
      if (loginResponse.getStatus().equals(Response.Status.SUCCESS)) {
        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        String command = null;
        System.out.print("User connected successfully\n");
        printPossibilities();
        System.out.print("client's command > ");
       
        while ((command = stdIn.readLine()) != null) {
          command = command.trim();
          command = command.replace(";", "");
          command = "-" + command;
          ConsoleParameters innerParam = ConsoleParameters.getInstance(command.trim().split(" "));
         
          String paramValue = null;
          String response = null;
         
          if (GeneralsHelper.isStringOk(paramValue = innerParam.getValue(ListInvokersService.COMMAND))) { // list
            response = new ListInvokersService(loginResponse.getSessionId()).execute(clientProtocol);
          } else if (GeneralsHelper.isStringOk(paramValue = innerParam.getValue(DescribeInvokerService.COMMAND))) { // describe
            response = new DescribeInvokerService(loginResponse.getSessionId(), paramValue).execute(clientProtocol);
          } else if (GeneralsHelper.isStringOk(paramValue = innerParam.getValue(ExecuteInvokerService.COMMAND))) { // execute
            response = new ExecuteInvokerService(loginResponse.getSessionId(), paramValue).execute(clientProtocol);
          } else if (GeneralsHelper.isStringOk(paramValue = innerParam.getValue(ServerShutdownService.COMMAND))) { // shutdown
            response = new ServerShutdownService().execute(clientProtocol);
          } else if (GeneralsHelper.isStringOk(paramValue = innerParam.getValue(LogoffService.COMMAND))) { // exit
            response = new LogoffService(loginResponse.getSessionId()).execute(clientProtocol);
           
            System.out.println(response);
            System.out.println("Bye!");
            break;
View Full Code Here

TOP

Related Classes of org.com.tatu.helper.parameter.ConsoleParameters

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.