/**
   * Uses the command line arguments to authenticate the GoogleService and build the basic feed URI,
   * then invokes all the other methods to demonstrate how to interface with the Translator toolkit
   * service.
   *
   * @param args See the usage method.
   */
  public static void main(String[] args) {
    try {
      // Connect to the Google translator toolkit service
      GttService service = new GttService("sample.gtt.GttClient");

      // Login if there is a command line argument for it.
      if (args.length >= 1 && NAME_TO_COMMAND_MAP.get(args[0]) == GttCommand.LOGIN) {
        GttCommand.LOGIN.execute(service, args);
      }

      // Input stream to get user input
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

      // Do some actions based on user input
      while (true) {
        // Get user input
        System.out.print(USER_PROMPT);
        System.out.flush();
        String userInput = in.readLine();
        System.out.println();

        // Do action corresponding to user input
        String[] commandArgs = userInput.split("\\s+");
        GttCommand command = NAME_TO_COMMAND_MAP.get(commandArgs[0]);
        if (command != null) {
          command.execute(service, commandArgs);
        } else {
          System.out.println("Sorry I did not understand that.");
        }
      }
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }
 static {
   ImmutableMap.Builder<String, GttCommand> builder = ImmutableMap.builder();
   for (GttCommand command : GttCommand.values()) {
     builder.put(command.name().toLowerCase(), command);
   }
   NAME_TO_COMMAND_MAP = builder.build();
 }