1 package net.sourceforge.phpeclipse.xdebug.php.model;
4 import net.sourceforge.phpeclipse.xdebug.core.Base64;
5 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
6 import net.sourceforge.phpeclipse.xdebug.core.xdebug.XDebugConnection;
7 import net.sourceforge.phpeclipse.xdebug.core.xdebug.ResponseListener.DebugResponse;
8 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugVariable;
9 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget;
11 import org.eclipse.debug.core.DebugException;
12 import org.eclipse.debug.core.model.IDebugElement;
13 import org.eclipse.debug.core.model.IVariable;
14 import org.eclipse.debug.core.model.IWatchExpressionDelegate;
15 import org.eclipse.debug.core.model.IWatchExpressionListener;
16 import org.eclipse.debug.core.model.IWatchExpressionResult;
17 import org.w3c.dom.Node;
18 import org.w3c.dom.NodeList;
20 public class XDebugWatchExpressionDelegate implements IWatchExpressionDelegate {
21 public void evaluateExpression(String expression, IDebugElement context, IWatchExpressionListener listener) {
22 IWatchExpressionResult x;
23 XDebugConnection connection;
26 x = new XDebugWatchExpressionResult(expression, null, null);
28 s = (XDebugTarget) context.getDebugTarget();
29 connection = (XDebugConnection) s.getDebugConnection();
31 if( connection != null ) {
33 if( ! connection.isClosed() ) {
34 DebugResponse evalCommand = connection.eval(expression);
36 Node evalNode = evalCommand.getParentNode();
37 XDebugVariable var= /*connection.*/getVariableFromNodeA( null, evalNode.getFirstChild());
38 XDebugVariable result[] = {var};
40 if (result.length == 0) {
41 x = new XDebugWatchExpressionResult(expression, null, null);
43 x = new XDebugWatchExpressionResult(expression, result[0].getValue(), null);
46 } catch (Exception e) {
51 x = new XDebugWatchExpressionResult(expression, null, s1);
55 listener.watchEvaluationFinished(x);
58 private XDebugVariable getVariableFromNodeA(XDebugStackFrame frame, Node property) {
59 String address = PHPDebugUtils.getAttributeValue(property, "address");
61 String Name = PHPDebugUtils.getAttributeValue(property,"name");
62 if ("".equals(Name)) {
68 String varEncoding=PHPDebugUtils.getAttributeValue(property,"encoding");
69 int varNumChildren = 0;
70 if (PHPDebugUtils.getAttributeValue(property,"numchildren").equals(""))
73 varNumChildren=Integer.parseInt(PHPDebugUtils.getAttributeValue(property,"numchildren"));
75 String typeName=PHPDebugUtils.getAttributeValue(property,"type");
77 XDebugVariable variable = new XDebugVariable(typeName, varName);
78 variable.setEncoding(varEncoding);
79 variable.setNumChildren(varNumChildren);
80 XDebugAbstractValue val=null;
82 val = (XDebugAbstractValue) variable.getValue();
83 } catch (DebugException e1) {
86 if (val.getType()!= XDebugAbstractValue.VALUETYPE_UNINITIALIZED) {
87 if (variable.hasChildren()) {
88 NodeList varNodes = property.getChildNodes();
89 val.renderValueString(""+varNodes.getLength());
90 IVariable[] variables = new IVariable[varNodes.getLength()];
91 for (int i = 0; i<varNodes.getLength(); i++) {
92 Node propertyNode = varNodes.item(i);
93 variables[i] = getVariableFromNodeA(frame, propertyNode);
95 val.setChildVariables(variables);
99 str=property.getFirstChild().getNodeValue();
100 } catch (NullPointerException e) {
103 if (variable.getEncoding().equals("base64")) {
105 str=new String(Base64.decode(str));
109 val.renderValueString(str);
112 String className=PHPDebugUtils.getAttributeValue(property,"classname");
113 if(!"".equals(className))
114 val.renderValueString(className);