Patches from Robert Kraske (robekras):
[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                                                                                                                                         //
60
61         /**
62          *
63          */
64         PHPValue () {
65                 this (null, "", PEVT_UNKNOWN, null);                                            // Creates an empty value
66         }
67
68         /**
69          *
70          * @param frame       The stackframe this value (and variable) belongs to.
71          * @param value       The value of this value.
72          * @param fValueType  The type of this value (see the PEVT_... values).
73          * @param subitems    This value has subitems.
74          */
75         PHPValue (PHPStackFrame frame, String value, int fValueType, Vector subitems)
76         {
77                 this.fValueType   = fValueType;
78                 this.fValueString = value;
79                 this.fStackFrame  = frame;
80
81                 if (subitems != null) {                                     // If there are children for this value (variable)
82                         this.fVariables = new Vector (subitems);                // Then add the children to this value (variable)
83                 }
84                 else {
85                         this.fVariables = new Vector ();                        // Create an empty vector
86                 }
87         }
88
89         /**
90          *
91          * @param item
92          */
93         Vector addVariable (Vector item)
94         {
95                 if (item != null) {                                                                                     // If there is something we want to add
96                         this.fVariables.addAll (item);                          //
97                 }
98
99                 return this.fVariables;
100         }
101
102         /**
103          *
104          * @param parent
105          */
106         public void setParent (PHPVariable parent) {
107                 if (!fVariables.isEmpty ()) {                                           // If we have child variables
108                         Iterator iter = fVariables.iterator ();                                 // Create an iterator for the children
109
110                         while (iter.hasNext ()) {                               // As long as we have children
111                                 ((PHPVariable) iter.next ()).setParent (parent);    // Set all child's parent
112                         }
113                 }
114         }
115
116         /**
117          * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
118          */
119         public String getReferenceTypeName(){
120                 return PEV_NAMES[fValueType];
121         }
122
123         /**
124          *
125          */
126         public int getReferenceType(){
127                 return fValueType;
128         }
129
130         /**
131          * @param type Set the reference type (see the PEVT_... values).
132          */
133         public int setReferenceType (int type) {
134                 return fValueType = type;
135         }
136
137         /**
138          * This method is called whenever this value (variable) is changed.
139          *
140          * @param value The changed value for this variable.
141          */
142         public void setValueString (String value) {
143                 fValueString = value;
144         }
145
146         /**
147          * @see org.eclipse.debug.core.model.IValue#getfValueString()
148          */
149         public String getValueString() {
150                 return fValueString;
151         }
152
153         /**
154          * @see org.eclipse.debug.core.model.IValue#isAllocated()
155          */
156         public boolean isAllocated() throws DebugException {
157                 return false;
158         }
159
160         /**
161          * @see org.eclipse.debug.core.model.IValue#getVariables()
162          *
163          * @return The array of child variable for this value (variable).
164          */
165         public IVariable[] getVariables() {
166                 return (PHPVariable[]) fVariables.toArray (new PHPVariable[fVariables.size ()]);
167 //              return  (IVariable[])fVariables.toArray();
168         }
169
170         /**
171          *
172          */
173         public Vector getChildVariables () {
174                 return (fVariables);
175         }
176
177         /**
178          * @see org.eclipse.debug.core.model.IValue#hasVariables()
179          *
180          * @return
181          * <ul>
182          * <li> <code>true</code> if this value (variable) has child variables
183          * <li> <code>false</code> if no child variable available
184          * </ul>
185          */
186         public boolean hasVariables() throws DebugException {
187                 // return (!fVariables.isEmpty ());
188                 return (fVariables.size () != 0);
189         }
190
191         /**
192          * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
193          */
194         public String getModelIdentifier() {
195                 // TODO Auto-generated method stub
196                 return null;
197         }
198
199         /**
200          * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
201          */
202         public IDebugTarget getDebugTarget() {
203                 return fStackFrame.getDebugTarget();
204         }
205
206         /**
207          * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
208          */
209         public ILaunch getLaunch() {
210                 return getDebugTarget().getLaunch();
211         }
212
213         /**
214          * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
215          */
216         public Object getAdapter(Class adapter) {
217                 return null;
218         }
219
220 }