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