Fix variable view value modification and refactored XDebugAbstractValue and derived...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugVariable.java
1 /*
2  * Created on 23.11.2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */
7 package net.sourceforge.phpeclipse.xdebug.php.model;
8
9 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
10
11 import org.eclipse.debug.core.DebugException;
12 import org.eclipse.debug.core.model.IValue;
13 import org.eclipse.debug.core.model.IVariable;
14 import org.w3c.dom.Node;
15
16 /**
17  * @author Axel
18  *
19  * TODO To change the template for this generated type comment go to
20  * Window - Preferences - Java - Code Style - Code Templates
21  */
22 public class XDebugVariable extends XDebugElement implements IVariable {
23         private String fName;
24         private XDebugStackFrame fFrame;
25         private XDebugAbstractValue fValue;
26         private String fFacet;
27         
28         /**
29          * Constructs a variable contained in the given stack frame
30          * with the given name.
31          * 
32          * @param frame owning stack frame
33          * @param name variable name
34          */
35         public XDebugVariable(XDebugStackFrame frame, Node property) throws DebugException {
36                 super((XDebugTarget) frame.getDebugTarget());
37                 if (frame != null ) {
38                         fFrame = frame;
39                 }
40
41                 fName = PHPDebugUtils.getAttributeValue(property,"name");
42                 if ("".equals(fName)) {
43                         fName = PHPDebugUtils.getAttributeValue(property,"address");
44                 }
45                 
46                 fFacet = PHPDebugUtils.getAttributeValue(property, "facet");
47
48                 String typeName = PHPDebugUtils.getAttributeValue(property, "type");
49
50                 if (typeName.equals("int") ) 
51                         fValue = new XDebugIntValue(frame, property);
52                 else if (typeName.equals("float") ) 
53                         fValue = new XDebugFloatValue(frame, property);
54                 else if (typeName.equals("bool") ) 
55                         fValue = new XDebugBooleanValue(frame, property);
56                 else if (typeName.equals("string") )
57                         fValue = new XDebugStringValue(frame, property);
58                 else if (typeName.equals("array") )
59                         fValue = new XDebugArrayValue(frame, property);
60                 else if (typeName.equals("object") )
61                         fValue = new XDebugObjectValue(frame, property);
62                 else if (typeName.equals("resource") )
63                         fValue = new XDebugResourceValue(frame, property);
64                 else
65                         fValue = new XDebugValue(frame, property);
66         }
67                 
68         /* (non-Javadoc)
69          * @see org.eclipse.debug.core.model.IVariable#getValue()
70          */
71         public IValue getValue() throws DebugException {
72                 return fValue;
73         }
74         
75         /* (non-Javadoc)
76          * @see org.eclipse.debug.core.model.IVariable#getName()
77          */
78         public String getName() throws DebugException {
79                 return fName;
80         }
81         
82         /* (non-Javadoc)
83          * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
84          */
85         public String getReferenceTypeName() throws DebugException {
86                 return fValue.getReferenceTypeName();
87         }
88         
89         /* (non-Javadoc)
90          * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
91          */
92         public boolean hasValueChanged() throws DebugException {
93                 return fValue.hasChanged();
94         }
95         
96         /* (non-Javadoc)
97          * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
98          */
99         public void setValue(String expression) throws DebugException {
100                 if (fFrame.setVariableValue(this, expression)) {
101                         fValue.setValue(expression);
102                 }
103         }
104         
105         /* (non-Javadoc)
106          * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
107          */
108         public void setValue(IValue value) throws DebugException {
109         }
110
111         /* (non-Javadoc)
112          * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
113          */
114         public boolean supportsValueModification() {
115                 return fValue.supportsValueModification();
116         }
117
118         /* (non-Javadoc)
119          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
120          */
121         public boolean verifyValue(String expression) throws DebugException {
122                 /*return true; */return fValue.verifyValue(expression);
123         }
124
125         /* (non-Javadoc)
126          * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
127          */
128         public boolean verifyValue(IValue value) throws DebugException {
129                 return false;
130         }
131         
132         public String getValueString() throws DebugException {
133                 return fValue.getValueString();
134         }
135         
136         public String getVisibility() {
137                 return fFacet;
138         }
139 }