KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > debug > DebugAction


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model.debug;
35
36 import com.sun.jdi.request.*;
37 import java.util.Vector JavaDoc;
38
39 /** Keeps track of information about any request to the debugger, such as Breakpoints.
40  * @version $Id: DebugAction.java 3856 2006-05-24 06:18:08Z rcartwright $
41  */

42 public abstract class DebugAction<T extends EventRequest> {
43   public static final int ANY_LINE = -1;
44
45   protected final JPDADebugger _manager;
46
47   // Request fields
48

49   /** Vector of EventRequests. There might be more than one, since there can be multiple reference types for one class.
50    * They all share the same attributes, though, so the other fields don't need to be vectors.
51    */

52   protected final Vector JavaDoc<T> _requests;
53   protected volatile int _suspendPolicy = EventRequest.SUSPEND_NONE;
54   protected volatile boolean _isEnabled = true;
55   protected volatile int _countFilter = -1;
56   protected volatile int _lineNumber = ANY_LINE;
57
58   /** Creates a new DebugAction. Automatically tries to create the EventRequest if a ReferenceType can be found, or
59    * else adds this object to the PendingRequestManager. Any subclass should automatically call _initializeRequest
60    * in its constructor.
61    * @param manager JPDADebugger in charge
62    */

63   public DebugAction(JPDADebugger manager) {
64     _manager = manager;
65     _requests = new Vector JavaDoc<T>();
66   }
67
68   /** Returns the EventRequest corresponding to this DebugAction, if it has been created, null otherwise. */
69   public Vector JavaDoc<T> getRequests() { return _requests; }
70
71   /** Returns the line number this DebugAction occurs on */
72   public int getLineNumber() { return _lineNumber; }
73
74   /** Creates an EventRequest corresponding to this DebugAction, using the given ReferenceType. This is called either
75    * from the DebugAction constructor or the PendingRequestManager, depending on when the ReferenceType becomes
76    * available. This DebugAction must be an instance of DocumentDebugAction since a ReferenceType is being used.
77    * @return true if the EventRequest is successfully created
78    */

79   //public abstract boolean createRequests(ReferenceType rt) throws DebugException;
80

81   public boolean createRequests() throws DebugException {
82     _createRequests();
83     if (_requests.size() > 0) {
84       _prepareRequests(_requests);
85       return true;
86     }
87     else return false;
88   }
89
90   /** This should always be called from the constructor of the subclass. Tries to create all applicable EventRequests
91    * for this DebugAction.
92    */

93   protected void _initializeRequests() throws DebugException {
94     createRequests();
95     if (_requests.size() == 0) {
96       throw new DebugException("Could not create EventRequests for this action!");
97     }
98   }
99
100   /** Creates an appropriate EventRequest from the EventRequestManager and stores it in the _request field.
101    * @throws DebugException if the request could not be created.
102    */

103   protected void _createRequests() throws DebugException { }
104
105   /** Prepares all relevant EventRequests with the current stored values.
106    * @param requests the EventRequests to prepare
107    */

108   protected void _prepareRequests(Vector JavaDoc<T> requests) {
109     for (int i=0; i < requests.size(); i++) {
110       _prepareRequest(requests.get(i));
111     }
112   }
113
114   /** Prepares this EventRequest with the current stored values.
115    * @param request the EventRequest to prepare
116    */

117   protected void _prepareRequest(T request) {
118     // the request must be disabled to be edited
119
request.setEnabled(false);
120
121     if (_countFilter != -1) {
122       request.addCountFilter(_countFilter);
123     }
124     request.setSuspendPolicy(_suspendPolicy);
125     request.setEnabled(_isEnabled);
126
127     // Add properties
128
request.putProperty("debugAction", this);
129   }
130   
131   /** @return true if breakpoint is enabled. */
132   public boolean isEnabled() { return _isEnabled; }
133   
134   
135   /** Enable/disable the breakpoint. */
136   public void setEnabled(boolean isEnabled) { _isEnabled = isEnabled; }
137 }
138
Popular Tags