Subversion Repositories eFlore/Applications.cel

Rev

Rev 1293 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
989 aurelien 1
package org.tela_botanica.client.modeles.dao;
140 aurelien 2
 
3
import org.tela_botanica.client.interfaces.Rafraichissable;
989 aurelien 4
import org.tela_botanica.client.modeles.objets.Configuration;
140 aurelien 5
import org.tela_botanica.client.observation.ObservationModele;
6
 
7
import com.google.gwt.http.client.Request;
8
import com.google.gwt.http.client.RequestBuilder;
9
import com.google.gwt.http.client.RequestCallback;
10
import com.google.gwt.http.client.RequestException;
11
import com.google.gwt.http.client.Response;
12
import com.google.gwt.json.client.JSONArray;
13
import com.google.gwt.json.client.JSONParser;
14
import com.google.gwt.json.client.JSONString;
15
import com.google.gwt.json.client.JSONValue;
16
 
989 aurelien 17
public class NomRetenuAsynchroneDAO {
140 aurelien 18
 
19
	private ObservationModele oModele = null ;
20
 
989 aurelien 21
	public NomRetenuAsynchroneDAO(ObservationModele observationModele) {
140 aurelien 22
		oModele = observationModele ;
23
	}
24
 
25
	public void obtenirNomRetenu(final Rafraichissable r, final String anum) {
26
 
27
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,
28
				Configuration.getServiceBaseUrl()
29
				+ "/name/"+anum);
30
 
31
		try {
32
			rb.sendRequest(null, new RequestCallback() {
33
 
1293 aurelien 34
				@Override
140 aurelien 35
				public void onError(Request request, Throwable exception) {
36
					// TODO Auto-generated method stub
37
				}
38
 
1293 aurelien 39
				@Override
140 aurelien 40
				public void onResponseReceived(Request request,
41
						Response response) {
42
 
43
					JSONValue jsonValue = JSONParser.parse(response.getText());
44
                    JSONArray jsonArray;
45
 
46
                    if ((jsonArray = jsonValue.isArray()) != null) {
47
 
973 aurelien 48
                            String aname = ((JSONString) jsonArray.get(0)).toString();
140 aurelien 49
 
50
                            // Nom
51
                            if (aname.compareTo("null")!=0) {
52
 
53
                            	String[] numNom = {aname, anum } ;
54
                            	r.rafraichir(numNom, false);
55
                            }
56
 
57
                    }
58
                }
59
			});
60
 
61
		} catch (RequestException e) {
62
			// TODO Auto-generated catch block
63
			e.printStackTrace();
64
		}
65
 
66
 
67
	}
68
 
69
}