util.collections.DefaultOrderComparator;org.json.simple.JSONArray;org.json.simple.JSONObject;org.json.simple.parser.JSONParser;java.util.*;
/ **
* Date: 29.03.13
* Time: 3:22
*
* @ author DoSOfRR
* / class Parser {static final String KEY_METHODNAME=«methodName»; static final String KEY_PARAMS=«params»; static MethodStruct parseRequest (String query) throws Exception { strParams=new TreeMap (new DefaultOrderComparator ()); parser=new JSONParser (); methodName; params; jsonObject=(JSONObject) parser.parse (query);
/ / get method name from request=(String) jsonObject.get (KEY_METHODNAME);
/ / get params from requestja=(JSONArray) jsonObject.get (KEY_PARAMS); (Object param: ja) {. put (
(String) ((JSONObject) param). get («type»),
(String) ((JSONObject) param). get («value»)
);
}
/ / get classes from strings [] classes=getClasses (strParams.keySet ());
/ / get parameters=getInstances (getMap (classes, strParams.values ??())); new MethodStruct (methodName, params, classes);
} static Class [] getClasses (Set classNames) throws ClassNotFoundException {[] result=new Class [classNames.size ()]; i=0; (String name: classNames) {( name) {«int» : Result [i]=int.class; break; «long» : Result [i]=long.class; break; «boolean» : Result [i]=boolean.class; break;: result [i]=Class.forName (name);
} + +;
} result;
} static Set getInstances (Map args) throws Exception {result=new TreeSet (new DefaultOrderComparator ()); (Map.Entry entry: args.entrySet ( )) {(entry.getKey (). toString ()) {«boolean» : Result.add (Boolean.parseBoolean (entry.getValue ())); break; «long» : Result.add (Long.parseLong (entry.getValue ())); break; «int» : Result.add (Integer.parseInt (entry.getValue ())); break;: result.add (getInstance (entry.getKey (), entry.getValue ()));
}
} result;
} static T getInstance (Class tClass, String value) throws Exception {(T) tClass.getConstructor (String.class). NewInstance (value);
} static Map getMap (Class [] classes, Collection values) { result=new TreeMap (new DefaultOrderComparator ()); i=0; (String value: values) {. put (classes [i], value); + +;
} result;
}
} com.gmail.dosofredriver.ajax.serviceserver.util.view;
/ **
* Date: 07.03.13
* Time: 22:32
*
* @ author DoSOfRR
* / enum Commands {_Server, Stop_Server, Restart_Server, SwitchOFF_Server, Deploy, Undeploy, Help, Undefined, Exit
}com.gmail.dosofredriver.ajax.serviceserver.util.view;sun.reflect.generics.reflectiveObjects.NotImplementedException;java.io.IOException;java.io.OutputStream;
/ **
* Date: 07.03.13