private void processArguments(final String[] args)
      throws CommandException
   {
      log.debug("processing arguments: " + Strings.join(args, ","));

      if (args.length == 0)
      {
         throw new CommandException("Command requires arguments");
      }
      
      String sopts = "-:dcl";
      LongOpt[] lopts =
      {
         new LongOpt("domain", LongOpt.NO_ARGUMENT, null, 'd'),
         new LongOpt("count", LongOpt.NO_ARGUMENT, null, 'c'),
         new LongOpt("list", LongOpt.NO_ARGUMENT, null, 'l'),
      };

      Getopt getopt = new Getopt(null, args, sopts, lopts);
      getopt.setOpterr(false);
      
      int code;
      while ((code = getopt.getopt()) != -1)
      {
         switch (code)
         {
            case ':':
               throw new CommandException
                  ("Option requires an argument: "+ args[getopt.getOptind() - 1]);

            case '?':
               throw new CommandException
                  ("Invalid (or ambiguous) option: " + args[getopt.getOptind() - 1]);

            // non-option arguments
            case 1:
               throw new CommandException("Unused argument: " + getopt.getOptarg());

            case 'd':
               mode = DEFAULT_DOMAIN;
               break;

            case 'c':
               mode = MBEAN_COUNT;
               break;
            case 'l':
               mode = LIST_NAMES;
               break;
         }
      }
   }