2
|
1 |
/*
|
715
|
2 |
* Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.tools.example.debug.bdi;
|
|
27 |
|
|
28 |
import java.util.*;
|
|
29 |
|
|
30 |
import com.sun.jdi.*;
|
|
31 |
import com.sun.jdi.request.EventRequest;
|
|
32 |
|
|
33 |
abstract public class EventRequestSpec {
|
|
34 |
|
|
35 |
static final int STATUS_UNRESOLVED = 1;
|
|
36 |
static final int STATUS_RESOLVED = 2;
|
|
37 |
static final int STATUS_ERROR = 3;
|
|
38 |
|
|
39 |
static final Object specPropertyKey = "spec";
|
|
40 |
|
|
41 |
final EventRequestSpecList specs;
|
|
42 |
final ReferenceTypeSpec refSpec;
|
|
43 |
EventRequest request = null;
|
|
44 |
|
|
45 |
int status = STATUS_UNRESOLVED;
|
|
46 |
|
|
47 |
EventRequestSpec(EventRequestSpecList specs, ReferenceTypeSpec refSpec) {
|
|
48 |
this.specs = specs;
|
|
49 |
this.refSpec = refSpec;
|
|
50 |
}
|
|
51 |
|
|
52 |
void setRequest(EventRequest request) {
|
|
53 |
this.request = request;
|
|
54 |
request.putProperty(specPropertyKey, this);
|
|
55 |
request.enable();
|
|
56 |
}
|
|
57 |
|
|
58 |
/**
|
|
59 |
* The 'refType' is known to match.
|
|
60 |
*/
|
|
61 |
abstract void resolve(ReferenceType refType) throws Exception;
|
|
62 |
|
|
63 |
abstract void notifySet(SpecListener listener, SpecEvent evt);
|
|
64 |
abstract void notifyDeferred(SpecListener listener, SpecEvent evt);
|
|
65 |
abstract void notifyResolved(SpecListener listener, SpecEvent evt);
|
|
66 |
abstract void notifyDeleted(SpecListener listener, SpecEvent evt);
|
|
67 |
abstract void notifyError(SpecListener listener, SpecErrorEvent evt);
|
|
68 |
|
|
69 |
/**
|
|
70 |
* The 'refType' is known to match.
|
|
71 |
*/
|
|
72 |
void resolveNotify(ReferenceType refType) {
|
|
73 |
try {
|
|
74 |
resolve(refType);
|
|
75 |
status = STATUS_RESOLVED;
|
|
76 |
specs.notifyResolved(this);
|
|
77 |
} catch(Exception exc) {
|
|
78 |
status = STATUS_ERROR;
|
|
79 |
specs.notifyError(this, exc);
|
|
80 |
}
|
|
81 |
}
|
|
82 |
|
|
83 |
/**
|
|
84 |
* See if 'refType' matches and resolve.
|
|
85 |
*/
|
|
86 |
void attemptResolve(ReferenceType refType) {
|
|
87 |
if (!isResolved() && refSpec.matches(refType)) {
|
|
88 |
resolveNotify(refType);
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
|
92 |
void attemptImmediateResolve(VirtualMachine vm) {
|
|
93 |
// try to resolve immediately
|
51
|
94 |
for (ReferenceType refType : vm.allClasses()) {
|
2
|
95 |
if (refSpec.matches(refType)) {
|
|
96 |
try {
|
|
97 |
resolve(refType);
|
|
98 |
status = STATUS_RESOLVED;
|
|
99 |
specs.notifySet(this);
|
|
100 |
} catch(Exception exc) {
|
|
101 |
status = STATUS_ERROR;
|
|
102 |
specs.notifyError(this, exc);
|
|
103 |
}
|
|
104 |
return;
|
|
105 |
}
|
|
106 |
}
|
|
107 |
specs.notifyDeferred(this);
|
|
108 |
}
|
|
109 |
|
|
110 |
public EventRequest getEventRequest() {
|
|
111 |
return request;
|
|
112 |
}
|
|
113 |
|
|
114 |
/**
|
|
115 |
* @return true if this spec has been resolved.
|
|
116 |
*/
|
|
117 |
public boolean isResolved() {
|
|
118 |
return status == STATUS_RESOLVED;
|
|
119 |
}
|
|
120 |
|
|
121 |
/**
|
|
122 |
* @return true if this spec has not yet been resolved.
|
|
123 |
*/
|
|
124 |
public boolean isUnresolved() {
|
|
125 |
return status == STATUS_UNRESOLVED;
|
|
126 |
}
|
|
127 |
|
|
128 |
/**
|
|
129 |
* @return true if this spec is unresolvable due to error.
|
|
130 |
*/
|
|
131 |
public boolean isErroneous() {
|
|
132 |
return status == STATUS_ERROR;
|
|
133 |
}
|
|
134 |
|
|
135 |
public String getStatusString() {
|
|
136 |
switch (status) {
|
|
137 |
case STATUS_RESOLVED:
|
|
138 |
return "resolved";
|
|
139 |
case STATUS_UNRESOLVED:
|
|
140 |
return "deferred";
|
|
141 |
case STATUS_ERROR:
|
|
142 |
return "erroneous";
|
|
143 |
}
|
|
144 |
return "unknown";
|
|
145 |
}
|
|
146 |
|
|
147 |
boolean isJavaIdentifier(String s) {
|
|
148 |
return Utils.isJavaIdentifier(s);
|
|
149 |
}
|
|
150 |
|
|
151 |
public String errorMessageFor(Exception e) {
|
|
152 |
if (e instanceof IllegalArgumentException) {
|
|
153 |
return ("Invalid command syntax");
|
|
154 |
} else if (e instanceof RuntimeException) {
|
|
155 |
// A runtime exception that we were not expecting
|
|
156 |
throw (RuntimeException)e;
|
|
157 |
} else {
|
|
158 |
return ("Internal error; unable to set" + this);
|
|
159 |
}
|
|
160 |
}
|
|
161 |
}
|