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
65 this (null, "", PEVT_UNKNOWN, null); // Creates an empty value
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.
75 PHPValue (PHPStackFrame frame, String value, int fValueType, Vector subitems)
77 this.fValueType = fValueType;
78 this.fValueString = value;
79 this.fStackFrame = frame;
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)
85 this.fVariables = new Vector (); // Create an empty vector
93 Vector addVariable (Vector item)
95 if (item != null) { // If there is something we want to add
96 this.fVariables.addAll (item); //
99 return this.fVariables;
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
110 while (iter.hasNext ()) { // As long as we have children
111 ((PHPVariable) iter.next ()).setParent (parent); // Set all child's parent
117 * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
119 public String getReferenceTypeName(){
120 return PEV_NAMES[fValueType];
126 public int getReferenceType(){
131 * @param type Set the reference type (see the PEVT_... values).
133 public int setReferenceType (int type) {
134 return fValueType = type;
138 * This method is called whenever this value (variable) is changed.
140 * @param value The changed value for this variable.
142 public void setValueString (String value) {
143 fValueString = value;
147 * @see org.eclipse.debug.core.model.IValue#getfValueString()
149 public String getValueString() {
154 * @see org.eclipse.debug.core.model.IValue#isAllocated()
156 public boolean isAllocated() throws DebugException {
161 * @see org.eclipse.debug.core.model.IValue#getVariables()
163 * @return The array of child variable for this value (variable).
165 public IVariable[] getVariables() {
166 return (PHPVariable[]) fVariables.toArray (new PHPVariable[fVariables.size ()]);
167 // return (IVariable[])fVariables.toArray();
173 public Vector getChildVariables () {
178 * @see org.eclipse.debug.core.model.IValue#hasVariables()
182 * <li> <code>true</code> if this value (variable) has child variables
183 * <li> <code>false</code> if no child variable available
186 public boolean hasVariables() throws DebugException {
187 // return (!fVariables.isEmpty ());
188 return (fVariables.size () != 0);
192 * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
194 public String getModelIdentifier() {
195 // TODO Auto-generated method stub
200 * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
202 public IDebugTarget getDebugTarget() {
203 return fStackFrame.getDebugTarget();
207 * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
209 public ILaunch getLaunch() {
210 return getDebugTarget().getLaunch();
214 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
216 public Object getAdapter(Class adapter) {