You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/11/23 00:45:09 UTC

svn commit: r478387 - /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/xml/XMLDecoder.java

Author: aadamchik
Date: Wed Nov 22 15:45:09 2006
New Revision: 478387

URL: http://svn.apache.org/viewvc?view=rev&rev=478387
Log:
CAY-710: XMLDecoder decodes Dates wrong
(patch similar to the one submitted by Adrian, but refactored the code a bit)

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/xml/XMLDecoder.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/xml/XMLDecoder.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/xml/XMLDecoder.java?view=diff&rev=478387&r1=478386&r2=478387
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/xml/XMLDecoder.java (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/xml/XMLDecoder.java Wed Nov 22 15:45:09 2006
@@ -22,8 +22,10 @@
 
 import java.io.Reader;
 import java.lang.reflect.Constructor;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -231,40 +233,27 @@
 
                 return ret;
             }
+            
+            String text = XMLUtil.getText(child);
 
-            // If we hit here, then we should be encoding "simple" properties, which are
-            // basically
-            // objects that take a single arg String constructor.
+            // handle dates using hardcoded format....
+            if (Date.class.isAssignableFrom(objectClass)) {
+                return new SimpleDateFormat("E MMM dd hh:mm:ss z yyyy").parse(text);
+            }
+
+            // handle all other primitive types...
             Constructor c = objectClass.getConstructor(new Class[] {
                 String.class
             });
-            if (c != null) {
-                // Create a new object of the type supplied as the "type" attribute
-                // in the XML element that
-                // represents the XML element's text value.
-                // E.g., for <count type="java.lang.Integer">13</count>, this is
-                // equivalent to new Integer("13");
-
-                return c.newInstance(new Object[] {
-                    XMLUtil.getText(child)
-                });
-            }
+            return c.newInstance(new Object[] {
+                text
+            });
         }
         catch (Exception e) {
             throw new CayenneRuntimeException("Error decoding tag '"
                     + child.getNodeName()
                     + "'", e);
         }
-
-        // If we hit here, then we're trying to decode something we're not equipped to
-        // handle.
-        // E.g., a complex object that does not implement XMLSerializable.
-
-        throw new CayenneRuntimeException(
-                "Error decoding tag '"
-                        + child.getNodeName()
-                        + "': "
-                        + "specified class does not have a constructor taking either a String or an XMLDecoder");
     }
 
     /**