KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > alt > jiapi > event > MethodEvent


1 /*
2  * Copyright(C) 2001 Mika Riekkinen, Joni Suominen
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or(at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package alt.jiapi.event;
20
21 /**
22  * MethodEvent objects are used to identify methods that
23  * are entered or exited.
24  *
25  * @author Mika Riekkinen
26  * @author Joni Suominen
27  * @version $Revision: 1.12 $ $Date: 2002/03/20 12:00:32 $
28  */

29 public class MethodEvent extends JiapiEvent {
30     /**
31      * Constant used as an id of the MethodEvent
32      */

33     public static final int METHOD_ENTERED = 1;
34
35     /**
36      * Constant used as an id of the MethodEvent
37      */

38     public static final int METHOD_EXITED = 2;
39
40     private Object JavaDoc[] methodArgs;
41
42     /**
43      * Constructor. Target and method args are set to null.
44      *
45      * @param mep an instance of MethodEventProducer
46      * @param sourceObject A Source Object. On static methods, this
47      * is the <code>Class</code>, that method belongs to.
48      * Otherwise Source Object is '<code>this</code>'.
49      * @param methodName Name of the method
50      * @param id METHOD_ENTERED or METHOD_EXITED values should be used
51      */

52     public MethodEvent(MethodEventProducer mep, Object JavaDoc sourceObject,
53                        String JavaDoc methodName, int id) {
54         this(mep, sourceObject, methodName, null, null, id);
55     }
56
57
58     /**
59      * Constructor.
60      *
61      * @param mep an instance of MethodEventProducer
62      * @param sourceObject A Source Object. On static methods, this
63      * is the <code>Class</code>, that method belongs to.
64      * Otherwise Source Object is '<code>this</code>'.
65      * @param methodName Name of the method
66      * @param target 'this'
67      * @param methodArgs arguments of the method
68      * @param id METHOD_ENTERED or METHOD_EXITED values should be used
69      */

70     public MethodEvent(MethodEventProducer mep, Object JavaDoc sourceObject,
71                        String JavaDoc methodName, Object JavaDoc target,
72                        Object JavaDoc[] methodArgs, int id) {
73         super(mep, sourceObject, methodName, target, id);
74
75         this.methodArgs = methodArgs;
76     }
77
78     /**
79      * Get the arguments.
80      * @return arguments, or null, if they were not given.
81      */

82     public Object JavaDoc[] getMethodArgs() {
83         return methodArgs;
84     }
85
86     /**
87      * Get the name of the class producing this event.
88      *
89      * @return name of the class producing this event
90      */

91     public String JavaDoc getClassName() {
92         if (sourceObject instanceof String JavaDoc) {
93             return (String JavaDoc)sourceObject;
94         }
95         if (sourceObject instanceof Class JavaDoc) {
96             // Once this is working, String comparison above
97
// may be removed.
98
return ((Class JavaDoc)sourceObject).getName();
99         }
100
101         return sourceObject.getClass().getName();
102     }
103
104     /**
105      * Get the name of the method producing this event.
106      * @return name of the method
107      */

108     public String JavaDoc getMethodName() {
109         return super.getTargetName();
110     }
111
112     /**
113      * Is this method a constructor?
114      * @return true, if this MethoEvent was triggered by constructor.
115      */

116     public boolean isConstructor() {
117         return "<init>".equals(getMethodName());
118     }
119
120     /**
121      * Is this method a static initializer.
122      * @return true, if this MethoEvent was triggered by static initializer.
123      */

124     public boolean isStaticInitializer() {
125         return "<clinit>".equals(getMethodName());
126     }
127 }
128
129
130
Popular Tags