cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r762567 - in /cxf/trunk/rt/databinding/aegis/src: main/java/org/apache/cxf/aegis/type/TypeUtil.java main/java/org/apache/cxf/aegis/type/basic/TimezoneLessDateType.java test/java/org/apache/cxf/aegis/type/basic/DateTimezoneTest.java
Date Mon, 06 Apr 2009 23:35:52 GMT
Author: bimargulies
Date: Mon Apr  6 23:35:52 2009
New Revision: 762567

URL: http://svn.apache.org/viewvc?rev=762567&view=rev
Log:
CXF-2130, CXF-2143

Added:
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/DateTimezoneTest.java
  (with props)
Modified:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/TimezoneLessDateType.java

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java?rev=762567&r1=762566&r2=762567&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java Mon
Apr  6 23:35:52 2009
@@ -71,7 +71,7 @@
             }
         
             if (baseType != null) {
-                LOG.info("xsi:type=\"" + overrideName
+                LOG.debug("xsi:type=\"" + overrideName
                          + "\" was specified, but no corresponding Type was registered; defaulting
to "
                          + baseType.getSchemaType());
                 return baseType;

Modified: 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=762567&r1=762566&r2=762567&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/TimezoneLessDateType.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/TimezoneLessDateType.java
Mon Apr  6 23:35:52 2009
@@ -55,8 +55,13 @@
 
     @Override
     public void writeObject(Object object, MessageWriter writer, Context context) {
-        Calendar c = Calendar.getInstance();
-        c.setTime((Date)object);
+        Calendar c;
+        if (object instanceof Calendar) {
+            c = (Calendar) object;
+        } else {
+            c = Calendar.getInstance();
+            c.setTime((Date) object);
+        }
         writer.writeValue(format.format(c));
     }
 }

Added: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/DateTimezoneTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/DateTimezoneTest.java?rev=762567&view=auto
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/DateTimezoneTest.java
(added)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/DateTimezoneTest.java
Mon Apr  6 23:35:52 2009
@@ -0,0 +1,121 @@
+/**
+ * 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.util.Calendar;
+import java.util.Date;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.apache.cxf.aegis.AbstractAegisTest;
+import org.apache.cxf.aegis.AegisContext;
+import org.apache.cxf.aegis.type.TypeMapping;
+import org.apache.cxf.common.util.XMLSchemaQNames;
+import org.junit.Test;
+
+
+
+public class DateTimezoneTest extends AbstractAegisTest {
+
+    TypeMapping mapping;
+    private AegisContext context;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+
+        context = new AegisContext();
+        context.initialize();
+        mapping = context.getTypeMapping();
+    }
+    
+    @Test
+    public void testTimezoneLessCalendar() throws Exception {
+        BeanTypeInfo info = new BeanTypeInfo(CalendarBean.class, "urn:Bean");
+        mapping.register(Calendar.class, XMLSchemaQNames.XSD_DATETIME, new TimezoneLessDateType());
+        mapping.register(Calendar.class, XMLSchemaQNames.XSD_DATE, new TimezoneLessDateType());
       
+        info.setTypeMapping(mapping);
+  
+        BeanType type = new BeanType(info);
+        type.setTypeClass(CalendarBean.class);
+        type.setTypeMapping(mapping);
+        type.setSchemaType(new QName("urn:Bean", "bean"));
+  
+        CalendarBean bean = new CalendarBean();
+        bean.setCalendar(Calendar.getInstance());
+        // Test writing
+        Element element = writeObjectToElement(type, bean, getContext());
+  
+        assertTimezoneLessString(element.getTextContent());
+    }
+    
+    @Test
+    public void testTimezoneLessDate() throws Exception {
+        BeanTypeInfo info = new BeanTypeInfo(DateBean.class, "urn:Bean");
+        mapping.register(Date.class, XMLSchemaQNames.XSD_DATETIME, new TimezoneLessDateType());
+        mapping.register(Date.class, XMLSchemaQNames.XSD_DATE, new TimezoneLessDateType());
       
+        info.setTypeMapping(mapping);
+  
+        BeanType type = new BeanType(info);
+        type.setTypeClass(DateBean.class);
+        type.setTypeMapping(mapping);
+        type.setSchemaType(new QName("urn:Bean", "bean"));
+  
+        DateBean bean = new DateBean();
+        bean.setDate(Calendar.getInstance().getTime());
+        // Test writing
+        Element element = writeObjectToElement(type, bean, getContext());
+        assertTimezoneLessString(element.getTextContent());
+        
+    }
+    
+    private void assertTimezoneLessString(String dateString) {
+        assertTrue(dateString.length() <= 10);
+        assertFalse(dateString.contains("+"));
+        assertFalse(dateString.contains("Z"));
+    }
+    
+    //TODO add tests with Timezones
+    
+    public static class CalendarBean {
+        private Calendar calendar;
+    
+        public Calendar getCalendar() {
+            return calendar;
+        }
+    
+        public void setCalendar(Calendar calendar) {
+            this.calendar = calendar;
+        }
+    }
+    
+    public static class DateBean {
+        private Date date;
+  
+        public Date getDate() {
+            return date;
+        }
+  
+        public void setDate(Date date) {
+            this.date = date;
+        }
+    }    
+}

Propchange: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/DateTimezoneTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/DateTimezoneTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message