示例#1
0
  private ResponseHandler createResponseHandler(
      Map.Entry<String, TextContainer> pair, String targetMethodName) {
    TextContainer container = pair.getValue();
    try {
      if (container.isForTemplate()) {
        Method method = Moco.class.getMethod(targetMethodName, String.class, Resource.class);
        return (ResponseHandler) method.invoke(null, pair.getKey(), template(container.getText()));
      }

      Method method = Moco.class.getMethod(targetMethodName, String.class, String.class);
      return (ResponseHandler) method.invoke(null, pair.getKey(), container.getText());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
示例#2
0
  private Resource resourceFrom(String name, TextContainer container) {
    if (container.isRawText()) {
      return invokeTarget(name, container.getText(), Resource.class);
    }

    if (container.isForTemplate()) {
      if ("version".equalsIgnoreCase(name)) {
        return version(template(container.getText()));
      }

      if (container.hasProperties()) {
        return template(
            invokeTarget(name, container.getText(), ContentResource.class), container.getProps());
      }

      return template(invokeTarget(name, container.getText(), ContentResource.class));
    }

    throw new IllegalArgumentException(format("unknown operation [%s]", container.getOperation()));
  }