aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-06 14:08:06 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-06 14:08:06 +0000
commitaeadc1f9129274949daaa57738c7c4550bdfbc7b (patch)
tree08dadf5ef7474fc41d1d48f74648f1ba8b55f34d /sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers
downloadsonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.tar.gz
sonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.zip
SONAR-236 remove deprecated code from checkstyle plugin + display default value of rule parameters in Q profile console
Diffstat (limited to 'sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/AbstractUnmarshaller.java58
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshaller.java54
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshaller.java42
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/EventUnmarshaller.java38
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/FavouriteUnmarshaller.java37
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/JsonUtils.java94
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/MetricUnmarshaller.java39
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshaller.java33
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshaller.java90
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java42
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/SourceUnmarshaller.java40
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshaller.java32
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java50
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java49
14 files changed, 698 insertions, 0 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/AbstractUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/AbstractUnmarshaller.java
new file mode 100644
index 00000000000..d906f4ad9d8
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/AbstractUnmarshaller.java
@@ -0,0 +1,58 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
+import org.sonar.wsclient.services.Model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AbstractUnmarshaller<MODEL extends Model> implements Unmarshaller<MODEL> {
+
+ public final MODEL toModel(String json) {
+ MODEL result = null;
+ JSONArray array = (JSONArray) JSONValue.parse(json);
+ if (array.size() >= 1) {
+ JSONObject elt = (JSONObject) array.get(0);
+ if (elt != null) {
+ result = parse(elt);
+ }
+ }
+ return result;
+
+ }
+
+ public final List<MODEL> toModels(String json) {
+ List<MODEL> result = new ArrayList<MODEL>();
+ JSONArray array = (JSONArray) JSONValue.parse(json);
+ for (Object anArray : array) {
+ JSONObject elt = (JSONObject) anArray;
+ if (elt != null) {
+ result.add(parse(elt));
+ }
+ }
+ return result;
+ }
+
+ protected abstract MODEL parse(JSONObject elt);
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshaller.java
new file mode 100644
index 00000000000..f326ba02176
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyTreeUnmarshaller.java
@@ -0,0 +1,54 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.DependencyTree;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DependencyTreeUnmarshaller extends AbstractUnmarshaller<DependencyTree> {
+ @Override
+ protected DependencyTree parse(JSONObject json) {
+ DependencyTree tree = new DependencyTree()
+ .setDepId(JsonUtils.getString(json, "did"))
+ .setResourceId(JsonUtils.getString(json, "rid"))
+ .setResourceKey(JsonUtils.getString(json, "k"))
+ .setResourceName(JsonUtils.getString(json, "n"))
+ .setResourceScope(JsonUtils.getString(json, "s"))
+ .setResourceQualifier(JsonUtils.getString(json, "q"))
+ .setResourceVersion(JsonUtils.getString(json, "v"))
+ .setUsage(JsonUtils.getString(json, "u"))
+ .setWeight(JsonUtils.getInteger(json, "w"));
+
+ List<DependencyTree> to = new ArrayList<DependencyTree>();
+ tree.setTo(to);
+
+ JSONArray toJson = (JSONArray) json.get("to");
+ if (toJson != null) {
+ for (Object aToJson : toJson) {
+ to.add(parse((JSONObject) aToJson));
+ }
+ }
+ return tree;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshaller.java
new file mode 100644
index 00000000000..803753aede7
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/DependencyUnmarshaller.java
@@ -0,0 +1,42 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Dependency;
+
+public class DependencyUnmarshaller extends AbstractUnmarshaller<Dependency> {
+
+ @Override
+ protected Dependency parse(JSONObject json) {
+ return new Dependency()
+ .setId(JsonUtils.getString(json, "id"))
+ .setFromId(JsonUtils.getLong(json, "fi"))
+ .setToId(JsonUtils.getLong(json, "ti"))
+ .setFromKey(JsonUtils.getString(json, "fk"))
+ .setToKey(JsonUtils.getString(json, "tk"))
+ .setUsage(JsonUtils.getString(json, "u"))
+ .setWeight(JsonUtils.getInteger(json, "w"))
+ .setFromName(JsonUtils.getString(json, "fn"))
+ .setFromQualifier(JsonUtils.getString(json, "fq"))
+ .setToName(JsonUtils.getString(json, "tn"))
+ .setToQualifier(JsonUtils.getString(json, "tq"));
+ }
+} \ No newline at end of file
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/EventUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/EventUnmarshaller.java
new file mode 100644
index 00000000000..2f7878e55ef
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/EventUnmarshaller.java
@@ -0,0 +1,38 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Event;
+
+public class EventUnmarshaller extends AbstractUnmarshaller<Event> {
+
+ @Override
+ protected Event parse(JSONObject json) {
+ return new Event()
+ .setId(JsonUtils.getString(json, "id"))
+ .setResourceKey(JsonUtils.getString(json, "rk"))
+ .setName(JsonUtils.getString(json, "n"))
+ .setCategory(JsonUtils.getString(json, "c"))
+ .setDate(JsonUtils.getDateTime(json, "dt"))
+ .setDescription(JsonUtils.getString(json, "ds"))
+ .setData(JsonUtils.getString(json, "data"));
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/FavouriteUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/FavouriteUnmarshaller.java
new file mode 100644
index 00000000000..ab93ef28082
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/FavouriteUnmarshaller.java
@@ -0,0 +1,37 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Favourite;
+
+public class FavouriteUnmarshaller extends AbstractUnmarshaller<Favourite> {
+
+ @Override
+ protected Favourite parse(JSONObject json) {
+ return new Favourite()
+ .setId(JsonUtils.getInteger(json, "id"))
+ .setKey(JsonUtils.getString(json, "key"))
+ .setName(JsonUtils.getString(json, "name"))
+ .setScope(JsonUtils.getString(json, "scope"))
+ .setQualifier(JsonUtils.getString(json, "qualifier"))
+ .setLanguage(JsonUtils.getString(json, "lang"));
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/JsonUtils.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/JsonUtils.java
new file mode 100644
index 00000000000..598812dc7e7
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/JsonUtils.java
@@ -0,0 +1,94 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+
+public final class JsonUtils {
+
+ private JsonUtils() {
+ // only static methods
+ }
+
+ public static String getString(Map obj, String field) {
+ Object value = obj.get(field);
+ if (value != null) {
+ return (String) value;
+ }
+ return null;
+ }
+
+ public static Integer getInteger(Map obj, String field) {
+ Object value = obj.get(field);
+ if (value != null) {
+ return ((Long) value).intValue();
+ }
+ return null;
+ }
+
+ public static Boolean getBoolean(Map obj, String field) {
+ Object value = obj.get(field);
+ if (value != null) {
+ return (Boolean)value;
+ }
+ return null;
+ }
+
+ public static Long getLong(Map obj, String field) {
+ Object value = obj.get(field);
+ if (value != null) {
+ return (Long) value;
+ }
+ return null;
+ }
+
+ public static Double getDouble(Map obj, String field) {
+ Object value = obj.get(field);
+ if (value != null) {
+ return (Double) value;
+ }
+ return null;
+ }
+
+ public static Date getDateTime(Map obj, String field) {
+ return parseDate(obj, field, "yyyy-MM-dd'T'HH:mm:ssZ");
+ }
+
+ public static Date getDate(Map obj, String field) {
+ return parseDate(obj, field, "yyyy-MM-dd");
+ }
+
+ private static Date parseDate(Map obj, String field, String format) {
+ String value = getString(obj, field);
+ if (value != null) {
+ try {
+ SimpleDateFormat dateFormat = new SimpleDateFormat(format);
+ return dateFormat.parse(value);
+
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return null;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/MetricUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/MetricUnmarshaller.java
new file mode 100644
index 00000000000..d90101b833d
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/MetricUnmarshaller.java
@@ -0,0 +1,39 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Metric;
+
+public class MetricUnmarshaller extends AbstractUnmarshaller<Metric> {
+
+ @Override
+ protected Metric parse(JSONObject json) {
+ return new Metric()
+ .setKey((String) json.get("key"))
+ .setName((String) json.get("name"))
+ .setDomain((String) json.get("domain"))
+ .setDescription((String) json.get("description"))
+ .setDirection(JsonUtils.getInteger(json, "direction"))
+ .setType(JsonUtils.getString(json, "val_type"))
+ .setUserManaged(JsonUtils.getBoolean(json, "user_managed"))
+ .setHidden(JsonUtils.getBoolean(json, "hidden"));
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshaller.java
new file mode 100644
index 00000000000..cf71b47c32b
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PropertyUnmarshaller.java
@@ -0,0 +1,33 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Property;
+
+public class PropertyUnmarshaller extends AbstractUnmarshaller<Property> {
+
+ @Override
+ protected Property parse(JSONObject json) {
+ return new Property()
+ .setKey((String) json.get("key"))
+ .setValue((String) json.get("value"));
+ }
+} \ No newline at end of file
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshaller.java
new file mode 100644
index 00000000000..87a31147a9f
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ResourceUnmarshaller.java
@@ -0,0 +1,90 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Measure;
+import org.sonar.wsclient.services.Resource;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ResourceUnmarshaller extends AbstractUnmarshaller<Resource> {
+
+ @Override
+ protected Resource parse(JSONObject json) {
+ Resource resource = new Resource();
+ parseResourceFields(json, resource);
+ parseMeasures(json, resource);
+ return resource;
+ }
+
+ private void parseResourceFields(JSONObject json, Resource resource) {
+ resource.setId(JsonUtils.getInteger(json, "id"))
+ .setKey(JsonUtils.getString(json, "key"))
+ .setName(JsonUtils.getString(json, "name"))
+ .setLongName(JsonUtils.getString(json, "lname"))
+ .setScope(JsonUtils.getString(json, "scope"))
+ .setQualifier(JsonUtils.getString(json, "qualifier"))
+ .setLanguage(JsonUtils.getString(json, "lang"))
+ .setDescription(JsonUtils.getString(json, "description"))
+ .setVersion(JsonUtils.getString(json, "version"));
+ }
+
+ private void parseMeasures(JSONObject json, Resource resource) {
+ JSONArray measuresJson = (JSONArray) json.get("msr");
+ if (measuresJson != null) {
+ resource.setMeasures(parseMeasures(measuresJson));
+ }
+ }
+
+ private List<Measure> parseMeasures(JSONArray measuresJson) {
+ List<Measure> projectMeasures = new ArrayList<Measure>();
+ int len = measuresJson.size();
+ for (int i = 0; i < len; i++) {
+ JSONObject measureJson = (JSONObject) measuresJson.get(i);
+ if (measureJson != null) {
+ Measure measure = parseMeasure(measureJson);
+ projectMeasures.add(measure);
+ }
+ }
+ return projectMeasures;
+ }
+
+ private Measure parseMeasure(JSONObject json) {
+ Measure measure = new Measure();
+ measure
+ .setMetricKey(JsonUtils.getString(json, "key"))
+ .setMetricName(JsonUtils.getString(json, "name"))
+ .setValue(JsonUtils.getDouble(json, "val"))
+ .setFormattedValue(JsonUtils.getString(json, "frmt_val"))
+ .setTrend(JsonUtils.getInteger(json, "trend"))
+ .setVar(JsonUtils.getInteger(json, "var"))
+ .setData(JsonUtils.getString(json, "data"))
+ .setRuleKey(JsonUtils.getString(json, "rule_key"))
+ .setRuleName(JsonUtils.getString(json, "rule_name"))
+ .setRuleCategory(JsonUtils.getString(json, "rule_category"))
+ .setRulePriority(JsonUtils.getString(json, "rule_priority"))
+ .setCharacteristicKey(JsonUtils.getString(json, "ctic_key"))
+ .setCharacteristicName(JsonUtils.getString(json, "ctic_name"));
+ return measure;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java
new file mode 100644
index 00000000000..d980876e3f8
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java
@@ -0,0 +1,42 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
+import org.sonar.wsclient.services.Server;
+
+import java.util.List;
+
+/**
+ * @author Evgeny Mandrikov
+ */
+public class ServerUnmarshaller implements Unmarshaller<Server> {
+ public Server toModel(String json) {
+ JSONObject map = (JSONObject) JSONValue.parse(json);
+ return new Server()
+ .setId(JsonUtils.getString(map, "id"))
+ .setVersion(JsonUtils.getString(map, "version"));
+ }
+
+ public List<Server> toModels(String json) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/SourceUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/SourceUnmarshaller.java
new file mode 100644
index 00000000000..cbda6b4c5d0
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/SourceUnmarshaller.java
@@ -0,0 +1,40 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Source;
+
+import java.util.Map;
+
+public class SourceUnmarshaller extends AbstractUnmarshaller<Source> {
+
+ @Override
+ protected Source parse(JSONObject json) {
+ Source source = new Source();
+
+ for (Object o : json.entrySet()) {
+ Map.Entry<String, String> entry = (Map.Entry<String, String>) o;
+ source.addLine(Integer.parseInt(entry.getKey()), entry.getValue());
+ }
+
+ return source;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshaller.java
new file mode 100644
index 00000000000..bed74add09a
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshaller.java
@@ -0,0 +1,32 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.sonar.wsclient.services.Model;
+
+import java.util.List;
+
+public interface Unmarshaller<MODEL extends Model> {
+
+ MODEL toModel(String json);
+
+ List<MODEL> toModels(String json);
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java
new file mode 100644
index 00000000000..3523f1ce836
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java
@@ -0,0 +1,50 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.sonar.wsclient.services.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public final class Unmarshallers {
+ private Unmarshallers() {
+ }
+
+ private static Map<Class, Unmarshaller> unmarshallers;
+
+ static {
+ unmarshallers = new HashMap<Class, Unmarshaller>();
+ unmarshallers.put(Metric.class, new MetricUnmarshaller());
+ unmarshallers.put(Dependency.class, new DependencyUnmarshaller());
+ unmarshallers.put(Resource.class, new ResourceUnmarshaller());
+ unmarshallers.put(Property.class, new PropertyUnmarshaller());
+ unmarshallers.put(Source.class, new SourceUnmarshaller());
+ unmarshallers.put(Violation.class, new ViolationUnmarshaller());
+ unmarshallers.put(Server.class, new ServerUnmarshaller());
+ unmarshallers.put(DependencyTree.class, new DependencyTreeUnmarshaller());
+ unmarshallers.put(Event.class, new EventUnmarshaller());
+ unmarshallers.put(Favourite.class, new FavouriteUnmarshaller());
+ }
+
+ public static <MODEL extends Model> Unmarshaller<MODEL> forModel(Class<MODEL> modelClass) {
+ return unmarshallers.get(modelClass);
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java
new file mode 100644
index 00000000000..ab8a91fa96a
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java
@@ -0,0 +1,49 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Violation;
+
+public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> {
+
+ @Override
+ protected Violation parse(JSONObject json) {
+ Violation violation = new Violation();
+ violation.setMessage(JsonUtils.getString(json, "message"));
+ violation.setLine(JsonUtils.getInteger(json, "line"));
+ violation.setPriority(JsonUtils.getString(json, "priority"));
+
+ JSONObject rule = (JSONObject)json.get("rule");
+ if (rule!=null) {
+ violation.setRuleKey(JsonUtils.getString(rule, "key"));
+ violation.setRuleName(JsonUtils.getString(rule, "name"));
+ }
+
+ JSONObject resource = (JSONObject)json.get("resource");
+ if (resource!=null) {
+ violation.setResourceKey(JsonUtils.getString(resource, "key"));
+ violation.setResourceName(JsonUtils.getString(resource, "name"));
+ violation.setResourceQualifier(JsonUtils.getString(resource, "qualifier"));
+ violation.setResourceScope(JsonUtils.getString(resource, "scope"));
+ }
+ return violation;
+ }
+}