KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > inf > iks > jvmai > jvmdi > ControlFlow


1 //
2
// This file is part of the prose package.
3
//
4
// The contents of this file are subject to the Mozilla Public License
5
// Version 1.1 (the "License"); you may not use this file except in
6
// compliance with the License. You may obtain a copy of the License at
7
// http://www.mozilla.org/MPL/
8
//
9
// Software distributed under the License is distributed on an "AS IS" basis,
10
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
// for the specific language governing rights and limitations under the
12
// License.
13
//
14
// The Original Code is prose.
15
//
16
// The Initial Developer of the Original Code is Andrei Popovici. Portions
17
// created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
18
// All Rights Reserved.
19
//
20
// Contributor(s):
21
// $Id: ControlFlow.java,v 1.2 2004/05/12 09:41:54 anicoara Exp $
22
// =====================================================================
23
//
24
// (history at end)
25
//
26

27 package ch.ethz.inf.iks.jvmai.jvmdi;
28
29 import ch.ethz.jvmai.CodeJoinPoint;
30 import ch.ethz.jvmai.MethodEntryJoinPoint;
31 import ch.ethz.jvmai.FieldAccessJoinPoint;
32 import ch.ethz.jvmai.FieldModificationJoinPoint;
33 import ch.ethz.jvmai.MethodExitJoinPoint;
34 import ch.ethz.jvmai.ExceptionJoinPoint;
35 import ch.ethz.jvmai.ExceptionCatchJoinPoint;
36
37 // used packages
38
import java.util.*;
39 import java.io.*;
40
41 /**
42  * Class ControlFlow encapsulates <em>thread local</em> information needed
43  * by the jvmai. Each thread will be associated via the ThreadLocalVariable
44  * AspectInterfaceImpl.cflows with an instance of <code>ControlFlow</code>.
45  * <p>
46  * With this, the need for <creating> joinpoints when they are needed
47  * is elimiated (hence no garbage collection artificially incurred by
48  * this JVMAI implementation.
49  * <p>
50  * The control flow contains AT LEAST a pointer to a join-point object
51  * of each kind. The thread-local join-points must be instantiated
52  * such that they all point to a <code>JoinPointContext</code> object
53  * which, again, belongs to this controlflow.
54  *
55  * @version $Revision: 1.2 $
56  * @author Andrei Popovici
57  */

58 public
59 class ControlFlow {
60
61     private SortedMap aopMap;
62     private JoinPointContext currentContext;
63     private MethodExecutionJoinPointImpl executionJoinPoint;
64     private FieldAccessJoinPointImpl getJoinPoint;
65     private FieldModificationJoinPointImpl setJoinPoint ;
66     private ExceptionJoinPointImpl throwJoinPoint ;
67     private ExceptionCatchJoinPointImpl catchJoinPoint;
68
69   /** Create a standard control flow */
70     public ControlFlow()
71     {
72            aopMap = new TreeMap();
73        currentContext = new JoinPointContext();
74        executionJoinPoint = new MethodExecutionJoinPointImpl(this,currentContext);
75        getJoinPoint = new FieldAccessJoinPointImpl(this,currentContext);
76        setJoinPoint = new FieldModificationJoinPointImpl(this,currentContext);
77        throwJoinPoint = new ExceptionJoinPointImpl(this,currentContext);
78        catchJoinPoint = new ExceptionCatchJoinPointImpl(this,currentContext);
79     }
80     protected Collection getAopTags(CodeJoinPointImpl jp)
81     {
82     SortedMap headMap = aopMap.headMap(valueOf(jp.context.depth));
83     return headMap.values();
84     }
85
86     protected void pushJoinPoint(CodeJoinPointImpl cjp)
87     {
88     aopMap.put(valueOf(currentContext.depth),cjp.getAopTag());
89     }
90
91     protected void popJoinPoint(int depth)
92     {
93
94     Integer JavaDoc intKey = valueOf(depth);
95
96     Integer JavaDoc lastKey = (Integer JavaDoc)aopMap.lastKey();
97
98     if (lastKey.equals(intKey))
99         aopMap.remove(lastKey);
100     else
101         {
102         SortedMap tail = aopMap.tailMap(intKey);
103         Iterator i = tail.keySet().iterator();
104         while (i.hasNext())
105             {
106             aopMap.remove(i.next());
107             }
108         }
109     }
110
111
112     private static Integer JavaDoc[] first100Integers;
113   private Integer JavaDoc valueOf(int x)
114     {
115       if (first100Integers == null)
116     {
117       first100Integers = new Integer JavaDoc[100];
118       for (int i =0; i<100; i++)
119         first100Integers[i]=new Integer JavaDoc(i);
120     }
121
122       if (x<100)
123     return first100Integers[x];
124       else
125             return new Integer JavaDoc(x);
126     }
127
128
129
130
131
132
133 }
134
135
136 //======================================================================
137
//
138
// $Log: ControlFlow.java,v $
139
// Revision 1.2 2004/05/12 09:41:54 anicoara
140
// Remove the README.RVM file
141
//
142
// Revision 1.1.1.1 2003/07/02 15:30:50 apopovic
143
// Imported from ETH Zurich
144
//
145
// Revision 1.5 2003/07/02 12:42:45 anicoara
146
// Added CatchJoinPoint Functionality (Requests, Join-Points, Filters, CatchCuts, Tests)
147
//
148
// Revision 1.4 2003/05/06 15:51:13 popovici
149
// Mozilla-ification
150
//
151
// Revision 1.3 2003/05/05 17:46:23 popovici
152
// Refactorization step (runes->prose) cleanup
153
//
154
// Revision 1.2 2003/03/04 16:09:32 popovici
155
// Documentation improvements
156
//
157
// Revision 1.1 2003/03/04 11:26:22 popovici
158
// Important refactorization step (march):
159
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
160
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
161
// structures
162
//
163
Popular Tags