9b0a57ecfdcf660bd8ff647b50284c2fa5086a82
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugAbstractValue.java
1 /*
2  * Created on 23.11.2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */
7 package net.sourceforge.phpeclipse.xdebug.php.model;
8
9 import net.sourceforge.phpeclipse.xdebug.core.Base64;
10 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
11
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                 NodeList property = varNode.getChildNodes();
41                 if (NumChildren > 0) {
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                         
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);
113
114         public abstract boolean verifyValue(String expression);
115         
116         public boolean setValue(String expression) {
117                 if (!verifyValue(expression))
118                         return false;
119         if( getDebugTarget() == null ) {
120             renderValueString(expression);
121             } else {
122                    /* if(((XDebugTarget) getDebugTarget()).setVarValue(fVariable.getFullName(),expression)) {
123                             renderValueString(expression);
124                             return true;
125                     }*/
126             }
127                 return false;
128         }
129         
130         public boolean supportsValueModification() {
131                 return false;
132         }
133 }