aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCheng Chen2012-05-21 23:22:17 (EDT)
committerCheng Chen2012-05-21 23:22:17 (EDT)
commit4b6236c00bd04862088da2e6891560b74f6c49b2 (patch)
treec2908db20925b80267ce195940d2d5c93cc9ec3b
parent0964802ee63c31e770423ac52792e30a4cfdc353 (diff)
downloadorg.eclipse.recommenders-4b6236c00bd04862088da2e6891560b74f6c49b2.zip
org.eclipse.recommenders-4b6236c00bd04862088da2e6891560b74f6c49b2.tar.gz
org.eclipse.recommenders-4b6236c00bd04862088da2e6891560b74f6c49b2.tar.bz2
[snipmatch] witch to remote client for class LoadProfileThreadrefs/changes/64/6064/1
Change-Id: I83a9e6bb893aba523ee50463b2850e861a0c5aae Signed-off-by: Cheng Chen <chengchendoc@gmail.com>
-rw-r--r--[-rwxr-xr-x]plugins/org.eclipse.recommenders.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/web/LoadProfileThread.java208
1 files changed, 106 insertions, 102 deletions
diff --git a/plugins/org.eclipse.recommenders.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/web/LoadProfileThread.java b/plugins/org.eclipse.recommenders.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/web/LoadProfileThread.java
index 4bc2753..143ce4e 100755..100644
--- a/plugins/org.eclipse.recommenders.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/web/LoadProfileThread.java
+++ b/plugins/org.eclipse.recommenders.snipmatch.rcp/src/org/eclipse/recommenders/snipmatch/web/LoadProfileThread.java
@@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
-*/
+ */
package org.eclipse.recommenders.snipmatch.web;
@@ -17,109 +17,113 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-
-
/**
* Sends a request asynchronously to retrieve a user's own list of effects (snippets).
*/
class LoadProfileThread extends PostThread {
- private long waitTime;
- private ILoadProfileListener listener;
-
- public LoadProfileThread(MatchClient client, long waitTime, ILoadProfileListener listener) {
-
- super(client, MatchClient.PROFILE_URL);
- this.waitTime = waitTime;
- this.listener = listener;
- }
-
- @Override
- public void run() {
-
- if (!client.isLoggedIn()) {
- listener.loadProfileFailed("User not authenticated.");
- done = true;
- return;
- }
-
- try {
- sleep(waitTime);
- }
- catch (Exception e) {
- e.printStackTrace();
- listener.loadProfileFailed("Client thread error.");
- done = true;
- return;
- }
-
- if (done) return;
-
- addParameter("username", client.getUsername());
- addParameter("password", client.getPassword());
- addParameter("clientName", client.getName());
- addParameter("clientVersion", client.getVersion());
-
- InputStream response = post();
-
- if (done) return;
-
- if (response == null) {
- listener.loadProfileFailed("Connection error.");
- done = true;
- return;
- }
-
- if (done) return;
-
- boolean success = parseResults(response);
-
- if (done) return;
-
- if (!success) listener.loadProfileFailed("Bad response format.");
- else listener.loadProfileSucceeded();
-
- done = true;
- }
-
- private boolean parseResults(InputStream input) {
-
- DocumentBuilderFactory dbf;
- DocumentBuilder db;
- Document resultsXml;
-
- try {
- dbf = DocumentBuilderFactory.newInstance();
- db = dbf.newDocumentBuilder();
- resultsXml = db.parse(input);
- }
- catch (Exception e) {
- e.printStackTrace();
- return false;
- }
-
- NodeList effectsNodes = resultsXml.getElementsByTagName("effectList");
- Element effectsNode = (Element) effectsNodes.item(0);
- NodeList effectNodes = effectsNode.getElementsByTagName("effect");
-
- Effect[] effects = new Effect[effectNodes.getLength()];
-
- for (int i = 0; i < effectNodes.getLength(); i++) {
-
- if (done) return true;
-
- try {
- effects[i] = MatchConverter.parseEffect((Element) effectNodes.item(i));
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
-
- if (done) return true;
-
- listener.effectLoaded(effects[i]);
- }
-
- return true;
- }
-}
+ private long waitTime;
+ private ILoadProfileListener listener;
+
+ public LoadProfileThread(RemoteMatchClient client, long waitTime, ILoadProfileListener listener) {
+
+ super(client, RemoteMatchClient.PROFILE_URL);
+ this.waitTime = waitTime;
+ this.listener = listener;
+ }
+
+ @Override
+ public void run() {
+
+ if (!client.isLoggedIn()) {
+ listener.loadProfileFailed("User not authenticated.");
+ done = true;
+ return;
+ }
+
+ try {
+ sleep(waitTime);
+ } catch (Exception e) {
+ e.printStackTrace();
+ listener.loadProfileFailed("Client thread error.");
+ done = true;
+ return;
+ }
+
+ if (done)
+ return;
+
+ addParameter("username", client.getUsername());
+ addParameter("password", client.getPassword());
+ addParameter("clientName", client.getName());
+ addParameter("clientVersion", client.getVersion());
+
+ InputStream response = post();
+
+ if (done)
+ return;
+
+ if (response == null) {
+ listener.loadProfileFailed("Connection error.");
+ done = true;
+ return;
+ }
+
+ if (done)
+ return;
+
+ boolean success = parseResults(response);
+
+ if (done)
+ return;
+
+ if (!success)
+ listener.loadProfileFailed("Bad response format.");
+ else
+ listener.loadProfileSucceeded();
+
+ done = true;
+ }
+
+ private boolean parseResults(InputStream input) {
+
+ DocumentBuilderFactory dbf;
+ DocumentBuilder db;
+ Document resultsXml;
+
+ try {
+ dbf = DocumentBuilderFactory.newInstance();
+ db = dbf.newDocumentBuilder();
+ resultsXml = db.parse(input);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ NodeList effectsNodes = resultsXml.getElementsByTagName("effectList");
+ Element effectsNode = (Element) effectsNodes.item(0);
+ NodeList effectNodes = effectsNode.getElementsByTagName("effect");
+
+ Effect[] effects = new Effect[effectNodes.getLength()];
+
+ for (int i = 0; i < effectNodes.getLength(); i++) {
+
+ if (done)
+ return true;
+
+ try {
+ effects[i] = MatchConverter.parseEffect((Element) effectNodes.item(i));
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ if (done)
+ return true;
+
+ listener.effectLoaded(effects[i]);
+ }
+
+ return true;
+ }
+} \ No newline at end of file