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;
9 import net.sourceforge.phpeclipse.xdebug.core.Base64;
10 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
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;
21 * TODO To change the template for this generated type comment go to
22 * Window - Preferences - Java - Code Style - Code Templates
24 public abstract class XDebugAbstractValue extends XDebugElement implements IValue {
26 public static final int VALUETYPE_UNKNOWN = -1;
27 public static final int VALUETYPE_UNINITIALIZED = 0;
28 public static final int VALUETYPE_STRING = 1;
29 public static final int VALUETYPE_INT = 4;
30 public static final int VALUETYPE_FLOAT = 5;
31 public static final int VALUETYPE_BOOLEAN = 6;
32 public static final int VALUETYPE_ARRAY = 8;
33 public static final int VALUETYPE_HASH = 9;
34 public static final int VALUETYPE_OBJECT = 10;
35 public static final int VALUETYPE_RESOURCE = 11;
38 protected XDebugVariable fVariable;
39 private IVariable[] fVariables;
40 protected String fValueString;
42 protected String fTypeName;
44 private boolean fhasChanged;
46 public XDebugAbstractValue(XDebugVariable variable, Node varNode, String typeName) {
47 super((XDebugTarget) variable.getDebugTarget());
51 System.out.println(variable.getName()+"=null");
52 } catch (DebugException e) {
53 // TODO Auto-generated catch block
59 NodeList property = varNode.getChildNodes();
60 if (variable.hasChildren()) {
61 renderValueString(""+property.getLength());
62 fVariables = new IVariable[property.getLength()];
63 for (int i = 0; i<property.getLength(); i++) {
64 Node propertyNode = property.item(i);
65 fVariables[i] = new XDebugVariable(variable.getStackFrame(), propertyNode);
69 fVariables = new IVariable[0];
70 // if (variable.getType()== XDebugVariable.VARTYPE_UNINITIALIZED)
71 // fValueString="uninitialized";
75 str=varNode.getFirstChild().getNodeValue();
76 } catch (NullPointerException e) {
79 if (variable.getEncoding().equals("base64")) {
81 str=new String(Base64.decode(str));
85 renderValueString(str);
88 String className=PHPDebugUtils.getAttributeValue(varNode,"classname");
89 if(!"".equals(className))
90 renderValueString(className);
94 public boolean hasChanged() {
98 public void sethasChanged(boolean hasChanged) {
99 fhasChanged = hasChanged;
102 public void setChildVariables(IVariable[] newChildVariables) {
103 fVariables = newChildVariables;
107 * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
109 public String getReferenceTypeName() throws DebugException {
114 * @see org.eclipse.debug.core.model.IValue#getValueString()
116 public String getValueString() throws DebugException {
121 * @see org.eclipse.debug.core.model.IValue#isAllocated()
123 public boolean isAllocated() throws DebugException {
128 * @see org.eclipse.debug.core.model.IValue#getVariables()
130 public IVariable[] getVariables() throws DebugException {
135 * @see org.eclipse.debug.core.model.IValue#hasVariables()
137 public boolean hasVariables() throws DebugException {
138 return (fVariables.length > 0);
141 public abstract void setType(String typeName);
142 public abstract void renderValueString(String data);
144 public abstract boolean verifyValue(String expression);
146 public boolean setValue(String expression) {
147 if (!verifyValue(expression))
149 if( getDebugTarget() == null ) {
150 renderValueString(expression);
152 if(((XDebugTarget) getDebugTarget()).setVarValue(fVariable.getFullName(),expression)) {
153 renderValueString(expression);
160 public boolean setValueA(String expression) {
161 if(! fValueString.toString().equals(expression)) {
162 fVariables= new IVariable[0];
163 fValueString = expression;
172 public boolean setValueB(IValue value) {
174 fTypeName = value.getReferenceTypeName();
175 } catch (DebugException e) {
180 switch (((XDebugAbstractValue) value). getType()) {
181 case VALUETYPE_UNINITIALIZED:
182 case VALUETYPE_STRING:
184 case VALUETYPE_FLOAT:
185 case VALUETYPE_BOOLEAN:
187 if (! fValueString.equals(value.getValueString())) {
188 fValueString = value.getValueString();
191 } catch (DebugException e) {
197 case VALUETYPE_RESOURCE:
199 if (! fValueString.equals(value.getValueString())) {
200 fValueString = value.getValueString();
203 } catch (DebugException e) {
214 case VALUETYPE_OBJECT:
215 case VALUETYPE_ARRAY:
217 IVariable[] newVariable = value.getVariables();
219 if (fVariables.length == 0) {
220 if (newVariable.length > 0) {
221 fValueString = value.getValueString();
222 fVariables = newVariable;
226 for(int i = 0; i < fVariables.length; i++) {
227 // da capire quando e perche'
229 if (! ((XDebugVariable)fVariables[i]).equals(((XDebugVariable)newVariable[i]))) {
230 //fVariables[i].setValue(newVariable[i].getValue());
233 } catch (Exception e) {
238 fValueString = value.getValueString();
239 for(int i = 0; i < fVariables.length; i++) {
241 fVariables[i].setValue(newVariable[i].getValue());
242 } catch (Exception e) {
248 } catch (DebugException e) {
259 public boolean setValueBOld(IValue value) {
262 switch (((XDebugAbstractValue) value). getType()) {
263 case VALUETYPE_UNINITIALIZED:
264 case VALUETYPE_STRING:
266 case VALUETYPE_FLOAT:
267 case VALUETYPE_BOOLEAN:
269 if (! fValueString.equals(value.getValueString())) {
270 fValueString = value.getValueString();
273 } catch (DebugException e) {
282 case VALUETYPE_OBJECT:
283 case VALUETYPE_ARRAY:
285 IVariable[] newVariable = value.getVariables();
287 if (fVariables.length == 0) {
288 if (newVariable.length > 0) {
289 fValueString = value.getValueString();
290 fVariables = newVariable;
294 for(int i = 0; i < fVariables.length; i++) {
295 if (! ((XDebugVariable)fVariables[i]).equals(((XDebugVariable)newVariable[i]))) {
296 //fVariables[i].setValue(newVariable[i].getValue());
301 fValueString = value.getValueString();
302 for(int i = 0; i < fVariables.length; i++) {
303 fVariables[i].setValue(newVariable[i].getValue());
307 } catch (DebugException e) {
316 public int getType() {
320 public boolean supportsValueModification() {