harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Hindess <mark.hind...@googlemail.com>
Subject Re: svn commit: r998763 - 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 Mon, 20 Sep 2010 08:17:29 GMT

Kevin,

You might want to check your svn client is configured to set the
svn:eol-style property for new text files.  See:

  http://wiki.apache.org/harmony/NewCommitter#line-29

I fixed this (and a missing license header) in r998814 and r998823.

Regards,
-Mark.


In message <20100920023230.0A31423889F1@eris.apache.org>, zhoukevin@apache.org 
writes:
>
> Author: zhoukevin
> Date: Mon Sep 20 02:32:29 2010
> New Revision: 998763
> 
> URL: http://svn.apache.org/viewvc?rev=998763&view=rev
> Log:
> When encoding a Enum property in a bean class, if it doesn't set a customized
>  persistence delegate for Enum class thru java.beans.Encoder.setPersistenceDe
> legate(Class, PersistenceDelegate), RI6 encodes this property successfully wh
> ile HARMONY6 fails to encode this property with some exception messages:
> 
> Exception during encoding:java.lang.Exception: failed to write expression: XM
> LEncoderTest$Element=Class.new();
> Continue...
> Exception during encoding:java.lang.Exception: failed to write expression: XM
> LEncoderTest$Element=Class.new();
> Continue...
> 
> By comparison, RI5 performs the same as HARMONY5, which fails to encode this 
> property with the above exceptions. That's why this patch is only committed t
> o HARMONY6 branch to follow the behavior of RI6.
> 
> Added:
>     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/reso
> urces/xml/MockEnumObject.xml
> 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/test/java
> /org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
> 
> Modified: harmony/enhanced/java/branches/java6/classlib/modules/beans/src/mai
> n/java/java/beans/Encoder.java
> URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classl
> ib/modules/beans/src/main/java/java/beans/Encoder.java?rev=998763&r1=998762&r
> 2=998763&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 Mon Sep 20 02:32:29 2010
> @@ -64,7 +64,6 @@ import javax.swing.ToolTipManager;
>   * </p>
>   * 
>   */
> -@SuppressWarnings("unchecked")
>  public class Encoder {
>  
>      private static final Hashtable<Class<?>, PersistenceDelegate> delegates

> = new Hashtable<Class<?>, PersistenceDelegate>();
> @@ -105,6 +104,7 @@ public class Encoder {
>          delegates.put(String.class, new StringPersistenceDelegate());
>          delegates.put(Proxy.class, new ProxyPersistenceDelegate());
>          delegates.put(Date.class, new UtilDatePersistenceDelegate());
> +        delegates.put(Enum.class, new LangEnumPersistenceDelegate());
>      }
>  
>      private ExceptionListener listener = defaultExListener;
> @@ -199,9 +199,10 @@ public class Encoder {
>  			registerSwingPDs();
>  			isInitilizedSwing = true;
>  		}
> -        
> +
>          // registered delegate
> -        PersistenceDelegate registeredPD = delegates.get(type);
> +        PersistenceDelegate registeredPD = Enum.class.isAssignableFrom(type)
>  ? delegates
> +                .get(Enum.class) : delegates.get(type);
>          if (registeredPD != null) {
>              return registeredPD;
>          }
> @@ -423,7 +424,7 @@ public class Encoder {
>          if (o == null) {
>              return;
>          }
> -        Class type = o.getClass();
> +        Class<?> type = o.getClass();
>          getPersistenceDelegate(type).writeObject(o, this);
>      }
>  
> 
> Added: harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/j
> ava/java/beans/LangEnumPersistenceDelegate.java
> URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classl
> ib/modules/beans/src/main/java/java/beans/LangEnumPersistenceDelegate.java?re
> v=998763&view=auto
> =============================================================================
> =
> --- harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java
> /java/beans/LangEnumPersistenceDelegate.java (added)
> +++ harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java
> /java/beans/LangEnumPersistenceDelegate.java Mon Sep 20 02:32:29 2010
> @@ -0,0 +1,28 @@
> +/* 
> + * 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.
> + */
> +package java.beans;
> +
> +class LangEnumPersistenceDelegate extends PersistenceDelegate {
> +
> +    @Override
> +    protected Expression instantiate(Object oldInstance, Encoder enc) {
> +        Enum<?> oldEnum = (Enum<?>) oldInstance;
> +        return new Expression(oldEnum, oldEnum.getClass(), "valueOf",
> +                new Object[] { oldEnum.name() });
> +    }
> +
> +}
> 
> Modified: harmony/enhanced/java/branches/java6/classlib/modules/beans/src/tes
> t/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
> URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classl
> ib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLE
> ncoderTest.java?rev=998763&r1=998762&r2=998763&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 Mon Sep 20 02:
> 32:29 2010
> @@ -59,20 +59,6 @@ import org.xml.sax.helpers.XMLReaderFact
>   */
>  public class XMLEncoderTest extends TestCase {
>  
> -    public static void main(String[] args) {
> -
> -        // VerboseEncoder enc = new VerboseEncoder();
> -        //
> -        // MockBean4Codec b = new MockBean4Codec();
> -        // b.getBornFriend().getZarr()[0] = 888;
> -        // b.setNill(b.getBornFriend());
> -        //
> -        // enc.writeObject(b);
> -        // enc.flush();
> -
> -        junit.textui.TestRunner.run(XMLEncoderTest.class);
> -    }
> -
>      public static class DependencyBean {
>          private int ints[] = new int[] { 1 };
>  
> @@ -120,9 +106,8 @@ public class XMLEncoderTest extends Test
>              return result;
>          }
>  
> -        @SuppressWarnings("unchecked")
>          @Override
> -        public PersistenceDelegate getPersistenceDelegate(Class type) {
> +        public PersistenceDelegate getPersistenceDelegate(Class<?> type) {
>              PersistenceDelegate result = super.getPersistenceDelegate(type);
>              return result;
>          }
> @@ -328,6 +313,7 @@ public class XMLEncoderTest extends Test
>      }
>      */
>  
> +    @SuppressWarnings({ "unchecked", "rawtypes" })
>      public void testWriteObject_MockTreeMap() throws Exception {
>          Map<String, TreeMap<String, String>> innerTreeMap = new MockTreeMapC
> lass();
>          TreeMap resultTreeMap = innerTreeMap.get("outKey");
> @@ -340,6 +326,29 @@ public class XMLEncoderTest extends Test
>          assertEquals(1, innerTreeMap.size());
>      }
>  
> +    public static enum Element {
> +        ELEMENTA, ELEMENTB, ELEMENTC
> +    }
> +
> +    public static class MockEnumObject {
> +
> +        Element element;
> +
> +        public Element getElement() {
> +            return element;
> +        }
> +
> +        public void setElement(Element element) {
> +            this.element = element;
> +        }
> +    }
> +
> +    public void testWriteObject_EnumObject() throws Exception {
> +        MockEnumObject mockEnumObject = new MockEnumObject();
> +        mockEnumObject.setElement(Element.ELEMENTA);
> +        assertCodedXML(mockEnumObject, "/xml/MockEnumObject.xml");
> +    }
> +
>      public void testClose() {
>          ByteArrayOutputStream out = new ByteArrayOutputStream() {
>              boolean closeCalled = false;
> @@ -783,9 +792,8 @@ public class XMLEncoderTest extends Test
>              final Object object = new Object();
>              e.setPersistenceDelegate(AType.class,
>                      new DefaultPersistenceDelegate() {
> -                        @SuppressWarnings("unchecked")
>                          @Override
> -                        protected void initialize(Class type,
> +                        protected void initialize(Class<?> type,
>                                  Object oldInstance, Object newInstance,
>                                  Encoder out) {
>                              out.writeExpression(new Expression(object,
> 
> Added: harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/r
> esources/xml/MockEnumObject.xml
> URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classl
> ib/modules/beans/src/test/resources/xml/MockEnumObject.xml?rev=998763&view=au
> to
> =============================================================================
> =
> --- harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/reso
> urces/xml/MockEnumObject.xml (added)
> +++ harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/reso
> urces/xml/MockEnumObject.xml Mon Sep 20 02:32:29 2010
> @@ -0,0 +1,10 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +<java version="${version}" class="java.beans.XMLDecoder">
> + <object class="${classname}">
> +  <void property="element">
> +   <object class="org.apache.harmony.beans.tests.java.beans.XMLEncoderTest$E
> lement" method="valueOf">
> +    <string>ELEMENTA</string>
> +   </object>
> +  </void>
> + </object>
> +</java>
> \ No newline at end of file
> 



Mime
View raw message