scheu       02/05/15 13:22:01

  Modified:    java/src/org/apache/axis/wsdl Java2WSDL.java WSDL2Java.java
               java/src/org/apache/axis/wsdl/gen WSDL2.java
  Log:
  Changed the Java2WSDL class to have similar structure and flow as
  WSDL2Java.
  
  Added method comments to Java2WSDL, WSDL2Java and WSDL2.
  
  Revision  Changes    Path
  1.15      +204 -143  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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Java2WSDL.java    28 Apr 2002 18:10:56 -0000      1.14
  +++ Java2WSDL.java    15 May 2002 20:22:01 -0000      1.15
  @@ -105,7 +105,7 @@
        * recognised.
        * - A description of the option for the usage message
        */
  -    protected static final CLOptionDescriptor[] options = new CLOptionDescriptor[]{
  +    protected CLOptionDescriptor[] options = new CLOptionDescriptor[]{
           new CLOptionDescriptor("help",
                   CLOptionDescriptor.ARGUMENT_DISALLOWED,
                   HELP_OPT,
  @@ -180,166 +180,213 @@
                   JavaUtils.getMessage("j2wopttypeMapping00"))
       };
   
  +    protected Emitter emitter;
  +    protected String className = null;
  +    protected String wsdlFilename = null;
  +    protected String wsdlImplFilename = null;
  +    protected HashMap namespaceMap = new HashMap();
  +    protected int mode = Emitter.MODE_ALL;
  +    boolean locationSet = false;
       
       /**
  -     * Main
  +     * Instantiate a Java2WSDL emitter.
        */
  -    public static void main(String args[]) {
  +    protected Java2WSDL() {
  +        emitter = createEmitter();
  +        addOptions(options);
  +    } // ctor
  +
  +
  +    /**
  +     * Instantiate an Emitter          
  +     */
  +    protected Emitter createEmitter() {
  +        return new Emitter();
  +    } // createEmitter
   
  -        String className = null;
  -        String wsdlFilename = null;
  -        String wsdlImplFilename = null;
  -        HashMap namespaceMap = new HashMap();
  -        int mode = Emitter.MODE_ALL;
  -        boolean locationSet = false;
  +    /**
  +     * addOptions
  +     * Add option descriptions to the tool.  Allows
  +     * extended classes to add additional options.
  +     * @param CLOptionDescriptor[] the options
  +     */
  +    protected void addOptions(CLOptionDescriptor[] newOptions) {
  +        if (newOptions != null && newOptions.length > 0) {
  +            CLOptionDescriptor[] allOptions = new CLOptionDescriptor[
  +                   options.length + newOptions.length];
  +            System.arraycopy(options, 0, allOptions, 0, options.length);
  +            System.arraycopy(newOptions, 0, allOptions, options.length, 
newOptions.length);
  +            options = allOptions;
  +        }
  +    }
  +
  +    /**
  +     * Parse an option
  +     * @param CLOption is the option 
  +     */
  +    protected void parseOption(CLOption option) {
  +        switch (option.getId()) {
  +        case CLOption.TEXT_ARGUMENT:
  +            if (className != null) {
  +                printUsage();
  +            }
  +            className = option.getArgument();
  +            break;
  +            
  +        case METHODS_ALLOWED_OPT:
  +            emitter.setAllowedMethods(option.getArgument());
  +            break;
  +            
  +        case INHERITED_CLASS_OPT:
  +            emitter.setUseInheritedMethods(true);
  +            break;
  +            
  +        case IMPL_CLASS_OPT:
  +            emitter.setImplCls(option.getArgument());
  +            break;
  +            
  +        case HELP_OPT:
  +            printUsage();
  +            break;
  +            
  +        case OUTPUT_WSDL_MODE_OPT:
  +            String modeArg = option.getArgument();
  +            if ("All".equalsIgnoreCase(modeArg))
  +                mode = Emitter.MODE_ALL;
  +            else if ("Interface".equalsIgnoreCase(modeArg))
  +                mode = Emitter.MODE_INTERFACE;
  +            else if ("Implementation".equalsIgnoreCase(modeArg))
  +                mode = Emitter.MODE_IMPLEMENTATION;
  +            else {
  +                mode = Emitter.MODE_ALL; 
  +                System.err.println(JavaUtils.getMessage("j2wmodeerror", modeArg));
  +            }
  +            break;
  +            
  +        case OUTPUT_OPT:
  +            wsdlFilename = option.getArgument();
  +            break;
  +            
  +        case OUTPUT_IMPL_OPT:
  +            wsdlImplFilename = option.getArgument();
  +            break;
  +            
  +        case PACKAGE_OPT:
  +            String packageName = option.getArgument(0);
  +            String namespace = option.getArgument(1);
  +            namespaceMap.put(packageName, namespace);
  +            break;
  +            
  +        case NAMESPACE_OPT:
  +            emitter.setIntfNamespace(option.getArgument());
  +            break;
  +            
  +        case NAMESPACE_IMPL_OPT:
  +            emitter.setImplNamespace(option.getArgument());
  +            break;
  +            
  +        case SERVICE_ELEMENT_NAME_OPT:
  +            emitter.setServiceElementName(option.getArgument());
  +            break;
  +            
  +        case SERVICE_PORT_NAME_OPT:
  +            emitter.setServicePortName(option.getArgument());
  +            break;
  +            
  +        case LOCATION_OPT:
  +            emitter.setLocationUrl(option.getArgument());
  +            locationSet = true;
  +            break;
  +            
  +        case LOCATION_IMPORT_OPT:
  +            emitter.setImportUrl(option.getArgument());
  +            break;
  +            
  +        case METHODS_NOTALLOWED_OPT:
  +            emitter.setDisallowedMethods(option.getArgument());
  +            break;
  +            
  +        case PORTTYPE_NAME_OPT:
  +            emitter.setPortTypeName(option.getArgument());
  +            break;
  +            
  +        case STOP_CLASSES_OPT:
  +            emitter.setStopClasses(option.getArgument());
  +            break;
  +            
  +        case TYPEMAPPING_OPT:
  +            String value = option.getArgument();
  +            if (value.equals("1.1")) {
  +                emitter.setDefaultTypeMapping(
  +                                              
DefaultTypeMappingImpl.getSingleton());
  +            } else if (value.equals("1.2")) {
  +                emitter.setDefaultTypeMapping(
  +                                              
DefaultSOAP12TypeMappingImpl.create());
  +            } else {
  +                System.out.println(JavaUtils.getMessage("j2wBadTypeMapping00"));
  +            }
  +            break;
  +            
  +        }
  +    }        
   
  +    /**
  +     * validateOptions
  +     * This method is invoked after the options are set to validate 
  +     * the option settings.
  +     */
  +    protected void validateOptions() {
  +        // Can't proceed without a class name
  +        if ((className == null)) {
  +            printUsage();
  +        }
  +        
  +        if (!locationSet && (mode == Emitter.MODE_ALL ||
  +                             mode == Emitter.MODE_IMPLEMENTATION)) {
  +            System.out.println(JavaUtils.getMessage("j2wMissingLocation00"));
  +            printUsage();
  +        }
  +        
  +        // Default to SOAP 1.2 JAX-RPC mapping
  +        if (emitter.getDefaultTypeMapping() == null) {
  +            emitter.setDefaultTypeMapping(DefaultSOAP12TypeMappingImpl.create());
  +        }            
  +    }
  +
  +    /**
  +     * run 
  +     * checks the command-line arguments and runs the tool.
  +     * @param String[] command-line arguments.
  +     */
  +    protected void run(String[] args) {
           // Parse the arguments
  -        CLArgsParser parser = new CLArgsParser(args, options);
  +        CLArgsParser argsParser = new CLArgsParser(args, options);
   
           // Print parser errors, if any
  -        if (null != parser.getErrorString()) {
  -            
System.err.println(JavaUtils.getMessage("j2werror00",parser.getErrorString()));
  +        if (null != argsParser.getErrorString()) {
  +            System.err.println(
  +                    JavaUtils.getMessage("j2werror00", 
argsParser.getErrorString()));
               printUsage();
           }
   
           // Get a list of parsed options
  -        List clOptions = parser.getArguments();
  +        List clOptions = argsParser.getArguments();
           int size = clOptions.size();
   
           try {
  -
  -            // Instantiate the emitter
  -            Emitter emitter = new Emitter();
  -
               // Parse the options and configure the emitter as appropriate.
               for (int i = 0; i < size; i++) {
  -                CLOption option = (CLOption)clOptions.get(i);
  -
  -                switch (option.getId()) {
  -                    case CLOption.TEXT_ARGUMENT:
  -                        if (className != null) {
  -                            printUsage();
  -                        }
  -                        className = option.getArgument();
  -                        break;
  -
  -                    case METHODS_ALLOWED_OPT:
  -                        emitter.setAllowedMethods(option.getArgument());
  -                        break;
  -
  -                    case INHERITED_CLASS_OPT:
  -                        emitter.setUseInheritedMethods(true);
  -                        break;
  -
  -                    case IMPL_CLASS_OPT:
  -                        emitter.setImplCls(option.getArgument());
  -                        break;
  -
  -                    case HELP_OPT:
  -                        printUsage();
  -                        break;
  -
  -                    case OUTPUT_WSDL_MODE_OPT:
  -                        String modeArg = option.getArgument();
  -                        if ("All".equalsIgnoreCase(modeArg))
  -                            mode = Emitter.MODE_ALL;
  -                        else if ("Interface".equalsIgnoreCase(modeArg))
  -                            mode = Emitter.MODE_INTERFACE;
  -                        else if ("Implementation".equalsIgnoreCase(modeArg))
  -                            mode = Emitter.MODE_IMPLEMENTATION;
  -                        else {
  -                            mode = Emitter.MODE_ALL; 
  -                            System.err.println(JavaUtils.getMessage("j2wmodeerror", 
modeArg));
  -                        }
  -                        break;
  -
  -                    case OUTPUT_OPT:
  -                        wsdlFilename = option.getArgument();
  -                        break;
  -
  -                    case OUTPUT_IMPL_OPT:
  -                        wsdlImplFilename = option.getArgument();
  -                        break;
  -
  -                    case PACKAGE_OPT:
  -                        String packageName = option.getArgument(0);
  -                        String namespace = option.getArgument(1);
  -                        namespaceMap.put(packageName, namespace);
  -                        break;
  -
  -                    case NAMESPACE_OPT:
  -                        emitter.setIntfNamespace(option.getArgument());
  -                        break;
  -
  -                    case NAMESPACE_IMPL_OPT:
  -                        emitter.setImplNamespace(option.getArgument());
  -                        break;
  -
  -                    case SERVICE_ELEMENT_NAME_OPT:
  -                        emitter.setServiceElementName(option.getArgument());
  -                        break;
  -
  -                    case SERVICE_PORT_NAME_OPT:
  -                        emitter.setServicePortName(option.getArgument());
  -                        break;
  -
  -                    case LOCATION_OPT:
  -                        emitter.setLocationUrl(option.getArgument());
  -                        locationSet = true;
  -                        break;
  -
  -                    case LOCATION_IMPORT_OPT:
  -                        emitter.setImportUrl(option.getArgument());
  -                        break;
  -                        
  -                    case METHODS_NOTALLOWED_OPT:
  -                        emitter.setDisallowedMethods(option.getArgument());
  -                        break;
  -                        
  -                    case PORTTYPE_NAME_OPT:
  -                        emitter.setPortTypeName(option.getArgument());
  -                        break;
  -                        
  -                    case STOP_CLASSES_OPT:
  -                        emitter.setStopClasses(option.getArgument());
  -                        break;
  -
  -                    case TYPEMAPPING_OPT:
  -                        String value = option.getArgument();
  -                        if (value.equals("1.1")) {
  -                            emitter.setDefaultTypeMapping(
  -                                DefaultTypeMappingImpl.getSingleton());
  -                        } else if (value.equals("1.2")) {
  -                            emitter.setDefaultTypeMapping(
  -                                DefaultSOAP12TypeMappingImpl.create());
  -                        } else {
  -                            
System.out.println(JavaUtils.getMessage("j2wBadTypeMapping00"));
  -                        }
  -                        break;
  -                        
  -                }
  +                parseOption((CLOption)clOptions.get(i));
               }
   
  -            // Can't proceed without a class name
  -            if ((className == null)) {
  -                printUsage();
  -            }
  +            // validate argument combinations
  +            validateOptions();
   
  -            if (!locationSet && (mode == Emitter.MODE_ALL ||
  -                                 mode == Emitter.MODE_IMPLEMENTATION)) {
  -                System.out.println(JavaUtils.getMessage("j2wMissingLocation00"));
  -                printUsage();
  -            }
  -
  -            // Default to SOAP 1.2 JAX-RPC mapping
  -            if (emitter.getDefaultTypeMapping() == null) {
  -                
emitter.setDefaultTypeMapping(DefaultSOAP12TypeMappingImpl.create());
  -            }            
  -                
  +            // Set the namespace map
               if (!namespaceMap.isEmpty()) {
                   emitter.setNamespaceMap(namespaceMap);
               }
  -
  +            
               // Find the class using the name
               emitter.setCls(className);
   
  @@ -349,17 +396,21 @@
               } else {
                   emitter.emit(wsdlFilename, wsdlImplFilename);
               }
  +
  +            // everything is good
  +            System.exit(0);
           }
           catch (Throwable t) {
               t.printStackTrace();
  +            System.exit(1);
           }
  -
  -    }
  +    } // run
   
       /**
  -     * Print usage message and exit
  +     * printUsage
  +     * print usage information and quit.
        */
  -    private static void printUsage() {
  +    protected void printUsage() {
           String lSep = System.getProperty("line.separator");
           StringBuffer msg = new StringBuffer();
           msg.append("Java2WSDL " 
  @@ -367,9 +418,19 @@
           msg.append(JavaUtils.getMessage("j2wusage00", 
                      "java " + Java2WSDL.class.getName() + " [options] 
class-of-portType")).append(lSep);
           msg.append(JavaUtils.getMessage("j2woptions00")).append(lSep);
  -        msg.append(CLUtil.describeOptions(Java2WSDL.options).toString());
  +        msg.append(CLUtil.describeOptions(options).toString());
           msg.append(JavaUtils.getMessage("j2wdetails00")).append(lSep);
           System.out.println(msg.toString());
           System.exit(0);
  +    }
  +
  +   /**
  +     * Main
  +     * Run the Java2WSDL emitter with the specified command-line arguments
  +     * @param String[] command-line arguments
  +     */
  +    public static void main(String args[]) {
  +        Java2WSDL java2wsdl = new Java2WSDL();
  +        java2wsdl.run(args);
       }
   }
  
  
  
  1.32      +14 -0     xml-axis/java/src/org/apache/axis/wsdl/WSDL2Java.java
  
  Index: WSDL2Java.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/WSDL2Java.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- WSDL2Java.java    10 May 2002 20:06:22 -0000      1.31
  +++ WSDL2Java.java    15 May 2002 20:22:01 -0000      1.32
  @@ -167,10 +167,17 @@
           addOptions(options);
       } // ctor
   
  +    /**
  +     * Instantiate an extension of the Parser
  +     */
       protected Parser createParser() {
           return new Emitter();
       } // createParser
   
  +    /**
  +     * Parse an option
  +     * @param CLOption is the option
  +     */
       protected void parseOption(CLOption option) {
           switch (option.getId()) {
               case FACTORY_CLASS_OPT:
  @@ -260,6 +267,11 @@
           }
       } // parseOption
   
  +    /**
  +     * validateOptions
  +     * This method is invoked after the options are set to validate 
  +     * the option settings.
  +     */
       protected void validateOptions() {
           super.validateOptions();
   
  @@ -276,6 +288,8 @@
   
       /**
        * Main
  +     * Run the WSDL2Java emitter with the specified command-line arguments
  +     * @param String[] command-line arguments
        */
       public static void main(String args[]) {
           WSDL2Java wsdl2java = new WSDL2Java();
  
  
  
  1.5       +45 -0     xml-axis/java/src/org/apache/axis/wsdl/gen/WSDL2.java
  
  Index: WSDL2.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/gen/WSDL2.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- WSDL2.java        10 May 2002 14:45:04 -0000      1.4
  +++ WSDL2.java        15 May 2002 20:22:01 -0000      1.5
  @@ -101,18 +101,35 @@
       protected String wsdlURI = null;
       protected Parser parser;
   
  +    /**
  +     * Constructor
  +     * Used by extended classes to construct an instance of WSDL2
  +     */
       protected WSDL2 () {
           parser = createParser();
       } // ctor
   
  +    /**
  +     * createParser
  +     * Used by extended classes to construct an instance of the Parser
  +     */
       protected Parser createParser() {
           return new Parser();
       } // createParser
   
  +    /**
  +     * getParser
  +     * get the Parser object
  +     */
       protected Parser getParser() {
           return parser;
       } // getParser
   
  +    /**
  +     * addOptions
  +     * Add option descriptions to the tool.
  +     * @param CLOptionDescriptor[] the options
  +     */
       protected void addOptions(CLOptionDescriptor[] newOptions) {
           if (newOptions != null && newOptions.length > 0) {
               CLOptionDescriptor[] allOptions = new CLOptionDescriptor[
  @@ -123,6 +140,10 @@
           }
       } // addOptions
   
  +    /**
  +     * Parse an option
  +     * @param CLOption is the option 
  +     */
       protected void parseOption(CLOption option) {
           switch (option.getId()) {
               case CLOption.TEXT_ARGUMENT:
  @@ -159,6 +180,11 @@
           }
       } // parseOption
   
  +    /**
  +     * validateOptions
  +     * This method is invoked after the options are set to validate and default the 
options
  +     * the option settings.
  +     **/
       protected void validateOptions() {
           if (wsdlURI == null) {
               printUsage();
  @@ -170,6 +196,11 @@
                   parser.getUsername(), parser.getPassword()));
       } // validateOptions
   
  +
  +    /**
  +     * checkForAuthInfo
  +     * set user and password information
  +     */
       private void checkForAuthInfo(String uri) {
           URL url = null;
           try {
  @@ -190,6 +221,10 @@
           } 
       }
   
  +    /**
  +     * printUsage
  +     * print usage information and quit.
  +     */
       protected void printUsage() {
           String lSep = System.getProperty("line.separator");
           StringBuffer msg = new StringBuffer();
  @@ -202,6 +237,11 @@
           System.exit(1);
       } // printUsage
   
  +    /**
  +     * run 
  +     * checkes the command-line arguments and runs the tool.
  +     * @param String[] command-line arguments.
  +     */
       protected void run(String[] args) {
           // Parse the arguments
           CLArgsParser argsParser = new CLArgsParser(args, options);
  @@ -238,6 +278,11 @@
           }
       } // run
   
  +    /**
  +     * Main
  +     * Run the tool with the specified command-line arguments
  +     * @param String[] command-line arguments
  +     */
       public static void main(String[] args) {
           WSDL2 wsdl2 = new WSDL2();
           wsdl2.run(args);
  
  
  


Reply via email to