BomberStudentReponse.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package rsx;
  2. import org.json.JSONObject;
  3. import org.json.JSONException;
  4. /**
  5. * Analyse reponse d'un serveur BomberStudent
  6. *
  7. * @author Arthur Brandao
  8. */
  9. public class BomberStudentReponse {
  10. protected boolean error = true;
  11. protected int statut;
  12. protected String message;
  13. protected JSONObject reponse = null;
  14. /* --- Constructeurs --- */
  15. public BomberStudentReponse() {
  16. }
  17. public BomberStudentReponse(String reponse) {
  18. this.error = false;
  19. //Parse reponse
  20. try {
  21. JSONObject json = new JSONObject(reponse);
  22. this.statut = json.getInt("statut");
  23. this.message = json.getString("message");
  24. if(json.has("param")){
  25. this.reponse = json.getJSONObject("param");
  26. }
  27. this.error = false;
  28. } catch(JSONException ex){
  29. System.err.println("La reponse n'est pas en JSON : " + ex.getMessage());
  30. }
  31. }
  32. /* --- Getter/Setter --- */
  33. public boolean isError() {
  34. return error;
  35. }
  36. public void setError(boolean error) {
  37. this.error = error;
  38. }
  39. public int getStatut() {
  40. return statut;
  41. }
  42. public void setStatut(int statut) {
  43. this.statut = statut;
  44. }
  45. public String getMessage() {
  46. return message;
  47. }
  48. public void setMessage(String message) {
  49. this.message = message;
  50. }
  51. public JSONObject getReponse() {
  52. return reponse;
  53. }
  54. public void setReponse(JSONObject reponse) {
  55. this.reponse = reponse;
  56. }
  57. }