KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > query > JoinPointRequestSurrogate


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: JoinPointRequestSurrogate.java,v 1.1.1.1 2003/07/02 15:30:52 apopovic Exp $
22
// =====================================================================
23
//
24
// (history at end)
25
//
26

27 package ch.ethz.prose.query;
28
29 // used packages
30
import ch.ethz.jvmai.JVMAspectInterface;
31 import ch.ethz.prose.engine.ExceptionThrowRequest;
32 import ch.ethz.prose.engine.FieldAccessRequest;
33 import ch.ethz.prose.engine.FieldModificationRequest;
34 import ch.ethz.prose.engine.JoinPointRequest;
35 import ch.ethz.prose.engine.MethodEntryRequest;
36 import ch.ethz.prose.engine.MethodExitRequest;
37 import ch.ethz.prose.engine.ExceptionCatchRequest;
38 import ch.ethz.prose.engine.JoinPointManager;
39 import ch.ethz.prose.ProseSystem;
40 import ch.ethz.jvmai.JoinPointKinds;
41 import ch.ethz.jvmai.ClassSpecific;
42 import ch.ethz.jvmai.MethodExitJoinPoint;
43 import ch.ethz.jvmai.FieldAccessJoinPoint;
44 import ch.ethz.jvmai.FieldModificationJoinPoint;
45 import ch.ethz.jvmai.ExceptionJoinPoint;
46
47
48
49
50 /**
51  * Class JoinPointRequestSurrogate
52  *
53  * @version $Revision: 1.1.1.1 $
54  * @author Philippe Schoch
55  */

56 public
57 class JoinPointRequestSurrogate implements java.io.Serializable JavaDoc {
58
59   private ClassSurrogate declaringClass;
60   private Surrogate member;
61   private String JavaDoc kind;
62   private int hashCode;
63
64   /**
65    * @param jpr <code>JoinPointRequest</code> that is represented by this Surrogate
66    */

67   public JoinPointRequestSurrogate(JoinPointRequest jpr)
68     {
69
70
71       // if a JoinPointRequest is null, the corresponding JoinPointRequest can't be null
72
// because the Collator in LocalAspectManager throws a NullPointerException
73
if (jpr == null)
74         {
75       kind = "null";
76       member = null;
77       declaringClass = null;
78       return;
79     }
80
81       kind = jpr.getKind();
82       if (jpr instanceof ClassSpecific)
83       declaringClass = new ClassSurrogate( ((ClassSpecific)jpr).getTargetClass());
84
85       if ( (jpr.getMask() & JoinPointKinds.MASK_METHOD_ENTRY_JP) != 0)
86       member = new MethodSurrogate(((MethodEntryRequest)jpr).getMethod());
87       else if ( (jpr.getMask() & JoinPointKinds.MASK_METHOD_EXIT_JP) != 0)
88       member = new MethodSurrogate(((MethodExitRequest)jpr).getMethod());
89       else if ( (jpr.getMask() & JoinPointKinds.MASK_FIELD_ACCESS_JP) != 0)
90       member = new FieldSurrogate(((FieldAccessRequest)jpr).getField());
91       else if ( (jpr.getMask() & JoinPointKinds.MASK_FIELD_MODIFICATION_JP) != 0)
92       member = new FieldSurrogate(((FieldModificationRequest)jpr).getField());
93       else if ( (jpr.getMask() & JoinPointKinds.MASK_EXCEPTION_THROW_ARGS_JP) != 0)
94       { member = new ClassSurrogate(((ExceptionThrowRequest)jpr).getExceptionClass());
95         declaringClass = (ClassSurrogate)member;
96       }
97       else if ( (jpr.getMask() & JoinPointKinds.MASK_EXCEPTION_CATCH_ARGS_JP) != 0)
98       { member = new ClassSurrogate(((ExceptionCatchRequest)jpr).getExceptionClass());
99         declaringClass = (ClassSurrogate)member;
100       }
101
102       else
103       throw new ClassCastException JavaDoc("the JoinPointRequest must have one of the known subtypes");
104
105       if (jpr != null)
106           hashCode = jpr.hashCode();
107
108
109
110     }
111
112   /**
113    * Return the name of this <code>JoinPointRequestSurrogate</code>. It consists of
114    * the return of the <code>toString()</code> method.
115    */

116   public String JavaDoc getName()
117     {
118       return toString();
119     }
120
121
122   /**
123    * Return the kind of this JoinPointRequest
124    *
125    * @returns the integer value representing the kind.
126    */

127   public String JavaDoc getKind()
128     {
129       return kind;
130     }
131
132
133   public Surrogate getMember()
134     {
135       return member;
136     }
137
138
139   public ClassSurrogate getDeclaringClass()
140     {
141       return declaringClass;
142     }
143
144
145
146   public boolean equals(Object JavaDoc o)
147     {
148       if (!(o instanceof JoinPointRequestSurrogate))
149           return false;
150
151       JoinPointRequestSurrogate other = (JoinPointRequestSurrogate)o;
152
153       if (kind != other.getKind())
154           return false;
155
156       if (! member.equals(other.getMember()))
157           return false;
158
159       if (! declaringClass.equals(other.getDeclaringClass()))
160           return false;
161
162       return true;
163     }
164
165   public int hashCode()
166     {
167       return hashCode;
168     }
169
170
171   public String JavaDoc toString()
172     {
173
174       if ((kind.equals(JoinPointKinds.KIND_METHOD_ENTRY_JP)) || (kind.equals(JoinPointKinds.KIND_METHOD_EXIT_JP)))
175           return kind + " on " + declaringClass + "." + member.toString();
176
177       else if ((kind.equals(JoinPointKinds.KIND_FIELD_ACCESS_JP)) || (kind.equals(JoinPointKinds.KIND_FIELD_MODIFICATION_JP)))
178           return kind + " on " + ((FieldSurrogate)member).getType() + " " + declaringClass + "." + member.getName();
179
180       else if (kind.equals(JoinPointKinds.KIND_EXCEPTION_THROW_ARGS_JP) || kind.equals (JoinPointKinds.KIND_EXCEPTION_CATCH_ARGS_JP))
181           return kind + " on " + member.toString();
182
183       else if (kind.equals("null"))
184           return "#NULL#";
185
186       return "##ERROR## in toString() of class JoinPointRequestSurrogate";
187     }
188 }
189
190
191 //======================================================================
192
//
193
// $Log: JoinPointRequestSurrogate.java,v $
194
// Revision 1.1.1.1 2003/07/02 15:30:52 apopovic
195
// Imported from ETH Zurich
196
//
197
// Revision 1.4 2003/07/02 13:40:54 anicoara
198
// Bug fix; the kind 'Catch' was not known;
199
//
200
// Revision 1.3 2003/05/20 16:05:08 popovici
201
//
202
// New QueryManager replaces functionality in AspectManager (better Soc)
203
// New 'Surrogate' classes for usage in the QueryManager
204
// The 'RemoteAspectManager' and tools modified to use the Surrogates and the QueryManager
205
//
206
// Revision 1.2 2003/05/06 15:51:50 popovici
207
// Mozilla-ification
208
//
209
// Revision 1.1 2003/05/05 13:58:20 popovici
210
// renaming from runes to prose
211
//
212
// Revision 1.8 2003/04/26 18:51:40 popovici
213
// 1 Bug fix which lead to a refactoring step:
214
// 1. the bug: 'JoinPointRequests' used to write to a static list, which survived a startup/teardown;
215
// now this list belongs to the JoinPointManager;
216
// 2. the refactoring: the JoinPointManager now creates (and shares state) with join-points.
217
//
218
// Revision 1.7 2003/04/17 15:14:57 popovici
219
// Extension->Aspect renaming
220
//
221
// Revision 1.6 2003/04/14 19:11:25 popovici
222
// Eliminating System.err.println
223
//
224
// Revision 1.5 2003/03/13 14:16:55 popovici
225
// All items traveling with Tupels are now Serializable
226
//
227
// Revision 1.4 2003/03/04 18:36:02 popovici
228
// Organization of imprts
229
//
230
// Revision 1.3 2003/03/04 11:27:36 popovici
231
// Important refactorization step (march):
232
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
233
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
234
// structures
235
//
236
// Revision 1.2 2003/01/27 12:58:57 pschoch
237
// new HashCode Policy with Surrogates; toString() of Surrogates improved
238
//
239
// Revision 1.1 2003/01/17 14:43:57 pschoch
240
// Introduction of 'query' methods in the AspectManager and its
241
// subclasses. The result set is given back in form of surrogates; 4 new tests added to ExtensionManagerTest
242
// ExtensionSystemTest
243
//
244
Popular Tags