2222import static apijson .RequestMethod .POST ;
2323import static apijson .RequestMethod .PUT ;
2424import static apijson .framework .APIJSONConstant .FUNCTION_ ;
25+ import static apijson .framework .APIJSONConstant .SCRIPT_ ;
2526
2627import java .io .IOException ;
2728import java .rmi .ServerException ;
@@ -145,24 +146,94 @@ public static <T extends Object> JSONObject init(boolean shutdownWhenServerError
145146
146147 boolean isAll = table == null || table .isEmpty ();
147148
148- JSONObject function = isAll ? new JSONRequest () : table ;
149- if (Log .DEBUG == false ) {
150- function .put (APIJSONConstant .KEY_DEBUG , 0 );
151- }
152-
153- JSONRequest functionItem = new JSONRequest ();
154- functionItem .put (FUNCTION_ , function );
155-
156- JSONObject request = new JSONObject ();
157- request .putAll (functionItem .toArray (0 , 0 , FUNCTION_ ));
149+ //JSONObject function = isAll ? new JSONRequest() : table;
150+ //if (Log.DEBUG == false) {
151+ // function.put(APIJSONConstant.KEY_DEBUG, 0);
152+ //}
153+ //
154+ //JSONRequest functionItem = new JSONRequest();
155+ //functionItem.put(FUNCTION_, function);
156+ //
157+ //JSONObject script = isAll ? new JSONRequest() : table;
158+ ////if (Log.DEBUG == false) {
159+ //// script.put(APIJSONConstant.KEY_DEBUG, 0);
160+ ////}
161+ //{ // name{}@ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
162+ // JSONRequest nameInAt = new JSONRequest();
163+ // nameInAt.put("from", "Function");
164+ // { // Function <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
165+ // JSONRequest fun = new JSONRequest();
166+ // fun.setColumn("name");
167+ // nameInAt.put("Function", fun);
168+ // } // Function >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
169+ //
170+ // script.put("simple", 0);
171+ // script.put("name{}@", nameInAt);
172+ //} // name{}@ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
173+ //
174+ //JSONRequest scriptItem = new JSONRequest();
175+ //scriptItem.put(SCRIPT_, script);
176+ //
177+ JSONObject request = new JSONObject ();
178+ //request.putAll(functionItem.toArray(0, 0, FUNCTION_));
179+ //request.putAll(scriptItem.toArray(0, 0, SCRIPT_));
180+
181+ // TODO 用这个来优化
182+ { // [] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
183+ JSONRequest item = new JSONRequest ();
184+
185+ { // Function <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
186+ JSONObject function = isAll ? new JSONRequest () : table ;
187+ if (Log .DEBUG == false ) {
188+ function .put (APIJSONConstant .KEY_DEBUG , 0 );
189+ }
190+ item .put ("Function" , function );
191+ } // Function >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
192+
193+ { // Script <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
194+ JSONRequest script = new JSONRequest ();
195+ script .put ("name@" , "/Function/name" );
196+ script .put ("simple" , 0 );
197+ item .put ("Script" , script );
198+ } // Script >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
199+
200+ request .putAll (item .toArray (0 , 0 ));
201+ } // [] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
158202
159203
160204 JSONObject response = creator .createParser ().setMethod (GET ).setNeedVerify (true ).parseResponse (request );
161205 if (JSONResponse .isSuccess (response ) == false ) {
162206 onServerError ("\n \n \n \n \n !!!! 查询远程函数异常 !!!\n " + response .getString (JSONResponse .KEY_MSG ) + "\n \n \n \n \n " , shutdownWhenServerError );
163207 }
164208
165- JSONArray list = response .getJSONArray (FUNCTION_ + "[]" );
209+ JSONArray scriptList = response .getJSONArray ("[]" ); // .getJSONArray(SCRIPT_ + "[]");
210+ if (scriptList != null && scriptList .isEmpty () == false ) {
211+ if (isAll ) {
212+ SCRIPT_MAP = new LinkedHashMap <>();
213+ }
214+
215+ for (int i = 0 ; i < scriptList .size (); i ++) {
216+ JSONObject item = scriptList .getJSONObject (i );
217+ item = item == null ? null : item .getJSONObject (SCRIPT_ );
218+ if (item == null ) {
219+ continue ;
220+ }
221+
222+ String n = item == null ? null : item .getString ("name" );
223+ if (StringUtil .isName (n ) == false ) {
224+ onServerError ("Script 表字段 name 的值 " + n + " 不合法!必须为合法的方法名字符串!" , shutdownWhenServerError );
225+ }
226+
227+ String s = item == null ? null : item .getString ("script" );
228+ if (StringUtil .isEmpty (s , true )) {
229+ onServerError ("Script 表字段 script 的值 " + s + " 不合法!不能为空!" , shutdownWhenServerError );
230+ }
231+
232+ SCRIPT_MAP .put (n , item );
233+ }
234+ }
235+
236+ JSONArray list = scriptList ; // response.getJSONArray(FUNCTION_ + "[]");
166237 int size = list == null ? 0 : list .size ();
167238 if (isAll && size <= 0 ) {
168239 Log .w (TAG , "init isAll && size <= 0,,没有可用的远程函数" );
@@ -177,6 +248,7 @@ public static <T extends Object> JSONObject init(boolean shutdownWhenServerError
177248
178249 for (int i = 0 ; i < size ; i ++) {
179250 JSONObject item = list .getJSONObject (i );
251+ item = item == null ? null : item .getJSONObject (FUNCTION_ );
180252 if (item == null ) {
181253 continue ;
182254 }
0 commit comments