Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / debugger / spec / EventRequestSpecList.java
1 package jde.debugger.spec;
2
3
4 import com.sun.jdi.*;
5 import com.sun.jdi.event.*;
6 import com.sun.jdi.request.*;
7
8 import java.util.*;
9 import jde.debugger.JDEException;
10 import jde.debugger.JDE;
11 import jde.debugger.Debugger;
12 import jde.debugger.Protocol;
13
14 /**
15  * EventRequestSpecList.java
16  * <p>
17  * Maintains a list of all the "specs", i.e. requests by the user for
18  * notification of a particular type of event. Not all commands create
19  * specs: watchpoints, breakpoints, and exception catches do.
20  * <p>
21  * See {@link EventRequestSpec} for more details.
22  * <p>
23  * Created: Thu Jul 15 11:26:23 1999
24  *
25  * @author Amit Kumar
26  * @since 0.1
27  */
28
29 public class EventRequestSpecList implements Protocol {
30
31   /**
32    * a Hashmap of all the {@link EventRequestSpec}s for the application,
33    * specID -> spec
34    */
35   private Map      m_eventRequestSpecs;
36   private Debugger m_debugger;
37
38   public EventRequestSpecList(Debugger debugger) {
39     m_eventRequestSpecs = new HashMap();
40     m_debugger          = debugger;
41   }
42     
43   /** 
44    * Resolve all deferred eventRequests waiting for 'refType'. This is
45    * called when a new reference type is prepared. We iterate through
46    * all the requestspecs, calling their
47    * {@link EventRequestSpec#attemptResolve attemptResolve}
48    * methods.
49    *
50    * @param refType The reference type that was recently prepared
51    */
52   public void resolve(ReferenceType refType) {
53     synchronized(m_eventRequestSpecs) {
54       Iterator iter = m_eventRequestSpecs.values().iterator();
55       while (iter.hasNext()) {
56         EventRequestSpec ers = (EventRequestSpec) iter.next();
57                 
58         try {
59           ers.attemptResolve(refType, m_debugger.getProcID());
60         }
61         catch (JDEException e) {
62           JDE.debug(EXCEPTION, e.toString());
63           // XXX should I do this: 
64           m_eventRequestSpecs.remove(ers.getID());
65           // I think so.
66         }
67       }
68     }
69   }
70     
71   /** Install a new event request spec - XXX synchronize throughout!? */
72   public void install(EventRequestSpec ers) throws JDEException {
73     synchronized (m_eventRequestSpecs) {
74       m_eventRequestSpecs.put(ers.getID(), ers);
75     }
76
77     try {
78       ers.attemptImmediateResolve(m_debugger.getVM(), m_debugger.getProcID());
79     }
80     catch (JDEException e) {
81       synchronized (m_eventRequestSpecs) {
82         m_eventRequestSpecs.remove(ers.getID());
83       }
84       // and propagate the problem
85       throw e;
86     }
87   }
88
89   /** Delete an existing event request spec */
90   public void delete(EventRequestSpec ers) {
91     EventRequest request = ers.getEventRequest();
92     synchronized (m_eventRequestSpecs) {
93       m_eventRequestSpecs.remove(ers.getID());
94     }
95     // XXX - prolly want to change the below stuff
96     if (request != null) {
97       request.virtualMachine().eventRequestManager()
98         .deleteEventRequest(request);
99     }
100   }
101
102   /** remove a spec based on its specID */
103   public void removeSpec(Long specID)
104     throws JDEException {
105     synchronized (m_eventRequestSpecs) {
106       if (!m_eventRequestSpecs.containsKey(specID))
107         throw new JDEException("'"+specID+"' doesn't exist");
108       delete((EventRequestSpec)m_eventRequestSpecs.get(specID));
109     }
110   }
111
112   public EventRequestSpec createExceptionIntercept(String classPattern, 
113                                                    boolean notifyCaught, 
114                                                    boolean notifyUncaught){
115     ReferenceTypeSpec refSpec =
116       new PatternReferenceTypeSpec(classPattern);
117     EventRequestSpec ers =
118       new ExceptionSpec(refSpec, notifyCaught, notifyUncaught);
119     return ers;
120   }
121
122   public WatchpointSpec createAccessWatchpoint
123     (String classPattern, String m) {
124     ReferenceTypeSpec refSpec = 
125       new PatternReferenceTypeSpec(classPattern);
126     WatchpointSpec ers =
127       new AccessWatchpointSpec(refSpec, m);
128     return ers;
129   }
130
131   public WatchpointSpec createModificationWatchpoint
132     (String classPattern, String m) {
133     ReferenceTypeSpec refSpec = 
134       new PatternReferenceTypeSpec(classPattern);
135     WatchpointSpec ers =
136       new ModificationWatchpointSpec(refSpec, m);
137     return ers;
138   }
139
140   public EventRequestSpec createClassLineBreakpoint
141     (String classPattern, int line) {
142     ReferenceTypeSpec refSpec = 
143       new PatternReferenceTypeSpec(classPattern);
144     EventRequestSpec ers =
145       new LineBreakpointSpec(refSpec, line);
146     return ers;
147   }
148
149   public EventRequestSpec createSourceLineBreakpoint
150     (String sourceName, int line) {
151     ReferenceTypeSpec refSpec = 
152       new SourceNameReferenceTypeSpec(sourceName, line);
153     EventRequestSpec ers = 
154       new LineBreakpointSpec(refSpec, line);
155     return ers;
156   }
157         
158   public EventRequestSpec createMethodBreakpoint
159     (String classPattern, String methodId, List methodArgs) {
160     ReferenceTypeSpec refSpec = 
161       new PatternReferenceTypeSpec(classPattern);
162     EventRequestSpec e = 
163       new MethodBreakpointSpec(refSpec, methodId, methodArgs);
164     return e;
165   }
166         
167 } // EventRequestSpecList
168
169 /*
170  * $Log: EventRequestSpecList.java,v $
171  * Revision 1.4  2003/01/15 06:06:15  paulk
172  * Petter Mahlen's changes.
173  *
174  */
175
176 // End of EventRequestSpecList.java