harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r555527 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/ main/java/org/apache/harmony/beans/ test/java/org/apache/harmony/beans/tests/java/beans/
Date Thu, 12 Jul 2007 08:17:25 GMT
Author: leoli
Date: Thu Jul 12 01:17:23 2007
New Revision: 555527

URL: http://svn.apache.org/viewvc?view=rev&rev=555527
Log:
Apply patch for HARMONY-4321([classlib][beans] Current java6 bean implementation does not
persist some class properly).

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Encoder.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLEncoder.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/DefaultPersistenceDelegatesFactory.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/ObjectNode.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_BooleanPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_BytePersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_CharacterPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ClassPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_DoublePersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_FloatPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_IntegerPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_LongPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ShortPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_FieldPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_ProxyPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EncoderTest.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -17,7 +17,6 @@
 
 package java.beans;
 
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import org.apache.harmony.beans.internal.nls.Messages;
@@ -57,8 +56,7 @@
 
         // added for compatibility with RI
         if (out == null) {
-            throw new NullPointerException(
-                    Messages.getString("beans.4C")); //$NON-NLS-1$
+            throw new NullPointerException(Messages.getString("beans.4C")); //$NON-NLS-1$
         }
 
         // added for compatibility with RI
@@ -67,46 +65,83 @@
                     new NullPointerException(Messages.getString("beans.4A"))); //$NON-NLS-1$
             return;
         }
-      
-        try {
-            PropertyDescriptor[] pds = Introspector.getBeanInfo(type)
-                    .getPropertyDescriptors();
 
-            for (PropertyDescriptor pd : pds) {
-                if (!isTransient(pd)) {
-                    Method getter = pd.getReadMethod();
-
-                    if (getter != null) {
-                        Method setter = pd.getWriteMethod();
-
-                        if (setter != null) {
-                            Object oldValue = getter.invoke(oldInstance,
-                                    (Object[]) null);
-                            Object newValue = getter.invoke(newInstance,
-                                    (Object[]) null);
-
-                            if (oldValue != null && !oldValue.equals(newValue)
-                                    || oldValue == null && newValue != null) {
-                                String setterName = setter.getName();
-                                Statement s = new Statement(oldInstance,
-                                        setterName, new Object[] { oldValue });
+        // added for compatibility with RI
+        if (oldInstance == null) {
+            throw new NullPointerException(Messages.getString("beans.4C")); //$NON-NLS-1$
+        }
 
-                                out.writeStatement(s);
+        BeanInfo info = null;
+        try {
+            info = Introspector.getBeanInfo(type);
+        } catch (IntrospectionException e) {
+            out.getExceptionListener().exceptionThrown(e);
+            return;
+        }
+        PropertyDescriptor[] pds = info.getPropertyDescriptors();
+
+        for (PropertyDescriptor pd : pds) {
+            if (!isTransient(pd)) {
+                Method getter = pd.getReadMethod();
+
+                if (getter != null) {
+                    Method setter = pd.getWriteMethod();
+
+                    if (setter != null) {
+                        Expression getterExp = new Expression(oldInstance, pd
+                                .getReadMethod().getName(), null);
+                        try {
+                            // Calculate the old value of the property
+                            Object oldValue = getterExp.getValue();
+
+                            // Write the getter expression to the encoder
+                            out.writeExpression(getterExp);
+
+                            // Get the target value that exists in the new
+                            // environment
+                            Object targetVal = out.get(oldValue);
+
+                            Object newValue = new Expression(newInstance, pd
+                                    .getReadMethod().getName(), null)
+                                    .getValue();
+
+                            /*
+                             * Make the target value and current property value
+                             * equivalent in the new environment
+                             */
+                            if (null == targetVal) {
+                                if (null != newValue) {
+                                    // Set to null
+                                    Statement setterStm = new Statement(
+                                            oldInstance, pd.getWriteMethod()
+                                                    .getName(),
+                                            new Object[] { null });
+                                    out.writeStatement(setterStm);
+                                }
+                            } else {
+                                PersistenceDelegate delegate = out
+                                        .getPersistenceDelegate(targetVal
+                                                .getClass());
+                                if (!delegate.mutatesTo(targetVal, newValue)) {
+                                    Statement setterStm = new Statement(
+                                            oldInstance, pd.getWriteMethod()
+                                                    .getName(),
+                                            new Object[] { oldValue });
+                                    out.writeStatement(setterStm);
+                                }
                             }
-                        } else {
-                            // commented since the process should be
-                            // continued even if no setter is found
-                            // throw new Exception("no setter for " +
-                            // pd.getName() + " property.");
-                            continue;
+                        } catch (Exception ex) {
+                            out.getExceptionListener().exceptionThrown(ex);
                         }
+                    } else {
+                        // commented since the process should be
+                        // continued even if no setter is found
+                        // throw new Exception("no setter for " +
+                        // pd.getName() + " property.");
+                        continue;
                     }
                 }
             }
-        } catch (RuntimeException e) {
-            throw e;
-        } catch (Exception e) {
-            out.getExceptionListener().exceptionThrown(e);
         }
     }
 
@@ -169,7 +204,7 @@
         if (oldInstance != null && constructorPropertyNames != null
                 && constructorPropertyNames.length > 0) {
 
-            //Get explicitly declared equals method.
+            // Get explicitly declared equals method.
             Method equalsMethod = null;
             try {
                 equalsMethod = oldInstance.getClass().getDeclaredMethod(
@@ -180,15 +215,15 @@
             }
 
             if (equalsMethod != null) {
-                    Object result;
-                    try {
-                        result = equalsMethod.invoke(oldInstance,
-                                new Object[] { newInstance });
-                    } catch (Exception e) {
-                        //should not happen here.
-                        throw new Error(e);
-                    }
-                    return ((Boolean) result).booleanValue();
+                Object result;
+                try {
+                    result = equalsMethod.invoke(oldInstance,
+                            new Object[] { newInstance });
+                } catch (Exception e) {
+                    // should not happen here.
+                    throw new Error(e);
+                }
+                return ((Boolean) result).booleanValue();
             }
         }
         return super.mutatesTo(oldInstance, newInstance);

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Encoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Encoder.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Encoder.java (original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Encoder.java Thu
Jul 12 01:17:23 2007
@@ -18,33 +18,47 @@
 package java.beans;
 
 import java.util.HashMap;
+import java.util.IdentityHashMap;
 import java.util.Vector;
 
 import org.apache.harmony.beans.DefaultPersistenceDelegatesFactory;
 import org.apache.harmony.beans.NullPersistenceDelegate;
 import org.apache.harmony.beans.ObjectNode;
-import org.apache.harmony.beans.internal.nls.Messages;
 
 public class Encoder {
 
-    private ExceptionListener exceptionListener = null;
+    private ExceptionListener exceptionListener = defaultExListener;
 
-    private final HashMap<Class<?>, PersistenceDelegate> persistenceDelegates
= new HashMap<Class<?>, PersistenceDelegate>();
+    private static final ExceptionListener defaultExListener = new DefaultExceptionListener();
+
+    private static class DefaultExceptionListener implements ExceptionListener {
+
+        public void exceptionThrown(Exception exception) {
+            System.err.println("Exception during encoding:" + exception); //$NON-NLS-1$
+            System.err.println("Continue...");
+        }
+
+    }
+
+    private static final HashMap<Class<?>, PersistenceDelegate> persistenceDelegates
= new HashMap<Class<?>, PersistenceDelegate>();
 
     Vector<Object> roots = new Vector<Object>();
 
-    HashMap<Object, ObjectNode> nodes = new HashMap<Object, ObjectNode>();
+    IdentityHashMap<Object, ObjectNode> nodes = new IdentityHashMap<Object, ObjectNode>();
+
+    private IdentityHashMap oldNewMap = new IdentityHashMap();
 
     public Encoder() {
         super();
     }
 
     public Object get(Object oldInstance) {
-        if (oldInstance == null) {
-            return null;
+        if (oldInstance == null || oldInstance instanceof String
+                || oldInstance == String.class) {
+            return oldInstance;
         }
 
-        return getValue(nodes.get(oldInstance));
+        return oldNewMap.get(oldInstance);
     }
 
     public Object remove(Object oldInstance) {
@@ -53,7 +67,8 @@
             return null;
         }
 
-        return getValue(nodes.remove(oldInstance));
+        getValue(nodes.remove(oldInstance));
+        return oldNewMap.remove(oldInstance);
     }
 
     public PersistenceDelegate getPersistenceDelegate(Class<?> type) {
@@ -77,6 +92,9 @@
 
     protected void writeObject(Object object) {
         roots.add(object);
+        if (object == null) {
+            return;
+        }
         doWriteObject(object);
     }
 
@@ -90,100 +108,98 @@
         }
 
         pd.writeObject(object, this);
+        if (isString(object.getClass())) {
+            nodes.put(object, new ObjectNode(pd.instantiate(object, this)));
+        }
     }
 
-    public void writeStatement(Statement oldStm) {
-        ObjectNode node = nodes.get(oldStm.getTarget());
+    private Object forceNew(Object old) {
+        if (old == null) {
+            return null;
+        }
+        Object nu = get(old);
+        if (nu != null) {
+            return nu;
+        }
+        writeObject(old);
+        return get(old);
+    }
 
-        if (node != null) {
-            try {
-                Statement statement;
-                Object[] oldArgs = oldStm.getArguments();
+    private Object[] forceNewArray(Object oldArray[]) {
+        if (oldArray == null) {
+            return null;
+        }
+        Object newArray[] = new Object[oldArray.length];
+        for (int i = 0; i < oldArray.length; i++) {
+            newArray[i] = forceNew(oldArray[i]);
+        }
+        return newArray;
+    }
 
-                // FIXME add target processing here
-                write(oldArgs);
-                statement = new Statement(node.getObjectValue(), oldStm
-                        .getMethodName(), oldArgs);
-                statement.execute();
-                node.addStatement(statement);
-            } catch (Exception e) {
-                getExceptionListener().exceptionThrown(e);
-            }
-        } else {
-            // FIXME incompatible with RI, default constructor should be
-            // called instead
-            System.out.println(Messages.getString(
-                    "beans.10", oldStm.getTarget())); //$NON-NLS-1$
+    public void writeStatement(Statement oldStm) {
+        if (oldStm == null) {
+            throw new NullPointerException();
         }
+        try {
+            // FIXME add target processing here
+            Object newTarget = forceNew(oldStm.getTarget());
+            Object newArgs[] = forceNewArray(oldStm.getArguments());
+            Statement statement = new Statement(newTarget, oldStm
+                    .getMethodName(), newArgs);
+            statement.execute();
+        } catch (Exception e) {
+            getExceptionListener().exceptionThrown(e);
+        }
+    }
+
+    private void put(Object old, Object nu) {
+        oldNewMap.put(old, nu);
     }
 
     public void writeExpression(Expression oldExp) {
+        if (oldExp == null) {
+            throw new NullPointerException();
+        }
         try {
             Object oldValue = oldExp.getValue();
-            Object oldTarget = oldExp.getTarget();
-
-            ObjectNode valueNode = null;
-            Class<?> valueType = null;
-
-            // write target
-            if (!Statement.isPDConstructor(oldExp)
-                    && !Statement.isStaticMethodCall(oldExp)) {
-                ObjectNode parent;
-
-                // XXX investigate
-                // write(oldTarget);
-                parent = nodes.get(oldTarget);
-                if (parent != null) {
-                    parent.addExpression(oldExp);
-                }
+            if (oldValue == null || get(oldValue) != null) {
+                return;
             }
 
-            // write value
+            // copy to newExp
+            Object newTarget = forceNew(oldExp.getTarget());
+            Object newArgs[] = forceNewArray(oldExp.getArguments());
+            Expression newExp = new Expression(newTarget, oldExp
+                    .getMethodName(), newArgs);
 
-            if (oldValue != null) {
-                valueType = oldValue.getClass();
-                valueNode = nodes.get(oldValue);
+            // execute newExp
+            Object newValue = null;
+            try {
+                newValue = newExp.getValue();
+            } catch (IndexOutOfBoundsException ex) {
+                // Current Container does not have any component, newVal set
+                // to null
             }
 
-            if (valueNode == null) {
+            // relate oldValue to newValue
+            put(oldValue, newValue);
 
-                if (isNull(valueType) || isPrimitive(valueType)
-                        || isString(valueType)) {
-                    valueNode = new ObjectNode(oldExp);
-                } else {
-                    write(oldExp.getArguments());
-                    valueNode = new ObjectNode(oldExp, nodes);
-                }
-
-                nodes.put(oldValue, valueNode);
-            } else if (oldExp.getMethodName().equals("new")) { //$NON-NLS-1$
-                valueNode.addReference();
-            } else {
-                // XXX the information about referencedExpressions is not
-                // being used by anyone
-                // node.addReferencedExpression(oldExp);
-            }
+            // force same state
+            writeObject(oldValue);
         } catch (Exception e) {
             // TODO - remove written args
-            e.printStackTrace();
             getExceptionListener().exceptionThrown(e);
         }
     }
 
     public void setExceptionListener(ExceptionListener exceptionListener) {
+        if (exceptionListener == null) {
+            exceptionListener = defaultExListener;
+        }
         this.exceptionListener = exceptionListener;
     }
 
     public ExceptionListener getExceptionListener() {
-        if (exceptionListener == null) {
-            exceptionListener = new ExceptionListener() {
-
-                public void exceptionThrown(Exception e) {
-                    System.out.println(e.getClass() + ": " + e.getMessage()); //$NON-NLS-1$
-                }
-            };
-        }
-
         return exceptionListener;
     }
 
@@ -204,7 +220,7 @@
         return node.getObjectValue();
     }
 
-    private Object[] write(Object[] oldInstances) throws Exception {
+    Object[] write(Object[] oldInstances) throws Exception {
         if (oldInstances != null) {
             Object[] newInstances = new Object[oldInstances.length];
 

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -68,9 +68,7 @@
         if (mutatesTo(oldInstance, newInstance)) {
             initialize(oldInstance.getClass(), oldInstance, newInstance, out);
         } else {
-            if (newInstance != null) {
-                out.remove(newInstance);
-            }
+        	out.remove(oldInstance);
 
             out.writeExpression(instantiate(oldInstance, out));
             newInstance = out.get(oldInstance);

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLEncoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLEncoder.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLEncoder.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLEncoder.java
Thu Jul 12 01:17:23 2007
@@ -53,6 +53,71 @@
     public Object getOwner() {
         return owner;
     }
+    
+    @Override
+    public void writeExpression(Expression oldExp) {
+
+		Object oldValue = null;
+		try {
+			oldValue = oldExp.getValue();
+		} catch (Exception e) {
+			getExceptionListener()
+					.exceptionThrown(
+							new Exception("failed to execute expression: "
+									+ oldExp, e));
+			return;
+		}
+		
+		if (get(oldValue) != null) {
+			return;
+		}
+		
+		Object oldTarget = oldExp.getTarget();
+
+		ObjectNode valueNode = null;
+		Class<?> valueType = null;
+
+		// write target
+		if (!Statement.isPDConstructor(oldExp)
+				&& !Statement.isStaticMethodCall(oldExp)) {
+			ObjectNode parent;
+
+			// XXX investigate
+			// write(oldTarget);
+			parent = nodes.get(oldTarget);
+			if (parent != null) {
+				parent.addExpression(oldExp);
+			}
+		}
+
+		// write value
+		valueType = oldValue.getClass();
+		valueNode = nodes.get(oldValue);
+
+		if (valueNode == null) {
+
+			if (isNull(valueType) || isPrimitive(valueType)
+					|| isString(valueType)) {
+				valueNode = new ObjectNode(oldExp);
+			} else {
+				try {
+					write((Object[])oldExp.getArguments());
+				} catch (Exception e) {
+					getExceptionListener().exceptionThrown(e);
+				}
+				valueNode = new ObjectNode(oldExp, nodes);
+			}
+
+			nodes.put(oldValue, valueNode);
+		} else if (oldExp.getMethodName().equals("new")) { //$NON-NLS-1$
+			valueNode.addReference();
+		} else {
+			// XXX the information about referencedExpressions is not
+			// being used by anyone
+			// node.addReferencedExpression(oldExp);
+		}
+		super.writeExpression(oldExp);
+	}
 
     @Override
     public void writeStatement(Statement oldStm) {
@@ -97,9 +162,9 @@
             if (object != null) {
                 ObjectNode node = nodes.get(object);
 
-                printObjectTag(0, object, node);
+                printObjectTag(1, object, node);
             } else {
-                printNullTag(0);
+                printNullTag(1);
             }
         }
 
@@ -174,7 +239,8 @@
                         tag.addAttr("length", ((Integer) arguments[1]) //$NON-NLS-1$
                                 .toString());
                     } else {
-                        tag.addAttr("class", node.getObjectType().getName()); //$NON-NLS-1$
+                        tag.addAttr("class", ((Class)node.getInitializer().getTarget()).getName());
//$NON-NLS-1$
+                        tag.addAttr("method", node.getInitializer().getMethodName());
                     }
                 } catch (Exception e) {
                     getExceptionListener().exceptionThrown(e);
@@ -389,7 +455,7 @@
             String result = ""; //$NON-NLS-1$
 
             for (int i = 0; i < tabCount; ++i) {
-                result += '\t';
+                result += ' ';
             }
             result = result + s + "\n"; //$NON-NLS-1$
             out.write(result.getBytes("UTF-8")); //$NON-NLS-1$

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/DefaultPersistenceDelegatesFactory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/DefaultPersistenceDelegatesFactory.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/DefaultPersistenceDelegatesFactory.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/DefaultPersistenceDelegatesFactory.java
Thu Jul 12 01:17:23 2007
@@ -25,7 +25,8 @@
 
 public final class DefaultPersistenceDelegatesFactory {
 
-    private static Map<String, PersistenceDelegate> persistenceDelegates = new HashMap<String,
PersistenceDelegate>();
+    private static final DefaultPersistenceDelegate DEFAULT_PERSISTENCE_DELEGATE = new DefaultPersistenceDelegate();
+	private static Map<String, PersistenceDelegate> persistenceDelegates = new HashMap<String,
PersistenceDelegate>();
 
     private static PersistenceDelegate createPersistenceDelegate(Class<?> type) {
         if (type == null) {
@@ -53,7 +54,7 @@
             }
 
             if (pd == null) {
-                pd = new DefaultPersistenceDelegate();
+                pd = DEFAULT_PERSISTENCE_DELEGATE;
             }
         }
         return pd;

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/ObjectNode.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/ObjectNode.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/ObjectNode.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/ObjectNode.java
Thu Jul 12 01:17:23 2007
@@ -19,7 +19,7 @@
 
 import java.beans.Expression;
 import java.beans.Statement;
-import java.util.HashMap;
+import java.util.IdentityHashMap;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Map;
@@ -51,7 +51,7 @@
         this.nodes = null;
     }
 
-    public ObjectNode(Expression initializer, HashMap<Object, ObjectNode> nodes) {
+    public ObjectNode(Expression initializer, IdentityHashMap<Object, ObjectNode> nodes)
{
         this.initializer = initializer;
         this.nodes = nodes;
     }

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_BooleanPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_BooleanPersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_BooleanPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_BooleanPersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -27,7 +27,7 @@
     protected Expression instantiate(Object oldInstance, Encoder out) {
         boolean value = ((Boolean) oldInstance).booleanValue();
         return new Expression(oldInstance, Boolean.class, "new", //$NON-NLS-1$
-                new Object[] { Boolean.valueOf(value) });
+                new Object[] { Boolean.valueOf(value).toString() });
     }
 
     @Override

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_BytePersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_BytePersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_BytePersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_BytePersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -26,7 +26,7 @@
     protected Expression instantiate(Object oldInstance, Encoder out) {
         Byte value = (Byte) oldInstance;
         return new Expression(oldInstance, Byte.class, "new", //$NON-NLS-1$
-                new Object[] { value });
+                new Object[] { value.toString() });
     }
 
     @Override

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_CharacterPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_CharacterPersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_CharacterPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_CharacterPersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -25,9 +25,8 @@
 
     @Override
     protected Expression instantiate(Object oldInstance, Encoder out) {
-        Character value = (Character) oldInstance;
-        return new Expression(oldInstance, Character.class, "new", //$NON-NLS-1$
-                new Object[] { value });
+        return new Expression(oldInstance, oldInstance.toString(),
+                "charAt", new Object[] { new Integer(0) });
     }
 
     @Override

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ClassPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ClassPersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ClassPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ClassPersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -29,6 +29,13 @@
         Field fld = null;
         final String TYPE = "TYPE"; //$NON-NLS-1$
         Expression result;
+        /*
+         * Special treatment to String.class to prevent endless loop of
+         * instantiation.
+         */
+        if (value == String.class) {
+            return new Expression(value, "", "getClass", null);  //$NON-NLS-1$//$NON-NLS-2$
+        }
         try {
             if (value.equals(Integer.TYPE)) {
                 fld = Integer.class.getField(TYPE);
@@ -56,7 +63,7 @@
             // we have primitive type
             result = new Expression(oldInstance, fld, "get", new Object[] { null }); //$NON-NLS-1$
         } else {
-            result = new Expression(oldInstance, Class.class, "forName", //$NON-NLS-1$ 
+            result = new Expression(oldInstance, String.class, "forName", //$NON-NLS-1$ 
                     new Object[] { value.getName() });
         }
         return result;

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_DoublePersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_DoublePersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_DoublePersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_DoublePersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -25,7 +25,7 @@
     @Override
     protected Expression instantiate(Object oldInstance, Encoder out) {
         Double value = (Double) oldInstance;
-        return new Expression(oldInstance, Double.class, "new", new Object[] { value });
//$NON-NLS-1$
+        return new Expression(oldInstance, Double.class, "new", new Object[] { value.toString()
}); //$NON-NLS-1$
     }
 
     @Override

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_FloatPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_FloatPersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_FloatPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_FloatPersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -25,7 +25,7 @@
     @Override
     protected Expression instantiate(Object oldInstance, Encoder out) {
         Float value = (Float) oldInstance;
-        return new Expression(oldInstance, Float.class, "new", new Object[] { value }); //$NON-NLS-1$
+        return new Expression(oldInstance, Float.class, "new", new Object[] { value.toString()
}); //$NON-NLS-1$
     }
 
     @Override

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_IntegerPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_IntegerPersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_IntegerPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_IntegerPersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -25,10 +25,21 @@
     @Override
     protected Expression instantiate(Object oldInstance, Encoder out) {
         Integer value = (Integer) oldInstance;
-        return new Expression(oldInstance, Integer.class, "new", new Object[] { value });
//$NON-NLS-1$
+        return new Expression(oldInstance, Integer.class,
+				"new", new Object[] { value.toString() }); //$NON-NLS-1$
     }
 
     @Override
     protected void initialize(Class<?> type, Object oldInstance, Object newInstance,
Encoder out) {
+    }
+    
+    /*
+     * Two Integer objects are regarded mutatable if they are equal.
+     */
+    protected boolean mutatesTo(Object o1, Object o2) {
+        if (null == o2) {
+            return false;
+        }
+        return o1.equals(o2);
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_LongPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_LongPersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_LongPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_LongPersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -25,7 +25,7 @@
     @Override
     protected Expression instantiate(Object oldInstance, Encoder out) {
         Long value = (Long) oldInstance;
-        return new Expression(oldInstance, Long.class, "new", new Object[] { value }); //$NON-NLS-1$
+        return new Expression(oldInstance, Long.class, "new", new Object[] { value.toString()
}); //$NON-NLS-1$
     }
 
     @Override

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ShortPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ShortPersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ShortPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ShortPersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -25,7 +25,7 @@
     @Override
     protected Expression instantiate(Object oldInstance, Encoder out) {
         Short value = (Short) oldInstance;
-        return new Expression(oldInstance, Short.class, "new", new Object[] { value }); //$NON-NLS-1$
+        return new Expression(oldInstance, Short.class, "new", new Object[] { value.toString()
}); //$NON-NLS-1$
     }
 
     @Override

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_FieldPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_FieldPersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_FieldPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_FieldPersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -32,7 +32,7 @@
         assert oldInstance instanceof Field : oldInstance;
         Field oldField = (Field) oldInstance;
         Class<?> declClass = oldField.getDeclaringClass();
-        return new Expression(oldField, declClass, "getDeclaredField", //$NON-NLS-1$
+        return new Expression(oldField, declClass, "getField", //$NON-NLS-1$
                 new Object[] { oldField.getName() });
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_ProxyPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_ProxyPersistenceDelegate.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_ProxyPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/java_lang_reflect_ProxyPersistenceDelegate.java
Thu Jul 12 01:17:23 2007
@@ -17,13 +17,13 @@
 
 package org.apache.harmony.beans;
 
+import java.beans.DefaultPersistenceDelegate;
 import java.beans.Encoder;
 import java.beans.Expression;
-import java.beans.PersistenceDelegate;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Proxy;
 
-public class java_lang_reflect_ProxyPersistenceDelegate extends PersistenceDelegate {
+public class java_lang_reflect_ProxyPersistenceDelegate extends DefaultPersistenceDelegate
{
     @Override
     protected Expression instantiate(Object oldInstance, Encoder out) {
         assert oldInstance instanceof Proxy : oldInstance;
@@ -39,11 +39,13 @@
         assert oldInstance instanceof Proxy : oldInstance;
         assert newInstance instanceof Proxy : newInstance;
         assert newInstance == oldInstance;
+        super.initialize(type, oldInstance, newInstance, out);
     }
 
     @Override
     protected boolean mutatesTo(Object oldInstance, Object newInstance) {
         assert oldInstance instanceof Proxy : oldInstance;
-        return oldInstance == newInstance;
+        assert oldInstance == newInstance;
+        return super.mutatesTo(oldInstance, newInstance);
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EncoderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EncoderTest.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EncoderTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EncoderTest.java
Thu Jul 12 01:17:23 2007
@@ -381,7 +381,7 @@
         Encoder enc = new Encoder();
         PersistenceDelegate pd = enc
                 .getPersistenceDelegate(MockFooLiYang.class);
-        assertTrue(pd instanceof VerbosePD);
+        assertTrue(pd instanceof DefaultPersistenceDelegate);
     }
 
     public void testGetPersistenceDelegate_Default() {

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java?view=diff&rev=555527&r1=555526&r2=555527
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java
Thu Jul 12 01:17:23 2007
@@ -30,7 +30,14 @@
 import org.apache.harmony.beans.tests.support.mock.MockFoo;
 import org.apache.harmony.beans.tests.support.mock.MockFooStop;
 
-
+import java.beans.XMLEncoder;
+import java.beans.XMLDecoder;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.lang.reflect.Field;
 /**
  * Test java.beans.PersistenceDelegate
  */
@@ -206,7 +213,45 @@
         assertFalse(pd.mutatesTo(null, "test"));
     }
 
-    
+    public void test_writeObject_Null_LXMLEncoder() throws Exception{
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(byteArrayOutputStream));
+        encoder.writeObject(null);
+        encoder.close();
+
+        DataInputStream stream = new DataInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
+        XMLDecoder decoder = new XMLDecoder(stream);
+        assertNull(decoder.readObject());
+        stream = new DataInputStream(PersistenceDelegateTest.class.getResourceAsStream("/xml/null.xml"));
+        decoder = new XMLDecoder(stream);
+        assertNull(decoder.readObject());
+    }
+
+    class Bar {
+        public int value;
+        public void barTalk() {
+            System.out.println("Bar is coming!");
+        }
+    }
+    public void test_writeObject_java_lang_reflect_Field()
+			throws SecurityException, NoSuchFieldException, IOException {
+		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+		XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+				byteArrayOutputStream));
+		Field value = Bar.class.getField("value");
+		encoder.writeObject(value);
+		encoder.close();
+
+		DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+				byteArrayOutputStream.toByteArray()));
+		
+		XMLDecoder decoder = new XMLDecoder(stream); Field field = (Field)
+		decoder.readObject();
+
+        assertEquals(value, field);
+		assertEquals(value.getName(), field.getName());
+	}
+
     // <--
 
     private void assertWasAdded(Class<?> targetClass, String methodName,



Mime
View raw message