Whole refactor.
[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         public void sethasChanged(boolean hasChanged) {
78                 fhasChanged = hasChanged;
79         }
80         
81         public void setChildVariables(IVariable[] newChildVariables) {
82                 fVariables = newChildVariables;
83         }
84         
85         /* (non-Javadoc)
86          * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
87          */
88         public String getReferenceTypeName() throws DebugException {
89                 return fTypeName;
90         }
91         
92         /* (non-Javadoc)
93          * @see org.eclipse.debug.core.model.IValue#getValueString()
94          */
95         public String getValueString() throws DebugException {
96                 return fValueString;
97         }
98         
99         /* (non-Javadoc)
100          * @see org.eclipse.debug.core.model.IValue#isAllocated()
101          */
102         public boolean isAllocated() throws DebugException {
103                 return true;
104         }
105         
106         /* (non-Javadoc)
107          * @see org.eclipse.debug.core.model.IValue#getVariables()
108          */
109         public IVariable[] getVariables() throws DebugException {
110                 return fVariables;
111         }
112         
113         /* (non-Javadoc)
114          * @see org.eclipse.debug.core.model.IValue#hasVariables()
115          */
116         public boolean hasVariables() throws DebugException {
117                 return (fVariables.length > 0);
118         }
119         
120         public abstract void renderValueString(String data);
121
122         public abstract boolean verifyValue(String expression);
123         
124         public boolean setValue(String expression) {
125                 if (!verifyValue(expression))
126                         return false;
127         if( getDebugTarget() == null ) {
128             renderValueString(expression);
129             } else {
130                    /* if(((XDebugTarget) getDebugTarget()).setVarValue(fVariable.getFullName(),expression)) {
131                             renderValueString(expression);
132                             return true;
133                     }*/
134             }
135                 return false;
136         }
137         
138         public boolean supportsValueModification() {
139                 return false;
140         }
141 }