b736b8e4f2ab0c8ae8e1adefe4198fb966d6ef71
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / model / PHPValue.java
1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Vicente Fernando - www.alfersoft.com.ar
11     Christian Perkonig - cperkonig@gmx.at
12 **********************************************************************/
13 package net.sourceforge.phpdt.internal.debug.core.model;
14
15
16 import java.util.Iterator;
17 import java.util.Vector;
18
19 import org.eclipse.debug.core.DebugException;
20 import org.eclipse.debug.core.ILaunch;
21 import org.eclipse.debug.core.model.IDebugTarget;
22 import org.eclipse.debug.core.model.IValue;
23 import org.eclipse.debug.core.model.IVariable;
24
25
26 /**
27  * PHPValue object belongs to a PHPVariable (is a member of PHPVariable).
28  * A PHPValue itself can have PHPVariables as children.
29  *
30  */
31 public class PHPValue implements IValue {
32
33         final static String[] PEV_NAMES = {"undefined",                 // 0
34                                            "long",                      // 1
35                                                                            "double",                    // 2
36                                                                            "string",                    // 3
37                                                                            "array",                     // 4
38                                                                            "object",                    // 5
39                                                                            "boolean",                   // 6
40                                                                            "resource",                  // 7
41                                                                            "reference",                 // 8
42                                                                            "soft reference"};           // 9
43         final static int PEVT_UNKNOWN   = 0;
44         final static int PEVT_LONG              = 1;
45         final static int PEVT_DOUBLE    = 2;
46         final static int PEVT_STRING    = 3;
47         final static int PEVT_ARRAY             = 4;
48         final static int PEVT_OBJECT    = 5;
49         final static int PEVT_BOOLEAN   = 6;
50         final static int PEVT_RESOURCE  = 7;
51         final static int PEVT_REF               = 8;
52         final static int PEVT_SOFTREF   = 9;
53
54         private int                     fValueType;                             // The type of this value (see the PEVT_... values)
55         private boolean                 hasChildren;                            // This value (variable) has children (more variables)
56         private String                  fValueString;                           // The value of this variable as text
57         private Vector                  fVariables;                             // The children of this variable (other variables) if any
58         private PHPStackFrame   fStackFrame;                            // The stackframe this value (variable) belongs to
59         private boolean         fHasChanged;                                                    // The value has changed between two suspends
60                                                                                                                                         // This variable was moved from PHPVariable due to the fact,
61                                                                                                                                         // that two PHPVariables can reference the same PHPValue,
62                                                                                                                                         // so only the first PHPVariable would win, when we check the variable tree
63                                                                                                                                         // for changed values.
64
65         /**
66          *
67          */
68         PHPValue () {
69                 this (null, "", PEVT_UNKNOWN, null);                                            // Creates an empty value
70         }
71
72         /**
73          *
74          * @param frame       The stackframe this value (and variable) belongs to.
75          * @param value       The value of this value.
76          * @param fValueType  The type of this value (see the PEVT_... values).
77          * @param subitems    This value has subitems.
78          */
79         PHPValue (PHPStackFrame frame, String value, int fValueType, Vector subitems)
80         {
81                 this.fValueType   = fValueType;
82                 this.fValueString = value;
83                 this.fStackFrame  = frame;
84                 this.fHasChanged  = false;
85
86                 if (subitems != null) {                                     // If there are children for this value (variable)
87                         this.fVariables = new Vector (subitems);                // Then add the children to this value (variable)
88                 }
89                 else {
90                         this.fVariables = new Vector ();                        // Create an empty vector
91                 }
92         }
93
94         /**
95          *
96          * @param item
97          */
98         Vector addVariable (Vector item)
99         {
100                 if (item != null) {                                                                                     // If there is something we want to add
101                         this.fVariables.addAll (item);                          //
102                 }
103
104                 return this.fVariables;
105         }
106
107         /**
108          *
109          * @param parent
110          */
111         public void setParent (PHPVariable parent) {
112                 if (!fVariables.isEmpty ()) {                                           // If we have child variables
113                         Iterator iter = fVariables.iterator ();                                 // Create an iterator for the children
114
115                         while (iter.hasNext ()) {                               // As long as we have children
116                                 ((PHPVariable) iter.next ()).setParent (parent);    // Set all child's parent
117                         }
118                 }
119         }
120
121         /**
122          * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
123          */
124         public String getReferenceTypeName(){
125                 return PEV_NAMES[fValueType];
126         }
127
128         /**
129          *
130          */
131         public int getReferenceType(){
132                 return fValueType;
133         }
134
135         /**
136          * @param type Set the reference type (see the PEVT_... values).
137          */
138         public int setReferenceType (int type) {
139                 return fValueType = type;
140         }
141
142         /**
143          * This method is called whenever this value (variable) is changed.
144          *
145          * @param value The changed value for this variable.
146          */
147         public void setValueString (String value) {
148                 fValueString = value;
149         }
150
151         /**
152          * @see org.eclipse.debug.core.model.IValue#getfValueString()
153          */
154         public String getValueString() {
155                 return fValueString;
156         }
157
158         /**
159          * @see org.eclipse.debug.core.model.IValue#isAllocated()
160          */
161         public boolean isAllocated() throws DebugException {
162                 return false;
163         }
164
165         /**
166          * @see org.eclipse.debug.core.model.IValue#getVariables()
167          *
168          * @return The array of child variable for this value (variable).
169          */
170         public IVariable[] getVariables() {
171                 return (PHPVariable[]) fVariables.toArray (new PHPVariable[fVariables.size ()]);
172 //              return  (IVariable[])fVariables.toArray();
173         }
174
175         /**
176          *
177          */
178         public Vector getChildVariables () {
179                 return (fVariables);
180         }
181
182         /**
183          * @see org.eclipse.debug.core.model.IValue#hasVariables()
184          *
185          * @return
186          * <ul>
187          * <li> <code>true</code> if this value (variable) has child variables
188          * <li> <code>false</code> if no child variable available
189          * </ul>
190          */
191         public boolean hasVariables() throws DebugException {
192                 // return (!fVariables.isEmpty ());
193                 return (fVariables.size () != 0);
194         }
195
196         /**
197          * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
198          */
199         public String getModelIdentifier() {
200                 // TODO Auto-generated method stub
201                 return null;
202         }
203
204         /**
205          * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
206          */
207         public IDebugTarget getDebugTarget() {
208                 return fStackFrame.getDebugTarget();
209         }
210
211         /**
212          * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
213          */
214         public ILaunch getLaunch() {
215                 return getDebugTarget().getLaunch();
216         }
217
218         /**
219          * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
220          */
221         public Object getAdapter(Class adapter) {
222                 return null;
223         }
224
225         public boolean hasValueChanged () throws DebugException {
226                 return fHasChanged;
227         }
228
229         public void setValueChanged (boolean changed) {
230                 fHasChanged = changed;
231         }
232
233
234 }