001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.debugger.jpda.breakpoints;
043:
044: import com.sun.jdi.event.ClassPrepareEvent;
045: import com.sun.jdi.event.Event;
046: import com.sun.jdi.request.ClassPrepareRequest;
047: import com.sun.jdi.request.ClassUnloadRequest;
048: import com.sun.jdi.request.EventRequest;
049:
050: import org.netbeans.api.debugger.Session;
051: import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint;
052: import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
053:
054: /**
055: * Implementation of breakpoint on method.
056: *
057: * @author Jan Jancura
058: */
059: public class ClassBreakpointImpl extends ClassBasedBreakpoint {
060:
061: private ClassLoadUnloadBreakpoint breakpoint;
062:
063: public ClassBreakpointImpl(ClassLoadUnloadBreakpoint breakpoint,
064: JPDADebuggerImpl debugger, Session session) {
065: super (breakpoint, debugger, session);
066: this .breakpoint = breakpoint;
067: set();
068: }
069:
070: protected void setRequests() {
071: setClassRequests(breakpoint.getClassFilters(), breakpoint
072: .getClassExclusionFilters(), breakpoint
073: .getBreakpointType(), false);
074: }
075:
076: protected EventRequest createEventRequest(EventRequest oldRequest) {
077: if (oldRequest instanceof ClassPrepareRequest) {
078: ClassPrepareRequest cpr = getEventRequestManager()
079: .createClassPrepareRequest();
080: String[] classFilters = breakpoint.getClassFilters();
081: int i, k = classFilters.length;
082: for (i = 0; i < k; i++) {
083: cpr.addClassFilter(classFilters[i]);
084: }
085: String[] classExclusionFilters = breakpoint
086: .getClassExclusionFilters();
087: k = classExclusionFilters.length;
088: for (i = 0; i < k; i++) {
089: cpr.addClassExclusionFilter(classExclusionFilters[i]);
090: }
091: return cpr;
092: }
093: if (oldRequest instanceof ClassUnloadRequest) {
094: ClassUnloadRequest cur = getEventRequestManager()
095: .createClassUnloadRequest();
096: String[] classFilters = breakpoint.getClassFilters();
097: int i, k = classFilters.length;
098: for (i = 0; i < k; i++) {
099: cur.addClassFilter(classFilters[i]);
100: }
101: String[] classExclusionFilters = breakpoint
102: .getClassExclusionFilters();
103: k = classExclusionFilters.length;
104: for (i = 0; i < k; i++) {
105: cur.addClassExclusionFilter(classExclusionFilters[i]);
106: }
107: return cur;
108: }
109: return null;
110: }
111:
112: public boolean exec(Event event) {
113: if (event instanceof ClassPrepareEvent)
114: try {
115: return perform(event, null, ((ClassPrepareEvent) event)
116: .thread(), ((ClassPrepareEvent) event)
117: .referenceType(), ((ClassPrepareEvent) event)
118: .referenceType().classObject());
119: } catch (UnsupportedOperationException ex) {
120: // PATCH for KVM. They does not support
121: // ReferenceType.classObject ()
122: return perform(event, null, ((ClassPrepareEvent) event)
123: .thread(), ((ClassPrepareEvent) event)
124: .referenceType(), null);
125: }
126: else
127: return perform(event, null, null, null, null);
128: }
129:
130: }
|