예제 #1
0
파일: Gateway.java 프로젝트: gdw2/py4j
  /**
   * Invokes a method.
   *
   * @param methodName
   * @param targetObjectId
   * @param args
   * @return
   */
  public ReturnObject invoke(String methodName, String targetObjectId, List<Object> args) {
    if (args == null) {
      args = new ArrayList<Object>();
    }
    ReturnObject returnObject = null;
    try {
      Object targetObject = getObjectFromId(targetObjectId);
      logger.finer("Calling: " + methodName);
      Object[] parameters = args.toArray();

      MethodInvoker method = null;
      if (targetObject != null) {
        method = rEngine.getMethod(targetObject, methodName, parameters);
      } else {
        method =
            rEngine.getMethod(
                targetObjectId.substring(Protocol.STATIC_PREFIX.length()), methodName, parameters);
      }

      Object object = rEngine.invoke(targetObject, method, parameters);
      returnObject = getReturnObject(object);
    } catch (Py4JJavaException je) {
      String id = putNewObject(je.getCause());
      returnObject = ReturnObject.getErrorReferenceReturnObject(id);
    } catch (Py4JException pe) {
      throw pe;
    } catch (Exception e) {
      throw new Py4JException(e);
    }

    return returnObject;
  }
예제 #2
0
파일: Gateway.java 프로젝트: gdw2/py4j
  /**
   * Invokes a constructor and returned the constructed object.
   *
   * @param fqn The fully qualified name of the class.
   * @param args
   * @return
   */
  public ReturnObject invoke(String fqn, List<Object> args) {
    if (args == null) {
      args = new ArrayList<Object>();
    }
    ReturnObject returnObject = null;
    try {
      logger.finer("Calling constructor: " + fqn);
      Object[] parameters = args.toArray();

      MethodInvoker method = rEngine.getConstructor(fqn, parameters);
      Object object = rEngine.invoke(null, method, parameters);
      returnObject = getReturnObject(object);
    } catch (Py4JJavaException je) {
      String id = putNewObject(je.getCause());
      returnObject = ReturnObject.getErrorReferenceReturnObject(id);
    } catch (Py4JException pe) {
      throw pe;
    } catch (Exception e) {
      throw new Py4JException(e);
    }

    return returnObject;
  }