blob: 66eb8cb37d61fa07a08951b74543f2fc8c7b9fa8 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-2002 Sun Microsystems, Inc. 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. 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
26package com.sun.tools.example.debug.tty;
27
28import com.sun.jdi.ReferenceType;
29import com.sun.jdi.request.*;
30
31import java.util.ArrayList;
32import java.util.List;
33import java.util.Iterator;
34
35class ExceptionSpec extends EventRequestSpec {
36 private boolean notifyCaught;
37 private boolean notifyUncaught;
38
39 private ExceptionSpec(ReferenceTypeSpec refSpec) {
40 this(refSpec, true, true);
41 }
42
43 ExceptionSpec(ReferenceTypeSpec refSpec,
44 boolean notifyCaught,
45 boolean notifyUncaught) {
46 super(refSpec);
47 this.notifyCaught = notifyCaught;
48 this.notifyUncaught = notifyUncaught;
49 }
50
51 /**
52 * The 'refType' is known to match, return the EventRequest.
53 */
54 EventRequest resolveEventRequest(ReferenceType refType) {
55 EventRequestManager em = refType.virtualMachine().eventRequestManager();
56 ExceptionRequest excReq = em.createExceptionRequest(refType,
57 notifyCaught,
58 notifyUncaught);
59 excReq.enable();
60 return excReq;
61 }
62
63 public boolean notifyCaught() {
64 return notifyCaught;
65 }
66
67 public boolean notifyUncaught() {
68 return notifyUncaught;
69 }
70
71 public int hashCode() {
72 //Reference: Effective Java[tm] (Bloch, 2001), Item 8
73 int result = 17;
74 result = (37 * result) + (notifyCaught() ? 0: 1);
75 result = (37 * result) + (notifyUncaught() ? 0: 1);
76 result = (37 * result) + refSpec.hashCode();
77 return result;
78 }
79
80 public boolean equals(Object obj) {
81 if (obj instanceof ExceptionSpec) {
82 ExceptionSpec es = (ExceptionSpec)obj;
83
84 if (refSpec.equals(es.refSpec) &&
85 (this.notifyCaught() == es.notifyCaught()) &&
86 (this.notifyUncaught() == es.notifyUncaught())) {
87 return true;
88 }
89 }
90 return false;
91 }
92
93 public String toString() {
94 String s;
95 if (notifyCaught && !notifyUncaught) {
96 s = MessageOutput.format("exceptionSpec caught",
97 refSpec.toString());
98 } else if (notifyUncaught && !notifyCaught) {
99 s = MessageOutput.format("exceptionSpec uncaught",
100 refSpec.toString());
101 } else {
102 s = MessageOutput.format("exceptionSpec all",
103 refSpec.toString());
104 }
105 return s;
106 }
107}