ws-wsif-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject cvs commit: xml-axis-wsif/java/test/models/javaProvider JavaWSIFPort.java JavaWSIFOperation.java
Date Tue, 06 May 2003 08:57:38 GMT
antelder    2003/05/06 01:57:38

  Modified:    java/src/org/apache/wsif/providers ModelWSIFOperation.java
                        ModelWSIFPort.java ModelWSIFProvider.java
               java/test/models/javaProvider JavaWSIFPort.java
                        JavaWSIFOperation.java
  Added:       java/src/org/apache/wsif/providers Part.java
  Log:
  more dev of the provider models
  
  Revision  Changes    Path
  1.2       +448 -243  xml-axis-wsif/java/src/org/apache/wsif/providers/ModelWSIFOperation.java
  
  Index: ModelWSIFOperation.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/ModelWSIFOperation.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ModelWSIFOperation.java	1 May 2003 09:23:05 -0000	1.1
  +++ ModelWSIFOperation.java	6 May 2003 08:57:37 -0000	1.2
  @@ -58,21 +58,17 @@
   package org.apache.wsif.providers;
   
   import java.util.ArrayList;
  -import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
   
  -import javax.wsdl.Binding;
   import javax.wsdl.BindingOperation;
   import javax.wsdl.Fault;
   import javax.wsdl.Input;
   import javax.wsdl.Message;
   import javax.wsdl.Operation;
   import javax.wsdl.Output;
  -import javax.wsdl.Part;
   import javax.wsdl.extensions.ExtensibilityElement;
  -import javax.xml.namespace.QName;
   
   import org.apache.wsif.WSIFConstants;
   import org.apache.wsif.WSIFCorrelationId;
  @@ -80,9 +76,9 @@
   import org.apache.wsif.WSIFMessage;
   import org.apache.wsif.WSIFOperation;
   import org.apache.wsif.WSIFResponseHandler;
  +import org.apache.wsif.attachments.WSIFAttachmentPart;
   import org.apache.wsif.base.WSIFDefaultMessage;
   import org.apache.wsif.logging.Trc;
  -import org.apache.wsif.util.WSIFUtils;
   
   /**
    * ModelWSIFOperation
  @@ -98,7 +94,21 @@
    * should be done in the model code. Subclasses should only 
    * need to provide code directly related to accessing the
    * particular service type they implement.
  - *  
  + * 
  + * For a subclass to use ModelWSIFOperation, as a minimum it
  + * would implement the doInvokeRequestResponse method. 
  + * 
  + * If special processing is required for input only operations 
  + * then subclasses would also implement doInvokeInputOnly.
  + * 
  + * If the binding being implemented uses a binding operation
  + * extensibility element then subclasses should override the
  + * getOperationExtensibilityClass, and validateOperationExtensibilityElement
  + * methods.
  + * 
  + * Other methods may be overriden to customise the behaviour,
  + * see the method javadoc for details. 
  + * 
    * @author <a href="mailto:antelder@apache.org">Ant Elder</a>
    */
   abstract public class ModelWSIFOperation implements WSIFOperation {
  @@ -107,15 +117,14 @@
       protected BindingOperation bindingOperation;
       protected Operation portTypeOperation;
   
  -    protected ArrayList inputPartOrder;
  -    protected ArrayList outputPartOrder;
  -    protected HashMap inputPartsAndClasses;
  -    protected HashMap outputPartsAndClasses;
  +    protected List inputParts;
  +    protected List outputParts;
   
       protected WSIFResponseHandler asyncResponseHandler;
   
       protected WSIFMessage context;
  -    transient protected List autoMappedTypes;
  +
  +    protected boolean used;
   
       /**
        * Construct a ModelWSIFOperation
  @@ -137,6 +146,10 @@
           throws WSIFException {
           Trc.entry(this, inMsg);
   
  +        markAsUsed();
  +
  +        //TODO: does this need supportsSync() or suuportsAsync()?
  +
           if (inMsg == null) {
               throw new IllegalArgumentException("input message is null");
           }
  @@ -156,6 +169,8 @@
           throws WSIFException {
           Trc.entry(this, inMsg, outMsg, faultMsg);
   
  +        markAsUsed();
  +
           if (wsifPort.supportsSync() == false) {
               throw new WSIFException("synchronus operations not supported");
           }
  @@ -177,15 +192,14 @@
       }
   
       /**
  -     * Default implementation of executeRequestResponseAsync.
  -     * By default async operation is not supported so this just
  -     * throws an exception.
        * @see WSIFOperation#executeRequestResponseAsync(WSIFMessage)
        */
       public WSIFCorrelationId executeRequestResponseAsync(WSIFMessage inMsg)
           throws WSIFException {
           Trc.entry(this, inMsg);
   
  +        markAsUsed();
  +
           if (wsifPort.supportsAsync() == false) {
               throw new WSIFException("asynchronous operations not supportted");
           }
  @@ -201,9 +215,6 @@
       }
   
       /**
  -     * Default implementation of executeRequestResponseAsync.
  -     * By default async operation is not supported so this just
  -     * throws an exception.
        * @see WSIFOperation#executeRequestResponseAsync(WSIFMessage, WSIFResponseHandler)
        */
       public WSIFCorrelationId executeRequestResponseAsync(
  @@ -212,6 +223,8 @@
           throws WSIFException {
           Trc.entry(this, inMsg, handler);
   
  +        markAsUsed();
  +
           if (wsifPort.supportsAsync() == false) {
               throw new WSIFException("asynchronous operations not supportted");
           }
  @@ -231,11 +244,7 @@
       }
   
       /**
  -     * Default implemantation of fireAsyncResponse.
  -     * By default async operation is not supported so this just
  -     * throws an exception.
        * @see WSIFOperation#fireAsyncResponse(Object)
  -     * @param response   an Object representing the response
        */
       public void fireAsyncResponse(Object response) throws WSIFException {
           Trc.entry(this, response);
  @@ -261,9 +270,6 @@
       }
   
       /**
  -     * Default implemantation of processAsyncResponse.
  -     * By default async operation is not supported so this just
  -     * throws an exception.
        * @see WSIFOperation#processAsyncResponse(Object,WSIFMessage,WSIFMessage)
        */
       public boolean processAsyncResponse(
  @@ -274,14 +280,14 @@
           Trc.entry(this, response, outMsg, faultMsg);
           Trc.exit();
           //TODO:
  -        throw new WSIFException("asynchronous operations not implemented yet");
  -    }
  -
  -    protected void invokeInputOnlyOperation(WSIFMessage inMsg)
  -        throws WSIFException {
  -        invokeRequestResponseOperation(inMsg, null, null);
  +        throw new WSIFException("not implemented yet");
       }
   
  +    /**
  +     * Invoke a request response operation
  +     * Subclasses should not normally override this, but
  +     * should implement doInvokeRequestResponse.
  +     */
       protected boolean invokeRequestResponseOperation(
           WSIFMessage inMsg,
           WSIFMessage outMsg,
  @@ -290,14 +296,18 @@
   
           boolean invokedOK = false;
   
  -        ArrayList inputArgs = getInputObjects(inMsg);
  -        ArrayList responseValues = new ArrayList();
  +        setPartValues(inputParts, inMsg);
  +        List inputArgs = getInputArguments();
  +        List responseValues = new ArrayList();
   
  -        invokedOK = doInvoke(inputArgs, responseValues);
  +        setInvocationContext();
  +
  +        invokedOK = doInvokeRequestResponse(inputArgs, responseValues);
   
           if (invokedOK == true) {
               if (outMsg != null) {
  -                setResponseObjects(outMsg, responseValues);
  +                setPartValues(outputParts, responseValues);
  +                setMessagePartValues(outMsg, outputParts);
               }
           } else {
               if (faultMsg != null) {
  @@ -307,22 +317,91 @@
   
           return invokedOK;
       }
  +
  +    /**
  +     * Template method for RequestResponse operation implementation.
  +     * This is the method that actually invokes the service 
  +     * Subclasses must implement this if they support synchronous operation
  +     */
  +    protected boolean doInvokeRequestResponse(
  +        List inputArgs,
  +        List responseArgs)
  +        throws WSIFException {
  +        throw new WSIFException("doInvoke must be implemented by subclass!");
  +    }
  +
  +    /**
  +     * Invoke an input only operation
  +     * Subclasses should not normally override this, but
  +     * should implement doInvokeInputOnly.
  +     */
  +    protected void invokeInputOnlyOperation(WSIFMessage inMsg)
  +        throws WSIFException {
  +        invokeRequestResponseOperation(inMsg, null, null);
  +
  +        boolean invokedOK = false;
  +
  +        setPartValues(inputParts, inMsg);
  +        List inputArgs = getInputArguments();
  +        List responseValues = new ArrayList();
  +
  +        setInvocationContext();
  +
  +        doInvokeInputOnly(inputArgs);
  +
  +    }
  +
  +    /**
  +     * Template method for inputOnly operation implementation.
  +     * This is the method that actually invokes the service 
  +     * By default this just calls doInvokeRequestResponse and
  +     * discards the response. 
  +     * Subclasses may override with their own implementation
  +     */
  +    protected void doInvokeInputOnly(List inputArgs) throws WSIFException {
  +        doInvokeRequestResponse(inputArgs, new ArrayList());
  +    }
  +
  +    /**
  +     * Invoke an asynchronus request response operation
  +     * Subclasses should not normally override this, but
  +     * should implement doInvokeRequestResponseAsync.
  +     */
       protected WSIFCorrelationId invokeRequestResponseAsync(
           WSIFMessage inMsg,
           WSIFResponseHandler handler)
           throws WSIFException {
   
  -        ArrayList inputArgs = getInputObjects(inMsg);
  +        setPartValues(inputParts, inMsg);
  +        List inputArgs = getInputArguments();
   
  -        WSIFCorrelationId cid = doInvokeAsync(inputArgs);
  +        setInvocationContext();
  +
  +        WSIFCorrelationId cid = doInvokeRequestResponseAsync(inputArgs);
   
           return cid;
       }
   
  +    /**
  +     * Template method for asynchronous RequestResponse operation implementation.
  +     * This is the method that actually invokes the service 
  +     * Subclasses must implement this if they support asynchronous operation
  +     */
  +    protected WSIFCorrelationId doInvokeRequestResponseAsync(List inputArgs)
  +        throws WSIFException {
  +        throw new WSIFException("doInvokeAsync must be implemented by subclass!");
  +    }
  +
  +    /**
  +     * Deserialises an asynchronus response object
  +     */
       protected Map doDeserialiseResponse(Object response) throws WSIFException {
           throw new WSIFException("doDeserialiseResponse must be implemented by subclass!");
       }
   
  +    /**
  +     * 
  +     */
       protected void buildResponseMessages(
           Map results,
           WSIFMessage outMsg,
  @@ -331,42 +410,125 @@
           throw new WSIFException("buildResponseMessages must be implemented by subclass!");
       }
   
  -    protected ArrayList getInputObjects(WSIFMessage msg) throws WSIFException {
  -        ArrayList objects = new ArrayList();
  -
  -        for (Iterator i = inputPartOrder.iterator(); i.hasNext();) {
  +    /**
  +     * Populates the inputParts List from a WSIFMessage 
  +     */
  +    protected void setPartValues(List parts, WSIFMessage msg)
  +        throws WSIFException {
  +        for (Iterator i = parts.iterator(); i.hasNext();) {
               Part part = (Part) i.next();
               Object partValue;
               try {
                   partValue = msg.getObjectPart(part.getName());
  +                validatePartValue(part, partValue);
               } catch (WSIFException e) {
  -                partValue = doMissingInputPart(msg, part.getName());
  +                partValue = doMissingPart(msg, part);
  +            }
  +            part.setValue(partValue);
  +        }
  +    }
  +
  +    /**
  +     * Populates the outputPartValues map from a List of response objects 
  +     */
  +    protected void setPartValues(List parts, List responseValues)
  +        throws WSIFException {
  +
  +        Iterator responses = responseValues.iterator();
  +        for (Iterator i = parts.iterator(); i.hasNext();) {
  +            Part part = (Part) i.next();
  +
  +            Object partValue;
  +            if (responses.hasNext() == true) {
  +                partValue = responses.next();
  +                validatePartValue(part, partValue);
  +            } else {
  +                partValue = doMissingOutputValue(part);
               }
  -            Class partClass = (Class) inputPartsAndClasses.get(part.getName());
  -            validatePartValue(part, partClass, partValue);
  -            objects.add(partValue);
  +            part.setValue(partValue);
  +        }
  +    }
  +
  +    /**
  +     * Populates a WSIFMessage with the part names and values from a Map  
  +     */
  +    protected void setMessagePartValues(WSIFMessage msg, List parts)
  +        throws WSIFException {
  +        for (Iterator i = parts.iterator(); i.hasNext();) {
  +            Part part = (Part) i.next();
  +            msg.setObjectPart(part.getName(), part.getValue());
  +        }
  +    }
  +
  +    /**
  +     * Populate a WSIFMessage from a list of fault objects
  +     */
  +    protected void setFaultObjects(WSIFMessage msg, List responseObjects)
  +        throws WSIFException {
  +
  +        //TODO: how to do faults properly
  +        int faultNumber = 0;
  +        for (Iterator i = responseObjects.iterator(); i.hasNext();) {
  +            Object faultValue = i.next();
  +            String faultName = "fault" + faultNumber++;
  +            msg.setObjectPart(faultName, faultValue);
           }
  +    }
   
  -        return objects;
  +    /**
  +     * Returns a List of the input value objects in inputPartOrder order 
  +     */
  +    protected List getInputArguments() throws WSIFException {
  +        List args = new ArrayList();
  +        for (Iterator i = inputParts.iterator(); i.hasNext();) {
  +            Part part = (Part) i.next();
  +            Object value = part.getValue();
  +            args.add(value);
  +        }
  +        return args;
       }
   
  -    protected Object doMissingInputPart(WSIFMessage msg, String partName) {
  +    /**
  +     * Handles a input WSIFMessage not containg a part in the WSDL message.
  +     * This default implementation defaults the part value to be null
  +     * Subclasses may overide with their own default  
  +     */
  +    protected Object doMissingPart(WSIFMessage msg, Part part) {
           Trc.event(
               this,
               "message "
                   + msg.getName()
                   + "has missing input part '"
  -                + partName
  +                + part.getName()
                   + "', defaulting to null");
           return null;
       }
   
  -    protected void validatePartValue(Part part, Class partClass, Object value)
  +    /**
  +     * Handles a output response not having a value for a part in the WSDL message.
  +     * This default implementation defaults the part value to be null
  +     * Subclasses may overide with their own default  
  +     */
  +    protected Object doMissingOutputValue(Part part) {
  +        Trc.event(this, "response value missing for part: " + part.getName());
  +        return null;
  +    }
  +
  +    /**
  +     * Validates an object is compatable with the type of a WSDL part
  +     */
  +    protected void validatePartValue(Part part, Object value)
           throws WSIFException {
           if (value != null) {
               Class valueClass = value.getClass();
  -            if (partClass.isAssignableFrom(valueClass)) {
  +            if (part.getJavaClass().isAssignableFrom(valueClass)) {
                   // type ok
  +                // TODO: what about int mapping to java.lang.Integer etc?                
  +                //            } else if (isPrimitiveWrapper(value, partClass)) {
  +                //            	// ?
  +            } else if (value instanceof WSIFAttachmentPart) {
  +                //TODO: what to do about WSIFAttachmentPart? 
  +                //      for now type ok
               } else if ("javax.activation.DataHandler".equals(valueClass)) {
                   //TODO: what to do about DataHandler? 
                   //      for now type ok
  @@ -375,75 +537,24 @@
                       "WSIFMessage part '"
                           + part.getName()
                           + "' has invalid type, expecting "
  -                        + partClass
  +                        + part.getJavaClass()
                           + " found "
                           + value.getClass());
               }
           }
       }
   
  -    protected void setResponseObjects(
  -        WSIFMessage msg,
  -        ArrayList responseObjects)
  -        throws WSIFException {
  -        ArrayList objects = new ArrayList();
  -
  -        Iterator responses = responseObjects.iterator();
  -        for (Iterator i = outputPartOrder.iterator(); i.hasNext();) {
  -            Part part = (Part) i.next();
  -
  -            Object partValue;
  -            if (responses.hasNext() == true) {
  -                partValue = responses.next();
  -            } else {
  -                partValue = doMissingInputPart(msg, part.getName());
  -            }
  -
  -            Class partClass = (Class) outputPartsAndClasses.get(part.getName());
  -            validatePartValue(part, partClass, partValue);
  -            msg.setObjectPart(part.getName(), partValue);
  -        }
  -    }
  -
  -    protected void setFaultObjects(WSIFMessage msg, ArrayList responseObjects)
  -        throws WSIFException {
  -        ArrayList objects = new ArrayList();
  -
  -        Iterator responses = responseObjects.iterator();
  -        for (Iterator i = outputPartOrder.iterator(); i.hasNext();) {
  -            Part part = (Part) i.next();
  -
  -            Object partValue;
  -            if (responses.hasNext() == true) {
  -                partValue = responses.next();
  -            } else {
  -                partValue = doMissingInputPart(msg, part.getName());
  -            }
  -
  -            Class partClass = (Class) outputPartsAndClasses.get(part);
  -            validatePartValue(part, partClass, partValue);
  -            msg.setObjectPart(part.getName(), partValue);
  -        }
  -    }
  -
  -    protected boolean doInvoke(ArrayList inputArgs, ArrayList responseArgs)
  -        throws WSIFException {
  -        throw new WSIFException("doInvoke must be implemented by subclass!");
  -    }
  -
  -    protected WSIFCorrelationId doInvokeAsync(ArrayList inputArgs)
  -        throws WSIFException {
  -        throw new WSIFException("doInvokeAsync must be implemented by subclass!");
  -    }
  -
       /**
        * Initialises the WSIFOperation.
  +     * This is called after the WSIFOperation is instantiated or
  +     * when it is a cached WSIFOperation about to be reused.
        * 
        * Subclasses would not normally override this but 
        * should override the doInitialise method.
        */
       protected void initialise() throws WSIFException {
  -        if (inputPartOrder == null) {
  +        used = false;
  +        if (inputParts == null) {
               prepare();
           }
           doInitialise();
  @@ -467,80 +578,108 @@
        */
       protected void prepare() throws WSIFException {
   
  -        this.inputPartOrder = new ArrayList();
  -        this.outputPartOrder = new ArrayList();
  -        this.inputPartsAndClasses = new HashMap();
  -        this.outputPartsAndClasses = new HashMap();
  +        this.inputParts = new ArrayList();
  +        this.outputParts = new ArrayList();
   
           Operation op = getPortTypeOperation();
   
  -        try {
  -            WSIFMessage context = getContext();
  -            autoMappedTypes =
  -                (List) context.getObjectPart(
  -                    WSIFConstants.CONTEXT_SCHEMA_TYPES);
  -        } catch (WSIFException e) {
  -            autoMappedTypes = null;
  -        }
  -
  +        // if this is a wrapped style operation, should the parts be unwrapped?
           boolean unwrap = ProviderUtils.isUnwrapable(op);
           if (unwrap == true) {
               // don't unwrap if context asks not to
               unwrap = !isWrappedInContext();
           }
   
  +        // initialise the input parts
           if (op.getInput() != null) {
               Message inMsg = op.getInput().getMessage();
  -            initialiseParts(
  -                inMsg,
  -                unwrap,
  -                inputPartOrder,
  -                inputPartsAndClasses);
  +            initialiseParts(inMsg, unwrap, inputParts);
           }
   
  +        // initialise the output parts
           if (op.getOutput() != null) {
               Message outMsg = op.getOutput().getMessage();
  -            initialiseParts(
  -                outMsg,
  -                unwrap,
  -                outputPartOrder,
  -                outputPartsAndClasses);
  +            initialiseParts(outMsg, unwrap, outputParts);
           }
   
  -        Class c = getOperationExtensabilityClass();
  +        initializeOperationExtensibilityElement();
  +
  +        // template method for subclasses
  +        doPrepare();
  +    }
  +
  +    /**
  +     * Initializes the binding operation extensebility element.
  +     * This find the binding operation extensebility element the
  +     * WSIFOperation concrete subclass implements, and then passes
  +     * it to the validateOperationExtensibilityElement method.
  +     */
  +    protected void initializeOperationExtensibilityElement()
  +        throws WSIFException {
  +
  +        Class c = getOperationExtensibilityClass();
           if (c != null) {
               if (!(ExtensibilityElement.class.isAssignableFrom(c))) {
                   throw new WSIFException("getOperationExtensabilityClass must return a subclass of ExtensibilityElement");
               }
               ExtensibilityElement ee = null;
               List ees = bindingOperation.getExtensibilityElements();
  -            for (Iterator i=ees.iterator(); ee==null && i.hasNext(); ) {
  -            	Object o = i.next();
  -            	if (c.isAssignableFrom(o.getClass())) {
  -            		ee = (ExtensibilityElement) o;
  -            	} 
  +            for (Iterator i = ees.iterator(); ee == null && i.hasNext();) {
  +                Object o = i.next();
  +                if (c.isAssignableFrom(o.getClass())) {
  +                    ee = (ExtensibilityElement) o;
  +                }
               }
  -            
  -            if (ee !=null) {
  -            	validateOperationExtensibilityElement(ee);
  +            if (ee != null) {
  +                validateOperationExtensibilityElement(ee);
               }
  -
           }
       }
   
  -    protected Class getOperationExtensabilityClass() {
  +    /**
  +     * Gets the binding operation extensebility element
  +     * This default implementation returns null. If subclasses
  +     * require a WSDL binding operation element they should 
  +     * override this method to return its WSDL4J implementation class.
  +     */
  +    protected Class getOperationExtensibilityClass() {
           return null;
       }
   
  +    /**
  +     * Validates the binding operation ExtensibilityElement
  +     * This default implementation does nothing. If subclasses
  +     * use a WSDL binding operation element they should override 
  +     * this method to validate the ExtensibilityElement attributes.
  +     */
       protected void validateOperationExtensibilityElement(ExtensibilityElement address)
           throws WSIFException {
       }
   
  -    protected void initialiseParts(
  -        Message msg,
  -        boolean unwrap,
  -        ArrayList partOrder,
  -        HashMap partsAndClasses)
  +    /**
  +     * Prepares the WSIFOperation.
  +     * 
  +     * This is called the first time a WSIFOperation is initialised.
  +     * The difference between doPrepare and doInitialise is that
  +     * doPrepare is called only once, whereas doInitialise is called
  +     * every time a WSIFOperation is about to be reused.
  +     * 
  +     * TODO: whats this all about, should it be called from the constructor then?
  +     * 
  +     * The default implementation does nothing, subclasses may
  +     * override it if they need to do something before reuse.
  +     */
  +    protected void doPrepare() {
  +    }
  +
  +    /**
  +     * Initializes part collections from a WSDL Message
  +     * The part collections incluse a List of the order of the 
  +     * parts in the WSDL message, and a Map with a key the part
  +     * in the WSDL message and a value the Java class for the
  +     * parts type.
  +     */
  +    protected void initialiseParts(Message msg, boolean unwrap, List parts)
           throws WSIFException {
   
           List msgParts = msg.getOrderedParts(null);
  @@ -549,87 +688,24 @@
                   Part p = (Part) msgParts.get(0);
                   List unwrappedParts =
                       ProviderUtils.unWrapPart(
  -                        p,
  +                        p.getWsdlPart(),
                           wsifPort.getDefinition(),
                           getContext());
  -                partOrder.add(0, unwrappedParts);
  -            }
  -            int startI = unwrap ? 1 : 0;
  -            for (int i = startI; i < msgParts.size(); i++) {
  -                Part p = (Part) msgParts.get(i);
  -                partOrder.add(p);
  -                partsAndClasses.put(p.getName(), getPartClass(p));
  +                msgParts.remove(p);
  +                msgParts.add(0, unwrappedParts);
               }
  -        }
  -    }
  -
  -    protected Class getPartClass(Part p) throws WSIFException {
  -        QName partType = ProviderUtils.getPartType(p);
  -
  -        Class partClass = null;
  -
  -        // first see if there's a WSIFDynamicTypeMap override
  -        partClass = getDynamicTypeClass(partType);
  -
  -        // otherwise see if there's a default mapping
  -        if (partClass == null) {
  -            partClass = getMappedType(partType);
  -        }
  -
  -        // perhaps a simple type
  -        if (partClass == null) {
  -            partClass = getSimpleType(partType);
  -        }
  -
  -        // finally try a default name
  -        if (partClass == null) {
  -            //            partClass = getDefaultType(partType);
  -        }
  -
  -        //         
  -        if (partClass == null) {
  -            throw new WSIFException("no class for type: " + partType);
  -        }
  -
  -        return partClass;
  -    }
  -
  -    protected Class getDynamicTypeClass(QName partType) {
  -        Class partClass = null;
  -        WSIFDynamicTypeMap typeMap = wsifPort.getTypeMap();
  -        for (Iterator i = typeMap.iterator();
  -            partClass == null && i.hasNext();
  -            ) {
  -
  -            WSIFDynamicTypeMapping mapping = (WSIFDynamicTypeMapping) i.next();
  -            if (partType.equals(mapping.getXmlType())) {
  -                partClass = mapping.javaType;
  +            for (Iterator i = msgParts.iterator(); i.hasNext();) {
  +                javax.wsdl.Part wsdlPart = (javax.wsdl.Part) i.next();
  +                Part part = new Part(wsdlPart);
  +                part.setJavaClass(wsifPort.getClassForPart(wsdlPart));
  +                parts.add(part);
               }
           }
  -
  -        return partClass;
  -    }
  -
  -    protected Class getMappedType(QName partType) {
  -        Class partClass = null;
  -
  -        return partClass;
  -    }
  -
  -    protected Class getSimpleType(QName partType) {
  -        Class partClass = null;
  -        Map simpleTypes = WSIFUtils.getSimpleTypesMap();
  -        String className = (String) simpleTypes.get(partType);
  -        if (className != null) {
  -            ClassLoader cl = Thread.currentThread().getContextClassLoader();
  -            try {
  -                partClass = Class.forName(className, true, cl);
  -            } catch (Throwable e) {
  -            }
  -        }
  -        return partClass;
       }
   
  +    /**
  +     * Tests if wrapped operations should use wrapped parts
  +     */
       protected boolean isWrappedInContext() {
           boolean wrappedInContext = false;
   
  @@ -651,6 +727,9 @@
           return wrappedInContext;
       }
   
  +    /**
  +     * Tests if wrapped operations should use unwrapped parts
  +     */
       protected boolean isUnwrappedInContext() {
           boolean unWrapInContext = false;
   
  @@ -691,9 +770,6 @@
           Trc.entry(this);
           if (portTypeOperation == null) {
   
  -            // <input> and <output> tags in binding operations are not mandatory
  -            // so deal with null BindingInputs or BindingOutputs
  -
               String inputName = null;
               if (bindingOperation.getBindingInput() != null) {
                   inputName = bindingOperation.getBindingInput().getName();
  @@ -801,35 +877,141 @@
       }
   
       /**
  -     * Returns the inputParts.
  -     * @return ArrayList
  +     * Returns the List of inputParts.
  +     * @return List   the List of inputParts
  +     */
  +    protected List getInputParts() {
  +        return inputParts;
  +    }
  +
  +    /**
  +     */
  +    protected void setInputParts(List parts) throws WSIFException {
  +        this.inputParts = parts;
  +    }
  +
  +    /**
  +     * Sets the order of the inputParts.
  +     * @param partNames   A List of String part names in required order
  +     */
  +    protected void setInputPartOrder(List partNames) throws WSIFException {
  +        this.inputParts = setPartOrder(partNames, inputParts);
  +    }
  +
  +    /**
  +     * Gets the WSDL output message return part
  +     * By default the return part is the first part in the WSDL message
  +     */
  +    protected Part getReturnPart() {
  +        Part returnPart;
  +        if (outputParts.size() > 0) {
  +            returnPart = (Part) outputParts.get(0);
  +        } else {
  +            returnPart = null;
  +        }
  +        return returnPart;
  +    }
  +
  +    /**
  +     * Sets the WSDL output message return part
        */
  -    public ArrayList getInputParts() {
  -        return inputPartOrder;
  +    protected void SetReturnPart(String returnPartName) throws WSIFException {
  +        Part p = getNamedPart(returnPartName, outputParts);
  +        if (p != null) {
  +            SetReturnPart(p);
  +        } else {
  +            throw new WSIFException("part does not exist: " + returnPartName);
  +        }
       }
   
       /**
  -     * Returns the inputPartClasses.
  -     * @return HashMap
  +     * Sets the WSDL output message return part
        */
  -    public HashMap getInputPartClasses() {
  -        return inputPartsAndClasses;
  +    protected void SetReturnPart(Part returnPart) throws WSIFException {
  +        if (outputParts.contains(returnPart)) {
  +            outputParts.remove(returnPart);
  +            outputParts.add(0, returnPart);
  +        } else {
  +            throw new WSIFException("part does not exist: " + returnPart);
  +        }
       }
   
       /**
  -     * Returns the outputPartNames.
  +     * Returns the outputPartOrder.
        * @return ArrayList
        */
  -    public ArrayList getOutputParts() {
  -        return outputPartOrder;
  +    protected List getOutputParts() {
  +        return outputParts;
       }
   
       /**
  -     * Returns the outputPartClass.
  -     * @return HashMap
  +     * Sets the order of the outputParts.
  +     * @param partNames   A List of String part names in required order
        */
  -    public HashMap getOutputPartClasses() {
  -        return outputPartsAndClasses;
  +    protected void setOutputPartOrder(List partNames) throws WSIFException {
  +        this.outputParts = setPartOrder(partNames, outputParts);
  +    }
  +
  +    /**
  +     * Get a ordered list of WSDL Parts
  +     * 
  +     * @param partNames   a List of String part names
  +     * @param parts   a Map with WSDL Parts as the key 
  +     * @return List   of WSDL Parts in the same order 
  +     *                 as the partNames list
  +     */
  +    protected List setPartOrder(List partNames, List parts)
  +        throws WSIFException {
  +        List oldPartOrder = parts;
  +        if (partNames != null) {
  +            List newPartOrder = new ArrayList();
  +            for (Iterator i = partNames.iterator(); i.hasNext();) {
  +                String partName = (String) i.next();
  +                Part p = getNamedPart(partName, parts);
  +                if (p != null) {
  +                    newPartOrder.add(p);
  +                    oldPartOrder.remove(p);
  +                } else {
  +                    throw new WSIFException(
  +                        "part does not exists: " + partName);
  +                }
  +            }
  +            for (Iterator i = oldPartOrder.iterator(); i.hasNext();) {
  +                newPartOrder.add(i.next());
  +            }
  +            parts = newPartOrder;
  +        }
  +        return parts;
  +    }
  +
  +    /**
  +     * Find a named part from a list of WSDL Parts
  +     */
  +    protected Part getNamedPart(String partName, List parts) {
  +        Part part = null;
  +        for (Iterator i = parts.iterator(); part == null && i.hasNext();) {
  +            Part p = (Part) i.next();
  +            if (p.getName().equals(partName)) {
  +                part = p;
  +            }
  +        }
  +        return part;
  +    }
  +
  +    /**
  +     * Find a named part from a map with WSDL Parts as the key
  +     */
  +    protected Part getNamedPart(String partName, Map parts) {
  +        Part part = null;
  +        for (Iterator i = parts.keySet().iterator();
  +            part == null && i.hasNext();
  +            ) {
  +            Part p = (Part) i.next();
  +            if (p.getName().equals(partName)) {
  +                part = p;
  +            }
  +        }
  +        return part;
       }
   
       /**
  @@ -840,10 +1022,9 @@
           WSIFMessage contextCopy;
           try {
               if (this.context == null) {
  -                contextCopy = (WSIFMessage) wsifPort.getContext().clone();
  -            } else {
  -                contextCopy = (WSIFMessage) this.context.clone();
  +                this.context = (WSIFMessage) wsifPort.getContext().clone();
               }
  +            contextCopy = (WSIFMessage) context.clone();
           } catch (CloneNotSupportedException e) {
               throw new WSIFException(
                   "CloneNotSupportedException cloning context",
  @@ -869,6 +1050,31 @@
       }
   
       /**
  +     * Sets this WSIFOperations context message in the InvocationHelper 
  +     */
  +    protected void setInvocationContext() throws WSIFException {
  +        WSIFMessage ctxt = getContext();
  +        if (this.context == null) {
  +            getContext();
  +        }
  +        InvocationHelper.setMessageContext(context);
  +    }
  +
  +    /**
  +     * Mark the WSIFOperation as having invoked an operation
  +     * A WSIFOperation may only be used once by a client, but
  +     * ModelWSIFPort may cache a WSIFOperation for reuse and
  +     * will reset the used flag if a WSIFOperation is reused.
  +     */
  +    protected void markAsUsed() throws WSIFException {
  +        if (used == true) {
  +            throw new WSIFException("WSIFOperations has already been executed");
  +        } else {
  +            used = true;
  +        }
  +    }
  +
  +    /**
        * String representation of this WSIFOperation for WSIF Trc.
        */
       public String deep() {
  @@ -877,10 +1083,9 @@
           buff.append("portTypeOperation:" + Trc.brief(portTypeOperation));
           buff.append(", bindingOperation:" + Trc.brief(bindingOperation));
           buff.append(", wsifPort:" + wsifPort);
  -        buff.append(", inputPartOrder:" + inputPartOrder);
  -        buff.append(", outputPartOrder:" + outputPartOrder);
  -        buff.append(", inputPartsAndClasses:" + inputPartsAndClasses);
  -        buff.append(", outputPartsAndClasses:" + outputPartsAndClasses);
  +        buff.append(", used:" + used);
  +        buff.append(", inputParts:" + inputParts);
  +        buff.append(", outputParts:" + outputParts);
           buff.append(", asyncResponseHandler:" + asyncResponseHandler);
           buff.append(", context:" + context);
           return buff.toString();
  
  
  
  1.2       +377 -21   xml-axis-wsif/java/src/org/apache/wsif/providers/ModelWSIFPort.java
  
  Index: ModelWSIFPort.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/ModelWSIFPort.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ModelWSIFPort.java	1 May 2003 09:23:05 -0000	1.1
  +++ ModelWSIFPort.java	6 May 2003 08:57:37 -0000	1.2
  @@ -58,12 +58,17 @@
   package org.apache.wsif.providers;
   
   import java.util.HashMap;
  +import java.util.Iterator;
  +import java.util.List;
  +import java.util.Map;
   
   import javax.wsdl.BindingOperation;
   import javax.wsdl.Definition;
  +import javax.wsdl.Part;
   import javax.wsdl.Port;
   import javax.wsdl.Service;
   import javax.wsdl.extensions.ExtensibilityElement;
  +import javax.xml.namespace.QName;
   
   import org.apache.wsif.WSIFException;
   import org.apache.wsif.WSIFMessage;
  @@ -72,6 +77,8 @@
   import org.apache.wsif.base.WSIFDefaultMessage;
   import org.apache.wsif.logging.Trc;
   import org.apache.wsif.util.WSIFUtils;
  +import org.apache.wsif.wsdl.extensions.format.TypeMap;
  +import org.apache.wsif.wsdl.extensions.format.TypeMapping;
   
   /**
    * ModelWSIFPort
  @@ -87,6 +94,15 @@
    * should be done in the model code. Subclasses should only 
    * need to provide code directly related to accessing the
    * particular service type they implement.
  + * 
  + * For a subclass to use ModelWSIFPort, as a minimum it
  + * would implement the makeWSIFOperation method, and the
  + * getImplementedAddressClass and validateAddress methods
  + * to define and validate the WSDL port address extensibility
  + * element being used by the provider.  
  + * 
  + * Other methods may be overriden to customise the behaviour,
  + * see the method javadoc for details. 
    *  
    * @author Ant Elder <ant.elder@uk.ibm.com>
    */
  @@ -95,11 +111,20 @@
       protected Definition def;
       protected Service service;
       protected Port port;
  +
  +    transient protected WSIFMessage context;
  +
       protected WSIFDynamicTypeMap typeMap;
  +
       protected ExtensibilityElement binding;
  +
       protected boolean cacheOperations;
       transient protected HashMap cachedOperations;
  -    transient protected WSIFMessage context;
  +
  +    protected boolean autoTypeMappingSupported;
  +
  +    protected boolean formatBindingSupported;
  +    protected HashMap formatBindingTypes;
   
       /**
        * Construct a ModelWSIFPort
  @@ -128,13 +153,18 @@
           this.binding = binding;
           this.typeMap = typeMap;
   
  -        //        cacheOperations = wsifService.isCacheOperations();
  +        //TODO: autoTypeMappingSupported = wsifService.isAutoTypeMappingSupported();
  +        autoTypeMappingSupported = true;
  +
  +        //TODO: cacheOperations = wsifService.isCacheOperations();
           cacheOperations = true;
   
           if (cacheOperations == true) {
               cachedOperations = new HashMap();
           }
   
  +        formatBindingSupported = false;
  +
           if (Trc.ON) {
               Trc.exit(deep());
           }
  @@ -161,9 +191,8 @@
           Trc.entry(this, opName, inputName, outputName);
   
           ModelWSIFOperation wsifOp = null;
  -
           String cacheKey = null;
  -        ;
  +
           if (cacheOperations == true) {
               cacheKey =
                   new StringBuffer(opName)
  @@ -174,6 +203,7 @@
                       .toString();
               wsifOp = (ModelWSIFOperation) cachedOperations.get(cacheKey);
           }
  +
           if (wsifOp == null) {
               BindingOperation wsdlBindingOperation =
                   WSIFUtils.getBindingOperation(
  @@ -207,6 +237,22 @@
       }
   
       /**
  +     * Returns the autoTypeMappingSupported.
  +     * @return boolean
  +     */
  +    protected boolean isAutoTypeMappingSupported() {
  +        return autoTypeMappingSupported;
  +    }
  +
  +    /**
  +     * Sets the autoTypeMappingSupported.
  +     * @param autoTypeMappingSupported The autoTypeMappingSupported to set
  +     */
  +    protected void setAutoTypeMappingSupported(boolean autoTypeMappingSupported) {
  +        this.autoTypeMappingSupported = autoTypeMappingSupported;
  +    }
  +
  +    /**
        * Returns the cacheOperations.
        * @return boolean
        */
  @@ -223,7 +269,7 @@
       }
   
       /**
  -     * Returns the binding.
  +     * Returns the binding ExtensibilityElement.
        * @return ExtensibilityElement
        */
       public ExtensibilityElement getBinding() {
  @@ -231,7 +277,7 @@
       }
   
       /**
  -     * Returns the def.
  +     * Returns the WSDL Definition object
        * @return Definition
        */
       public Definition getDefinition() {
  @@ -239,7 +285,7 @@
       }
   
       /**
  -     * Returns the port.
  +     * Returns the WSDL port.
        * @return Port
        */
       public Port getPort() {
  @@ -247,7 +293,7 @@
       }
   
       /**
  -     * Returns the service.
  +     * Returns the WSDL service.
        * @return Service
        */
       public Service getService() {
  @@ -268,20 +314,19 @@
        */
       public WSIFMessage getContext() throws WSIFException {
           Trc.entry(this);
  +        if (context == null) {
  +            // TODO: really this should call getContext on the WSIFService but
  +            // theres no reference to that so it has to rely on WSIFService
  +            // should call setContext on any WSIFPort it creates.
  +            this.context = new WSIFDefaultMessage();
  +        }
           WSIFMessage contextCopy;
  -        if (this.context == null) {
  -            // really this should call getContext on the WSIFService but
  -            // theres no reference to that so WSIFService must call setContext
  -            // on any WSIFPorts it creates.
  -            contextCopy = new WSIFDefaultMessage();
  -        } else {
  -            try {
  -                contextCopy = (WSIFMessage) this.context.clone();
  -            } catch (CloneNotSupportedException e) {
  -                throw new WSIFException(
  -                    "CloneNotSupportedException cloning context",
  -                    e);
  -            }
  +        try {
  +            contextCopy = (WSIFMessage) this.context.clone();
  +        } catch (CloneNotSupportedException e) {
  +            throw new WSIFException(
  +                "CloneNotSupportedException cloning context: ",
  +                e);
           }
           Trc.exit(contextCopy);
           return contextCopy;
  @@ -322,6 +367,25 @@
           return false;
       }
   
  +    /**
  +     * Returns the formatBindingSupported.
  +     * @return boolean
  +     */
  +    public boolean isFormatBindingSupported() {
  +        return formatBindingSupported;
  +    }
  +
  +    /**
  +     * Sets the formatBindingSupported.
  +     * @param formatBindingSupported The formatBindingSupported to set
  +     */
  +    protected void setFormatBindingSupported(boolean formatBindingSupported) {
  +        this.formatBindingSupported = formatBindingSupported;
  +    }
  +
  +    /**
  +     * Override java.lang.Object finalize method to close the WSIFPort
  +     */
       public void finalize() throws Throwable {
           Trc.entry(this);
           try {
  @@ -333,6 +397,286 @@
           Trc.exit();
       }
   
  +    /**
  +     * Gets the Java class for a WSDL part 
  +     * TODO: what should format binding mappings take preference, should 
  +     *      there be a way to disbale auto type mapping?
  +     */
  +    protected Class getClassForPart(Part p) throws WSIFException {
  +        QName partType = ProviderUtils.getPartType(p);
  +
  +        Class partClass = null;
  +
  +        // first see if there's format binding mapping
  +        if (partClass == null && isFormatBindingSupported() == true) {
  +            partClass = getFormatBindingType(partType);
  +        }
  +
  +        if (isFormatBindingSupported() == false
  +            || isAutoTypeMappingSupported() == true) {
  +
  +            // see if there's a WSIFDynamicTypeMap mapping
  +            partClass = getDynamicTypeClass(partType);
  +
  +            // perhaps a known standard type
  +            if (partClass == null) {
  +                partClass = getStandardType(partType);
  +            }
  +
  +            // try a default name?
  +            if (partClass == null) {
  +                // TODO: should there be a default? partClass = getDefaultType(partType);
  +            }
  +        }
  +
  +        // handle unknown type 
  +        if (partClass == null) {
  +            partClass = doNoClassForPart(partType, p);
  +        }
  +
  +        return partClass;
  +    }
  +
  +    /**
  +     * Process a part where the Java class for the part type is unknown
  +     * Defaults to just throwing an exception, subclasses may override
  +     * with their own implementation 
  +     */
  +    protected Class doNoClassForPart(QName partType, Part p)
  +        throws WSIFException {
  +        throw new WSIFException("cannot determine class for type: " + partType);
  +    }
  +
  +    /**
  +     * Gets the Java class for a type from the WSIFDynamicTypeMap
  +     */
  +    protected Class getDynamicTypeClass(QName partType) {
  +        Class partClass = null;
  +        for (Iterator i = typeMap.iterator();
  +            partClass == null && i.hasNext();
  +            ) {
  +
  +            WSIFDynamicTypeMapping mapping = (WSIFDynamicTypeMapping) i.next();
  +            if (partType.equals(mapping.getXmlType())) {
  +                partClass = mapping.javaType;
  +            }
  +        }
  +
  +        return partClass;
  +    }
  +
  +    /**
  +     * Gets the Java class for a type from the WSDL format binding typeMap
  +     */
  +    protected Class getFormatBindingType(QName partType) throws WSIFException {
  +        Class partClass = null;
  +
  +        if (formatBindingTypes == null && isFormatBindingSupported()) {
  +            initializeFormatBindingTypes();
  +        }
  +
  +        if (formatBindingTypes != null) {
  +            for (Iterator i = formatBindingTypes.keySet().iterator();
  +                partClass == null && i.hasNext();
  +                ) {
  +
  +                QName fbType = (QName) i.next();
  +                if (fbType.equals(partType)) {
  +                    partClass = (Class) formatBindingTypes.get(partType);
  +                }
  +            }
  +        }
  +
  +        return partClass;
  +    }
  +
  +    /**
  +     * Gets the Java class for a known type
  +     * A known type is a standard Java type like java.lang.String
  +     */
  +    protected Class getStandardType(QName partType) throws WSIFException {
  +        Class partClass = null;
  +        Map simpleTypes = WSIFUtils.getSimpleTypesMap();
  +        String className = (String) simpleTypes.get(partType);
  +
  +        //TODO: how to do this???
  +        //      classname is something like "int", "[B", or "java.lang.String" 
  +        //      hack...
  +        if (className != null && className.length() > 0) {
  +            char c = className.charAt(0);
  +            if (className.indexOf('.') < 0 && Character.isLowerCase(c)) {
  +                partClass = getPrimitiveClass(className);
  +            } else if ('[' == c) {
  +                partClass = getArrayClass(className);
  +            } else {
  +                partClass = getClassForType(className);
  +            }
  +        }
  +        return partClass;
  +    }
  +
  +    /**
  +     * Gets the Java class for the named primitive type
  +     * TODO: usesthe wrapper classes, does this matter?  
  +     */
  +    protected Class getPrimitiveClass(String primitiveName) {
  +        Class javaClass = null;
  +        if (primitiveName.equals("int")) {
  +            javaClass = Integer.class;
  +        } else if (primitiveName.equals("float")) {
  +            javaClass = Float.class;
  +        } else if (primitiveName.equals("double")) {
  +            javaClass = Double.class;
  +        } else if (primitiveName.equals("boolean")) {
  +            javaClass = Boolean.class;
  +        } else if (primitiveName.equals("long")) {
  +            javaClass = Long.class;
  +        } else if (primitiveName.equals("short")) {
  +            javaClass = Short.class;
  +        } else if (primitiveName.equals("byte")) {
  +            javaClass = Byte.class;
  +        } else if (primitiveName.equals("void")) {
  +            javaClass = Void.class;
  +        }
  +        return javaClass;
  +    }
  +
  +    protected Class getArrayClass(String type) {
  +        Class typeClass = null;
  +        //TODO:
  +        return typeClass;
  +    }
  +
  +    /**
  +     * Gets a Java class object from the fully qualified String className  
  +     */
  +    protected Class getClassForType(String className) throws WSIFException {
  +        Class clazz = null;
  +        try {
  +            ClassLoader cl = Thread.currentThread().getContextClassLoader();
  +            clazz = Class.forName(className, true, cl);
  +        } catch (Throwable ex) {
  +            throw new WSIFException(
  +                "exception getting class for simple type '"
  +                    + clazz
  +                    + "': "
  +                    + ex);
  +        }
  +        return clazz;
  +    }
  +
  +    /**
  +     * Builds the type map from the WSDL format binding.
  +     * The formatBindingTypes is a HashTable with the key
  +     * a type QName, and the value a Java class.
  +     * 
  +     * The format binding has the form:
  +     * <format:typeMapping style="uri" encoding="..."/>?
  +     *    <format:typeMap typeName="qname"|elementName="qname" formatType="nmtoken"/>*
  +     * </format:typeMapping> 
  +     * 
  +     * TODO: what are the valid style, enocoding to support?
  +     * TODO: need to make this more pluggable - JMS provider uses diff styles
  +     */
  +    protected void initializeFormatBindingTypes() throws WSIFException {
  +        Trc.entry(this);
  +
  +        TypeMapping typeMapping = getFormatTypeMapping();
  +        if (typeMapping == null) {
  +            doMissingFormatTypeMapping();
  +        }
  +
  +        // Build the formatBindingTypes hashmap 
  +        formatBindingTypes = new HashMap();
  +        if (typeMapping != null) {
  +            List typeMaps = typeMapping.getMaps();
  +            for (Iterator i = typeMaps.iterator(); i.hasNext();) {
  +                TypeMap typeMap = (TypeMap) i.next();
  +                QName typeName = typeMap.getTypeName();
  +                if (typeName == null) {
  +                    typeName = typeMap.getElementName();
  +                }
  +                String className = typeMap.getFormatType();
  +                Class typeClass = getNamedClass(className);
  +                if (typeName != null && typeClass != null) {
  +                    //TODO: should duplicate mappings be allowed?              	
  +                    this.formatBindingTypes.put(typeName, typeClass);
  +                } else {
  +                    throw new WSIFException("Error in binding TypeMap. Key or Value is null");
  +                }
  +            }
  +        }
  +        Trc.exit();
  +    }
  +
  +    /**
  +     * Gets the format:typeMapping ExtensibilityElement from the WSDL
  +     */
  +    protected TypeMapping getFormatTypeMapping() {
  +        TypeMapping typeMapping = null;
  +
  +        // Get the TypeMappings from the binding
  +        Iterator bindingIterator =
  +            this.port.getBinding().getExtensibilityElements().iterator();
  +
  +        // Choose the first typeMap that has encoding=Java and style=Java. 
  +        // Ignore any other typeMap's that have other encodings and styles.
  +        while (bindingIterator.hasNext()) {
  +            Object next = bindingIterator.next();
  +            if (next instanceof TypeMapping) {
  +                typeMapping = (TypeMapping) next;
  +                if ("Java".equals(typeMapping.getEncoding())
  +                    && "Java".equals(typeMapping.getStyle())) {
  +                    break;
  +                }
  +                typeMapping = null;
  +            }
  +        }
  +        return typeMapping;
  +    }
  +
  +    /**
  +     * Handles the case where there is no format binding in the WSDL
  +     * This does nothing, subclasses may override
  +     */
  +    protected void doMissingFormatTypeMapping() throws WSIFException {
  +        //TODO: maybe it should throw an exception by default?
  +    }
  +
  +    /**
  +     * Finds the Java class object for the String class name
  +     */
  +    protected Class getNamedClass(String className) throws WSIFException {
  +        Class clazz = null;
  +        try {
  +            ClassLoader cl = Thread.currentThread().getContextClassLoader();
  +            clazz = Class.forName(className, true, cl);
  +        } catch (Throwable ex) {
  +            Trc.exception(ex);
  +            doUnknownClassName(className);
  +        }
  +        return clazz;
  +    }
  +
  +    /**
  +     * Handles case where the class named in the WSDL formatType is not found
  +     * This just throws an exception, subclasses may override
  +     */
  +    protected void doUnknownClassName(String className) throws WSIFException {
  +        throw new WSIFException(
  +            "can not find Java class for formatType: " + className);
  +    }
  +
  +    /**
  +     * Initialise the WSIFPort
  +     * This is called after the constructor has run and
  +     * all extensebility elements have been validated 
  +     * (ie validateAddress has been called). This default
  +     * implementation does nothing, subclasses may override.
  +     */
  +    protected void doInitialize() throws WSIFException {
  +    }
  +
       // the methods subclasses must implement
   
       abstract protected ModelWSIFOperation makeWSIFOperation(
  @@ -359,10 +703,22 @@
           buff.append(Trc.brief(service));
           buff.append(" portModel:");
           buff.append(Trc.brief(port));
  +        buff.append(" context:");
  +        buff.append(context);
           buff.append(" typeMap:");
           buff.append(typeMap);
           buff.append(" binding:");
           buff.append(binding);
  +        buff.append(" autoTypeMappingSupported:");
  +        buff.append(autoTypeMappingSupported);
  +        buff.append(" cacheOperations:");
  +        buff.append(cacheOperations);
  +        buff.append(" cachedOperations:");
  +        buff.append(cachedOperations);
  +        buff.append(" formatBindingSupported:");
  +        buff.append(formatBindingSupported);
  +        buff.append(" formatBindingTypes:");
  +        buff.append(formatBindingTypes);
           return buff.toString();
       }
   
  
  
  
  1.3       +3 -4      xml-axis-wsif/java/src/org/apache/wsif/providers/ModelWSIFProvider.java
  
  Index: ModelWSIFProvider.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/ModelWSIFProvider.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ModelWSIFProvider.java	1 May 2003 09:23:05 -0000	1.2
  +++ ModelWSIFProvider.java	6 May 2003 08:57:37 -0000	1.3
  @@ -200,6 +200,7 @@
                       + addressClass.getName());
           }
           wsifPort.validateAddress(addrEE);
  +        wsifPort.doInitialize();
       }
   
       /**
  @@ -269,12 +270,10 @@
                       .newInstance();
           } catch (InstantiationException e) {
               throw new WSIFException(
  -                "InstantiationException creating binding: "
  -                    + e.getLocalizedMessage());
  +                "InstantiationException creating binding: " + e);
           } catch (IllegalAccessException e) {
               throw new WSIFException(
  -                "IllegalAccessException creating binding: "
  -                    + e.getLocalizedMessage());
  +                "IllegalAccessException creating binding: " + e);
           }
           return new String[] { binding.getElementType().getNamespaceURI()};
       }
  
  
  
  1.1                  xml-axis-wsif/java/src/org/apache/wsif/providers/Part.java
  
  Index: Part.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2002 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 "WSIF" 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 and was
   * originally based on software copyright (c) 2001, 2002, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.wsif.providers;
  
  import java.io.Serializable;
  
  import javax.xml.namespace.QName;
  
  import org.apache.wsif.logging.Trc;
  
  /**
   * WSIF representation of a WSDL Part
   *  
   * @author <a href="mailto:ant.elder@uk.ibm.com">Ant Elder</a>
   */
  public class Part implements Serializable {
  
      protected javax.wsdl.Part wsdlPart;
  
      protected QName type;
      protected Class javaClass;
      protected Object value;
  
      /**
       * Construct a new Part
       */
      protected Part(javax.wsdl.Part wsdlPart) {
          Trc.entry(this);
          if (wsdlPart == null) {
              throw new IllegalArgumentException("wsdlPart is null");
          }
  
          this.wsdlPart = wsdlPart;
  
          Trc.exit();
      }
  
      /**
       * Returns the name of the Part.
       * @return String
       */
      public String getName() {
          return wsdlPart.getName();
      }
  
      /**
       * Returns the type of the Part.
       * @return QName
       */
      public QName getType() {
          if (type == null) {
              type = ProviderUtils.getPartType(wsdlPart);
          }
          return type;
      }
  
      /**
       * Returns the javaClass the Part type represents.
       * @return Class
       */
      public Class getJavaClass() {
          return javaClass;
      }
  
      /**
       * Sets the javaClass the Part type represents.
       * @param javaClass The javaClass to set
       */
      public void setJavaClass(Class javaClass) {
          this.javaClass = javaClass;
      }
  
      /**
       * Returns the wsdlPart object for the part.
       * @return javax.wsdl.Part
       */
      public javax.wsdl.Part getWsdlPart() {
          return wsdlPart;
      }
  
      /**
       * Returns the value.
       * @return Object
       */
      public Object getValue() {
          return value;
      }
  
      /**
       * Sets the value.
       * @param value The value to set
       */
      public void setValue(Object value) {
          this.value = value;
      }
  
  }
  
  
  
  1.2       +1 -0      xml-axis-wsif/java/test/models/javaProvider/JavaWSIFPort.java
  
  Index: JavaWSIFPort.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/models/javaProvider/JavaWSIFPort.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JavaWSIFPort.java	1 May 2003 09:50:24 -0000	1.1
  +++ JavaWSIFPort.java	6 May 2003 08:57:37 -0000	1.2
  @@ -87,6 +87,7 @@
       public JavaWSIFPort(Definition def, Port port, WSIFDynamicTypeMap typeMap)
           throws WSIFException {
           super(def, port, typeMap);
  +        setFormatBindingSupported(true);
       }
   
       protected ModelWSIFOperation makeWSIFOperation(
  
  
  
  1.2       +49 -31    xml-axis-wsif/java/test/models/javaProvider/JavaWSIFOperation.java
  
  Index: JavaWSIFOperation.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/models/javaProvider/JavaWSIFOperation.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JavaWSIFOperation.java	1 May 2003 09:50:24 -0000	1.1
  +++ JavaWSIFOperation.java	6 May 2003 08:57:37 -0000	1.2
  @@ -59,6 +59,7 @@
   
   import java.lang.reflect.Method;
   import java.util.ArrayList;
  +import java.util.Arrays;
   import java.util.List;
   
   import javax.wsdl.BindingOperation;
  @@ -74,46 +75,70 @@
    */
   public class JavaWSIFOperation extends ModelWSIFOperation {
   
  -    protected JavaOperation javaOperation;
  +    protected String methodName;
  +    protected String methodType;
  +
  +    protected static final ArrayList validMethodTypes =
  +        new ArrayList(
  +            Arrays.asList(
  +                new String[] { "instance", "static", "constructor" }));
   
       public JavaWSIFOperation(ModelWSIFPort wsifPort, BindingOperation bop)
           throws WSIFException {
           super(wsifPort, bop);
       }
   
  -    protected Class getOperationExtensabilityClass() {
  +    protected Class getOperationExtensibilityClass() {
           return JavaOperation.class;
       }
   
  -    protected void validateOperationExtensibilityElement(ExtensibilityElement javaOperation)
  +    protected void validateOperationExtensibilityElement(ExtensibilityElement ee)
           throws WSIFException {
  -        this.javaOperation = (JavaOperation) javaOperation;
  +        JavaOperation javaOperation = (JavaOperation) ee;
  +
  +        this.methodName = javaOperation.getMethodName();
  +        if (methodName == null || methodName.length() < 1) {
  +            methodName = bindingOperation.getName();
  +        }
  +
  +        this.methodType = javaOperation.getMethodType();
  +        if (methodType == null || methodType.length() < 1) {
  +            methodType = "instance";
  +        } else if (!validMethodTypes.contains(methodType)) {
  +            throw new WSIFException("invalid methodType: " + methodType);
  +        }
  +
  +        List partNames = javaOperation.getParameterOrder();
  +        if (partNames != null) {
  +            setInputPartOrder(partNames);
  +        }
  +
  +        String returnPartName = javaOperation.getReturnPart();
  +        if (returnPartName != null && returnPartName.length() > 0) {
  +            SetReturnPart(returnPartName);
  +        }
  +
       }
   
  -    protected boolean doInvoke(ArrayList inputArgs, ArrayList responseArgs)
  +    protected boolean doInvokeRequestResponse(List inputArgs, List responseArgs)
           throws WSIFException {
           boolean workedOK = false;
   
  -        JavaWSIFPort p = (JavaWSIFPort) wsifPort;
  -
  -        Method m = getMethod();
  -
           Object target;
  -        if ("static".equalsIgnoreCase(javaOperation.getMethodType())) {
  +        if ("static".equalsIgnoreCase(methodType)) {
               target = null;
           } else {
  -            target = p.getObjectReference();
  +            target = ((JavaWSIFPort) wsifPort).getObjectReference();
           }
   
           Object response;
           try {
  -            response = m.invoke(target, inputArgs.toArray());
  +            response = getMethod().invoke(target, inputArgs.toArray());
           } catch (Throwable e) {
               throw new WSIFException(
                   "exception invoking method: " + e.getLocalizedMessage(),
                   e);
           }
  -        
   
           responseArgs.add(response);
           workedOK = true;
  @@ -127,37 +152,30 @@
           JavaWSIFPort p = (JavaWSIFPort) wsifPort;
           Method[] methods = p.getServiceObjectMethods();
           for (int i = 0; method == null && i < methods.length; i++) {
  -            if (methods[i].getName().equals(javaOperation.getMethodName())) {
  -            	if (isMethodArgsOK(methods[i])) {
  +            if (methods[i].getName().equals(methodName)) {
  +                if (isMethodArgsOK(methods[i])) {
                       method = methods[i];
  -            	}
  +                }
               }
           }
   
           if (method == null) {
               throw new WSIFException(
  -                "no method on target object named: "
  -                    + javaOperation.getMethodName());
  +                "no method on target object named: " + methodName);
           }
   
           return method;
       }
   
       protected boolean isMethodArgsOK(Method m) throws WSIFException {
  -    	boolean ok = false;
  -    	
  -        JavaWSIFPort p = (JavaWSIFPort) wsifPort;
  -    	List argNames = javaOperation.getParameterOrder();
  -    	if (argNames == null) {
  -    		argNames = getInputParts();
  -    	}
  -
  -        if (m.getParameterTypes().length == argNames.size()) {
  -        	//TODO:
  -        	ok = true;
  +        boolean ok = false;
  +
  +        if (m.getParameterTypes().length == getInputParts().size()) {
  +            //TODO: check types
  +            ok = true;
           }
  -    	
  -    	return ok;
  +
  +        return ok;
       }
   
   }
  
  
  

Mime
View raw message