コード例 #1
0
  public void callActionOnView(CarpaccioAction action, View view) {
    // find the controller for this call
    ObjectAndMethod objectAndMethod = action.getObjectAndMethod();
    if (objectAndMethod == null) {
      // check if cached it
      String key = action.getFunction() + (action.getArgs().length + 1);

      objectAndMethod = savedControllers.get(key);

      if (objectAndMethod == null) { // if not cached,
        objectAndMethod =
            CarpaccioHelper.findObjectWithThisMethod(
                this.registerControllers,
                action.getFunction(),
                action.getArgs().length + 1); // +1 for the view

        if (objectAndMethod != null) {
          CarpaccioLogger.d(
              TAG, objectAndMethod.getObject() + " used for " + action.getCompleteCall());
        } else {
          CarpaccioLogger.e(TAG, "cannot find any controller for " + action.getCompleteCall());
          throw new CarpaccioException(
              "cannot find any controller for " + action.getCompleteCall());
        }

        savedControllers.put(key, objectAndMethod);
      }
      action.setObjectAndMethod(objectAndMethod);
    }

    if (objectAndMethod != null) {
      // call !
      CarpaccioHelper.callMethod(
          action.getObjectAndMethod().getObject(),
          action.getObjectAndMethod().getMethod(),
          action.getFunction(),
          view,
          action.getValues());
    }
  }