owenb       2003/03/14 03:43:20

  Modified:    java/src/org/apache/wsif/providers/ejb Tag: pre1_2_0-patches
                        WSIFOperation_EJB.java
               java/test/util Tag: pre1_2_0-patches WSIFTestRunner.java
               java/src/org/apache/wsif/providers/java Tag:
                        pre1_2_0-patches WSIFOperation_Java.java
  Added:       java/test/multiout/ejb Tag: pre1_2_0-patches Test.java
                        TestBean.java TestHome.java
               java/test/multiout/java Tag: pre1_2_0-patches Test_Java.java
               java/test/multiout Tag: pre1_2_0-patches MultiOut.wsdl
                        MultiOutTest.java
  Log:
  Add support for returning multiple output parts from Java and EJB services.
  The Java/EJB method must return a java.util.Map containing the names and
  values of all output parts.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +68 -0     xml-axis-wsif/java/test/multiout/ejb/Attic/Test.java
  
  
  
  
  1.1.2.1   +127 -0    xml-axis-wsif/java/test/multiout/ejb/Attic/TestBean.java
  
  
  
  
  1.1.2.1   +70 -0     xml-axis-wsif/java/test/multiout/ejb/Attic/TestHome.java
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +84 -0     xml-axis-wsif/java/test/multiout/java/Attic/Test_Java.java
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +128 -0    xml-axis-wsif/java/test/multiout/Attic/MultiOut.wsdl
  
  
  
  
  1.1.2.1   +327 -0    xml-axis-wsif/java/test/multiout/Attic/MultiOutTest.java
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.19.2.7  +156 -102  
xml-axis-wsif/java/src/org/apache/wsif/providers/ejb/WSIFOperation_EJB.java
  
  Index: WSIFOperation_EJB.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/ejb/WSIFOperation_EJB.java,v
  retrieving revision 1.19.2.6
  retrieving revision 1.19.2.7
  diff -u -r1.19.2.6 -r1.19.2.7
  --- WSIFOperation_EJB.java    10 Jan 2003 10:32:04 -0000      1.19.2.6
  +++ WSIFOperation_EJB.java    14 Mar 2003 11:43:19 -0000      1.19.2.7
  @@ -124,6 +124,7 @@
       protected boolean fieldIsHomeInterface = false;
       protected Map fieldTypeMaps = new HashMap();
       protected boolean fieldTypeMapBuilt = false;
  +    protected Object returnClass = null;
   
       private class FaultMessageInfo {
           String fieldMessageName;
  @@ -352,26 +353,42 @@
                   if (params.length != args.length)
                       continue;
                   Class retType = fieldAllMethods[i].getReturnType();
  -                if (retClass != null && retClass instanceof Vector) {
  -                    Vector vec = (Vector) retClass;
  +                
  +                boolean tryAMap = false;
  +                if (fieldOutParameterNames.length > 1) {
  +                    Class mapClass = java.util.Map.class;
                       boolean found = false;
  -                    for (int p = 0; p < vec.size(); p++) {
  -                        Class cl = (Class) vec.get(p);
  -                        if (cl.getName().equals(retType.getName())) {
  -                            found = true;
  -                            break;
  -                        } else if (cl.isAssignableFrom(retType)) {
  -                            found = true;
  -                            break;
  -                        }
  +                    if (mapClass.getName().equals(retType.getName())) {
  +                        tryAMap = true;
  +                    } else if (mapClass.isAssignableFrom(retType)) {
  +                        tryAMap = true;
                       }
  -                    if (!found)
  -                        continue;
  -                } else {
  -                    if (retType != null && retClass != null) {
  -                        if (!(((Class) 
retClass).getName().equals(retType.getName()))
  -                             && !(((Class) retClass).isAssignableFrom(retType)))
  +                }
  +                if (!tryAMap) {
  +                    if (retClass != null && retClass instanceof Vector) {
  +                        Vector vec = (Vector) retClass;
  +                        boolean found = false;
  +                        for (int p = 0; p < vec.size(); p++) {
  +                            Class cl = (Class) vec.get(p);
  +                            if (cl.getName().equals(retType.getName())) {
  +                                found = true;
  +                                break;
  +                            } else if (cl.isAssignableFrom(retType)) {
  +                                found = true;
  +                                break;
  +                            }
  +                        }
  +                        if (!found)
                               continue;
  +                    } else {
  +                        if (retType != null && retClass != null) {
  +                            if (!(((Class) retClass)
  +                                .getName()
  +                                .equals(retType.getName()))
  +                                && !(((Class) retClass)
  +                                    .isAssignableFrom(retType)))
  +                                continue;
  +                        }
                       }
                   }
   
  @@ -541,7 +558,8 @@
       }
   
       protected Object getMethodReturnClass() throws WSIFException {
  -        Trc.entry(this);
  +        Trc.entry(this);  
  +        
           Object methodReturnClass = null;
           try {
               String returnPartString = fieldEJBOperationModel.getReturnPart();
  @@ -596,7 +614,8 @@
                       + " : The meta information is not consistent.",
                   ex);
           }
  -
  +        
  +        returnClass = methodReturnClass;
           Trc.exit(methodReturnClass);
           return methodReturnClass;
       }
  @@ -949,7 +968,6 @@
           close();
   
           boolean operationSucceeded = true;
  -        boolean foundInputParameter = false;
           boolean usedOutputParam = false;
   
           try {
  @@ -973,33 +991,9 @@
                       try {
                           part = input.getObjectPart(fieldInParameterNames[i]);
                           arguments[i] = part;
  -                        foundInputParameter = true;
                       } catch (WSIFException e) {
  -                     Trc.exception(e);
  -                        if (fieldOutParameterNames.length > 0) {
  -                            String outParameterName = null;
  -                            for (int j = 0;
  -                                j < fieldOutParameterNames.length;
  -                                j++) {
  -                                outParameterName = fieldOutParameterNames[j];
  -                                if ((outParameterName != null)
  -                                    && (outParameterName
  -                                        .equals(fieldInParameterNames[i]))) {
  -                                    arguments[i] =
  -                                        (methods[0].getParameterTypes()[i])
  -                                            .newInstance();
  -                                    foundInputParameter = true;
  -                                    usedOutputParam = true;
  -                                }
  -                            }
  -                        }
  -                    }
  -                    if (!foundInputParameter) {
  -                        throw new WSIFException(
  -                            this
  -                                + " : Could not set input parameter '"
  -                                + fieldInParameterNames[i]
  -                                + "'");
  +                        // if we can't find the part, a default value will be used 
later
  +                        Trc.ignoredException(e);
                       }
                   }
               }
  @@ -1011,7 +1005,8 @@
                           "create")) // only handle create methods -> entity EJB 
finders not supported
                       {
                       try {
  -                        // Get a set of arguments which are compatible with the ctor
  +                        // Get a set of arguments which are compatible with the 
ctor. Creates default
  +                        // values for missing parts
                           Object[] compatibleArguments =
                               getCompatibleArguments(
                                   methods[a].getParameterTypes(),
  @@ -1045,26 +1040,9 @@
                       }
                       // Side effect: Initialize port's object reference 
                   } else {
  -                    if (usedOutputParam) {
  -                        for (int i = 0;
  -                            i < fieldInParameterNames.length;
  -                            i++) {
  -                            String outParameterName = null;
  -                            for (int j = 0; j < fieldOutParameterNames.length; j++) 
{
  -                                outParameterName = fieldOutParameterNames[j];
  -                                if ((outParameterName != null)
  -                                    && (outParameterName
  -                                        .equals(fieldInParameterNames[i]))) {
  -                                    arguments[i] =
  -                                        (methods[a].getParameterTypes()[i])
  -                                            .newInstance();
  -                                }
  -                            }
  -                        }
  -                    }
  -
                       try {
  -                        // Get a set of arguments which are compatible with the ctor
  +                        // Get a set of arguments which are compatible with the 
method. Creates default
  +                        // values for missing parts
                           Object[] compatibleArguments =
                               getCompatibleArguments(
                                   methods[a].getParameterTypes(),
  @@ -1073,7 +1051,7 @@
                           if (compatibleArguments == null)
                               break;
                           // Parts are compatible so invoke the ctor with the 
compatible set
  -                        
  +
                           EJBObject obj = fieldPort.getEjbObject();
                           Trc.event(
                               this,
  @@ -1092,7 +1070,7 @@
                           fieldMethod = methods[a];
   
                           String outParameterName = null;
  -                        if (fieldOutParameterNames.length > 0) {
  +                        if (fieldOutParameterNames.length == 1) {
                               output.setName(getOutputMessageName());
                               outParameterName =
                                   (String) fieldOutParameterNames[0];
  @@ -1102,37 +1080,104 @@
                                       getCompatibleReturn(fieldMethod, result));
                                   // Should we use the class of the method signature 
instead here ?
                               }
  +                        } else if (fieldOutParameterNames.length > 1) {
  +                            if 
(Map.class.isAssignableFrom(fieldMethod.getReturnType())) {
  +                                     
  +                                // Method should have returned a Map
  +                                if (!(result instanceof Map)) {
  +                                    throw new WSIFException(
  +                                        "Operation "
  +                                            + getOperation().getName()
  +                                            + " defined as returning multiple parts 
"
  +                                            + "and the EJB method did not return an 
instance of java.util.Map");
  +                                }
  +
  +                                Map returnedMap = (Map) result;
  +                                output.setName(getOutputMessageName());
   
  -                            if (arguments != null) {
  -                                for (int i = 1;
  -                                    i < fieldOutParameterNames.length;
  -                                    i++) {
  -                                    outParameterName =
  -                                        fieldOutParameterNames[i];
  -                                    if (outParameterName != null) {
  -                                        try {
  -                                            for (int r = 0;
  -                                                r < fieldInParameterNames.length;
  -                                                r++) {
  -                                                if (outParameterName
  -                                                    
.equals(fieldInParameterNames[r])) {
  -                                                    output.setObjectPart(
  -                                                        outParameterName,
  -                                                        arguments[r]);
  -                                                    break;
  -                                                }
  -                                            }
  -                                        } catch (WSIFException e) {
  -                                             Trc.ignoredException(e);
  -                                            //ignore
  +                                // Get multiple output parts from the map
  +                                for (int p = 0;
  +                                    p < fieldOutParameterNames.length;
  +                                    p++) {
  +                                    String pName = fieldOutParameterNames[p];
  +                                    if (returnedMap.containsKey(pName)) {
  +                                        Object outPart = returnedMap.get(pName);
  +                                        Message outputMessage =
  +                                            getOperation()
  +                                                .getOutput()
  +                                                .getMessage();
  +                                        Part wsdlPart =
  +                                            outputMessage.getPart(pName);
  +                                        QName partType = wsdlPart.getTypeName();
  +                                        if (partType == null) {
  +                                            partType =
  +                                                wsdlPart.getElementName();
                                           }
  +                                        Object typeObj =
  +                                            this.fieldTypeMaps.get(partType);
  +                                        if (typeObj != null) {
  +                                            Class c =
  +                                                getClassForName(
  +                                                    (String) typeObj);
  +                                            Object outPart2 =
  +                                                getCompatibleObject(c, outPart);
  +                                            output.setObjectPart(
  +                                                pName,
  +                                                outPart2);
  +                                        } else {
  +                                            throw new WSIFException(
  +                                                "The Class of part "
  +                                                    + pName
  +                                                    + ", returned by the EJB method 
for"
  +                                                    + " operation "
  +                                                    + getOperation().getName()
  +                                                    + " does not match the Class 
defined in the format "
  +                                                    + "binding for that part.");
  +                                        }
  +                                    } else {
  +                                        // A part was not found in the map. Check 
the return
  +                                        // class. If it's a Map, just add the map 
to the output
  +                                        // message. If not, throw an exception to 
say the map
  +                                        // does not contain the missing part.
  +                                        if (returnClass != null
  +                                            && returnClass instanceof Class
  +                                            && Map.class.isAssignableFrom(
  +                                                (Class) returnClass)) {
  +                                            Map m = new HashMap();
  +                                            m.put(
  +                                                fieldOutParameterNames[0],
  +                                                result);
  +                                            output.setParts(m);
  +                                            break;
  +                                        }
  +                                        throw new WSIFException(
  +                                            "Operation "
  +                                                + getOperation().getName()
  +                                                + " defined as returning multiple 
parts."
  +                                                + " Part "
  +                                                + pName
  +                                                + " was missing from the Map 
returned by "
  +                                                + "the EJB service");
                                       }
                                   }
  +                            } else {
  +                                // Backwards compatiblity - method returns just the 
output part specified
  +                                // by returnPart
  +                                output.setName(getOutputMessageName());
  +                                outParameterName =
  +                                    (String) fieldOutParameterNames[0];
  +                                if (outParameterName != null) {
  +                                    output.setObjectPart(
  +                                        outParameterName,
  +                                        getCompatibleReturn(
  +                                            fieldMethod,
  +                                            result));
  +                                }
                               }
                           }
                           break;
                       } catch (IllegalArgumentException ia) {
  -                             Trc.ignoredException(ia);
  +                        Trc.ignoredException(ia);
                           // Ingore and try next method
                       }
                   }
  @@ -1143,7 +1188,7 @@
                           + fieldEJBOperationModel.getMethodName()
                           + "'");
           } catch (InvocationTargetException ex) {
  -             Trc.exception(ex);
  +            Trc.exception(ex);
               Throwable invocationFault = ex.getTargetException();
               String className = invocationFault.getClass().getName();
               Map faultMessageInfos = getFaultMessageInfos();
  @@ -1158,10 +1203,12 @@
                   fault.setObjectPart(faultMessageInfo.fieldPartName, faultPart);
                   fault.setName(faultMessageInfo.fieldMessageName);
                   if (faultMessageInfo.fieldMessageName != null) {
  -                     Fault wsdlFault = 
fieldBindingOperationModel.getOperation().getFault(faultMessageInfo.fieldMessageName);
  -                     if (wsdlFault != null) {
  -                         fault.setMessageDefinition(wsdlFault.getMessage());
  -                     }
  +                    Fault wsdlFault =
  +                        fieldBindingOperationModel.getOperation().getFault(
  +                            faultMessageInfo.fieldMessageName);
  +                    if (wsdlFault != null) {
  +                        fault.setMessageDefinition(wsdlFault.getMessage());
  +                    }
                   }
                   operationSucceeded = false;
               } else {
  @@ -1187,15 +1234,20 @@
                                   faultPart);
                               fault.setName(faultMessageInfo.fieldMessageName);
                               if (faultMessageInfo.fieldMessageName != null) {
  -                             Fault wsdlFault = 
fieldBindingOperationModel.getOperation().getFault(faultMessageInfo.fieldMessageName);
  -                                 if (wsdlFault != null) {
  -                                     
fault.setMessageDefinition(wsdlFault.getMessage());
  -                                 }
  +                                Fault wsdlFault =
  +                                    fieldBindingOperationModel
  +                                        .getOperation()
  +                                        .getFault(
  +                                        faultMessageInfo.fieldMessageName);
  +                                if (wsdlFault != null) {
  +                                    fault.setMessageDefinition(
  +                                        wsdlFault.getMessage());
  +                                }
                               }
                               operationSucceeded = false;
                           }
                       } catch (Exception exc) {
  -                     Trc.ignoredException(exc);
  +                        Trc.ignoredException(exc);
                           // Nothing to do - just try the next one...
                       }
                   }
  @@ -1207,7 +1259,9 @@
                           fieldEJBOperationModel.getMethodName());
   
                       // End message
  -                    throw new WSIFException("Operation failed!",invocationFault);
  +                    throw new WSIFException(
  +                        "Operation failed!",
  +                        invocationFault);
                   }
               }
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.17.2.2  +3 -0      xml-axis-wsif/java/test/util/WSIFTestRunner.java
  
  Index: WSIFTestRunner.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/util/WSIFTestRunner.java,v
  retrieving revision 1.17.2.1
  retrieving revision 1.17.2.2
  diff -u -r1.17.2.1 -r1.17.2.2
  --- WSIFTestRunner.java       5 Dec 2002 12:11:19 -0000       1.17.2.1
  +++ WSIFTestRunner.java       14 Mar 2003 11:43:19 -0000      1.17.2.2
  @@ -57,6 +57,8 @@
   
   package util;
   
  +import multiout.MultiOutTest;
  +
   import faults.FaultMsgTest;
   import headers.HeadersTest;
   import inout.InoutTest;
  @@ -112,6 +114,7 @@
           suite.addTest(new TestSuite(ProvidersInitialisationTest.class));
           
           suite.addTest(new TestSuite(ShoppingCartTest.class));
  +        suite.addTest(new TestSuite(MultiOutTest.class));
           suite.addTest(new TestSuite(AsyncTests.class));
           suite.addTest(new TestSuite(HeadersTest.class));
           suite.addTest(new TestSuite(FaultMsgTest.class));
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.21.2.6  +192 -42   
xml-axis-wsif/java/src/org/apache/wsif/providers/java/WSIFOperation_Java.java
  
  Index: WSIFOperation_Java.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/java/WSIFOperation_Java.java,v
  retrieving revision 1.21.2.5
  retrieving revision 1.21.2.6
  diff -u -r1.21.2.5 -r1.21.2.6
  --- WSIFOperation_Java.java   6 Dec 2002 13:32:14 -0000       1.21.2.5
  +++ WSIFOperation_Java.java   14 Mar 2003 11:43:19 -0000      1.21.2.6
  @@ -69,10 +69,8 @@
   import java.util.Vector;
   
   import javax.wsdl.BindingFault;
  -import javax.wsdl.BindingInput;
   import javax.wsdl.BindingOperation;
   import javax.wsdl.BindingOutput;
  -import javax.wsdl.Definition;
   import javax.wsdl.Fault;
   import javax.wsdl.Message;
   import javax.wsdl.Operation;
  @@ -81,13 +79,10 @@
   import javax.wsdl.Port;
   import javax.xml.namespace.QName;
   
  -import org.apache.wsif.WSIFConstants;
   import org.apache.wsif.WSIFException;
   import org.apache.wsif.WSIFMessage;
  -import org.apache.wsif.WSIFMessageFactory;
   import org.apache.wsif.WSIFOperation;
   import org.apache.wsif.base.WSIFDefaultOperation;
  -import org.apache.wsif.base.WSIFServiceImpl;
   import org.apache.wsif.logging.MessageLogger;
   import org.apache.wsif.logging.Trc;
   import org.apache.wsif.providers.ProviderUtils;
  @@ -120,6 +115,8 @@
       protected boolean fieldIsStatic = false;
       protected boolean fieldIsConstructor = false;
       protected Map fieldTypeMaps = null;
  +    protected boolean multiOutParts = false;
  +    private Object returnClass = null;
   
       private class FaultMessageInfo {
           String fieldMessageName;
  @@ -192,7 +189,9 @@
           String outMName,
           boolean isSttc,
           boolean isCnstr,
  -        Map tMap) {
  +        Map tMap,
  +        boolean mulOP,
  +        Object retCl) {
           Trc.entry(
               this,
               p,
  @@ -207,7 +206,9 @@
               outMName,
               new Boolean(isSttc),
               new Boolean(isCnstr),
  -            tMap);
  +            tMap,
  +            new Boolean(mulOP),
  +            retCl);
   
           fieldPortModel = p;
           fieldPort = pj;
  @@ -222,6 +223,8 @@
           fieldIsStatic = isSttc;
           fieldIsConstructor = isCnstr;
           fieldTypeMaps = tMap;
  +        multiOutParts = mulOP;
  +        returnClass = retCl;
   
           if (Trc.ON)
               Trc.exit(deep());
  @@ -247,7 +250,9 @@
                   fieldOutputMessageName,
                   fieldIsStatic,
                   fieldIsConstructor,
  -                fieldTypeMaps);
  +                fieldTypeMaps,
  +                multiOutParts,
  +                returnClass);
           Trc.exit(woj);
           return woj;
       }
  @@ -429,26 +434,42 @@
                       if (params.length != args.length)
                           continue;
                       Class retType = allMethods[i].getReturnType();
  -                    if (retClass != null && retClass instanceof Vector) {
  -                        Vector vec = (Vector) retClass;
  -                        boolean found = false;
  -                        for (int p = 0; p < vec.size(); p++) {
  -                            Class cl = (Class) vec.get(p);
  -                            if (cl.getName().equals(retType.getName())) {
  -                                found = true;
  -                                break;
  -                            } else if (cl.isAssignableFrom(retType)) {
  -                                     found = true;
  -                                     break;
  -                            }
  +                    
  +                    boolean tryAMap = false;
  +                    if (multiOutParts) {
  +                     Class mapClass = java.util.Map.class;
  +                     boolean found = false;
  +                     if (mapClass.getName().equals(retType.getName())) {
  +                            tryAMap = true;
  +                        } else if (mapClass.isAssignableFrom(retType)) {
  +                            tryAMap = true;
                           }
  -                        if (!found)
  -                            continue;
  -                    } else {
  -                        if (retType != null && retClass != null) {
  -                            if (!(((Class) 
retClass).getName().equals(retType.getName()))
  -                             && !(((Class) retClass).isAssignableFrom(retType)))
  +                    }
  +                    if (!tryAMap) {
  +                        if (retClass != null && retClass instanceof Vector) {
  +                            Vector vec = (Vector) retClass;
  +                            boolean found = false;
  +                            for (int p = 0; p < vec.size(); p++) {
  +                                Class cl = (Class) vec.get(p);
  +                                if (cl.getName().equals(retType.getName())) {
  +                                    found = true;
  +                                    break;
  +                                } else if (cl.isAssignableFrom(retType)) {
  +                                    found = true;
  +                                    break;
  +                                }
  +                            }
  +                            if (!found)
                                   continue;
  +                        } else {
  +                            if (retType != null && retClass != null) {
  +                                if (!(((Class) retClass)
  +                                    .getName()
  +                                    .equals(retType.getName()))
  +                                    && !(((Class) retClass)
  +                                        .isAssignableFrom(retType)))
  +                                    continue;
  +                            }
                           }
                       }
   
  @@ -537,6 +558,20 @@
           Object methodReturnClass = null;
           try {
               String returnPartString = fieldJavaOperationModel.getReturnPart();
  +            List parameterOrder = fieldJavaOperationModel.getParameterOrder();
  +
  +                     // Service with multiple output parts
  +            if (fieldOutParameterNames.length > 1) {
  +             multiOutParts = true;
  +                for (int p = 0; p < fieldOutParameterNames.length; p++) {
  +                    String pName = fieldOutParameterNames[p];
  +                    if (pName != null
  +                        && parameterOrder.contains(pName)) {
  +                        multiOutParts = false;
  +                    }
  +                }
  +            }
  +            
               if (returnPartString != null) {
                   // A returnPart has been specified so check that this method has 
the correct
                   // return type
  @@ -585,6 +620,7 @@
                       + " : The meta information is not consistent.",
                   ex);
           }
  +        returnClass = methodReturnClass;
           Trc.exit(methodReturnClass);
           return methodReturnClass;
       }
  @@ -1114,32 +1150,146 @@
                               "Failed to invoke method '" + 
fieldJavaOperationModel.getMethodName() + "'");
                   }
   
  +                // Deal with the output message
                   String outParameterName = null;
  -                if (fieldOutParameterNames != null && fieldOutParameterNames.length 
> 0) {
  +                if (fieldOutParameterNames.length == 1) {
  +                    // Only one output part - it must be the object returned by the
  +                    // Java service invocation
                       output.setName(getOutputMessageName());
                       outParameterName = (String) fieldOutParameterNames[0];
                       if (outParameterName != null) {
                           output.setObjectPart(
                               outParameterName,
                               getCompatibleReturn(chosenMethod, result));
  -                        // Should we use the class of the method signature instead 
here ?
                       }
  +                } else if (fieldOutParameterNames.length > 1) {
  +                    if (multiOutParts) {
  +                        if 
(Map.class.isAssignableFrom(chosenMethod.getReturnType())) {
  +                            // Method should have returned a Map
  +                            if (!(result instanceof Map)) {
  +                                throw new WSIFException(
  +                                    "Operation "
  +                                        + getOperation().getName()
  +                                        + " defined as returning multiple parts "
  +                                        + "and the Java method did not return an 
instance of java.util.Map");
  +                            }
  +
  +                            Map returnedMap = (Map) result;
  +                            output.setName(getOutputMessageName());
  +
  +                            // Get multiple output parts from the map
  +
  +                            for (int p = 0;
  +                                p < fieldOutParameterNames.length;
  +                                p++) {
  +                                String pName = fieldOutParameterNames[p];
  +                                if (returnedMap.containsKey(pName)) {
  +                                    Object outPart = returnedMap.get(pName);
  +                                    Message outputMessage =
  +                                        getOperation().getOutput().getMessage();
  +                                    Part wsdlPart =
  +                                        outputMessage.getPart(pName);
  +                                    QName partType = wsdlPart.getTypeName();
  +                                    if (partType == null) {
  +                                        partType = wsdlPart.getElementName();
  +                                    }
  +                                    Object typeObj =
  +                                        this.fieldTypeMaps.get(partType);
  +                                    if (typeObj != null) {
  +                                        Class c =
  +                                            getClassForName((String) typeObj);
  +                                        Object outPart2 =
  +                                            getCompatibleObject(c, outPart);
  +                                        output.setObjectPart(pName, outPart2);
  +                                    } else {
  +                                        throw new WSIFException(
  +                                            "The Class of part "
  +                                                + pName
  +                                                + ", returned by the Java method 
for"
  +                                                + " operation "
  +                                                + getOperation().getName()
  +                                                + " does not match the Class 
defined in the format "
  +                                                + "binding for that part.");
  +                                    }
  +                                } else {
  +                                    // A part was not found in the map. Check the 
return
  +                                    // class. If it's a Map, just add the map to 
the output
  +                                    // message. If not, throw an exception to say 
the map
  +                                    // does not contain the missing part.
  +                                    if (returnClass != null
  +                                        && returnClass instanceof Class
  +                                        && Map.class.isAssignableFrom(
  +                                            (Class) returnClass)) {
  +                                        Map m = new HashMap();
  +                                        m.put(
  +                                            fieldOutParameterNames[0],
  +                                            result);
  +                                        output.setParts(m);
  +                                        break;
  +                                    }
  +                                    throw new WSIFException(
  +                                        "Operation "
  +                                            + getOperation().getName()
  +                                            + " defined as returning multiple 
parts."
  +                                            + " Part "
  +                                            + pName
  +                                            + " was missing from the Map returned 
by "
  +                                            + "the Java service class");
  +                                }
  +                            }
   
  -                    if (arguments != null) {
  -                        for (int i = 1; i < fieldOutParameterNames.length; i++) {
  -                            outParameterName = fieldOutParameterNames[i];
  +                        } else {
  +                             // Backwards compatiblity - method returns just the 
output part specified
  +                             // by returnPart
  +                            output.setName(getOutputMessageName());
  +                            outParameterName =
  +                                (String) fieldOutParameterNames[0];
                               if (outParameterName != null) {
  -                             try {
  -                                     for (int r = 0; r < 
fieldInParameterNames.length; r++) {
  -                                             if 
(outParameterName.equals(fieldInParameterNames[r])) {
  -                                                     
output.setObjectPart(outParameterName, arguments[r]);
  -                                                     break;
  -                                             }
  -                                     }
  -                             } catch (WSIFException e) {
  -                                     Trc.ignoredException(e);
  -                                     //ignore
  -                             }
  +                                output.setObjectPart(
  +                                    outParameterName,
  +                                    getCompatibleReturn(chosenMethod, result));
  +                            }
  +                        }
  +                    } else {
  +                        // Method has returned one object and updated the 
references of
  +                        // other objects passed into the method.             
  +                        output.setName(getOutputMessageName());
  +
  +                        // Add the returned object to the output message
  +                        outParameterName = (String) fieldOutParameterNames[0];
  +                        if (outParameterName != null) {
  +                            output.setObjectPart(
  +                                outParameterName,
  +                                getCompatibleReturn(chosenMethod, result));
  +                        }
  +
  +                        // Deal with objects whose reference has been updated by 
the Java
  +                        // service method. Parts for such objects will appear in 
the WSDL
  +                        // output message and their names will also be included in 
the 
  +                        // parameterOrder attribute
  +                        if (arguments != null) {
  +                            for (int i = 1;
  +                                i < fieldOutParameterNames.length;
  +                                i++) {
  +                                outParameterName = fieldOutParameterNames[i];
  +                                if (outParameterName != null) {
  +                                    try {
  +                                        for (int r = 0;
  +                                            r < fieldInParameterNames.length;
  +                                            r++) {
  +                                            if (outParameterName
  +                                                .equals(fieldInParameterNames[r])) {
  +                                                output.setObjectPart(
  +                                                    outParameterName,
  +                                                    arguments[r]);
  +                                                break;
  +                                            }
  +                                        }
  +                                    } catch (WSIFException e) {
  +                                        Trc.ignoredException(e);
  +                                        //ignore
  +                                    }
  +                                }
                               }
                           }
                       }
  
  
  

Reply via email to