aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-gwt-api
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-01-26 19:21:54 +0300
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-01-27 17:11:11 +0300
commit815899837ca07904fe9dc9223b4a4e8ac486cb59 (patch)
treeb92834ad5dd92bdd9eb8504e8bd649e81e559d41 /sonar-gwt-api
parent40e0e78a54535e1a5009a626fb43dccad9230328 (diff)
downloadsonarqube-815899837ca07904fe9dc9223b4a4e8ac486cb59.tar.gz
sonarqube-815899837ca07904fe9dc9223b4a4e8ac486cb59.zip
SONAR-2046: Reuse unmarshallers from sonar-ws-client for sonar-gwt-api
* WSUtils has two implementations - one for GWT and another for Java, so can be used by unmarshallers in both cases. But this not very good, because code is not type-safe. In fact it would be better to use emulation of types from org.json.simple for GWT, but this solution is more straightforward.
Diffstat (limited to 'sonar-gwt-api')
-rw-r--r--sonar-gwt-api/pom.xml2
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/gwt/ui/Page.java24
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/GwtUtils.java65
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/Sonar.java15
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/AbstractUnmarshaller.java53
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/DependencyTreeUnmarshaller.java55
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/DependencyUnmarshaller.java42
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/EventUnmarshaller.java38
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/MetricUnmarshaller.java39
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/PropertyUnmarshaller.java33
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java100
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ServerUnmarshaller.java49
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/SourceUnmarshaller.java42
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java45
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/Unmarshaller.java33
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/Unmarshallers.java55
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java50
17 files changed, 91 insertions, 649 deletions
diff --git a/sonar-gwt-api/pom.xml b/sonar-gwt-api/pom.xml
index 7f60b4adf39..1b0e10f2544 100644
--- a/sonar-gwt-api/pom.xml
+++ b/sonar-gwt-api/pom.xml
@@ -66,7 +66,7 @@
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
- <includes>**/services/*.java</includes>
+ <includes>**/services/*.java,**/unmarshallers/*.java</includes>
</artifactItem>
</artifactItems>
<overWriteReleases>true</overWriteReleases>
diff --git a/sonar-gwt-api/src/main/java/org/sonar/gwt/ui/Page.java b/sonar-gwt-api/src/main/java/org/sonar/gwt/ui/Page.java
index 94b2785f6e9..ccd7ad4ed04 100644
--- a/sonar-gwt-api/src/main/java/org/sonar/gwt/ui/Page.java
+++ b/sonar-gwt-api/src/main/java/org/sonar/gwt/ui/Page.java
@@ -22,13 +22,18 @@ package org.sonar.gwt.ui;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.json.client.JSONObject;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
-import org.sonar.wsclient.gwt.unmarshallers.ResourceUnmarshaller;
+import org.sonar.wsclient.gwt.GwtUtils;
import org.sonar.wsclient.services.Resource;
+import org.sonar.wsclient.services.WSUtils;
+import org.sonar.wsclient.unmarshallers.ResourceUnmarshaller;
public abstract class Page implements EntryPoint {
+ private static final ResourceUnmarshaller RESOURCE_UNMARSHALLER = new ResourceUnmarshaller();
+
private Widget currentWidget = null;
private Integer currentResourceId = null;
@@ -40,7 +45,7 @@ public abstract class Page implements EntryPoint {
private void load() {
Widget widget = doOnModuleLoad();
- if (widget!=null) {
+ if (widget != null) {
getRootPanel().add(widget);
}
}
@@ -52,7 +57,11 @@ public abstract class Page implements EntryPoint {
public final void onResourceLoad() {
JavaScriptObject json = loadResource();
if (json != null) {
- Resource resource = ResourceUnmarshaller.getInstance().toModel(json);
+ if (WSUtils.getINSTANCE() == null) {
+ WSUtils.setInstance(new GwtUtils()); // TODO dirty hack to initialize WSUtils
+ }
+ String jsonStr = (new JSONObject(json)).toString();
+ Resource resource = RESOURCE_UNMARSHALLER.toModel(jsonStr);
RootPanel container = getRootPanel();
container.clear();
@@ -82,11 +91,10 @@ public abstract class Page implements EntryPoint {
}
private native JavaScriptObject loadResource()/*-{
- return $wnd.config['resource'];
- }-*/;
+ return $wnd.config['resource'];
+ }-*/;
private native void export(String gwtId, Page page)/*-{
- $wnd.modules[gwtId]=function() {page.@org.sonar.gwt.ui.Page::onResourceLoad()()};
- }-*/;
+ $wnd.modules[gwtId]=function() {page.@org.sonar.gwt.ui.Page::onResourceLoad()()};
+ }-*/;
}
-
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/GwtUtils.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/GwtUtils.java
index 8fc7df08fb6..ddeeb92d990 100644
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/GwtUtils.java
+++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/GwtUtils.java
@@ -20,9 +20,14 @@
package org.sonar.wsclient.gwt;
import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONParser;
+import com.google.gwt.json.client.JSONValue;
+import org.sonar.gwt.JsonUtils;
import org.sonar.wsclient.services.WSUtils;
import java.util.Date;
+import java.util.Set;
public class GwtUtils extends WSUtils {
@Override
@@ -34,4 +39,64 @@ public class GwtUtils extends WSUtils {
public String encodeUrl(String url) {
return com.google.gwt.http.client.URL.encode(url);
}
+
+ @Override
+ public Object getField(Object json, String field) {
+ return ((JSONObject) json).get(field);
+ }
+
+ @Override
+ public String getString(Object json, String field) {
+ return JsonUtils.getString((JSONObject) json, field);
+ }
+
+ @Override
+ public Boolean getBoolean(Object json, String field) {
+ return JsonUtils.getBoolean((JSONObject) json, field);
+ }
+
+ @Override
+ public Integer getInteger(Object json, String field) {
+ return JsonUtils.getInteger((JSONObject) json, field);
+ }
+
+ @Override
+ public Double getDouble(Object json, String field) {
+ return JsonUtils.getDouble((JSONObject) json, field);
+ }
+
+ @Override
+ public Long getLong(Object json, String field) {
+ Double d = JsonUtils.getDouble((JSONObject) json, field);
+ if (d != null) {
+ return d.longValue();
+ }
+ return null;
+ }
+
+ @Override
+ public Date getDateTime(Object json, String field) {
+ return JsonUtils.getDate((JSONObject) json, field);
+ }
+
+ @Override
+ public int getArraySize(Object array) {
+ return JsonUtils.getArraySize((JSONValue) array);
+ }
+
+ @Override
+ public Object getArrayElement(Object array, int i) {
+ return JsonUtils.getArray((JSONValue) array, i);
+ }
+
+ @Override
+ public Object parse(String jsonStr) {
+ return JSONParser.parse(jsonStr);
+ }
+
+ @Override
+ public Set<String> getFields(Object json) {
+ return ((JSONObject) json).keySet();
+ }
+
}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/Sonar.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/Sonar.java
index 33f404dd551..916b086d01a 100644
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/Sonar.java
+++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/Sonar.java
@@ -21,18 +21,19 @@ package org.sonar.wsclient.gwt;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.i18n.client.Dictionary;
+import com.google.gwt.json.client.JSONObject;
import org.sonar.gwt.JsonUtils;
-import org.sonar.wsclient.gwt.unmarshallers.Unmarshaller;
-import org.sonar.wsclient.gwt.unmarshallers.Unmarshallers;
import org.sonar.wsclient.services.Model;
import org.sonar.wsclient.services.Query;
import org.sonar.wsclient.services.WSUtils;
+import org.sonar.wsclient.unmarshallers.Unmarshaller;
+import org.sonar.wsclient.unmarshallers.Unmarshallers;
public class Sonar {
static {
WSUtils.setInstance(new GwtUtils());
}
-
+
private static Sonar instance = null;
private final String host;
@@ -56,7 +57,8 @@ public class Sonar {
JsonUtils.requestJson(getUrl(query), new JsonUtils.JSONHandler() {
public void onResponse(JavaScriptObject obj) {
Unmarshaller<MODEL> unmarshaller = Unmarshallers.forModel(query.getModelClass());
- callback.onResponse(unmarshaller.toModel(obj), obj);
+ String json = (new JSONObject(obj)).toString();
+ callback.onResponse(unmarshaller.toModel(json), obj);
}
public void onTimeout() {
@@ -73,7 +75,8 @@ public class Sonar {
JsonUtils.requestJson(getUrl(query), new JsonUtils.JSONHandler() {
public void onResponse(JavaScriptObject obj) {
Unmarshaller<MODEL> unmarshaller = Unmarshallers.forModel(query.getModelClass());
- callback.onResponse(unmarshaller.toModels(obj), obj);
+ String json = (new JSONObject(obj)).toString();
+ callback.onResponse(unmarshaller.toModels(json), obj);
}
public void onTimeout() {
@@ -89,4 +92,4 @@ public class Sonar {
private String getUrl(Query query) {
return host + query.getUrl();
}
-} \ No newline at end of file
+}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/AbstractUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/AbstractUnmarshaller.java
deleted file mode 100644
index a7a6f835a85..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/AbstractUnmarshaller.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.gwt.unmarshallers;
-
-import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONObject;
-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(JavaScriptObject json) {
- JSONArray array = new JSONArray(json);
- if (array.size() >= 1) {
- JSONObject elt = array.get(0).isObject();
- return parse(elt);
- }
- return null;
- }
-
- public final List<MODEL> toModels(JavaScriptObject json) {
- List<MODEL> result = new ArrayList<MODEL>();
- JSONArray array = new JSONArray(json);
- for (int i = 0; i < array.size(); i++) {
- JSONObject elt = array.get(i).isObject();
- if (elt != null) {
- result.add(parse(elt));
- }
- }
- return result;
- }
-
- protected abstract MODEL parse(JSONObject json);
-}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/DependencyTreeUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/DependencyTreeUnmarshaller.java
deleted file mode 100644
index c7c3bb3d29e..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/DependencyTreeUnmarshaller.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.gwt.unmarshallers;
-
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONObject;
-import org.sonar.gwt.JsonUtils;
-import org.sonar.wsclient.services.DependencyTree;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class DependencyTreeUnmarshaller extends AbstractUnmarshaller<DependencyTree> {
-
- 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 (int index = 0; index < toJson.size(); index++) {
- to.add(parse((JSONObject) toJson.get(index)));
- }
- }
- return tree;
- }
-}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/DependencyUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/DependencyUnmarshaller.java
deleted file mode 100644
index 76dd2397eba..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/DependencyUnmarshaller.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.gwt.unmarshallers;
-
-import com.google.gwt.json.client.JSONObject;
-import org.sonar.gwt.JsonUtils;
-import org.sonar.wsclient.services.Dependency;
-
-public class DependencyUnmarshaller extends AbstractUnmarshaller<Dependency> {
-
- protected Dependency parse(JSONObject json) {
- return new Dependency()
- .setId(JsonUtils.getString(json, "id"))
- .setFromId(JsonUtils.getDouble(json, "fi").longValue())
- .setToId(JsonUtils.getDouble(json, "ti").longValue())
- .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"));
- }
-}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/EventUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/EventUnmarshaller.java
deleted file mode 100644
index bd7ca08aa75..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/EventUnmarshaller.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.gwt.unmarshallers;
-
-import com.google.gwt.json.client.JSONObject;
-import org.sonar.gwt.JsonUtils;
-import org.sonar.wsclient.services.Event;
-
-public class EventUnmarshaller extends AbstractUnmarshaller<Event> {
-
- 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.getDate(json, "dt"))
- .setDescription(JsonUtils.getString(json, "ds"))
- .setData(JsonUtils.getString(json, "data"));
- }
-}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/MetricUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/MetricUnmarshaller.java
deleted file mode 100644
index 283f5fe19a9..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/MetricUnmarshaller.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.gwt.unmarshallers;
-
-import com.google.gwt.json.client.JSONObject;
-import org.sonar.gwt.JsonUtils;
-import org.sonar.wsclient.services.Metric;
-
-public class MetricUnmarshaller extends AbstractUnmarshaller<Metric> {
-
- protected Metric parse(JSONObject json) {
- return new Metric()
- .setKey(JsonUtils.getString(json, "key"))
- .setName(JsonUtils.getString(json, "name"))
- .setDomain(JsonUtils.getString(json, "domain"))
- .setDescription(JsonUtils.getString(json, "description"))
- .setDirection(JsonUtils.getInteger(json, "direction"))
- .setType(JsonUtils.getString(json, "val_type"))
- .setHidden(JsonUtils.getBoolean(json, "hidden"))
- .setUserManaged(JsonUtils.getBoolean(json, "user_managed"));
- }
-}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/PropertyUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/PropertyUnmarshaller.java
deleted file mode 100644
index 3ff7931a1c8..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/PropertyUnmarshaller.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.gwt.unmarshallers;
-
-import com.google.gwt.json.client.JSONObject;
-import org.sonar.gwt.JsonUtils;
-import org.sonar.wsclient.services.Property;
-
-public class PropertyUnmarshaller extends AbstractUnmarshaller<Property> {
-
- protected Property parse(JSONObject json) {
- return new Property()
- .setKey(JsonUtils.getString(json, "key"))
- .setValue(JsonUtils.getString(json, "value"));
- }
-}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java
deleted file mode 100644
index 3451bf16ed5..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ResourceUnmarshaller.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.gwt.unmarshallers;
-
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONValue;
-import org.sonar.gwt.JsonUtils;
-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> {
-
- private static final ResourceUnmarshaller INSTANCE = new ResourceUnmarshaller();
-
- private ResourceUnmarshaller() {
- }
-
- public static ResourceUnmarshaller getInstance() {
- return INSTANCE;
- }
-
- 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"))
- .setVersion(JsonUtils.getString(json, "version"))
- .setDate(JsonUtils.getDate(json, "date"))
- .setCopy(JsonUtils.getInteger(json, "copy"));
- }
-
- private void parseMeasures(JSONObject json, Resource resource) {
- JSONValue measuresJson = json.get("msr");
- if (measuresJson != null) {
- resource.setMeasures(parseMeasures(measuresJson));
- }
- }
-
- private List<Measure> parseMeasures(JSONValue measuresJson) {
- List<Measure> projectMeasures = new ArrayList<Measure>();
- int len = JsonUtils.getArraySize(measuresJson);
- for (int i = 0; i < len; i++) {
- JSONObject measureJson = JsonUtils.getArray(measuresJson, 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"))
- .setData(JsonUtils.getString(json, "data"))
- .setTrend(JsonUtils.getInteger(json, "trend"))
- .setVar(JsonUtils.getInteger(json, "var"))
- .setRuleKey(JsonUtils.getString(json, "rule_key"))
- .setRuleName(JsonUtils.getString(json, "rule_name"))
- .setRuleCategory(JsonUtils.getString(json, "rule_category"))
- .setRuleSeverity(JsonUtils.getString(json, "rule_priority"))
- .setCharacteristicKey(JsonUtils.getString(json, "ctic_key"))
- .setCharacteristicName(JsonUtils.getString(json, "ctic_name"));
- return measure;
- }
-}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ServerUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ServerUnmarshaller.java
deleted file mode 100644
index ad87a8133e6..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ServerUnmarshaller.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.gwt.unmarshallers;
-
-import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.json.client.JSONObject;
-import org.sonar.gwt.JsonUtils;
-import org.sonar.wsclient.services.Server;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class ServerUnmarshaller implements Unmarshaller<Server> {
-
- public Server toModel(JavaScriptObject json) {
- JSONObject map = new JSONObject(json);
- Server server = new Server()
- .setId(JsonUtils.getString(map, "id"))
- .setVersion(JsonUtils.getString(map, "version"));
- server.setStatusMessage(JsonUtils.getString(map, "status_msg"));
- String status = JsonUtils.getString(map, "status");
- if (status != null) {
- server.setStatus(Server.Status.valueOf(status));
- }
- return server;
- }
-
- public List<Server> toModels(JavaScriptObject json) {
- return Arrays.asList(toModel(json));
- }
-}
-
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/SourceUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/SourceUnmarshaller.java
deleted file mode 100644
index bf2c3ef2f38..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/SourceUnmarshaller.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.gwt.unmarshallers;
-
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONValue;
-import org.sonar.wsclient.services.Source;
-
-public class SourceUnmarshaller extends AbstractUnmarshaller<Source> {
-
- protected Source parse(JSONObject json) {
- Source source = new Source();
-
- for (String key : json.keySet()) {
- JSONValue val = json.get(key);
- if (val.isString() != null) {
- source.addLine(Integer.parseInt(key), val.isString().stringValue());
- } else {
- source.addLine(Integer.parseInt(key), "");
- }
- }
-
- return source;
- }
-}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java
deleted file mode 100644
index 562e986c70e..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.sonar.wsclient.gwt.unmarshallers;
-
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONObject;
-import org.sonar.gwt.JsonUtils;
-import org.sonar.wsclient.services.TimeMachine;
-import org.sonar.wsclient.services.TimeMachineCell;
-import org.sonar.wsclient.services.TimeMachineColumn;
-
-public class TimeMachineUnmarshaller extends AbstractUnmarshaller<TimeMachine> {
-
- protected TimeMachine parse(JSONObject json) {
- JSONArray cols = json.get("cols").isArray();
- JSONArray cells = json.get("cells").isArray();
- return new TimeMachine(toColumns(cols), toCells(cells));
- }
-
- private TimeMachineColumn[] toColumns(JSONArray cols) {
- int size = cols.size();
- TimeMachineColumn[] result = new TimeMachineColumn[size];
- for (int index = 0; index < JsonUtils.getArraySize(cols); index++) {
- JSONObject elem = JsonUtils.getArray(cols, index);
- result[index] = new TimeMachineColumn(index, JsonUtils.getString(elem, "metric"), null, null);
- }
- return result;
- }
-
- private TimeMachineCell[] toCells(JSONArray cells) {
- int size = JsonUtils.getArraySize(cells);
- TimeMachineCell[] result = new TimeMachineCell[size];
- for (int i = 0; i < size; i++) {
- JSONObject cellJson = JsonUtils.getArray(cells, i);
- JSONArray valuesJson = cellJson.get("v").isArray();
-
- Object[] resultValues = new Object[JsonUtils.getArraySize(valuesJson)];
- for (int indexValue = 0; indexValue < JsonUtils.getArraySize(valuesJson); indexValue++) {
- Object value = valuesJson.get(indexValue);
- resultValues[indexValue] = value;
- }
- result[i] = new TimeMachineCell(JsonUtils.getDate(cellJson, "d"), resultValues);
- }
- return result;
- }
-
-}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/Unmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/Unmarshaller.java
deleted file mode 100644
index 39c5628c302..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/Unmarshaller.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.gwt.unmarshallers;
-
-import com.google.gwt.core.client.JavaScriptObject;
-import org.sonar.wsclient.services.Model;
-
-import java.util.List;
-
-public interface Unmarshaller<MODEL extends Model> {
-
- MODEL toModel(JavaScriptObject json);
-
- List<MODEL> toModels(JavaScriptObject json);
-
-}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/Unmarshallers.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/Unmarshallers.java
deleted file mode 100644
index d28a90ccee8..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/Unmarshallers.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.gwt.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, ResourceUnmarshaller.getInstance());
- 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());
- // TODO
- // FavouriteUnmarshaller
- // PluginUnmarshaller
- // RuleUnmarshaller
- unmarshallers.put(TimeMachine.class, new TimeMachineUnmarshaller());
- }
-
- public static Unmarshaller forModel(Class modelClass) {
- return unmarshallers.get(modelClass);
- }
-}
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java
deleted file mode 100644
index bf0194820e3..00000000000
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.gwt.unmarshallers;
-
-import com.google.gwt.json.client.JSONObject;
-import org.sonar.gwt.JsonUtils;
-import org.sonar.wsclient.services.Violation;
-
-public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> {
-
- protected Violation parse(JSONObject json) {
- Violation violation = new Violation();
- violation.setMessage(JsonUtils.getString(json, "message"));
- violation.setLine(JsonUtils.getInteger(json, "line"));
- violation.setSeverity(JsonUtils.getString(json, "priority"));
- violation.setCreatedAt(JsonUtils.getDate(json, "createdAt"));
-
- 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;
- }
-}