21663d3e8de0082880d3c0ef52e283b640d28be1
[phpeclipse.git] /
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.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
17 /**
18  * @author Axel
19  * 
20  * TODO To change the template for this generated type comment go to Window -
21  * Preferences - Java - Code Style - Code Templates
22  */
23 public class XDebugVariable extends XDebugElement implements IVariable {
24
25         public static final int VARTYPE_UNKNOWN = -1;
26
27         public static final int VARTYPE_UNINITIALIZED = 0;
28
29         public static final int VARTYPE_STRING = 1;
30
31         public static final int VARTYPE_INT = 2;
32
33         public static final int VARTYPE_FLOAT = 3;
34
35         public static final int VARTYPE_ARRAY = 8;
36
37         public static final int VARTYPE_HASH = 9;
38
39         public static final int VARTYPE_OBJECT = 10;
40
41         // name & stack frmae
42         private String fName;
43
44         private XDebugStackFrame fFrame;
45
46         private String fFullName;
47
48         // private String fTypeName;
49         // private int fType;
50         private XDebugAbstractValue fValue;
51
52         private String fEncoding;
53
54         private int fNumChildren;
55
56         // private Node fVariableNode;
57
58         /**
59          * Constructs a variable contained in the given stack frame with the given
60          * name.
61          * 
62          * @param frame
63          *            owning stack frame
64          * @param name
65          *            variable name
66          */
67         public XDebugVariable(XDebugStackFrame frame, Node property) {
68                 super((XDebugTarget) frame.getDebugTarget());
69                 fFrame = frame;
70                 init(property);
71
72         }
73
74         private void init(Node property) {
75                 fFullName = PHPDebugUtils.getAttributeValue(property, "fullname");
76                 fName = PHPDebugUtils.getAttributeValue(property, "name");
77                 fEncoding = PHPDebugUtils.getAttributeValue(property, "encoding");
78                 if (PHPDebugUtils.getAttributeValue(property, "numchildren").equals(""))
79                         fNumChildren = 0;
80                 else
81                         fNumChildren = Integer.parseInt(PHPDebugUtils.getAttributeValue(
82                                         property, "numchildren"));
83
84                 String typeName = PHPDebugUtils.getAttributeValue(property, "type");
85
86                 // if (typeName.equals("uninitialized") )
87                 // fValue= new XDebugValue(this,property,typeName);
88                 if (typeName.equals("int"))
89                         fValue = new XDebugIntValue(this, property, typeName);
90                 else if (typeName.equals("float"))
91                         fValue = new XDebugFloatValue(this, property, typeName);
92                 else if (typeName.equals("bool"))
93                         fValue = new XDebugBooleanValue(this, property, typeName);
94                 else if (typeName.equals("string"))
95                         fValue = new XDebugStringValue(this, property, typeName);
96                 else if (typeName.equals("array"))
97                         fValue = new XDebugArrayValue(this, property, typeName);
98                 else if (typeName.equals("hash"))
99                         fValue = new XDebugArrayValue(this, property, typeName);
100                 else if (typeName.equals("object"))
101                         fValue = new XDebugArrayValue(this, property, typeName);
102                 else
103                         fValue = new XDebugValue(this, property, typeName);
104
105                 // else if (typeName.equals("float") )
106                 // fTypeName= VARTYPE_FLOAT;
107                 // else if (typeName.equals("string") )
108                 // fTypeName= VARTYPE_STRING;
109                 // else if (typeName.equals("hash") )
110                 // fTypeName= VARTYPE_HASH;
111                 // else if (typeName.equals("array") )
112                 // fTypeName= VARTYPE_ARRAY;
113                 // else if (typeName.equals("object") )
114                 // fTypeName= VARTYPE_OBJECT;
115
116                 // fTypeName=type;
117                 //              
118                 // fValue= new XDebugValue(this,property);
119         }
120
121         /*
122          * (non-Javadoc)
123          * 
124          * @see org.eclipse.debug.core.model.IVariable#getValue()
125          */
126         public IValue getValue() throws DebugException {
127                 return fValue;
128                 // return ((XDebugTarget)getDebugTarget()).getVariableValue(this);
129         }
130
131         /*
132          * (non-Javadoc)
133          * 
134          * @see org.eclipse.debug.core.model.IVariable#getName()
135          */
136         public String getName() throws DebugException {
137                 if (fFullName.endsWith("]"))
138                         return fFullName.substring(fFullName.lastIndexOf('['));
139                 else
140                         return fName;
141         }
142
143         /*
144          * (non-Javadoc)
145          * 
146          * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
147          */
148         public String getReferenceTypeName() throws DebugException {
149                 return fValue.getReferenceTypeName();
150         }
151
152         /*
153          * (non-Javadoc)
154          * 
155          * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
156          */
157         public boolean hasValueChanged() throws DebugException {
158                 // TODO Auto-generated method stub
159                 return false;
160         }
161
162         /*
163          * (non-Javadoc)
164          * 
165          * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
166          */
167         public void setValue(String expression) throws DebugException {
168                 if (fValue.setValue(expression))
169                         fireEvent(new DebugEvent(this, DebugEvent.CHANGE,
170                                         DebugEvent.CONTENT));
171         }
172
173         /*
174          * (non-Javadoc)
175          * 
176          * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
177          */
178         public void setValue(IValue value) throws DebugException {
179         }
180
181         /*
182          * (non-Javadoc)
183          * 
184          * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
185          */
186         public boolean supportsValueModification() {
187                 return fValue.supportsValueModification();
188         }
189
190         /*
191          * (non-Javadoc)
192          * 
193          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
194          */
195         public boolean verifyValue(String expression) throws DebugException {
196                 return fValue.verifyValue(expression);
197         }
198
199         /*
200          * (non-Javadoc)
201          * 
202          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
203          */
204         public boolean verifyValue(IValue value) throws DebugException {
205                 return false;
206         }
207
208         /**
209          * Returns the stack frame owning this variable.
210          * 
211          * @return the stack frame owning this variable
212          */
213         protected XDebugStackFrame getStackFrame() {
214                 return fFrame;
215         }
216
217         // public int getType() {
218         // return fType;
219         // }
220
221         public String getValueString() throws DebugException {
222                 return fValue.getValueString();
223         }
224
225         public boolean hasChildren() {
226                 return (fNumChildren > 0);
227         }
228
229         public boolean isArray() {
230                 return (fValue.isArray());
231         }
232
233         public String getEncoding() {
234                 return fEncoding;
235         }
236
237         public void setEncoding(String encoding) {
238                 fEncoding = encoding;
239         }
240
241         public String toString() {
242                 return fValue.toString();
243         }
244
245         public String getFullName() {
246                 return fFullName;
247         }
248
249 }