harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r558606 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/Encoder.java main/java/java/beans/UtilDatePersistenceDelegate.java test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java
Date Mon, 23 Jul 2007 05:36:17 GMT
Author: tonywu
Date: Sun Jul 22 22:36:17 2007
New Revision: 558606

URL: http://svn.apache.org/viewvc?view=rev&rev=558606
Log:
Apply patch Harmony-4505 ([classlib][beans] Beans module needs a persistence delegate for
java.util.Date class)

Added:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/UtilDatePersistenceDelegate.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Encoder.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/Encoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Encoder.java?view=diff&rev=558606&r1=558605&r2=558606
==============================================================================
--- 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 Sun
Jul 22 22:36:17 2007
@@ -23,6 +23,7 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.Collection;
+import java.util.Date;
 import java.util.Map;
 import java.util.Hashtable;
 
@@ -109,6 +110,8 @@
         delegates.put(JTabbedPane.class, new SwingJTabbedPanePersistenceDelegate());
         delegates.put(DefaultComboBoxModel.class, new SwingDefaultComboBoxModelPersistenceDelegate());
         delegates.put(ToolTipManager.class, new SwingToolTipManagerPersistenceDelegate());
+        
+        delegates.put(Date.class, new UtilDatePersistenceDelegate());
         
 	}
 

Added: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/UtilDatePersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/UtilDatePersistenceDelegate.java?view=auto&rev=558606
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/UtilDatePersistenceDelegate.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/UtilDatePersistenceDelegate.java
Sun Jul 22 22:36:17 2007
@@ -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;
+
+import java.util.Date;
+
+class UtilDatePersistenceDelegate extends DefaultPersistenceDelegate {
+    protected Expression instantiate(Object oldInstance, Encoder enc) {
+        Date date = (Date) oldInstance;
+        return new Expression(oldInstance, oldInstance.getClass(),
+                Statement.CONSTRUCTOR_NAME, new Object[] { date.getTime() });
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/UtilDatePersistenceDelegate.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=558606&r1=558605&r2=558606
==============================================================================
--- 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
Sun Jul 22 22:36:17 2007
@@ -973,6 +973,75 @@
         assertEquals(manager, aManager);
         assertEquals(manager.getDismissDelay(), aManager.getDismissDelay());
     }
+    
+    public static class DummyBean {
+
+        private String value;
+
+        public DummyBean() {
+        }
+
+        public DummyBean(String s) {
+            value = s;
+        }
+
+        public String getDummyValue() {
+            return value;
+        }
+
+        public void setDummyValue(String s) {
+            value = s;
+        }
+        
+        public boolean equals(Object bean) {
+            if (!(bean instanceof DummyBean)) {
+                return false;
+            }
+            DummyBean aBean = (DummyBean) bean;
+            
+            if (aBean.value == null && value != null || value != null
+                    && aBean.value == null) {
+                return false;
+            } else if(value != null && aBean.value != null){
+                return value.equals(aBean.value);
+            }
+            return true;
+        }
+    }
+    public void test_writeExpression_writeObject() {
+        ByteArrayOutputStream output = new ByteArrayOutputStream();
+        XMLEncoder encoder = new XMLEncoder( output );
+
+        Date date = new Date(2007, 06, 26);
+        Expression expression = new Expression( date, "toString", null );
+        String date_string = null;
+        try {
+                date_string = (String) expression.getValue();
+        } catch (Exception e ) {
+                System.out.println("Failed to get the date value.");
+                e.printStackTrace();
+        }
+        DummyBean bean = new DummyBean( date_string );
+        // The expression knows about the date object.
+        encoder.writeExpression( expression );
+        encoder.writeObject( date );
+        // The value for the bean is already part of the expression
+        // so instead of writing the value we write a reference to
+        // the extpression.
+        encoder.writeObject( bean );
+
+        encoder.flush();
+        encoder.close();
+        
+        DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+                output.toByteArray()));
+        XMLDecoder decoder = new XMLDecoder(stream);
+        Date aDate = (Date) decoder.readObject();
+        assertEquals(date, aDate);
+        
+        DummyBean aBean = (DummyBean) decoder.readObject();
+        assertEquals(bean, aBean);
+    }
 
     // <--
 



Mime
View raw message