com.google.gwt.user.client.rpc.RpcRequestBuilder Java Examples

The following examples show how to use com.google.gwt.user.client.rpc.RpcRequestBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtendedServiceProxyGenerator.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * Generates a wrapper around the proxy generated by
 * {@link ServiceInterfaceProxyGenerator}.
 *
 * @param logger log interface
 * @param context generator context
 * @param typeName name of the interface that was passed to
 *        {@link com.google.gwt.core.client.GWT#create(Class)}
 * @param proxyTypeName the name of the wrapped proxy class
 * @return the name of the extended proxy class
 */
private String generateExtendedProxy(TreeLogger logger, GeneratorContext context,
    String typeName, String proxyTypeName) {
  JClassType type = context.getTypeOracle().findType(typeName);
  String packageName = type.getPackage().getName();
  String className = type.getSimpleSourceName() + PROXY_SUFFIX;
  String asyncName = typeName + ASYNC_SUFFIX;

  String classNameExtendedServiceProxy = "com.google.appinventor.client.ExtendedServiceProxy";

  // The generator can be invoked for the same class name more than once.
  // In this case the GeneratorContext.tryCreate method will return null to
  // indicate that the file already exists. This is not an error.
  PrintWriter out = context.tryCreate(logger, packageName, className);
  if (out != null) {
    out.println("package " + packageName + ";");
    out.println("class " + className);
    out.println("    extends " + classNameExtendedServiceProxy + "<" + typeName + ">");
    out.println("    implements " + ServiceDefTarget.class.getName() + ", " + asyncName + " {");
    out.println("  private " + proxyTypeName + " proxy = new " + proxyTypeName + "();");
    out.println("  public String getServiceEntryPoint() {");
    out.println("    return proxy.getServiceEntryPoint();");
    out.println("  }");
    out.println("  public void setRpcRequestBuilder(" + RpcRequestBuilder.class.getName() +
        " builder) {");
    out.println("    proxy.setRpcRequestBuilder(builder);");
    out.println("  }");
    out.println("  public void setServiceEntryPoint(String address) {");
    out.println("    proxy.setServiceEntryPoint(address);");
    out.println("  }");
    out.println("  public String getSerializationPolicyName() {");
    out.println("    return proxy.getSerializationPolicyName();");
    out.println("  }");

    for (JMethod method : type.getMethods()) {
      printMethod(out, method, typeName);
    }

    out.println("}");

    context.commit(logger, out);
  }

  return packageName + "." + className;
}