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 abstract void setType(String typeName);
150 public abstract void renderValueString(String data);
152 public abstract boolean verifyValue(String expression);
154 public boolean setValue(String expression) {
155 if (!verifyValue(expression))
157 if( fTarget == null ) {
158 renderValueString(expression);
160 if(fTarget.setVarValue(fVariable.getFullName(),expression)) {
161 renderValueString(expression);
168 public boolean setValueA(String expression) {
169 if(! fValueString.toString().equals(expression)) {
170 fVariables= new IVariable[0];
171 fValueString = expression;
180 public boolean setValueB(IValue value) {
182 fTypeName = value.getReferenceTypeName();
183 } catch (DebugException e) {
188 switch (((XDebugAbstractValue) value). getType()) {
189 case VALUETYPE_UNINITIALIZED:
190 case VALUETYPE_STRING:
192 case VALUETYPE_FLOAT:
193 case VALUETYPE_BOOLEAN:
195 if (! fValueString.equals(value.getValueString())) {
196 fValueString = value.getValueString();
199 } catch (DebugException e) {
205 case VALUETYPE_RESOURCE:
207 if (! fValueString.equals(value.getValueString())) {
208 fValueString = value.getValueString();
211 } catch (DebugException e) {
222 case VALUETYPE_OBJECT:
223 case VALUETYPE_ARRAY:
225 IVariable[] newVariable = value.getVariables();
227 if (fVariables.length == 0) {
228 if (newVariable.length > 0) {
229 fValueString = value.getValueString();
230 fVariables = newVariable;
234 for(int i = 0; i < fVariables.length; i++) {
235 // da capire quando e perche'
237 if (! ((XDebugVariable)fVariables[i]).equals(((XDebugVariable)newVariable[i]))) {
238 //fVariables[i].setValue(newVariable[i].getValue());
241 } catch (Exception e) {
246 fValueString = value.getValueString();
247 for(int i = 0; i < fVariables.length; i++) {
249 fVariables[i].setValue(newVariable[i].getValue());
250 } catch (Exception e) {
256 } catch (DebugException e) {
267 public boolean setValueBOld(IValue value) {
270 switch (((XDebugAbstractValue) value). getType()) {
271 case VALUETYPE_UNINITIALIZED:
272 case VALUETYPE_STRING:
274 case VALUETYPE_FLOAT:
275 case VALUETYPE_BOOLEAN:
277 if (! fValueString.equals(value.getValueString())) {
278 fValueString = value.getValueString();
281 } catch (DebugException e) {
290 case VALUETYPE_OBJECT:
291 case VALUETYPE_ARRAY:
293 IVariable[] newVariable = value.getVariables();
295 if (fVariables.length == 0) {
296 if (newVariable.length > 0) {
297 fValueString = value.getValueString();
298 fVariables = newVariable;
302 for(int i = 0; i < fVariables.length; i++) {
303 if (! ((XDebugVariable)fVariables[i]).equals(((XDebugVariable)newVariable[i]))) {
304 //fVariables[i].setValue(newVariable[i].getValue());
309 fValueString = value.getValueString();
310 for(int i = 0; i < fVariables.length; i++) {
311 fVariables[i].setValue(newVariable[i].getValue());
315 } catch (DebugException e) {
324 public int getType() {
328 public boolean supportsValueModification() {