Showing the changes to java/pkg/com/sun/tools/example/debug/bdi/EventRequestSpec.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,159 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. | |
| 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. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.tools.example.debug.bdi; | |
| 27 | + | |
| 28 | +import com.sun.jdi.*; | |
| 29 | +import com.sun.jdi.request.EventRequest; | |
| 30 | + | |
| 31 | +abstract public class EventRequestSpec { | |
| 32 | + | |
| 33 | + static final int STATUS_UNRESOLVED = 1; | |
| 34 | + static final int STATUS_RESOLVED = 2; | |
| 35 | + static final int STATUS_ERROR = 3; | |
| 36 | + | |
| 37 | + static final Object specPropertyKey = "spec"; | |
| 38 | + | |
| 39 | + final EventRequestSpecList specs; | |
| 40 | + final ReferenceTypeSpec refSpec; | |
| 41 | + EventRequest request = null; | |
| 42 | + | |
| 43 | + int status = STATUS_UNRESOLVED; | |
| 44 | + | |
| 45 | + EventRequestSpec(EventRequestSpecList specs, ReferenceTypeSpec refSpec) { | |
| 46 | + this.specs = specs; | |
| 47 | + this.refSpec = refSpec; | |
| 48 | + } | |
| 49 | + | |
| 50 | + void setRequest(EventRequest request) { | |
| 51 | + this.request = request; | |
| 52 | + request.putProperty(specPropertyKey, this); | |
| 53 | + request.enable(); | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * The 'refType' is known to match. | |
| 58 | + */ | |
| 59 | + abstract void resolve(ReferenceType refType) throws Exception; | |
| 60 | + | |
| 61 | + abstract void notifySet(SpecListener listener, SpecEvent evt); | |
| 62 | + abstract void notifyDeferred(SpecListener listener, SpecEvent evt); | |
| 63 | + abstract void notifyResolved(SpecListener listener, SpecEvent evt); | |
| 64 | + abstract void notifyDeleted(SpecListener listener, SpecEvent evt); | |
| 65 | + abstract void notifyError(SpecListener listener, SpecErrorEvent evt); | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * The 'refType' is known to match. | |
| 69 | + */ | |
| 70 | + void resolveNotify(ReferenceType refType) { | |
| 71 | + try { | |
| 72 | + resolve(refType); | |
| 73 | + status = STATUS_RESOLVED; | |
| 74 | + specs.notifyResolved(this); | |
| 75 | + } catch(Exception exc) { | |
| 76 | + status = STATUS_ERROR; | |
| 77 | + specs.notifyError(this, exc); | |
| 78 | + } | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * See if 'refType' matches and resolve. | |
| 83 | + */ | |
| 84 | + void attemptResolve(ReferenceType refType) { | |
| 85 | + if (!isResolved() && refSpec.matches(refType)) { | |
| 86 | + resolveNotify(refType); | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 90 | + void attemptImmediateResolve(VirtualMachine vm) { | |
| 91 | + // try to resolve immediately | |
| 92 | + for (ReferenceType refType : vm.allClasses()) { | |
| 93 | + if (refSpec.matches(refType)) { | |
| 94 | + try { | |
| 95 | + resolve(refType); | |
| 96 | + status = STATUS_RESOLVED; | |
| 97 | + specs.notifySet(this); | |
| 98 | + } catch(Exception exc) { | |
| 99 | + status = STATUS_ERROR; | |
| 100 | + specs.notifyError(this, exc); | |
| 101 | + } | |
| 102 | + return; | |
| 103 | + } | |
| 104 | + } | |
| 105 | + specs.notifyDeferred(this); | |
| 106 | + } | |
| 107 | + | |
| 108 | + public EventRequest getEventRequest() { | |
| 109 | + return request; | |
| 110 | + } | |
| 111 | + | |
| 112 | + /** | |
| 113 | + * @return true if this spec has been resolved. | |
| 114 | + */ | |
| 115 | + public boolean isResolved() { | |
| 116 | + return status == STATUS_RESOLVED; | |
| 117 | + } | |
| 118 | + | |
| 119 | + /** | |
| 120 | + * @return true if this spec has not yet been resolved. | |
| 121 | + */ | |
| 122 | + public boolean isUnresolved() { | |
| 123 | + return status == STATUS_UNRESOLVED; | |
| 124 | + } | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * @return true if this spec is unresolvable due to error. | |
| 128 | + */ | |
| 129 | + public boolean isErroneous() { | |
| 130 | + return status == STATUS_ERROR; | |
| 131 | + } | |
| 132 | + | |
| 133 | + public String getStatusString() { | |
| 134 | + switch (status) { | |
| 135 | + case STATUS_RESOLVED: | |
| 136 | + return "resolved"; | |
| 137 | + case STATUS_UNRESOLVED: | |
| 138 | + return "deferred"; | |
| 139 | + case STATUS_ERROR: | |
| 140 | + return "erroneous"; | |
| 141 | + } | |
| 142 | + return "unknown"; | |
| 143 | + } | |
| 144 | + | |
| 145 | + boolean isJavaIdentifier(String s) { | |
| 146 | + return Utils.isJavaIdentifier(s); | |
| 147 | + } | |
| 148 | + | |
| 149 | + public String errorMessageFor(Exception e) { | |
| 150 | + if (e instanceof IllegalArgumentException) { | |
| 151 | + return ("Invalid command syntax"); | |
| 152 | + } else if (e instanceof RuntimeException) { | |
| 153 | + // A runtime exception that we were not expecting | |
| 154 | + throw (RuntimeException)e; | |
| 155 | + } else { | |
| 156 | + return ("Internal error; unable to set" + this); | |
| 157 | + } | |
| 158 | + } | |
| 159 | +} | |