private String generateJSONResult(MapService mapService) {
String result = null;
try {
MapDesc mapDesc = mapService.getMapDesc();
MapServiceDesc mapServiceDesc = mapService.getMapServiceDesc();
String mapName = mapDesc.getName();
JSONObject obj = new JSONObject();
JSONObject objSR = null;
JSONObject objTemp = null;
JSONObject objTemp2 = null;
JSONArray arrayTemp = null;
obj.put("GIServerVersion", VersionUtil.getCurrentversion());
obj.put("name", mapName);
obj.put("maxInstances", mapServiceDesc.getMaxInstances());
obj.put("maxResults", mapServiceDesc.getMaxResults());
arrayTemp = new JSONArray();
for (int i = 0, count = mapDesc.getLayerInfos().size(); i < count; i++) {
LayerInfo layerInfo = mapDesc.getLayerInfo(i);
objTemp = new JSONObject();
objTemp.put("id", i);
objTemp.put("name", layerInfo.getName());
objTemp.put("defaultVisibility", layerInfo.isVisible());
objTemp.put("editable", layerInfo.isEditable());
arrayTemp.put(objTemp);
}
obj.put("layers", arrayTemp);
objSR = new JSONObject();
try {
Integer.parseInt(mapDesc.getWkid());
objSR.put("wkid", Integer.valueOf(mapDesc.getWkid()));
} catch (NumberFormatException e) {
objSR.put("wkid", mapDesc.getWkid());
}
obj.put("spatialReference", objSR);
objTemp = new JSONObject();
Envelope initialExtent = mapDesc.getInitialExtent();
objTemp.put("xmin", initialExtent.getMinX());
objTemp.put("xmax", initialExtent.getMaxX());
objTemp.put("ymin", initialExtent.getMinY());
objTemp.put("ymax", initialExtent.getMaxY());
objTemp.put("spatialReference", objSR);