Author: bimargulies
Date: Thu Apr 2 00:29:08 2009
New Revision: 761120
URL: http://svn.apache.org/viewvc?rev=761120&view=rev
Log:
CXF-2143.
Added:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/TimezoneLessDateType.java
(with props)
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/TimezoneLessXsDateFormat.java
(with props)
Modified:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateTimeFormat.java
Added:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/TimezoneLessDateType.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/TimezoneLessDateType.java?rev=761120&view=auto
==============================================================================
---
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/TimezoneLessDateType.java
(added)
+++
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/TimezoneLessDateType.java
Thu Apr 2 00:29:08 2009
@@ -0,0 +1,62 @@
+/**
+ * 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 org.apache.cxf.aegis.type.basic;
+
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.util.date.TimezoneLessXsDateFormat;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+
+/**
+ * Type for the Date class which serializes as an xsd:date (no time
+ * and timezone information).
+ *
+ * @author Dennis Kieselhorst
+ *
+ */
+public class TimezoneLessDateType extends DateType {
+ private static TimezoneLessXsDateFormat format = new
TimezoneLessXsDateFormat();
+
+ @Override
+ public Object readObject(MessageReader reader, Context context) throws
DatabindingException {
+ String value = reader.getValue();
+
+ if (value == null) {
+ return null;
+ }
+
+ try {
+ return ((Calendar)format.parseObject(value)).getTime();
+ } catch (ParseException e) {
+ throw new DatabindingException("Could not parse xs:date: " +
e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public void writeObject(Object object, MessageWriter writer, Context
context) {
+ Calendar c = Calendar.getInstance();
+ c.setTime((Date)object);
+ writer.writeValue(format.format(c));
+ }
+}
Propchange:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/TimezoneLessDateType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/TimezoneLessDateType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/TimezoneLessXsDateFormat.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/TimezoneLessXsDateFormat.java?rev=761120&view=auto
==============================================================================
---
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/TimezoneLessXsDateFormat.java
(added)
+++
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/TimezoneLessXsDateFormat.java
Thu Apr 2 00:29:08 2009
@@ -0,0 +1,35 @@
+/**
+ * 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 org.apache.cxf.aegis.util.date;
+
+/**
+ * <p>
+ * An instance of {...@link java.text.Format}, which may be used to parse and
+ * format <code>xs:date</code> values without timezone.
+ * </p>
+ */
+public class TimezoneLessXsDateFormat extends XsDateTimeFormat {
+
+ /**
+ * Creates a new instance.
+ */
+ public TimezoneLessXsDateFormat() {
+ super(true, false, false);
+ }
+}
Propchange:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/TimezoneLessXsDateFormat.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/TimezoneLessXsDateFormat.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateTimeFormat.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateTimeFormat.java?rev=761120&r1=761119&r2=761120&view=diff
==============================================================================
---
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateTimeFormat.java
(original)
+++
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/date/XsDateTimeFormat.java
Thu Apr 2 00:29:08 2009
@@ -40,17 +40,24 @@
final boolean parseDate;
final boolean parseTime;
+
+ final boolean parseTimezone;
XsDateTimeFormat(boolean pParseDate, boolean pParseTime) {
+ this(pParseDate, pParseTime, true);
+ }
+
+ XsDateTimeFormat(boolean pParseDate, boolean pParseTime, boolean
pParseTimezone) {
parseDate = pParseDate;
parseTime = pParseTime;
+ parseTimezone = pParseTimezone;
}
/**
* Creates a new instance.
*/
public XsDateTimeFormat() {
- this(true, true);
+ this(true, true, true);
}
@@ -136,27 +143,29 @@
append(pBuffer, millis, 3);
}
}
- TimeZone tz = cal.getTimeZone();
- // JDK 1.4: int offset = tz.getOffset(cal.getTimeInMillis());
- int offset = cal.get(Calendar.ZONE_OFFSET);
- if (tz.inDaylightTime(cal.getTime())) {
- offset += cal.get(Calendar.DST_OFFSET);
- }
- if (offset == 0) {
- pBuffer.append('Z');
- } else {
- if (offset < 0) {
- pBuffer.append('-');
- offset = -offset;
+ if (parseTimezone) {
+ TimeZone tz = cal.getTimeZone();
+ // JDK 1.4: int offset = tz.getOffset(cal.getTimeInMillis());
+ int offset = cal.get(Calendar.ZONE_OFFSET);
+ if (tz.inDaylightTime(cal.getTime())) {
+ offset += cal.get(Calendar.DST_OFFSET);
+ }
+ if (offset == 0) {
+ pBuffer.append('Z');
} else {
- pBuffer.append('+');
+ if (offset < 0) {
+ pBuffer.append('-');
+ offset = -offset;
+ } else {
+ pBuffer.append('+');
+ }
+ int minutes = offset / (60 * 1000);
+ int hours = minutes / 60;
+ minutes -= hours * 60;
+ append(pBuffer, hours, 2);
+ pBuffer.append(':');
+ append(pBuffer, minutes, 2);
}
- int minutes = offset / (60 * 1000);
- int hours = minutes / 60;
- minutes -= hours * 60;
- append(pBuffer, hours, 2);
- pBuffer.append(':');
- append(pBuffer, minutes, 2);
}
return pBuffer;
}