Refactor and enabled value view in variable 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
25 public abstract class XDebugAbstractValue  extends XDebugElement implements IValue {
26         private IVariable[] fVariables;
27         protected String fValueString;
28         private String fTypeName;
29         private boolean fhasChanged;
30
31         public XDebugAbstractValue(XDebugStackFrame frame, Node varNode) throws DebugException  {
32                 super(frame == null ? null : (XDebugTarget) frame.getDebugTarget());
33
34                 fTypeName = PHPDebugUtils.getAttributeValue(varNode,"type");
35
36                 int NumChildren = 0;
37                 if (!PHPDebugUtils.getAttributeValue(varNode,"numchildren").equals("")) {
38                         NumChildren = Integer.parseInt(PHPDebugUtils.getAttributeValue(varNode, "numchildren"));
39                 }               
40
41                 if (NumChildren > 0) {
42                         NodeList property = varNode.getChildNodes();
43                         renderValueString(""+property.getLength());
44                         fVariables = new IVariable[property.getLength()];
45                         for (int i = 0; i<property.getLength(); i++) {
46                                 Node propertyNode = property.item(i);
47                                 fVariables[i] = new XDebugVariable(frame, propertyNode);
48                         }
49                 }else {
50                         fVariables = new IVariable[0];
51                         String str="";
52                         try {
53                                 str=varNode.getFirstChild().getNodeValue();
54                         } catch (NullPointerException e) {
55                                 str="";
56                         }
57
58                         String Encoding = PHPDebugUtils.getAttributeValue(varNode,"encoding");
59                         
60                         if (Encoding.equals("base64")) {
61                                 if (str.length()!=0)
62                                         str=new String(Base64.decode(str));
63                                 else
64                                         str="";
65                         }
66                         renderValueString(str);
67                 }
68                 String className=PHPDebugUtils.getAttributeValue(varNode,"classname");
69                 if(!"".equals(className))
70                         renderValueString(className);
71         }
72         
73         public boolean hasChanged() {
74                 return fhasChanged;
75         }
76         
77         /* (non-Javadoc)
78          * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
79          */
80         public String getReferenceTypeName() throws DebugException {
81                 return fTypeName;
82         }
83         
84         /* (non-Javadoc)
85          * @see org.eclipse.debug.core.model.IValue#getValueString()
86          */
87         public String getValueString() throws DebugException {
88                 return fValueString;
89         }
90         
91         /* (non-Javadoc)
92          * @see org.eclipse.debug.core.model.IValue#isAllocated()
93          */
94         public boolean isAllocated() throws DebugException {
95                 return true;
96         }
97         
98         /* (non-Javadoc)
99          * @see org.eclipse.debug.core.model.IValue#getVariables()
100          */
101         public IVariable[] getVariables() throws DebugException {
102                 return fVariables;
103         }
104         
105         /* (non-Javadoc)
106          * @see org.eclipse.debug.core.model.IValue#hasVariables()
107          */
108         public boolean hasVariables() throws DebugException {
109                 return (fVariables.length > 0);
110         }
111         
112         public abstract void renderValueString(String data) throws DebugException;
113
114         public abstract boolean verifyValue(String expression);
115         
116         public boolean setValue(String expression) throws DebugException {
117                 if (!verifyValue(expression)) {
118                         return false;
119                 }
120                 
121                 renderValueString(expression);
122                 fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
123         
124                 return true;
125         }
126         
127         public boolean supportsValueModification() {
128                 return false;
129         }
130 }