2 * Created on 23.11.2004
4 * TODO To change the template for this generated file go to
5 * Window - Preferences - Java - Code Style - Code Templates
7 package net.sourceforge.phpeclipse.xdebug.php.model;
10 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
12 import org.eclipse.debug.core.DebugEvent;
13 import org.eclipse.debug.core.DebugException;
14 import org.eclipse.debug.core.model.IValue;
15 import org.eclipse.debug.core.model.IVariable;
16 import org.w3c.dom.Node;
21 * TODO To change the template for this generated type comment go to
22 * Window - Preferences - Java - Code Style - Code Templates
24 public class XDebugVariable extends XDebugElement implements IVariable {
26 public static final int VARTYPE_UNKNOWN = -1;
27 public static final int VARTYPE_UNINITIALIZED = 0;
28 public static final int VARTYPE_STRING = 1;
29 public static final int VARTYPE_INT = 2;
30 public static final int VARTYPE_FLOAT = 3;
31 public static final int VARTYPE_ARRAY = 8;
32 public static final int VARTYPE_HASH = 9;
33 public static final int VARTYPE_OBJECT = 10;
38 private XDebugStackFrame fFrame;
39 private String fFullName;
40 // private String fTypeName;
42 private XDebugAbstractValue fValue;
43 private String fEncoding;
44 private int fNumChildren;
45 // private Node fVariableNode;
48 * Constructs a variable contained in the given stack frame
49 * with the given name.
51 * @param frame owning stack frame
52 * @param name variable name
54 public XDebugVariable(XDebugStackFrame frame, Node property) {
55 super((XDebugTarget) frame.getDebugTarget());
61 private void init(Node property) {
62 fFullName=PHPDebugUtils.getAttributeValue(property,"fullname");
63 fName=PHPDebugUtils.getAttributeValue(property,"name");
64 fEncoding=PHPDebugUtils.getAttributeValue(property,"encoding");
65 if (PHPDebugUtils.getAttributeValue(property,"numchildren").equals(""))
68 fNumChildren=Integer.parseInt(PHPDebugUtils.getAttributeValue(property,"numchildren"));
70 String typeName=PHPDebugUtils.getAttributeValue(property,"type");
72 // if (typeName.equals("uninitialized") )
73 // fValue= new XDebugValue(this,property,typeName);
74 if (typeName.equals("int") )
75 fValue= new XDebugIntValue(this,property,typeName);
76 else if (typeName.equals("float") )
77 fValue= new XDebugFloatValue(this,property,typeName);
78 else if (typeName.equals("bool") )
79 fValue= new XDebugBooleanValue(this,property,typeName);
80 else if (typeName.equals("string") )
81 fValue= new XDebugStringValue(this,property,typeName);
82 else if (typeName.equals("array") )
83 fValue= new XDebugArrayValue(this,property,typeName);
84 else if (typeName.equals("hash") )
85 fValue= new XDebugArrayValue(this,property,typeName);
86 else if (typeName.equals("object") )
87 fValue= new XDebugArrayValue(this,property,typeName);
89 fValue= new XDebugValue(this,property,typeName);
91 // else if (typeName.equals("float") )
92 // fTypeName= VARTYPE_FLOAT;
93 // else if (typeName.equals("string") )
94 // fTypeName= VARTYPE_STRING;
95 // else if (typeName.equals("hash") )
96 // fTypeName= VARTYPE_HASH;
97 // else if (typeName.equals("array") )
98 // fTypeName= VARTYPE_ARRAY;
99 // else if (typeName.equals("object") )
100 // fTypeName= VARTYPE_OBJECT;
106 // fValue= new XDebugValue(this,property);
109 * @see org.eclipse.debug.core.model.IVariable#getValue()
111 public IValue getValue() throws DebugException {
113 // return ((XDebugTarget)getDebugTarget()).getVariableValue(this);
116 * @see org.eclipse.debug.core.model.IVariable#getName()
118 public String getName() throws DebugException {
119 if (fFullName.endsWith("]"))
120 return fFullName.substring(fFullName.lastIndexOf('['));
125 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
127 public String getReferenceTypeName() throws DebugException {
128 return fValue.getReferenceTypeName();
131 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
133 public boolean hasValueChanged() throws DebugException {
134 // TODO Auto-generated method stub
138 * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
140 public void setValue(String expression) throws DebugException {
141 if(fValue.setValue(expression))
142 fireEvent(new DebugEvent(this, DebugEvent.CHANGE, DebugEvent.CONTENT));
145 * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
147 public void setValue(IValue value) throws DebugException {
150 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
152 public boolean supportsValueModification() {
153 return fValue.supportsValueModification();
156 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
158 public boolean verifyValue(String expression) throws DebugException {
159 return fValue.verifyValue(expression);
162 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
164 public boolean verifyValue(IValue value) throws DebugException {
169 * Returns the stack frame owning this variable.
171 * @return the stack frame owning this variable
173 protected XDebugStackFrame getStackFrame() {
177 // public int getType() {
181 public String getValueString() throws DebugException {
182 return fValue.getValueString();
185 public boolean hasChildren() {
186 return (fNumChildren>0);
189 public boolean isArray() {
190 return (fValue.isArray());
193 public String getEncoding() {
197 public void setEncoding(String encoding) {
198 fEncoding = encoding;
201 public String toString() {
202 return fValue.toString();
205 public String getFullName() {