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
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;
16 import java.util.Iterator;
17 import java.util.Vector;
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;
27 * PHPValue object belongs to a PHPVariable (is a member of PHPVariable).
28 * A PHPValue itself can have PHPVariables as children.
31 public class PHPValue implements IValue {
33 final static String[] PEV_NAMES = {"undefined", // 0
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;
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.
69 this (null, "", PEVT_UNKNOWN, null); // Creates an empty value
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.
79 PHPValue (PHPStackFrame frame, String value, int fValueType, Vector subitems)
81 this.fValueType = fValueType;
82 this.fValueString = value;
83 this.fStackFrame = frame;
84 this.fHasChanged = false;
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)
90 this.fVariables = new Vector (); // Create an empty vector
98 Vector addVariable (Vector item)
100 if (item != null) { // If there is something we want to add
101 this.fVariables.addAll (item); //
104 return this.fVariables;
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
115 while (iter.hasNext ()) { // As long as we have children
116 ((PHPVariable) iter.next ()).setParent (parent); // Set all child's parent
122 * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
124 public String getReferenceTypeName(){
125 return PEV_NAMES[fValueType];
131 public int getReferenceType(){
136 * @param type Set the reference type (see the PEVT_... values).
138 public int setReferenceType (int type) {
139 return fValueType = type;
143 * This method is called whenever this value (variable) is changed.
145 * @param value The changed value for this variable.
147 public void setValueString (String value) {
148 fValueString = value;
152 * @see org.eclipse.debug.core.model.IValue#getfValueString()
154 public String getValueString() {
159 * @see org.eclipse.debug.core.model.IValue#isAllocated()
161 public boolean isAllocated() throws DebugException {
166 * @see org.eclipse.debug.core.model.IValue#getVariables()
168 * @return The array of child variable for this value (variable).
170 public IVariable[] getVariables() {
171 return (PHPVariable[]) fVariables.toArray (new PHPVariable[fVariables.size ()]);
172 // return (IVariable[])fVariables.toArray();
178 public Vector getChildVariables () {
183 * @see org.eclipse.debug.core.model.IValue#hasVariables()
187 * <li> <code>true</code> if this value (variable) has child variables
188 * <li> <code>false</code> if no child variable available
191 public boolean hasVariables() throws DebugException {
192 // return (!fVariables.isEmpty ());
193 return (fVariables.size () != 0);
197 * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
199 public String getModelIdentifier() {
200 // TODO Auto-generated method stub
205 * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
207 public IDebugTarget getDebugTarget() {
208 return fStackFrame.getDebugTarget();
212 * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
214 public ILaunch getLaunch() {
215 return getDebugTarget().getLaunch();
219 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
221 public Object getAdapter(Class adapter) {
225 public boolean hasValueChanged () throws DebugException {
229 public void setValueChanged (boolean changed) {
230 fHasChanged = changed;