Enable first implementation of value change in varialbles view.
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugAbstractValue.java
1  /* Created on 23.11.2004
2  *
3  * TODO To change the template for this generated file go to
4  * Window - Preferences - Java - Code Style - Code Templates
5  */
6 package net.sourceforge.phpeclipse.xdebug.php.model;
7
8 import net.sourceforge.phpeclipse.xdebug.core.Base64;
9 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
10
11 import org.eclipse.debug.core.DebugEvent;
12 import org.eclipse.debug.core.DebugException;
13 import org.eclipse.debug.core.model.IValue;
14 import org.eclipse.debug.core.model.IVariable;
15 import org.w3c.dom.Node;
16 import org.w3c.dom.NodeList;
17
18 /**
19  * @author Axel
20  *
21  * TODO To change the template for this generated type comment go to
22  * Window - Preferences - Java - Code Style - Code Templates
23  */
24 public abstract class XDebugAbstractValue  extends XDebugElement implements IValue {
25         private IVariable[] fVariables;
26         protected String fValueString;
27         protected String fTypeName;
28         private boolean fhasChanged;
29
30         public XDebugAbstractValue(XDebugStackFrame frame, Node varNode)  {
31                 super((XDebugTarget) frame.getDebugTarget());
32
33                 fTypeName = PHPDebugUtils.getAttributeValue(varNode,"type");
34
35                 int NumChildren = 0;
36                 if (!PHPDebugUtils.getAttributeValue(varNode,"numchildren").equals("")) {
37                         NumChildren = Integer.parseInt(PHPDebugUtils.getAttributeValue(varNode, "numchildren"));
38                 }               
39
40                 if (NumChildren > 0) {
41                         NodeList property = varNode.getChildNodes();
42                         renderValueString(""+property.getLength());
43                         fVariables = new IVariable[property.getLength()];
44                         for (int i = 0; i<property.getLength(); i++) {
45                                 Node propertyNode = property.item(i);
46                                 fVariables[i] = new XDebugVariable(frame, propertyNode);
47                         }
48                 }else {
49                         fVariables = new IVariable[0];
50                         String str="";
51                         try {
52                                 str=varNode.getFirstChild().getNodeValue();
53                         } catch (NullPointerException e) {
54                                 str="";
55                         }
56
57                         String Encoding = PHPDebugUtils.getAttributeValue(varNode,"encoding");
58                         
59                         if (Encoding.equals("base64")) {
60                                 if (str.length()!=0)
61                                         str=new String(Base64.decode(str));
62                                 else
63                                         str="";
64                         }
65                         renderValueString(str);
66                 }
67                 String className=PHPDebugUtils.getAttributeValue(varNode,"classname");
68                 if(!"".equals(className))
69                         renderValueString(className);
70         }
71         
72         public boolean hasChanged() {
73                 return fhasChanged;
74         }
75         
76         /* (non-Javadoc)
77          * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
78          */
79         public String getReferenceTypeName() throws DebugException {
80                 return fTypeName;
81         }
82         
83         /* (non-Javadoc)
84          * @see org.eclipse.debug.core.model.IValue#getValueString()
85          */
86         public String getValueString() throws DebugException {
87                 return fValueString;
88         }
89         
90         /* (non-Javadoc)
91          * @see org.eclipse.debug.core.model.IValue#isAllocated()
92          */
93         public boolean isAllocated() throws DebugException {
94                 return true;
95         }
96         
97         /* (non-Javadoc)
98          * @see org.eclipse.debug.core.model.IValue#getVariables()
99          */
100         public IVariable[] getVariables() throws DebugException {
101                 return fVariables;
102         }
103         
104         /* (non-Javadoc)
105          * @see org.eclipse.debug.core.model.IValue#hasVariables()
106          */
107         public boolean hasVariables() throws DebugException {
108                 return (fVariables.length > 0);
109         }
110         
111         public abstract void renderValueString(String data);
112
113         public abstract boolean verifyValue(String expression);
114         
115         public boolean setValue(String expression) {
116                 if (!verifyValue(expression)) {
117                         return false;
118                 }
119                 
120                 renderValueString(expression);
121                 fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
122         
123                 return true;
124         }
125         
126         public boolean supportsValueModification() {
127                 return false;
128         }
129 }