KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > bdi > EventRequestSpec


1 /*
2  * @(#)EventRequestSpec.java 1.10 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
9  *
10  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
11  * modify and redistribute this software in source and binary code form,
12  * provided that i) this copyright notice and license appear on all copies of
13  * the software; and ii) Licensee does not utilize the software in a manner
14  * which is disparaging to Sun.
15  *
16  * This software is provided "AS IS," without a warranty of any kind. ALL
17  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
18  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
19  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
20  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
21  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
22  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
23  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
24  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
25  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGES.
27  *
28  * This software is not designed or intended for use in on-line control of
29  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
30  * the design, construction, operation or maintenance of any nuclear
31  * facility. Licensee represents and warrants that it will not use or
32  * redistribute the Software for such purposes.
33  */

34
35 package com.sun.tools.example.debug.bdi;
36
37 import java.util.*;
38
39 import com.sun.jdi.*;
40 import com.sun.jdi.request.EventRequest;
41
42 abstract public class EventRequestSpec {
43
44     static final int STATUS_UNRESOLVED = 1;
45     static final int STATUS_RESOLVED = 2;
46     static final int STATUS_ERROR = 3;
47
48     static final Object JavaDoc specPropertyKey = "spec";
49
50     final EventRequestSpecList specs;
51     final ReferenceTypeSpec refSpec;
52     EventRequest request = null;
53
54     int status = STATUS_UNRESOLVED;
55
56     EventRequestSpec(EventRequestSpecList specs, ReferenceTypeSpec refSpec) {
57         this.specs = specs;
58         this.refSpec = refSpec;
59     }
60
61     void setRequest(EventRequest request) {
62         this.request = request;
63         request.putProperty(specPropertyKey, this);
64         request.enable();
65     }
66
67     /**
68      * The 'refType' is known to match.
69      */

70     abstract void resolve(ReferenceType refType) throws Exception JavaDoc;
71
72     abstract void notifySet(SpecListener listener, SpecEvent evt);
73     abstract void notifyDeferred(SpecListener listener, SpecEvent evt);
74     abstract void notifyResolved(SpecListener listener, SpecEvent evt);
75     abstract void notifyDeleted(SpecListener listener, SpecEvent evt);
76     abstract void notifyError(SpecListener listener, SpecErrorEvent evt);
77
78     /**
79      * The 'refType' is known to match.
80      */

81     void resolveNotify(ReferenceType refType) {
82         try {
83             resolve(refType);
84             status = STATUS_RESOLVED;
85             specs.notifyResolved(this);
86         } catch(Exception JavaDoc exc) {
87             status = STATUS_ERROR;
88             specs.notifyError(this, exc);
89         }
90     }
91
92     /**
93      * See if 'refType' matches and resolve.
94      */

95     void attemptResolve(ReferenceType refType) {
96         if (!isResolved() && refSpec.matches(refType)) {
97             resolveNotify(refType);
98         }
99     }
100
101     void attemptImmediateResolve(VirtualMachine vm) {
102         // try to resolve immediately
103
Iterator iter = vm.allClasses().iterator();
104         while (iter.hasNext()) {
105             ReferenceType refType = (ReferenceType)iter.next();
106             if (refSpec.matches(refType)) {
107                 try {
108                     resolve(refType);
109                     status = STATUS_RESOLVED;
110                     specs.notifySet(this);
111                 } catch(Exception JavaDoc exc) {
112                     status = STATUS_ERROR;
113                     specs.notifyError(this, exc);
114                 }
115                 return;
116             }
117         }
118         specs.notifyDeferred(this);
119     }
120
121     public EventRequest getEventRequest() {
122         return request;
123     }
124
125     /**
126      * @return true if this spec has been resolved.
127      */

128     public boolean isResolved() {
129         return status == STATUS_RESOLVED;
130     }
131
132     /**
133      * @return true if this spec has not yet been resolved.
134      */

135     public boolean isUnresolved() {
136         return status == STATUS_UNRESOLVED;
137     }
138
139     /**
140      * @return true if this spec is unresolvable due to error.
141      */

142     public boolean isErroneous() {
143         return status == STATUS_ERROR;
144     }
145
146     public String JavaDoc getStatusString() {
147         switch (status) {
148             case STATUS_RESOLVED:
149                 return "resolved";
150             case STATUS_UNRESOLVED:
151                 return "deferred";
152             case STATUS_ERROR:
153                 return "erroneous";
154         }
155         return "unknown";
156     }
157
158     boolean isJavaIdentifier(String JavaDoc s) {
159         return Utils.isJavaIdentifier(s);
160     }
161
162     public String JavaDoc errorMessageFor(Exception JavaDoc e) {
163         if (e instanceof IllegalArgumentException JavaDoc) {
164             return ("Invalid command syntax");
165         } else if (e instanceof RuntimeException JavaDoc) {
166             // A runtime exception that we were not expecting
167
throw (RuntimeException JavaDoc)e;
168         } else {
169             return ("Internal error; unable to set" + this);
170         }
171     }
172 }
173
174
175
Popular Tags