df5c92a3611da8c8a2a85b08e539cf223acb6428
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugAbstractValue.java
1  /* Created on 23.11.2004
2  *
3  * TODO To change the template for this generated file go to
4  * Window - Preferences - Java - Code Style - Code Templates
5  */
6 package net.sourceforge.phpeclipse.xdebug.php.model;
7
8 import java.util.Arrays;
9 import java.util.Iterator;
10 import java.util.Vector;
11 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
12
13 import org.eclipse.debug.core.DebugException;
14 import org.eclipse.debug.core.model.IValue;
15 import org.eclipse.debug.core.model.IVariable;
16 import org.w3c.dom.Node;
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
25 public /*abstract*/ class XDebugAbstractValue  extends XDebugElement implements IValue {
26         private String          fValueString;
27         private String          fTypeName;
28         private boolean         fhasChanged;
29         protected String        rowValue;
30         private boolean         fSorted;
31         private Vector          fVariables;                                                     // The children of this variable (other variables) if any
32
33         public XDebugAbstractValue(XDebugStackFrame frame, Node value) throws DebugException  {
34                 super(frame == null ? null : (XDebugTarget)frame.getDebugTarget());
35
36                 fTypeName     = PHPDebugUtils.getAttributeValue(value, "type");
37
38                 fVariables    = new Vector();                                           // Create an empty vector
39                 fValueString  = "";
40                 rowValue      = "";
41                 fSorted       = false;
42
43                 try {
44                         rowValue = value.getFirstChild().getNodeValue();
45                 } catch (NullPointerException e) {
46                         rowValue = "";
47                 }
48         }
49
50         public boolean hasChanged() {
51                 return fhasChanged;
52         }
53
54         public void setChanged(boolean changed) {
55                 fhasChanged = changed;
56         }
57
58         /**
59          *
60          * @param item
61          */
62         public Vector addVariable(Vector item) {
63                 if (item != null) {                                                                             // If there is something we want to add
64                         fVariables.addAll(item);
65                         fSorted = false;
66                 }
67
68                 return this.fVariables;
69         }
70
71         /**
72          *
73          * @param parent
74          */
75         public void setParent(XDebugVariable parent) {
76                 if (!fVariables.isEmpty()) {                                                            // If we have child variables
77                         Iterator iter = fVariables.iterator();                                  // Create an iterator for the children
78
79                         while (iter.hasNext()) {                                                                // As long as we have children
80                                 ((XDebugVariable) iter.next()).setParent(parent);       // Set all child's parent
81                         }
82                 }
83         }
84
85         /* (non-Javadoc)
86          * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
87          */
88         public String getReferenceTypeName() throws DebugException {
89                 return fTypeName;
90         }
91
92         /* (non-Javadoc)
93          * @see org.eclipse.debug.core.model.IValue#getValueString()
94          */
95         public String getValueString() throws DebugException {
96                 return fValueString;
97         }
98
99         /* (non-Javadoc)
100          * @see org.eclipse.debug.core.model.IValue#isAllocated()
101          */
102         public boolean isAllocated() throws DebugException {
103                 return true;
104         }
105
106         /* (non-Javadoc)
107          * @see org.eclipse.debug.core.model.IValue#getVariables()
108          */
109         public IVariable[] getVariables() throws DebugException {
110                 return (XDebugVariable[]) getChildVariables().toArray(
111                                 new XDebugVariable[fVariables.size()]);
112         }
113
114         /**
115          *
116          */
117         public Vector getChildVariables() {
118                 return fVariables;
119         }
120
121         /* (non-Javadoc)
122          * @see org.eclipse.debug.core.model.IValue#hasVariables()
123          */
124         public boolean hasVariables() throws DebugException {
125                 return (fVariables.size() != 0);
126         }
127
128         public boolean setValue(String expression) throws DebugException {
129                 return true;
130         };
131
132         protected boolean verifyValue(String expression) {
133                 return true;
134         }
135
136         protected boolean supportsValueModification() {
137                 return false;
138         }
139
140         protected void setValueString(String valueString) {
141                 fValueString = valueString;
142         }
143
144         protected void setChildren(IVariable[] newChildren) {
145                 fVariables = new Vector (Arrays.asList(newChildren));
146         }
147 }