Initial implementation of the new Debug Plugin
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugAbstractValue.java
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.Base64;
10 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
11
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;
17
18 /**
19  * @author Axel
20  *
21  * TODO To change the template for this generated type comment go to
22  * Window - Preferences - Java - Code Style - Code Templates
23  */
24 public abstract class XDebugAbstractValue  extends XDebugElement implements IValue {
25         
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
36         
37         protected XDebugVariable fVariable;
38         private IVariable[] fVariables;
39         protected String fValueString;
40         protected int fType;
41         protected String fTypeName;
42         
43         public XDebugAbstractValue(XDebugVariable  variable,Node varNode,String typeName) {
44                 super((XDebugTarget) variable.getDebugTarget());
45                 fVariable = variable;
46                 if (varNode==null){
47                         try {
48                                 System.out.println(variable.getName()+"=null");
49                         } catch (DebugException e) {
50                                 // TODO Auto-generated catch block
51                                 e.printStackTrace();
52                         }
53                         return; 
54                 }
55                 setType(typeName);
56                 NodeList property = varNode.getChildNodes();
57                 if (variable.hasChildren()) {
58                         renderValueString(""+property.getLength());
59                         fVariables = new IVariable[property.getLength()];
60                         for (int i = 0; i<property.getLength(); i++) {
61                                 Node propertyNode = property.item(i);
62                                 fVariables[i] = new XDebugVariable(variable.getStackFrame(), propertyNode);
63                         }
64                 }else {
65 //                      fDataString="";
66                         fVariables = new IVariable[0];
67 //                      if (variable.getType()== XDebugVariable.VARTYPE_UNINITIALIZED)
68 //                              fValueString="uninitialized";
69 //                      else {
70                         String str="";
71                         try {
72                                 str=varNode.getFirstChild().getNodeValue();
73                         } catch (NullPointerException e) {
74                                 str="";
75                         }
76                         if (variable.getEncoding().equals("base64")) {
77                                 if (str.length()!=0)
78                                         str=new String(Base64.decode(str));
79                                 else
80                                         str="";
81                         }
82                         renderValueString(str);
83 //                      }
84                 }
85                 String className=PHPDebugUtils.getAttributeValue(varNode,"classname");
86                 if(className!="")
87                         renderValueString(className);
88
89         }
90         
91         /* (non-Javadoc)
92          * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
93          */
94         public String getReferenceTypeName() throws DebugException {
95                 return fTypeName;
96         }
97         /* (non-Javadoc)
98          * @see org.eclipse.debug.core.model.IValue#getValueString()
99          */
100         public String getValueString() throws DebugException {
101                 return fValueString;
102         }
103         /* (non-Javadoc)
104          * @see org.eclipse.debug.core.model.IValue#isAllocated()
105          */
106         public boolean isAllocated() throws DebugException {
107                 return true;
108         }
109         /* (non-Javadoc)
110          * @see org.eclipse.debug.core.model.IValue#getVariables()
111          */
112         public IVariable[] getVariables() throws DebugException {
113                 return fVariables;
114         }
115         /* (non-Javadoc)
116          * @see org.eclipse.debug.core.model.IValue#hasVariables()
117          */
118         public boolean hasVariables() throws DebugException {
119                 return (fVariables.length>0);
120         }
121         
122         public boolean isArray() {
123                 return ((fType & VALUETYPE_ARRAY) > 0);
124         }
125         
126         public abstract void setType(String typeName);
127         public abstract void renderValueString(String data);
128
129         public abstract boolean verifyValue(String expression);
130         
131         public boolean setValue(String expression) {
132                 if (!verifyValue(expression))
133                         return false;
134                 if(fTarget.setVarValue(fVariable.getFullName(),expression)) {
135                         renderValueString(expression);
136                         return true;
137                 }
138                 return false;
139         }
140
141         public boolean supportsValueModification() {
142                 return false;
143         }
144 }