Skip to content

Commit 630791e

Browse files
committed
同步更新至 4.1.0
1 parent 49d7c40 commit 630791e

File tree

6 files changed

+1042
-7
lines changed

6 files changed

+1042
-7
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>apijson.framework</groupId>
77
<artifactId>apijson-framework</artifactId>
8-
<version>4.0.0</version>
8+
<version>4.1.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>APIJSONFramework</name>
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>com.github.APIJSON</groupId>
2828
<artifactId>apijson-orm</artifactId>
29-
<version>4.0.0</version>
29+
<version>4.1.0</version>
3030
</dependency>
3131
<dependency>
3232
<groupId>javax.servlet</groupId>

src/main/java/apijson/framework/APIJSONController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,12 @@ public Object logout(@NotNull HttpSession session) {
223223
}
224224

225225

226+
public JSONObject invokeMethod(String request) {
227+
return MethodUtil.invokeMethod(request);
228+
}
229+
230+
public JSONObject listMethod(String request) {
231+
return MethodUtil.listMethod(request);
232+
}
233+
226234
}

src/main/java/apijson/framework/APIJSONFunctionParser.java

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import static apijson.framework.APIJSONConstant.FUNCTION_;
1818

19+
import java.io.IOException;
1920
import java.rmi.ServerException;
2021
import java.util.ArrayList;
2122
import java.util.Arrays;
@@ -33,6 +34,7 @@
3334
import apijson.RequestMethod;
3435
import apijson.RequestRole;
3536
import apijson.StringUtil;
37+
import apijson.framework.MethodUtil.Argument;
3638
import apijson.orm.AbstractFunctionParser;
3739
import apijson.orm.JSONRequest;
3840
import apijson.orm.ParserCreator;
@@ -292,6 +294,149 @@ public Object verifyAccess(@NotNull JSONObject request) throws Exception {
292294

293295

294296

297+
/**获取方法参数的定义
298+
* @param request
299+
* @return
300+
* @throws IOException
301+
* @throws ClassNotFoundException
302+
* @throws IllegalArgumentException
303+
*/
304+
public String getMethodArguments(@NotNull JSONObject request) throws IllegalArgumentException, ClassNotFoundException, IOException {
305+
return getMethodArguments(request, "methodArgs");
306+
}
307+
/**获取方法参数的定义
308+
* @param request
309+
* @param requestKey
310+
* @param methodArgs
311+
* @return
312+
* @throws IllegalArgumentException
313+
* @throws ClassNotFoundException
314+
* @throws IOException
315+
*/
316+
public String getMethodArguments(@NotNull JSONObject request, String methodArgsKey) throws IllegalArgumentException, ClassNotFoundException, IOException {
317+
String argsStr = request.getString(methodArgsKey);
318+
if (StringUtil.isEmpty(argsStr, true)) {
319+
JSONObject obj = request.getJSONObject("request");
320+
argsStr = obj == null ? null : obj.getString(methodArgsKey);
321+
}
322+
List<Argument> methodArgs = JSON.parseArray(removeComment(argsStr), Argument.class);
323+
if (methodArgs == null || methodArgs.isEmpty()) {
324+
return "";
325+
}
326+
327+
Class<?>[] types = new Class<?>[methodArgs.size()];
328+
Object[] args = new Object[methodArgs.size()];
329+
MethodUtil.initTypesAndValues(methodArgs, types, args, true);
330+
331+
String s = "";
332+
if (types != null) {
333+
String sn;
334+
for (int i = 0; i < types.length; i++) {
335+
sn = types[i] == null ? null : types[i].getSimpleName();
336+
if (sn == null) {
337+
sn = Object.class.getSimpleName();
338+
}
339+
340+
if (i > 0) {
341+
s += ",";
342+
}
343+
344+
if (MethodUtil.CLASS_MAP.containsKey(sn)) {
345+
s += sn;
346+
}
347+
else {
348+
s += types[i].getName();
349+
}
350+
}
351+
}
352+
return s;
353+
}
354+
355+
356+
/**获取方法的定义
357+
* @param request
358+
* @return
359+
* @throws IOException
360+
* @throws ClassNotFoundException
361+
* @throws IllegalArgumentException
362+
*/
363+
public String getMethodDefination(@NotNull JSONObject request)
364+
throws IllegalArgumentException, ClassNotFoundException, IOException {
365+
// request.put("arguments", removeComment(request.getString("methodArgs")));
366+
return getMethodDefination(request, "method", "arguments", "type", "exceptions", "Java");
367+
}
368+
/**获取方法的定义
369+
* @param request
370+
* @param method
371+
* @param arguments
372+
* @param type
373+
* @return method(argType0,argType1...): returnType
374+
* @throws IOException
375+
* @throws ClassNotFoundException
376+
* @throws IllegalArgumentException
377+
*/
378+
public String getMethodDefination(@NotNull JSONObject request, String method, String arguments, String type, String exceptions, String language)
379+
throws IllegalArgumentException, ClassNotFoundException, IOException {
380+
String n = request.getString(method);
381+
if (StringUtil.isEmpty(n, true)) {
382+
throw new NullPointerException("getMethodDefination StringUtil.isEmpty(methodArgs, true) !");
383+
}
384+
String a = request.getString(arguments);
385+
String t = request.getString(type);
386+
String e = request.getString(exceptions);
387+
388+
if (language == null) {
389+
language = "";
390+
}
391+
switch (language) {
392+
case "TypeScript":
393+
return n + "(" + (StringUtil.isEmpty(a, true) ? "" : a) + ")" + (StringUtil.isEmpty(t, true) ? "" : ": " + t) + (StringUtil.isEmpty(e, true) ? "" : " throws " + e);
394+
case "Go":
395+
return n + "(" + (StringUtil.isEmpty(a, true) ? "" : a ) + ")" + (StringUtil.isEmpty(t, true) ? "" : " " + t) + (StringUtil.isEmpty(e, true) ? "" : " throws " + e);
396+
default:
397+
//类型可能很长,Eclipse, Idea 代码提示都是类型放后面 return (StringUtil.isEmpty(t, true) ? "" : t + " ") + n + "(" + (StringUtil.isEmpty(a, true) ? "" : a) + ")";
398+
return n + "(" + (StringUtil.isEmpty(a, true) ? "" : a) + ")" + (StringUtil.isEmpty(t, true) ? "" : ": " + t) + (StringUtil.isEmpty(e, true) ? "" : " throws " + e);
399+
}
400+
}
401+
402+
/**
403+
* methodArgs 和 classArgs 都可以带注释
404+
*/
405+
public String getMethodRequest(@NotNull JSONObject request) {
406+
String req = request.getString("request");
407+
if (StringUtil.isEmpty(req, true) == false) {
408+
return req;
409+
}
410+
411+
req = "{";
412+
Boolean isStatic = request.getBoolean("static");
413+
String methodArgs = request.getString("methodArgs");
414+
String classArgs = request.getString("classArgs");
415+
416+
boolean comma = false;
417+
if (isStatic != null && isStatic) {
418+
req += "\n \"static\": " + true;
419+
comma = true;
420+
}
421+
if (StringUtil.isEmpty(methodArgs, true) == false) {
422+
req += (comma ? "," : "") + "\n \"methodArgs\": " + methodArgs;
423+
comma = true;
424+
}
425+
if (StringUtil.isEmpty(classArgs, true) == false) {
426+
req += (comma ? "," : "") + "\n \"classArgs\": " + classArgs;
427+
}
428+
req += "\n}";
429+
return req;
430+
}
431+
432+
// public static JSONObject removeComment(String json) {
433+
// return JSON.parseObject(removeComment(json));
434+
// }
435+
public static String removeComment(String json) {
436+
return json == null ? null: json.replaceAll("(//.*)|(/\\*[\\s\\S]*?\\*/)", "");
437+
}
438+
439+
295440

296441
public double plus(@NotNull JSONObject request, String i0, String i1) {
297442
return request.getDoubleValue(i0) + request.getDoubleValue(i1);

src/main/java/apijson/framework/APIJSONSQLExecutor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ public class APIJSONSQLExecutor extends AbstractSQLExecutor {
8989
Log.e(TAG, "加载 Oracle 驱动失败,请检查 pom.xml 中 com.oracle.jdbc 版本是否存在以及可用 !!!");
9090
}
9191

92+
try { //加载驱动程序
93+
Log.d(TAG, "尝试加载 DB2 驱动 <<<<<<<<<<<<<<<<<<<<< ");
94+
Class.forName("com.ibm.db2.jcc.DB2Driver");
95+
Log.d(TAG, "成功加载 DB2 驱动!>>>>>>>>>>>>>>>>>>>>> ");
96+
}
97+
catch (ClassNotFoundException e) {
98+
e.printStackTrace();
99+
Log.e(TAG, "加载 DB2 驱动失败,请检查 pom.xml 中 com.ibm.db2 版本是否存在以及可用 !!!");
100+
}
101+
92102
}
93103

94104

0 commit comments

Comments
 (0)