Ejemplo n.º 1
0
  /**
   * Returns a String explaining the runtime parameter usage. It will take the form
   *
   * <pre>
   * command - description <dataType> [<required>]
   * </pre>
   *
   * @return a String explaining the runtime parameter usage.
   */
  public String getParameterUsageTable() {
    int minLen = 0;

    final Collection<ApplicationParameter> params = getParameters();
    final HashMap<ApplicationParameter, String> verboseKeys =
        new HashMap<ApplicationParameter, String>(params.size());

    for (ApplicationParameter param : params) {
      final String[] keys = param.getKeys();
      final StringBuilder keyString = new StringBuilder(64);
      for (int i = 0; i < keys.length; i++) {
        keyString.append(keys[i]);
        if (i < keys.length - 1) keyString.append(", ");
      }
      verboseKeys.put(param, keyString.toString());
      minLen = Math.max(minLen, keyString.length());
    }

    final StringBuilder builder = new StringBuilder(256);
    for (Iterator<ApplicationParameter> it = params.iterator(); it.hasNext(); ) {
      final ApplicationParameter param = it.next();
      final String str = verboseKeys.get(param);
      builder.append(str);
      for (int i = str.length(); i < minLen; i++) builder.append(' ');
      builder.append(" - ").append(param.getName());
      if (param.isRequired()) builder.append("[required]");
      builder.append(" (").append(param.getType()).append(')');
      if (it.hasNext()) builder.append('\n');
    }

    return builder.toString();
  }
Ejemplo n.º 2
0
 /**
  * This method will ensure that all runtime parameters marked 'required' have been specified.
  * Otherwise, a ParameterValueException will be thrown.
  *
  * @throws ParameterValueException if a required parameter is missing
  */
 public void ensureRequiredParametersArePresent() throws ParameterValueException {
   for (ApplicationParameter param : _parameters.values()) {
     if (param.isRequired() && !param.isPresent())
       throw new ParameterValueException(
           param, null, "Required parameter " + param.getName() + " not set.");
   }
 }