001: //
002: // This file is part of the prose package.
003: //
004: // The contents of this file are subject to the Mozilla Public License
005: // Version 1.1 (the "License"); you may not use this file except in
006: // compliance with the License. You may obtain a copy of the License at
007: // http://www.mozilla.org/MPL/
008: //
009: // Software distributed under the License is distributed on an "AS IS" basis,
010: // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: // for the specific language governing rights and limitations under the
012: // License.
013: //
014: // The Original Code is prose.
015: //
016: // The Initial Developer of the Original Code is Andrei Popovici. Portions
017: // created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
018: // All Rights Reserved.
019: //
020: // Contributor(s):
021: // $Id: JoinPointRequestSurrogate.java,v 1.1.1.1 2003/07/02 15:30:52 apopovic Exp $
022: // =====================================================================
023: //
024: // (history at end)
025: //
026:
027: package ch.ethz.prose.query;
028:
029: // used packages
030: import ch.ethz.prose.engine.ExceptionThrowRequest;
031: import ch.ethz.prose.engine.FieldAccessRequest;
032: import ch.ethz.prose.engine.FieldModificationRequest;
033: import ch.ethz.prose.engine.JoinPointRequest;
034: import ch.ethz.prose.engine.MethodEntryRequest;
035: import ch.ethz.prose.engine.MethodExitRequest;
036: import ch.ethz.prose.engine.ExceptionCatchRequest;
037: import ch.ethz.jvmai.JoinPointKinds;
038: import ch.ethz.jvmai.ClassSpecific;
039:
040: /**
041: * Class JoinPointRequestSurrogate
042: *
043: * @version $Revision: 1.1.1.1 $
044: * @author Philippe Schoch
045: */
046: public class JoinPointRequestSurrogate implements java.io.Serializable {
047:
048: private static final long serialVersionUID = 3256722892229193776L;
049: private ClassSurrogate declaringClass;
050: private Surrogate member;
051: private String kind;
052: private int hashCode;
053:
054: /**
055: * @param jpr <code>JoinPointRequest</code> that is represented by this Surrogate
056: */
057: public JoinPointRequestSurrogate(JoinPointRequest jpr) {
058:
059: // if a JoinPointRequest is null, the corresponding JoinPointRequest can't be null
060: // because the Collator in LocalAspectManager throws a NullPointerException
061: if (jpr == null) {
062: kind = "null";
063: member = null;
064: declaringClass = null;
065: return;
066: }
067:
068: kind = jpr.getKind();
069: if (jpr instanceof ClassSpecific)
070: declaringClass = new ClassSurrogate(((ClassSpecific) jpr)
071: .getTargetClass());
072:
073: if ((jpr.getMask() & JoinPointKinds.MASK_METHOD_ENTRY_JP) != 0)
074: member = new MethodSurrogate(((MethodEntryRequest) jpr)
075: .getMethod());
076: else if ((jpr.getMask() & JoinPointKinds.MASK_METHOD_EXIT_JP) != 0)
077: member = new MethodSurrogate(((MethodExitRequest) jpr)
078: .getMethod());
079: else if ((jpr.getMask() & JoinPointKinds.MASK_FIELD_ACCESS_JP) != 0)
080: member = new FieldSurrogate(((FieldAccessRequest) jpr)
081: .getField());
082: else if ((jpr.getMask() & JoinPointKinds.MASK_FIELD_MODIFICATION_JP) != 0)
083: member = new FieldSurrogate(
084: ((FieldModificationRequest) jpr).getField());
085: else if ((jpr.getMask() & JoinPointKinds.MASK_EXCEPTION_THROW_ARGS_JP) != 0) {
086: member = new ClassSurrogate(((ExceptionThrowRequest) jpr)
087: .getExceptionClass());
088: declaringClass = (ClassSurrogate) member;
089: } else if ((jpr.getMask() & JoinPointKinds.MASK_EXCEPTION_CATCH_ARGS_JP) != 0) {
090: member = new ClassSurrogate(((ExceptionCatchRequest) jpr)
091: .getExceptionClass());
092: declaringClass = (ClassSurrogate) member;
093: }
094:
095: else
096: throw new ClassCastException(
097: "the JoinPointRequest must have one of the known subtypes");
098:
099: if (jpr != null)
100: hashCode = jpr.hashCode();
101:
102: }
103:
104: /**
105: * Return the name of this <code>JoinPointRequestSurrogate</code>. It consists of
106: * the return of the <code>toString()</code> method.
107: */
108: public String getName() {
109: return toString();
110: }
111:
112: /**
113: * Return the kind of this JoinPointRequest
114: *
115: * @return the integer value representing the kind.
116: */
117: public String getKind() {
118: return kind;
119: }
120:
121: public Surrogate getMember() {
122: return member;
123: }
124:
125: public ClassSurrogate getDeclaringClass() {
126: return declaringClass;
127: }
128:
129: public boolean equals(Object o) {
130: if (!(o instanceof JoinPointRequestSurrogate))
131: return false;
132:
133: JoinPointRequestSurrogate other = (JoinPointRequestSurrogate) o;
134:
135: if (kind != other.getKind())
136: return false;
137:
138: if (!member.equals(other.getMember()))
139: return false;
140:
141: if (!declaringClass.equals(other.getDeclaringClass()))
142: return false;
143:
144: return true;
145: }
146:
147: public int hashCode() {
148: return hashCode;
149: }
150:
151: public String toString() {
152:
153: if ((kind.equals(JoinPointKinds.KIND_METHOD_ENTRY_JP))
154: || (kind.equals(JoinPointKinds.KIND_METHOD_EXIT_JP)))
155: return kind + " on " + declaringClass + "."
156: + member.toString();
157:
158: else if ((kind.equals(JoinPointKinds.KIND_FIELD_ACCESS_JP))
159: || (kind
160: .equals(JoinPointKinds.KIND_FIELD_MODIFICATION_JP)))
161: return kind + " on " + ((FieldSurrogate) member).getType()
162: + " " + declaringClass + "." + member.getName();
163:
164: else if (kind
165: .equals(JoinPointKinds.KIND_EXCEPTION_THROW_ARGS_JP)
166: || kind
167: .equals(JoinPointKinds.KIND_EXCEPTION_CATCH_ARGS_JP))
168: return kind + " on " + member.toString();
169:
170: else if (kind.equals("null"))
171: return "#NULL#";
172:
173: return "##ERROR## in toString() of class JoinPointRequestSurrogate";
174: }
175: }
176:
177: //======================================================================
178: //
179: // $Log: JoinPointRequestSurrogate.java,v $
180: // Revision 1.1.1.1 2003/07/02 15:30:52 apopovic
181: // Imported from ETH Zurich
182: //
183: // Revision 1.4 2003/07/02 13:40:54 anicoara
184: // Bug fix; the kind 'Catch' was not known;
185: //
186: // Revision 1.3 2003/05/20 16:05:08 popovici
187: //
188: // New QueryManager replaces functionality in AspectManager (better Soc)
189: // New 'Surrogate' classes for usage in the QueryManager
190: // The 'RemoteAspectManager' and tools modified to use the Surrogates and the QueryManager
191: //
192: // Revision 1.2 2003/05/06 15:51:50 popovici
193: // Mozilla-ification
194: //
195: // Revision 1.1 2003/05/05 13:58:20 popovici
196: // renaming from runes to prose
197: //
198: // Revision 1.8 2003/04/26 18:51:40 popovici
199: // 1 Bug fix which lead to a refactoring step:
200: // 1. the bug: 'JoinPointRequests' used to write to a static list, which survived a startup/teardown;
201: // now this list belongs to the JoinPointManager;
202: // 2. the refactoring: the JoinPointManager now creates (and shares state) with join-points.
203: //
204: // Revision 1.7 2003/04/17 15:14:57 popovici
205: // Extension->Aspect renaming
206: //
207: // Revision 1.6 2003/04/14 19:11:25 popovici
208: // Eliminating System.err.println
209: //
210: // Revision 1.5 2003/03/13 14:16:55 popovici
211: // All items traveling with Tupels are now Serializable
212: //
213: // Revision 1.4 2003/03/04 18:36:02 popovici
214: // Organization of imprts
215: //
216: // Revision 1.3 2003/03/04 11:27:36 popovici
217: // Important refactorization step (march):
218: // - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
219: // - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
220: // structures
221: //
222: // Revision 1.2 2003/01/27 12:58:57 pschoch
223: // new HashCode Policy with Surrogates; toString() of Surrogates improved
224: //
225: // Revision 1.1 2003/01/17 14:43:57 pschoch
226: // Introduction of 'query' methods in the AspectManager and its
227: // subclasses. The result set is given back in form of surrogates; 4 new tests added to ExtensionManagerTest
228: // ExtensionSystemTest
229: //
|