You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsif-dev@ws.apache.org by an...@apache.org on 2003/04/24 17:22:36 UTC

cvs commit: xml-axis-wsif/java/src/org/apache/wsif/tools/tojava WSIFJavaTestCaseWriter.java

antelder    2003/04/24 08:22:36

  Modified:    java/src/org/apache/wsif/tools/tojava
                        WSIFJavaTestCaseWriter.java
  Log:
  fix to work properly with array parameter types
  
  Revision  Changes    Path
  1.4       +85 -27    xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/WSIFJavaTestCaseWriter.java
  
  Index: WSIFJavaTestCaseWriter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/WSIFJavaTestCaseWriter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WSIFJavaTestCaseWriter.java	31 Mar 2003 12:51:12 -0000	1.3
  +++ WSIFJavaTestCaseWriter.java	24 Apr 2003 15:22:36 -0000	1.4
  @@ -79,9 +79,11 @@
   import org.apache.axis.wsdl.symbolTable.PortTypeEntry;
   import org.apache.axis.wsdl.symbolTable.ServiceEntry;
   import org.apache.axis.wsdl.symbolTable.SymbolTable;
  +import org.apache.axis.wsdl.symbolTable.Type;
   import org.apache.axis.wsdl.toJava.Emitter;
   import org.apache.axis.wsdl.toJava.JavaClassWriter;
   import org.apache.axis.wsdl.toJava.Utils;
  +import org.apache.wsif.WSIFConstants;
   import org.apache.wsif.WSIFException;
   import org.apache.wsif.providers.ProviderUtils;
   import org.apache.wsif.util.WSIFUtils;
  @@ -348,6 +350,8 @@
           tabOut();
           skipLines(pw, 1);
   
  +        writeMapPackages(pw);
  +
           String seiName = getSEIName(portType);
   
           addNewCodeLine(pw, seiName);
  @@ -492,7 +496,9 @@
           skipLines(pw, 1);
   
           if (returnPartName != null) {
  -            addNewCodeLine(pw, "System.out.println(\" port \" + portName + \" operation '");
  +            addNewCodeLine(
  +                pw,
  +                "System.out.println(\" port \" + portName + \" operation '");
               addCode(pw, op.getName());
               addCode(pw, "' returned: \" + ");
               addCode(pw, returnPartName);
  @@ -572,6 +578,8 @@
           tabOut();
           skipLines(pw, 1);
   
  +        writeMapPackages(pw);
  +
           addNewCodeLine(pw, "WSIFPort port = service.getPort(portName);");
   
           skipLines(pw, 1);
  @@ -609,6 +617,48 @@
       }
   
       /**
  +     */
  +    protected void writeMapPackages(PrintWriter pw) {
  +        SymbolTable st = emitter.getSymbolTable();
  +        String packageMapping = emitter.getPackageName();
  +        if (packageMapping != null) {
  +            ArrayList nss = new ArrayList();
  +            Map m = st.getElementIndex();
  +            for (Iterator i = m.keySet().iterator(); i.hasNext();) {
  +                QName qn = (QName) i.next();
  +                String ns = qn.getNamespaceURI();
  +                if (!nss.contains(ns)) {
  +                    nss.add(ns);
  +                }
  +            }
  +            m = st.getTypeIndex();
  +            for (Iterator i = m.keySet().iterator(); i.hasNext();) {
  +                QName qn = (QName) i.next();
  +                String ns = qn.getNamespaceURI();
  +                if (!nss.contains(ns)) {
  +                    nss.add(ns);
  +                }
  +            }
  +            for (Iterator i = nss.iterator(); i.hasNext();) {
  +                String ns = (String) i.next();
  +                if (!(ns.equals(WSIFConstants.NS_URI_SOAP_ENC)
  +                    || ns.equals(WSIFConstants.NS_URI_1999_SCHEMA_XSD)
  +                    || ns.equals(WSIFConstants.NS_URI_2000_SCHEMA_XSD)
  +                    || ns.equals(WSIFConstants.NS_URI_2001_SCHEMA_XSD))) {
  +                    addNewCodeLine(
  +                        pw,
  +                        "service.mapPackage(\""
  +                            + ns
  +                            + "\", \""
  +                            + packageMapping
  +                            + " \");");
  +                }
  +            }
  +            skipLines(pw, 1);
  +        }
  +    }
  +
  +    /**
        * Write the executeOp method using the WSIF DII
        */
       protected void writeDIIOperationMethod(
  @@ -667,7 +717,9 @@
                   requireWrapperFlag = false;
               }
   
  -            addNewCodeLine(pw, "// TODO: change these parameter values");
  +            if (parts.size() > 0) {
  +                addNewCodeLine(pw, "// TODO: change these parameter values");
  +            }
   
               int parameterCounter = 0;
               for (Iterator i = parts.iterator(); i.hasNext();) {
  @@ -820,7 +872,8 @@
           String methodName,
           String portName)
           throws IOException {
  -        String testMethodname = "test" + ProviderUtils.capitalizeFirst(methodName) + portName;
  +        String testMethodname =
  +            "test" + ProviderUtils.capitalizeFirst(methodName) + portName;
           addNewCodeLine(pw, "public void " + testMethodname + "() {");
           tabIn();
           addNewCodeLine(pw, methodName + "(\"" + portName + "\");");
  @@ -913,22 +966,28 @@
       /**
        * Gets the fully qualified Java class name from a QName 
        */
  -    protected static String getClassName(QName type) {
  +    protected String getClassName(QName type) {
           String className = "";
  -        Map types = WSIFUtils.getSimpleTypesMap();
  -        Object o = types.get(type);
  -        if (o != null) {
  -            String s = (String) o;
  -            if (s.indexOf('[') < 0) {
  -                className = s;
  +        SymbolTable st = emitter.getSymbolTable();
  +        Type t = st.getType(type);
  +        if (t != null) {
  +            className = t.getName();
  +        } else {
  +            Map types = WSIFUtils.getSimpleTypesMap();
  +            Object o = types.get(type);
  +            if (o != null) {
  +                String s = (String) o;
  +                if (s.indexOf('[') < 0) {
  +                    className = s;
  +                } else {
  +                    className = getArrayType(s);
  +                }
               } else {
  -                className = getArrayType(s);
  +                className =
  +                    Utils.makePackageName(type.getNamespaceURI())
  +                        + "."
  +                        + Utils.xmlNameToJavaClass(type.getLocalPart());
               }
  -        } else {
  -            className =
  -                Utils.makePackageName(type.getNamespaceURI())
  -                    + "."
  -                    + Utils.xmlNameToJavaClass(type.getLocalPart());
           }
           return className;
       }
  @@ -962,8 +1021,7 @@
                   arrayType = "short";
                   break;
               case 'L' :
  -                arrayType =
  -                    type.substring(type.lastIndexOf('[') + 2);
  +                arrayType = type.substring(type.lastIndexOf('[') + 2);
                   break;
           }
           return arrayType + dimensions;
  @@ -995,16 +1053,16 @@
           } else if ("String".equals(uqClassName)) {
               s = "\"\"";
           } else {
  -        	StringBuffer constructor = new StringBuffer(className);
  -        	if (className.indexOf('[') < 0) {
  +            StringBuffer constructor = new StringBuffer(className);
  +            if (className.indexOf('[') < 0) {
                   constructor.append("()");
  -        	} else {
  -            	for (int i = 0; i < constructor.length(); i++) {
  -            		if (constructor.charAt(i) == '[') {
  -            			constructor.insert(i+1, '0');
  -            		}
  -        	    }
  -        	}
  +            } else {
  +                for (int i = 0; i < constructor.length(); i++) {
  +                    if (constructor.charAt(i) == '[') {
  +                        constructor.insert(i + 1, '0');
  +                    }
  +                }
  +            }
               s = "new " + constructor.toString() + ";";
           }
           return s;