1 7 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 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 70 abstract void resolve(ReferenceType refType) throws Exception ; 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 81 void resolveNotify(ReferenceType refType) { 82 try { 83 resolve(refType); 84 status = STATUS_RESOLVED; 85 specs.notifyResolved(this); 86 } catch(Exception exc) { 87 status = STATUS_ERROR; 88 specs.notifyError(this, exc); 89 } 90 } 91 92 95 void attemptResolve(ReferenceType refType) { 96 if (!isResolved() && refSpec.matches(refType)) { 97 resolveNotify(refType); 98 } 99 } 100 101 void attemptImmediateResolve(VirtualMachine vm) { 102 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 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 128 public boolean isResolved() { 129 return status == STATUS_RESOLVED; 130 } 131 132 135 public boolean isUnresolved() { 136 return status == STATUS_UNRESOLVED; 137 } 138 139 142 public boolean isErroneous() { 143 return status == STATUS_ERROR; 144 } 145 146 public String 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 s) { 159 return Utils.isJavaIdentifier(s); 160 } 161 162 public String errorMessageFor(Exception e) { 163 if (e instanceof IllegalArgumentException ) { 164 return ("Invalid command syntax"); 165 } else if (e instanceof RuntimeException ) { 166 throw (RuntimeException )e; 168 } else { 169 return ("Internal error; unable to set" + this); 170 } 171 } 172 } 173 174 175 | Popular Tags |