harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r1023369 - in /harmony/enhanced/java/branches/mrh: ./ classlib/ classlib/modules/beans/main/ classlib/modules/beans/main/java/ classlib/modules/beans/main/java/java/ classlib/modules/beans/main/java/java/beans/ classlib/modules/beans/src/ma...
Date Sat, 16 Oct 2010 20:05:19 GMT
Author: hindessm
Date: Sat Oct 16 20:05:18 2010
New Revision: 1023369

URL: http://svn.apache.org/viewvc?rev=1023369&view=rev
Log:
Merge changes up to trunk@1022963.

Added:
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/main/
      - copied from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/main/
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/main/java/
      - copied from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/main/java/
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/main/java/java/
      - copied from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/main/java/java/
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/main/java/java/beans/
      - copied from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/main/java/java/beans/
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/main/java/java/beans/UtilCollectionsPersistenceDelegate.java
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/main/java/java/beans/UtilCollectionsPersistenceDelegate.java
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/UtilCollectionsPersistenceDelegate.java
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/UtilCollectionsPersistenceDelegate.java
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockCheckedCollection.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockCheckedCollection.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockCheckedList.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockCheckedList.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockCheckedMap.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockCheckedMap.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockCheckedRandomAccessList.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockCheckedRandomAccessList.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockCheckedSet.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockCheckedSet.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockCheckedSortedMap.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockCheckedSortedMap.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockCheckedSortedSet.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockCheckedSortedSet.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockGetPropertyClass.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockGetPropertyClass.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockListImplements.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockListImplements.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockSetImplements.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockSetImplements.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockSynchronizedCollection.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockSynchronizedCollection.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockSynchronizedList.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockSynchronizedList.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockSynchronizedMap.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockSynchronizedMap.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockSynchronizedRandomAccessList.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockSynchronizedRandomAccessList.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockSynchronizedSet.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockSynchronizedSet.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockSynchronizedSortedMap.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockSynchronizedSortedMap.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockSynchronizedSortedSet.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockSynchronizedSortedSet.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableCollection.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableCollection.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableList.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableList.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableMap.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableMap.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableRandomAccessList.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableRandomAccessList.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableSet.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableSet.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableSortedMap.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableSortedMap.xml
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableSortedSet.xml
      - copied unchanged from r1022963, harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockUnmodifiableSortedSet.xml
Modified:
    harmony/enhanced/java/branches/mrh/   (props changed)
    harmony/enhanced/java/branches/mrh/classlib/   (props changed)
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/Encoder.java
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/XMLDecoder.java
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java
    harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
    harmony/enhanced/java/branches/mrh/common_resources/   (props changed)
    harmony/enhanced/java/branches/mrh/drlvm/   (props changed)

Propchange: harmony/enhanced/java/branches/mrh/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 16 20:05:18 2010
@@ -1,2 +1,2 @@
 /harmony/enhanced/java/branches/mrh:935751
-/harmony/enhanced/java/trunk:935751-1022493
+/harmony/enhanced/java/trunk:935751-1022963

Propchange: harmony/enhanced/java/branches/mrh/classlib/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 16 20:05:18 2010
@@ -1,4 +1,4 @@
 /harmony/enhanced/classlib/trunk:926318-926838
 /harmony/enhanced/java/branches/mrh/classlib:935751
-/harmony/enhanced/java/trunk/classlib:935751-1022493
+/harmony/enhanced/java/trunk/classlib:935751-1022963
 /harmony/enhanced/trunk/classlib:476395-926317

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java?rev=1023369&r1=1023368&r2=1023369&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java Sat Oct 16 20:05:18 2010
@@ -141,10 +141,8 @@ public class DefaultPersistenceDelegate 
                 Object targetVal = enc.get(oldVal);
                 Object newVal = new Expression(newInstance, getter.getName(),
                         null).getValue();
-                boolean invokeSetter = targetVal == null ? (newVal != null && oldVal == null)
-                        : !enc.getPersistenceDelegate(targetVal.getClass())
-                                .mutatesTo(targetVal, newVal);
-                if (invokeSetter) {
+                if (targetVal == null ? (newVal != null && oldVal == null)
+                        : targetVal != newVal && !targetVal.equals(newVal)) {
                     enc.writeStatement(new Statement(oldInstance, setter
                             .getName(), new Object[] { oldVal }));
                 }

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/Encoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/Encoder.java?rev=1023369&r1=1023368&r2=1023369&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/Encoder.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/Encoder.java Sat Oct 16 20:05:18 2010
@@ -71,6 +71,8 @@ public class Encoder {
 
     private static final DefaultPersistenceDelegate defaultPD = new DefaultPersistenceDelegate();
 
+    private static final UtilCollectionsPersistenceDelegate utilCollectionsPD = new UtilCollectionsPersistenceDelegate();
+
     private static final ArrayPersistenceDelegate arrayPD = new ArrayPersistenceDelegate();
 
     private static final ProxyPersistenceDelegate proxyPD = new ProxyPersistenceDelegate();
@@ -136,6 +138,19 @@ public class Encoder {
         delegates.put(ScrollPane.class, new AwtScrollPanePersistenceDelegate());
 
         delegates.put(Date.class, new UtilDatePersistenceDelegate());
+
+        PersistenceDelegate pd = new UtilListPersistenceDelegate();
+        delegates.put(java.util.List.class, pd);
+        delegates.put(java.util.AbstractList.class, pd);
+
+        pd = new UtilCollectionPersistenceDelegate();
+        delegates.put(java.util.Collection.class, pd);
+        delegates.put(java.util.AbstractCollection.class, pd);
+
+        pd = new UtilMapPersistenceDelegate();
+        delegates.put(java.util.Map.class, pd);
+        delegates.put(java.util.AbstractMap.class, pd);
+        delegates.put(java.util.Hashtable.class, pd);
     }
 
     private ExceptionListener listener = defaultExListener;
@@ -221,16 +236,9 @@ public class Encoder {
             return registeredPD;
         }
 
-        if (java.util.List.class.isAssignableFrom(type)) {
-            return new UtilListPersistenceDelegate();
-        }
-
-        if (Collection.class.isAssignableFrom(type)) {
-            return new UtilCollectionPersistenceDelegate();
-        }
-
-        if (Map.class.isAssignableFrom(type)) {
-            return new UtilMapPersistenceDelegate();
+        if (type.getName().startsWith(
+                UtilCollectionsPersistenceDelegate.CLASS_PREFIX)) {
+            return utilCollectionsPD;
         }
 
         if (type.isArray()) {

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/XMLDecoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/XMLDecoder.java?rev=1023369&r1=1023368&r2=1023369&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/XMLDecoder.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/XMLDecoder.java Sat Oct 16 20:05:18 2010
@@ -111,6 +111,7 @@ public class XMLDecoder {
             elem.isExpression = true;
             elem.id = attributes.getValue("id");
             elem.idref = attributes.getValue("idref");
+            elem.attributes = attributes;
             if (elem.idref == null) {
                 obtainTarget(elem, attributes);
                 obtainMethod(elem, attributes);
@@ -201,6 +202,7 @@ public class XMLDecoder {
             Elem elem = new Elem();
             elem.isExpression = true;
             elem.id = attributes.getValue("id"); //$NON-NLS-1$
+            elem.attributes = attributes;
             try {
                 // find component class
                 Class<?> compClass = classForName(attributes.getValue("class")); //$NON-NLS-1$
@@ -230,6 +232,7 @@ public class XMLDecoder {
         private void startVoidElem(Attributes attributes) {
             Elem elem = new Elem();
             elem.id = attributes.getValue("id");
+            elem.attributes = attributes;
             obtainTarget(elem, attributes);
             obtainMethod(elem, attributes);
             readObjs.push(elem);
@@ -242,6 +245,7 @@ public class XMLDecoder {
             elem.isExpression = true;
             elem.id = attributes.getValue("id");
             elem.idref = attributes.getValue("idref");
+            elem.attributes = attributes;
             elem.target = tagName;
             readObjs.push(elem);
         }
@@ -258,6 +262,21 @@ public class XMLDecoder {
             }
             // find the elem to close
             Elem toClose = latestUnclosedElem();
+            if ("string".equals(toClose.target)) {
+                StringBuilder sb = new StringBuilder();
+                for (int index = readObjs.size() - 1; index >= 0; index--) {
+                    Elem elem = (Elem) readObjs.get(index);
+                    if (toClose == elem) {
+                        break;
+                    }
+                    if ("char".equals(elem.target)) {
+                        sb.insert(0, elem.methodName);
+                    }
+                }
+                toClose.methodName = toClose.methodName != null ? toClose.methodName
+                        + sb.toString()
+                        : sb.toString();
+            }
             // make sure it is executed
             execute(toClose);
             // set to closed
@@ -465,6 +484,15 @@ public class XMLDecoder {
             } else if ("byte".equals(tag)) {
                 return Byte.valueOf(value);
             } else if ("char".equals(tag)) {
+                if (value == null && elem.attributes != null) {
+                    String codeAttr = elem.attributes.getValue("code");
+                    if (codeAttr != null) {
+                        Character character = new Character((char) Integer
+                                .valueOf(codeAttr.substring(1), 16).intValue());
+                        elem.methodName = character.toString();
+                        return character;
+                    }
+                }
                 return Character.valueOf(value.charAt(0));
             } else if ("double".equals(tag)) {
                 return Double.valueOf(value);
@@ -522,6 +550,8 @@ public class XMLDecoder {
 
         boolean fromOwner;
 
+        Attributes attributes;
+
         Object result;
 
     }

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java?rev=1023369&r1=1023368&r2=1023369&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java Sat Oct 16 20:05:18 2010
@@ -126,7 +126,7 @@ public class XMLEncoder extends Encoder 
      */
     public void close() {
         flush();
-        out.println("</java>"); //$NON-NLS-1$
+        out.println("</java> "); //$NON-NLS-1$
         out.close();
     }
 
@@ -136,15 +136,6 @@ public class XMLEncoder extends Encoder 
         return buf;
     }
 
-    private String idSerialNoOfObject(Object obj) {
-        Class<?> clazz = obj.getClass();
-        Integer serialNo = (Integer) clazzCounterMap.get(clazz);
-        serialNo = serialNo == null ? 0 : serialNo;
-        String id = BeansUtils.idOfClass(obj.getClass()) + serialNo;
-        clazzCounterMap.put(clazz, ++serialNo);
-        return id;
-    }
-
     /**
      * Writes out all objects since last flush to the output stream.
      * <p>
@@ -157,10 +148,10 @@ public class XMLEncoder extends Encoder 
         synchronized (this) {
             // write xml header
             if (!hasXmlHeader) {
-                out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+                out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?> ");
                 out.println("<java version=\""
                         + System.getProperty("java.version")
-                        + "\" class=\"java.beans.XMLDecoder\">");
+                        + "\" class=\"java.beans.XMLDecoder\"> ");
                 hasXmlHeader = true;
             }
 
@@ -201,7 +192,7 @@ public class XMLEncoder extends Encoder 
         }
         flushIndent(indent);
         if (obj == null) {
-            out.println("<null />");
+            out.println("<null /> ");
         } else if (obj instanceof String) {
             Record rec = objRecordMap.get(obj);
             if (null != rec) {
@@ -211,31 +202,42 @@ public class XMLEncoder extends Encoder 
             }
             out.print("<string>");
             flushString((String) obj);
-            out.println("</string>");
+            out.println("</string> ");
         } else if (obj instanceof Class<?>) {
-            out.println("<class>" + ((Class<?>) obj).getName() + "</class>");
+            out.println("<class>" + ((Class<?>) obj).getName() + "</class> ");
         } else if (obj instanceof Boolean) {
-            out.println("<boolean>" + obj + "</boolean>");
+            out.println("<boolean>" + obj + "</boolean> ");
         } else if (obj instanceof Byte) {
-            out.println("<byte>" + obj + "</byte>");
+            out.println("<byte>" + obj + "</byte> ");
         } else if (obj instanceof Character) {
-            out.println("<char>" + obj + "</char>");
+            char objChar = ((Character) obj).charValue();
+            if (invalidCharacter(objChar)) {
+                out.println("<char code=\"#" + Integer.toString(objChar, 16)
+                        + "\"/>");
+            } else {
+                out.println("<char>" + objChar + "</char> ");
+            }
         } else if (obj instanceof Double) {
-            out.println("<double>" + obj + "</double>");
+            out.println("<double>" + obj + "</double> ");
         } else if (obj instanceof Float) {
-            out.println("<float>" + obj + "</float>");
+            out.println("<float>" + obj + "</float> ");
         } else if (obj instanceof Integer) {
-            out.println("<int>" + obj + "</int>");
+            out.println("<int>" + obj + "</int> ");
         } else if (obj instanceof Long) {
-            out.println("<long>" + obj + "</long>");
+            out.println("<long>" + obj + "</long> ");
         } else if (obj instanceof Short) {
-            out.println("<short>" + obj + "</short>");
+            out.println("<short>" + obj + "</short> ");
         } else {
             getExceptionListener().exceptionThrown(
                     new Exception(Messages.getString("beans.73", obj)));
         }
     }
 
+    private boolean invalidCharacter(char c) {
+        return ((0x0000 <= c && c < 0x0009) || (0x000a < c && c < 0x000d)
+                || (0x000d < c && c < 0x0020) || (0xd7ff < c && c < 0xe000) || c == 0xfffe);
+    }
+
     @SuppressWarnings("nls")
     private void flushExpression(Object obj, Record rec, int indent,
             boolean asStatement) {
@@ -253,7 +255,7 @@ public class XMLEncoder extends Encoder 
             flushIndent(indent);
             out.print("<object idref=\"");
             out.print(rec.id);
-            out.println("\" />");
+            out.println("\"/> ");
             return;
         }
 
@@ -313,10 +315,10 @@ public class XMLEncoder extends Encoder 
 
         // open tag, end
         if (rec.exp.getArguments().length == 0 && rec.stats.isEmpty()) {
-            out.println("/>");
+            out.println("/> ");
             return;
         }
-        out.println(">");
+        out.println("> ");
 
         // arguments
         for (int i = 0; i < rec.exp.getArguments().length; i++) {
@@ -330,7 +332,7 @@ public class XMLEncoder extends Encoder 
         flushIndent(indent);
         out.print("</");
         out.print(tagName);
-        out.println(">");
+        out.println("> ");
     }
 
     @SuppressWarnings("nls")
@@ -356,17 +358,17 @@ public class XMLEncoder extends Encoder 
 
         // open tag, end
         if (subStats.isEmpty()) {
-            out.println("/>");
+            out.println("/> ");
             return;
         }
-        out.println(">");
+        out.println("> ");
 
         // sub statements
         flushSubStatements(subStats, indent);
 
         // close tag
         flushIndent(indent);
-        out.println("</array>");
+        out.println("</array> ");
     }
 
     @SuppressWarnings("nls")
@@ -401,10 +403,10 @@ public class XMLEncoder extends Encoder 
 
         // open tag, end
         if (stat.getArguments().length == 0 && subStats.isEmpty()) {
-            out.println("/>");
+            out.println("/> ");
             return;
         }
-        out.println(">");
+        out.println("> ");
 
         // arguments
         for (int i = 0; i < stat.getArguments().length; i++) {
@@ -418,7 +420,7 @@ public class XMLEncoder extends Encoder 
         flushIndent(indent);
         out.print("</");
         out.print(tagName);
-        out.println(">");
+        out.println("> ");
     }
 
     @SuppressWarnings("nls")
@@ -484,15 +486,15 @@ public class XMLEncoder extends Encoder 
             out.print(" field=\"");
             out.print(stat.getArguments()[0]);
             out.print("\"");
-            out.println("/>");
+            out.println("/> ");
         } else {
             out.print(" method=\"");
             out.print(stat.getMethodName());
             out.print("\"");
-            out.println(">");
+            out.println("> ");
             flushObject(stat.getArguments()[0], indent + INDENT_UNIT);
             flushIndent(indent);
-            out.println("</object>");
+            out.println("</object> ");
         }
     }
 
@@ -501,7 +503,7 @@ public class XMLEncoder extends Encoder 
             List<?> subStats, int indent) {
         // open tag, begin
         flushIndent(indent);
-        String tagName = stat instanceof Expression ? "object" : "void";
+        String tagName = "void";
         out.print("<");
         out.print(tagName);
 
@@ -526,10 +528,10 @@ public class XMLEncoder extends Encoder 
 
         // open tag, end
         if (stat.getArguments().length == 0 && subStats.isEmpty()) {
-            out.println("/>");
+            out.println("/> ");
             return;
         }
-        out.println(">");
+        out.println("> ");
 
         // arguments
         for (int i = 0; i < stat.getArguments().length; i++) {
@@ -543,7 +545,7 @@ public class XMLEncoder extends Encoder 
         flushIndent(indent);
         out.print("</");
         out.print(tagName);
-        out.println(">");
+        out.println("> ");
     }
 
     @SuppressWarnings("nls")
@@ -576,10 +578,10 @@ public class XMLEncoder extends Encoder 
 
         // open tag, end
         if (stat.getArguments().length == 1 && subStats.isEmpty()) {
-            out.println("/>");
+            out.println("/> ");
             return;
         }
-        out.println(">");
+        out.println("> ");
 
         // arguments
         for (int i = 1; i < stat.getArguments().length; i++) {
@@ -593,7 +595,7 @@ public class XMLEncoder extends Encoder 
         flushIndent(indent);
         out.print("</");
         out.print(tagName);
-        out.println(">");
+        out.println("> ");
     }
 
     @SuppressWarnings("nls")
@@ -612,7 +614,12 @@ public class XMLEncoder extends Encoder 
             } else if (c == '"') {
                 out.print("&quot;");
             } else {
-                out.print(c);
+                if (invalidCharacter(c)) {
+                    out.print("<char code=\"#" + Integer.toString(c, 16)
+                            + "\"/>");
+                } else {
+                    out.print(c);
+                }
             }
         }
     }
@@ -673,6 +680,15 @@ public class XMLEncoder extends Encoder 
         return (method.startsWith(BeansUtils.SET) && method.length() > 3 && args.length == 1);
     }
 
+    private String idSerialNoOfObject(Object obj) {
+        Class<?> clazz = obj.getClass();
+        Integer serialNo = (Integer) clazzCounterMap.get(clazz);
+        serialNo = serialNo == null ? 0 : serialNo;
+        String id = BeansUtils.idOfClass(obj.getClass()) + serialNo;
+        clazzCounterMap.put(clazz, ++serialNo);
+        return id;
+    }
+
     /*
      * The preprocess removes unused statements and counts references of every
      * object
@@ -783,17 +799,48 @@ public class XMLEncoder extends Encoder 
             return;
         }
         // deal with 'owner' property
-        if (stat.getTarget() == owner && owner != null) {
+        Object target = stat.getTarget();
+        if (target == owner && owner != null) {
             needOwner = true;
         }
 
         // record how a statement affects the target object
-        Record rec = objRecordMap.get(stat.getTarget());
+        Record rec = objRecordMap.get(target);
         if (rec == null) {
             rec = new Record();
-            objRecordMap.put(stat.getTarget(), rec);
+            objRecordMap.put(target, rec);
+        }
+
+        boolean hasRecord = false;
+        String methodName = stat.getMethodName();
+        Object[] args = stat.getArguments();
+        if (isSetPropertyStat(methodName, args)
+                || isSetArrayStat(target, methodName, args)) {
+            for (Statement subStat : rec.stats) {
+                if (target == subStat.getTarget()
+                        && methodName.equals(subStat.getMethodName())) {
+                    Object[] subArgs = subStat.getArguments();
+                    if (args.length == subArgs.length) {
+                        boolean equals = true;
+                        for (int index = 0; index < args.length; index++) {
+                            if (getPersistenceDelegate(args[index].getClass())
+                                    .mutatesTo(args[index], subArgs[index])) {
+                                continue;
+                            }
+                            equals = false;
+                            break;
+                        }
+                        if (equals) {
+                            hasRecord = true;
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+        if (!hasRecord) {
+            rec.stats.add(stat);
         }
-        rec.stats.add(stat);
     }
 
     /**

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java?rev=1023369&r1=1023368&r2=1023369&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java Sat Oct 16 20:05:18 2010
@@ -25,6 +25,7 @@ import java.beans.ExceptionListener;
 import java.beans.Expression;
 import java.beans.PersistenceDelegate;
 import java.beans.Statement;
+import java.beans.XMLDecoder;
 import java.beans.XMLEncoder;
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
@@ -35,10 +36,23 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
 import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.SortedSet;
 import java.util.TreeMap;
+import java.util.TreeSet;
 
 import junit.framework.TestCase;
 
@@ -1022,4 +1036,883 @@ public class XMLEncoderTest extends Test
             this.name = name;
         }
     }
+
+    public static class MockCharProperty {
+        private char property;
+
+        public char getProperty() {
+            return property;
+        }
+
+        public void setProperty(char property) {
+            this.property = property;
+        }
+
+        public boolean equals(Object obj) {
+            if (obj instanceof MockCharProperty) {
+                return ((MockCharProperty) obj).property == (this.property);
+            }
+            return false;
+        }
+    }
+
+    public void testMockCharProperty() {
+        MockCharProperty expectedObj = new MockCharProperty();
+        MockCharProperty actualObj;
+        ByteArrayOutputStream baos;
+        ByteArrayInputStream bais;
+        XMLEncoder xmlEncoder;
+        XMLDecoder xmlDecoder;
+        char ch;
+        for (int index = 1; index < 65536; index++) {
+            ch = (char) index;
+            if (invalidCharacter(ch)) {
+                expectedObj.setProperty(ch);
+                baos = new ByteArrayOutputStream();
+                xmlEncoder = new XMLEncoder(baos);
+                xmlEncoder.writeObject(expectedObj);
+                xmlEncoder.close();
+                assertTrue(baos.toString().contains("<char code=\"#"));
+
+                bais = new ByteArrayInputStream(baos.toByteArray());
+                xmlDecoder = new XMLDecoder(bais);
+                actualObj = (MockCharProperty) xmlDecoder.readObject();
+                xmlDecoder.close();
+                assertEquals(expectedObj, actualObj);
+            }
+        }
+    }
+
+    public static class MockStringProperty {
+        private String property;
+
+        public String getProperty() {
+            return property;
+        }
+
+        public void setProperty(String property) {
+            this.property = property;
+        }
+
+        public boolean equals(Object obj) {
+            if (obj instanceof MockStringProperty) {
+                return ((MockStringProperty) obj).property
+                        .equals(this.property);
+            }
+            return false;
+        }
+    }
+
+    public void testMockStringProperty() {
+        MockStringProperty expectedObj = new MockStringProperty();
+        MockStringProperty actualObj;
+        ByteArrayOutputStream baos;
+        ByteArrayInputStream bais;
+        XMLEncoder xmlEncoder;
+        XMLDecoder xmlDecoder;
+        char ch;
+        for (int index = 0; index < 65536; index++) {
+            ch = (char) index;
+            if (invalidCharacter(ch)) {
+                expectedObj.setProperty(stringWithChar(ch));
+                baos = new ByteArrayOutputStream();
+                xmlEncoder = new XMLEncoder(baos);
+                xmlEncoder.writeObject(expectedObj);
+                xmlEncoder.close();
+                assertTrue(baos.toString().contains("<char code=\"#"));
+
+                bais = new ByteArrayInputStream(baos.toByteArray());
+                xmlDecoder = new XMLDecoder(bais);
+                actualObj = (MockStringProperty) xmlDecoder.readObject();
+                xmlDecoder.close();
+                assertEquals(expectedObj, actualObj);
+            }
+        }
+    }
+
+    private String stringWithChar(char character) {
+        return "a string with a " + character + " character";
+    }
+
+    private boolean invalidCharacter(char c) {
+        return ((0x0000 <= c && c < 0x0009) || (0x000a < c && c < 0x000d)
+                || (0x000d < c && c < 0x0020) || (0xd7ff < c && c < 0xe000) || c == 0xfffe);
+    }
+
+    public static class MockUnmodifiableCollection {
+
+        private Collection<String> property = new ArrayList<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.unmodifiableCollection(property);
+        }
+
+        public void setProperty(Collection<String> set) {
+            property.clear();
+            property.addAll(set);
+        }
+    }
+
+    public void testWriteObject_MockUnmodifiableCollection() throws Exception {
+        MockUnmodifiableCollection mockCollections = new MockUnmodifiableCollection();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$UnmodifiableCollection",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections, "/xml/MockUnmodifiableCollection.xml");
+    }
+
+    public static class MockUnmodifiableList {
+
+        private List<String> property = new LinkedList<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.unmodifiableList(property);
+        }
+
+        public void setProperty(Collection<String> set) {
+            property.clear();
+            property.addAll(set);
+        }
+    }
+
+    public void testWriteObject_MockUnmodifiableList() throws Exception {
+        MockUnmodifiableList mockCollections = new MockUnmodifiableList();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$UnmodifiableList",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections, "/xml/MockUnmodifiableList.xml");
+    }
+
+    public static class MockUnmodifiableRandomAccessList {
+
+        private List<String> property = new ArrayList<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.unmodifiableList(property);
+        }
+
+        public void setProperty(Collection<String> set) {
+            property.clear();
+            property.addAll(set);
+        }
+    }
+
+    public void testWriteObject_MockUnmodifiableRandomAccessList()
+            throws Exception {
+        MockUnmodifiableRandomAccessList mockCollections = new MockUnmodifiableRandomAccessList();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$UnmodifiableRandomAccessList",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections,
+                "/xml/MockUnmodifiableRandomAccessList.xml");
+    }
+
+    public static class MockUnmodifiableSet {
+
+        private Set<String> property = new HashSet<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.unmodifiableSet(property);
+        }
+
+        public void setProperty(Collection<String> set) {
+            property.clear();
+            property.addAll(set);
+        }
+    }
+
+    public void testWriteObject_MockUnmodifiableSet() throws Exception {
+        MockUnmodifiableSet mockCollections = new MockUnmodifiableSet();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$UnmodifiableSet",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        Set<String> prop = new HashSet<String>();
+        prop.add("A");
+        prop.add("B");
+        prop.add("C");
+        mockCollections.setProperty(prop);
+        assertCodedXML(mockCollections, "/xml/MockUnmodifiableSet.xml");
+    }
+
+    public static class MockUnmodifiableSortedSet {
+
+        private SortedSet<String> property = new TreeSet<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.unmodifiableSortedSet(property);
+        }
+
+        public void setProperty(Collection<String> set) {
+            property.clear();
+            property.addAll(set);
+        }
+    }
+
+    public void testWriteObject_MockUnmodifiableSortedSet() throws Exception {
+        MockUnmodifiableSortedSet mockCollections = new MockUnmodifiableSortedSet();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$UnmodifiableSortedSet",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        Set<String> prop = new HashSet<String>();
+        prop.add("A");
+        prop.add("B");
+        prop.add("C");
+        mockCollections.setProperty(prop);
+        assertCodedXML(mockCollections, "/xml/MockUnmodifiableSortedSet.xml");
+    }
+
+    public static class MockUnmodifiableMap {
+
+        private Map<String, String> property = new HashMap<String, String>();
+
+        public Map<String, String> getProperty() {
+            return Collections.unmodifiableMap(property);
+        }
+
+        public void setProperty(Map<String, String> prop) {
+            property.clear();
+            property.putAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockUnmodifiableMap() throws Exception {
+        MockUnmodifiableMap mockCollections = new MockUnmodifiableMap();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$UnmodifiableMap",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        Map<String, String> prop = new HashMap<String, String>();
+        prop.put("A", "a");
+        prop.put("B", "b");
+        prop.put("C", "c");
+        mockCollections.setProperty(prop);
+        assertCodedXML(mockCollections, "/xml/MockUnmodifiableMap.xml");
+    }
+
+    public static class MockUnmodifiableSortedMap {
+
+        private SortedMap<String, String> property = new TreeMap<String, String>();
+
+        public Map<String, String> getProperty() {
+            return Collections.unmodifiableSortedMap(property);
+        }
+
+        public void setProperty(Map<String, String> prop) {
+            property.clear();
+            property.putAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockUnmodifiableSortedMap() throws Exception {
+        MockUnmodifiableSortedMap mockCollections = new MockUnmodifiableSortedMap();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$UnmodifiableSortedMap",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        Map<String, String> prop = new HashMap<String, String>();
+        prop.put("A", "a");
+        prop.put("B", "b");
+        prop.put("C", "c");
+        mockCollections.setProperty(prop);
+        assertCodedXML(mockCollections, "/xml/MockUnmodifiableSortedMap.xml");
+    }
+
+    public static class MockSynchronizedCollection {
+
+        private Collection<String> property = new ArrayList<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.synchronizedCollection(property);
+        }
+
+        public void setProperty(Collection<String> prop) {
+            property.clear();
+            property.addAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockSynchronizedCollection() throws Exception {
+        MockSynchronizedCollection mockCollections = new MockSynchronizedCollection();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$SynchronizedCollection",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections, "/xml/MockSynchronizedCollection.xml");
+    }
+
+    public static class MockSynchronizedList {
+
+        private List<String> property = new LinkedList<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.synchronizedList(property);
+        }
+
+        public void setProperty(Collection<String> prop) {
+            property.clear();
+            property.addAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockSynchronizedList() throws Exception {
+        MockSynchronizedList mockCollections = new MockSynchronizedList();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$SynchronizedList",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections, "/xml/MockSynchronizedList.xml");
+    }
+
+    public static class MockSynchronizedRandomAccessList {
+
+        private List<String> property = new ArrayList<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.synchronizedList(property);
+        }
+
+        public void setProperty(Collection<String> prop) {
+            property.clear();
+            property.addAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockSynchronizedRandomAccessList()
+            throws Exception {
+        MockSynchronizedRandomAccessList mockCollections = new MockSynchronizedRandomAccessList();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$SynchronizedRandomAccessList",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections,
+                "/xml/MockSynchronizedRandomAccessList.xml");
+    }
+
+    public static class MockSynchronizedSet {
+
+        private Set<String> property = new HashSet<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.synchronizedSet(property);
+        }
+
+        public void setProperty(Collection<String> prop) {
+            property.clear();
+            property.addAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockSynchronizedSet() throws Exception {
+        MockSynchronizedSet mockCollections = new MockSynchronizedSet();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$SynchronizedSet",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections, "/xml/MockSynchronizedSet.xml");
+    }
+
+    public static class MockSynchronizedSortedSet {
+
+        private SortedSet<String> property = new TreeSet<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.synchronizedSortedSet(property);
+        }
+
+        public void setProperty(Collection<String> prop) {
+            property.clear();
+            property.addAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockSynchronizedSortedSet() throws Exception {
+        MockSynchronizedSortedSet mockCollections = new MockSynchronizedSortedSet();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$SynchronizedSortedSet",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections, "/xml/MockSynchronizedSortedSet.xml");
+    }
+
+    public static class MockSynchronizedMap {
+
+        private Map<String, String> property = new HashMap<String, String>();
+
+        public Map<String, String> getProperty() {
+            return Collections.synchronizedMap(property);
+        }
+
+        public void setProperty(Map<String, String> prop) {
+            property.clear();
+            property.putAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockSynchronizedMap() throws Exception {
+        MockSynchronizedMap mockCollections = new MockSynchronizedMap();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$SynchronizedMap",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        Map<String, String> prop = new HashMap<String, String>();
+        prop.put("A", "a");
+        prop.put("B", "b");
+        prop.put("C", "c");
+        mockCollections.setProperty(prop);
+        assertCodedXML(mockCollections, "/xml/MockSynchronizedMap.xml");
+    }
+
+    public static class MockSynchronizedSortedMap {
+
+        private SortedMap<String, String> property = new TreeMap<String, String>();
+
+        public Map<String, String> getProperty() {
+            return Collections.synchronizedSortedMap(property);
+        }
+
+        public void setProperty(Map<String, String> prop) {
+            property.clear();
+            property.putAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockSynchronizedSortedMap() throws Exception {
+        MockSynchronizedSortedMap mockCollections = new MockSynchronizedSortedMap();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$SynchronizedSortedMap",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        Map<String, String> prop = new HashMap<String, String>();
+        prop.put("A", "a");
+        prop.put("B", "b");
+        prop.put("C", "c");
+        mockCollections.setProperty(prop);
+        assertCodedXML(mockCollections, "/xml/MockSynchronizedSortedMap.xml");
+    }
+
+    public static class MockCheckedCollection {
+
+        private Collection<String> property = new ArrayList<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.checkedCollection(property, String.class);
+        }
+
+        public void setProperty(Collection<String> prop) {
+            property.clear();
+            property.addAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockCheckedCollection() throws Exception {
+        MockCheckedCollection mockCollections = new MockCheckedCollection();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$CheckedCollection",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections, "/xml/MockCheckedCollection.xml");
+    }
+
+    public static class MockCheckedList {
+
+        private List<String> property = new LinkedList<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.checkedList(property, String.class);
+        }
+
+        public void setProperty(Collection<String> prop) {
+            property.clear();
+            property.addAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockCheckedList() throws Exception {
+        MockCheckedList mockCollections = new MockCheckedList();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$CheckedList",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections, "/xml/MockCheckedList.xml");
+    }
+
+    public static class MockCheckedRandomAccessList {
+
+        private List<String> property = new ArrayList<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.checkedList(property, String.class);
+        }
+
+        public void setProperty(Collection<String> prop) {
+            property.clear();
+            property.addAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockCheckedRandomAccessList() throws Exception {
+        MockCheckedRandomAccessList mockCollections = new MockCheckedRandomAccessList();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$CheckedRandomAccessList",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections, "/xml/MockCheckedRandomAccessList.xml");
+    }
+
+    public static class MockCheckedSet {
+
+        private Set<String> property = new HashSet<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.checkedSet(property, String.class);
+        }
+
+        public void setProperty(Collection<String> prop) {
+            property.clear();
+            property.addAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockCheckedSet() throws Exception {
+        MockCheckedSet mockCollections = new MockCheckedSet();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$CheckedSet",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections, "/xml/MockCheckedSet.xml");
+    }
+
+    public static class MockCheckedSortedSet {
+
+        private SortedSet<String> property = new TreeSet<String>();
+
+        public Collection<String> getProperty() {
+            return Collections.checkedSortedSet(property, String.class);
+        }
+
+        public void setProperty(Collection<String> prop) {
+            property.clear();
+            property.addAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockCheckedSortedSet() throws Exception {
+        MockCheckedSortedSet mockCollections = new MockCheckedSortedSet();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$CheckedSortedSet",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        mockCollections.setProperty(Arrays
+                .asList(new String[] { "A", "B", "C" }));
+        assertCodedXML(mockCollections, "/xml/MockCheckedSortedSet.xml");
+    }
+
+    public static class MockCheckedMap {
+
+        private Map<String, String> property = new HashMap<String, String>();
+
+        public Map<String, String> getProperty() {
+            return Collections.checkedMap(property, String.class, String.class);
+        }
+
+        public void setProperty(Map<String, String> prop) {
+            property.clear();
+            property.putAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockCheckedMap() throws Exception {
+        MockCheckedMap mockCollections = new MockCheckedMap();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$CheckedMap",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        Map<String, String> prop = new HashMap<String, String>();
+        prop.put("A", "a");
+        prop.put("B", "b");
+        prop.put("C", "c");
+        mockCollections.setProperty(prop);
+        assertCodedXML(mockCollections, "/xml/MockCheckedMap.xml");
+    }
+
+    public static class MockCheckedSortedMap {
+
+        private SortedMap<String, String> property = new TreeMap<String, String>();
+
+        public Map<String, String> getProperty() {
+            return Collections.checkedSortedMap(property, String.class,
+                    String.class);
+        }
+
+        public void setProperty(Map<String, String> prop) {
+            property.clear();
+            property.putAll(prop);
+        }
+    }
+
+    public void testWriteObject_MockCheckedSortedMap() throws Exception {
+        MockCheckedSortedMap mockCollections = new MockCheckedSortedMap();
+        Class<?> propertyClass = mockCollections.getProperty().getClass();
+        assertEquals("java.util.Collections$CheckedSortedMap",
+                propertyClass.getName());
+        assertSamePD(propertyClass);
+        Map<String, String> prop = new HashMap<String, String>();
+        prop.put("A", "a");
+        prop.put("B", "b");
+        prop.put("C", "c");
+        mockCollections.setProperty(prop);
+        assertCodedXML(mockCollections, "/xml/MockCheckedSortedMap.xml");
+    }
+
+    public static class MockGetPropertyClass {
+
+        private Set<String> property = new HashSet<String>();
+
+        public Set<String> getProperty() {
+            return new HashSet<String>(property);
+        }
+
+        public void setProperty(Set<String> set) {
+            property.clear();
+            property.addAll(set);
+        }
+    }
+
+    public void testWriteObject_MockGetPropertyClass() throws Exception {
+        MockGetPropertyClass mockCollections = new MockGetPropertyClass();
+        assertSamePD(mockCollections.getProperty().getClass());
+        Set<String> prop = new HashSet<String>();
+        prop.add("A");
+        prop.add("B");
+        prop.add("C");
+        mockCollections.setProperty(prop);
+        assertCodedXML(mockCollections, "/xml/MockGetPropertyClass.xml");
+    }
+
+    public static class MockListImplements implements List<String> {
+
+        private List<String> property = new ArrayList<String>();
+
+        public List<String> getProperty() {
+            return property;
+        }
+
+        public void setProperty(List<String> prop) {
+            property = prop;
+        }
+
+        public boolean add(String o) {
+            return property.add(o);
+        }
+
+        public void add(int index, String o) {
+            property.add(index, o);
+        }
+
+        public boolean addAll(Collection<? extends String> c) {
+            return property.addAll(c);
+        }
+
+        public boolean addAll(int index, Collection<? extends String> c) {
+            return property.addAll(index, c);
+        }
+
+        public void clear() {
+            property.clear();
+        }
+
+        public boolean contains(Object o) {
+            return property.contains(o);
+        }
+
+        public boolean containsAll(Collection<?> c) {
+            return property.containsAll(c);
+        }
+
+        public String get(int index) {
+            return property.get(index);
+        }
+
+        public int indexOf(Object o) {
+            return property.indexOf(o);
+        }
+
+        public boolean isEmpty() {
+            return property.isEmpty();
+        }
+
+        public Iterator<String> iterator() {
+            return property.iterator();
+        }
+
+        public int lastIndexOf(Object o) {
+            return property.lastIndexOf(o);
+        }
+
+        public ListIterator<String> listIterator() {
+            return property.listIterator();
+        }
+
+        public ListIterator<String> listIterator(int index) {
+            return property.listIterator(index);
+        }
+
+        public boolean remove(Object o) {
+            return property.remove(o);
+        }
+
+        public String remove(int index) {
+            return property.remove(index);
+        }
+
+        public boolean removeAll(Collection<?> c) {
+            return property.removeAll(c);
+        }
+
+        public boolean retainAll(Collection<?> c) {
+            return property.retainAll(c);
+        }
+
+        public String set(int index, String o) {
+            return property.set(index, o);
+        }
+
+        public int size() {
+            return property.size();
+        }
+
+        public List<String> subList(int fromIndex, int toIndex) {
+            return property.subList(fromIndex, toIndex);
+        }
+
+        public Object[] toArray() {
+            return property.toArray();
+        }
+
+        public <T> T[] toArray(T[] a) {
+            return property.toArray(a);
+        }
+    }
+
+    public void testWriteObject_MockListImplements() throws Exception {
+        List<String> mockListImplements = new MockListImplements();
+        mockListImplements.add("A");
+        assertCodedXML(mockListImplements, "/xml/MockListImplements.xml");
+    }
+
+    public static class MockSetImplements implements Set<String> {
+
+        private Set<String> property;
+
+        public MockSetImplements() {
+            property = new HashSet<String>();
+        }
+
+        public Set<String> getProperty() {
+            return property;
+        }
+
+        public void setProperty(Set<String> prop) {
+            property = prop;
+        }
+
+        public boolean add(String o) {
+            return property.add(o);
+        }
+
+        public void clear() {
+            property.clear();
+        }
+
+        public boolean contains(final Object o) {
+            return property.contains(o);
+        }
+
+        public boolean containsAll(final Collection<?> c) {
+            return property.containsAll(c);
+        }
+
+        public boolean isEmpty() {
+            return property.isEmpty();
+        }
+
+        public Iterator<String> iterator() {
+            return property.iterator();
+        }
+
+        public boolean remove(final Object o) {
+            return property.remove(o);
+        }
+
+        public boolean removeAll(final Collection<?> c) {
+            return property.removeAll(c);
+        }
+
+        public boolean retainAll(final Collection<?> c) {
+            return property.retainAll(c);
+        }
+
+        public int size() {
+            return property.size();
+        }
+
+        public Object[] toArray() {
+            return property.toArray();
+        }
+
+        public <T> T[] toArray(final T[] a) {
+            return property.toArray(a);
+        }
+
+        public int hashCode() {
+            return property.hashCode();
+        }
+
+        public boolean addAll(Collection<? extends String> c) {
+            return property.addAll(c);
+        }
+    }
+
+    public void testWriteObject_MockSetImplements() throws Exception {
+        Set<String> mockSetImplements = new MockSetImplements();
+        mockSetImplements.add("A");
+        assertCodedXML(mockSetImplements, "/xml/MockSetImplements.xml");
+    }
+
+    private Encoder encoder = new Encoder();
+
+    private void assertSamePD(Class<?> clazz) {
+        assertSame(encoder.getPersistenceDelegate(clazz),
+                encoder.getPersistenceDelegate(clazz));
+    }
+
 }
\ No newline at end of file

Propchange: harmony/enhanced/java/branches/mrh/common_resources/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 16 20:05:18 2010
@@ -1,4 +1,4 @@
 /harmony/enhanced/java/branches/mrh/common_resources:935751
-/harmony/enhanced/java/trunk/common_resources:935751-1022493
+/harmony/enhanced/java/trunk/common_resources:935751-1022963
 /harmony/enhanced/trunk/common_resources:476395-921782
 /incubator/harmony/enhanced/trunk/common_resources:292550-476394

Propchange: harmony/enhanced/java/branches/mrh/drlvm/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 16 20:05:18 2010
@@ -1,5 +1,5 @@
 /harmony/enhanced/java/branches/mrh/drlvm:935751
-/harmony/enhanced/java/trunk/drlvm:935751-1022493
+/harmony/enhanced/java/trunk/drlvm:935751-1022963
 /harmony/enhanced/trunk/drlvm:476395-926313
 /harmony/enhanced/trunk/working_vm:476396-920147
 /incubator/harmony/enhanced/trunk/working_vm:423974-476394



Mime
View raw message