Java Reference
In-Depth Information
private
String when
#
null
; // "before" or "after"
private
Class[] parameters
#
null
;
// the list of parameter types
private
Object[] arguments
#
null
;
// the list of argument values
. . .
public
Entry(Trackable target, String methodName,
Class[] parameters, Object[] arguments) {
this
.methodName
#
methodName;
this
.targetRef
#
Tracker.getObjectRef(target);
this
.parameters
#
parameters;
this
.arguments
#
arguments;
}
// use reflection to invoke a method on a target object
public
Object invoke(Object target) {
Object result
#
null
;
try
{
Class c
#
target.getClass();
Method m
#
c.getMethod
(
this
.methodName,
this
.parameters);
result
#
m.invoke(target,
this
.arguments);
}
catch
(Exception e) { System.out.println(e); }
return
result;
}
}
Class
Tracker
has two new member variables that are used to enable and
disable the tracking process and to select the tracking type (logical or
physical).
public final class
Tracker {
...
private static boolean
tracking
#
false
;
private static boolean
logicalRecording
#
false
;
public static void
setLogicalRecording(
boolean
logical) {
logicalRecording
#
logical;
}
public static boolean
isLogicalRecording() {
return
logicalRecording;
}
// opens the tracking log
public static void
startTracking() {
try
{
if
(logicalRecording)
outputFile
#
new
FileOutputStream
("trackerLogical.log");