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/03/24 15:07:27 UTC

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

antelder    2003/03/24 06:07:27

  Modified:    java/src/org/apache/wsif/tools/tojava
                        JavaBindingGenerator.java
                        WSIFJavaTestCaseWriter.java WSIFEmitter.java
               java/src/org/apache/wsif/tools WSDL2Java.java
  Log:
  More development of the tooling
  
  Revision  Changes    Path
  1.2       +18 -0     xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/JavaBindingGenerator.java
  
  Index: JavaBindingGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/JavaBindingGenerator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JavaBindingGenerator.java	20 Mar 2003 15:46:36 -0000	1.1
  +++ JavaBindingGenerator.java	24 Mar 2003 14:07:27 -0000	1.2
  @@ -62,6 +62,8 @@
   import java.util.Map;
   
   import javax.wsdl.Binding;
  +import javax.wsdl.BindingInput;
  +import javax.wsdl.BindingOutput;
   import javax.wsdl.Definition;
   import javax.wsdl.Input;
   import javax.wsdl.Message;
  @@ -81,7 +83,9 @@
   import org.apache.wsif.wsdl.extensions.java.JavaBindingConstants;
   import org.apache.wsif.wsdl.extensions.java.JavaOperation;
   
  +import com.ibm.wsdl.BindingInputImpl;
   import com.ibm.wsdl.BindingOperationImpl;
  +import com.ibm.wsdl.BindingOutputImpl;
   import com.ibm.wsdl.PortImpl;
   
   /**
  @@ -175,6 +179,20 @@
   
               JavaOperation javaOp = makeJavaOperation(op);
               bo.addExtensibilityElement(javaOp);
  +
  +            Input input = op.getInput();
  +            if (input != null) {
  +            	BindingInput bin = new BindingInputImpl();
  +            	bin.setName(input.getName());
  +                bo.setBindingInput(bin);
  +            }
  +
  +            Output output = op.getOutput();
  +            if (output != null) {
  +            	BindingOutput bout = new BindingOutputImpl();
  +            	bout.setName(output.getName());
  +                bo.setBindingOutput(bout);
  +            }
   
               b.addBindingOperation(bo);
   
  
  
  
  1.2       +137 -61   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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WSIFJavaTestCaseWriter.java	20 Mar 2003 15:46:36 -0000	1.1
  +++ WSIFJavaTestCaseWriter.java	24 Mar 2003 14:07:27 -0000	1.2
  @@ -224,6 +224,8 @@
           pw.println(" *");
           pw.println(" * This file was auto-generated from WSDL");
           pw.println(" * by the Apache WSIF WSDL2Java emitter.");
  +        pw.println(" *");
  +        pw.println(" * Search for TODO: for code requiring completing");
           pw.println(" */");
           pw.println();
       } // writeHeaderComments
  @@ -362,13 +364,7 @@
           skipLines(pw, 1);
           for (Iterator i = portType.getOperations().iterator(); i.hasNext();) {
               Operation op = (Operation) i.next();
  -
  -            String javaOpName = Utils.xmlNameToJavaClass(op.getName());
  -            String opMethodName = "executeOp" + javaOpName;
  -            if (isOverloaded(portType, op)) {
  -                opMethodName += getInMsgName(op);
  -            }
  -
  +            String opMethodName = makeExecuteOpMethodName(portType, op);
               addNewCodeLine(pw, opMethodName + "(stub);");
           }
   
  @@ -410,11 +406,7 @@
   
           addNewCodeLine(pw, "protected void ");
   
  -        String javaOpName = Utils.xmlNameToJavaClass(op.getName());
  -        String opMethodName = "executeOp" + javaOpName;
  -        if (isOverloaded(portType, op)) {
  -            opMethodName += getInMsgName(op);
  -        }
  +        String opMethodName = makeExecuteOpMethodName(portType, op);
           addCode(pw, opMethodName);
   
           addCode(pw, "(");
  @@ -433,9 +425,11 @@
                   parts,
                   op.getName());
   
  -            addNewCodeLine(
  -                pw,
  -                "// TODO: change these params to required values");
  +            if (parts.size() > 0) {
  +                addNewCodeLine(
  +                    pw,
  +                    "// TODO: change these params to required values");
  +            }
   
               int parameterCounter = 0;
               for (Iterator i = parts.iterator(); i.hasNext();) {
  @@ -470,7 +464,7 @@
               Part p = (Part) parts.get(0);
               returnPartName = p.getName();
               if (JavaUtils.isJavaKeyword(returnPartName)) {
  -            	returnPartName = "_" + returnPartName;
  +                returnPartName = "_" + returnPartName;
               }
               QName type = ProviderUtils.getPartType(p);
               returnClassName = Utils.getJavaLocalName(getClassName(type));
  @@ -583,12 +577,7 @@
           skipLines(pw, 1);
           for (Iterator i = portType.getOperations().iterator(); i.hasNext();) {
               Operation op = (Operation) i.next();
  -
  -            String opMethodName = "executeOp" + capitalizeFirst(op.getName());
  -            if (isOverloaded(portType, op)) {
  -                opMethodName += getInMsgName(op);
  -            }
  -
  +            String opMethodName = makeExecuteOpMethodName(portType, op);
               addNewCodeLine(pw, opMethodName + "(port);");
           }
   
  @@ -629,11 +618,7 @@
   
           addNewCodeLine(pw, "protected void ");
   
  -        String opMethodName = "executeOp" + capitalizeFirst(op.getName());
  -        boolean overloaded = isOverloaded(portType, op);
  -        if (overloaded) {
  -            opMethodName += getInMsgName(op);
  -        }
  +        String opMethodName = makeExecuteOpMethodName(portType, op);
           addCode(pw, opMethodName);
   
           addCode(pw, "(WSIFPort wsifPort) throws WSIFException {");
  @@ -642,7 +627,7 @@
           tabIn();
   
           addNewCodeLine(pw, "WSIFOperation op = wsifPort.createOperation(");
  -        if (overloaded) {
  +        if (isOverloaded(portType, op)) {
               tabIn();
               addNewCodeLine(pw, "\"");
               addCode(pw, op.getName());
  @@ -664,13 +649,23 @@
           addNewCodeLine(pw, "WSIFMessage faultMsg = op.createFaultMessage();");
   
           skipLines(pw, 1);
  +        boolean requireWrapperFlag = true;
           Input in = op.getInput();
           if (in != null && in.getMessage() != null) {
               List parts = in.getMessage().getOrderedParts(null);
  -            unwrapIfWrapped(
  -                emitter.getCurrentDefinition(),
  -                parts,
  -                op.getName());
  +            boolean wasUnwrapped =
  +                unwrapIfWrapped(
  +                    emitter.getCurrentDefinition(),
  +                    parts,
  +                    op.getName());
  +
  +            if (wasUnwrapped) {
  +                if (parts.size() > 1) {
  +                    requireWrapperFlag = false;
  +                }
  +            } else {
  +                requireWrapperFlag = false;
  +            }
   
               addNewCodeLine(pw, "// TODO: change these parameter values");
   
  @@ -703,6 +698,19 @@
               }
           }
   
  +        if (requireWrapperFlag) {
  +            addNewCodeLine(pw, "WSIFMessage ctx = op.getContext();");
  +            addNewCodeLine(pw, "ctx.setObjectPart(");
  +            tabIn();
  +            addNewCodeLine(pw, "WSIFConstants.CONTEXT_OPERATION_STYLE,");
  +            addNewCodeLine(
  +                pw,
  +                "WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED);");
  +            tabOut();
  +            addNewCodeLine(pw, "op.setContext(ctx);");
  +            skipLines(pw, 1);
  +        }
  +
           addNewCodeLine(pw, "boolean success =");
           tabIn();
           addNewCodeLine(
  @@ -763,12 +771,13 @@
                           + paramName
                           + ");");
               }
  +            if (parts.size() > 0) {
  +                skipLines(pw, 1);
  +                addNewCodeLine(pw, "// TODO: add tests for return parts here");
  +                skipLines(pw, 1);
  +            }
           }
   
  -        skipLines(pw, 1);
  -        addNewCodeLine(pw, "// TODO: add tests for return parts here");
  -        skipLines(pw, 1);
  -
           tabOut();
           addNewCodeLine(pw, "} else {");
   
  @@ -854,31 +863,24 @@
           return sb.toString();
       }
   
  -    /**
  -     * Gets the fully qualified Java class name from a QName 
  -     */
  -    protected static String getClassName(QName type) {
  -        String className = "";
  -        Map types = WSIFUtils.getSimpleTypesMap();
  -        Object o = types.get(type);
  -        if (o != null) {
  -            className = (String) o;
  -        } else {
  -            className =
  -                Utils.makePackageName(type.getNamespaceURI())
  -                    + "."
  -                    + Utils.xmlNameToJavaClass(type.getLocalPart());
  +    protected String makeExecuteOpMethodName(PortType portType, Operation op) {
  +        String javaOpName = Utils.xmlNameToJavaClass(op.getName());
  +        String opMethodName = "executeOp" + javaOpName;
  +        if (isOverloaded(portType, op)) {
  +            opMethodName += capitalizeFirst(getInMsgName(op));
           }
  -        return className;
  +        return opMethodName;
       }
   
       /**
        * Unwraps a WSDL message if required
        */
  -    protected void unwrapIfWrapped(
  +    protected boolean unwrapIfWrapped(
           Definition def,
           List parts,
           String operationName) {
  +
  +        boolean wasUnwrapped = false;
           if (!emitter.isNowrap()) {
               Part p = ProviderUtils.getWrapperPart(parts, operationName);
               if (p != null) {
  @@ -895,8 +897,10 @@
                   int i = parts.indexOf(p);
                   parts.remove(i);
                   parts.addAll(i, unwrappedParts);
  +                wasUnwrapped = true;
               }
           }
  +        return wasUnwrapped;
       }
   
       /**
  @@ -929,29 +933,101 @@
       }
   
       /**
  +     * Gets the fully qualified Java class name from a QName 
  +     */
  +    protected static 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;
  +            } else {
  +                className = getArrayType(s);
  +            }
  +        } else {
  +            className =
  +                Utils.makePackageName(type.getNamespaceURI())
  +                    + "."
  +                    + Utils.xmlNameToJavaClass(type.getLocalPart());
  +        }
  +        return className;
  +    }
  +
  +    protected static String getArrayType(String type) {
  +        String dimensions = "";
  +        for (int i = 0; type.charAt(i) == '['; i++) {
  +            dimensions += "[]";
  +        }
  +        String arrayType = "";
  +        switch (type.charAt(type.lastIndexOf('[') + 1)) {
  +            case 'I' :
  +                arrayType = "int";
  +                break;
  +            case 'F' :
  +                arrayType = "float";
  +                break;
  +            case 'J' :
  +                arrayType = "long";
  +                break;
  +            case 'D' :
  +                arrayType = "double";
  +                break;
  +            case 'Z' :
  +                arrayType = "boolean";
  +                break;
  +            case 'B' :
  +                arrayType = "byte";
  +                break;
  +            case 'S' :
  +                arrayType = "short";
  +                break;
  +            case 'L' :
  +                arrayType =
  +                    type.substring(type.lastIndexOf('[') + 2);
  +                break;
  +        }
  +        return arrayType + dimensions;
  +    }
  +
  +    /**
        * Gets the initiliser for a type
        */
       protected String getTypeInitialiser(QName type) {
           String s = "";
           String className = Utils.getJavaLocalName(getClassName(type));
  -        if ("int".equals(className)) {
  +        String uqClassName = Utils.getJavaLocalName(className);
  +        if ("int".equals(uqClassName)) {
               s = "0";
  -        } else if ("short".equals(className)) {
  +        } else if ("short".equals(uqClassName)) {
               s = "0";
  -        } else if ("boolean".equals(className)) {
  +        } else if ("boolean".equals(uqClassName)) {
               s = "false";
  -        } else if ("byte".equals(className)) {
  +        } else if ("byte".equals(uqClassName)) {
               s = "0";
  -        } else if ("long".equals(className)) {
  +        } else if ("long".equals(uqClassName)) {
               s = "0";
  -        } else if ("double".equals(className)) {
  +        } else if ("double".equals(uqClassName)) {
               s = "0";
  -        } else if ("float".equals(className)) {
  +        } else if ("float".equals(uqClassName)) {
               s = "0";
  -        } else if ("char".equals(className)) {
  +        } else if ("char".equals(uqClassName)) {
               s = "''";
  +        } else if ("String".equals(uqClassName)) {
  +            s = "\"\"";
           } else {
  -            s = "new " + className + "()";
  +        	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');
  +            		}
  +        	    }
  +        	}
  +            s = "new " + constructor.toString() + ";";
           }
           return s;
       }
  
  
  
  1.2       +1 -1      xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/WSIFEmitter.java
  
  Index: WSIFEmitter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/WSIFEmitter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WSIFEmitter.java	20 Mar 2003 15:46:36 -0000	1.1
  +++ WSIFEmitter.java	24 Mar 2003 14:07:27 -0000	1.2
  @@ -70,7 +70,7 @@
   public class WSIFEmitter extends Emitter {
   
       protected boolean testcaseGenDII = false;
  -    protected boolean testcaseGenStubs = true;
  +    protected boolean testcaseGenStubs = false;
   
       /**
        * Constructor
  
  
  
  1.2       +1 -1      xml-axis-wsif/java/src/org/apache/wsif/tools/WSDL2Java.java
  
  Index: WSDL2Java.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/tools/WSDL2Java.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WSDL2Java.java	20 Mar 2003 15:46:36 -0000	1.1
  +++ WSDL2Java.java	24 Mar 2003 14:07:27 -0000	1.2
  @@ -125,7 +125,7 @@
               ((WSIFEmitter) parser).setTestcaseGenDII(true);
           } else if ("none".equalsIgnoreCase(arg)) {
               ((WSIFEmitter) parser).setTestCaseWanted(false);
  -            ((WSIFEmitter) parser).setTestcaseGenStubs(false);
  +            ((WSIFEmitter) parser).setTestcaseGenStubs(true);
               ((WSIFEmitter) parser).setTestcaseGenDII(false);
           } else if (arg == null || arg.length() < 1) {
               ((WSIFEmitter) parser).setTestcaseGenStubs(true);