axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/encoding/ser MapSerializer.java
Date Thu, 08 Jan 2004 17:47:23 GMT
tomj        2004/01/08 09:47:23

  Modified:    java/src/org/apache/axis/encoding/ser MapSerializer.java
  Added:       java/test/wsdl/map build.xml MapService.java
                        MapServiceSoapBindingImpl.java
                        MapServiceTestCase.java
  Log:
  Change the Schema for a Map to use anyType as the key and value elements
  instead of string.
  
  Add a complex Map test case, which actually doesn't show the problem as
  Axis recognizes the Apache namespace Map Schema and always does the
  right thing with it.  Still, a good test for passing maps back and forth.
  
  Revision  Changes    Path
  1.1                  ws-axis/java/test/wsdl/map/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0" ?>
  <!DOCTYPE project [
          <!ENTITY properties SYSTEM "file:../../../xmls/properties.xml">
          <!ENTITY paths  SYSTEM "file:../../../xmls/path_refs.xml">
          <!ENTITY taskdefs SYSTEM "file:../../../xmls/taskdefs.xml">
          <!ENTITY taskdefs_post_compile SYSTEM "file:../../../xmls/taskdefs_post_compile.xml">
          <!ENTITY targets SYSTEM "file:../../../xmls/targets.xml">
  ]>
  
  <!-- ===================================================================
  <description>
     Test/Sample Component file for Axis
  
  Notes:
     This is a build file for use with the Jakarta Ant build tool.
  
  Prerequisites:
  
     jakarta-ant from http://jakarta.apache.org
  
  Build Instructions:
     To compile
          ant compile
     To execute
          ant run
  
  Author:
    Tom Jordahl
  
  Copyright:
    Copyright (c) 2002-2003 Apache Software Foundation.
  </description>
  ==================================================================== -->
  
  <project default="compile">
  
  <property name="axis.home" location="../../.." />
  <property name="componentName" value="test/wsdl/map" />
          &properties;
          &paths;
          &taskdefs;
          &taskdefs_post_compile;
          &targets;
  
  <target name="clean">
      <echo message="componentName is ${componentName}"/>
      <echo message="Removing ${build.dir}/**/test/wsdl/map" />
      <delete dir="${build.dir}/classes/test/wsdl/map"/>
      <delete dir="${build.dir}/work/test/wsdl/map"/>
  </target>
  
  <!-- main target, always start from scratch -->
  <target name="compile" depends="setenv, clean">
    <echo message="Compiling test.wsdl.map"/>
    
      <!-- Compile the test classes for Java2WSDL -->
      <javac srcdir="${axis.home}/test/wsdl/map" 
             destdir="${build.dest}" 
             fork="${javac.fork}"
             debug="${debug}">
        <classpath refid="classpath" />
        <include name="MapService.java" />
      </javac>
      
      <mkdir dir="${build.dir}/work/test/wsdl/map"/>
      
      <!-- Generate WSDL from java -->
      <java2wsdl output="${build.dir}/work/test/wsdl/map/MapService.wsdl"
                 className= "test.wsdl.map.MapService"
                 namespace="http://test.com/MapService"
                 location="http://localhost:8080/axis/services/MapService">
          <mapping package="test.wsdl.map" namespace="http://test.com/MapService" />
      </java2wsdl>
      
      <!-- Verify files generated based on everything in WSDL -->
      <wsdl2java url="${build.dir}/work/test/wsdl/map/MapService.wsdl"
                 output="${axis.home}/build/work"
                 all="yes"
                 verbose="no"
                 serverside="yes"
                 testcase="no">
          <mapping namespace="http://test.com/MapService" package="test.wsdl.map"/>
      </wsdl2java>
  
      <!-- Copy the test case -->
      <copy file="MapServiceTestCase.java" overwrite="true"
            todir="${build.dir}/work/test/wsdl/map"/>
  
      <copy file="MapServiceSoapBindingImpl.java" overwrite="true"
            todir="${build.dir}/work/test/wsdl/map"/>
  
  	<!-- Clean up old classes -->
      <delete dir="${build.dir}/classes/test/wsdl/map" />
      
      <!-- Compile the test case -->
      <javac srcdir="${build.dir}/work" destdir="${build.dest}" fork="${javac.fork}"
             debug="${debug}">
        <classpath refid="classpath" />
        <include name="test/wsdl/map/*.java" />
      </javac>
  
  </target>
  
  <target name="run" >
    <antcall target="execute-Component" />
  </target>
  
  </project>
  
  
  
  1.1                  ws-axis/java/test/wsdl/map/MapService.java
  
  Index: MapService.java
  ===================================================================
      /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2002-2003 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 test.wsdl.map;
  
  import java.util.Map;
  
  /**
   * Test service for testing Map Schema in WSDL
   */
  public class MapService {
      /**
       * echo the input Map
       */ 
      public java.util.Map echoMap(Map in) {
  	    return in;
      }
  }
  
  
  
  1.1                  ws-axis/java/test/wsdl/map/MapServiceSoapBindingImpl.java
  
  Index: MapServiceSoapBindingImpl.java
  ===================================================================
  /**
   * MapServiceSoapBindingImpl.java
   *
   * Implementation of the Map service used after we convert from Java to WSDL
   * then back to Java again.  Should be identical to MapService.java
   */
  
  package test.wsdl.map;
  
  import java.util.Map;
  import java.util.HashMap;
  
  public class MapServiceSoapBindingImpl implements test.wsdl.map.MapService{
      /**
       * echo the input Map
       */
      public HashMap echoMap(HashMap in) {
  	    return in;
      }
  }
  
  
  
  1.1                  ws-axis/java/test/wsdl/map/MapServiceTestCase.java
  
  Index: MapServiceTestCase.java
  ===================================================================
  /**
   * MapServiceServiceTestCase.java
   *
   */
  
  package test.wsdl.map;
  
  import java.util.Map;
  import java.util.HashMap;
  
  public class MapServiceTestCase extends junit.framework.TestCase {
      public MapServiceTestCase(java.lang.String name) {
          super(name);
      }
      public void test1EchoMap() throws Exception {
          test.wsdl.map.MapService binding;
          try {
              binding = new MapServiceServiceLocator().getMapService();
          }
          catch (javax.xml.rpc.ServiceException jre) {
              if(jre.getLinkedCause()!=null)
                  jre.getLinkedCause().printStackTrace();
              throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught:
" + jre);
          }
          assertTrue("binding is null", binding != null);
  
          // populate test data
          HashMap m = new HashMap();
          String stringKey = "stringKey";
          String stringVal = "stringValue";
          m.put(stringKey, stringVal);
  
          Integer intKey = new Integer(77);
          Double doubleVal = new Double(3.14159);
          m.put(intKey, doubleVal);
  
          Long longKey = new Long("1231231231");
          Boolean boolVal = new Boolean(true);
          m.put(longKey, boolVal);
  
          String[] stringArrayKey = new String[] {"array1", "array2"};
          Integer[] intArray = new Integer[] {new Integer(1), new Integer(2)};
          m.put(stringArrayKey, intArray );
  
          Long[] longArrayKey = new Long[] {new Long("1000001"), new Long(2000002)};
          Boolean[] boolArray = new Boolean[]{ new Boolean(true), new Boolean(false)};
          m.put(longArrayKey, boolArray);
  
          // Test operation
          Map outMap = binding.echoMap(m);
  
          // Verify return map
          Object value;
          value = outMap.get(stringKey);
          assertNotNull("Can not find entry for STRING key", value);
          assertEquals("The class of the map value does not match",  String.class.getName(),
value.getClass().getName());
          assertEquals("The value does not match", stringVal, (String) value);
  
          value = outMap.get(intKey);
          assertNotNull("Can not find entry for INTEGER key", value);
          assertEquals("The class of the map value does not match", Double.class.getName(),
value.getClass().getName());
          assertEquals("The value does not match", (Double) value, doubleVal);
  
          value = outMap.get(longKey);
          assertNotNull("Can not find entry for LONG key", value);
          assertEquals("The class of the map value does not match",  Boolean.class.getName(),
value.getClass().getName());
          assertEquals("The value does not match", boolVal, (Boolean) value);
  
          // This is a pain because a get with the orignal keys wont return entries in the
new map
          java.util.Iterator it = outMap.keySet().iterator();
          boolean foundInt = false;
          boolean foundBool = false;
          while (it.hasNext())
          {
              Object oKey = it.next();
              if (oKey.getClass().isArray())
              {
                  Object[] oArrayKey = (Object[]) oKey;
                  Object oValue = outMap.get(oKey);
  
                  if (String.class.getName().equals(oArrayKey[0].getClass().getName()))
                  {
                      // Verify Key data
                      String[] sArray = (String[]) oArrayKey;
                      for (int i = 0; i < sArray.length; i++)
                      {
                          assertEquals("STRING Array KEY data does not match", stringArrayKey[i],
sArray[i]);
                      }
  
                      // verify value data
                      assertTrue("The Array VALUE does not match", oValue.getClass().isArray());
                      Object[] oArrayValue = (Object[]) oValue;
                      assertEquals("Class of the array does not match epected", Integer.class.getName(),
oArrayValue[0].getClass().getName());
                      Integer[] ia = (Integer[]) oValue;
                      for (int i = 0; i < ia.length; i++)
                      {
                          assertEquals("INTEGER Array VALUE does not match", intArray[i],
ia[i]);
                      }
                      foundInt = true;
                  }
                  else if (Long.class.getName().equals(oArrayKey[0].getClass().getName()))
                  {
                      // verify Key data
                      Long[] lArray = (Long[]) oArrayKey;
                      for (int i = 0; i < lArray.length; i++)
                      {
                          assertEquals("LONG Array KEY data does not match", longArrayKey[i],
lArray[i]);
  
                      }
                      // verify value data
                      assertTrue("The Array VALUE does not match", oValue.getClass().isArray());
                      Object[] oArrayValue = (Object[]) oValue;
                      assertEquals("Class of the array does not match epected", Boolean.class.getName(),
oArrayValue[0].getClass().getName());
                      Boolean[] ba = (Boolean[]) oValue;
                      for (int i = 0; i < ba.length; i++)
                      {
                          assertEquals("BOOLEAN Array VALUE does not match", boolArray[i],
ba[i]);
                      }
                      foundBool = true;
                  }
  
              }
          }
          if (!foundInt || ! foundBool)
          {
              assertTrue("Unable to find integer or boolean key in returned Map", false);
          }
      }
  
  }
  
  
  
  1.25      +2 -2      ws-axis/java/src/org/apache/axis/encoding/ser/MapSerializer.java
  
  Index: MapSerializer.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/MapSerializer.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- MapSerializer.java	5 Sep 2003 17:58:52 -0000	1.24
  +++ MapSerializer.java	8 Jan 2004 17:47:23 -0000	1.25
  @@ -172,12 +172,12 @@
           Element element2 = types.createElement("element");
           element2.setAttribute("name", "key");
           element2.setAttribute("nillable", "true");
  -        element2.setAttribute("type", "xsd:string");
  +        element2.setAttribute("type", "xsd:anyType");
           seq2.appendChild(element2);
           Element element3 = types.createElement("element");
           element3.setAttribute("name", "value");
           element3.setAttribute("nillable", "true");
  -        element3.setAttribute("type", "xsd:string");
  +        element3.setAttribute("type", "xsd:anyType");
           seq2.appendChild(element3);
           types.writeSchemaTypeDecl(QNAME_ITEMTYPE, itemType);
   
  
  
  

Mime
View raw message