a3c7cddc6de49b51e31c7e440ba2af28dd798dfb
[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 Window -
22  * Preferences - Java - Code Style - Code Templates
23  */
24 public abstract class XDebugAbstractValue extends XDebugElement implements
25                 IValue {
26
27         public static final int VALUETYPE_UNKNOWN = -1;
28
29         public static final int VALUETYPE_UNINITIALIZED = 0;
30
31         public static final int VALUETYPE_STRING = 1;
32
33         public static final int VALUETYPE_INT = 4;
34
35         public static final int VALUETYPE_FLOAT = 5;
36
37         public static final int VALUETYPE_BOOLEAN = 6;
38
39         public static final int VALUETYPE_ARRAY = 8;
40
41         public static final int VALUETYPE_HASH = 9;
42
43         public static final int VALUETYPE_OBJECT = 10;
44
45         protected XDebugVariable fVariable;
46
47         private IVariable[] fVariables;
48
49         protected String fValueString;
50
51         protected int fType;
52
53         protected String fTypeName;
54
55         public XDebugAbstractValue(XDebugVariable variable, Node varNode,
56                         String typeName) {
57                 super((XDebugTarget) variable.getDebugTarget());
58                 fVariable = variable;
59                 if (varNode == null) {
60                         try {
61                                 System.out.println(variable.getName() + "=null");
62                         } catch (DebugException e) {
63                                 // TODO Auto-generated catch block
64                                 e.printStackTrace();
65                         }
66                         return;
67                 }
68                 setType(typeName);
69                 NodeList property = varNode.getChildNodes();
70                 if (variable.hasChildren()) {
71                         renderValueString("" + property.getLength());
72                         fVariables = new IVariable[property.getLength()];
73                         for (int i = 0; i < property.getLength(); i++) {
74                                 Node propertyNode = property.item(i);
75                                 fVariables[i] = new XDebugVariable(variable.getStackFrame(),
76                                                 propertyNode);
77                         }
78                 } else {
79                         // fDataString="";
80                         fVariables = new IVariable[0];
81                         // if (variable.getType()== XDebugVariable.VARTYPE_UNINITIALIZED)
82                         // fValueString="uninitialized";
83                         // else {
84                         String str = "";
85                         try {
86                                 str = varNode.getFirstChild().getNodeValue();
87                         } catch (NullPointerException e) {
88                                 str = "";
89                         }
90                         if (variable.getEncoding().equals("base64")) {
91                                 if (str.length() != 0)
92                                         str = new String(Base64.decode(str));
93                                 else
94                                         str = "";
95                         }
96                         renderValueString(str);
97                         // }
98                 }
99                 String className = PHPDebugUtils
100                                 .getAttributeValue(varNode, "classname");
101                 if (className != "")
102                         renderValueString(className);
103
104         }
105
106         /*
107          * (non-Javadoc)
108          * 
109          * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
110          */
111         public String getReferenceTypeName() throws DebugException {
112                 return fTypeName;
113         }
114
115         /*
116          * (non-Javadoc)
117          * 
118          * @see org.eclipse.debug.core.model.IValue#getValueString()
119          */
120         public String getValueString() throws DebugException {
121                 return fValueString;
122         }
123
124         /*
125          * (non-Javadoc)
126          * 
127          * @see org.eclipse.debug.core.model.IValue#isAllocated()
128          */
129         public boolean isAllocated() throws DebugException {
130                 return true;
131         }
132
133         /*
134          * (non-Javadoc)
135          * 
136          * @see org.eclipse.debug.core.model.IValue#getVariables()
137          */
138         public IVariable[] getVariables() throws DebugException {
139                 return fVariables;
140         }
141
142         /*
143          * (non-Javadoc)
144          * 
145          * @see org.eclipse.debug.core.model.IValue#hasVariables()
146          */
147         public boolean hasVariables() throws DebugException {
148                 return (fVariables.length > 0);
149         }
150
151         public boolean isArray() {
152                 return ((fType & VALUETYPE_ARRAY) > 0);
153         }
154
155         public abstract void setType(String typeName);
156
157         public abstract void renderValueString(String data);
158
159         public abstract boolean verifyValue(String expression);
160
161         public boolean setValue(String expression) {
162                 if (!verifyValue(expression))
163                         return false;
164                 if (fTarget.setVarValue(fVariable.getFullName(), expression)) {
165                         renderValueString(expression);
166                         return true;
167                 }
168                 return false;
169         }
170
171         public boolean supportsValueModification() {
172                 return false;
173         }
174 }