axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/wsdl/toJava Emitter.java JavaGeneratorFactory.java
Date Tue, 16 Jul 2002 18:32:47 GMT
scheu       2002/07/16 11:32:47

  Modified:    java/src/org/apache/axis/utils axisNLS.properties
               java/src/org/apache/axis/wsdl Java2WSDL.java
               java/src/org/apache/axis/wsdl/fromJava Emitter.java
                        Types.java
               java/src/org/apache/axis/wsdl/toJava Emitter.java
                        JavaGeneratorFactory.java
  Log:
  The following new options are added to Java2WSDL
    -I, --input <wsdl>
    -b, --bindingName <name>
  
  The --input <wsdl> option is used to read an existing
  wsdl file and use it as the javax.wsdl.Definition.
  
  The code is changed in several places to query for
  an existing wsdl construct before adding a new one.
  For example a binding is created only if a
  binding with the same qname does not exist.
  
  Ignoring existing constructs is a simple rule.  (An alternative
  rule would be to replace the existing construct, but
  a replacement rule is more error prone and less desirable.)
  
  Dealing with the types was a bit more complicated due to the
  way types are processed.  The Types class builds a SymbolTable
  with the input wsdl file and examines the types in the symbol table
  to determine which types/elements do not need to be reprocessed.
  This has the beneficial side effect of checking the
  input wsdl file.
  
  The new code exposed some minor bugs, which I fixed.
  
  ---------------------
  
  The --binding <name> option is used to set the name of the
  wsdl binding element.
  
  ---------------------
  I used these new options to generate wsdl for the TCK
  tests that required multi-ports, mult-services, multi-portTypes, etc.
  
  The --input <wsdl> option will also be useful in the future to
  add such things as doc-lit bindings.  (First run the tool to generate
  a wsdl with the RPC binding, and then run again with the --input <wsdl>
  to add a doc-lit binding).
  
  --------------------------------------------
  
  I also changed some Java2WSDL signatures to be
  more specific in regards to Exceptions.
  
  --------------------------------------------
  I expect that there will be additions to this code as it matures.
  I need to add information to the user guide and add a testcase.
  
  Revision  Changes    Path
  1.27      +6 -3      xml-axis/java/src/org/apache/axis/utils/axisNLS.properties
  
  Index: axisNLS.properties
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/axisNLS.properties,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- axisNLS.properties	12 Jul 2002 22:38:55 -0000	1.26
  +++ axisNLS.properties	16 Jul 2002 18:32:46 -0000	1.27
  @@ -653,9 +653,9 @@
   j2wemitter00=emitter
   j2wusage00=Usage: {0}
   j2woptions00=Options:
  -j2wdetails00=Details:\n   portType element name= <--portTypeName value> OR <class-of-portType
name>\n   binding  element name= <--servicePortName value>SoapBinding\n   service
 element name= <--serviceElementName value> OR <--portTypeName value>Service \n
  port     element name= <--servicePortName value>\n   address location     = <--location
value>
  +j2wdetails00=Details:\n   portType element name= <--portTypeName value> OR <class-of-portType
name>\n   binding  element name= <--bindingName value> OR <--servicePortName value>SoapBinding\n
  service  element name= <--serviceElementName value> OR <--portTypeName value>Service
\n   port     element name= <--servicePortName value>\n   address location     = <--location
value>
   j2wopthelp00=print this message and exit
  -j2woptoutput00=output Wsdl filename
  +j2woptoutput00=output WSDL filename
   j2woptlocation00=service location url
   j2woptportTypeName00=portType name (obtained from class-of-portType if not specified)
   j2woptservicePortName00=service port name (obtained from --location if not specified)
  @@ -667,7 +667,7 @@
   j2woptoutputWsdlMode00=output WSDL mode: All, Interface, Implementation
   j2woptlocationImport00=location of interface wsdl
   j2woptnamespaceImpl00=target namespace for implementation wsdl
  -j2woptoutputImpl00=output Implementation Wsdl filename, setting this causes --outputWsdlMode
to be ignored
  +j2woptoutputImpl00=output Implementation WSDL filename, setting this causes --outputWsdlMode
to be ignored
   j2woptfactory00=name of the Java2WSDLFactory class for extending WSDL generation functions
   j2woptimplClass00=optional class that contains implementation of methods in class-of-portType.
 The debug information in the class is used to obtain the method parameter names, which are
used to set the WSDL part names.
   j2werror00=Error: {0}
  @@ -943,3 +943,6 @@
   badNormalizedString00=Invalid normalizedString value
   badToken00=Invalid token value
   badPropertyDesc00=Internal Error occurred while build the property descriptors for {0}
  +j2woptinput00=input WSDL filename
  +j2woptbindingName00=binding name (--servicePortName value + "SOAPBinding" if not specified)
  +writeSchemaProblem00=Problems encountered trying to write schema for {0}
  
  
  
  1.21      +18 -0     xml-axis/java/src/org/apache/axis/wsdl/Java2WSDL.java
  
  Index: Java2WSDL.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Java2WSDL.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- Java2WSDL.java	8 Jul 2002 15:56:36 -0000	1.20
  +++ Java2WSDL.java	16 Jul 2002 18:32:46 -0000	1.21
  @@ -79,6 +79,7 @@
       // Define our short one-letter option identifiers.
       protected static final int HELP_OPT = 'h';
       protected static final int OUTPUT_WSDL_MODE_OPT = 'w';
  +    protected static final int INPUT_OPT = 'I';
       protected static final int OUTPUT_OPT = 'o';
       protected static final int OUTPUT_IMPL_OPT = 'O';
       protected static final int PACKAGE_OPT = 'p';
  @@ -87,6 +88,7 @@
       protected static final int PORTTYPE_NAME_OPT = 'P';
       protected static final int SERVICE_ELEMENT_NAME_OPT = 'S';
       protected static final int SERVICE_PORT_NAME_OPT = 's';
  +    protected static final int BINDING_NAME_OPT = 'b';
       protected static final int LOCATION_OPT = 'l';
       protected static final int LOCATION_IMPORT_OPT = 'L';
       protected static final int METHODS_ALLOWED_OPT = 'm';
  @@ -112,6 +114,10 @@
                   CLOptionDescriptor.ARGUMENT_DISALLOWED,
                   HELP_OPT,
                   JavaUtils.getMessage("j2wopthelp00")),
  +        new CLOptionDescriptor("input",
  +                CLOptionDescriptor.ARGUMENT_REQUIRED,
  +                INPUT_OPT,
  +                JavaUtils.getMessage("j2woptinput00")),
           new CLOptionDescriptor("output",
                   CLOptionDescriptor.ARGUMENT_REQUIRED,
                   OUTPUT_OPT,
  @@ -124,6 +130,10 @@
                   CLOptionDescriptor.ARGUMENT_REQUIRED,
                   PORTTYPE_NAME_OPT,
                   JavaUtils.getMessage("j2woptportTypeName00")),
  +        new CLOptionDescriptor("bindingName",
  +                CLOptionDescriptor.ARGUMENT_REQUIRED,
  +                BINDING_NAME_OPT,
  +                JavaUtils.getMessage("j2woptbindingName00")),
           new CLOptionDescriptor("serviceElementName",
                   CLOptionDescriptor.ARGUMENT_REQUIRED,
                   SERVICE_ELEMENT_NAME_OPT,
  @@ -282,6 +292,10 @@
               wsdlFilename = option.getArgument();
               break;
               
  +        case INPUT_OPT:
  +            emitter.setInputWSDL(option.getArgument());
  +            break;
  +            
           case OUTPUT_IMPL_OPT:
               wsdlImplFilename = option.getArgument();
               break;
  @@ -323,6 +337,10 @@
               
           case PORTTYPE_NAME_OPT:
               emitter.setPortTypeName(option.getArgument());
  +            break;
  +            
  +        case BINDING_NAME_OPT:
  +            emitter.setBindingName(option.getArgument());
               break;
               
           case STOP_CLASSES_OPT:
  
  
  
  1.49      +204 -79   xml-axis/java/src/org/apache/axis/wsdl/fromJava/Emitter.java
  
  Index: Emitter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Emitter.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- Emitter.java	2 Jul 2002 22:54:32 -0000	1.48
  +++ Emitter.java	16 Jul 2002 18:32:46 -0000	1.49
  @@ -65,6 +65,7 @@
   import com.ibm.wsdl.extensions.soap.SOAPBodyImpl;
   import com.ibm.wsdl.extensions.soap.SOAPOperationImpl;
   
  +import org.apache.axis.AxisFault;
   import org.apache.axis.Constants;
   import org.apache.axis.wsdl.toJava.Utils;
   import org.apache.axis.description.OperationDesc;
  @@ -76,6 +77,9 @@
   import org.apache.axis.utils.XMLUtils;
   import org.apache.axis.utils.JavaUtils;
   import org.w3c.dom.Document;
  +import org.w3c.dom.Element; 
  +import org.w3c.dom.Node;
  +import org.w3c.dom.NodeList;
   
   
   import javax.wsdl.Binding;
  @@ -93,11 +97,13 @@
   import javax.wsdl.PortType;
   import javax.wsdl.Service;
   import javax.wsdl.Fault;
  +import javax.wsdl.WSDLException;
   import javax.wsdl.factory.WSDLFactory;
   import javax.xml.namespace.QName;
   
   import java.io.File;
   import java.io.FileOutputStream;
  +import java.io.IOException;
   import java.io.StringWriter;
   import java.util.*;
   
  @@ -126,6 +132,7 @@
       private boolean useInheritedMethods = false;
       private String intfNS;
       private String implNS;
  +    private String inputWSDL;
       private String locationUrl;
       private String importUrl;
       private String servicePortName;
  @@ -142,6 +149,7 @@
       private Types types;
       private String clsName;
       private String portTypeName;
  +    private String bindingName;
   
       private ServiceDesc serviceDesc;
       private ServiceDesc serviceDesc2;
  @@ -162,9 +170,9 @@
        *
        * @param filename1  interface WSDL
        * @param filename2  implementation WSDL
  -     * @throws Exception
  +     * @throws IOException, WSDLException
        */
  -    public void emit(String filename1, String filename2) throws Exception {
  +    public void emit(String filename1, String filename2) throws IOException, WSDLException
{
           // Get interface and implementation defs
           Definition intf = getIntfWSDL();
           Definition impl = getImplWSDL();
  @@ -192,9 +200,9 @@
        * Generates a complete WSDL document for a given <code>Class</code>
        *
        * @param filename  WSDL
  -     * @throws Exception
  +     * @throws IOException, WSDLException
        */
  -    public void emit(String filename) throws Exception {
  +    public void emit(String filename) throws IOException, WSDLException {
           emit(filename, MODE_ALL);
       }
   
  @@ -207,9 +215,9 @@
        *
        * @param mode generation mode - all, interface, implementation
        * @return Document
  -     * @throws Exception
  +     * @throws IOException, WSDLException
        */
  -    public Document emit(int mode) throws Exception {
  +    public Document emit(int mode) throws IOException, WSDLException {
           Document doc = null;
           Definition def = null;
           switch (mode) {
  @@ -230,8 +238,6 @@
                   doc = WSDLFactory.newInstance().
                       newWSDLWriter().getDocument(def);
                   break;
  -            default:
  -                throw new Exception ("unrecognized output WSDL mode");
           }
   
           // Return the document
  @@ -247,9 +253,9 @@
        *
        * @param mode generation mode - all, interface, implementation
        * @return String
  -     * @throws Exception
  +     * @throws IOException, WSDLException
        */
  -    public String emitToString(int mode) throws Exception {
  +    public String emitToString(int mode) throws IOException, WSDLException {
           Document doc = emit(mode);
           StringWriter sw = new StringWriter();
           XMLUtils.PrettyDocumentToWriter(doc, sw);
  @@ -265,9 +271,9 @@
        *
        * @param filename  WSDL
        * @param mode generation mode - all, interface, implementation
  -     * @throws Exception
  +     * @throws IOException, WSDLException
        */
  -    public void emit(String filename, int mode) throws Exception {
  +    public void emit(String filename, int mode) throws IOException, WSDLException {
           Document doc = emit(mode);
   
           // Supply a reasonable file name if not supplied
  @@ -294,19 +300,22 @@
        * configuration parameters
        *
        * @return WSDL <code>Definition</code>
  -     * @throws Exception
  +     * @throws IOException, WSDLException
        */
  -    public Definition getWSDL() throws Exception {
  +    public Definition getWSDL() throws IOException, WSDLException {
           // Invoke the init() method to ensure configuration is setup
  -        init();
  +        init(MODE_ALL);
   
  -        // Create a definition
  -        Definition def = WSDLFactory.newInstance().newDefinition();
  +        // Create a Definition for the output wsdl
  +        Definition def = createDefinition();
   
           // Write interface header
           writeDefinitions(def, intfNS);
  -        types = new Types(def, tm, defaultTM, namespaces,
  -                          intfNS, stopClasses);
  +
  +        // Create Types
  +        types = createTypes(def);
  +
  +        // Write the WSDL constructs and return full Definition
           Binding binding = writeBinding(def, true);
           writePortType(def, binding);
           writeService(def, binding);
  @@ -318,19 +327,22 @@
        * current configuration parameters
        *
        * @return WSDL <code>Definition</code>
  -     * @throws Exception
  +     * @throws IOException, WSDLException
        */
  -    public Definition getIntfWSDL() throws Exception {
  +    public Definition getIntfWSDL() throws IOException, WSDLException {
           // Invoke the init() method to ensure configuration is setup
  -        init();
  +        init(MODE_INTERFACE);
   
  -        // Create a definition
  -        Definition def = WSDLFactory.newInstance().newDefinition();
  +        // Create a definition for the output wsdl
  +        Definition def = createDefinition();
   
           // Write interface header
           writeDefinitions(def, intfNS);
  -        types = new Types(def, tm, defaultTM, namespaces,
  -                          intfNS, stopClasses);
  +
  +        // Create Types
  +        types = createTypes(def);
  +
  +        // Write the interface WSDL constructs and return the Definition
           Binding binding = writeBinding(def, true);
           writePortType(def, binding);
           return def;
  @@ -341,28 +353,30 @@
        * current configuration parameters
        *
        * @return WSDL <code>Definition</code>
  -     * @throws Exception
  +     * @throws IOException, WSDLException
        */
  -    public Definition getImplWSDL() throws Exception {
  +    public Definition getImplWSDL() throws IOException, WSDLException {
           // Invoke the init() method to ensure configuration is setup
  -        init();
  +        init(MODE_IMPLEMENTATION);
   
  -        // Create a definition
  -        Definition def = WSDLFactory.newInstance().newDefinition();
  +        // Create a Definition for the output wsdl
  +        Definition def = createDefinition();
   
  -        // Write interface header
  +        // Write implementation header and import
           writeDefinitions(def, implNS);
           writeImport(def, intfNS, importUrl);
  +
  +        // Write the implementation WSDL constructs and return Definition
           Binding binding = writeBinding(def, false); // Don't add binding to def
           writeService(def, binding);
           return def;
       }
  +
       /**
        * Invoked prior to building a definition to ensure parms
        * and data are set up.
  -     * @throws Exception
        */
  -    private void init() throws Exception {
  +    private void init(int mode) {
   
           // Set up a ServiceDesc to use to introspect the Service
           if (serviceDesc == null) {
  @@ -432,6 +446,11 @@
                   setServicePortName(name);
               }
   
  +            // Default the bindingName
  +            if (getBindingName() == null) {
  +                setBindingName(getServicePortName() + "SoapBinding");
  +            }
  +            
               encodingList = new ArrayList();
               encodingList.add(Constants.URI_DEFAULT_SOAP_ENC);
   
  @@ -449,23 +468,70 @@
                   intfNS = namespaces.getCreate(
                           pkg == null ? null : pkg.getName());
               }
  -            if (implNS == null)
  -                implNS = intfNS + "-impl";
  -
  +            // Default the implementation namespace to the interface
  +            // namespace if not split wsdl mode.
  +            if (implNS == null) {
  +                if (mode == MODE_ALL) {
  +                    implNS = intfNS;
  +                } else {
  +                    implNS = intfNS + "-impl";
  +                }
  +            }
  +                
               namespaces.put(cls.getName(), intfNS, "intf");
               namespaces.putPrefix(implNS, "impl");
           }
       }
   
  +
  +    /**
  +     * Build a Definition from the input wsdl file or create
  +     * a new Definition
  +     *
  +     * @return WSDL Definition
  +     */
  +    private Definition createDefinition()
  +        throws WSDLException {
  +        Definition def;
  +        if (inputWSDL == null) {
  +            def = WSDLFactory.newInstance().newDefinition();
  +        } else {
  +            javax.wsdl.xml.WSDLReader reader =
  +                WSDLFactory.newInstance().newWSDLReader();
  +            Document doc = XMLUtils.newDocument(inputWSDL);
  +            def = reader.readWSDL(null, doc);
  +            // The input wsdl types section is deleted.  The
  +            // types will be added back in at the end of processing.
  +            def.setTypes(null); 
  +        }
  +        return def;
  +    }
  +
  +    /**
  +     * Build a Types object and load the input wsdl types
  +     * @param Corresponding wsdl Definition
  +     * @return Types object
  +     */
  +    private Types createTypes(Definition def)
  +        throws IOException, WSDLException {
  +        types = new Types(def, tm, defaultTM, namespaces,
  +                          intfNS, stopClasses);
  +        if (inputWSDL != null) {
  +            types.loadInputTypes(inputWSDL);
  +        }
  +        return types;
  +    }
  +
  +
       /**
        * Create the definition header information.
        *
        * @param def  <code>Definition</code>
        * @param tns  target namespace
  -     * @throws Exception
  +     * @throws WSDLException
        */
       private void writeDefinitions(Definition def, String tns)
  -        throws Exception {
  +        throws WSDLException {
           def.setTargetNamespace(tns);
   
           def.addNamespace("intf", intfNS);
  @@ -503,10 +569,10 @@
        * @param def  <code>Definition</code>
        * @param tns  target namespace
        * @param loc  target location
  -     * @throws Exception
  +     * @throws WSDLException
        */
       private void writeImport(Definition def, String tns, String loc)
  -        throws Exception {
  +        throws WSDLException {
           Import imp = def.createImport();
   
           imp.setNamespaceURI(tns);
  @@ -520,14 +586,23 @@
        *
        * @param def  <code>Definition</code>
        * @param add  true if binding should be added to the def
  -     * @throws Exception
  +     * @throws WSDLException
        */
       private Binding writeBinding(Definition def, boolean add)
  -        throws Exception {
  -        Binding binding = def.createBinding();
  +        throws WSDLException {
  +        QName bindingQName = 
  +            new QName(intfNS, getBindingName());
  +
  +        // If a binding already exists, don't replace it.
  +        Binding binding = def.getBinding(bindingQName);
  +        if (binding != null) {
  +            return binding;
  +        } 
  +
  +        // Create a binding
  +        binding = def.createBinding();
           binding.setUndefined(false);
  -        binding.setQName(
  -          new QName(intfNS, getServicePortName() + "SoapBinding"));
  +        binding.setQName(bindingQName);
   
           SOAPBinding soapBinding = new SOAPBindingImpl();
           String modeStr = (mode == MODE_RPC) ? "rpc" : "document";
  @@ -550,17 +625,21 @@
        */
       private void writeService(Definition def, Binding binding) {
   
  -        Service service = def.createService();
  -
  -        service.setQName(new QName(implNS,
  -                                              getServiceElementName()));
  -
  -        def.addService(service);
  +        QName serviceElementQName = 
  +            new QName(implNS,
  +                      getServiceElementName());
  +        
  +        // Locate an existing service, or get a new service
  +        Service service = def.getService(serviceElementQName);
  +        if (service == null) {
  +            service = def.createService();
  +            service.setQName(serviceElementQName);
  +            def.addService(service);
  +        }
   
  +        // Add the port
           Port port = def.createPort();
  -
           port.setBinding(binding);
  -
           // Probably should use the end of the location Url
           port.setName(getServicePortName());
   
  @@ -576,19 +655,28 @@
        *
        * @param def
        * @param binding
  -     * @throws Exception
  +     * @throws WSDLException, AxisFault
        */
       private void writePortType(Definition def, Binding binding)
  -        throws Exception{
  +        throws WSDLException, AxisFault {
   
  -        PortType portType = def.createPortType();
  -        portType.setUndefined(false);
  +        QName portTypeQName = new QName(intfNS, getPortTypeName());
   
  -        // PortType name is the name of the class being processed
  -        // Split statement to isolate NPE
  -        QName tempqn = new QName(intfNS, getPortTypeName());
  -        portType.setQName(tempqn);
  +        // Get or create a portType
  +        PortType portType = def.getPortType(portTypeQName);
  +        boolean newPortType = false;
  +        if (portType == null) {
  +            portType = def.createPortType();
  +            portType.setUndefined(false);
  +            portType.setQName(portTypeQName);
  +            newPortType = true;
  +        } else if (binding.getBindingOperations().size() > 0) {
  +            // If both portType and binding already exist, 
  +            // no additional processing is needed.
  +            return;
  +        }
   
  +        // Add the port and binding operations.
           ArrayList operations = serviceDesc.getOperations();
           for (Iterator i = operations.iterator(); i.hasNext();) {
               OperationDesc thisOper = (OperationDesc)i.next();
  @@ -637,10 +725,14 @@
   
               writeMessages(def, oper, messageOper, 
                             bindingOper);
  -            portType.addOperation(oper);
  +            if (newPortType) {
  +                portType.addOperation(oper);
  +            }
           }
   
  -        def.addPortType(portType);
  +        if (newPortType) {
  +            def.addPortType(portType);
  +        }
   
           binding.setPortType(portType);
       }
  @@ -651,13 +743,13 @@
        * @param oper Operation, the wsdl operation
        * @param desc OperationDesc, the Operation Description
        * @param bindingOper BindingOperation, corresponding Binding Operation
  -     * @throws Exception
  +     * @throws WSDLException, AxisFault
        */
       private void writeMessages(Definition def,
                                  Operation oper,
                                  OperationDesc desc,
                                  BindingOperation bindingOper)
  -            throws Exception{
  +            throws WSDLException, AxisFault {
           Input input = def.createInput();
   
           Message msg = writeRequestMessage(def, desc);
  @@ -671,7 +763,6 @@
           bindingOper.getBindingInput().setName(name);
   
           oper.setInput(input);
  -
           def.addMessage(msg);
   
           msg = writeResponseMessage(def, desc);
  @@ -686,7 +777,6 @@
           bindingOper.getBindingOutput().setName(name);
   
           oper.setOutput(output);
  -
           def.addMessage(msg);
   
           ArrayList exceptions = desc.getFaults();
  @@ -824,10 +914,11 @@
       /** Create a Request Message
        *
        * @param def
  -     * @throws Exception
  +     * @throws WSDLException, AxisFault
        */
       private Message writeRequestMessage(Definition def,
  -                                        OperationDesc oper) throws Exception
  +                                        OperationDesc oper)
  +        throws WSDLException, AxisFault
       {
           Message msg = def.createMessage();
   
  @@ -848,10 +939,11 @@
       /** Create a Response Message
        *
        * @param def
  -     * @throws Exception
  +     * @throws WSDLException, AxisFault
        */
       private Message writeResponseMessage(Definition def,
  -                                         OperationDesc desc) throws Exception
  +                                         OperationDesc desc)
  +        throws WSDLException, AxisFault
       {
           Message msg = def.createMessage();
   
  @@ -885,10 +977,11 @@
        *
        * @param def
        * @param exception (an ExceptionRep object)
  -     * @throws Exception
  +     * @throws WSDLException, AxisFault
        */
       private Message writeFaultMessage(Definition def,
  -                                      FaultDesc exception) throws Exception
  +                                      FaultDesc exception) 
  +        throws WSDLException, AxisFault
       {
   
           String pkgAndClsName = exception.getName();
  @@ -935,12 +1028,12 @@
        * @param request     message is for a request
        * @param param       ParamRep object
        * @return The parameter name added or null
  -     * @throws Exception
  +     * @throws WSDLException, AxisFault
        */
       public String writePartToMessage(Definition def,
                                        Message msg,
                                        boolean request,
  -                                     ParameterDesc param) throws Exception
  +                                     ParameterDesc param) throws WSDLException, AxisFault
       {
           // Return if this is a void type
           if (param == null ||
  @@ -977,7 +1070,7 @@
           if (mode != MODE_RPC)
               elemQName = param.getQName();
           QName typeQName = types.writePartType(javaType,
  -                elemQName);
  +                elemQName); 
           if (mode == MODE_RPC) {
               if (typeQName != null) {
                   part.setTypeName(typeQName);
  @@ -1027,10 +1120,10 @@
        *
        * @param doc the Document to write
        * @param filename the name of the file to be written
  -     * @throws Exception various file i/o exceptions
  +     * @throws IOException various file i/o exceptions
        */
       private void prettyDocumentToFile(Document doc, String filename)
  -        throws Exception {
  +        throws IOException {
           FileOutputStream fos = new FileOutputStream(new File(filename));
           XMLUtils.PrettyDocumentToStream(doc, fos);
           fos.close();
  @@ -1307,6 +1400,22 @@
       }
   
       /**
  +     * Get the name of the input WSDL                              
  +     * @return name of the input wsdl or null
  +     */
  +    public String getInputWSDL() {
  +        return inputWSDL;
  +    }
  +
  +    /**
  +     * Set the name of the input WSDL
  +     * @param inputWSDL the name of the input WSDL
  +     */
  +    public void setInputWSDL(String inputWSDL) {
  +        this.inputWSDL = inputWSDL;
  +    }
  +
  +    /**
        * Returns the String representation of the service endpoint URL
        * @return String representation of the service endpoint URL
        */
  @@ -1386,6 +1495,22 @@
        */
       public void setPortTypeName(String portTypeName) {
           this.portTypeName = portTypeName;
  +    }
  +
  +    /**
  +     * Returns the String representation of the binding name
  +     * @return String representation of the binding name
  +     */
  +    public String getBindingName() {
  +        return bindingName;
  +    }
  +
  +    /**
  +     * Set the String representation of the binding name
  +     * @param bindingName the String representation of the binding name
  +     */
  +    public void setBindingName(String bindingName) {
  +        this.bindingName = bindingName;
       }
   
       /**
  
  
  
  1.45      +115 -26   xml-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java
  
  Index: Types.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- Types.java	10 Jul 2002 16:03:48 -0000	1.44
  +++ Types.java	16 Jul 2002 18:32:46 -0000	1.45
  @@ -59,6 +59,7 @@
   import org.apache.axis.AxisFault;
   import org.apache.axis.AxisProperties;
   import org.apache.axis.Constants;
  +import org.apache.axis.encoding.DefaultTypeMappingImpl;
   import org.apache.axis.encoding.Serializer;
   import org.apache.axis.encoding.SerializerFactory;
   import org.apache.axis.encoding.SimpleType;
  @@ -66,6 +67,10 @@
   import org.apache.axis.encoding.ser.BeanSerializerFactory;
   import org.apache.axis.utils.JavaUtils;
   import org.apache.axis.utils.XMLUtils;
  +import org.apache.axis.wsdl.symbolTable.BaseTypeMapping;
  +import org.apache.axis.wsdl.symbolTable.SymbolTable;
  +import org.apache.axis.wsdl.symbolTable.Type;
  +import org.apache.axis.wsdl.symbolTable.TypeEntry;
   
   import org.apache.axis.components.logger.LogFactory;
   import org.apache.commons.logging.Log;
  @@ -75,15 +80,19 @@
   import org.w3c.dom.Element;
   import org.w3c.dom.NamedNodeMap;
   import org.w3c.dom.NodeList;
  +import org.w3c.dom.Node;
   
   import javax.wsdl.Definition;
  +import javax.wsdl.WSDLException;
   import javax.xml.namespace.QName;
   import javax.xml.rpc.holders.Holder;
  +import java.io.IOException;
   import java.lang.reflect.Field;
   import java.lang.reflect.Modifier;
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.List;
  +import java.util.Vector;
   
   /**
    *
  @@ -138,6 +147,81 @@
       }
   
       /**
  +     * Load the types from the input wsdl file.
  +     * @param inputWSDL file or URL
  +     */
  +    public void loadInputTypes(String inputWSDL)
  +        throws IOException, WSDLException
  +    {
  +
  +        // Read the input wsdl file into a Document
  +        Document doc = XMLUtils.newDocument(inputWSDL);
  +
  +        // Search for the 'types' element
  +        NodeList elements = doc.getChildNodes();
  +        if (elements.getLength() > 0 && 
  +            elements.item(0).getLocalName().equals("definitions")) {
  +            elements = elements.item(0).getChildNodes();
  +            for (int i=0;
  +                 i < elements.getLength() && wsdlTypesElem == null; 
  +                 i++) {
  +                Node node = elements.item(i);
  +                if (node.getLocalName() != null &&
  +                    node.getLocalName().equals("types")) {
  +                    Document emptyDoc = XMLUtils.newDocument(inputWSDL);
  +                    wsdlTypesElem = (Element) node;
  +                    
  +                }
  +            }
  +        }
  +
  +        // If types element not found, there is no need to continue.
  +        if (wsdlTypesElem == null) {
  +            return;
  +        }
  +
  +        // Import the types element into the Types docHolder document
  +        wsdlTypesElem = 
  +            (Element) docHolder.importNode(wsdlTypesElem, true);
  +        docHolder.appendChild(wsdlTypesElem);
  +
  +        // Create a symbol table and populate it with the input wsdl document
  +        BaseTypeMapping btm = 
  +            new BaseTypeMapping() {
  +                TypeMapping defaultTM = DefaultTypeMappingImpl.getSingleton();
  +                    public String getBaseName(QName qNameIn) {
  +                        QName qName = new QName(
  +                              qNameIn.getNamespaceURI(),                              
  
  +                              qNameIn.getLocalPart());
  +                        Class cls = defaultTM.getClassForQName(qName);
  +                        if (cls == null)
  +                            return null;
  +                        else 
  +                            return JavaUtils.getTextClassName(cls.getName());
  +                    }
  +                }; 
  +        SymbolTable symbolTable = new SymbolTable(btm,
  +                                                  true, false, false, false);
  +        symbolTable.populate(null, doc);
  +
  +        // Walk the type/element entries in the symbol table and 
  +        // add each one to the list of processed types.  This prevents
  +        // the types from being duplicated.
  +        Vector v = symbolTable.getTypes();
  +        for (int i=0; i < v.size(); i++) {
  +            TypeEntry te = (TypeEntry) v.elementAt(i);
  +            if (te instanceof org.apache.axis.wsdl.symbolTable.Element) { 
  +                addToTypesList(te.getQName(), 
  +                               te.getQName().getLocalPart());
  +            } else if (te instanceof Type) {
  +                addToElementsList(te.getQName());
  +            }
  +        }
  +
  +    
  +    }
  +
  +    /**
        * Serialize the Class as XML schema to the document.
        * Create a types node for the WSDL if one doesn't exist
        * Create a schema node for the Class namespace, if one doesn't exist
  @@ -148,7 +232,7 @@
        * @param type <code>Class</code> to generate the XML Schema info for
        * @return the QName of the generated Schema type, null if void
        */
  -    public QName writePartType(Class type, javax.xml.namespace.QName qname) throws Exception
{
  +    public QName writePartType(Class type, QName qname) throws AxisFault {
           //patch by costin to fix an NPE; commented out till we find out what the problem
is
           //if you get NullPointerExceptions in this class, turn it on and submit some
           //replicable test data to the Axis team via bugzilla
  @@ -164,7 +248,7 @@
               type = JavaUtils.getHolderValueType(type);
           }
           if (isSimpleType(type)) {
  -            javax.xml.namespace.QName typeQName = getTypeQName(type);
  +            QName typeQName = getTypeQName(type);
               // Still need to write any element declaration...
               if (qname != null) {
                   String elementType = writeType(type);
  @@ -187,7 +271,7 @@
        * @param type the class type
        * @return the QName of the generated Element
        */
  -    private QName writeTypeAsElement(Class type, QName qName) throws Exception {
  +    private QName writeTypeAsElement(Class type, QName qName) throws AxisFault {
           QName typeQName = writeTypeNamespace(type);
           if (qName == null) {
               qName = typeQName;
  @@ -210,7 +294,7 @@
        * @return QName for the schema type representing the class
        */
       private QName writeTypeNamespace(Class type) {
  -        javax.xml.namespace.QName qName = getTypeQName(type);
  +        QName qName = getTypeQName(type);
           String pref = def.getPrefix(qName.getNamespaceURI());
           if (pref == null)
             def.addNamespace(namespaces.getCreatePrefix(qName.getNamespaceURI()), qName.getNamespaceURI());
  @@ -222,11 +306,11 @@
        * @param javaType input javaType Class
        * @return QName
        */
  -    private javax.xml.namespace.QName getTypeQName(Class javaType) {
  -        javax.xml.namespace.QName qName = null;
  +    private QName getTypeQName(Class javaType) {
  +        QName qName = null;
   
           // Use the typeMapping information to lookup the qName.
  -        javax.xml.namespace.QName dQName = null;
  +        QName dQName = null;
           if (defaultTM != null) {
               dQName = defaultTM.getTypeQName(javaType);
           }
  @@ -255,14 +339,14 @@
               // Construct ArrayOf<componentLocalPart>
               // Else
               // Construct ArrayOf_<componentPrefix>_<componentLocalPart>
  -            javax.xml.namespace.QName cqName = getTypeQName(componentType);
  +            QName cqName = getTypeQName(componentType);
               if (targetNamespace.equals(cqName.getNamespaceURI())) {
  -                qName = new javax.xml.namespace.QName(
  +                qName = new QName(
                           targetNamespace,
                           "ArrayOf" + cqName.getLocalPart());
               } else {
                   String pre = namespaces.getCreatePrefix(cqName.getNamespaceURI());
  -                qName = new javax.xml.namespace.QName(
  +                qName = new QName(
                           targetNamespace,
                           "ArrayOf_" + pre + "_" + cqName.getLocalPart());
               }
  @@ -278,7 +362,7 @@
               String ns = namespaces.getCreate(pkg);
               namespaces.getCreatePrefix(ns);
               String localPart = lcl.replace('$', '_');
  -            qName = new javax.xml.namespace.QName(ns, localPart);
  +            qName = new QName(ns, localPart);
           }
   
           return qName;
  @@ -328,11 +412,13 @@
           NodeList nl = wsdlTypesElem.getChildNodes();
           for (int i = 0; i < nl.getLength(); i++ ) {
               NamedNodeMap attrs = nl.item(i).getAttributes();
  -            for (int n = 0; n < attrs.getLength(); n++) {
  -                Attr a = (Attr)attrs.item(n);
  -                if (a.getName().equals("targetNamespace") &&
  -                    a.getValue().equals(qName.getNamespaceURI()))
  -                    schemaElem = (Element)nl.item(i);
  +            if (attrs != null) {
  +                for (int n = 0; n < attrs.getLength(); n++) {
  +                    Attr a = (Attr)attrs.item(n);
  +                    if (a.getName().equals("targetNamespace") &&
  +                        a.getValue().equals(qName.getNamespaceURI()))
  +                        schemaElem = (Element)nl.item(i);
  +                }
               }
           }
           if (schemaElem == null) {
  @@ -351,9 +437,8 @@
   
       /**
        * Get the Types element for the WSDL document. If not present, create one
  -     * @throws Exception
        */
  -    private void writeWsdlTypesElement() throws Exception {
  +    private void writeWsdlTypesElement() {
           if (wsdlTypesElem == null) {
               // Create a <wsdl:types> element corresponding to the wsdl namespaces.
               wsdlTypesElem =
  @@ -371,9 +456,8 @@
        *
        * @param type Class for which to generate schema
        * @return a prefixed string for the schema type
  -     * @throws Exception
        */
  -    public String writeType(Class type) throws Exception {
  +    public String writeType(Class type) throws AxisFault {
   
           // Quick return if schema type
           if (isSimpleType(type)) {
  @@ -464,10 +548,14 @@
               attribute.setAttribute(Constants.NS_PREFIX_WSDL +":arrayType",
                                      componentTypeName );
           } else {
  -            if (isEnumClass(type)) {
  -                writeEnumType(qName, type);
  -            } else {
  -                ser.writeSchema(this);
  +            try {
  +                if (isEnumClass(type)) {
  +                    writeEnumType(qName, type);
  +                } else {
  +                    ser.writeSchema(this);
  +                }
  +            } catch (Exception e) {
  +                throw new AxisFault(JavaUtils.getMessage("writeSchemaProblem00", type.getName()),
e);
               }
           }
           return prefixedName;
  @@ -516,7 +604,8 @@
        * @param qName QName of type.
        * @param cls class of type
        */
  -    private void writeEnumType(QName qName, Class cls)  throws Exception  {
  +    private void writeEnumType(QName qName, Class cls) 
  +        throws NoSuchMethodException, IllegalAccessException, AxisFault  {
           if (!isEnumClass(cls))
               return;
           // Get the base type of the enum class
  @@ -639,7 +728,7 @@
                 type == java.lang.Short.TYPE ||
                 type == java.math.BigInteger.class ||
                 type == java.math.BigDecimal.class ||
  -              type == javax.xml.namespace.QName.class ||
  +              type == QName.class ||
                 type == java.util.Calendar.class ||
                 type == org.apache.axis.encoding.Token.class ||
                 type == org.apache.axis.encoding.NormalizedString.class ||
  
  
  
  1.47      +12 -4     xml-axis/java/src/org/apache/axis/wsdl/toJava/Emitter.java
  
  Index: Emitter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/Emitter.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- Emitter.java	8 Jul 2002 15:56:36 -0000	1.46
  +++ Emitter.java	16 Jul 2002 18:32:46 -0000	1.47
  @@ -387,8 +387,12 @@
       } // run
   
       /**
  -     * Call this method if your WSDL document has already been parsed as an XML DOM document.
  -     * @param context context This is directory context for the Document.  If the Document
were from file "/x/y/z.wsdl" then the context could be "/x/y" (even "/x/y/z.wsdl" would work).
 If context is null, then the context becomes the current directory.
  +     * Call this method if your WSDL document has already been
  +     * parsed as an XML DOM document.
  +     * @param context context This is directory context for the Document.
  +     * If the Document were from file "/x/y/z.wsdl" then the context
  +     * could be "/x/y" (even "/x/y/z.wsdl" would work).  
  +     * If context is null, then the context becomes the current directory.
        * @param doc doc This is the XML Document containing the WSDL.
        */
       public void run(String context, Document doc) throws IOException, WSDLException {
  @@ -503,8 +507,12 @@
       } // emit
   
       /**
  -     * Call this method if your WSDL document has already been parsed as an XML DOM document.
  -     * @param context context This is directory context for the Document.  If the Document
were from file "/x/y/z.wsdl" then the context could be "/x/y" (even "/x/y/z.wsdl" would work).
 If context is null, then the context becomes the current directory.
  +     * Call this method if your WSDL document has already been
  +     * parsed as an XML DOM document.
  +     * @param context context This is directory context for the Document.
  +     * If the Document were from file "/x/y/z.wsdl" then the context could be "/x/y"
  +     * (even "/x/y/z.wsdl" would work).  If context is null, then the context
  +     * becomes the current directory.
        * @param doc doc This is the XML Document containing the WSDL.
        * @deprecated Call run(context, doc) instead.
        */
  
  
  
  1.13      +2 -2      xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaGeneratorFactory.java
  
  Index: JavaGeneratorFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaGeneratorFactory.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- JavaGeneratorFactory.java	28 Jun 2002 23:27:25 -0000	1.12
  +++ JavaGeneratorFactory.java	16 Jul 2002 18:32:46 -0000	1.13
  @@ -74,7 +74,7 @@
   import javax.wsdl.Service;
   
   import org.apache.axis.encoding.TypeMapping;
  -import org.apache.axis.encoding.DefaultSOAP12TypeMappingImpl;
  +import org.apache.axis.encoding.DefaultTypeMappingImpl;
   
   import org.apache.axis.utils.JavaUtils;
   
  @@ -955,7 +955,7 @@
       public BaseTypeMapping getBaseTypeMapping() {
           if (btm == null) {
               btm = new BaseTypeMapping() {
  -                    TypeMapping defaultTM = DefaultSOAP12TypeMappingImpl.create();
  +                    TypeMapping defaultTM = DefaultTypeMappingImpl.getSingleton();
                       public String getBaseName(QName qNameIn) {
                           javax.xml.namespace.QName qName = 
                               new javax.xml.namespace.QName(
  
  
  

Mime
View raw message