Main.java
2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package client ;
import javax.naming.InitialContext;
import javax.naming.NamingException ;
import ejb.sessions.* ;
import ejb.entites.* ;
public class Main {
public static void main(String[] args) {
try {
InitialContext ctx = new InitialContext();
System.out.println("Accès au service distant") ;
Object obj = ctx.lookup("ejb:appliBanque/appliBanqueSessions//ServiceBanqueBean"+
"!ejb.sessions.ServiceBanqueRemote");
ServiceBanqueRemote service = (ServiceBanqueRemote) obj ;
service.addCompte(1, "Olivier", 2000.0);
service.addCompte(2, "Paul", 300.0) ;
service.addAction("nintendo",46.5) ;
service.addAction("sega", 12.0) ;
System.out.println("achat de 10 actions sega") ;
service.acheteActions(1, "sega", 10);
System.out.println("achat de 3 actions nintendo") ;
service.acheteActions(1, "nintendo", 3);
System.out.println("Actions de Olivier:") ;
for (LigneAction la : service.getActionsAchetees(1))
System.out.println(la.getNombre()+" action(s) "+la.getAction().getNom()
+" au taux de "+la.getAction().getTaux()) ;
System.out.println("vente de 2 actions sega") ;
service.vendActions(1, "sega", 2);
System.out.println("Actions de Olivier:") ;
for (LigneAction la : service.getActionsAchetees(1))
System.out.println(la.getNombre()+" action(s) "+la.getAction().getNom()
+" au taux de "+la.getAction().getTaux()) ;
System.out.println("vente de 8 actions sega") ;
service.vendActions(1, "sega", 8);
System.out.println("Actions de Olivier:") ;
for (LigneAction la : service.getActionsAchetees(1))
System.out.println(la.getNombre()+" action(s) "+la.getAction().getNom()
+" au taux de "+la.getAction().getTaux()) ;
} catch(CompteInconnuException e) {
System.err.println("Compte inconnu") ;
} catch (NamingException e1) {
System.err.println("erreur accès service") ;
} catch (ActionInconnueException e) {
System.err.println("Action inconnue") ;
} catch (ApprovisionnementException e) {
System.err.println("pb approvisionnement") ;
} catch (CompteDejaExistantException e) {
System.err.println("Compte existe") ;
} catch (ActionDejaExistanteException e) {
System.err.println("Action existe") ;
}
}
}