KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > breakpoints > FieldBreakpointImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.debugger.jpda.breakpoints;
21
22 import com.sun.jdi.Field;
23 import com.sun.jdi.ReferenceType;
24 import com.sun.jdi.VMDisconnectedException;
25 import com.sun.jdi.event.Event;
26 import com.sun.jdi.event.ModificationWatchpointEvent;
27 import com.sun.jdi.event.WatchpointEvent;
28 import com.sun.jdi.event.LocatableEvent;
29 import com.sun.jdi.event.AccessWatchpointEvent;
30 import com.sun.jdi.request.AccessWatchpointRequest;
31 import com.sun.jdi.request.ModificationWatchpointRequest;
32 import org.netbeans.api.debugger.Breakpoint.VALIDITY;
33 import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint;
34 import org.netbeans.api.debugger.jpda.FieldBreakpoint;
35 import org.netbeans.api.debugger.Session;
36 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
37 import org.openide.util.NbBundle;
38
39 /**
40 * Implementation of breakpoint on method.
41 *
42 * @author Jan Jancura
43 */

44 public class FieldBreakpointImpl extends ClassBasedBreakpoint {
45
46     
47     private FieldBreakpoint breakpoint;
48     
49     
50     public FieldBreakpointImpl (FieldBreakpoint breakpoint, JPDADebuggerImpl debugger, Session session) {
51         super (breakpoint, debugger, session);
52         this.breakpoint = breakpoint;
53         set ();
54     }
55     
56     protected void setRequests () {
57         boolean access = (breakpoint.getBreakpointType () &
58                           FieldBreakpoint.TYPE_ACCESS) != 0;
59         if (access && !getVirtualMachine().canWatchFieldAccess()) {
60             setValidity(VALIDITY.INVALID,
61                     NbBundle.getMessage(FieldBreakpointImpl.class, "MSG_NoFieldAccess"));
62             return ;
63         }
64         boolean modification = (breakpoint.getBreakpointType () &
65                                 FieldBreakpoint.TYPE_MODIFICATION) != 0;
66         if (modification && !getVirtualMachine().canWatchFieldModification()) {
67             setValidity(VALIDITY.INVALID,
68                     NbBundle.getMessage(FieldBreakpointImpl.class, "MSG_NoFieldModification"));
69             return ;
70         }
71         setClassRequests (
72             new String JavaDoc[] {breakpoint.getClassName ()},
73             new String JavaDoc[0],
74             ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED
75         );
76         checkLoadedClasses (breakpoint.getClassName ());
77     }
78     
79     protected void classLoaded (ReferenceType referenceType) {
80         Field f = referenceType.fieldByName (breakpoint.getFieldName ());
81         if (f == null) {
82             setValidity(VALIDITY.INVALID,
83                     NbBundle.getMessage(FieldBreakpointImpl.class, "MSG_NoField", referenceType.name(), breakpoint.getFieldName ()));
84             return ;
85         }
86         try {
87             if ( (breakpoint.getBreakpointType () &
88                   FieldBreakpoint.TYPE_ACCESS) != 0
89             ) {
90                 AccessWatchpointRequest awr = getEventRequestManager ().
91                     createAccessWatchpointRequest (f);
92                 addEventRequest (awr);
93             }
94             if ( (breakpoint.getBreakpointType () &
95                   FieldBreakpoint.TYPE_MODIFICATION) != 0
96             ) {
97                 ModificationWatchpointRequest mwr = getEventRequestManager ().
98                     createModificationWatchpointRequest (f);
99                 addEventRequest (mwr);
100             }
101             setValidity(VALIDITY.VALID, null);
102         } catch (VMDisconnectedException e) {
103         }
104     }
105
106     public boolean exec (Event event) {
107         if (event instanceof ModificationWatchpointEvent)
108             return perform (
109                 breakpoint.getCondition (),
110                 ((WatchpointEvent) event).thread (),
111                 ((LocatableEvent) event).location ().declaringType (),
112                 ((ModificationWatchpointEvent) event).valueToBe ()
113             );
114         if (event instanceof AccessWatchpointEvent)
115             return perform (
116                 breakpoint.getCondition (),
117                 ((WatchpointEvent) event).thread (),
118                 ((LocatableEvent) event).location ().declaringType (),
119                 ((AccessWatchpointEvent) event).valueCurrent ()
120             );
121         return super.exec (event);
122     }
123 }
124
125
Popular Tags