axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject cvs commit: xml-axis/java/test/encoding TestDeser.java
Date Thu, 15 Nov 2001 20:31:38 GMT
rubys       01/11/15 12:31:38

  Modified:    java/src/org/apache/axis/encoding
                        SOAPTypeMappingRegistry.java
               java/test/encoding TestDeser.java
  Added:       java/src/org/apache/axis/encoding FloatSerializer.java
  Log:
  I'm tired of seeing these three interop failures on various web pages...
  
  Revision  Changes    Path
  1.48      +8 -5      xml-axis/java/src/org/apache/axis/encoding/SOAPTypeMappingRegistry.java
  
  Index: SOAPTypeMappingRegistry.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SOAPTypeMappingRegistry.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- SOAPTypeMappingRegistry.java	2001/11/07 23:20:15	1.47
  +++ SOAPTypeMappingRegistry.java	2001/11/15 20:31:38	1.48
  @@ -246,8 +246,8 @@
           SOAPEncoding se = new SOAPEncoding();
           addSerializer(java.lang.String.class, XSD_STRING, se);
           addSerializer(java.lang.Boolean.class, XSD_BOOLEAN, se);
  -        addSerializer(java.lang.Double.class, XSD_DOUBLE, se);
  -        addSerializer(java.lang.Float.class, XSD_FLOAT, se);
  +        addSerializer(java.lang.Double.class, XSD_DOUBLE, new FloatSerializer());
  +        addSerializer(java.lang.Float.class, XSD_FLOAT, new FloatSerializer());
           addSerializer(java.lang.Integer.class, XSD_INT, se);
           addSerializer(java.lang.Long.class, XSD_LONG, se);
           addSerializer(java.lang.Short.class, XSD_SHORT, se);
  @@ -258,15 +258,18 @@
           addSerializer(java.math.BigDecimal.class, XSD_DECIMAL, se);
           
           addDeserializersFor(XSD_STRING, java.lang.String.class, factory);    
  -        addDeserializersFor(XSD_DOUBLE, java.lang.Double.class, factory);
  -        addDeserializersFor(XSD_FLOAT, java.lang.Float.class, factory);
           addDeserializersFor(XSD_INT, java.lang.Integer.class, factory);
           addDeserializersFor(XSD_LONG, java.lang.Long.class, factory);
           addDeserializersFor(XSD_SHORT, java.lang.Short.class, factory);
           addDeserializersFor(XSD_BYTE, java.lang.Byte.class, factory);
           addDeserializersFor(XSD_DECIMAL, java.math.BigDecimal.class, factory);
           
  -        addDeserializersFor(XSD_BOOLEAN, java.lang.Boolean.class, new BooleanDeserializerFactory());
  +        addDeserializersFor(XSD_BOOLEAN, java.lang.Boolean.class, 
  +            new BooleanDeserializerFactory());
  +        addDeserializersFor(XSD_FLOAT, java.lang.Float.class, 
  +            new FloatSerializer.FloatDeserializerFactory());
  +        addDeserializersFor(XSD_DOUBLE, java.lang.Double.class, 
  +            new FloatSerializer.FloatDeserializerFactory());
   
           // handle the various datetime QNames...
           addDeserializerFactory(
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/encoding/FloatSerializer.java
  
  Index: FloatSerializer.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.axis.encoding;
  
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  
  import javax.xml.rpc.namespace.QName;
  import java.io.IOException;
  
  /**
   * serializer/deserializerFactory for float
   *
   * @author Sam Ruby <rubys@us.ibm.com>
   * @see <a href="http://www.w3.org/TR/2001/PR-xmlschema-2-20010330/#float">XML Schema
3.2.4</a>
   */
  public class FloatSerializer implements Serializer {
  
      static class FloatDeser extends Deserializer {
          public void characters(char [] chars, int start, int end)
              throws SAXException
          {
              String data = new String(chars, start, end);
  
              if (data.equals("NaN")) {
                  value = new Float(Float.NaN);
              } else if (data.equals("INF")) {
                  value = new Float(Float.POSITIVE_INFINITY);
              } else if (data.equals("-INF")) {
                  value = new Float(Float.NEGATIVE_INFINITY);
              } else { 
                  value = new Float(data);
              }
          }
      }
  
      static class DoubleDeser extends Deserializer {
          public void characters(char [] chars, int start, int end)
              throws SAXException
          {
              String data = new String(chars, start, end);
  
              if (data.equals("NaN")) {
                  value = new Double(Double.NaN);
              } else if (data.equals("INF")) {
                  value = new Double(Double.POSITIVE_INFINITY);
              } else if (data.equals("-INF")) {
                  value = new Double(Double.NEGATIVE_INFINITY);
              } else { 
                  value = new Double(data);
              }
          }
      }
  
      static public class FloatDeserializerFactory
          implements DeserializerFactory 
      {
          public Deserializer getDeserializer(Class cls) {
              if (cls == Float.class) {
                  return new FloatDeser();
              } else {
                  return new DoubleDeser();
              }
          }
      }
  
      /** 
       * Serialize a Float quantity.
       */
      public void serialize(QName name, Attributes attributes,
                            Object value, SerializationContext context)
          throws IOException
      {
          double data = 0.0;
  
          if (value instanceof Float) {
              data = ((Float) value).doubleValue();
          } else {
              data = ((Double) value).doubleValue();
          }
  
          context.startElement(name, attributes);
          if (data == Double.NaN) {
              context.writeString("NaN");
          } else if (data == Double.POSITIVE_INFINITY) {
              context.writeString("INF");
          } else if (data == Double.NEGATIVE_INFINITY) {
              context.writeString("-INF");
          } else {
              context.writeString(value.toString());
          }
          context.endElement();
      }
  }
  
  
  
  1.20      +30 -0     xml-axis/java/test/encoding/TestDeser.java
  
  Index: TestDeser.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/encoding/TestDeser.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- TestDeser.java	2001/11/02 03:07:42	1.19
  +++ TestDeser.java	2001/11/15 20:31:38	1.20
  @@ -131,9 +131,39 @@
                       new Double(3.14));
       }
   
  +    public void testDoubleNaN() throws Exception {
  +        deserialize("<result xsi:type=\"xsd:double\">NaN</result>",
  +                    new Double(Double.NaN));
  +    }
  +
  +    public void testDoubleINF() throws Exception {
  +        deserialize("<result xsi:type=\"xsd:double\">INF</result>",
  +                    new Double(Double.POSITIVE_INFINITY));
  +    }
  +
  +    public void testDoubleNINF() throws Exception {
  +        deserialize("<result xsi:type=\"xsd:double\">-INF</result>",
  +                    new Double(Double.NEGATIVE_INFINITY));
  +    }
  +
       public void testFloat() throws Exception {
           deserialize("<result xsi:type=\"xsd:float\">3.14</result>",
                       new Float(3.14F));
  +    }
  +
  +    public void testFloatNaN() throws Exception {
  +        deserialize("<result xsi:type=\"xsd:float\">NaN</result>",
  +                    new Float(Float.NaN));
  +    }
  +
  +    public void testFloatINF() throws Exception {
  +        deserialize("<result xsi:type=\"xsd:float\">INF</result>",
  +                    new Float(Float.POSITIVE_INFINITY));
  +    }
  +
  +    public void testFloatNINF() throws Exception {
  +        deserialize("<result xsi:type=\"xsd:float\">-INF</result>",
  +                    new Float(Float.NEGATIVE_INFINITY));
       }
   
       public void testInt() throws Exception {
  
  
  

Mime
View raw message