public String getInputNomask(String prompt, boolean isNotInputMask)
      throws IOException, UserInterruption {
    String userInput = "";

    String breakConnectPrompt = EXIT_PROD_STR;
    if (isNotInputMask) breakConnectPrompt = "Command Interrupted - Please hit <Enter> ... ";

    crObj.setPrompt(breakConnectPrompt, false, false);

    try {
      System.out.print("                                 \r" + prompt);
      userInput = crObj.getLine();
    } catch (Throwable t) {
      UserInterruption uie = null;
      if (t instanceof UserInterruption) {
        uie = (UserInterruption) t;
        retryCnt = 0;
      } else uie = new UserInterruption();

      throw uie;
    } finally {
      cwObj.print(SessionDefaults.lineSeperator);
    }
    // return characters entered by the user
    return userInput;
  }
  public String getInputMask(String prompt, boolean isInputMask)
      throws IOException, UserInterruption {
    String password = "";
    WCIUtils wcs = null;
    boolean isWindows = System.getProperty("os.name").toUpperCase().startsWith("WINDOW");

    MaskingThread et = new MaskingThread(prompt);
    Thread mask = new Thread(et);
    mask.start();

    // if it is windows envrionment use the dll to disable echo
    if (isWindows) {
      try {
        wcs = new WCIUtils();
        wcs.disableEcho();

      } catch (Throwable e) {
      }
    }
    crObj.setMaskingThread(et, wcs);

    String breakConnectPrompt = EXIT_PROD_STR;
    if (!this.isLaunchConnect || isInputMask)
      breakConnectPrompt =
          "Command Interrupted - Please hit <Enter> ... " + SessionDefaults.lineSeperator;

    crObj.setPrompt(breakConnectPrompt, false, false);

    try {
      password = crObj.getLine();
    } catch (Throwable t) {
      UserInterruption uie = null;
      if (t instanceof UserInterruption) {
        uie = (UserInterruption) t;
        retryCnt = 0;
      } else uie = new UserInterruption();

      throw uie;
    } finally {

      // stop masking
      et.stopMasking();

      if (isWindows) {
        try {
          wcs.enableEcho();

        } catch (Exception e) {
        }

        wcs = null;
      }
      cwObj.print(SessionDefaults.lineSeperator);
    }
    // return the password entered by the user

    return password;
  }
  private String getRequiredArg(String prompt) throws IOException, UserInterruption {
    String value = null;
    String breakConnectPrompt = EXIT_PROD_STR;
    if (!this.isLaunchConnect)
      breakConnectPrompt =
          "Command Interrupted - Please hit <Enter> ... " + SessionDefaults.lineSeperator;

    crObj.setPrompt(breakConnectPrompt, false, false);
    cwObj.print(prompt);

    // set retry count to 0 if user hits a Ctrl+C while entering login parameters
    try {
      value = crObj.getLine();
    } catch (UserInterruption ui) {
      retryCnt = 0;
      throw ui;
    }
    return value;
  }
  public String[] validateArgs(String[] args, boolean isLaunchConnect)
      throws InvalidNumberOfArguments, IOException, UserInterruption {

    osName = System.getProperty("os.name");
    setArgs(args);
    this.isLaunchConnect = isLaunchConnect;

    List<String> argsList = new ArrayList<String>(Arrays.asList(args));

    // Pre-parse args for special cases
    if (argsList.contains("-version")) {
      cwObj.print("JDBC Type 4 Driver Build ID : ");
      cwObj.println(JDBCVproc.getVproc());
      cwObj.print("Command Interface Build ID  : ");
      org.trafodion.ci.Vproc.main(args);
      cwObj.println("");
      System.exit(0); // any other args included w/version are ignored
    }

    // Display argument help if -help argument is passed
    if (argsList.contains("-help")) {
      printUsage();
      System.exit(0); // any other args included w/help are ignored
    }

    // No retries if in query mode
    if (argsList.contains("-q") || argsList.contains("-sql")) retryCnt = 1;

    if (argsList.remove("-noconnect")) {
      noConnectOption = true;
    }

    if (argsList.remove("-dfm")) {
      dfm = true;
    }

    /* reset args b/c of -noconnect or -dfm, dont need the if but perhaps a small perf gain? */
    if (dfm || noConnectOption) {
      args = null;
      args = new String[argsList.size()];
      // args = (String[])
      argsList.toArray(args);
      noOfArgs = args.length;
    }

    // the number of arguments must be an odd number if -noconnect option is specified
    // otherwise it should be an even number

    if (noOfArgs % 2 != 0 || noOfArgs > 14) {
      printUsage();
      throw new InvalidNumberOfArguments();
    }

    argsList = null;

    // Pre-parsing complete

    for (int i = 0; i < noOfArgs; i++) {
      String option = args[i++].trim();
      String value = args[i].trim();

      if (option.equalsIgnoreCase("-u") || option.equalsIgnoreCase("-user")) {
        userName = value;
      } else if (option.equalsIgnoreCase("-p") || option.equalsIgnoreCase("-password")) {
        password = value;
      } else if (option.equalsIgnoreCase("-r") || option.equalsIgnoreCase("-role")) {
        roleName = value;
      } else if (option.equalsIgnoreCase("-h") || option.equalsIgnoreCase("-host")) {
        String[] hostAddr = value.split(":");
        if (hostAddr.length > 0) serverName = hostAddr[0];
        else serverName = "";

        String portValue = "";

        for (int j = 1; j < hostAddr.length; j++) {
          portValue += ":" + hostAddr[j];
        }
        if (portValue.length() > 0) {
          portNumber = portValue;
        }

      } else if (isLaunchConnect
          && (option.equalsIgnoreCase("-q") || option.equalsIgnoreCase("-sql"))) {
        queryStr = value;
        if (fileName != null) {
          cwObj.println("-s|script and -q|sql options must not be specified together.");
          this.printUsage();
        }
      } else if (isLaunchConnect
          && (option.equalsIgnoreCase("-s") || option.equalsIgnoreCase("-script"))) {
        fileName = value;
        if (queryStr != null) {
          cwObj.println("-s|script and -q|sql options must not be specified together.");
          this.printUsage();
        }
      }
      /* Instead of -cmd we will implement a set cmdecho <on|off> command
       * and replace -cmd with -DFM which will execute both set lookandfeel mxci and
       * set cmdecho on
       *
       * else if (isLaunchConnect &&(option.equalsIgnoreCase("-cmd")))
      {
         if (value.equalsIgnoreCase("Y"))
            cmdEcho = true;
      }*/
      else {
        cwObj.println("Unknown option " + option + " specified.");
        printUsage();
        throw new UnknownHostException();
      }
    } // end for

    if (!noConnectOption) {
      do {

        if (serverName == null) {
          String value = getRequiredArg("Host Name/IP Address: ");
          String[] hostAddr = value.split(":");
          if (hostAddr.length > 0) serverName = hostAddr[0];
          else serverName = "";
          String portValue = "";
          for (int j = 1; j < hostAddr.length; j++) {
            portValue += ":" + hostAddr[j];
          }
          portNumber = null;
          if (portValue.length() > 0) {
            portNumber = portValue;
          }
        }

        try {
          if (serverName.trim().equals("")) throw new UnknownHostException("Host Name is empty");
          else InetAddress.getByName(serverName);
        } catch (UnknownHostException uh) {
          cwObj.println(
              SessionDefaults.lineSeperator
                  + "Unknown Host: "
                  + serverName
                  + SessionDefaults.lineSeperator);
          serverName = null;

          // Rebuild the argument list to remove the hostname
          args = this.rebuildArgList(args);
          if ((--retryCnt) == 0) throw uh;
        }

      } while (serverName == null && retryCnt > 0);
    }

    if (!noConnectOption && userName == null) {
      do {
        userName = getRequiredArg("User Name: ");
      } while (userName.trim().equals(""));
    }

    if (!noConnectOption && password == null) {
      password = getPassword("Password: "******"Role Name [Primary Role]: ");
    }

    if (portNumber == null) {
      portNumber = ":" + defaultPortNumber;
    }

    return args;
  }