Subversion Repositories eFlore/Applications.cel

Rev

Rev 989 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client.modeles.dao;

import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.objets.Configuration;
import org.tela_botanica.client.observation.ObservationModele;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;

public class NomRetenuAsynchroneDAO {

        private ObservationModele oModele = null ;
        
        public NomRetenuAsynchroneDAO(ObservationModele observationModele) {
                oModele = observationModele ;
        }

        public void obtenirNomRetenu(final Rafraichissable r, final String anum) {
                
                RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,
                                Configuration.getServiceBaseUrl()
                                + "/name/"+anum);

                try {
                        rb.sendRequest(null, new RequestCallback() {

                                @Override
                                public void onError(Request request, Throwable exception) {
                                        // TODO Auto-generated method stub
                                }

                                @Override
                                public void onResponseReceived(Request request,
                                                Response response) {
                                        
                                        JSONValue jsonValue = JSONParser.parse(response.getText());
                    JSONArray jsonArray;

                    if ((jsonArray = jsonValue.isArray()) != null) {
   
                            String aname = ((JSONString) jsonArray.get(0)).toString();
                           
                            // Nom
                            if (aname.compareTo("null")!=0) {
                                
                                String[] numNom = {aname, anum } ;
                                r.rafraichir(numNom, false);
                            }
                       
                    }
                }
                        });

                } catch (RequestException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        
                
        }

}