nmukhi      2002/12/20 04:53:22

  Modified:    java/samples/customfactory README.html
               java/samples/simplesoap/client/dynamic README.html
  Added:       java/samples/customfactory StockQuoteService.wsdl
               java/samples/customfactory/client
                        CustomServiceFactoryImpl.java
                        CustomServiceImpl.java
                        MyPrivateCompositeExtensionRegistry.java
               java/samples/customfactory/client/dynamic README.html
               java/samples/customfactory/client/stub README.html Run.java
               java/samples/customfactory/client/stub/com/themindelectric/www
                        NetXmethodsServicesStockquoteStockQuotePortType.java
               java/samples/customfactory/service README.html
                        StockQuoteService.java
  Log:
  Minor change to simplesoap documentation.
  Added custom factory sample, including the following, see
  the sample README for details.
  
  Revision  Changes    Path
  1.2       +26 -0     xml-axis-wsif/java/samples/customfactory/README.html
  
  Index: README.html
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/samples/customfactory/README.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- README.html       11 Dec 2002 16:00:48 -0000      1.1
  +++ README.html       20 Dec 2002 12:53:21 -0000      1.2
  @@ -0,0 +1,26 @@
  +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>
  +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  +<meta name="Author" content="Nirmal Mukhi">
  +<meta http-equiv="Content-Style-Type" content="text/css">
  +<title>Web Services Invocation Framework: Samples</title>
  +<link rel="stylesheet" href="wsif.css" type="text/css"></head>
  +
  +<body alink="#0000ff" bgcolor="#ffffff" leftmargin="2" topmargin="2" 
marginwidth="2" marginheight="2">
  +
  +<h1>
  +Web Services Invocation Framework:<br>
  +Custom factory binding sample</h1>
  +<p><b>This samples will not work; it needs a code change to 
<tt>WSIFServiceFactory</tt>; once that is done this sample will work as described. 
This note will be removed once the code change has been made.</b>
  +<p>This sample aims to demonstrate a simple customization of WSIF. One of the 
central pieces of code in the WSIF runtime is the <tt><a 
href="../../src/org/apache/wsif/WSIFService.java">WSIFService</a></tt>. This interface 
is responsible for (amongst other things) returning the instance of the <tt><a 
href="../../src/org/apache/wsif/WSIFPort.java">WSIFPort</a></tt> object that will be 
used for invocation, through one of the available <tt>getPort</tt> methods. 
<tt>WSIFService</tt> objects themselves are created using a factory, the <tt><a 
href="../../src/org/apache/wsif/WSIFServiceFactory.java">WSIFServiceFactory</a></tt>. 
This is an abstract factory whose implementation we can customise.</p>
  +<p>This sample employs a customised service factory, which behaves no different 
from the default service factory other than the fact that it returns a customised 
implementation of the <tt>WSIFService</tt> interface. This customised service 
implementation differs from the default one that comes with WSIF in one respect only. 
The <tt>getPort()</tt> method has been changed to return a port that uses a java 
binding, if there is one, in preference to any other port. The rationale is that if 
the same service is available as a local java binding, it's probably a lot faster to 
use that than to attempt to make a SOAP invocation, use an EJB, etc. Of course this is 
very simplistic, but the sample demonstrates how you can use your own customised 
algorithm for choosing between bindings at runtime. All you need to do is add the 
following line to your <tt>wsif.properties</tt> file:
  +<br><tt>wsif.servicefactory=customfactory.client.CustomServiceFactoryImpl</tt>
  +<br>You can change the class name to point to your customised factory if you like, 
or just omit this property for the default factory to be used.</p>
  +<p>The service used to demonstrate the flexibility is the familiar stock quote 
example. The WSDL in this directory offers two bindings: a SOAP binding and a java 
binding. Through the use of trace you will be able to detect which binding is actually 
used. You will see that when the custom factory is used, the java binding is always 
picked. Try removing the custom factory by commenting out the 
<tt>wsif.servicefactory</tt> property from your <tt>wsif.properties</tt> file. Now the 
default factory will be used; its algorithm for picking a suitable port/binding is 
very simple: it just picks the first one. So now when you run your clients you may see 
the SOAP binding being picked (the actual one picked is the first port in the list of 
ports, and since the list is not ordered it is impossible to predict exactly which one 
it will be, but if it happens to be the java port, it isn't because the default 
service implementation did that purposefully, it just happened to be first on the 
list!).
  +<p>The <a href="StockQuoteService.wsdl">WSDL file</a> is in this sample 
directory.</p>
  +<p>The SOAP implementation is hosted by the good folks at <a 
href="http://www.xmethods.net";>XMethods</a>. The service URL, where you can find 
details on the service implementation, etc. is <a 
href="http://www.xmethods.net/ve2/ViewListing.po?serviceid=2";>here</a>.</p>
  +<p><a href="service/README.html">Here's</a> how the local java class that 
implements the service functionality.</p>
  +<p><a href="client/dynamic/README.html">Here's</a> how to invoke this service 
dynamically using WSIF's dynamic invocation interface (DII).</p>
  +<p><a href="client/stub/README.html">Here's</a> how to invoke this service by first 
generating the stub interface and using this directly through WSIF's dynamic proxy, 
thus hiding all WSIF specifics from the client code. Note that the stub interface used 
is the the service interface as defined by the JAX-RPC specification.</p>
  +<p><a href="client/CustomServiceFactoryImpl.java">Here's</a> the customised factory 
implementation that create our customised service, and <a 
href="client/CustomServiceImpl.java">here's</a> the customised service class. Note the 
implementation of the <tt>getPort()</tt> method in the latter class.</p>
  +<hr width="100%">
  +</body></html>
  
  
  
  1.1                  xml-axis-wsif/java/samples/customfactory/StockQuoteService.wsdl
  
  Index: StockQuoteService.wsdl
  ===================================================================
  <?xml version='1.0' encoding='UTF-8'?>
  <definitions name='net.xmethods.services.stockquote.StockQuote' 
             
targetNamespace='http://www.themindelectric.com/wsdl/net.xmethods.services.stockquote.StockQuote/'
 
             
xmlns:tns='http://www.themindelectric.com/wsdl/net.xmethods.services.stockquote.StockQuote/'
 
               xmlns:electric='http://www.themindelectric.com/' 
               xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' 
               xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
               xmlns:format="http://schemas.xmlsoap.org/wsdl/formatbinding/";
               xmlns:java="http://schemas.xmlsoap.org/wsdl/java/";
               xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' 
               xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' 
               xmlns='http://schemas.xmlsoap.org/wsdl/'>
  
     <message name='getQuoteResponse1'>
        <part name='Result' type='xsd:float'/>
     </message>
  
     <message name='getQuoteRequest1'>
        <part name='symbol' type='xsd:string'/>
     </message>
  
     <portType name='net.xmethods.services.stockquote.StockQuotePortType'>
        <operation name='getQuote' parameterOrder='symbol'>
           <input message='tns:getQuoteRequest1'/>
           <output message='tns:getQuoteResponse1'/>
        </operation>
     </portType>
  
     <!-- SOAP binding -->
     <binding name='StockQuoteSOAPBinding' 
              type='tns:net.xmethods.services.stockquote.StockQuotePortType'>
        <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>
        <operation name='getQuote'>
           <soap:operation soapAction='urn:xmethods-delayed-quotes#getQuote'/>
           <input>
              <soap:body use='encoded' 
                         namespace='urn:xmethods-delayed-quotes' 
                         encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
           </input>
           <output>
              <soap:body use='encoded' 
                         namespace='urn:xmethods-delayed-quotes' 
                         encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
           </output>
        </operation>
     </binding>
  
     <!-- Java binding -->
     <binding name='StockQuoteJavaBinding' 
              type='tns:net.xmethods.services.stockquote.StockQuotePortType'>
      <java:binding/>
      <format:typeMapping encoding="Java" style="Java">
        <format:typeMap typeName="xsd:string" formatType="java.lang.String" />
        <format:typeMap typeName="xsd:float" formatType="java.lang.Float" />
      </format:typeMapping>
      <operation name="getQuote">
        <java:operation
           methodName="getQuote"
           methodType="instance" />
        <input/>
      </operation>
     </binding>
  
     <service name='net.xmethods.services.stockquote.StockQuoteService'>
        <documentation>net.xmethods.services.stockquote.StockQuote web 
service</documentation>
        <port name="StockQuoteJavaPort" binding="tns:StockQuoteJavaBinding">
          <java:address className="multibinding.service.StockQuoteService"/>
        </port>
        <port name='StockQuoteSOAPPort' 
              binding='tns:StockQuoteSOAPBinding'>
           <soap:address location='http://66.28.98.121:9090/soap'/>
        </port>
     </service>
  </definitions>
  
  
  1.1                  
xml-axis-wsif/java/samples/customfactory/client/CustomServiceFactoryImpl.java
  
  Index: CustomServiceFactoryImpl.java
  ===================================================================
  package customfactory.client;
  
  import org.apache.wsif.WSIFServiceFactory;
  import org.apache.wsif.WSIFService;
  import org.apache.wsif.WSIFException;
  import javax.wsdl.*;
  
  public class CustomServiceFactoryImpl extends WSIFServiceFactory {
      public CustomServiceFactoryImpl() {
        System.out.println("Using custom factory");
      }
      /**
       * Create a WSIFService from WSDL document URL.
       * <br> If serviceName or serviceNS is null,
       *   then WSDL document must have exactly one service in it.
       * <br> If portTypeName or portTypeNS is null,
       *   then WSDL document must have exactly one portType in it
       *   and all ports of the selected service must
       *    implement the same portType.
       * @param wsdlLoc The URL for the wsdl's location
       * @param serviceNS The namespace of the service
       * @param serviceName The name of the service
       * @param portTypeNS The namespace of the port type
       * @param portTypeName The name of the port type
       * @return The service
       * @exception A WSIFException if an error occurs when creating the service
       */
      public WSIFService getService(
          String wsdlLoc,
          String serviceNS,
          String serviceName,
          String portTypeNS,
          String portTypeName)
          throws WSIFException {
          CustomServiceImpl wsi =
              new CustomServiceImpl(
                  wsdlLoc,
                  serviceNS,
                  serviceName,
                  portTypeNS,
                  portTypeName);
          return wsi;
      }
  
      /**
       * Create a WSIF service instance from WSDL document URL
       * using a ClassLoader to find local resources.
       * <br> If serviceName or serviceNS is null,
       *   then WSDL document must have exactly one service in it.
       * <br> If portTypeName or portTypeNS is null,
       *   then WSDL document must have exactly one portType in it
       *   and all ports of the selected service must
       *    implement the same portType.
       * @param wsdlLoc The URL for the wsdl's location
       * @param cl A ClassLoader to use in locating the wsdl
       * @param serviceNS The namespace of the service
       * @param serviceName The name of the service
       * @param portTypeNS The namespace of the port type
       * @param portTypeName The name of the port type
       * @return The service
       * @exception A WSIFException if an error occurs when creating the service
       */
      public WSIFService getService(
          String wsdlLoc,
          ClassLoader cl,
          String serviceNS,
          String serviceName,
          String portTypeNS,
          String portTypeName)
          throws WSIFException {
          CustomServiceImpl wsi =
              new CustomServiceImpl(
                  wsdlLoc,
                  cl,
                  serviceNS,
                  serviceName,
                  portTypeNS,
                  portTypeName);
          return wsi;
      }
  
      /**
       * Returns a new WSIFService.
       * @param def The Definition object representing the wsdl
       * @return The service
       * @exception A WSIFException if an error occurs when creating the service
       */
      public WSIFService getService(Definition def) throws WSIFException {
          CustomServiceImpl wsi = new CustomServiceImpl(def);
          return wsi;
      }
  
      /**
       * Returns a new WSIFService.
       * @param def The Definition object representing the wsdl
       * @param service The Service object representing the service to use
       * @return The service
       * @exception A WSIFException if an error occurs when creating the service
       */
      public WSIFService getService(Definition def, Service service)
          throws WSIFException {
          CustomServiceImpl wsi = new CustomServiceImpl(def, service);
          return wsi;
      }
  
      /**
       * Returns a new WSIFService.
       * @param def The Definition object representing the wsdl
       * @param service The Service object representing the service to use
       * @param portType The PortType object representing the port type to use
       * @return The service
       * @exception A WSIFException if an error occurs when creating the service
       */
      public WSIFService getService(
          Definition def,
          Service service,
          PortType portType)
          throws WSIFException {
          CustomServiceImpl wsi = new CustomServiceImpl(def, service, portType);
          return wsi;
      }
  
      /**
       * Returns a new WSIFService.
       * @param def The Definition object representing the wsdl
       * @param serviceNS The namespace of the service
       * @param serviceName The name of the service
       * @param portTypeNS The namespace of the port type
       * @param portTypeName The name of the port type
       * @return The service
       * @exception A WSIFException if an error occurs when creating the service
       */
      public WSIFService getService(
          Definition def,
          String serviceNS,
          String serviceName,
          String portTypeNS,
          String portTypeName)
          throws WSIFException {
          CustomServiceImpl wsi =
              new CustomServiceImpl(
                  def,
                  serviceNS,
                  serviceName,
                  portTypeNS,
                  portTypeName);
          return wsi;
      }
  }
  
  
  
  1.1                  
xml-axis-wsif/java/samples/customfactory/client/CustomServiceImpl.java
  
  Index: CustomServiceImpl.java
  ===================================================================
  package customfactory.client;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Hashtable;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
  import javax.wsdl.Binding;
  import javax.wsdl.Definition;
  import javax.wsdl.Input;
  import javax.wsdl.Message;
  import javax.wsdl.Operation;
  import javax.wsdl.OperationType;
  import javax.wsdl.Output;
  import javax.wsdl.Port;
  import javax.wsdl.PortType;
  import javax.wsdl.Service;
  import javax.wsdl.WSDLException;
  import javax.wsdl.extensions.ExtensibilityElement;
  import javax.wsdl.extensions.ExtensionRegistry;
  import javax.wsdl.extensions.UnknownExtensibilityElement;
  import javax.xml.namespace.QName;
  
  import org.apache.wsif.WSIFConstants;
  import org.apache.wsif.base.WSIFServiceImpl;
  import org.apache.wsif.WSIFException;
  import org.apache.wsif.WSIFPort;
  import org.apache.wsif.WSIFService;
  import org.apache.wsif.compiler.schema.tools.Schema2Java;
  import org.apache.wsif.compiler.util.TypeMapping;
  import org.apache.wsif.compiler.util.Utils;
  import org.apache.wsif.logging.MessageLogger;
  import org.apache.wsif.logging.Trc;
  import org.apache.wsif.providers.WSIFDynamicTypeMap;
  import org.apache.wsif.spi.WSIFProvider;
  import org.apache.wsif.util.WSIFPluggableProviders;
  import org.apache.wsif.util.WSIFUtils;
  import org.apache.wsif.wsdl.extensions.java.JavaBinding;
  import org.apache.wsif.base.*;
  import org.w3c.dom.Element;
  import com.ibm.wsdl.util.xml.QNameUtils;
  
  /**
   * An entry point to dynamic WSDL invocations.
   *
   * @author Alekander Slominski
   * @author Sanjiva Weerawarana
   * @author Owen Burroughs <[EMAIL PROTECTED]>
   * @author Ant Elder <[EMAIL PROTECTED]>
   * @author Jeremy Hughes <[EMAIL PROTECTED]>
   * @author Mark Whitlock <[EMAIL PROTECTED]>
   */
  public class CustomServiceImpl implements WSIFService {
      private static MyPrivateCompositeExtensionRegistry providersExtRegs =
          new MyPrivateCompositeExtensionRegistry();
      private Definition def = null;
      private Service service;
      private PortType portType;
      private Port[] myPortsArr;
      private Map myPortsMap;
      private WSIFDynamicTypeMap typeMap = new WSIFDynamicTypeMap();
      private boolean typeMapInitialised = false;
      private String preferredPort = null;
      private Map typeReg = null;
      private Port chosenPort = null;
  
      /**
       * Create a WSIF service instance from WSDL document URL.
       * <br> If serviceName or serviceNS is null,
       *   then WSDL document must have exactly one service in it.
       * <br> If portTypeName or portTypeNS is null,
       *   then WSDL document must have exactly one portType in it
       *   and all ports of the selected service must
       *    implement the same portType.
       * <br>NOTE: 
       * The equivalent {@link org.apache.wsif.WSIFServiceFactory}.getService method
       * should be used to create a WSIFService.
       */
      CustomServiceImpl(
          String wsdlLoc,
          String serviceNS,
          String serviceName,
          String portTypeNS,
          String portTypeName)
          throws WSIFException {
          Trc.entry(this, wsdlLoc, serviceNS, serviceName, portTypeNS, portTypeName);
  
          // load WSDL defintion
          Definition def = null;
          try {
              def = WSIFUtils.readWSDL(null, wsdlLoc);
              checkWSDL(def);
          } catch (WSDLException ex) {
                Trc.exception(ex);
              throw new WSIFException("could not load " + wsdlLoc, ex);
          }
  
          // select WSDL service if given name
          Service service = WSIFUtils.selectService(def, serviceNS, serviceName);
  
          // select WSDL portType if given name
          PortType portType = WSIFUtils.selectPortType(def, portTypeNS, portTypeName);
  
          init(def, service, portType);
          if (Trc.ON)
              Trc.exit(deep());
      }
  
      /**
        * Create a WSIF service instance from WSDL document URL
        * using a ClassLoader to find local resources.
        * <br> If serviceName or serviceNS is null,
        *   then WSDL document must have exactly one service in it.
        * <br> If portTypeName or portTypeNS is null,
        *   then WSDL document must have exactly one portType in it
        *   and all ports of the selected service must
        *    implement the same portType.
        * <br>NOTE: 
        * The equivalent {@link org.apache.wsif.WSIFServiceFactory}.getService method
        * should be used to create a WSIFService.
        */
      CustomServiceImpl(
          String wsdlLoc,
          ClassLoader cl,
          String serviceNS,
          String serviceName,
          String portTypeNS,
          String portTypeName)
          throws WSIFException {
          Trc.entry(this, wsdlLoc, cl, serviceNS, serviceName, portTypeNS, 
portTypeName);
  
          // load WSDL defintion
          Definition def = null;
          try {
              def = WSIFUtils.readWSDL(null, wsdlLoc, cl);
              checkWSDL(def);
          } catch (WSDLException ex) {
                Trc.exception(ex);
              throw new WSIFException("could not load " + wsdlLoc, ex);
          }
  
          // select WSDL service if given name
          Service service = WSIFUtils.selectService(def, serviceNS, serviceName);
  
          // select WSDL portType if given name
          PortType portType = WSIFUtils.selectPortType(def, portTypeNS, portTypeName);
  
          init(def, service, portType);
          if (Trc.ON)
              Trc.exit(deep());
      }
  
      /**
        * Create a WSIF service instance
        * <br>NOTE:
        * The equivalent {@link org.apache.wsif.WSIFServiceFactory}.getService method
        * should be used to create a WSIFService.
        */
      CustomServiceImpl(Definition def) throws WSIFException {
          this(def, null);
      }
  
      /**
        * Create a WSIF service instance
        * <br>NOTE: 
        * The equivalent {@link org.apache.wsif.WSIFServiceFactory}.getService method
        * should be used to create a WSIFService.
        */
      CustomServiceImpl(Definition def, Service service) throws WSIFException {
          this(def, service, null);
      }
  
      /**
        * Create a WSIF service instance
        * <br>NOTE: 
        * The equivalent {@link org.apache.wsif.WSIFServiceFactory}.getService method
        * should be used to create a WSIFService.
        */
      CustomServiceImpl(Definition def, Service service, PortType portType)
          throws WSIFException {
          Trc.entry(this, def, service, portType);
  
          init(def, service, portType);
          if (Trc.ON)
              Trc.exit(deep());
      }
  
      /**
        * Create a WSIF service instance
        * <br>NOTE: 
        * The equivalent {@link org.apache.wsif.WSIFServiceFactory}.getService method
        * should be used to create a WSIFService.
        */
      CustomServiceImpl(Definition def, String serviceNS, String serviceName)
          throws WSIFException {
          Trc.entry(this, def, serviceNS, serviceName);
  
          // select WSDL service if given by name or only one
          Service service = WSIFUtils.selectService(def, serviceNS, serviceName);
          init(def, service, null);
          if (Trc.ON)
              Trc.exit(deep());
      }
  
      /**
        * Create a WSIF service instance
        * <br>NOTE: 
        * The equivalent {@link org.apache.wsif.WSIFServiceFactory}.getService method
        * should be used to create a WSIFService.
        */
      CustomServiceImpl(
          Definition def,
          String serviceNS,
          String serviceName,
          String portTypeNS,
          String portTypeName)
          throws WSIFException {
          Trc.entry(this, def, serviceNS, serviceName, portTypeNS, portTypeName);
  
          checkWSDLForWSIF(def);
  
          // select WSDL service if given by name or only one
          Service service = WSIFUtils.selectService(def, serviceNS, serviceName);
  
          // select WSDL portType if given by name or only one portType
          PortType portType = WSIFUtils.selectPortType(def, portTypeNS, portTypeName);
  
          init(def, service, portType);
          if (Trc.ON)
              Trc.exit(deep());
      }
  
      /**
        * Create a WSIF service instance from another instance. 
        */
      CustomServiceImpl(CustomServiceImpl wsi)
          throws WSIFException {
          Trc.entry(this, wsi);
          copyInitializedService(wsi);
          if (Trc.ON)
              Trc.exit(deep());
      }
  
        /**
         * Copy the "read-only" parts of an initialized CustomServiceImpl
         */
        private void copyInitializedService(CustomServiceImpl svc) {
                this.def = svc.def;
          this.service = svc.service;
          this.portType = svc.portType;
                this.myPortsArr = new Port[svc.myPortsArr.length];
                System.arraycopy(svc.myPortsArr, 0, this.myPortsArr, 0, 
svc.myPortsArr.length);
          this.myPortsMap = (Map) ((Hashtable) svc.myPortsMap).clone();
                this.typeMap = svc.typeMap.copy();
        }
  
      /**
       * Set the preferred port
       * @param portName The name of the port to use
       */
      public void setPreferredPort(String portName) throws WSIFException {
          Trc.entry(this, portName);
  
          if (portName == null) {
              throw new WSIFException("Preferred port name cannot be null");
          }
          PortType pt = getPortTypeFromPortName(portName);
          if (pt.getQName().equals(this.portType.getQName())) {
              this.preferredPort = portName;
          } else {
              throw new WSIFException(
                  "Preferred port "
                      + portName
                      + "is not available for the port type "
                      + this.portType.getQName());
          }
          Trc.exit();
      }
  
      /**
       * Create a PortType object from the name of a port
       * @param portName The name of the port
       * @return A PortType corresponding to the port type used by the
       * specified port
       */
      private PortType getPortTypeFromPortName(String portName)
          throws WSIFException {
          if (portName == null) {
              throw new WSIFException("Unable to find port type from a null port 
name");
          }
          Port port = (Port) service.getPort(portName);
          if (port == null) {
              throw new WSIFException(
                  "Port '" + portName + "' cannot be found in the service");
          }
          Binding binding = port.getBinding();
          if (binding == null) {
              throw new WSIFException("No binding found for port '" + portName + "'");
          }
          PortType pt = binding.getPortType();
          if (pt == null) {
              throw new WSIFException(
                  "No port type found for binding '" + binding.getQName() + "'");
          }
          checkPortTypeInformation(def, pt);
          return pt;
      }
  
      /**
       * Get the names of the available ports
       * @return Iterator for list of available port names.
       */
      public Iterator getAvailablePortNames() throws WSIFException {
          Trc.entry(this);
          Iterator it = null;
          try {
              it = this.myPortsMap.keySet().iterator();
          } catch (NullPointerException ne) {
                Trc.exception(ne);
              it = null;
          }
          Trc.exit();
          return it;
      }
  
      /**
       * Create dynamic port instance from WSDL model defnition and port.
       */
      private WSIFPort createDynamicWSIFPort(
          Definition def,
          Service service,
          Port port)
          throws WSIFException {
          checkWSDLForWSIF(def);
          List bindingExList = port.getBinding().getExtensibilityElements();
          ExtensibilityElement bindingFirstEx =
              (ExtensibilityElement) bindingExList.get(0);
          String bindingNS = bindingFirstEx.getElementType().getNamespaceURI();
          WSIFProvider provider = WSIFPluggableProviders.getProvider(bindingNS);
          if (provider != null) {
              return provider.createDynamicWSIFPort(def, service, port, typeMap);
          } else {
              throw new WSIFException(
                  "could not find suitable provider for binding namespace '" + 
bindingNS + "'");
          }
      }
  
      public WSIFPort getPort() throws WSIFException {
        // ignore preferred port preference
        // check if the service has a java binding; if so use that port
        // since it will be faster than accessing a SOAP, EJB etc. implemenations of 
        // the same thing
        Definition definition = getDefinition();
        // get the first service (we assume there is exactly one)
        // if we have no services, no bindings or other screwy stuff
        // the code below will choke
        Map services = definition.getServices();
        Service service = (Service) services.values().iterator().next();
        Iterator ports = service.getPorts().values().iterator();
        while (ports.hasNext()) {
            Port port = (Port) ports.next();
            // check the binding
            Binding binding = port.getBinding();
            if (binding instanceof JavaBinding)
                return getPort(port.getName());
        }
        // no java binding available, just return the first port
        Port firstPort = (Port) service.getPorts().values().iterator().next();
        return getPort(firstPort.getName());
      }
  
      /**
       * Return dynamic port instance selected by port name.
       */
      public WSIFPort getPort(String portName) throws WSIFException {
          Trc.entry(this, portName);
          Port port = null;
  
          if (portName == null) {
              // Get first available port
              if (myPortsArr.length > 0) {
                  port = myPortsArr[0];
              }
          } else {
              port = (Port) myPortsMap.get(portName);
          }
          if (port == null) {
              if (portName == null) {
                  throw new WSIFException("Unable to find an available port");
              } else {
                  throw new WSIFException(
                      "Port '"
                          + portName
                          + "' is not available and "
                          + " no alternative can be found");
              }
          }
  
          portName = port.getName();
          WSIFPort portInstance = createDynamicWSIFPort(def, service, port);
          if (portInstance == null) {
              throw new WSIFException(
                  "Provider was unable to create WSIFPort for port " + portName);
          }
          // Store the chosen port so that we can query which was is being used
          chosenPort = port;
  
          Trc.exit(portInstance);
          return portInstance;
      }
  
      /**
       * Add association between XML and Java type.
       * @param xmlType The qualified xml name
       * @param javaType The Java class 
       */
      public void mapType(QName xmlType, Class javaType) throws WSIFException {
          Trc.entry(this, xmlType, javaType);
          typeMap.mapType(xmlType, javaType);
          Trc.exit();
      }
  
      /**
       * Add an association between XML and Java type.
       * @param xmlType The qualified xml name
       * @param javaType The Java class
       * @param force flag to indicate if mapping should override an existing one
       * for the same xmlType 
       */
      private void mapType(QName xmlType, Class javaType, boolean force)
          throws WSIFException {
          Trc.entry(this, xmlType, javaType, new Boolean(force));
          typeMap.mapType(xmlType, javaType, force);
          Trc.exit();
      }
  
      /**
       * Add an association between a namespace URI and and a Java package.
       * @param namespace The namespace URI
       * @param packageName The full package name
       */
      public void mapPackage(String namespace, String packageName)
          throws WSIFException {
          Trc.entry(namespace, packageName);
          typeMap.mapPackage(namespace, packageName);
          Trc.exit();
      }
  
      /**
       * @deprecated this method is replaced by the getProvider
       * method in the org.apache.util.WSIFPluggableProviders class
       */
      public static WSIFProvider getDynamicWSIFProvider(String namespaceURI) {
          Trc.entry(null, namespaceURI);
          WSIFProvider p = 
             WSIFPluggableProviders.getProvider( namespaceURI );
          Trc.exit( p );
          return p;
      }
  
      /**
       * @deprecated this method is replaced by the overrideDefaultProvider
       * method in the org.apache.util.WSIFPluggableProviders class
       */
      public static void setDynamicWSIFProvider(
          String providerNamespaceURI,
          WSIFProvider provider) {
          Trc.entry(null, providerNamespaceURI, provider);
  
          WSIFPluggableProviders.overrideDefaultProvider(
             providerNamespaceURI, provider );
  
          Trc.exit();
      }
  
      /**
       * @deprecated this method is replaced by the setAutoLoadProviders
       * method in the org.apache.util.WSIFPluggableProviders class
       */
      public static void setAutoLoadProviders(boolean b) {
          Trc.entry(null, b);
          WSIFPluggableProviders.setAutoLoadProviders( b );
          Trc.exit();
      }
  
      /**
       * Get the dynamic proxy that will implement the interface iface
       * for the port portName.
       */
      public Object getStub(String portName, Class iface) throws WSIFException {
          Trc.entry(this, portName, iface);
  
          // Initialise the type mappings here (not in the constructor) so that
          // other products which use non-standard WSDL in their complexTypes
          // that WSIF wouldn't understand, can use the DynamicInvoker 
          // successfully. Using the DynamicInvoker means we would never come
          // through this code and so never try to parse the complexTypes.
          // Obviously if the user wants to use dynamic proxies then we have to 
          // parse the complex types.
          if (!typeMapInitialised) {
              initialiseTypeMappings();
              typeMapInitialised = true;
          }
  
          // if the port is not available, force the expection now rather
          // rather than go through the rest of this method             
          WSIFPort wsifPort = getPort(portName);
  
          // If we've got to this line then the port must be available
          PortType pt = getPortTypeFromPortName(portName);
  
          // If the user has already created a proxy for this interface before
          // but is now asking for a proxy for the same interface but a different
          // portName, we should cache the proxy here and just call 
          // clientProxy.setPort() instead.
          WSIFClientProxy clientProxy =
              WSIFClientProxy.newInstance(
                  iface,
                  def,
                  service.getQName().getNamespaceURI(),
                  service.getQName().getLocalPart(),
                  portType.getQName().getNamespaceURI(),
                  portType.getQName().getLocalPart(),
                  typeMap);
  
          clientProxy.setPort(wsifPort);
          Object proxy = clientProxy.getProxy();
  
          // Tracing the proxy causes a hang!
          Trc.exit();
          return proxy;
      }
  
      /**
       * Get the dynamic proxy that will implement the interface iface
       */
      public Object getStub(Class iface) throws WSIFException {
          Trc.entry(this, iface);
  
          // Initialise the type mappings here (not in the constructor) so that
          // other products which use non-standard WSDL in their complexTypes
          // that WSIF wouldn't understand, can use the DynamicInvoker 
          // successfully. Using the DynamicInvoker means we would never come
          // through this code and so never try to parse the complexTypes.
          // Obviously if the user wants to use dynamic proxies then we have to 
          // parse the complex types.
          if (!typeMapInitialised) {
              initialiseTypeMappings();
              typeMapInitialised = true;
          }
  
          // if the port is not available, force the expection now rather
          // rather than go through the rest of this method             
          WSIFPort wsifPort = getPort();
  
          // Chosen port has been stored so use it to find portType
          String portName = chosenPort.getName();
          PortType pt = getPortTypeFromPortName(portName);
  
          // If the user has already created a proxy for this interface before
          // but is now asking for a proxy for the same interface but a different
          // portName, we should cache the proxy here and just call 
          // clientProxy.setPort() instead.
          WSIFClientProxy clientProxy =
              WSIFClientProxy.newInstance(
                  iface,
                  def,
                  service.getQName().getNamespaceURI(),
                  service.getQName().getLocalPart(),
                  pt.getQName().getNamespaceURI(),
                  pt.getQName().getLocalPart(),
                  typeMap);
  
          clientProxy.setPort(wsifPort);
          Object proxy = clientProxy.getProxy();
  
          // Tracing the proxy causes a hang!
          Trc.exit();
          return proxy;
      }
  
      /**
       * Add new WSDL model extension registry that is shared by all
       * dynamic WSIF providers.
       */
      public static void addExtensionRegistry(ExtensionRegistry reg) {
          Trc.entry(null, reg);
          providersExtRegs.addExtensionRegistry(reg);
          Trc.exit();
      }
  
      /**
       * Return extension registry that contains ALL declared extensions.
       * This is special registry that does not allow to register serializers
       * but only to add new extension registreis through
       * addExtensionRegistry method.
       *
       * @see #addExtensionRegistry
       */
      public static ExtensionRegistry getCompositeExtensionRegistry() {
          Trc.entry(null);
          Trc.exit(providersExtRegs);
          return providersExtRegs;
      }
  
      private void init(Definition def, Service service, PortType portType)
          throws WSIFException {
          if (def == null)
              throw new IllegalArgumentException("WSDL definition can not be null");
          checkWSDLForWSIF(def);
  
          if (service == null) {
              Map services = WSIFUtils.getAllItems(def, "Service");
  
              service = (Service) WSIFUtils.getNamedItem(services, null, "Service");
          }
  
          if (portType == null) {
              // if all ports have the same portType --> use it
              Map ports = service.getPorts();
              if (ports.size() == 0) {
                  throw new WSIFException(
                      "WSDL must contain at least one port in " + service.getQName());
              }
  
              for (Iterator i = ports.values().iterator(); i.hasNext();) {
                  Port port = (Port) i.next();
                  if (portType == null) {
                      portType = port.getBinding().getPortType();
                  } else {
                      PortType pt = port.getBinding().getPortType();
                      if (!pt.getQName().equals(portType.getQName())) {
                          throw new WSIFException(
                              "when no port type was specified all ports "
                                  + "must have the same port type in WSDL service "
                                  + service.getQName());
                      }
                  }
              }
              if (portType == null) {
                  throw new IllegalArgumentException(
                      "WSDL more than one portType in service " + service);
  
              }
          }
          this.def = def;
          this.service = service;
          this.portType = portType;
  
          // checkPortTypeIsRPC(Definition def, PortType portType) has been replaced 
by 
          // checkPortTypeInformation(Definition def, PortType portType) since "Input 
Only"
          // operations are supported.
          checkPortTypeInformation(def, portType);
  
          // get all ports from service that has given portType
  
          Map ports = service.getPorts();
          // check that service has at least one port ...
          if (ports.size() == 0) {
              throw new WSIFException(
                  "WSDL must contain at least one port in " + service.getQName());
          }
  
          myPortsMap = new Hashtable();
          for (Iterator i = ports.values().iterator(); i.hasNext();) {
              Port port = (Port) i.next();
  
              Binding binding = port.getBinding();
              if (binding == null)
                  continue; // Ignore this error for the moment
  
              try {
                  // Ignore port if provider is not available for supporting it
                  List bindingExList = port.getBinding().getExtensibilityElements();
                  ExtensibilityElement bindingFirstEx =
                      (ExtensibilityElement) bindingExList.get(0);
                  String bindingNS = bindingFirstEx.getElementType().getNamespaceURI();
                  String addressNS = bindingNS;
                  try {
                      List addressExList = port.getExtensibilityElements();
                      ExtensibilityElement addressFirstEx =
                          (ExtensibilityElement) addressExList.get(0);
                      addressNS = addressFirstEx.getElementType().getNamespaceURI();
                  } catch (NullPointerException npe) {
                                Trc.ignoredException(npe);
                                        // ignore
                  } catch (ArrayIndexOutOfBoundsException aie) {
                                Trc.ignoredException(aie);
                                        // Extensibility element 0 does not exist
                                        // Allow address namespace to be the same as 
binding
                  }
                  // Check for a provider that supports the 
                  if (WSIFPluggableProviders.isProviderAvailable(bindingNS, addressNS) 
) {
                     // check if port has the same port type
                     if (binding.getPortType().getQName().equals(portType.getQName())) 
{
                        String portName = port.getName();
                        myPortsMap.put(portName, port);
                     }
                  }
              } catch (NullPointerException e) {
                        Trc.ignoredException(e);
                  // Binding or extensibility element or QName was null
                  // any of which means something's not right with
                  // the port so don't include it.
              } catch (ArrayIndexOutOfBoundsException aie) {
                        Trc.ignoredException(aie);
                                // Extensibility element 0 does not exist
              }
          }
          int size = myPortsMap.size();
          myPortsArr = new Port[size];
          int count = 0;
          for (Iterator i = myPortsMap.values().iterator(); i.hasNext();) {
              // NOTE: there is no order in ports (it is hash function dependent...)
              Port port = (Port) i.next();
              myPortsArr[count++] = port;
          }
  
          // Provide the WSIDDynamicTypeMap with a list of all of the custom
          // types in the wsdl
          typeMap.setAllTypes(getAllCustomTypes());
      }
  
      /**
       * Get a list of all the custom complexTypes and simpleTypes in the wsdl
       */
      private ArrayList getAllCustomTypes() {
          ArrayList types = new ArrayList();
          Iterator typeMappingIterator = getDefaultTypeMappings();
          if (typeMappingIterator != null) {
              while (typeMappingIterator.hasNext()) {
                  TypeMapping tm = (TypeMapping) typeMappingIterator.next();
                  if (tm != null) {
                      String namespaceURI = tm.elementType.getNamespaceURI();
                      if (!namespaceURI.equals(WSIFConstants.NS_URI_1999_SCHEMA_XSD)
                          && !namespaceURI.equals(WSIFConstants.NS_URI_2000_SCHEMA_XSD)
                          && 
!namespaceURI.equals(WSIFConstants.NS_URI_2001_SCHEMA_XSD)) {
                          QName element = tm.elementType;
                          if (element != null) {
                              types.add(element);
                          }
                      }
                  }
              }
          }
          return types;
      }
  
      /**
       * Get a list of all the default mappings for complexTypes and simpleTypes 
       * in the wsdl
       */
      private Iterator getDefaultTypeMappings() {
          if (typeReg != null) {
                return typeReg.values().iterator();
        }
          typeReg = new HashMap();
          List typesElList = Utils.getAllTypesElements(def);
          if (typesElList.size() > 0) {
              String schemaURI1999 = WSIFConstants.NS_URI_1999_SCHEMA_XSD;
              Schema2Java s2j1999 = new Schema2Java(schemaURI1999);
              QName qElemSchema1999 = new QName(schemaURI1999, "schema");
              String schemaURI2000 = WSIFConstants.NS_URI_2000_SCHEMA_XSD;
              Schema2Java s2j2000 = new Schema2Java(schemaURI2000);
              QName qElemSchema2000 = new QName(schemaURI2000, "schema");
              String schemaURI2001 = WSIFConstants.NS_URI_2001_SCHEMA_XSD;
              Schema2Java s2j2001 = new Schema2Java(schemaURI2001);
              QName qElemSchema2001 = new QName(schemaURI2001, "schema");
  
              Iterator typesElIterator = typesElList.iterator();
              while (typesElIterator.hasNext()) {
                  UnknownExtensibilityElement unknExEl =
                      (UnknownExtensibilityElement) typesElIterator.next();
                  Element schemaEl = unknExEl.getElement();
                  try {
                      if (QNameUtils.matches(qElemSchema1999, schemaEl)
                          || QNameUtils.matches(qElemSchema2000, schemaEl)
                          || QNameUtils.matches(qElemSchema2001, schemaEl)) {
                          //Hashtable typeReg = new Hashtable();
                          if (QNameUtils.matches(qElemSchema1999, schemaEl))
                              s2j1999.createJavaMapping(schemaEl, typeReg);
                          else if (QNameUtils.matches(qElemSchema2000, schemaEl))
                              s2j2000.createJavaMapping(schemaEl, typeReg);
                          else
                              s2j2001.createJavaMapping(schemaEl, typeReg);
                      }
                  } catch (Exception e) {
                                Trc.ignoredException(e);
                      //ignored
                  }
              }
          }
          return typeReg.values().iterator();
      }
  
      /**
       * Initialize default mappings between custom complex types and simple types and
       * Java classes.
       */
      private void initialiseTypeMappings() throws WSIFException {
          Iterator typeMappingIterator = getDefaultTypeMappings();
          if (typeMappingIterator != null) {
              while (typeMappingIterator.hasNext()) {
                  TypeMapping tm = (TypeMapping) typeMappingIterator.next();
  
                  if (tm.elementType != null && tm.elementType.getNamespaceURI() != 
null) {
                      String namespaceURI = tm.elementType.getNamespaceURI();
                      if (namespaceURI != null
                          && !namespaceURI.equals(WSIFConstants.NS_URI_1999_SCHEMA_XSD)
                          && !namespaceURI.equals(WSIFConstants.NS_URI_2000_SCHEMA_XSD)
                          && !namespaceURI.equals(WSIFConstants.NS_URI_2001_SCHEMA_XSD)
                          && !namespaceURI.equals(WSIFConstants.NS_URI_SOAP_ENC)
                          && tm.javaType != null) {
                          String packageName = Utils.getPackageName(tm.javaType);
                          if (packageName != null && !packageName.equals("")) {
                                packageName += ".";
                          }
                          String className = packageName + 
Utils.getClassName(tm.javaType);
                          Class clazz = null;
  
                          try {
                              clazz =
                                  Class.forName(className, true, 
Thread.currentThread().getContextClassLoader());
                          } catch (ClassNotFoundException e) {
                              // Ignore error - mapping will not be added
                              Trc.ignoredException(e);
                          }
                          // Create a new mapping but don't override one that already 
exists for this element type
                          if (clazz != null) {
                                mapType(tm.elementType, clazz, false);
                          }
                      }
                  }
              } // end while
          }
      }
  
      /**
       * Check PortType information is consistent. This method can be updated when
       * new operation types are supported.
       */
      private void checkPortTypeInformation(Definition def, PortType portType)
          throws WSIFException {
          List operationList = portType.getOperations();
  
          // process each operation to create dynamic operation instance
          for (Iterator i = operationList.iterator(); i.hasNext();) {
              Operation op = (Operation) i.next();
              String name = op.getName();
              if (op.isUndefined()) {
                  throw new WSIFException("operation " + name + " is undefined!");
              }
              OperationType opType = op.getStyle();
              if (opType == null) {
                  throw new WSIFException("operation " + name + " has no type!");
              }
              if (opType.equals(OperationType.REQUEST_RESPONSE)) {
                  Input input = op.getInput();
                  Output output = op.getOutput();
                  if (input == null) {
                      throw new WSIFException("missing input message for operation " + 
name);
                  }
                  if (output == null) {
                      throw new WSIFException("missing output message for operation " 
+ name);
                  }
              } else if (opType.equals(OperationType.ONE_WAY)) {
                  Input input = op.getInput();
                  if (input == null) {
                      throw new WSIFException("missing input message for operation " + 
name);
                  }
              } else {
                  // Log message
                  MessageLogger.log(
                      "WSIF.0004E",
                      opType,
                      portType.getQName().getLocalPart());
  
                  // End message
                  throw new WSIFException(
                      "operation type "
                          + opType
                          + " is not supported in port instance for "
                          + portType.getQName());
              }
          }
      }
  
      private void checkWSDLForWSIF(Definition def) throws WSIFException {
          try {
              checkWSDL(def);
          } catch (WSDLException ex) {
                Trc.exception(ex);
              throw new WSIFException("invalid WSDL defintion " + def.getQName(), ex);
          }
      }
  
      /**
       * Check WSDL defintion to make sure it does not contain undefined
       * elements (typical case is referncing not defined portType).
       * <p><b>NOTE:</b> check is done only for curent document and not
       *  recursively for imported ones (they may be invalid but this
       *  port factory may not need them...).
       */
      private void checkWSDL(Definition def) throws WSDLException {
          for (Iterator i = def.getMessages().values().iterator(); i.hasNext();) {
              Message v = (Message) i.next();
              if (v.isUndefined()) {
                  throw new WSDLException(
                      WSDLException.INVALID_WSDL,
                      "referencing undefined message " + v);
              }
          }
          for (Iterator i = def.getPortTypes().values().iterator(); i.hasNext();) {
              PortType v = (PortType) i.next();
              if (v.isUndefined()) {
                  throw new WSDLException(
                      WSDLException.INVALID_WSDL,
                      "referencing undefined portType " + v);
              }
          }
          for (Iterator i = def.getBindings().values().iterator(); i.hasNext();) {
              Binding v = (Binding) i.next();
              if (v.isUndefined()) {
                  throw new WSDLException(
                      WSDLException.INVALID_WSDL,
                      "referencing undefined binding " + v);
              }
          }
      }
  
      /**
      * Get the Definition object representing the wsdl document
      * @return The Definition object
      */
      public Definition getDefinition() {
          Trc.entry(this);
          Trc.exit(def);
          return def;
      }
  
      public String deep() {
          String buff = "";
          try {
              buff = new String(this.toString());
              buff += "\nprovidersExtRegs:"
                  + (providersExtRegs == null ? "null" : providersExtRegs.toString());
              buff += "\ndef:" + Trc.brief(def);
              buff += "\nservice:" + Trc.brief(service);
              buff += "\nportType:" + Trc.brief(portType);
              buff += "\nmyPortsArr:" + (myPortsArr == null ? "null" : 
myPortsArr.toString());
              buff += "\nmyPortsMap:" + Trc.brief(myPortsMap);
              buff += "\ntypeMap:" + (typeMap == null ? "null" : typeMap.toString());
              buff += "\ntypeMapInitialised:" + typeMapInitialised;
              buff += "\npreferredPort:" + (preferredPort == null ? "null" : 
preferredPort);
              buff += "\nchosenPort:" + Trc.brief(chosenPort);
          } catch (Exception e) {
              Trc.exceptionInTrace(e);
          }
          return buff;
      }
  }
  
  
  
  
  1.1                  
xml-axis-wsif/java/samples/customfactory/client/MyPrivateCompositeExtensionRegistry.java
  
  Index: MyPrivateCompositeExtensionRegistry.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 [EMAIL PROTECTED]
   *
   * 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 customfactory.client;
  
  import java.util.Enumeration;
  import java.util.Vector;
  
  import javax.wsdl.WSDLException;
  import javax.wsdl.extensions.ExtensibilityElement;
  import javax.wsdl.extensions.ExtensionDeserializer;
  import javax.wsdl.extensions.ExtensionRegistry;
  import javax.wsdl.extensions.ExtensionSerializer;
  import javax.wsdl.extensions.UnknownExtensionDeserializer;
  import javax.wsdl.extensions.UnknownExtensionSerializer;
  import javax.xml.namespace.QName;
  
  import org.apache.wsif.logging.Trc;
  import org.apache.wsif.wsdl.extensions.ejb.EJBBindingSerializer;
  import org.apache.wsif.wsdl.extensions.format.FormatBindingSerializer;
  import org.apache.wsif.wsdl.extensions.java.JavaBindingSerializer;
  
  import com.ibm.wsdl.extensions.PopulatedExtensionRegistry;
  
  /**
   * This is utility class that allows to aggregate multiple
   * extensions registries into one. By default all standard WSDL4J
   * extensions are made available.
   * 
   * @author Alekander Slominski
   * @author Sanjiva Weerawarana
   * @author Owen Burroughs <[EMAIL PROTECTED]>
   * @author Ant Elder <[EMAIL PROTECTED]>
   * @author Jeremy Hughes <[EMAIL PROTECTED]>
   * @author Mark Whitlock <[EMAIL PROTECTED]>
   */
  
  class MyPrivateCompositeExtensionRegistry extends ExtensionRegistry {
        private static final long serialVersionUID = 1L;
      private Vector extRegs = new Vector();
  
      MyPrivateCompositeExtensionRegistry() {
          Trc.entry(this);
  
          // Add (de)serializers for Java, EJB and Format extensions to the
          // PopulatedExetensionRegistry and add the registry to our list
          PopulatedExtensionRegistry per = new PopulatedExtensionRegistry();
          JavaBindingSerializer javaBindingSerializer = new JavaBindingSerializer();
          javaBindingSerializer.registerSerializer(per);
          FormatBindingSerializer formatSerializer = new FormatBindingSerializer();
          formatSerializer.registerSerializer(per);
          EJBBindingSerializer ejbBindingSerializer = new EJBBindingSerializer();
          ejbBindingSerializer.registerSerializer(per);
          extRegs.add(per);
          Trc.exit();
      }
  
      public void addExtensionRegistry(ExtensionRegistry reg) {
          Trc.entry(this, reg);
          extRegs.add(reg);
          Trc.exit();
      }
  
      public void registerSerializer(
          Class parentType,
          Class extensionType,
          ExtensionSerializer es) {
          throw new RuntimeException(
              getClass() + " does not allow to register serializers");
      }
  
      public void registerDeserializer(
          Class parentType,
          QName elementType,
          ExtensionDeserializer ed) {
          throw new RuntimeException(
              getClass() + " does not allow to register deserializers");
      }
  
      public ExtensionSerializer querySerializer(
          Class parentType,
          QName extensionType)
          throws WSDLException {
          Trc.entry(this, parentType, extensionType);
  
          ExtensionSerializer ser;
          Enumeration enum = extRegs.elements();
          while (enum.hasMoreElements()) {
              ExtensionRegistry reg = (ExtensionRegistry) enum.nextElement();
              try {
                  ser = reg.querySerializer(parentType, extensionType);
                  // Check that we're not looking at the default serializer
                  ExtensionSerializer def = reg.getDefaultSerializer();
                  if (ser != null && !(ser.equals(def))) {
                      Trc.exit(ser);
                      return ser;
                  }
              } catch (WSDLException ex) {
                        Trc.exception(ex);
                  throw ex;
              }
          }
          ser = new UnknownExtensionSerializer();
          Trc.exit();
          return ser;
      }
  
      public ExtensionDeserializer queryDeserializer(
          Class parentType,
          QName elementType)
          throws WSDLException {
          Trc.entry(this, parentType, elementType);
  
          ExtensionDeserializer deser;
          Enumeration enum = extRegs.elements();
          while (enum.hasMoreElements()) {
              ExtensionRegistry reg = (ExtensionRegistry) enum.nextElement();
              try {
                  deser = reg.queryDeserializer(parentType, elementType);
                  // Check that we're not looking at the default deserializer
                  ExtensionDeserializer def = reg.getDefaultDeserializer();
                  if (deser != null && !(deser.equals(def))) {
                      Trc.exit(deser);
                      return deser;
                  }
              } catch (WSDLException ex) {
                        Trc.exception(ex);
                  throw ex;
              }
          }
          deser = new UnknownExtensionDeserializer();
          Trc.exit(deser);
          return deser;
      }
  
      public ExtensibilityElement createExtension(
          Class parentType,
          QName elementType)
          throws WSDLException {
          Trc.entry(this, parentType, elementType);
  
          ExtensibilityElement ee;
          Enumeration enum = extRegs.elements();
          while (enum.hasMoreElements()) {
              ExtensionRegistry reg = (ExtensionRegistry) enum.nextElement();
              try {
                  ee = reg.createExtension(parentType, elementType);
                  Trc.exit(ee);
                  return ee;
              } catch (WSDLException ignored) {
                        Trc.ignoredException(ignored);
              }
          }
          ee = super.createExtension(parentType, elementType);
          Trc.exit(ee);
          return ee;
      }
  
  }
  
  
  
  1.1                  
xml-axis-wsif/java/samples/customfactory/client/dynamic/README.html
  
  Index: README.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Nirmal Mukhi">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <title>Web Services Invocation Framework: Samples</title>
  <link rel="stylesheet" href="wsif.css" type="text/css"></head>
  
  <body alink="#0000ff" bgcolor="#ffffff" leftmargin="2" topmargin="2" marginwidth="2" 
marginheight="2">
  
  <h2>
  Web Services Invocation Framework:<br>
  Invoking the CustomFactory Sample using WSIF's dynamic invocation interface</h2>
  <p>After you have <a href="../../../../doc/samples.html">set up the CLASSPATH in 
your environment</a>, to invoke this sample using WSIF's DII, run the DynamicInvoker 
class. Specify as command line arguments the location of the WSDL file for the 
stockquote sample followed by the operation you wish to invoke and the symbol for the 
company whose stockquote you are interested in. For example, <br><tt>java  
clients.DynamicInvoker samples/simplesoap/StockquoteSOAP.wsdl getQuote IBM</tt></p>
  <p>To see details of how the WSIF API is used to make invocations dynamically, take 
a look at the code for the <a 
href="../../../clients/DynamicInvoker.java">DynamicInvoker class</a>.</p>
  <hr width="100%">
  </body></html>
  
  
  1.1                  xml-axis-wsif/java/samples/customfactory/client/stub/README.html
  
  Index: README.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Nirmal Mukhi">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <title>Web Services Invocation Framework: Samples</title>
  <link rel="stylesheet" href="wsif.css" type="text/css"></head>
  
  <body alink="#0000ff" bgcolor="#ffffff" leftmargin="2" topmargin="2" marginwidth="2" 
marginheight="2">
  
  <h2>
  Web Services Invocation Framework:<br>
  Invoking the CustomFactory Sample through a high level stub interface</h2>
  First, you must <a href="../../../../doc/samples.html">set up the CLASSPATH in your 
environment</a>.
  <p>This directory contains a file called <tt>Run.java</tt> that contains the 
<tt>main</tt> method. This is the logic that uses the generated stub interface to run 
the sample. So you can run this class, specifying on the command line the location of 
the WSDL file for the sample and the symbol for the company whose stock quote you are 
interested in. For example, <br>
  <tt>java simplesoap.client.stub.Run samples/simplesoap/StockquoteSOAP.wsdl 
IBM</tt></p>
  <p>To generate the stub interface, you can use any tool that generates Java 
interfaces for WSDL services using their port type descriptions, such as WSDL2Java 
from Axis. WSIF assumes a correspondence between the generated Java interface and the 
WSDL port type that has its abstract description as specified in the JAX-RPC 
specification. This particular sample used WSDL2Java in the following way:<br>
  <tt>java org.apache.axis.wsdl.WSDL2Java ../../StockquoteSOAP.wsdl</tt><br>
  After the tool finished running, we deleted all the generated files except 
<tt>NetXmethodsServicesStockquoteStockQuotePortType.java</tt> (this is the java 
interface corresponding to the port type and is all that is required by WSIF).</p>
  <hr width="100%">
  </body></html>
  
  
  1.1                  xml-axis-wsif/java/samples/customfactory/client/stub/Run.java
  
  Index: Run.java
  ===================================================================
  package customfactory.client.stub;
  
  import org.apache.wsif.WSIFService;
  import org.apache.wsif.WSIFServiceFactory;
  import org.apache.wsif.WSIFException;
  import java.rmi.RemoteException;
  import 
customfactory.client.stub.com.themindelectric.www.NetXmethodsServicesStockquoteStockQuotePortType;
  
  /**
   * Simple class that Runs the customfactory sample using a pregenerated stub 
interface
   * To use this class, provide a company stock symbol 
   * on the command line. WSIF should then invoke the service with this information, 
   * using the port returned by the custom factory and returning with a recent 
stockquote.
   * @author Nirmal K. Mukhi ([EMAIL PROTECTED])
   */
  
  public class Run {
        
      public static void main(String[] args) {
          try {
  
              if (args.length != 2) {
                  System.out.println(
                      "Usage: java customfactory.client.stub.Run <wsdl location> 
<company symbol>");
                  System.exit(1);
              }
  
              // create a service factory
              WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
  
              // parse WSDL
              WSIFService service =
                  factory.getService(
                      args[0],
                      null,
                      null,
                      
"http://www.themindelectric.com/wsdl/net.xmethods.services.stockquote.StockQuote/";,
                      "net.xmethods.services.stockquote.StockQuotePortType");
              // create the stub
            // check if the user specified a preferred port
              NetXmethodsServicesStockquoteStockQuotePortType stub = null;
            stub = (NetXmethodsServicesStockquoteStockQuotePortType) 
                service.getStub(NetXmethodsServicesStockquoteStockQuotePortType.class);
  
              // do the invocation
              // args[1] is the company symbol
              float quote = stub.getQuote(args[1]);
              System.out.println(quote);
  
          } catch (WSIFException we) {
              System.out.println(
                  "Error while executing sample, received an exception from WSIF; 
details:");
              we.printStackTrace();
          } catch (RemoteException re) {
              System.out.println(
                  "Error while executing sample, received an exception due to remote 
invocation; details:");
              re.printStackTrace();
          }
      }
  }
  
  
  
  1.1                  
xml-axis-wsif/java/samples/customfactory/client/stub/com/themindelectric/www/NetXmethodsServicesStockquoteStockQuotePortType.java
  
  Index: NetXmethodsServicesStockquoteStockQuotePortType.java
  ===================================================================
  /**
   * NetXmethodsServicesStockquoteStockQuotePortType.java
   *
   * This file was auto-generated from WSDL
   * by the Apache Axis WSDL2Java emitter.
   */
  
  package customfactory.client.stub.com.themindelectric.www;
  
  public interface NetXmethodsServicesStockquoteStockQuotePortType extends 
java.rmi.Remote {
      public float getQuote(java.lang.String symbol) throws java.rmi.RemoteException;
  }
  
  
  
  1.1                  xml-axis-wsif/java/samples/customfactory/service/README.html
  
  Index: README.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Nirmal Mukhi">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <title>Web Services Invocation Framework: Samples</title>
  <link rel="stylesheet" href="wsif.css" type="text/css"></head>
  
  <body alink="#0000ff" bgcolor="#ffffff" leftmargin="2" topmargin="2" marginwidth="2" 
marginheight="2">
  
  <h2>
  Web Services Invocation Framework:<br>
  Java implementation of the StockQuoteService</h2>
  Take a look at the <tt><a 
href="StockQuoteService.java">StockQuoteService.java</a></tt> file in this directory. 
<p>This class implements the stock quote service functionality advertised in <a 
href="../StockQuoteService.wsdl">the sample WSDL</a>. This implementation actually 
uses HTTP GET to communicate with a remote web site that returns the quote for a given 
stock symbol; of course it could also look up a local table of stock quotes; the 
details are completely hidden from the code that accesses the class. Note that the 
WSDL file refers to this class as the service endpoint in the <tt>java:address</tt> 
element.</p>
  <hr width="100%">
  </body></html>
  
  
  
  1.1                  
xml-axis-wsif/java/samples/customfactory/service/StockQuoteService.java
  
  Index: StockQuoteService.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 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 "AXIS" 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 [EMAIL PROTECTED]
   *
   * 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package customfactory.service;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.NodeList;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import java.net.URL;
  
  /**
   *
   * @author Sanjiva Weerawarana ([EMAIL PROTECTED])
   * @author Doug Davis ([EMAIL PROTECTED])
   */
  public class StockQuoteService {
    public float getQuote (String symbol) throws Exception {
      // get a real (delayed by 20min) stockquote from 
      // http://www.xmltoday.com/examples/stockquote/. The IP addr 
      // below came from the host that the above form posts to ..
  
      if ( symbol.equals("XXX") ) return( (float) 55.25 );
  
      URL          url = new URL( "http://services.xmethods.net/"; +
                                  "axis/getQuote?s="+symbol );
  
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder        db  = dbf.newDocumentBuilder();
  
      Document doc  = db.parse( url.toExternalForm() );
      Element  elem = doc.getDocumentElement();
      NodeList list = elem.getElementsByTagName( "stock_quote" );
  
      if ( list != null && list.getLength() != 0 ) {
        elem = (Element) list.item(0);
        list = elem.getElementsByTagName( "price" );
        elem = (Element) list.item(0);
        String quoteStr = elem.getAttribute("value");
        try {
          return Float.valueOf(quoteStr).floatValue();
        } catch (NumberFormatException e1) {
          // maybe its an int?
          try {
            return Integer.valueOf(quoteStr).intValue() * 1.0F;
          } catch (NumberFormatException e2) {
            return -1.0F;
          }
        }
      }
      return( 0 );
    }
  }
  
  
  
  1.5       +1 -0      xml-axis-wsif/java/samples/simplesoap/client/dynamic/README.html
  
  Index: README.html
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/samples/simplesoap/client/dynamic/README.html,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- README.html       12 Dec 2002 14:41:02 -0000      1.4
  +++ README.html       20 Dec 2002 12:53:22 -0000      1.5
  @@ -11,5 +11,6 @@
   Web Services Invocation Framework:<br>
   Invoking the SimpleSOAP Sample using WSIF's dynamic invocation interface</h2>
   <p>After you have <a href="../../../../doc/samples.html">set up the CLASSPATH in 
your environment</a>, to invoke this sample using WSIF's DII, run the DynamicInvoker 
class. Specify as command line arguments the location of the WSDL file for the 
stockquote sample followed by the operation you wish to invoke and the symbol for the 
company whose stockquote you are interested in. For example, <br><tt>java  
clients.DynamicInvoker samples/simplesoap/StockquoteSOAP.wsdl getQuote IBM</tt></p>
  +<p>To see details of how the WSIF API is used to make invocations dynamically, take 
a look at the code for the <a 
href="../../../clients/DynamicInvoker.java">DynamicInvoker class</a>.</p>
   <hr width="100%">
   </body></html>
  
  
  


Reply via email to