Example #1
0
 protected CmdOptionHandler findHandler(
     final AccessibleObject element,
     final int argsCount,
     final Class<? extends CmdOptionHandler> cmdOptionHandlerType) {
   CmdOptionHandler handler = null;
   if (cmdOptionHandlerType != null && !cmdOptionHandlerType.equals(CmdOptionHandler.class)) {
     // requested a specific handler
     final CmdOptionHandler dedicatedHandler;
     if (handlerRegistry.containsKey(cmdOptionHandlerType)) {
       dedicatedHandler = handlerRegistry.get(cmdOptionHandlerType);
     } else {
       try {
         dedicatedHandler = cmdOptionHandlerType.newInstance();
       } catch (final Exception e) {
         final PreparedI18n msg =
             i18n.preparetr("Could not create handler: {0}", cmdOptionHandlerType);
         throw new CmdlineParserException(msg.notr(), e, msg.tr());
       }
       // not registering this handler because self-introduced handler
       // (only in a specific annotation) should not be made available
       // to all other options.
     }
     if (dedicatedHandler.canHandle(element, argsCount)) {
       handler = dedicatedHandler;
     }
   } else {
     // walk through registered hander and find one
     for (final CmdOptionHandler regHandle : handlerRegistry.values()) {
       if (regHandle.canHandle(element, argsCount)) {
         handler = regHandle;
         break;
       }
     }
   }
   if (handler == null && parent != null) {
     return parent.findHandler(element, argsCount, cmdOptionHandlerType);
   } else {
     return handler;
   }
 }
Example #2
0
  private void debug(final String msg, final Object... args) {
    // always log.debug
    if (log.isDebugEnabled()) {
      if (args == null || args.length == 0) {
        log.debug(msg);
      } else {
        log.debug(MessageFormat.format(msg, args));
      }
    }

    if (parent != null) {
      parent.debug(msg, args);
    } else {
      if (debugMode) {
        if (args == null || args.length == 0) {
          System.out.println(DEBUG_PREFIX + msg);
        } else {
          System.out.println(DEBUG_PREFIX + MessageFormat.format(msg, args));
        }
      }
    }
  }