Subversion Repositories eFlore/Applications.del

Rev

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

package org.tela_botanica.del.client.services.rest.async;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.Window;

public abstract class VoteProtocoleCallback implements RequestCallback {
        
        public enum ModeRequete {
                AJOUT, MODIFICATION
        }
        
        protected ModeRequete mode;
                
        public VoteProtocoleCallback(ModeRequete mode) {
                this.mode = mode;
        }

        public VoteProtocoleCallback() {
                // TODO Auto-generated constructor stub
        }
        
        public void setMode(ModeRequete mode) {
                this.mode = mode;
        }

        @Override
        public void onResponseReceived(Request request, Response response){
                int statusCode = response.getStatusCode();
                int codeAttendu = 500;
                switch (mode) {
                        case AJOUT:
                                codeAttendu = 201;
                                break;
                        case MODIFICATION:
                                codeAttendu = 200;
                                break;
                        default:
                                codeAttendu = 500;
                                break;
                }
                
                if (statusCode == codeAttendu) {
                        surRetour(response.getText());
                } else {
                        surErreur("Erreur " + statusCode + ": " + response.getText());
                }
        }

        @Override
        public void onError(Request request, Throwable exception) {
                Window.alert(exception.getMessage());
        }
        
        public abstract void surRetour(String messageRetour);
        public abstract void surErreur(String messageErreur);
}