You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsif-dev@ws.apache.org by an...@apache.org on 2003/05/01 11:23:06 UTC

cvs commit: xml-axis-wsif/java/src/org/apache/wsif/providers ModelWSIFOperation.java ModelWSIFPort.java ModelWSIFProvider.java

antelder    2003/05/01 02:23:06

  Modified:    java/src/org/apache/wsif/providers ModelWSIFProvider.java
  Added:       java/src/org/apache/wsif/providers ModelWSIFOperation.java
                        ModelWSIFPort.java
  Log:
  More models
  
  Revision  Changes    Path
  1.2       +45 -14    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ModelWSIFProvider.java	17 Apr 2003 13:53:19 -0000	1.1
  +++ ModelWSIFProvider.java	1 May 2003 09:23:05 -0000	1.2
  @@ -79,6 +79,18 @@
   /**
    * Model super class for a WSIFProvider
    * 
  + * Models are provided for all the classes required to 
  + * be implemented when writing a WSIF provider: 
  + * 			WSIFProvider, WSIFPort, and WSIFOperation. 
  + * The models are intended to simplify the work in the
  + * implementing subclasses, and insure that all providers
  + * work in standard way. Things like hunting around in 
  + * the WSDL for ExtensabilityElements and verifying the 
  + * types of request and response objects against the WSDL
  + * should be done in the model code. Subclasses should only 
  + * need to provide code directly related to accessing the
  + * particular service type they implement.
  + *  
    * @author <a href="mailto:ant.elder@uk.ibm.com">Ant Elder</a>
    */
   public abstract class ModelWSIFProvider implements WSIFProvider {
  @@ -149,34 +161,54 @@
               throw new WSIFException("getImplementedBindingClass must return a subclass of ExtensibilityElement");
           }
   
  -        WSIFPort wsifPort = null;
  +        ModelWSIFPort wsifPort = null;
           Binding binding = port.getBinding();
   
           List l = binding.getExtensibilityElements();
  -        for (Iterator i = l.iterator(); i.hasNext() && wsifPort == null;) {
  +        for (Iterator i = l.iterator(); wsifPort == null && i.hasNext();) {
               Object o = i.next();
               if (bindingClass.isAssignableFrom(o.getClass())) {
  -                wsifPort =
  -                    makeWSIFPort(
  -                        def,
  -                        service,
  -                        port,
  -                        typeMap,
  -                        (ExtensibilityElement) o);
  +                ExtensibilityElement ee = (ExtensibilityElement) o;
  +                wsifPort = makeWSIFPort(def, service, port, typeMap, ee);
               }
           }
   
  +        if (wsifPort != null) {
  +            initializeWSIFPort(port, wsifPort);
  +        }
  +
           Trc.exit(wsifPort);
           return wsifPort;
       }
   
  +    protected void initializeWSIFPort(Port port, ModelWSIFPort wsifPort)
  +        throws WSIFException {
  +        Class addressClass = wsifPort.getImplementedAddressClass();
  +        ExtensibilityElement addrEE = null;
  +        List portEEs = port.getExtensibilityElements();
  +        for (Iterator i = portEEs.iterator(); addrEE == null && i.hasNext();) {
  +            ExtensibilityElement ee = (ExtensibilityElement) i.next();
  +            if (addressClass.isAssignableFrom(ee.getClass())) {
  +                addrEE = ee;
  +            }
  +        }
  +        if (addrEE == null) {
  +            throw new WSIFException(
  +                "port '"
  +                    + port
  +                    + "' missing address ExtensibilityElement: "
  +                    + addressClass.getName());
  +        }
  +        wsifPort.validateAddress(addrEE);
  +    }
  +
       /**
        * Factory method to create a WSIFPort.
        * By default this calls the short form of makeWSIFPort
        * which takes only a Definition, Port and WSIFDynamicType.
        * Subclass may override this implementation if required. 
        */
  -    protected WSIFPort makeWSIFPort(
  +    protected ModelWSIFPort makeWSIFPort(
           Definition def,
           Service service,
           Port port,
  @@ -266,8 +298,7 @@
               for (int i = 0; classesAvailable && i < classes.length; i++) {
                   final String className = classes[i];
                   Class c =
  -                    (
  -                        Class) AccessController
  +                    (Class) AccessController
                               .doPrivileged(new PrivilegedAction() {
                       public Object run() {
                           try {
  @@ -315,12 +346,12 @@
       /**
        * Returns a tooling BindingGenerator for the provider
        */
  -    abstract public BindingGenerator getBindingGenerator();
  +    abstract public BindingGenerator[] getBindingGenerators();
   
       /**
        * Factory method for providers to make a WSIFPort
        */
  -    abstract protected WSIFPort makeWSIFPort(
  +    abstract protected ModelWSIFPort makeWSIFPort(
           Definition def,
           Port port,
           WSIFDynamicTypeMap typeMap)
  
  
  
  1.1                  xml-axis-wsif/java/src/org/apache/wsif/providers/ModelWSIFOperation.java
  
  Index: ModelWSIFOperation.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.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;
  import org.apache.wsif.WSIFException;
  import org.apache.wsif.WSIFMessage;
  import org.apache.wsif.WSIFOperation;
  import org.apache.wsif.WSIFResponseHandler;
  import org.apache.wsif.base.WSIFDefaultMessage;
  import org.apache.wsif.logging.Trc;
  import org.apache.wsif.util.WSIFUtils;
  
  /**
   * ModelWSIFOperation
   * 
   * Models are provided for all the classes required to 
   * be implemented when writing a WSIF provider: 
   * 			WSIFProvider, WSIFPort, and WSIFOperation. 
   * The models are intended to simplify the work in the
   * implementing subclasses, and insure that all providers
   * work in standard way. Things like hunting around in 
   * the WSDL for ExtensabilityElements and verifying the 
   * types of request and response objects against the WSDL
   * should be done in the model code. Subclasses should only 
   * need to provide code directly related to accessing the
   * particular service type they implement.
   *  
   * @author <a href="mailto:antelder@apache.org">Ant Elder</a>
   */
  abstract public class ModelWSIFOperation implements WSIFOperation {
  
      protected ModelWSIFPort wsifPort;
      protected BindingOperation bindingOperation;
      protected Operation portTypeOperation;
  
      protected ArrayList inputPartOrder;
      protected ArrayList outputPartOrder;
      protected HashMap inputPartsAndClasses;
      protected HashMap outputPartsAndClasses;
  
      protected WSIFResponseHandler asyncResponseHandler;
  
      protected WSIFMessage context;
      transient protected List autoMappedTypes;
  
      /**
       * Construct a ModelWSIFOperation
       */
      public ModelWSIFOperation(
          ModelWSIFPort wsifPort,
          BindingOperation bindingOperation)
          throws WSIFException {
  
          this.wsifPort = wsifPort;
          this.bindingOperation = bindingOperation;
  
      }
  
      /**
       * @see WSIFOperation#executeInputOnlyOperation(WSIFMessage)
       */
      public void executeInputOnlyOperation(WSIFMessage inMsg)
          throws WSIFException {
          Trc.entry(this, inMsg);
  
          if (inMsg == null) {
              throw new IllegalArgumentException("input message is null");
          }
  
          invokeInputOnlyOperation(inMsg);
  
          Trc.exit();
      }
  
      /**
       * @see WSIFOperation#executeInputOnlyOperation(WSIFMessage,WSIFMessage,WSIFMessage)
       */
      public boolean executeRequestResponseOperation(
          WSIFMessage inMsg,
          WSIFMessage outMsg,
          WSIFMessage faultMsg)
          throws WSIFException {
          Trc.entry(this, inMsg, outMsg, faultMsg);
  
          if (wsifPort.supportsSync() == false) {
              throw new WSIFException("synchronus operations not supported");
          }
  
          if (inMsg == null) {
              throw new IllegalArgumentException("input message is null");
          }
          if (outMsg == null) {
              throw new IllegalArgumentException("output message is null");
          }
          if (faultMsg == null) {
              throw new IllegalArgumentException("fault message is null");
          }
  
          boolean ok = invokeRequestResponseOperation(inMsg, outMsg, faultMsg);
  
          Trc.exit(ok);
          return ok;
      }
  
      /**
       * 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);
  
          if (wsifPort.supportsAsync() == false) {
              throw new WSIFException("asynchronous operations not supportted");
          }
  
          if (inMsg == null) {
              throw new IllegalArgumentException("input message is null");
          }
  
          WSIFCorrelationId cid = invokeRequestResponseAsync(inMsg, null);
  
          Trc.exit(cid);
          return cid;
      }
  
      /**
       * 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(
          WSIFMessage inMsg,
          WSIFResponseHandler handler)
          throws WSIFException {
          Trc.entry(this, inMsg, handler);
  
          if (wsifPort.supportsAsync() == false) {
              throw new WSIFException("asynchronous operations not supportted");
          }
  
          if (inMsg == null) {
              throw new IllegalArgumentException("input message is null");
          }
  
          if (handler == null) {
              throw new IllegalArgumentException("WSIFResponseHandler is null");
          }
  
          WSIFCorrelationId cid = invokeRequestResponseAsync(inMsg, handler);
  
          Trc.exit(cid);
          return cid;
      }
  
      /**
       * 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);
  
          if (wsifPort.supportsAsync() == false) {
              throw new WSIFException("asynchronous operations not supportted");
          }
  
          if (asyncResponseHandler == null) {
              throw new WSIFException("asyncResponseHandler is null!");
          }
  
          Map results = doDeserialiseResponse(response);
  
          WSIFMessage outMsg = createOutputMessage();
          WSIFMessage faultMsg = createFaultMessage();
  
          buildResponseMessages(results, outMsg, faultMsg);
  
          asyncResponseHandler.executeAsyncResponse(outMsg, faultMsg);
  
          Trc.exit();
      }
  
      /**
       * 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(
          Object response,
          WSIFMessage outMsg,
          WSIFMessage faultMsg)
          throws WSIFException {
          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);
      }
  
      protected boolean invokeRequestResponseOperation(
          WSIFMessage inMsg,
          WSIFMessage outMsg,
          WSIFMessage faultMsg)
          throws WSIFException {
  
          boolean invokedOK = false;
  
          ArrayList inputArgs = getInputObjects(inMsg);
          ArrayList responseValues = new ArrayList();
  
          invokedOK = doInvoke(inputArgs, responseValues);
  
          if (invokedOK == true) {
              if (outMsg != null) {
                  setResponseObjects(outMsg, responseValues);
              }
          } else {
              if (faultMsg != null) {
                  setFaultObjects(faultMsg, responseValues);
              }
          }
  
          return invokedOK;
      }
      protected WSIFCorrelationId invokeRequestResponseAsync(
          WSIFMessage inMsg,
          WSIFResponseHandler handler)
          throws WSIFException {
  
          ArrayList inputArgs = getInputObjects(inMsg);
  
          WSIFCorrelationId cid = doInvokeAsync(inputArgs);
  
          return cid;
      }
  
      protected Map doDeserialiseResponse(Object response) throws WSIFException {
          throw new WSIFException("doDeserialiseResponse must be implemented by subclass!");
      }
  
      protected void buildResponseMessages(
          Map results,
          WSIFMessage outMsg,
          WSIFMessage faultMsg)
          throws WSIFException {
          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();) {
              Part part = (Part) i.next();
              Object partValue;
              try {
                  partValue = msg.getObjectPart(part.getName());
              } catch (WSIFException e) {
                  partValue = doMissingInputPart(msg, part.getName());
              }
              Class partClass = (Class) inputPartsAndClasses.get(part.getName());
              validatePartValue(part, partClass, partValue);
              objects.add(partValue);
          }
  
          return objects;
      }
  
      protected Object doMissingInputPart(WSIFMessage msg, String partName) {
          Trc.event(
              this,
              "message "
                  + msg.getName()
                  + "has missing input part '"
                  + partName
                  + "', defaulting to null");
          return null;
      }
  
      protected void validatePartValue(Part part, Class partClass, Object value)
          throws WSIFException {
          if (value != null) {
              Class valueClass = value.getClass();
              if (partClass.isAssignableFrom(valueClass)) {
                  // type ok
              } else if ("javax.activation.DataHandler".equals(valueClass)) {
                  //TODO: what to do about DataHandler? 
                  //      for now type ok
              } else {
                  throw new WSIFException(
                      "WSIFMessage part '"
                          + part.getName()
                          + "' has invalid type, expecting "
                          + partClass
                          + " 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.
       * 
       * Subclasses would not normally override this but 
       * should override the doInitialise method.
       */
      protected void initialise() throws WSIFException {
          if (inputPartOrder == null) {
              prepare();
          }
          doInitialise();
      }
  
      /**
       * Initialises the WSIFOperation.
       * This will be called when the WSIFOperation is first created,
       * or when a cached WSIFOperation is about to be reused. 
       * The default implementation does nothing, subclasses may
       * override it if they need to do something before reuse.
       */
      protected void doInitialise() {
      }
  
      /**
       * This sets up the WSIFOperation from the WSDL including:
       * - do any unwrapping of parameters if required
       * - finding the names and types of the input/output
       *   parameters
       */
      protected void prepare() throws WSIFException {
  
          this.inputPartOrder = new ArrayList();
          this.outputPartOrder = new ArrayList();
          this.inputPartsAndClasses = new HashMap();
          this.outputPartsAndClasses = new HashMap();
  
          Operation op = getPortTypeOperation();
  
          try {
              WSIFMessage context = getContext();
              autoMappedTypes =
                  (List) context.getObjectPart(
                      WSIFConstants.CONTEXT_SCHEMA_TYPES);
          } catch (WSIFException e) {
              autoMappedTypes = null;
          }
  
          boolean unwrap = ProviderUtils.isUnwrapable(op);
          if (unwrap == true) {
              // don't unwrap if context asks not to
              unwrap = !isWrappedInContext();
          }
  
          if (op.getInput() != null) {
              Message inMsg = op.getInput().getMessage();
              initialiseParts(
                  inMsg,
                  unwrap,
                  inputPartOrder,
                  inputPartsAndClasses);
          }
  
          if (op.getOutput() != null) {
              Message outMsg = op.getOutput().getMessage();
              initialiseParts(
                  outMsg,
                  unwrap,
                  outputPartOrder,
                  outputPartsAndClasses);
          }
  
          Class c = getOperationExtensabilityClass();
          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;
              	} 
              }
              
              if (ee !=null) {
              	validateOperationExtensibilityElement(ee);
              }
  
          }
      }
  
      protected Class getOperationExtensabilityClass() {
          return null;
      }
  
      protected void validateOperationExtensibilityElement(ExtensibilityElement address)
          throws WSIFException {
      }
  
      protected void initialiseParts(
          Message msg,
          boolean unwrap,
          ArrayList partOrder,
          HashMap partsAndClasses)
          throws WSIFException {
  
          List msgParts = msg.getOrderedParts(null);
          if (msgParts != null && !msgParts.isEmpty()) {
              if (unwrap == true) {
                  Part p = (Part) msgParts.get(0);
                  List unwrappedParts =
                      ProviderUtils.unWrapPart(
                          p,
                          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));
              }
          }
      }
  
      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;
              }
          }
  
          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;
      }
  
      protected boolean isWrappedInContext() {
          boolean wrappedInContext = false;
  
          String value = null;
          try {
              WSIFMessage context = getContext();
              value =
                  (String) context.getObjectPart(
                      WSIFConstants.CONTEXT_OPERATION_STYLE);
  
          } catch (WSIFException e) {
              Trc.ignoredException(e);
          }
  
          if (WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED.equals(value)) {
              wrappedInContext = true;
          }
  
          return wrappedInContext;
      }
  
      protected boolean isUnwrappedInContext() {
          boolean unWrapInContext = false;
  
          String value = null;
          try {
              WSIFMessage context = getContext();
              value =
                  (String) context.getObjectPart(
                      WSIFConstants.CONTEXT_OPERATION_STYLE);
  
          } catch (WSIFException e) {
              Trc.ignoredException(e);
          }
  
          if (WSIFConstants.CONTEXT_OPERATION_STYLE_UNWRAPPED.equals(value)) {
              unWrapInContext = true;
          }
  
          return unWrapInContext;
      }
  
      /**
       * @deprecated use getPortTypeOperation
       */
      protected Operation getOperation() throws WSIFException {
          Trc.entry(this);
          getPortTypeOperation();
          Trc.exit(portTypeOperation);
          return portTypeOperation;
      }
  
      /**
       * Get the WSDL portType operation this WSIFOperation implements.
       * 
       * @see WSIFDefaultOperation#getOperation()
       */
      public Operation getPortTypeOperation() {
          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();
              }
  
              String outputName = null;
              if (bindingOperation.getBindingOutput() != null) {
                  outputName = bindingOperation.getBindingOutput().getName();
              }
  
              portTypeOperation =
                  wsifPort.getPort().getBinding().getPortType().getOperation(
                      bindingOperation.getName(),
                      inputName,
                      outputName);
              if (portTypeOperation == null) {
                  throw new RuntimeException(
                      "no WSDL portType operation found for binding opertion: "
                          + bindingOperation.getName()
                          + ":"
                          + inputName
                          + ":"
                          + outputName);
              }
          }
          Trc.exit(portTypeOperation);
          return portTypeOperation;
      }
  
      /**
       * @see WSIFOperation#createInputMessage()
       */
      public WSIFMessage createInputMessage() {
          Trc.entry(this);
          WSIFMessage msg = createInputMessage(null);
          Trc.exit(msg);
          return msg;
      }
  
      /**
       * @see WSIFOperation#createInputMessage(String)
       */
      public WSIFMessage createInputMessage(String name) {
          Trc.entry(this, name);
          WSIFMessage msg = new WSIFDefaultMessage();
          msg.setName(name);
          Input in = getPortTypeOperation().getInput();
          if (in != null) {
              msg.setMessageDefinition(in.getMessage());
              //TODO: should also add unwrapped parts?
          }
          Trc.exit(msg);
          return msg;
      }
  
      /**
       * @see WSIFOperation#createOutputMessage()
       */
      public WSIFMessage createOutputMessage() {
          Trc.entry(this);
          WSIFMessage msg = createOutputMessage(null);
          Trc.exit(msg);
          return msg;
      }
  
      /**
       * @see WSIFOperation#createOutputMessage(String)
       */
      public WSIFMessage createOutputMessage(String name) {
          Trc.entry(this, name);
          WSIFMessage msg = new WSIFDefaultMessage();
          msg.setName(name);
          Output out = getPortTypeOperation().getOutput();
          if (out != null) {
              msg.setMessageDefinition(out.getMessage());
              //TODO: should also add unwrapped parts?
          }
          Trc.exit(msg);
          return msg;
      }
  
      /**
       * @see WSIFOperation#createFaultMessage()
       */
      public WSIFMessage createFaultMessage() {
          Trc.entry(this);
          WSIFMessage msg = createFaultMessage(null);
          Trc.exit(msg);
          return msg;
      }
  
      /**
       * @see WSIFOperation#createFaultMessage(String)
       */
      public WSIFMessage createFaultMessage(String name) {
          Trc.entry(this, name);
          WSIFMessage msg = new WSIFDefaultMessage();
          msg.setName(name);
          Fault fault = getPortTypeOperation().getFault(name);
          if (fault != null) {
              msg.setMessageDefinition(fault.getMessage());
          }
          Trc.exit(msg);
          return msg;
      }
  
      /**
       * Returns the inputParts.
       * @return ArrayList
       */
      public ArrayList getInputParts() {
          return inputPartOrder;
      }
  
      /**
       * Returns the inputPartClasses.
       * @return HashMap
       */
      public HashMap getInputPartClasses() {
          return inputPartsAndClasses;
      }
  
      /**
       * Returns the outputPartNames.
       * @return ArrayList
       */
      public ArrayList getOutputParts() {
          return outputPartOrder;
      }
  
      /**
       * Returns the outputPartClass.
       * @return HashMap
       */
      public HashMap getOutputPartClasses() {
          return outputPartsAndClasses;
      }
  
      /**
       * Gets the context information for this binding.
       */
      public WSIFMessage getContext() throws WSIFException {
          Trc.entry(this);
          WSIFMessage contextCopy;
          try {
              if (this.context == null) {
                  contextCopy = (WSIFMessage) wsifPort.getContext().clone();
              } else {
                  contextCopy = (WSIFMessage) this.context.clone();
              }
          } catch (CloneNotSupportedException e) {
              throw new WSIFException(
                  "CloneNotSupportedException cloning context",
                  e);
          }
          Trc.exit(contextCopy);
          return contextCopy;
      }
  
      /**
       * Allows the application programmer or stub to pass context 
       * information to the binding. The Port implementation may use 
       * this context - for example to update a SOAP header. There is 
       * no definition of how a Port may utilize the context.
       */
      public void setContext(WSIFMessage context) {
          Trc.entry(this, context);
          if (context == null) {
              throw new IllegalArgumentException("context must not be null");
          }
          this.context = context;
          Trc.exit();
      }
  
      /**
       * String representation of this WSIFOperation for WSIF Trc.
       */
      public String deep() {
          StringBuffer buff = new StringBuffer(super.toString());
          buff.append(":\n");
          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(", asyncResponseHandler:" + asyncResponseHandler);
          buff.append(", context:" + context);
          return buff.toString();
      }
  
  }
  
  
  1.1                  xml-axis-wsif/java/src/org/apache/wsif/providers/ModelWSIFPort.java
  
  Index: ModelWSIFPort.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.util.HashMap;
  
  import javax.wsdl.BindingOperation;
  import javax.wsdl.Definition;
  import javax.wsdl.Port;
  import javax.wsdl.Service;
  import javax.wsdl.extensions.ExtensibilityElement;
  
  import org.apache.wsif.WSIFException;
  import org.apache.wsif.WSIFMessage;
  import org.apache.wsif.WSIFOperation;
  import org.apache.wsif.WSIFPort;
  import org.apache.wsif.base.WSIFDefaultMessage;
  import org.apache.wsif.logging.Trc;
  import org.apache.wsif.util.WSIFUtils;
  
  /**
   * ModelWSIFPort
   * 
   * Models are provided for all the classes required to 
   * be implemented when writing a WSIF provider: 
   * 			WSIFProvider, WSIFPort, and WSIFOperation. 
   * The models are intended to simplify the work in the
   * implementing subclasses, and insure that all providers
   * work in standard way. Things like hunting around in 
   * the WSDL for ExtensabilityElements and verifying the 
   * types of request and response objects against the WSDL
   * should be done in the model code. Subclasses should only 
   * need to provide code directly related to accessing the
   * particular service type they implement.
   *  
   * @author Ant Elder <an...@uk.ibm.com>
   */
  abstract public class ModelWSIFPort implements WSIFPort {
  
      protected Definition def;
      protected Service service;
      protected Port port;
      protected WSIFDynamicTypeMap typeMap;
      protected ExtensibilityElement binding;
      protected boolean cacheOperations;
      transient protected HashMap cachedOperations;
      transient protected WSIFMessage context;
  
      /**
       * Construct a ModelWSIFPort
       */
      public ModelWSIFPort(Definition def, Port port, WSIFDynamicTypeMap typeMap)
          throws WSIFException {
  
          this(def, null, port, typeMap, null);
      }
  
      /**
       * Construct a ModelWSIFPort
       */
      public ModelWSIFPort(
          Definition def,
          Service service,
          Port port,
          WSIFDynamicTypeMap typeMap,
          ExtensibilityElement binding)
          throws WSIFException {
          Trc.entry(this, def, service, port, typeMap, binding);
  
          this.def = def;
          this.service = service;
          this.port = port;
          this.binding = binding;
          this.typeMap = typeMap;
  
          //        cacheOperations = wsifService.isCacheOperations();
          cacheOperations = true;
  
          if (cacheOperations == true) {
              cachedOperations = new HashMap();
          }
  
          if (Trc.ON) {
              Trc.exit(deep());
          }
      }
  
      /**
       * @see WSIFPort#createOperation(String)
       */
      public WSIFOperation createOperation(String opName) throws WSIFException {
          Trc.entry(this, opName);
          WSIFOperation op = createOperation(opName, null, null);
          Trc.exit(op);
          return op;
      }
  
      /**
       * @see WSIFPort#createOperation(String, String, String)
       */
      public WSIFOperation createOperation(
          String opName,
          String inputName,
          String outputName)
          throws WSIFException {
          Trc.entry(this, opName, inputName, outputName);
  
          ModelWSIFOperation wsifOp = null;
  
          String cacheKey = null;
          ;
          if (cacheOperations == true) {
              cacheKey =
                  new StringBuffer(opName)
                      .append(":")
                      .append(inputName)
                      .append(":")
                      .append(outputName)
                      .toString();
              wsifOp = (ModelWSIFOperation) cachedOperations.get(cacheKey);
          }
          if (wsifOp == null) {
              BindingOperation wsdlBindingOperation =
                  WSIFUtils.getBindingOperation(
                      port.getBinding(),
                      opName,
                      inputName,
                      outputName);
              if (wsdlBindingOperation != null) {
                  wsifOp = makeWSIFOperation(this, wsdlBindingOperation);
              }
          }
  
          if (wsifOp == null) {
              throw new WSIFException(
                  "Could not create operation: "
                      + opName
                      + ":"
                      + inputName
                      + ":"
                      + outputName);
          }
  
          if (cacheOperations == true) {
              cachedOperations.put(cacheKey, wsifOp);
          }
  
          wsifOp.initialise();
  
          Trc.exit(wsifOp);
          return wsifOp;
      }
  
      /**
       * Returns the cacheOperations.
       * @return boolean
       */
      public boolean isCacheOperations() {
          return cacheOperations;
      }
  
      /**
       * Sets the cacheOperations.
       * @param cacheOperations The cacheOperations to set
       */
      protected void setCacheOperations(boolean cacheOperations) {
          this.cacheOperations = cacheOperations;
      }
  
      /**
       * Returns the binding.
       * @return ExtensibilityElement
       */
      public ExtensibilityElement getBinding() {
          return binding;
      }
  
      /**
       * Returns the def.
       * @return Definition
       */
      public Definition getDefinition() {
          return def;
      }
  
      /**
       * Returns the port.
       * @return Port
       */
      public Port getPort() {
          return port;
      }
  
      /**
       * Returns the service.
       * @return Service
       */
      public Service getService() {
          return service;
      }
  
      /**
       * Returns the typeMap.
       * @return WSIFDynamicTypeMap
       */
      public WSIFDynamicTypeMap getTypeMap() {
          return typeMap;
      }
  
      /**
       * Gets the context information for this WSIFPort.
       * @return context
       */
      public WSIFMessage getContext() throws WSIFException {
          Trc.entry(this);
          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);
              }
          }
          Trc.exit(contextCopy);
          return contextCopy;
      }
  
      /**
       * Sets the context information for this WSIFPort.
       * @param WSIFMessage the new context information
       */
      public void setContext(WSIFMessage context) {
          Trc.entry(this, context);
          if (context == null) {
              throw new IllegalArgumentException("context must not be null");
          }
          this.context = context;
          Trc.exit(null);
      }
  
      /**
       * Tests if this port supports synchronous calls to operations.
       * 
       * @return true   by default WSIFPorts do support synchronous calls
       */
      public boolean supportsSync() {
          Trc.entry(this);
          Trc.exit(true);
          return true;
      }
  
      /**
       * Tests if this port supports asynchronous calls to operations.
       * 
       * @return false   by default ports do not support asynchronous calls
       */
      public boolean supportsAsync() {
          Trc.entry(this);
          Trc.exit(false);
          return false;
      }
  
      public void finalize() throws Throwable {
          Trc.entry(this);
          try {
              close();
          } catch (WSIFException ex) {
              Trc.ignoredException(ex);
          }
          super.finalize();
          Trc.exit();
      }
  
      // the methods subclasses must implement
  
      abstract protected ModelWSIFOperation makeWSIFOperation(
          ModelWSIFPort port,
          BindingOperation bop)
          throws WSIFException;
  
      abstract protected Class getImplementedAddressClass();
  
      abstract protected void validateAddress(ExtensibilityElement address)
          throws WSIFException;
  
      abstract public void close() throws WSIFException;
  
      /**
       * String representation of this WSIFPort for WSIF Trc.
       */
      public String deep() {
          StringBuffer buff = new StringBuffer();
          buff.append(super.toString() + ":\n");
          buff.append("definition:");
          buff.append(Trc.brief(def));
          buff.append(" service:");
          buff.append(Trc.brief(service));
          buff.append(" portModel:");
          buff.append(Trc.brief(port));
          buff.append(" typeMap:");
          buff.append(typeMap);
          buff.append(" binding:");
          buff.append(binding);
          return buff.toString();
      }
  
  }