001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.model.debug.jpda;
038:
039: import com.sun.jdi.request.*;
040: import java.util.Vector;
041: import edu.rice.cs.drjava.model.debug.DebugException;
042:
043: /** Keeps track of information about any request to the debugger, such as Breakpoints.
044: * @version $Id: DebugAction.java 4255 2007-08-28 19:17:37Z mgricken $
045: */
046: public abstract class DebugAction<T extends EventRequest> {
047: public static final int ANY_LINE = -1;
048:
049: protected final JPDADebugger _manager;
050:
051: // Request fields
052:
053: /** Vector of EventRequests. There might be more than one, since there can be multiple reference types for one class.
054: * They all share the same attributes, though, so the other fields don't need to be vectors.
055: */
056: protected final Vector<T> _requests;
057: protected volatile int _suspendPolicy = EventRequest.SUSPEND_NONE;
058: protected volatile boolean _isEnabled = true;
059: protected volatile int _countFilter = -1;
060: protected volatile int _lineNumber = ANY_LINE;
061:
062: /** Creates a new DebugAction. Automatically tries to create the EventRequest if a ReferenceType can be found, or
063: * else adds this object to the PendingRequestManager. Any subclass should automatically call _initializeRequest
064: * in its constructor.
065: * @param manager JPDADebugger in charge
066: */
067: public DebugAction(JPDADebugger manager) {
068: _manager = manager;
069: _requests = new Vector<T>();
070: }
071:
072: /** Returns the EventRequest corresponding to this DebugAction, if it has been created, null otherwise. */
073: public Vector<T> getRequests() {
074: return _requests;
075: }
076:
077: /** Returns the line number this DebugAction occurs on */
078: public int getLineNumber() {
079: return _lineNumber;
080: }
081:
082: /** Creates an EventRequest corresponding to this DebugAction, using the given ReferenceType. This is called either
083: * from the DebugAction constructor or the PendingRequestManager, depending on when the ReferenceType becomes
084: * available. This DebugAction must be an instance of DocumentDebugAction since a ReferenceType is being used.
085: * @return true if the EventRequest is successfully created
086: */
087: //public abstract boolean createRequests(ReferenceType rt) throws DebugException;
088: public boolean createRequests() throws DebugException {
089: _createRequests();
090: if (_requests.size() > 0) {
091: _prepareRequests(_requests);
092: return true;
093: } else
094: return false;
095: }
096:
097: /** This should always be called from the constructor of the subclass. Tries to create all applicable EventRequests
098: * for this DebugAction.
099: */
100: protected void _initializeRequests() throws DebugException {
101: createRequests();
102: if (_requests.size() == 0) {
103: throw new DebugException(
104: "Could not create EventRequests for this action!");
105: }
106: }
107:
108: /** Creates an appropriate EventRequest from the EventRequestManager and stores it in the _request field.
109: * @throws DebugException if the request could not be created.
110: */
111: protected void _createRequests() throws DebugException {
112: }
113:
114: /** Prepares all relevant EventRequests with the current stored values.
115: * @param requests the EventRequests to prepare
116: */
117: protected void _prepareRequests(Vector<T> requests) {
118: for (int i = 0; i < requests.size(); i++) {
119: _prepareRequest(requests.get(i));
120: }
121: }
122:
123: /** Prepares this EventRequest with the current stored values.
124: * @param request the EventRequest to prepare
125: */
126: protected void _prepareRequest(T request) {
127: // the request must be disabled to be edited
128: request.setEnabled(false);
129:
130: if (_countFilter != -1) {
131: request.addCountFilter(_countFilter);
132: }
133: request.setSuspendPolicy(_suspendPolicy);
134: request.setEnabled(_isEnabled);
135:
136: // Add properties
137: request.putProperty("debugAction", this );
138: }
139:
140: /** @return true if breakpoint is enabled. */
141: public boolean isEnabled() {
142: return _isEnabled;
143: }
144:
145: /** Enable/disable the breakpoint. */
146: public void setEnabled(boolean isEnabled) {
147: _isEnabled = isEnabled;
148: }
149: }
|