[seam-commits] Seam SVN: r10611 - in branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting: wrapper and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Apr 23 10:30:16 EDT 2009
Author: manaRH
Date: 2009-04-23 10:30:16 -0400 (Thu, 23 Apr 2009)
New Revision: 10611
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/InterfaceGenerator.java
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/wrapper/DateWrapper.java
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/wrapper/WrapperFactory.java
Log:
JBPAPP-1919
Modified: branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/InterfaceGenerator.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/InterfaceGenerator.java 2009-04-23 13:35:51 UTC (rev 10610)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/InterfaceGenerator.java 2009-04-23 14:30:16 UTC (rev 10611)
@@ -10,6 +10,7 @@
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
@@ -656,7 +657,7 @@
else if (type instanceof Class)
{
Class cls = (Class) type;
- if (Date.class.isAssignableFrom(cls))
+ if (Date.class.isAssignableFrom(cls) || Calendar.class.isAssignableFrom(cls))
return "date";
else if (cls.isArray())
return "bag";
Modified: branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/wrapper/DateWrapper.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/wrapper/DateWrapper.java 2009-04-23 13:35:51 UTC (rev 10610)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/wrapper/DateWrapper.java 2009-04-23 14:30:16 UTC (rev 10611)
@@ -6,55 +6,87 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.Date;
/**
* Handles date conversions
- *
+ *
* @author Shane Bryzak
*/
public class DateWrapper extends BaseWrapper implements Wrapper
{
- private static final byte[] DATE_TAG_OPEN = "<date>".getBytes();
- private static final byte[] DATE_TAG_CLOSE = "</date>".getBytes();
- private static final DateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
-
- public void marshal(OutputStream out) throws IOException
- {
- out.write(DATE_TAG_OPEN);
- out.write(df.format(value).getBytes());
- out.write(DATE_TAG_CLOSE);
- }
-
- public Object convert(Type type)
- throws ConversionException
- {
- if ((type instanceof Class && Date.class.isAssignableFrom((Class) type)) ||
- type.equals(Object.class))
- {
- try {
- value = df.parse(element.getStringValue());
+ private static final byte[] DATE_TAG_OPEN = "<date>".getBytes();
+ private static final byte[] DATE_TAG_CLOSE = "</date>".getBytes();
+
+ private static final String DATE_FORMAT = "yyyyMMddHHmmssSSS";
+
+ private DateFormat getDateFormat()
+ {
+ return new SimpleDateFormat(DATE_FORMAT);
+ }
+
+ public void marshal(OutputStream out) throws IOException
+ {
+ out.write(DATE_TAG_OPEN);
+ if (Date.class.isAssignableFrom(value.getClass()))
+ {
+ out.write(getDateFormat().format(value).getBytes());
}
- catch (ParseException ex) {
- throw new ConversionException(String.format(
- "Date value [%s] is not in a valid format.", element.getStringValue()));
+ else if (Calendar.class.isAssignableFrom(value.getClass()))
+ {
+ out.write(getDateFormat().format(((Calendar) value).getTime()).getBytes());
}
- }
- else
- throw new ConversionException(String.format(
- "Value [%s] cannot be converted to type [%s].", element.getStringValue(),
- type));
-
- return value;
- }
-
- public ConversionScore conversionScore(Class cls)
- {
- if (Date.class.isAssignableFrom(cls))
- return ConversionScore.exact;
- else if (cls.equals(Object.class))
- return ConversionScore.compatible;
- else
- return ConversionScore.nomatch;
- }
+ out.write(DATE_TAG_CLOSE);
+ }
+
+ public Object convert(Type type) throws ConversionException
+ {
+ if ((type instanceof Class && Date.class.isAssignableFrom((Class) type)) || type.equals(Object.class))
+ {
+ try
+ {
+ value = getDateFormat().parse(element.getStringValue());
+ }
+ catch (ParseException ex)
+ {
+ throw new ConversionException(String.format("Date value [%s] is not in a valid format.", element.getStringValue()));
+ }
+ }
+ else if ((type instanceof Class && Calendar.class.isAssignableFrom((Class) type)))
+ {
+ try
+ {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(getDateFormat().parse(element.getStringValue()));
+ value = cal;
+ }
+ catch (ParseException ex)
+ {
+ throw new ConversionException(String.format("Date value [%s] is not in a valid format.", element.getStringValue()));
+ }
+ }
+ else
+ {
+ throw new ConversionException(String.format("Value [%s] cannot be converted to type [%s].", element.getStringValue(), type));
+ }
+
+ return value;
+ }
+
+ public ConversionScore conversionScore(Class cls)
+ {
+ if (Date.class.isAssignableFrom(cls) || Calendar.class.isAssignableFrom(cls))
+ {
+ return ConversionScore.exact;
+ }
+ else if (cls.equals(Object.class))
+ {
+ return ConversionScore.compatible;
+ }
+ else
+ {
+ return ConversionScore.nomatch;
+ }
+ }
}
Modified: branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/wrapper/WrapperFactory.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/wrapper/WrapperFactory.java 2009-04-23 13:35:51 UTC (rev 10610)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/wrapper/WrapperFactory.java 2009-04-23 14:30:16 UTC (rev 10611)
@@ -2,6 +2,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
@@ -106,7 +107,7 @@
w = new BooleanWrapper();
else if (obj.getClass().isEnum())
w = new StringWrapper();
- else if (Date.class.isAssignableFrom(obj.getClass()))
+ else if (Date.class.isAssignableFrom(obj.getClass()) || Calendar.class.isAssignableFrom(obj.getClass()))
w = new DateWrapper();
else if (classRegistry.containsKey(obj.getClass()))
{
More information about the seam-commits
mailing list