KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > tty > ExceptionSpec


1 /*
2  * @(#)ExceptionSpec.java 1.17 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.tty;
36
37 import com.sun.jdi.ReferenceType;
38 import com.sun.jdi.request.*;
39
40 import java.util.ArrayList JavaDoc;
41 import java.util.List JavaDoc;
42 import java.util.Iterator JavaDoc;
43
44 class ExceptionSpec extends EventRequestSpec {
45     private boolean notifyCaught;
46     private boolean notifyUncaught;
47
48     private ExceptionSpec(ReferenceTypeSpec refSpec) {
49         this(refSpec, true, true);
50     }
51
52     ExceptionSpec(ReferenceTypeSpec refSpec,
53                   boolean notifyCaught,
54                   boolean notifyUncaught) {
55         super(refSpec);
56         this.notifyCaught = notifyCaught;
57         this.notifyUncaught = notifyUncaught;
58     }
59
60     /**
61      * The 'refType' is known to match, return the EventRequest.
62      */

63     EventRequest resolveEventRequest(ReferenceType refType) {
64         EventRequestManager em = refType.virtualMachine().eventRequestManager();
65         ExceptionRequest excReq = em.createExceptionRequest(refType,
66                                                             notifyCaught,
67                                                             notifyUncaught);
68         excReq.enable();
69         return excReq;
70     }
71
72     public boolean notifyCaught() {
73         return notifyCaught;
74     }
75
76     public boolean notifyUncaught() {
77         return notifyUncaught;
78     }
79
80     public int hashCode() {
81         //Reference: Effective Java[tm] (Bloch, 2001), Item 8
82
int result = 17;
83         result = (37 * result) + (notifyCaught() ? 0: 1);
84         result = (37 * result) + (notifyUncaught() ? 0: 1);
85         result = (37 * result) + refSpec.hashCode();
86         return result;
87     }
88
89     public boolean equals(Object JavaDoc obj) {
90         if (obj instanceof ExceptionSpec) {
91             ExceptionSpec es = (ExceptionSpec)obj;
92
93             if (refSpec.equals(es.refSpec) &&
94                 (this.notifyCaught() == es.notifyCaught()) &&
95                 (this.notifyUncaught() == es.notifyUncaught())) {
96                 return true;
97             }
98         }
99         return false;
100     }
101
102     public String JavaDoc toString() {
103         String JavaDoc s;
104         if (notifyCaught && !notifyUncaught) {
105             s = MessageOutput.format("exceptionSpec caught",
106                                      refSpec.toString());
107         } else if (notifyUncaught && !notifyCaught) {
108             s = MessageOutput.format("exceptionSpec uncaught",
109                                      refSpec.toString());
110         } else {
111             s = MessageOutput.format("exceptionSpec all",
112                                      refSpec.toString());
113         }
114         return s;
115     }
116 }
117
Popular Tags