Refactor.
authorincastrix <incastrix>
Wed, 24 Dec 2008 17:35:22 +0000 (17:35 +0000)
committerincastrix <incastrix>
Wed, 24 Dec 2008 17:35:22 +0000 (17:35 +0000)
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseList.java
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/ResponseListener.java
net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/core/xdebug/XDebugConnection.java

index 2bc1f66..bf0f967 100644 (file)
@@ -13,7 +13,8 @@ public class ResponseList {
                fList = new HashMap();
        }
 
-       public synchronized void add(XDebugResponse response, int id) {
+       public synchronized void add(XDebugResponse response/*, int id*/) {
+               int id = response.getTransactionID();
                fList.put(new Integer(id), response);
                fLastId = id;
                notifyAll();
index 345bd3d..d1ea8f8 100644 (file)
@@ -49,7 +49,16 @@ public class ResponseListener extends Job {
                private String fAddress;
                private String fIdeKey;
                        
-               public synchronized void setParentNode(String xmlInput) {
+               public XDebugResponse(String XMLInput) {
+                       fTransactionID = -1;
+                       fCommand = "";
+                       fStatus = "";
+                       fReason = "";                   
+                       fName= "";
+                       setParentNode(XMLInput);
+               }
+       
+               /*public*/private synchronized void setParentNode(String xmlInput) {
                        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                        DocumentBuilder builder = null;
                        Document doc = null;
@@ -109,11 +118,11 @@ public class ResponseListener extends Job {
                                        int code = Integer.parseInt(PHPDebugUtils.getAttributeValue(child, "code"));
                                        String text = (child.getFirstChild()).getNodeValue();
                                        XDebugCorePlugin.log(IStatus.ERROR," ERROR "+code+": "+text);
-                                       setError(true);
+                                       fError = true;
                                        return;
                                }
                        }
-                       setError(false);
+                       fError = false;
                        
                        fStatus = getAttributeValue("status");
                        fReason = getAttributeValue("reason");
@@ -137,6 +146,8 @@ public class ResponseListener extends Job {
                                        
                                        if( firstChild1 != null ) {
                                                fValue = firstChild1.getNodeValue();
+                                       } else {
+                                               fValue = "";
                                        }
                                } catch (Exception e) {
                                        // TODO: handle exception
@@ -174,14 +185,10 @@ public class ResponseListener extends Job {
                        return parentNode;
                }
                
-               public synchronized String getIdeKey(){
-                       return fIdeKey;
-               }
-               
-               public synchronized String getCommand() {
+               /*public*/private  synchronized String getCommand() {
                        return fCommand;
                }
-               public synchronized String getName() {
+               /*public*/private synchronized String getName() {
                        return fName;
                }
                
@@ -189,18 +196,6 @@ public class ResponseListener extends Job {
                        return fValue;
                }
        
-               public synchronized String getType() {
-                       return fType;
-               }
-       
-               public synchronized String getAddress() {
-                       return fAddress;
-               }
-       
-               public XDebugResponse(String XMLInput) {
-                       setParentNode(XMLInput);
-               }
-       
                public synchronized String getReason() {
                        return fReason;
                }
@@ -213,69 +208,40 @@ public class ResponseListener extends Job {
                        return fTransactionID;
                }
                
-               public boolean  isError() {
+               public boolean isError() {
                        return fError;
                }
-       
-               public void setError(boolean error) {
-                       fError = error;
-               }
-               
-               XDebugResponse() {
-                       fTransactionID = -1;
-                       fCommand = "";
-                       fStatus = "";
-                       fReason = "";                   
-                       fName= "";
-               }
        }
        
+       
        private XDebugConnection fConnection;
-       private XDebugResponse lastResponse; 
-
+       private ResponseList fResponseList;
+       
        public ResponseListener(XDebugConnection connection) {
                super("XDebug Event Dispatch");
                setSystem(true);
                fConnection = connection;
-               lastResponse = new XDebugResponse();
                fResponseList = new ResponseList();
        }
                
        private void checkResponse(XDebugResponse response) {
-               Node node = response.getParentNode();
-               if (node.hasChildNodes()) {
-                       Node child = node.getFirstChild();
-                       if (child.getNodeName().equals("error")) {
-                               int code = Integer.parseInt(PHPDebugUtils.getAttributeValue(child, "code"));
-                               String text=(child.getFirstChild()).getNodeValue();
-                               XDebugCorePlugin.log(IStatus.ERROR," ERROR "+code+": "+text);
-                               lastResponse.setError(true);
-                               return;
-                       }
-               }
-               lastResponse.setError(false);
                if (response.getStatus().equals("stopping") || response.getStatus().equals("stopped")) {
                        this.cancel();
-                       fireEvent(IPHPDebugEvent.STOPPED);
+                       fireEvent(IPHPDebugEvent.STOPPED, null);
                } else if (response.getStatus().equals("break") && response.getReason().equals("ok")){ 
                        if (response.getCommand().equals("run")) {
                                fireEvent(IPHPDebugEvent.BREAKPOINT_HIT, null);
                        } else if (response.getCommand().equals("step_into")) {
-                               fireEvent(IPHPDebugEvent.STEP_END);
+                               fireEvent(IPHPDebugEvent.STEP_END, null);
                        } else if (response.getCommand().equals("step_over")) {
-                               fireEvent(IPHPDebugEvent.STEP_END);
+                               fireEvent(IPHPDebugEvent.STEP_END, null);
                        } else if (response.getCommand().equals("step_out")) {
-                               fireEvent(IPHPDebugEvent.STEP_END);
+                               fireEvent(IPHPDebugEvent.STEP_END, null);
                        } 
                } 
        }
        
-       protected void fireEvent(int detail) {
-               DebugEvent event = new DebugEvent(this, DebugEvent.MODEL_SPECIFIC, detail);
-               DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event});
-       }
-       
-       protected void fireEvent(int detail, Object data) {
+       private void fireEvent(int detail, Object data) {
                DebugEvent event = new DebugEvent(this, DebugEvent.MODEL_SPECIFIC, detail);
                event.setData(data);
                DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {event});
@@ -286,33 +252,26 @@ public class ResponseListener extends Job {
         */
        protected IStatus run(IProgressMonitor monitor) {
                String InputXML = "";
-               while (!fConnection.isClosed() && (InputXML != null)) {
+               while (!fConnection.isClosed()) {
                        if (!monitor.isCanceled()) {
                                try {
-                               if(!fConnection.isClosed()) {
                                        InputXML = fConnection.readData();
-                               }
                                } catch (Exception e) {
                                        ; //
                                }
                                if (InputXML != null) {
                                        XDebugCorePlugin.log(IStatus.INFO, InputXML);
-                                       lastResponse.setParentNode(InputXML);
-                                       if (lastResponse.getName() == "response") {
-                                               addResponse(lastResponse, lastResponse.getTransactionID());
-                                               checkResponse(lastResponse);
+                                       XDebugResponse response = new XDebugResponse(InputXML);
+                                       if (response.getName() == "response") {
+                                               fResponseList.add(response);
+                                               checkResponse(response);
                                        }
                                }
                        }
                }
                return Status.OK_STATUS;
        }
-       private ResponseList fResponseList;
-       
-       protected void addResponse(XDebugResponse response, int id) {
-               fResponseList.add(response, id);
-       }
-       
+
        public XDebugResponse getResponse(int id) {
                return fResponseList.get(id);
        }
index 19e6a2f..a2b9a03 100644 (file)
@@ -114,6 +114,10 @@ public class XDebugConnection {
        }
 
        private synchronized int _sendRequest(String command, String arguments) {
+               if (fDebugSocket == null) {
+                       return 0;
+               }
+               
                XDebugCorePlugin.log(IStatus.INFO,command+" -i "+fTransactionID+" "+arguments);
                synchronized (fDebugSocket) {
                        try {