antelder    2003/03/31 04:51:12

  Modified:    java/src/org/apache/wsif/tools/tojava
                        WSIFJavaTestCaseWriter.java
               java/src/org/apache/wsif/providers ProviderUtils.java
               java/src/org/apache/wsif/tools WSDL2WSDL.java
  Added:       java/src/org/apache/wsif/tools/wsdl BindingGenerator.java
                        EJBBindingGenerator.java JavaBindingGenerator.java
                        ModelBindingGenerator.java
                        SOAPJMSBindingGenerator.java
  Removed:     java/src/org/apache/wsif/tools/tojava
                        JavaBindingGenerator.java
  Log:
  Start enabling WSDL2WSDL for beter binding support
  
  Revision  Changes    Path
  1.1                  
xml-axis-wsif/java/src/org/apache/wsif/tools/wsdl/BindingGenerator.java
  
  Index: BindingGenerator.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 org.apache.wsif.tools.wsdl;
  
  import javax.wsdl.Definition;
  
  /**
   * Interface for classes capable of adding new bindings to a WSDL Definition 
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
   */
  public interface BindingGenerator {
  
      public String getBindingTypeName();
  
      public void addBindings(Definition def);
  
  }
  
  
  
  1.1                  
xml-axis-wsif/java/src/org/apache/wsif/tools/wsdl/EJBBindingGenerator.java
  
  Index: EJBBindingGenerator.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 org.apache.wsif.tools.wsdl;
  
  import java.util.Iterator;
  import java.util.List;
  
  import javax.wsdl.Binding;
  import javax.wsdl.BindingOperation;
  import javax.wsdl.Definition;
  import javax.wsdl.Input;
  import javax.wsdl.Message;
  import javax.wsdl.Operation;
  import javax.wsdl.Output;
  import javax.wsdl.Part;
  import javax.wsdl.Port;
  import javax.wsdl.PortType;
  import javax.xml.namespace.QName;
  
  import org.apache.wsif.wsdl.extensions.ejb.EJBAddress;
  import org.apache.wsif.wsdl.extensions.ejb.EJBBinding;
  import org.apache.wsif.wsdl.extensions.ejb.EJBBindingConstants;
  import org.apache.wsif.wsdl.extensions.ejb.EJBOperation;
  import org.apache.wsif.wsdl.extensions.format.FormatBindingConstants;
  import org.apache.wsif.wsdl.extensions.format.TypeMap;
  import org.apache.wsif.wsdl.extensions.format.TypeMapping;
  
  /**
   * Utility to add a WSIF Java binding to a WSDL4J definition
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
   */
  public class EJBBindingGenerator extends ModelBindingGenerator {
  
      // name of this BindingGenerators binding type
      protected static String ejbBindingTypeName = "ejb";
  
      /**
       * Construct a new binding generator
       */
      public EJBBindingGenerator() {
          super(ejbBindingTypeName);
      }
  
      /**
       * Dont add an EJBBinding for an existing EJBBinding
       */
      protected boolean isNewBindingRequired(Port port) {
          boolean wanted = true;
          Binding b = port.getBinding();
          List extEls = b.getExtensibilityElements();
          for (Iterator i = extEls.iterator(); wanted && i.hasNext();) {
              if (i.next() instanceof EJBBinding) {
                  wanted = false;
              }
          }
          return wanted;
      }
  
      /**
       * Add the EJB and Format binding namespaces
       */
      protected void doAddNamespace(Definition def) {
          def.addNamespace("ejb", EJBBindingConstants.NS_URI_EJB);
          def.addNamespace("format", FormatBindingConstants.NS_URI_FORMAT);
      }
  
      /**
       * Add the EJB and Format bindings
       */
      protected void doCreateBinding(PortType portType, Binding binding) {
          EJBBinding ejbBinding = new EJBBinding();
          binding.addExtensibilityElement(ejbBinding);
  
          TypeMapping formatTypeMapping = createFormatTypeMapping();
          binding.addExtensibilityElement(formatTypeMapping);
      }
  
      /**
       * Create the format binding
       * 
       * <format:typeMapping encoding="Java" style="Java">
       *    <format:typeMap typeName="typens:type" formatType="package.class" />
       *</format:typeMapping>
       * 
       * TODO: automatically create correct type mappings for definition
       */
      protected TypeMapping createFormatTypeMapping() {
          TypeMapping formatTypeMapping = new TypeMapping();
          formatTypeMapping.setEncoding("Java");
          formatTypeMapping.setStyle("Java");
  
          TypeMap tm = new TypeMap();
          tm.setTypeName(new QName("http://www.w3.org/2001/XMLSchema";, "string"));
          tm.setFormatType("java.lang.String");
  
          formatTypeMapping.addMap(tm);
          return formatTypeMapping;
      }
  
      /**
       * Create the Java binding operation
       */
      protected void doCreateBindingOperation(
          Operation op,
          BindingOperation bop) {
          EJBOperation ejbOp = new EJBOperation();
          ejbOp.setMethodName(op.getName());
          ejbOp.setEjbInterface("Remote");
  
          Input input = op.getInput();
          if (input != null) {
              Message msg = input.getMessage();
              if (msg != null) {
                  List parts = msg.getOrderedParts(null);
                  String partList = "";
                  for (int j = 0; j < parts.size(); j++) {
                      partList += ((Part) parts.get(j)).getName();
                      if (j < parts.size()) {
                          partList += " ";
                      }
                  }
                  ejbOp.setParameterOrder(partList);
              }
          }
  
          Output output = op.getOutput();
          if (output != null) {
              Message msg = output.getMessage();
              if (msg != null) {
                  List parts = msg.getOrderedParts(null);
                  if (parts.size() > 0) {
                      Part part = (Part) parts.get(0);
                      String partName = part.getName();
                      ejbOp.setReturnPart(partName);
                  }
              }
          }
          bop.addExtensibilityElement(ejbOp);
      }
  
      /**
       * Create the java address for the port
       * 
       * <ejb:address className="addressbook.wsiftypes.AddressBookHome"
       *     jndiName="/services/addressbook"
       *     initialContextFactory="com.mycompany.server.MyappInitialContext"
       *     jndiProviderURL="ormi://myserver.mycompany.com/ejbsample"/>
       */
      protected void doCreateServicePort(Port p) {
          EJBAddress addr = new EJBAddress();
          addr.setClassName("your.ejb.home.classname.here");
          addr.setJndiName("/your/jndi/name/here");
  //        addr.setInitialContextFactory("your.initial.context.here");
  //        addr.setJndiProviderURL("your://jndi.provider.url/here");
          p.addExtensibilityElement(addr);
      }
  
  }
  
  
  
  1.1                  
xml-axis-wsif/java/src/org/apache/wsif/tools/wsdl/JavaBindingGenerator.java
  
  Index: JavaBindingGenerator.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 org.apache.wsif.tools.wsdl;
  
  import java.util.Iterator;
  import java.util.List;
  
  import javax.wsdl.Binding;
  import javax.wsdl.BindingOperation;
  import javax.wsdl.Definition;
  import javax.wsdl.Input;
  import javax.wsdl.Message;
  import javax.wsdl.Operation;
  import javax.wsdl.Output;
  import javax.wsdl.Part;
  import javax.wsdl.Port;
  import javax.wsdl.PortType;
  import javax.xml.namespace.QName;
  
  import org.apache.wsif.wsdl.extensions.format.FormatBindingConstants;
  import org.apache.wsif.wsdl.extensions.format.TypeMap;
  import org.apache.wsif.wsdl.extensions.format.TypeMapping;
  import org.apache.wsif.wsdl.extensions.java.JavaAddress;
  import org.apache.wsif.wsdl.extensions.java.JavaBinding;
  import org.apache.wsif.wsdl.extensions.java.JavaBindingConstants;
  import org.apache.wsif.wsdl.extensions.java.JavaOperation;
  
  /**
   * Utility to add a WSIF Java binding to a WSDL4J definition
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
   */
  public class JavaBindingGenerator extends ModelBindingGenerator {
  
      // name of this BindingGenerators binding type
      protected static String javaBindingTypeName = "java";
  
      /**
       * Construct a new binding generator
       */
      public JavaBindingGenerator(String name) {
          super(name);
      }
  
      /**
       * Construct a new binding generator
       */
      public JavaBindingGenerator() {
          super(javaBindingTypeName);
      }
  
      /**
       * Dont add a Javabinding for an existing Java binding
       */
      protected boolean isNewBindingRequired(Port port) {
          boolean wanted = true;
          Binding b = port.getBinding();
          List extEls = b.getExtensibilityElements();
          for (Iterator i = extEls.iterator(); wanted && i.hasNext();) {
              if (i.next() instanceof JavaBinding) {
                  wanted = false;
              }
          }
          return wanted;
      }
  
      /**
       * Add the Java and Format binding namespaces
       */
      protected void doAddNamespace(Definition def) {
          def.addNamespace("java", JavaBindingConstants.NS_URI_JAVA);
          def.addNamespace("format", FormatBindingConstants.NS_URI_FORMAT);
      }
  
      /**
       * Add the Java and Format bindings
       */
      protected void doCreateBinding(PortType portType, Binding binding) {
          JavaBinding javaBinding = new JavaBinding();
          binding.addExtensibilityElement(javaBinding);
  
          TypeMapping formatTypeMapping = createFormatTypeMapping();
          binding.addExtensibilityElement(formatTypeMapping);
      }
  
      /**
       * Create the format binding
       * 
       * <format:typeMapping encoding="Java" style="Java">
       *    <format:typeMap typeName="typens:type" formatType="package.class" />
       *</format:typeMapping>
       * 
       * TODO: automatically create correct type mappings for definition
       */
      protected TypeMapping createFormatTypeMapping() {
          TypeMapping formatTypeMapping = new TypeMapping();
          formatTypeMapping.setEncoding("Java");
          formatTypeMapping.setStyle("Java");
  
          TypeMap tm = new TypeMap();
          tm.setTypeName(new QName("http://www.w3.org/2001/XMLSchema";, "string"));
          tm.setFormatType("java.lang.String");
  
          formatTypeMapping.addMap(tm);
          return formatTypeMapping;
      }
  
      /**
       * Create the Java binding operation
       */
      protected void doCreateBindingOperation(
          Operation op,
          BindingOperation bop) {
          JavaOperation javaOp = new JavaOperation();
          javaOp.setMethodName(op.getName());
          javaOp.setMethodType("Instance");
  
          Input input = op.getInput();
          if (input != null) {
              Message msg = input.getMessage();
              if (msg != null) {
                  List parts = msg.getOrderedParts(null);
                  String partList = "";
                  for (int j = 0; j < parts.size(); j++) {
                      partList += ((Part) parts.get(j)).getName();
                      if (j < parts.size()) {
                          partList += " ";
                      }
                  }
                  javaOp.setParameterOrder(partList);
              }
          }
  
          Output output = op.getOutput();
          if (output != null) {
              Message msg = output.getMessage();
              if (msg != null) {
                  List parts = msg.getOrderedParts(null);
                  if (parts.size() > 0) {
                      Part part = (Part) parts.get(0);
                      String partName = part.getName();
                      javaOp.setReturnPart(partName);
                  }
              }
          }
          bop.addExtensibilityElement(javaOp);
      }
  
      /**
       * Create the java address for the port
       */
      protected void doCreateServicePort(Port p) {
          JavaAddress ja = new JavaAddress();
          ja.setClassName("your.target.class.here");
          p.addExtensibilityElement(ja);
      }
  
  }
  
  
  
  1.1                  
xml-axis-wsif/java/src/org/apache/wsif/tools/wsdl/ModelBindingGenerator.java
  
  Index: ModelBindingGenerator.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 org.apache.wsif.tools.wsdl;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
  import javax.wsdl.Binding;
  import javax.wsdl.BindingInput;
  import javax.wsdl.BindingOperation;
  import javax.wsdl.BindingOutput;
  import javax.wsdl.Definition;
  import javax.wsdl.Input;
  import javax.wsdl.Operation;
  import javax.wsdl.Output;
  import javax.wsdl.Port;
  import javax.wsdl.PortType;
  import javax.wsdl.Service;
  import javax.xml.namespace.QName;
  
  import org.apache.wsif.providers.ProviderUtils;
  import org.apache.wsif.util.WSIFUtils;
  
  import com.ibm.wsdl.BindingInputImpl;
  import com.ibm.wsdl.BindingOperationImpl;
  import com.ibm.wsdl.BindingOutputImpl;
  import com.ibm.wsdl.PortImpl;
  
  /**
   * Model for classes to add new bindings to a WSDL4J definition
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
   */
  public abstract class ModelBindingGenerator implements BindingGenerator {
  
      // name of the binding type this generates
      protected String bindingTypeName;
  
      /**
       * Construct a new binding generator
       */
      public ModelBindingGenerator(String bindingName) {
          this.bindingTypeName = bindingName;
      }
  
      /**
       * Returns the bindingTypeName.
       * @return String
       */
      public String getBindingTypeName() {
          return bindingTypeName;
      }
  
      /**
       * Adds new bindings to a WSDL4J Definition
       */
      public void addBindings(Definition def) {
          List newPorts = new ArrayList();
          List donePortTypes = new ArrayList();
  
          // for all the services in the WSDL
          Map services = def.getServices();
          for (Iterator i = services.keySet().iterator(); i.hasNext();) {
              QName serviceName = (QName) i.next();
              Service service = (Service) services.get(serviceName);
  
              // for all the ports in the service
              Map ports = service.getPorts();
              for (Iterator j = ports.keySet().iterator(); j.hasNext();) {
                  String portName = (String) j.next();
                  Port port = (Port) ports.get(portName);
                  PortType portType = port.getBinding().getPortType();
                  if (donePortTypes.contains(portType) == false) {
                      if (isNewBindingRequired(port) == true) {
                          Binding newBinding = createBinding(def, port);
                          def.addBinding(newBinding);
                          Port newPort =
                              createServicePort(service, port, newBinding);
                          newPorts.add(newPort);
                          donePortTypes.add(portType);
                      }
                  }
              }
  
              // add any new ports to the service
              for (Iterator j = newPorts.iterator(); j.hasNext();) {
                  service.addPort((Port) j.next());
              }
          }
  
          // only add namespaces if a binding was added
          if (donePortTypes.size() > 0) {
              doAddNamespace(def);
          }
      }
  
      /**
       * Is a new binding required for a Port
       */
      protected boolean isNewBindingRequired(Port port) {
          return true;
      }
  
      /**
       * Add any new namespaces to the Definition
       */
      protected void doAddNamespace(Definition def) {
      }
  
      /**
       * Create a new binding from an existing Port
       */
      protected Binding createBinding(Definition def, Port port) {
          Binding oldBinding = port.getBinding();
          PortType p = oldBinding.getPortType();
  
          Binding newBinding = def.createBinding();
          newBinding.setPortType(p);
          QName oldName = oldBinding.getQName();
          QName newName =
              new QName(
                  oldName.getNamespaceURI(),
                  oldName.getLocalPart()
                      + ProviderUtils.capitalizeFirst(getBindingTypeName()));
          newBinding.setQName(newName);
  
          doCreateBinding(p, newBinding);
  
          addOperations(p, newBinding);
          newBinding.setUndefined(false);
          return newBinding;
      }
  
      /**
       * Template method for subclasses to customise the binding
       */
      protected void doCreateBinding(PortType portType, Binding binding) {
      }
  
      /**
       * Adds the PortType operations to the binding
       */
      protected void addOperations(PortType p, Binding b) {
          for (Iterator i = p.getOperations().iterator(); i.hasNext();) {
              Operation op = (Operation) i.next();
  
              BindingOperation bop = new BindingOperationImpl();
              bop.setName(op.getName());
  
              doCreateBindingOperation(op, bop);
  
              Input input = op.getInput();
              if (input != null) {
                  BindingInput bin = new BindingInputImpl();
                  bin.setName(input.getName());
                  doCreateBindingInput(op, bop, bin);
                  bop.setBindingInput(bin);
              }
  
              Output output = op.getOutput();
              if (output != null) {
                  BindingOutput bout = new BindingOutputImpl();
                  bout.setName(output.getName());
                  doCreateBindingOutput(op, bop, bout);
                  bop.setBindingOutput(bout);
              }
  
              b.addBindingOperation(bop);
  
          }
      }
  
      /**
       * Template method for subclasses to customise the binding operation
       */
      protected void doCreateBindingOperation(
          Operation op,
          BindingOperation bop) {
      }
  
      /**
       * Template method for subclasses to customise the binding input
       */
      protected void doCreateBindingInput(
          Operation op,
          BindingOperation bop,
          BindingInput bin) {
      }
  
      /**
       * Template method for subclasses to customise the binding output
       */
      protected void doCreateBindingOutput(
          Operation op,
          BindingOperation bop,
          BindingOutput bout) {
      }
  
      /**
       * Adds a port to the service for the new binding
       */
      protected Port createServicePort(Service s, Port oldPort, Binding b) {
          Port port = new PortImpl();
          port.setName(
              oldPort.getName()
                  + ProviderUtils.capitalizeFirst(getBindingTypeName()));
          port.setBinding(b);
  
          doCreateServicePort(port);
  
          return port;
      }
  
      /**
       * Template method for subclasses to customise the service port
       */
      protected void doCreateServicePort(Port p) {
      }
  
  }
  
  
  
  1.1                  
xml-axis-wsif/java/src/org/apache/wsif/tools/wsdl/SOAPJMSBindingGenerator.java
  
  Index: SOAPJMSBindingGenerator.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 org.apache.wsif.tools.wsdl;
  
  import java.util.Iterator;
  import java.util.List;
  
  import javax.wsdl.Binding;
  import javax.wsdl.BindingOperation;
  import javax.wsdl.Definition;
  import javax.wsdl.Port;
  import javax.wsdl.extensions.ExtensibilityElement;
  import javax.wsdl.extensions.soap.SOAPAddress;
  import javax.wsdl.extensions.soap.SOAPBinding;
  import javax.xml.namespace.QName;
  
  import org.apache.wsif.providers.ProviderUtils;
  import org.apache.wsif.util.WSIFUtils;
  import org.apache.wsif.wsdl.extensions.jms.JMSConstants;
  
  import com.ibm.wsdl.extensions.soap.SOAPAddressImpl;
  import com.ibm.wsdl.extensions.soap.SOAPBindingImpl;
  
  /**
   * Utility to add a WSIF SOAP/JMS binding to a WSDL4J definition
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
   */
  public class SOAPJMSBindingGenerator extends ModelBindingGenerator {
  
      // name of this BindingGenerators binding type
      protected static String soapjmsBindingTypeName = "soapjms";
  
      /**
       * Construct a new binding generator
       */
      public SOAPJMSBindingGenerator(String name) {
          super(name);
      }
  
      /**
       * Construct a new binding generator
       */
      public SOAPJMSBindingGenerator() {
          super(soapjmsBindingTypeName);
      }
  
      /**
       * Only add a JMS binding for a SOAP binding,
       * and only if the SOAP binding doesn't already
       * have a JMS transport.
       */
      protected boolean isNewBindingRequired(Port port) {
          boolean wanted = false;
          Binding b = port.getBinding();
          List extEls = b.getExtensibilityElements();
          for (Iterator i = extEls.iterator(); !wanted && i.hasNext();) {
              Object o = i.next();
              if (o instanceof SOAPBinding) {
                  SOAPBinding sb = (SOAPBinding) o;
                  if (JMSConstants.NS_URI_SOAPJMS.equals(sb.getTransportURI())) {
                      wanted = false;
                  } else {
                      wanted = true;
                  }
              }
          }
          return wanted;
      }
  
      /**
       * Add the JMS binding namespaces
       */
      protected void doAddNamespaces(Definition def) {
          def.addNamespace("jms", JMSConstants.NS_URI_SOAPJMS);
      }
  
      /**
       * Make the new JMS binding
       * Overrides makeBining in ModelBindingGenerator as 
       * the new SOAPJMS binding is the same as the existing
       * SOAP binding with only the transport URL changed.
       */
      protected Binding createBinding(Definition def, Port port) {
          Binding oldBinding = port.getBinding();
          Binding newBinding = def.createBinding();
  
          newBinding.setDocumentationElement(
              oldBinding.getDocumentationElement());
          newBinding.setPortType(oldBinding.getPortType());
  
          QName oldBindingName = oldBinding.getQName();
          QName newBindingName =
              new QName(
                  oldBindingName.getNamespaceURI(),
                  oldBindingName.getLocalPart()
                      + ProviderUtils.capitalizeFirst(getBindingTypeName()));
          newBinding.setQName(newBindingName);
  
          List operations = oldBinding.getBindingOperations();
          for (Iterator i = operations.iterator(); i.hasNext();) {
              newBinding.addBindingOperation((BindingOperation) i.next());
          }
  
          List ees = oldBinding.getExtensibilityElements();
          for (Iterator i = ees.iterator(); i.hasNext();) {
              ExtensibilityElement ee = (ExtensibilityElement) i.next();
              if (ee instanceof SOAPBinding) {
                  ee = createSOAPJMSBinding((SOAPBinding) ee);
              }
              newBinding.addExtensibilityElement(ee);
          }
  
          newBinding.setUndefined(false);
          return newBinding;
      }
  
      /**
       * Create a new SOAP/JMS binding from a SOAPBinding
       */
      protected SOAPBinding createSOAPJMSBinding(SOAPBinding oldBinding) {
          SOAPBinding jmsSoapBinding = new SOAPBindingImpl();
          jmsSoapBinding.setElementType(oldBinding.getElementType());
          jmsSoapBinding.setRequired(oldBinding.getRequired());
          jmsSoapBinding.setStyle(oldBinding.getStyle());
          jmsSoapBinding.setTransportURI(JMSConstants.NS_URI_SOAPJMS);
          return jmsSoapBinding;
      }
  
      /**
       * Add the JMS location URL to the port
       */
      protected void doCreateServicePort(Port p) {
          SOAPAddress sa = new SOAPAddressImpl();
          sa.setLocationURI(
              
"jms:/queue?destination=yourQName|connectionFactory=yourQCF|initialContextFactory=com.sun.jndi.fscontext.RefFSContextFactory|jndiProviderURL=file:///JNDI-Directory");
          p.addExtensibilityElement(sa);
      }
  
  }
  
  
  
  1.3       +10 -32    
xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/WSIFJavaTestCaseWriter.java
  
  Index: WSIFJavaTestCaseWriter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/WSIFJavaTestCaseWriter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WSIFJavaTestCaseWriter.java       24 Mar 2003 14:07:27 -0000      1.2
  +++ WSIFJavaTestCaseWriter.java       31 Mar 2003 12:51:12 -0000      1.3
  @@ -365,7 +365,7 @@
           for (Iterator i = portType.getOperations().iterator(); i.hasNext();) {
               Operation op = (Operation) i.next();
               String opMethodName = makeExecuteOpMethodName(portType, op);
  -            addNewCodeLine(pw, opMethodName + "(stub);");
  +            addNewCodeLine(pw, opMethodName + "(portName, stub);");
           }
   
           skipLines(pw, 1);
  @@ -409,7 +409,7 @@
           String opMethodName = makeExecuteOpMethodName(portType, op);
           addCode(pw, opMethodName);
   
  -        addCode(pw, "(");
  +        addCode(pw, "(String portName, ");
           addCode(pw, seiName);
           addCode(pw, " stub) throws RemoteException {");
   
  @@ -472,11 +472,11 @@
               addCode(pw, " ");
               addCode(pw, returnPartName);
               addCode(pw, " = stub.");
  -            addCode(pw, lowercaseFirst(op.getName()));
  +            addCode(pw, ProviderUtils.lowercaseFirst(op.getName()));
               addCode(pw, "(");
           } else {
               addNewCodeLine(pw, "stub.");
  -            addCode(pw, lowercaseFirst(op.getName()));
  +            addCode(pw, ProviderUtils.lowercaseFirst(op.getName()));
               addCode(pw, "(");
           }
   
  @@ -492,7 +492,7 @@
           skipLines(pw, 1);
   
           if (returnPartName != null) {
  -            addNewCodeLine(pw, "System.out.println(\"operation '");
  +            addNewCodeLine(pw, "System.out.println(\" port \" + portName + \" 
operation '");
               addCode(pw, op.getName());
               addCode(pw, "' returned: \" + ");
               addCode(pw, returnPartName);
  @@ -685,7 +685,7 @@
                           + ";");
                   String setType;
                   if (Character.isLowerCase(className.charAt(0))) {
  -                    setType = capitalizeFirst(className);
  +                    setType = ProviderUtils.capitalizeFirst(className);
                   } else {
                       setType = "Object";
                   }
  @@ -745,7 +745,7 @@
                   String getType;
                   String cast;
                   if (Character.isLowerCase(className.charAt(0))) {
  -                    getType = capitalizeFirst(className);
  +                    getType = ProviderUtils.capitalizeFirst(className);
                       cast = "";
                   } else {
                       getType = "Object";
  @@ -820,7 +820,7 @@
           String methodName,
           String portName)
           throws IOException {
  -        String testMethodname = "test" + capitalizeFirst(methodName) + portName;
  +        String testMethodname = "test" + ProviderUtils.capitalizeFirst(methodName) 
+ portName;
           addNewCodeLine(pw, "public void " + testMethodname + "() {");
           tabIn();
           addNewCodeLine(pw, methodName + "(\"" + portName + "\");");
  @@ -841,33 +841,11 @@
           skipLines(pw, 1);
       } // writeMainMethod
   
  -    /**
  -     * Capatalise the first character of a String
  -     */
  -    protected static String capitalizeFirst(String name) {
  -        StringBuffer sb = new StringBuffer(name);
  -        if (sb.length() > 0) {
  -            sb.setCharAt(0, (char) ((sb.charAt(0) & (char) 223)));
  -        }
  -        return sb.toString();
  -    }
  -
  -    /**
  -     * Lowercase the first character of a String
  -     */
  -    protected static String lowercaseFirst(String name) {
  -        StringBuffer sb = new StringBuffer(name);
  -        if (sb.length() > 0) {
  -            sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
  -        }
  -        return sb.toString();
  -    }
  -
       protected String makeExecuteOpMethodName(PortType portType, Operation op) {
           String javaOpName = Utils.xmlNameToJavaClass(op.getName());
           String opMethodName = "executeOp" + javaOpName;
           if (isOverloaded(portType, op)) {
  -            opMethodName += capitalizeFirst(getInMsgName(op));
  +            opMethodName += ProviderUtils.capitalizeFirst(getInMsgName(op));
           }
           return opMethodName;
       }
  @@ -1036,7 +1014,7 @@
        * Gets the Service Endpoint Interface name for a WSDL portType
        */
       protected String getSEIName(PortType portType) {
  -        return capitalizeFirst(
  +        return ProviderUtils.capitalizeFirst(
               Utils.getJavaLocalName(getClassName(portType.getQName())));
       }
   
  
  
  
  1.8       +26 -1     
xml-axis-wsif/java/src/org/apache/wsif/providers/ProviderUtils.java
  
  Index: ProviderUtils.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/ProviderUtils.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ProviderUtils.java        21 Mar 2003 09:14:31 -0000      1.7
  +++ ProviderUtils.java        31 Mar 2003 12:51:12 -0000      1.8
  @@ -59,7 +59,6 @@
   
   import java.lang.reflect.Array;
   import java.util.ArrayList;
  -import java.util.Iterator;
   import java.util.List;
   
   import javax.wsdl.Definition;
  @@ -511,6 +510,32 @@
                        type = p.getElementName();
                }
                return type;
  +    }
  +
  +    /**
  +     * Capatalise the first character of a String
  +     * @param s   the string to be capatalized
  +     * @return String the capatalized String
  +     */
  +    public static String capitalizeFirst(String s) {
  +        StringBuffer sb = new StringBuffer(s);
  +        if (sb.length() > 0) {
  +            sb.setCharAt(0, (char) ((sb.charAt(0) & (char) 223)));
  +        }
  +        return sb.toString();
  +    }
  +
  +    /**
  +     * Lowercase the first character of a String
  +     * @param s   the string to be lowercased
  +     * @return String the lowercased String
  +     */
  +    public static String lowercaseFirst(String s) {
  +        StringBuffer sb = new StringBuffer(s);
  +        if (sb.length() > 0) {
  +            sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
  +        }
  +        return sb.toString();
       }
   
   }
  
  
  
  1.2       +41 -14    xml-axis-wsif/java/src/org/apache/wsif/tools/WSDL2WSDL.java
  
  Index: WSDL2WSDL.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/tools/WSDL2WSDL.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WSDL2WSDL.java    25 Mar 2003 10:07:17 -0000      1.1
  +++ WSDL2WSDL.java    31 Mar 2003 12:51:12 -0000      1.2
  @@ -61,7 +61,6 @@
   import java.io.FileWriter;
   import java.io.IOException;
   import java.util.ArrayList;
  -import java.util.Arrays;
   import java.util.Iterator;
   import java.util.List;
   import java.util.StringTokenizer;
  @@ -76,7 +75,10 @@
   import org.apache.axis.utils.CLOptionDescriptor;
   import org.apache.axis.utils.CLUtil;
   import org.apache.wsif.WSIFException;
  -import org.apache.wsif.tools.tojava.JavaBindingGenerator;
  +import org.apache.wsif.tools.wsdl.BindingGenerator;
  +import org.apache.wsif.tools.wsdl.EJBBindingGenerator;
  +import org.apache.wsif.tools.wsdl.JavaBindingGenerator;
  +import org.apache.wsif.tools.wsdl.SOAPJMSBindingGenerator;
   import org.apache.wsif.util.WSIFUtils;
   
   /**
  @@ -106,10 +108,8 @@
       // the binding types to be added to the WSDL
       protected ArrayList requestedBindings;
   
  -    protected static final String JAVA_BINDING = "java";
  -
  -    protected static final ArrayList AVAILABLE_BINDINGS =
  -        new ArrayList(Arrays.asList(new Object[] { JAVA_BINDING }));
  +    // all the available generators of new WSDL Bindings
  +    protected ArrayList availableGenerators;
   
       // Define the short one-letter option identifiers.
       protected static final int HELP_OPT = 'h';
  @@ -154,15 +154,29 @@
        */
       public WSDL2WSDL() {
           requestedBindings = new ArrayList();
  +     availableGenerators = new ArrayList();
  +        addGenerators();
  +    }
  +
  +    /**
  +     * The generators available by default
  +     */
  +    protected void addGenerators() {
  +     availableGenerators.add(new JavaBindingGenerator());
  +     availableGenerators.add(new EJBBindingGenerator());
  +     availableGenerators.add(new SOAPJMSBindingGenerator());
       }
   
       /**
        * Add all the requested bindings to the WSDL
        */
       protected void addBindings(Definition def) {
  -        if (requestedBindings.contains(JAVA_BINDING)) {
  -            JavaBindingGenerator.addJAVABinding(def);
  -        }
  +     for (Iterator i = availableGenerators.iterator(); i.hasNext(); ) {
  +             BindingGenerator bg = (BindingGenerator) i.next();
  +             if (requestedBindings.contains(bg)) {
  +                     bg.addBindings(def);
  +             }
  +     }
       }
   
       /**
  @@ -221,20 +235,32 @@
           StringTokenizer st = new StringTokenizer(bindings, ",");
           while (st.hasMoreTokens()) {
               String binding = st.nextToken();
  -            if (!AVAILABLE_BINDINGS.contains(binding.toLowerCase())) {
  +            BindingGenerator bg = getGenerator(binding);
  +            if (bg == null) {
                   System.err.println("invalid binding: " + binding);
                   ok = false;
  -            } else if (requestedBindings.contains(binding.toLowerCase())) {
  +            } else if (requestedBindings.contains(bg)) {
                   System.err.println("duplicate binding: " + binding);
                   ok = false;
               } else {
  -                requestedBindings.add(binding.toLowerCase());
  +                requestedBindings.add(bg);
               }
           }
   
           return ok;
       }
   
  +    protected BindingGenerator getGenerator(String name) {
  +     BindingGenerator bg = null;
  +     for (Iterator i = availableGenerators.iterator(); bg == null && i.hasNext(); ) 
{
  +            BindingGenerator x = (BindingGenerator) i.next();
  +            if (x.getBindingTypeName().equalsIgnoreCase(name)) {
  +             bg = x;
  +            }
  +     }
  +     return bg;
  +    }
  +
       /**
        * validateOptions
        * This method is invoked after the options are set to validate 
  @@ -399,8 +425,9 @@
           System.err.println(CLUtil.describeOptions(options).toString());
   
           System.err.print("available binding types to add are: ");
  -        for (Iterator i = AVAILABLE_BINDINGS.iterator(); i.hasNext();) {
  -            System.err.print(i.next());
  +        for (Iterator i = availableGenerators.iterator(); i.hasNext();) {
  +             BindingGenerator bg = (BindingGenerator) i.next();
  +            System.err.print(bg.getBindingTypeName());
               if (i.hasNext()) {
                   System.err.print(", ");
               }
  
  
  

Reply via email to