harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r1022829 - in /harmony/enhanced/java/branches/java6/classlib/modules/beans/src: main/java/java/beans/ test/java/org/apache/harmony/beans/tests/java/beans/ test/resources/xml/
Date Fri, 15 Oct 2010 06:27:11 GMT
Author: zhoukevin
Date: Fri Oct 15 06:27:11 2010
New Revision: 1022829

URL: http://svn.apache.org/viewvc?rev=1022829&view=rev
Log:
This patch fixes 2 behavior difference and it's only for Java6. 1. No matter whether we set
up specific persistence delegate for enum class, HARMONY should uses the default PD rather
than the given one by Encoder.setPersistenceDelegate(EnumClass, PD). 2. If a object has an
enum property with a default non-null value, and if it's modified to another enum value, HARMONY
should encode this property.

Added:
    harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/resources/xml/Mock2EnumObject.xml
  (with props)
Modified:
    harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/Encoder.java
    harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/LangEnumPersistenceDelegate.java
    harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java

Modified: harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/Encoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/Encoder.java?rev=1022829&r1=1022828&r2=1022829&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/Encoder.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/Encoder.java
Fri Oct 15 06:27:11 2010
@@ -198,16 +198,16 @@ public class Encoder {
             isInitilizedSwing = true;
         }
 
+        if (java.lang.Enum.class.isAssignableFrom(type)) {
+            return langEnumPD;
+        }
+
         // registered delegate
         PersistenceDelegate registeredPD = delegates.get(type);
         if (registeredPD != null) {
             return registeredPD;
         }
 
-        if (java.lang.Enum.class.isAssignableFrom(type)) {
-            return langEnumPD;
-        }
-
         if (java.util.List.class.isAssignableFrom(type)) {
             return new UtilListPersistenceDelegate();
         }

Modified: harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/LangEnumPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/LangEnumPersistenceDelegate.java?rev=1022829&r1=1022828&r2=1022829&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/LangEnumPersistenceDelegate.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/LangEnumPersistenceDelegate.java
Fri Oct 15 06:27:11 2010
@@ -25,4 +25,9 @@ class LangEnumPersistenceDelegate extend
                 new Object[] { oldEnum.name() });
     }
 
+    @Override
+    protected boolean mutatesTo(Object oldObject, Object newObject) {
+        return oldObject == newObject;
+    }
+
 }

Modified: harmony/enhanced/java/branches/java6/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/java6/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java?rev=1022829&r1=1022828&r2=1022829&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
Fri Oct 15 06:27:11 2010
@@ -349,6 +349,33 @@ public class XMLEncoderTest extends Test
         assertCodedXML(mockEnumObject, "/xml/MockEnumObject.xml");
     }
 
+    public static class Mock2EnumObject {
+
+        Element element = Element.ELEMENTA;
+
+        public Element getElement() {
+            return element;
+        }
+
+        public void setElement(Element element) {
+            this.element = element;
+        }
+    }
+
+    public static class ElementPersistenceDelegate extends
+            DefaultPersistenceDelegate {
+    }
+
+    public void testWriteObject_2EnumObject() throws Exception {
+        Mock2EnumObject mockEnumObject = new Mock2EnumObject();
+        Encoder encoder = new Encoder();
+        encoder.setPersistenceDelegate(Element.class,
+                new ElementPersistenceDelegate());
+        assertFalse(encoder.getPersistenceDelegate(Element.class) instanceof ElementPersistenceDelegate);
+        mockEnumObject.setElement(Element.ELEMENTB);
+        assertCodedXML(mockEnumObject, "/xml/Mock2EnumObject.xml");
+    }
+
     public void testClose() {
         ByteArrayOutputStream out = new ByteArrayOutputStream() {
             boolean closeCalled = false;

Added: harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/resources/xml/Mock2EnumObject.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/resources/xml/Mock2EnumObject.xml?rev=1022829&view=auto
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/resources/xml/Mock2EnumObject.xml
(added)
+++ harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/resources/xml/Mock2EnumObject.xml
Fri Oct 15 06:27:11 2010
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<java version="${version}" class="java.beans.XMLDecoder">
+ <object class="${classname}">
+  <void property="element">
+   <object class="org.apache.harmony.beans.tests.java.beans.XMLEncoderTest$Element" method="valueOf">
+    <string>ELEMENTB</string>
+   </object>
+  </void>
+ </object>
+</java>

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/resources/xml/Mock2EnumObject.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message