Index: XMLDecoder.java
===================================================================
--- XMLDecoder.java (revision 477840)
+++ XMLDecoder.java (working copy)
@@ -29,6 +29,10 @@
import java.util.List;
import java.util.Map;
+// aw
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
import javax.xml.parsers.DocumentBuilder;
import org.apache.cayenne.CayenneRuntimeException;
@@ -232,23 +236,33 @@
return ret;
}
- // If we hit here, then we should be encoding "simple" properties, which are
- // basically
- // objects that take a single arg String constructor.
- 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 13, this is
- // equivalent to new Integer("13");
-
- return c.newInstance(new Object[] {
- XMLUtil.getText(child)
- });
- }
+ // aw: handle Date with a special constructor
+ // Cayenne does store it in this format: "Mon Nov 06 22:46:30 CET 2006"
+ if(objectClass == Date.class)
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd hh:mm:ss z yyyy");
+ return sdf.parse(XMLUtil.getText(child));
+ }
+ else
+ {
+ // If we hit here, then we should be encoding "simple" properties, which are
+ // basically
+ // objects that take a single arg String constructor.
+ 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 13, this is
+ // equivalent to new Integer("13");
+
+ return c.newInstance(new Object[] {
+ XMLUtil.getText(child)
+ });
+ }
+ }
}
catch (Exception e) {
throw new CayenneRuntimeException("Error decoding tag '"