cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r702663 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ rt/databinding/aegis/src/main...
Date Tue, 07 Oct 2008 23:10:12 GMT
Author: bimargulies
Date: Tue Oct  7 16:10:11 2008
New Revision: 702663

URL: http://svn.apache.org/viewvc?rev=702663&view=rev
Log:
Add byte binding to aegis.

Added:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ByteType.java
  (with props)
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/byteBeans.xml
  (with props)
Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/XMLSchemaQNames.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/AbstractMessageWriter.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/MessageWriter.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/common/common/src/main/java/org/apache/cxf/common/util/XMLSchemaQNames.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/XMLSchemaQNames.java?rev=702663&r1=702662&r2=702663&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/XMLSchemaQNames.java
(original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/XMLSchemaQNames.java
Tue Oct  7 16:10:11 2008
@@ -31,6 +31,7 @@
     public static final QName XSD_DOUBLE = new QName(SOAPConstants.XSD, "double", SOAPConstants.XSD_PREFIX);
     public static final QName XSD_INT = new QName(SOAPConstants.XSD, "int", SOAPConstants.XSD_PREFIX);
     public static final QName XSD_SHORT = new QName(SOAPConstants.XSD, "short", SOAPConstants.XSD_PREFIX);
+    public static final QName XSD_BYTE = new QName(SOAPConstants.XSD, "byte", SOAPConstants.XSD_PREFIX);
     public static final QName XSD_BOOLEAN = new QName(SOAPConstants.XSD,
                                                          "boolean", SOAPConstants.XSD_PREFIX);
     public static final QName XSD_DATETIME = new QName(SOAPConstants.XSD, "dateTime",

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=702663&r1=702662&r2=702663&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 Oct  7 16:10:11 2008
@@ -43,6 +43,7 @@
 import org.apache.cxf.aegis.type.basic.BigDecimalType;
 import org.apache.cxf.aegis.type.basic.BigIntegerType;
 import org.apache.cxf.aegis.type.basic.BooleanType;
+import org.apache.cxf.aegis.type.basic.ByteType;
 import org.apache.cxf.aegis.type.basic.CalendarType;
 import org.apache.cxf.aegis.type.basic.CharacterAsStringType;
 import org.apache.cxf.aegis.type.basic.CharacterType;
@@ -241,6 +242,7 @@
         defaultRegister(tm, defaultNillable, Integer.class, XMLSchemaQNames.XSD_INT, new
IntType());
         defaultRegister(tm, defaultNillable, Long.class, XMLSchemaQNames.XSD_LONG, new LongType());
         defaultRegister(tm, defaultNillable, Object.class, XMLSchemaQNames.XSD_ANY, new ObjectType());
+        defaultRegister(tm, defaultNillable, Byte.class, XMLSchemaQNames.XSD_BYTE, new ByteType());
         defaultRegister(tm, defaultNillable, Short.class, XMLSchemaQNames.XSD_SHORT, new
ShortType());
         defaultRegister(tm, defaultNillable, Source.class, XMLSchemaQNames.XSD_ANY, new SourceType());
         defaultRegister(tm, defaultNillable, String.class, XMLSchemaQNames.XSD_STRING, new
StringType());
@@ -258,6 +260,7 @@
         defaultRegister(tm, defaultNillable, float.class, XMLSchemaQNames.XSD_FLOAT, new
FloatType());
         defaultRegister(tm, defaultNillable, int.class, XMLSchemaQNames.XSD_INT, new IntType());
         defaultRegister(tm, defaultNillable, short.class, XMLSchemaQNames.XSD_SHORT, new
ShortType());
+        defaultRegister(tm, defaultNillable, byte.class, XMLSchemaQNames.XSD_BYTE, new ByteType());
         defaultRegister(tm, defaultNillable, long.class, XMLSchemaQNames.XSD_LONG, new LongType());
 
         defaultRegister(tm, defaultNillable, java.sql.Date.class, XMLSchemaQNames.XSD_DATETIME,

Added: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ByteType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ByteType.java?rev=702663&view=auto
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ByteType.java
(added)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ByteType.java
Tue Oct  7 16:10:11 2008
@@ -0,0 +1,47 @@
+/**
+ * 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.type.Type;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+
+/**
+ * SimpleSerializer
+ * 
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ */
+public class ByteType extends Type {
+    @Override
+    public Object readObject(MessageReader reader, Context context) {
+        return new Byte(reader.getValue());
+    }
+
+    @Override
+    public void writeObject(Object object, MessageWriter writer, Context context) {
+        if (object instanceof Integer) {
+            writer.writeValueAsByte((Byte)object);
+        } else {
+            int intValue = ((Number)object).intValue();
+            byte byteValue = (byte)(intValue & 0xff);
+            writer.writeValueAsByte(new Byte(byteValue));
+        }
+    }
+}

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

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

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/AbstractMessageWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/AbstractMessageWriter.java?rev=702663&r1=702662&r2=702663&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/AbstractMessageWriter.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/AbstractMessageWriter.java
Tue Oct  7 16:10:11 2008
@@ -68,6 +68,10 @@
     public void writeValueAsInt(Integer i) {
         writeValue(i.toString());
     }
+    
+    public void writeValueAsByte(Byte b) {
+        writeValue(b.toString());
+    }
 
     /**
      * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsDouble(java.lang.Double)

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/MessageWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/MessageWriter.java?rev=702663&r1=702662&r2=702663&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/MessageWriter.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/MessageWriter.java
Tue Oct  7 16:10:11 2008
@@ -39,6 +39,8 @@
     void writeValueAsFloat(Float f);
 
     void writeValueAsShort(Short short1);
+    
+    void writeValueAsByte(Byte b);
 
     void writeValueAsBoolean(boolean b);
 

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=702663&r1=702662&r2=702663&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 Oct  7 16:10:11 2008
@@ -32,6 +32,8 @@
     
     private Character character;
     private char primitiveCharacter;
+    private byte littleByte;
+    private Byte bigByte;
 
     public int[] getNumbers() {
         return numbers;
@@ -82,4 +84,20 @@
     public void setPrimitiveChar(char pchar) {
         this.primitiveCharacter = pchar;
     }
+
+    public byte getLittleByte() {
+        return littleByte;
+    }
+
+    public void setLittleByte(byte littleByte) {
+        this.littleByte = littleByte;
+    }
+
+    public Byte getBigByte() {
+        return bigByte;
+    }
+
+    public void setBigByte(Byte bigByte) {
+        this.bigByte = bigByte;
+    }
 }

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=702663&r1=702662&r2=702663&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 Oct  7 16:10:11 2008
@@ -53,6 +53,7 @@
         super.setUp();
     
         addNamespace("b", "urn:Bean");
+        addNamespace("bz", "urn:beanz");
         addNamespace("a", "urn:anotherns");
         addNamespace("xsi", SOAPConstants.XSI_NS);
 
@@ -364,6 +365,66 @@
     }
     
     @Test
+    public void testByteMappings() throws Exception {
+        context = new AegisContext();
+        context.initialize();
+        mapping = context.getTypeMapping();
+
+        BeanType type = (BeanType)mapping.getTypeCreator().createType(SimpleBean.class);
+        type.setTypeClass(SimpleBean.class);
+        type.setTypeMapping(mapping);
+
+        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 typeAttrNode = 
+            assertValid("//xsd:complexType[@name='SimpleBean']/xsd:sequence/xsd:element[@name='littleByte']"
+                       + "/@type", 
+                       schema); 
+        assertEquals(1, typeAttrNode.getLength());
+        Attr typeAttr = (Attr)typeAttrNode.item(0);
+        String typeQnameString = typeAttr.getValue();
+        String[] pieces = typeQnameString.split(":");
+        assertEquals("xsd", pieces[0]);
+        assertEquals("byte", pieces[1]);
+        
+        typeAttrNode = 
+            assertValid("//xsd:complexType[@name='SimpleBean']/xsd:sequence/xsd:element[@name='bigByte']"
+                       + "/@type", 
+                       schema); 
+        assertEquals(1, typeAttrNode.getLength());
+        typeAttr = (Attr)typeAttrNode.item(0);
+        typeQnameString = typeAttr.getValue();
+        pieces = typeQnameString.split(":");
+        assertEquals("xsd", pieces[0]);
+        assertEquals("byte", pieces[1]);
+        
+        Element element = new Element("root", "b", "urn:Bean");
+        new Document(element);
+        SimpleBean bean = new SimpleBean();
+        bean.setBigByte(new Byte((byte)0xfe));
+        bean.setLittleByte((byte)0xfd);
+        type.writeObject(bean, new JDOMWriter(element), getContext());
+        Byte bb = new Byte((byte)0xfe);
+        String bbs = bb.toString();
+        assertValid("/b:root/bz:bigByte[text()='" + bbs + "']", element);
+        
+        // Test reading
+        ElementReader reader = new ElementReader(getResourceAsStream("byteBeans.xml"));
+        bean = (SimpleBean)type.readObject(reader, getContext());
+        assertEquals(-5, bean.getLittleByte());
+        assertEquals(25, bean.getBigByte().byteValue());
+
+        reader.getXMLStreamReader().close();
+
+    }
+    
+    @Test
     public void testNullNonNillableWithDate() throws Exception {
         BeanTypeInfo info = new BeanTypeInfo(DateBean.class, "urn:Bean");
         info.setTypeMapping(mapping);
@@ -397,7 +458,7 @@
         type.setSchemaType(new QName("urn:Bean", "bean"));
 
         PropertyDescriptor[] pds = info.getPropertyDescriptors();
-        assertEquals(6, pds.length);
+        assertEquals(8, pds.length);
 
         ExtendedBean bean = new ExtendedBean();
         bean.setHowdy("howdy");

Added: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/byteBeans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/byteBeans.xml?rev=702663&view=auto
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/byteBeans.xml
(added)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/byteBeans.xml
Tue Oct  7 16:10:11 2008
@@ -0,0 +1,24 @@
+<!--
+  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.
+-->
+<b:bean xmlns:b="urn:Bean" xsi:type="b:SimpleBean"
+   xmlns:beanz="urn:beanz"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <beanz:littleByte>-5</beanz:littleByte>
+  <beanz:bigByte>25</beanz:bigByte>
+</b:bean>
\ No newline at end of file

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

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

Propchange: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/byteBeans.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message