antelder    2003/03/07 06:59:31

  Modified:    java/src/org/apache/wsif/base WSIFClientProxy.java
               java/src/org/apache/wsif/util WSIFUtils.java
               java/src/org/apache/wsif/providers ProviderUtils.java
  Log:
  More unwrapping fixes for stubs
  
  Revision  Changes    Path
  1.21      +56 -32    xml-axis-wsif/java/src/org/apache/wsif/base/WSIFClientProxy.java
  
  Index: WSIFClientProxy.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/base/WSIFClientProxy.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- WSIFClientProxy.java      5 Mar 2003 17:16:27 -0000       1.20
  +++ WSIFClientProxy.java      7 Mar 2003 14:59:30 -0000       1.21
  @@ -285,23 +285,16 @@
               wsifFaultMessage = wsifOperation.createFaultMessage(inputMsgName);
           }
   
  +        boolean usingwrapped = false;
           List inputParts = (inputMessage == null) 
              ? new ArrayList() 
              : inputMessage.getOrderedParts(null);
           if (args != null) {
  -             if (inputParts.size() != args.length) {
  -                unWrapIfWrappedDocLit(inputParts, operation.getName());
  -            }
  +             usingwrapped = unWrapIfRequired(operation.getName(), inputParts, args);
               Iterator partIt = inputParts.iterator();
               for (int argIndex = 0; partIt.hasNext(); argIndex++) {
                   Part part = (Part) partIt.next();
  -                String partName;
  -                if (isWrappedInContext()) {
  -                    QName qn = part.getElementName();
  -                    partName = (qn == null) ? "" : qn.getLocalPart(); 
  -                } else {
  -                    partName = part.getName();
  -                }
  +                String partName = part.getName();
                   wsifInputMessage.setObjectPart(partName, args[argIndex]);
               }
           }
  @@ -332,18 +325,15 @@
           if (outputMessage != null) {
               List outputParts = outputMessage.getOrderedParts(null);
               if (outputParts != null && outputParts.size() > 0) {
  +                if (usingwrapped || isWrappedInContext()) {
  +                     unwrap(operation.getName()+"Response", outputParts);
  +                } 
  +
                   // The return value is always the first output part
                   Iterator outPartIt = outputParts.iterator();
                   Part returnPart = (Part) outPartIt.next();
  -                try {
  -                    result = wsifOutputMessage.getObjectPart(returnPart.getName());
  -                } catch (WSIFException e) {
  -                     Trc.ignoredException(e);
  -                    unWrapIfWrappedDocLit(outputParts, 
operation.getName()+"Response");
  -                    outPartIt = outputParts.iterator();
  -                    returnPart = (Part) outPartIt.next();
  -                    result = wsifOutputMessage.getObjectPart(returnPart.getName());
  -                }
  +                result = wsifOutputMessage.getObjectPart(returnPart.getName());
  +
                   // Are there any inout parts? Multiple output-only parts
                   // are not allowed in java. Skip over input-only parts in the 
message.
                   if (outPartIt.hasNext()) {
  @@ -467,12 +457,16 @@
               }
   
               // No match if there are different numbers of parameters
  -            if (types != null && (numInputParts != types.length)) {
  -                unWrapIfWrappedDocLit(inputParts, operation.getName());
  -                numInputParts = inputParts.size();
  -                if (numInputParts != types.length) {
  -                    continue;
  -                }
  +            if (isWrappedInContext() || (types != null && (numInputParts != 
types.length))) {
  +             if (ProviderUtils.isUnwrapable(operation)) {
  +                    unWrapIfRequired(operation.getName(), inputParts, args);
  +                    numInputParts = inputParts.size();
  +                    if (numInputParts != types.length) {
  +                        continue;
  +                    }
  +             } else {
  +                     continue;
  +             }
               }
   
               // Go through all the parameters making sure all their datatypes match
  @@ -641,17 +635,47 @@
           return sb.toString();
       }
   
  +    protected boolean isUnwrapRequired() {
  +     boolean unwrapRequired = false;
  +     try {
  +             WSIFMessage ctx = wsifport.getContext();
  +             String style = (String) 
ctx.getObjectPart(WSIFConstants.CONTEXT_OPERATION_STYLE);
  +             unwrapRequired = 
WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED.equals(style);
  +     } catch (WSIFException e) {
  +             Trc.ignoredException(e);
  +     }
  +     return unwrapRequired;
  +    }
  +
        /**
         * Unwraps the top level element if this a wrapped message.
         */
  -     private void unWrapIfWrappedDocLit(List parts, String operationName)
  +     private boolean unWrapIfRequired(String name, List parts, Object[] args)
                throws WSIFException {
  -         Part p = ProviderUtils.getWrappedDocLiteralPart(parts, operationName);
  -             if (p != null) {
  -                 List unWrappedParts = ProviderUtils.unWrapPart(p, def);
  -                     parts.remove(p);
  -                     parts.addAll(unWrappedParts);
  -             }
  +             boolean unwrapped = false;
  +        boolean unwrap = isWrappedInContext();
  +        if (!unwrap) { 
  +             // TODO: try to work out from part types
  +             // for now just hack
  +             unwrap = args.length != parts.size();
  +        } 
  +        if (unwrap) {
  +             unwrapped = unwrap(name, parts);
  +        }
  +        return unwrapped;
  +     }
  +
  +
  +     private boolean unwrap(String name, List parts) throws WSIFException {
  +             boolean unwrapped = false;
  +         Part p = ProviderUtils.getWrapperPart(parts, name);
  +     if (p != null) {
  +             List unWrappedParts = ProviderUtils.unWrapPart(p, def, 
wsifport.getContext());
  +                 parts.remove(p);
  +                 parts.addAll(unWrappedParts);
  +                 unwrapped = true;
  +         }
  +         return unwrapped;
        }
        
        private boolean isWrappedInContext() throws WSIFException {
  
  
  
  1.35      +4 -4      xml-axis-wsif/java/src/org/apache/wsif/util/WSIFUtils.java
  
  Index: WSIFUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/util/WSIFUtils.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- WSIFUtils.java    6 Mar 2003 16:54:20 -0000       1.34
  +++ WSIFUtils.java    7 Mar 2003 14:59:31 -0000       1.35
  @@ -1368,15 +1368,15 @@
        /**
         * @deprecated use org.apache.wsif.providers.ProviderUtils.isWrappedDocLiteral
         */
  -     public static boolean isWrappedDocLiteral(List parts, String operationName) {
  -             return ProviderUtils.isWrappedDocLiteral(parts, operationName);
  +     public static boolean isWrappedDocLiteral(List parts, String name) {
  +             return !(ProviderUtils.getWrapperPart(parts, name) == null);
        }
   
        /**
  -      * @deprecated use 
org.apache.wsif.providers.ProviderUtils.getWrappedDocLiteralPart
  +      * @deprecated use org.apache.wsif.providers.ProviderUtils.getWrapperPart
         */
        public static Part getWrappedDocLiteralPart(List parts, String operationName) {
  -        return ProviderUtils.getWrappedDocLiteralPart(parts, operationName);
  +        return ProviderUtils.getWrapperPart(parts, operationName);
        }
   
        /**
  
  
  
  1.6       +45 -26    
xml-axis-wsif/java/src/org/apache/wsif/providers/ProviderUtils.java
  
  Index: ProviderUtils.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/ProviderUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ProviderUtils.java        5 Mar 2003 16:56:16 -0000       1.5
  +++ ProviderUtils.java        7 Mar 2003 14:59:31 -0000       1.6
  @@ -59,9 +59,14 @@
   
   import java.lang.reflect.Array;
   import java.util.ArrayList;
  +import java.util.Iterator;
   import java.util.List;
   
   import javax.wsdl.Definition;
  +import javax.wsdl.Input;
  +import javax.wsdl.Message;
  +import javax.wsdl.Operation;
  +import javax.wsdl.Output;
   import javax.wsdl.Part;
   import javax.xml.namespace.QName;
   
  @@ -318,33 +323,47 @@
        }       
   
        /**
  -      * Tests if this is wrapped document literal stype operation.
  +      * Tests if this is wrapped stype operation.
         * An operation is wrapped if:
  -      *    - there is only one input or output message part
  -      *      and that part is an element not a type 
  -      *      (MIME means there can be many parts, so all this 
  -      *       can check is that there is only one element part)
  -      *    - the message name is the same as the operation name
  -      *      (for a response the operation name is appened with "Response")
  -      */
  -     public static boolean isWrappedDocLiteral(List parts, String operationName) {
  -             boolean wrapped = !(parts==null);
  -             Part elementPart = null;
  -             for (int i = 0; wrapped && i < parts.size(); i++) {
  -                     Part p = (Part) parts.get(i);
  -                     if (p.getElementName() != null) {
  -                             if (elementPart == null) {
  -                                     elementPart = p;
  -                                 String pName = p.getElementName().getLocalPart();
  -                                 if (!operationName.equals(pName)) {
  -                                        wrapped = false;
  +      *    - the input message name has a part with an element which
  +      *      has the same name as the operation name, and the output
  +      *      message has an element with a name the same as the 
  +      *      operation name appended with "Response"
  +      *    - there is only a single part (but with attachments
  +      *      there may be multiple parts so ignore this for now?)
  +      */
  +     public static boolean isUnwrapable(Operation op) {
  +             boolean unwrapable = true;
  +             Input in = op.getInput();
  +             if (in != null) {
  +                     Message inMsg = in.getMessage();
  +                     if (inMsg != null) {
  +                     List parts = inMsg.getOrderedParts(null);
  +                     if (parts.size() > 0) {
  +                         String name = op.getName();
  +                                 if (getWrapperPart(parts, name) == null) {
  +                                         unwrapable = false;
                                    }
  -                             } else {
  -                                     wrapped = false;
  -                             }
  +                     }
                        }
  +                     
                }
  -             return wrapped;
  +        if (unwrapable) {
  +                 Output out = op.getOutput();
  +                 if (out != null) {
  +                         Message outMsg = out.getMessage();
  +                         if (outMsg != null) {
  +                             List parts = outMsg.getOrderedParts(null);
  +                     if (parts.size() > 0) {
  +                             String name = op.getName() + "Response";
  +                             if (getWrapperPart(parts, name) == null) {
  +                                     unwrapable = false;
  +                             }
  +                     }
  +                         }
  +                 }
  +        }
  +             return unwrapable;
        }
   
        /**
  @@ -357,7 +376,7 @@
         *    - the message name is the same as the operation name
         *      (for a response the operation name is appened with "Response")
         */
  -     public static Part getWrappedDocLiteralPart(List parts, String operationName) {
  +     public static Part getWrapperPart(List parts, String operationName) {
                boolean wrapped = !(parts==null);
                Part elementPart = null;
                for (int i = 0; wrapped && i < parts.size(); i++) {
  @@ -452,7 +471,7 @@
                return unWrappedParts;
        }
   
  -    private static ElementType getElementType(List l, QName qn) {
  +    protected static ElementType getElementType(List l, QName qn) {
        ElementType et = null;
                for (int i=0; i<l.size() && et==null; i++ ){
                        Object o = l.get(i);
  @@ -466,7 +485,7 @@
                return et;
       }
        
  -    private static ComplexType getComplexType(List l, QName type) {
  +    protected static ComplexType getComplexType(List l, QName type) {
                ComplexType ct = null;
        if (type != null && l != null) {
                String name = type.getLocalPart();
  
  
  

Reply via email to