Exemple #1
0
 /**
  * Execute callback. It is useful when all the API can not satisfy your requirement.
  *
  * @param config the Config object
  * @param callback the ICallback interface
  */
 Object execute(Config config, ICallback callback) {
   Connection conn = null;
   try {
     conn = config.getConnection();
     return callback.run(conn);
   } catch (Exception e) {
     throw new ActiveRecordException(e);
   } finally {
     config.close(conn);
   }
 }
Exemple #2
0
  public static void parseParam(
      LinkedHashMap<String, String> parameterTypesMap,
      String jarPath,
      int api_id,
      int pid,
      int level,
      ICallback callback) {
    if (level > 10) {
      System.out.println(" level limit max ");
      return;
    }

    for (Map.Entry<String, String> item : parameterTypesMap.entrySet()) {
      Class clazz = null;
      String typeName = item.getValue();

      if (isPrimitive(typeName)) {
        callback.run(api_id, pid, typeName, item.getKey(), level);
        continue;
      }

      try { // java class
        clazz = Class.forName(typeName);
      } catch (ClassNotFoundException e) {

      }

      if (clazz == null) { // 加载jar包的class
        try {
          //                        clazz =
          // getClazz3("file:C:/Users/sunlijie/Desktop/jop-router-client-0.0.2-SNAPSHOT.jar",
          // typeName);
          clazz = getClass(jarPath, typeName);
        } catch (RuntimeException e1) { // 基础类型

        }
      }

      if (clazz == null) { // 基础类型 或者一些泛型的 比如 List<String>
        // TODO: 2016/9/18 处理list 为数组
        callback.run(api_id, pid, typeName, item.getKey(), level);
        continue;
      }

      if (!isJavaClass(clazz)) { // 自定义类型
        int id = (Integer) callback.run(api_id, pid, typeName, item.getKey(), level);
        Field[] fields = clazz.getDeclaredFields();

        LinkedHashMap<String, String> types = new LinkedHashMap<String, String>();

        for (Field field : fields) {
          if (field.getName().equals("serialVersionUID")) {
            continue;
          }
          String fieldTypeName = field.getGenericType().toString();
          if (fieldTypeName.startsWith("class ")) {
            fieldTypeName = fieldTypeName.substring(6);
          }
          types.put(field.getName(), fieldTypeName);
        }
        parseParam(types, jarPath, api_id, id, level + 1, callback);
      } else {
        callback.run(api_id, pid, typeName, item.getKey(), level);
      }
    }
  }