1) Need to syncronize also the type of variable values not only the values (makes...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugAbstractValue.java
index 3899a24..3912916 100644 (file)
@@ -1,19 +1,19 @@
-/*
- * Created on 23.11.2004
+ /* Created on 23.11.2004
  *
  * TODO To change the template for this generated file go to
  * Window - Preferences - Java - Code Style - Code Templates
  */
 package net.sourceforge.phpeclipse.xdebug.php.model;
 
-import net.sourceforge.phpeclipse.xdebug.core.Base64;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Vector;
 import net.sourceforge.phpeclipse.xdebug.core.PHPDebugUtils;
 
 import org.eclipse.debug.core.DebugException;
 import org.eclipse.debug.core.model.IValue;
 import org.eclipse.debug.core.model.IVariable;
 import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 /**
  * @author Axel
@@ -21,303 +21,131 @@ import org.w3c.dom.NodeList;
  * TODO To change the template for this generated type comment go to
  * Window - Preferences - Java - Code Style - Code Templates
  */
-public abstract class XDebugAbstractValue  extends XDebugElement implements IValue {
-       
-       public static final int VALUETYPE_UNKNOWN = -1;
-       public static final int VALUETYPE_UNINITIALIZED = 0;
-       public static final int VALUETYPE_STRING = 1;
-       public static final int VALUETYPE_INT = 4;
-       public static final int VALUETYPE_FLOAT = 5;
-       public static final int VALUETYPE_BOOLEAN = 6;
-       public static final int VALUETYPE_ARRAY = 8;
-       public static final int VALUETYPE_HASH = 9;
-       public static final int VALUETYPE_OBJECT = 10;
-       public static final int VALUETYPE_RESOURCE = 11;
 
-       
-       protected XDebugVariable fVariable;
-       private IVariable[] fVariables;
-       protected String fValueString;
-       protected int fType;
-       protected String fTypeName;
-       
-       private boolean fhasChanged;
+public /*abstract*/ class XDebugAbstractValue  extends XDebugElement implements IValue {
+       private String          fValueString;
+       private String          fTypeName;
+       private boolean         fhasChanged;
+       protected String        rowValue;
+       private boolean         fSorted;
+       private Vector          fVariables;                                                     // The children of this variable (other variables) if any
 
-       public XDebugAbstractValue(XDebugVariable variable, Node varNode, String typeName) {
-               super((XDebugTarget) variable.getDebugTarget());
-               fVariable = variable;
-               if (varNode==null){
-                       try {
-                               System.out.println(variable.getName()+"=null");
-                       } catch (DebugException e) {
-                               // TODO Auto-generated catch block
-                               e.printStackTrace();
-                       }
-                       return; 
-               }
-               setType(typeName);
-               NodeList property = varNode.getChildNodes();
-               if (variable.hasChildren()) {
-                       renderValueString(""+property.getLength());
-                       fVariables = new IVariable[property.getLength()];
-                       for (int i = 0; i<property.getLength(); i++) {
-                               Node propertyNode = property.item(i);
-                               fVariables[i] = new XDebugVariable(variable.getStackFrame(), propertyNode);
-                       }
-               }else {
-//                     fDataString="";
-                       fVariables = new IVariable[0];
-//                     if (variable.getType()== XDebugVariable.VARTYPE_UNINITIALIZED)
-//                             fValueString="uninitialized";
-//                     else {
-                       String str="";
-                       try {
-                               str=varNode.getFirstChild().getNodeValue();
-                       } catch (NullPointerException e) {
-                               str="";
-                       }
-                       if (variable.getEncoding().equals("base64")) {
-                               if (str.length()!=0)
-                                       str=new String(Base64.decode(str));
-                               else
-                                       str="";
-                       }
-                       renderValueString(str);
-//                     }
-               }
-               String className=PHPDebugUtils.getAttributeValue(varNode,"classname");
-               if(!"".equals(className))
-                       renderValueString(className);
+       public XDebugAbstractValue(XDebugStackFrame frame, Node value) throws DebugException  {
+               super(frame == null ? null : (XDebugTarget)frame.getDebugTarget());
 
+               fTypeName     = PHPDebugUtils.getAttributeValue(value, "type");
+
+               fVariables    = new Vector();                                           // Create an empty vector
+               fValueString  = "";
+               rowValue      = "";
+               fSorted       = false;
+
+               try {
+                       rowValue = value.getFirstChild().getNodeValue();
+               } catch (NullPointerException e) {
+                       rowValue = "";
+               }
        }
-       
+
        public boolean hasChanged() {
                return fhasChanged;
        }
-       
-       public void sethasChanged(boolean hasChanged) {
-               fhasChanged = hasChanged;
+
+       public void setChanged(boolean changed) {
+               fhasChanged = changed;
+       }
+
+       /**
+        *
+        * @param item
+        */
+       public Vector addVariable(Vector item) {
+               if (item != null) {                                                                             // If there is something we want to add
+                       fVariables.addAll(item);
+                       fSorted = false;
+               }
+
+               return this.fVariables;
        }
-       
-       public void setChildVariables(IVariable[] newChildVariables) {
-               fVariables = newChildVariables;
+
+       /**
+        *
+        * @param parent
+        */
+       public void setParent(XDebugVariable parent) {
+               if (!fVariables.isEmpty()) {                                                            // If we have child variables
+                       Iterator iter = fVariables.iterator();                                  // Create an iterator for the children
+
+                       while (iter.hasNext()) {                                                                // As long as we have children
+                               ((XDebugVariable) iter.next()).setParent(parent);       // Set all child's parent
+                       }
+               }
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
         */
        public String getReferenceTypeName() throws DebugException {
                return fTypeName;
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValue#getValueString()
         */
        public String getValueString() throws DebugException {
                return fValueString;
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValue#isAllocated()
         */
        public boolean isAllocated() throws DebugException {
                return true;
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValue#getVariables()
         */
        public IVariable[] getVariables() throws DebugException {
+               return (XDebugVariable[]) getChildVariables().toArray(
+                               new XDebugVariable[fVariables.size()]);
+       }
+
+       /**
+        *
+        */
+       public Vector getChildVariables() {
                return fVariables;
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.debug.core.model.IValue#hasVariables()
         */
        public boolean hasVariables() throws DebugException {
-               return (fVariables.length > 0);
+               return (fVariables.size() != 0);
        }
-       
-       public abstract void setType(String typeName);
-       public abstract void renderValueString(String data);
 
-       public abstract boolean verifyValue(String expression);
-       
-       public boolean setValue(String expression) {
-               if (!verifyValue(expression))
-                       return false;
-        if( getDebugTarget() == null ) {
-            renderValueString(expression);
-           } else {
-                   if(((XDebugTarget) getDebugTarget()).setVarValue(fVariable.getFullName(),expression)) {
-                           renderValueString(expression);
-                           return true;
-                   }
-           }
-               return false;
-       }
-       
-       public boolean setValueA(String expression) {
-        if(! fValueString.toString().equals(expression)) {
-               fVariables= new IVariable[0];
-               fValueString = expression;
-            fhasChanged = true;                
-        } else {
-            fhasChanged = false;                       
-        }
+       public boolean setValue(String expression) throws DebugException {
+               return true;
+       };
 
-        return true;
+       protected boolean verifyValue(String expression) {
+               return true;
        }
 
-       public boolean setValueB(IValue value) {
-               try {
-                       fTypeName = value.getReferenceTypeName();
-               } catch (DebugException e) {
-               }
-               
-               fhasChanged = false;
-               
-               switch (((XDebugAbstractValue) value). getType()) {
-                       case VALUETYPE_UNINITIALIZED:
-                       case VALUETYPE_STRING:
-                       case VALUETYPE_INT:
-                       case VALUETYPE_FLOAT:
-                       case VALUETYPE_BOOLEAN:
-                               try {
-                                       if (! fValueString.equals(value.getValueString())) {
-                                               fValueString = value.getValueString();
-                                               fhasChanged = true;
-                                       }
-                               } catch (DebugException e) {
-                                       int a = 10;
-                                       a++;
-                               }
-                               break;
-
-                       case VALUETYPE_RESOURCE:
-                               try {
-                                       if (! fValueString.equals(value.getValueString())) {
-                                               fValueString = value.getValueString();
-                                               fhasChanged = true;
-                                       }
-                               } catch (DebugException e) {
-                                       int a = 10;
-                                       a++;
-                               }
-                               break;
-
-                       case VALUETYPE_HASH:
-                               int a = 20;
-                               a = a +2;
-                               break;
-                               
-                       case VALUETYPE_OBJECT:
-                       case VALUETYPE_ARRAY:
-                               try {
-                                       IVariable[] newVariable = value.getVariables();
-                                       
-                                       if (fVariables.length == 0) {
-                                               if (newVariable.length > 0) {
-                                                       fValueString = value.getValueString();
-                                                       fVariables = newVariable;
-                                                       fhasChanged = true;
-                                               }
-                                       } else {
-                                               for(int i = 0; i < fVariables.length; i++) {
-                                                       // da capire quando e perche'
-                                                       try {
-                                                               if (! ((XDebugVariable)fVariables[i]).equals(((XDebugVariable)newVariable[i]))) {
-                                                                       //fVariables[i].setValue(newVariable[i].getValue());
-                                                                       fhasChanged = true;
-                                                               }
-                                                       } catch (Exception e) {
-                                                               //int b = 1;
-                                                       }
-                                               }
-                                               if (fhasChanged) {
-                                                       fValueString = value.getValueString();
-                                                       for(int i = 0; i < fVariables.length; i++) {
-                                                               try {
-                                                                       fVariables[i].setValue(newVariable[i].getValue());
-                                                               } catch (Exception e) {
-                                                                       //int b = 1;
-                                                               }
-                                                       }
-                                               }
-                                       }
-                               } catch (DebugException e) {
-                                       int b = 10;
-                                       b++;
-                               }
-                               
-                               break;
-               }
-
-        return true;
+       protected boolean supportsValueModification() {
+               return false;
        }
-       
-       public boolean setValueBOld(IValue value) {
-               fhasChanged = false;
-
-               switch (((XDebugAbstractValue) value). getType()) {
-                       case VALUETYPE_UNINITIALIZED:
-                       case VALUETYPE_STRING:
-                       case VALUETYPE_INT:
-                       case VALUETYPE_FLOAT:
-                       case VALUETYPE_BOOLEAN:
-                               try {
-                                       if (! fValueString.equals(value.getValueString())) {
-                                               fValueString = value.getValueString();
-                                               fhasChanged = true;
-                                       }
-                               } catch (DebugException e) {
-                               }
-                               break;
-
-                       case VALUETYPE_HASH:
-                               int a = 20;
-                               a = a +2;
-                               break;
-                               
-                       case VALUETYPE_OBJECT:
-                       case VALUETYPE_ARRAY:
-                               try {
-                                       IVariable[] newVariable = value.getVariables();
-                                       
-                                       if (fVariables.length == 0) {
-                                               if (newVariable.length > 0) {
-                                                       fValueString = value.getValueString();
-                                                       fVariables = newVariable;
-                                                       fhasChanged = true;
-                                               }
-                                       } else {
-                                               for(int i = 0; i < fVariables.length; i++) {
-                                                       if (! ((XDebugVariable)fVariables[i]).equals(((XDebugVariable)newVariable[i]))) {
-                                                               //fVariables[i].setValue(newVariable[i].getValue());
-                                                               fhasChanged = true;
-                                                       }
-                                               }
-                                               if (fhasChanged) {
-                                                       fValueString = value.getValueString();
-                                                       for(int i = 0; i < fVariables.length; i++) {
-                                                               fVariables[i].setValue(newVariable[i].getValue());
-                                                       }
-                                               }
-                                       }
-                               } catch (DebugException e) {
-                               }
-                               
-                               break;
-               }
 
-        return true;
+       protected void setValueString(String valueString) {
+               fValueString = valueString;
        }
 
-       public int getType() {
-               return fType;
+       protected void setChildren(IVariable[] newChildren) {
+               fVariables = new Vector (Arrays.asList(newChildren));
        }
 
-       public boolean supportsValueModification() {
-               return false;
-       }
-}
\ No newline at end of file
+    public void setReferenceTypeName (String referenceTypeName) {
+        fTypeName = referenceTypeName;
+    }
+}