cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r691338 - in /cxf/trunk/rt/databinding/aegis/src: main/java/org/apache/cxf/aegis/type/ main/java/org/apache/cxf/aegis/type/basic/ test/java/org/apache/cxf/aegis/ test/java/org/apache/cxf/aegis/services/ test/java/org/apache/cxf/aegis/type/b...
Date Tue, 02 Sep 2008 18:15:06 GMT
Author: bimargulies
Date: Tue Sep  2 11:15:05 2008
New Revision: 691338

URL: http://svn.apache.org/viewvc?rev=691338&view=rev
Log:
When not using 'soap encoding', map Character objects to xsd:strings.

Added:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/CharacterAsStringType.java
  (with props)
Modified:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/SimpleBean.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/BeanTest.java

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java?rev=691338&r1=691337&r2=691338&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
Tue Sep  2 11:15:05 2008
@@ -45,6 +45,7 @@
 import org.apache.cxf.aegis.type.basic.BigIntegerType;
 import org.apache.cxf.aegis.type.basic.BooleanType;
 import org.apache.cxf.aegis.type.basic.CalendarType;
+import org.apache.cxf.aegis.type.basic.CharacterAsStringType;
 import org.apache.cxf.aegis.type.basic.CharacterType;
 import org.apache.cxf.aegis.type.basic.DateTimeType;
 import org.apache.cxf.aegis.type.basic.DoubleType;
@@ -230,7 +231,8 @@
                         new BooleanType());
         defaultRegister(tm, defaultNillable, Calendar.class, XMLSchemaQNames.XSD_DATETIME,
                         new CalendarType());
-        defaultRegister(tm, defaultNillable, Character.class, Soap11.ENCODED_CHAR, new CharacterType());
+        defaultRegister(tm, defaultNillable, Character.class, XMLSchemaQNames.XSD_STRING,

+                        new CharacterAsStringType());
         defaultRegister(tm, defaultNillable, Date.class, XMLSchemaQNames.XSD_DATETIME, new
DateTimeType());
         defaultRegister(tm, defaultNillable, Document.class, XMLSchemaQNames.XSD_ANY, new
DocumentType());
         defaultRegister(tm, defaultNillable, Element.class, XMLSchemaQNames.XSD_ANY,

Added: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/CharacterAsStringType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/CharacterAsStringType.java?rev=691338&view=auto
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/CharacterAsStringType.java
(added)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/CharacterAsStringType.java
Tue Sep  2 11:15:05 2008
@@ -0,0 +1,56 @@
+/**
+ * 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 org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+
+/**
+ * 
+ */
+public class CharacterAsStringType extends Type {
+    
+    private StringType stringType;
+    
+    public CharacterAsStringType() {
+        stringType = new StringType();
+    }
+
+    /** {@inheritDoc}*/
+    @Override
+    public Object readObject(MessageReader reader, Context context) throws DatabindingException
{
+        String string = (String)stringType.readObject(reader, context);
+        if (string.length() == 0) {
+            return Character.valueOf((char)0);
+        }
+        return new Character(string.charAt(0));
+    }
+
+    /** {@inheritDoc}*/
+    @Override
+    public void writeObject(Object object, MessageWriter writer, Context context) 
+        throws DatabindingException {
+        Character charObject = (Character) object;
+        stringType.writeObject(charObject.toString(), writer, context);
+    }
+}

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

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

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java?rev=691338&r1=691337&r2=691338&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
Tue Sep  2 11:15:05 2008
@@ -30,6 +30,7 @@
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusException;
@@ -221,10 +222,10 @@
         assertXPathEquals(xpath, value, doc);
     }
     
-    protected void assertValid(String xpath, Element element) throws Exception {
+    protected NodeList assertValid(String xpath, Element element) throws Exception {
         org.w3c.dom.Document doc = new DOMOutputter().output(element.getDocument());
         
-        assertValid(xpath, doc);
+        return assertValid(xpath, doc);
     }
 
     protected void assertInvalid(String xpath, Element element) throws Exception {

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/SimpleBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/SimpleBean.java?rev=691338&r1=691337&r2=691338&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/SimpleBean.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/services/SimpleBean.java
Tue Sep  2 11:15:05 2008
@@ -29,6 +29,8 @@
     private String howdy;
     
     private int[] numbers;
+    
+    private Character character;
 
     public int[] getNumbers() {
         return numbers;
@@ -63,4 +65,12 @@
     public void setHowdy(String howdy) {
         this.howdy = howdy;
     }
+
+    public Character getCharacter() {
+        return character;
+    }
+
+    public void setCharacter(Character character) {
+        this.character = character;
+    }
 }

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/BeanTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/BeanTest.java?rev=691338&r1=691337&r2=691338&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/BeanTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/BeanTest.java
Tue Sep  2 11:15:05 2008
@@ -25,6 +25,9 @@
 
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
 import org.apache.cxf.aegis.AbstractAegisTest;
 import org.apache.cxf.aegis.AegisContext;
 import org.apache.cxf.aegis.Context;
@@ -237,6 +240,33 @@
         assertValid("/b:root[@b2:bleh='bleh']", element);
         assertValid("/b:root[@b2:howdy='howdy']", element);
     }
+    
+    @Test
+    public void testCharStringMapping() throws Exception {
+        BeanTypeInfo info = new BeanTypeInfo(SimpleBean.class, "urn:Bean");
+        info.setTypeMapping(mapping);
+        BeanType type = new BeanType(info);
+        type.setTypeClass(SimpleBean.class);
+        type.setTypeMapping(mapping);
+        type.setSchemaType(new QName("urn:Bean", "bean"));
+        Element types = new Element("types", "xsd", SOAPConstants.XSD);
+        Element schema = new Element("schema", "xsd", SOAPConstants.XSD);
+        types.addContent(schema);
+
+        new Document(types);
+
+        type.writeSchema(schema);
+
+        NodeList charNodes 
+            = assertValid("//xsd:complexType[@name='bean']/xsd:sequence/xsd:element[@name='character']",

+                          schema);
+        Node charNode = charNodes.item(0);
+        org.w3c.dom.Element charElement = (org.w3c.dom.Element)charNode;
+        assertNotNull(charElement);
+        String xsdType = charElement.getAttribute("type");
+        assertEquals("xsd:string", xsdType);
+        
+    }
 
     @Test
     public void testNullProperties() throws Exception {
@@ -363,7 +393,7 @@
         type.setSchemaType(new QName("urn:Bean", "bean"));
 
         PropertyDescriptor[] pds = info.getPropertyDescriptors();
-        assertEquals(4, pds.length);
+        assertEquals(5, pds.length);
 
         ExtendedBean bean = new ExtendedBean();
         bean.setHowdy("howdy");



Mime
View raw message