Exemple #1
0
  private void printMethodAsync(RemoteInfo rinfoImpl, MethodInfo methodInfo) throws IOException {
    // log.debug(GeneratorJ.class.getName(), "printMethodAsync");

    CodePrinter mpr = pctxt.printDeclareMethodAsync(pr, rinfoImpl, methodInfo);
    mpr.println("{");
    pr.beginBlock();
    pr.checkpoint();

    String requestClass = methodInfo.requestInfo.toString(rinfoImpl.pack);
    pr.print(requestClass).print(" req = new ").print(requestClass).print("();");
    pr.println();

    for (MemberInfo pinfo : methodInfo.requestInfo.members) {

      // Supply authentication parameter
      if (pctxt.isSessionParam(rinfoImpl, pinfo)) {
        // Session is set in BTransport by a call to BMethodRequest.setSession()
      } else {
        mpr = pr.print("req.").print(pinfo.name).print(" = ");
        mpr.print(pinfo.name).print(";").println();
      }
    }

    // String rtype = pctxt.getReturnTypeAsObjType(methodInfo, rinfoImpl.pack);
    // String outerAsyncClass = "BAsyncResultReceiveMethod<" + rtype + ">";
    // pr.print(outerAsyncClass).print(" outerResult = new
    // ").print(outerAsyncClass).print("(asyncResult);").println();

    pr.println("transport.sendMethod(req, asyncResult);");

    pr.endBlock();

    pr.println("}");
    // log.debug(GeneratorJ.class.getName(), "printMethodAsync");
  }
Exemple #2
0
  private void printMethod(RemoteInfo rinfoImpl, MethodInfo methodInfo) throws IOException {
    // log.debug(GeneratorJ.class.getName(), "printMethod");

    pctxt.printDeclareMethod(pr, rinfoImpl, methodInfo).println(" {");

    pr.beginBlock();
    pr.checkpoint();

    String rtype = pctxt.getReturnTypeAsObjType(methodInfo, rinfoImpl.pack);
    String asyncResultType = "BSyncResult<" + rtype + ">";
    pr.print("final ")
        .print(asyncResultType)
        .print(" asyncResult = new ")
        .print(asyncResultType)
        .print("();");
    pr.println();

    CodePrinter mpr = pr.print(methodInfo.name).print("(");
    boolean first = true;
    for (MemberInfo pinfo : methodInfo.requestInfo.members) {

      // Skip authentication parameter
      if (pctxt.isSessionParam(rinfoImpl, pinfo)) continue;

      if (first) first = false;
      else mpr.print(", ");
      mpr.print(pinfo.name);
    }
    if (!first) mpr.print(", ");
    mpr.print("asyncResult");
    mpr.println(");");

    boolean hasOwnExceptions = methodInfo.exceptions.size() != 0;
    if (hasOwnExceptions) {
      pr.println("try {");
      pr.beginBlock();
    }

    mpr = pr;
    if (!methodInfo.resultInfo.members.get(0).type.isVoidType()) {
      mpr = pr.print("return ");
    }
    mpr.print("asyncResult.getResult();");
    pr.println();

    if (hasOwnExceptions) {
      pr.endBlock();
      pr.println("} ");
      pr.println("catch (BException e) {");
      pr.beginBlock();
      pr.println("Throwable cause = e.getCause();");
      pr.println("if (cause != null) {");
      pr.beginBlock();
      for (TypeInfo exInfo : methodInfo.exceptions) {
        String exName = exInfo.toString(rinfoImpl.pack);
        pr.print("if (cause instanceof ")
            .print(exName)
            .print(") throw (")
            .print(exName)
            .print(")cause;")
            .println();
      }
      pr.endBlock();
      pr.println("}");
      pr.println("throw e;");
      pr.endBlock();
      pr.println("}");
    }

    pr.endBlock();
    pr.println("}");

    // log.debug(GeneratorJ.class.getName(), "printMethod");
  }