|  | @@ -1,35 +1,43 @@
 | 
	
		
			
				|  |  |  package rsx;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import org.json.JSONObject;
 | 
	
		
			
				|  |  | +import org.json.JSONException;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * Analyse reponse d'un serveur BomberStudent
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  |   * @author Arthur Brandao
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  public class BomberStudentReponse {
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      protected boolean error = true;
 | 
	
		
			
				|  |  |      protected int statut;
 | 
	
		
			
				|  |  |      protected String message;
 | 
	
		
			
				|  |  | -    protected JSONObject reponse;
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | +    protected JSONObject reponse = null;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /* --- Constructeurs --- */
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    public BomberStudentReponse(){
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | +    public BomberStudentReponse() {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    public BomberStudentReponse(String reponse){
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public BomberStudentReponse(String reponse) {
 | 
	
		
			
				|  |  |          this.error = false;
 | 
	
		
			
				|  |  |          //Parse reponse
 | 
	
		
			
				|  |  | -        JSONObject json = new JSONObject(reponse);
 | 
	
		
			
				|  |  | -        this.statut = json.getInt("statut");
 | 
	
		
			
				|  |  | -        this.message = json.getString("message");
 | 
	
		
			
				|  |  | -        this.reponse = json.getJSONObject("param");
 | 
	
		
			
				|  |  | -    }  
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    /* --- Getter/Setter --- */
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            JSONObject json = new JSONObject(reponse);
 | 
	
		
			
				|  |  | +            this.statut = json.getInt("statut");
 | 
	
		
			
				|  |  | +            this.message = json.getString("message");
 | 
	
		
			
				|  |  | +            if(json.has("param")){
 | 
	
		
			
				|  |  | +                this.reponse = json.getJSONObject("param");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            this.error = false;
 | 
	
		
			
				|  |  | +        } catch(JSONException ex){
 | 
	
		
			
				|  |  | +            System.err.println("La reponse n'est pas en JSON : " + ex.getMessage());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /* --- Getter/Setter --- */
 | 
	
		
			
				|  |  |      public boolean isError() {
 | 
	
		
			
				|  |  |          return error;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -61,7 +69,5 @@ public class BomberStudentReponse {
 | 
	
		
			
				|  |  |      public void setReponse(JSONObject reponse) {
 | 
	
		
			
				|  |  |          this.reponse = reponse;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |