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, String typeName) {
47 super((XDebugTarget) variable.getDebugTarget());
50 fVariables= new IVariable[0];
54 public XDebugAbstractValue(XDebugVariable variable,Node varNode,String typeName) {
55 super((XDebugTarget) variable.getDebugTarget());
59 System.out.println(variable.getName()+"=null");
60 } catch (DebugException e) {
61 // TODO Auto-generated catch block
67 NodeList property = varNode.getChildNodes();
68 if (variable.hasChildren()) {
69 renderValueString(""+property.getLength());
70 fVariables = new IVariable[property.getLength()];
71 for (int i = 0; i<property.getLength(); i++) {
72 Node propertyNode = property.item(i);
73 fVariables[i] = new XDebugVariable(variable.getStackFrame(), propertyNode);
77 fVariables = new IVariable[0];
78 // if (variable.getType()== XDebugVariable.VARTYPE_UNINITIALIZED)
79 // fValueString="uninitialized";
83 str=varNode.getFirstChild().getNodeValue();
84 } catch (NullPointerException e) {
87 if (variable.getEncoding().equals("base64")) {
89 str=new String(Base64.decode(str));
93 renderValueString(str);
96 String className=PHPDebugUtils.getAttributeValue(varNode,"classname");
97 if(!"".equals(className))
98 renderValueString(className);
102 public boolean hasChanged() {
106 public void sethasChanged(boolean hasChanged) {
107 fhasChanged = hasChanged;
110 public void setChildVariables(IVariable[] newChildVariables) {
111 fVariables = newChildVariables;
115 * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
117 public String getReferenceTypeName() throws DebugException {
122 * @see org.eclipse.debug.core.model.IValue#getValueString()
124 public String getValueString() throws DebugException {
129 * @see org.eclipse.debug.core.model.IValue#isAllocated()
131 public boolean isAllocated() throws DebugException {
136 * @see org.eclipse.debug.core.model.IValue#getVariables()
138 public IVariable[] getVariables() throws DebugException {
143 * @see org.eclipse.debug.core.model.IValue#hasVariables()
145 public boolean hasVariables() throws DebugException {
146 return (fVariables.length > 0);
149 public boolean isArray() {
150 return ((fType & VALUETYPE_ARRAY) > 0);
153 public abstract void setType(String typeName);
154 public abstract void renderValueString(String data);
156 public abstract boolean verifyValue(String expression);
158 public boolean setValue(String expression) {
159 if (!verifyValue(expression))
161 if( fTarget == null ) {
162 renderValueString(expression);
164 if(fTarget.setVarValue(fVariable.getFullName(),expression)) {
165 renderValueString(expression);
172 public boolean setValueA(String expression) {
173 if(! fValueString.toString().equals(expression)) {
174 fVariables= new IVariable[0];
175 fValueString = expression;
184 public boolean setValueB(IValue value) {
186 fTypeName = value.getReferenceTypeName();
187 } catch (DebugException e) {
192 switch (((XDebugAbstractValue) value). getType()) {
193 case VALUETYPE_UNINITIALIZED:
194 case VALUETYPE_STRING:
196 case VALUETYPE_FLOAT:
197 case VALUETYPE_BOOLEAN:
199 if (! fValueString.equals(value.getValueString())) {
200 fValueString = value.getValueString();
203 } catch (DebugException e) {
209 case VALUETYPE_RESOURCE:
211 if (! fValueString.equals(value.getValueString())) {
212 fValueString = value.getValueString();
215 } catch (DebugException e) {
226 case VALUETYPE_OBJECT:
227 case VALUETYPE_ARRAY:
229 IVariable[] newVariable = value.getVariables();
231 if (fVariables.length == 0) {
232 if (newVariable.length > 0) {
233 fValueString = value.getValueString();
234 fVariables = newVariable;
238 for(int i = 0; i < fVariables.length; i++) {
239 // da capire quando e perche'
241 if (! ((XDebugVariable)fVariables[i]).equals(((XDebugVariable)newVariable[i]))) {
242 //fVariables[i].setValue(newVariable[i].getValue());
245 } catch (Exception e) {
250 fValueString = value.getValueString();
251 for(int i = 0; i < fVariables.length; i++) {
253 fVariables[i].setValue(newVariable[i].getValue());
254 } catch (Exception e) {
260 } catch (DebugException e) {
271 public boolean setValueBOld(IValue value) {
274 switch (((XDebugAbstractValue) value). getType()) {
275 case VALUETYPE_UNINITIALIZED:
276 case VALUETYPE_STRING:
278 case VALUETYPE_FLOAT:
279 case VALUETYPE_BOOLEAN:
281 if (! fValueString.equals(value.getValueString())) {
282 fValueString = value.getValueString();
285 } catch (DebugException e) {
294 case VALUETYPE_OBJECT:
295 case VALUETYPE_ARRAY:
297 IVariable[] newVariable = value.getVariables();
299 if (fVariables.length == 0) {
300 if (newVariable.length > 0) {
301 fValueString = value.getValueString();
302 fVariables = newVariable;
306 for(int i = 0; i < fVariables.length; i++) {
307 if (! ((XDebugVariable)fVariables[i]).equals(((XDebugVariable)newVariable[i]))) {
308 //fVariables[i].setValue(newVariable[i].getValue());
313 fValueString = value.getValueString();
314 for(int i = 0; i < fVariables.length; i++) {
315 fVariables[i].setValue(newVariable[i].getValue());
319 } catch (DebugException e) {
328 public int getType() {
332 public boolean supportsValueModification() {