public static String interfaceToSmd20(Class<?> klazz, String serviceUrl) {
try {
String name = klazz.getSimpleName();
Method[] methods = klazz.getMethods();
JSONObject smd = new JSONObject();
smd.put("SMDVersion", "2.0");
smd.put("transport", "POST");
smd.put("envelope", "JSON-RPC-1.0");
smd.put("target", serviceUrl);
smd.put("id", klazz.getName());
smd.put("description", "JSON-RPC service provided by Tuscany: " + name);
JSONObject services = new JSONObject();
for (int i = 0; i < methods.length; i++) {
JSONObject service = new JSONObject();
Class<?>[] params = methods[i].getParameterTypes();
JSONArray paramArray = new JSONArray();
for (int j = 0; j < params.length; j++) {
JSONObject param = new JSONObject();
param.put("name", "param" + j);
param.put("type", getJSONType(params[j]));
paramArray.put(param);
}
service.put("parameters", paramArray);
services.put(methods[i].getName(), service);
}