KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Aspects


1 /* ----------------------------------------------------------------------------
2  * EAOP 1.0, 2002-12-19
3  * (c) 2002 Remi Douence, Mario Sudholt; OBASCO group; EMN/INRIA; France
4  * THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY WARRANTY
5   -------------------------------------------------------------------------- */

6
7 import fr.emn.info.eaop.*;
8 import fr.emn.info.eaop.aspect.*;
9 import fr.emn.info.eaop.event.*;
10
11 import java.lang.reflect.*;
12
13 class Billing extends Aspect {
14
15     public Event nextPointCutClient() {
16     boolean ok = false;
17     Event e = null;
18     while (!ok) {
19         e = nextEvent();
20         ok = (e instanceof MethodReturn)
21         && ((MethodReturn)e).method.getName().equals("makeRequest");
22     }
23     return e;
24     }
25
26     public Event nextPointCutService() {
27     boolean ok = false;
28     Event e = null;
29     while (!ok) {
30         e = nextEvent();
31         ok = (e instanceof MethodCall)
32         && ((MethodCall)e).method.getName().equals("serve");
33     }
34     this.isCrosscutting = true;
35     return e;
36     }
37
38     public void definition() {
39     while (true) {
40         // crosscut
41
Event e1 = nextPointCutClient();
42         int clientId = ((Client)(((MethodReturn)e1).receiver)).id;
43         Event e2 = nextPointCutService();
44         String JavaDoc serviceId = ((Service)(((MethodCall)e2).receiver)).id;
45         // action
46
this.print(serviceId, clientId);
47     }
48     }
49
50     public void print(String JavaDoc service, int client) {
51     System.out.println("\tbill service " + service
52                + " to client " + client);
53     }
54
55 }
56
57 class Profiling extends Aspect {
58
59     public Event nextPointCut() {
60     boolean ok = false;
61     Event e = null;
62     while (!ok) {
63         e = nextEvent();
64         ok = (e instanceof MethodCall)
65         && ((MethodCall)e).method.getName().equals("print");
66     }
67     this.isCrosscutting = true;
68     return e;
69     }
70     public void definition() {
71     int n=0;
72     while (true) {
73         Event e = nextPointCut();
74         this.isCrosscutting = true;
75         n++;
76         System.out.println("\tprofile n=" + n);
77     }
78     }
79 }
80
Popular Tags