1 package net.sourceforge.phpeclipse.xdebug.core.xdebug;
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
6 //import javax.print.attribute.standard.Fidelity;
7 import javax.xml.parsers.DocumentBuilder;
8 import javax.xml.parsers.DocumentBuilderFactory;
9 import javax.xml.parsers.ParserConfigurationException;
11 import net.sourceforge.phpeclipse.xdebug.core.IPHPDebugEvent;
12 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
13 import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin;
14 import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugResponse;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.core.runtime.jobs.Job;
19 import org.eclipse.debug.core.DebugEvent;
20 import org.eclipse.debug.core.DebugPlugin;
21 import org.w3c.dom.Document;
22 import org.w3c.dom.NamedNodeMap;
23 import org.w3c.dom.Node;
24 import org.xml.sax.SAXException;
25 import org.w3c.dom.CDATASection;
28 * Listens to events from the XDebug and fires corresponding
32 public class ResponseListener extends Job {
33 private XDebugConnection fConnection;
34 private ResponseList fResponseList;
36 public ResponseListener(XDebugConnection connection) {
37 super("XDebug Event Dispatch");
39 fConnection = connection;
40 fResponseList = new ResponseList();
43 private void checkResponse(XDebugResponse response) {
44 if (response.getStatus().equals("stopping") || response.getStatus().equals("stopped")) {
46 fireEvent(IPHPDebugEvent.STOPPED, null);
47 } else if (response.getStatus().equals("break") && response.getReason().equals("ok")){
48 if (response.getCommand().equals("run")) {
49 fireEvent(IPHPDebugEvent.BREAKPOINT_HIT, null);
50 } else if (response.getCommand().equals("step_into")) {
51 fireEvent(IPHPDebugEvent.STEP_END, null);
52 } else if (response.getCommand().equals("step_over")) {
53 fireEvent(IPHPDebugEvent.STEP_END, null);
54 } else if (response.getCommand().equals("step_out")) {
55 fireEvent(IPHPDebugEvent.STEP_END, null);
60 private void fireEvent(int detail, Object data) {
61 DebugEvent event = new DebugEvent(this, DebugEvent.MODEL_SPECIFIC, detail);
63 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event});
67 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
69 protected IStatus run(IProgressMonitor monitor) {
71 while (!fConnection.isClosed()) {
72 if (!monitor.isCanceled()) {
74 InputXML = fConnection.readData();
75 } catch (Exception e) {
78 if (InputXML != null) {
79 XDebugCorePlugin.log(IStatus.INFO, InputXML);
80 XDebugResponse response = new XDebugResponse(InputXML);
81 if (response.getName() == "response") {
82 fResponseList.add(response);
83 checkResponse(response);
88 return Status.OK_STATUS;
91 public XDebugResponse getResponse(int id) {
92 return fResponseList.get(id);