Remove unused constructor.
[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         public static final int VALUETYPE_RESOURCE = 11;
36
37         
38         protected XDebugVariable fVariable;
39         private IVariable[] fVariables;
40         protected String fValueString;
41         protected int fType;
42         protected String fTypeName;
43         
44         private boolean fhasChanged;
45
46         public XDebugAbstractValue(XDebugVariable variable, Node varNode, String typeName) {
47                 super((XDebugTarget) variable.getDebugTarget());
48                 fVariable = variable;
49                 if (varNode==null){
50                         try {
51                                 System.out.println(variable.getName()+"=null");
52                         } catch (DebugException e) {
53                                 // TODO Auto-generated catch block
54                                 e.printStackTrace();
55                         }
56                         return; 
57                 }
58                 setType(typeName);
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);
66                         }
67                 }else {
68 //                      fDataString="";
69                         fVariables = new IVariable[0];
70 //                      if (variable.getType()== XDebugVariable.VARTYPE_UNINITIALIZED)
71 //                              fValueString="uninitialized";
72 //                      else {
73                         String str="";
74                         try {
75                                 str=varNode.getFirstChild().getNodeValue();
76                         } catch (NullPointerException e) {
77                                 str="";
78                         }
79                         if (variable.getEncoding().equals("base64")) {
80                                 if (str.length()!=0)
81                                         str=new String(Base64.decode(str));
82                                 else
83                                         str="";
84                         }
85                         renderValueString(str);
86 //                      }
87                 }
88                 String className=PHPDebugUtils.getAttributeValue(varNode,"classname");
89                 if(!"".equals(className))
90                         renderValueString(className);
91
92         }
93         
94         public boolean hasChanged() {
95                 return fhasChanged;
96         }
97         
98         public void sethasChanged(boolean hasChanged) {
99                 fhasChanged = hasChanged;
100         }
101         
102         public void setChildVariables(IVariable[] newChildVariables) {
103                 fVariables = newChildVariables;
104         }
105         
106         /* (non-Javadoc)
107          * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
108          */
109         public String getReferenceTypeName() throws DebugException {
110                 return fTypeName;
111         }
112         
113         /* (non-Javadoc)
114          * @see org.eclipse.debug.core.model.IValue#getValueString()
115          */
116         public String getValueString() throws DebugException {
117                 return fValueString;
118         }
119         
120         /* (non-Javadoc)
121          * @see org.eclipse.debug.core.model.IValue#isAllocated()
122          */
123         public boolean isAllocated() throws DebugException {
124                 return true;
125         }
126         
127         /* (non-Javadoc)
128          * @see org.eclipse.debug.core.model.IValue#getVariables()
129          */
130         public IVariable[] getVariables() throws DebugException {
131                 return fVariables;
132         }
133         
134         /* (non-Javadoc)
135          * @see org.eclipse.debug.core.model.IValue#hasVariables()
136          */
137         public boolean hasVariables() throws DebugException {
138                 return (fVariables.length > 0);
139         }
140         
141         public abstract void setType(String typeName);
142         public abstract void renderValueString(String data);
143
144         public abstract boolean verifyValue(String expression);
145         
146         public boolean setValue(String expression) {
147                 if (!verifyValue(expression))
148                         return false;
149         if( getDebugTarget() == null ) {
150             renderValueString(expression);
151             } else {
152                     if(((XDebugTarget) getDebugTarget()).setVarValue(fVariable.getFullName(),expression)) {
153                             renderValueString(expression);
154                             return true;
155                     }
156             }
157                 return false;
158         }
159         
160         public boolean setValueA(String expression) {
161         if(! fValueString.toString().equals(expression)) {
162                 fVariables= new IVariable[0];
163                 fValueString = expression;
164             fhasChanged = true;                 
165         } else {
166             fhasChanged = false;                        
167         }
168
169         return true;
170         }
171
172         public boolean setValueB(IValue value) {
173                 try {
174                         fTypeName = value.getReferenceTypeName();
175                 } catch (DebugException e) {
176                 }
177                 
178                 fhasChanged = false;
179                 
180                 switch (((XDebugAbstractValue) value). getType()) {
181                         case VALUETYPE_UNINITIALIZED:
182                         case VALUETYPE_STRING:
183                         case VALUETYPE_INT:
184                         case VALUETYPE_FLOAT:
185                         case VALUETYPE_BOOLEAN:
186                                 try {
187                                         if (! fValueString.equals(value.getValueString())) {
188                                                 fValueString = value.getValueString();
189                                                 fhasChanged = true;
190                                         }
191                                 } catch (DebugException e) {
192                                         int a = 10;
193                                         a++;
194                                 }
195                                 break;
196
197                         case VALUETYPE_RESOURCE:
198                                 try {
199                                         if (! fValueString.equals(value.getValueString())) {
200                                                 fValueString = value.getValueString();
201                                                 fhasChanged = true;
202                                         }
203                                 } catch (DebugException e) {
204                                         int a = 10;
205                                         a++;
206                                 }
207                                 break;
208
209                         case VALUETYPE_HASH:
210                                 int a = 20;
211                                 a = a +2;
212                                 break;
213                                 
214                         case VALUETYPE_OBJECT:
215                         case VALUETYPE_ARRAY:
216                                 try {
217                                         IVariable[] newVariable = value.getVariables();
218                                         
219                                         if (fVariables.length == 0) {
220                                                 if (newVariable.length > 0) {
221                                                         fValueString = value.getValueString();
222                                                         fVariables = newVariable;
223                                                         fhasChanged = true;
224                                                 }
225                                         } else {
226                                                 for(int i = 0; i < fVariables.length; i++) {
227                                                         // da capire quando e perche'
228                                                         try {
229                                                                 if (! ((XDebugVariable)fVariables[i]).equals(((XDebugVariable)newVariable[i]))) {
230                                                                         //fVariables[i].setValue(newVariable[i].getValue());
231                                                                         fhasChanged = true;
232                                                                 }
233                                                         } catch (Exception e) {
234                                                                 //int b = 1;
235                                                         }
236                                                 }
237                                                 if (fhasChanged) {
238                                                         fValueString = value.getValueString();
239                                                         for(int i = 0; i < fVariables.length; i++) {
240                                                                 try {
241                                                                         fVariables[i].setValue(newVariable[i].getValue());
242                                                                 } catch (Exception e) {
243                                                                         //int b = 1;
244                                                                 }
245                                                         }
246                                                 }
247                                         }
248                                 } catch (DebugException e) {
249                                         int b = 10;
250                                         b++;
251                                 }
252                                 
253                                 break;
254                 }
255
256         return true;
257         }
258         
259         public boolean setValueBOld(IValue value) {
260                 fhasChanged = false;
261
262                 switch (((XDebugAbstractValue) value). getType()) {
263                         case VALUETYPE_UNINITIALIZED:
264                         case VALUETYPE_STRING:
265                         case VALUETYPE_INT:
266                         case VALUETYPE_FLOAT:
267                         case VALUETYPE_BOOLEAN:
268                                 try {
269                                         if (! fValueString.equals(value.getValueString())) {
270                                                 fValueString = value.getValueString();
271                                                 fhasChanged = true;
272                                         }
273                                 } catch (DebugException e) {
274                                 }
275                                 break;
276
277                         case VALUETYPE_HASH:
278                                 int a = 20;
279                                 a = a +2;
280                                 break;
281                                 
282                         case VALUETYPE_OBJECT:
283                         case VALUETYPE_ARRAY:
284                                 try {
285                                         IVariable[] newVariable = value.getVariables();
286                                         
287                                         if (fVariables.length == 0) {
288                                                 if (newVariable.length > 0) {
289                                                         fValueString = value.getValueString();
290                                                         fVariables = newVariable;
291                                                         fhasChanged = true;
292                                                 }
293                                         } else {
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());
297                                                                 fhasChanged = true;
298                                                         }
299                                                 }
300                                                 if (fhasChanged) {
301                                                         fValueString = value.getValueString();
302                                                         for(int i = 0; i < fVariables.length; i++) {
303                                                                 fVariables[i].setValue(newVariable[i].getValue());
304                                                         }
305                                                 }
306                                         }
307                                 } catch (DebugException e) {
308                                 }
309                                 
310                                 break;
311                 }
312
313         return true;
314         }
315
316         public int getType() {
317                 return fType;
318         }
319
320         public boolean supportsValueModification() {
321                 return false;
322         }
323 }