@@ -45,13 +45,15 @@ public class AbstractFunctionParser implements FunctionParser {
4545 private RequestMethod method ;
4646 private String tag ;
4747 private int version ;
48+ private JSONObject request ;
4849 public AbstractFunctionParser () {
49- this (null , null , 0 );
50+ this (null , null , 0 , null );
5051 }
51- public AbstractFunctionParser (RequestMethod method , String tag , int version ) {
52+ public AbstractFunctionParser (RequestMethod method , String tag , int version , @ NotNull JSONObject request ) {
5253 setMethod (method == null ? RequestMethod .GET : method );
5354 setTag (tag );
5455 setVersion (version );
56+ setRequest (request );
5557 }
5658
5759 @ Override
@@ -81,6 +83,62 @@ public AbstractFunctionParser setVersion(int version) {
8183 this .version = version ;
8284 return this ;
8385 }
86+
87+ private String key ;
88+ @ Override
89+ public String getKey () {
90+ return key ;
91+ }
92+ @ Override
93+ public AbstractFunctionParser setKey (String key ) {
94+ this .key = key ;
95+ return this ;
96+ }
97+
98+ private String parentPath ;
99+ @ Override
100+ public String getParentPath () {
101+ return parentPath ;
102+ }
103+ @ Override
104+ public AbstractFunctionParser setParentPath (String parentPath ) {
105+ this .parentPath = parentPath ;
106+ return this ;
107+ }
108+ private String currentName ;
109+ @ Override
110+ public String getCurrentName () {
111+ return currentName ;
112+ }
113+ @ Override
114+ public AbstractFunctionParser setCurrentName (String currentName ) {
115+ this .currentName = currentName ;
116+ return this ;
117+ }
118+
119+ @ NotNull
120+ @ Override
121+ public JSONObject getRequest () {
122+ return request ;
123+ }
124+ @ Override
125+ public AbstractFunctionParser setRequest (@ NotNull JSONObject request ) {
126+ this .request = request ;
127+ return this ;
128+ }
129+
130+ private JSONObject currentObject ;
131+ @ NotNull
132+ @ Override
133+ public JSONObject getCurrentObject () {
134+ return currentObject ;
135+ }
136+ @ Override
137+ public AbstractFunctionParser setCurrentObject (@ NotNull JSONObject currentObject ) {
138+ this .currentObject = currentObject ;
139+ return this ;
140+ }
141+
84142
85143 /**反射调用
86144 * @param function 例如get(object,key),参数只允许引用,不能直接传值
@@ -93,12 +151,12 @@ public Object invoke(@NotNull String function, @NotNull JSONObject currentObject
93151 }
94152
95153 /**反射调用
96- * @param fun
154+ * @param parser
97155 * @param request
98156 * @param function 例如get(Map:map,key),参数只允许引用,不能直接传值
99157 * @return {@link #invoke(AbstractFunctionParser, String, Class[], Object[])}
100158 */
101- public static Object invoke (@ NotNull AbstractFunctionParser fun , @ NotNull String function , @ NotNull JSONObject currentObject ) throws Exception {
159+ public static Object invoke (@ NotNull AbstractFunctionParser parser , @ NotNull String function , @ NotNull JSONObject currentObject ) throws Exception {
102160
103161 FunctionBean fb = parseFunction (function , currentObject , false );
104162
@@ -108,21 +166,21 @@ public static Object invoke(@NotNull AbstractFunctionParser fun, @NotNull String
108166 }
109167
110168 int v = row .getIntValue ("version" );
111- if (fun .getVersion () < v ) {
112- throw new UnsupportedOperationException ("不允许 version = " + fun .getVersion () + " 的请求调用远程函数 " + fb .getMethod () + " ! 必须满足 version >= " + v + " !" );
169+ if (parser .getVersion () < v ) {
170+ throw new UnsupportedOperationException ("不允许 version = " + parser .getVersion () + " 的请求调用远程函数 " + fb .getMethod () + " ! 必须满足 version >= " + v + " !" );
113171 }
114172 String t = row .getString ("tag" );
115- if (t != null && t .equals (fun .getTag ()) == false ) {
116- throw new UnsupportedOperationException ("不允许 tag = " + fun .getTag () + " 的请求调用远程函数 " + fb .getMethod () + " ! 必须满足 tag = " + t + " !" );
173+ if (t != null && t .equals (parser .getTag ()) == false ) {
174+ throw new UnsupportedOperationException ("不允许 tag = " + parser .getTag () + " 的请求调用远程函数 " + fb .getMethod () + " ! 必须满足 tag = " + t + " !" );
117175 }
118176 String [] methods = StringUtil .split (row .getString ("methods" ));
119177 List <String > ml = methods == null || methods .length <= 0 ? null : Arrays .asList (methods );
120- if (ml != null && ml .contains (fun .getMethod ().toString ()) == false ) {
121- throw new UnsupportedOperationException ("不允许 method = " + fun .getMethod () + " 的请求调用远程函数 " + fb .getMethod () + " ! 必须满足 method 在 " + methods + "内 !" );
178+ if (ml != null && ml .contains (parser .getMethod ().toString ()) == false ) {
179+ throw new UnsupportedOperationException ("不允许 method = " + parser .getMethod () + " 的请求调用远程函数 " + fb .getMethod () + " ! 必须满足 method 在 " + methods + "内 !" );
122180 }
123181
124182 try {
125- return invoke (fun , fb .getMethod (), fb .getTypes (), fb .getValues ());
183+ return invoke (parser , fb .getMethod (), fb .getTypes (), fb .getValues ());
126184 } catch (Exception e ) {
127185 if (e instanceof NoSuchMethodException ) {
128186 throw new IllegalArgumentException ("字符 " + function + " 对应的远程函数 " + getFunction (fb .getMethod (), fb .getKeys ()) + " 不在后端工程的DemoFunction内!"
@@ -143,6 +201,16 @@ public static Object invoke(@NotNull AbstractFunctionParser fun, @NotNull String
143201 }
144202
145203 }
204+
205+ /**反射调用
206+ * @param methodName
207+ * @param parameterTypes
208+ * @param args
209+ * @return
210+ */
211+ public static Object invoke (@ NotNull AbstractFunctionParser parser , @ NotNull String methodName , @ NotNull Class <?>[] parameterTypes , @ NotNull Object [] args ) throws Exception {
212+ return parser .getClass ().getMethod (methodName , parameterTypes ).invoke (parser , args );
213+ }
146214
147215 /**解析函数
148216 * @param function
@@ -231,16 +299,6 @@ else if (v instanceof JSONArray) { // Collection) {
231299 }
232300
233301
234- /**反射调用
235- * @param methodName
236- * @param parameterTypes
237- * @param args
238- * @return
239- */
240- public static Object invoke (@ NotNull AbstractFunctionParser fun , @ NotNull String methodName , @ NotNull Class <?>[] parameterTypes , @ NotNull Object [] args ) throws Exception {
241- return fun .getClass ().getMethod (methodName , parameterTypes ).invoke (fun , args );
242- }
243-
244302 /**
245303 * @param method
246304 * @param keys
0 commit comments