示例#1
0
  private static void printOperatorUsage(String name) {
    OperationRegistry operationRegistry = JAI.getDefaultInstance().getOperationRegistry();
    OperationDescriptor descriptor =
        (OperationDescriptor) operationRegistry.getDescriptor(OperationDescriptor.class, name);
    if (descriptor == null) {
      System.out.println("Unknown operation '" + name + "'");
      return;
    }

    String[][] resources = descriptor.getResources(Locale.getDefault());
    String globalName = resources[0][1];
    String description = resources[3][1];

    String[] sourceNames = descriptor.getSourceNames();
    Class[] sourceTypes = descriptor.getSourceClasses("rendered");
    ParameterListDescriptor parameterListDescriptor =
        descriptor.getParameterListDescriptor("rendered");
    String[] paramNames = parameterListDescriptor.getParamNames();
    Class[] paramTypes = parameterListDescriptor.getParamClasses();

    StringBuilder text = new StringBuilder();
    text.append("Usage: ");
    text.append(globalName);
    text.append('(');
    StringBuilder paramListText = new StringBuilder();
    if (sourceNames != null) {
      for (String sourceName : sourceNames) {
        if (paramListText.length() > 0) {
          paramListText.append(", ");
        }
        paramListText.append(sourceName);
      }
    }
    if (paramNames != null) {
      for (String paramName : paramNames) {
        if (paramListText.length() > 0) {
          paramListText.append(", ");
        }
        paramListText.append(paramName);
        Object defaultValue = parameterListDescriptor.getParamDefaultValue(paramName);
        if (defaultValue != ParameterListDescriptor.NO_PARAMETER_DEFAULT) {
          paramListText.append("=");
          paramListText.append(format(defaultValue));
        }
      }
    }
    text.append(paramListText);
    text.append(')');
    text.append('\n');
    text.append("Description: ");
    text.append(description);
    text.append('\n');
    text.append("Arguments:\n");
    if (sourceNames != null) {
      for (int i = 0; i < sourceNames.length; i++) {
        String sourceName = sourceNames[i];
        Class sourceType = sourceTypes[i];
        text.append("  ");
        text.append(sourceName);
        text.append(": ");
        text.append("A source.");
        text.append(" (" + sourceType.getName() + ")");
        text.append('\n');
      }
    }

    if (paramNames != null) {
      for (int i = 0; i < paramNames.length; i++) {
        String paramName = paramNames[i];
        Class paramType = paramTypes[i];

        text.append("  ");
        text.append(paramName);

        text.append(": ");
        text.append(resources[6 + i][1]);
        text.append(" (" + paramType.getName() + ")");
        text.append('\n');
      }
    }

    System.out.println(text);
  }