Advertisement
adibdoub

Untitled

Jan 17th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.50 KB | None | 0 0
  1. public class SAMOPClient extends SAMOPBase {
  2.    
  3.     boolean isLogged;
  4.     List<Salary> salaires;
  5.    
  6.    
  7.     public SAMOPClient(Socket serviceSocket) throws ProtocolException {
  8.         super(serviceSocket);
  9.        
  10.         isLogged = false;
  11.     }
  12.    
  13.     public void loginSSLRequest(String name, String password) throws ProtocolException {
  14.         try {
  15.             this.loginSSLRequest = new LoginSSLRequest(name, password);
  16.             oos.writeObject(this.loginSSLRequest);
  17.             oos.flush();
  18.            
  19.             super.receive();
  20.            
  21.             if (receivedObject instanceof SimpleAnswer) {
  22.                 SimpleAnswer answer = (SimpleAnswer)receivedObject;
  23.                 if (answer.getAnswer() == SimpleAnswer.ACCEPT)
  24.                     isLogged = true;
  25.                 else
  26.                     System.out.println(answer.getDenyReason());
  27.             }
  28.            
  29.         } catch (Exception ex) {
  30.             throw new ProtocolException(ex.getMessage());
  31.         }
  32.     }
  33.    
  34.     public void launchPaymentRequest(String employee) throws ProtocolException {
  35.         try {
  36.             this.launchPaymentRequest = new LaunchPaymentRequest(employee);
  37.             oos.writeObject(this.launchPaymentRequest);
  38.             oos.flush();
  39.            
  40.             super.receive();
  41.            
  42.             if(receivedObject instanceof PaymentsResponse) {
  43.                 PaymentsResponse response = (PaymentsResponse) receivedObject;
  44.                
  45.                 salaires = response.getList();
  46.             } else if (receivedObject instanceof SimpleTextAnswer) {
  47.                 SimpleTextAnswer answer = (SimpleTextAnswer) receivedObject;
  48.                 System.out.println(answer.getAnswer());
  49.             }
  50.            
  51.         } catch (Exception ex) {
  52.             throw new ProtocolException(ex.getMessage());
  53.         }
  54.     }
  55.        
  56.     public void launchPaymentsRequest() throws ProtocolException {
  57.         try {
  58.             this.launchPaymentsRequest = new LaunchPaymentsRequest();
  59.             oos.writeObject(this.launchPaymentsRequest);
  60.             oos.flush();
  61.            
  62.            
  63.             super.receive();
  64.            
  65.             if(receivedObject instanceof PaymentsResponse) {
  66.                 PaymentsResponse response = (PaymentsResponse) receivedObject;
  67.                
  68.                 salaires = response.getList();
  69.             } else if (receivedObject instanceof SimpleTextAnswer) {
  70.                 SimpleTextAnswer answer = (SimpleTextAnswer) receivedObject;
  71.                 System.out.println(answer.getAnswer());
  72.             }
  73.            
  74.            
  75.         } catch (Exception ex) {
  76.             throw new ProtocolException(ex.getMessage());
  77.         }
  78.     }
  79.    
  80.      public void askPayments(int mois) throws ProtocolException {
  81.         try {
  82.             this.askPaymentsRequest = new AskPaymentsRequest(mois);
  83.             oos.writeObject(this.askPaymentsRequest);
  84.             oos.flush();
  85.            
  86.            
  87.             super.receive();
  88.            
  89.             if(receivedObject instanceof PaymentsResponse) {
  90.                 PaymentsResponse response = (PaymentsResponse) receivedObject;
  91.                
  92.                 salaires = response.getList();
  93.             } else if (receivedObject instanceof SimpleTextAnswer) {
  94.                 SimpleTextAnswer answer = (SimpleTextAnswer) receivedObject;
  95.                 System.out.println(answer.getAnswer());
  96.             }
  97.            
  98.            
  99.         } catch (Exception ex) {
  100.             throw new ProtocolException(ex.getMessage());
  101.         }
  102.     }    
  103.    
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement