FileDocCategorySizeDatePackage
Java2WSDL.javaAPI DocApache Axis 1.423183Sat Apr 22 18:57:28 BST 2006org.apache.axis.wsdl

Java2WSDL

public class Java2WSDL extends Object
Command line interface to the java2wsdl utility
author
Ravi Kumar (rkumar@borland.com)
author
Rich Scheuerle (scheu@us.ibm.com)

Fields Summary
protected static final int
INHERITED_CLASS_OPT
Field INHERITED_CLASS_OPT
protected static final int
SOAPACTION_OPT
Field SOAPACTION_OPT
protected static final int
BINDING_NAME_OPT
Field BINDING_NAME_OPT
protected static final int
STOP_CLASSES_OPT
Field STOP_CLASSES_OPT
protected static final int
IMPORT_SCHEMA_OPT
Field IMPORT_SCHEMA_OPT
protected static final int
EXTRA_CLASSES_OPT
Field EXTRA_CLASSES_OPT
protected static final int
HELP_OPT
Field HELP_OPT
protected static final int
IMPL_CLASS_OPT
Field IMPL_CLASS_OPT
protected static final int
INPUT_OPT
Field INPUT_OPT
protected static final int
LOCATION_OPT
Field LOCATION_OPT
protected static final int
LOCATION_IMPORT_OPT
Field LOCATION_IMPORT_OPT
protected static final int
METHODS_ALLOWED_OPT
Field METHODS_ALLOWED_OPT
protected static final int
NAMESPACE_OPT
Field NAMESPACE_OPT
protected static final int
NAMESPACE_IMPL_OPT
Field NAMESPACE_IMPL_OPT
protected static final int
OUTPUT_OPT
Field OUTPUT_OPT
protected static final int
OUTPUT_IMPL_OPT
Field OUTPUT_IMPL_OPT
protected static final int
PACKAGE_OPT
Field PACKAGE_OPT
protected static final int
PORTTYPE_NAME_OPT
Field PORTTYPE_NAME_OPT
protected static final int
SERVICE_PORT_NAME_OPT
Field SERVICE_PORT_NAME_OPT
protected static final int
SERVICE_ELEMENT_NAME_OPT
Field SERVICE_ELEMENT_NAME_OPT
protected static final int
TYPEMAPPING_OPT
Field TYPEMAPPING_OPT
protected static final int
USE_OPT
Field USE_OPT
protected static final int
OUTPUT_WSDL_MODE_OPT
Field OUTPUT_WSDL_MODE_OPT
protected static final int
METHODS_NOTALLOWED_OPT
Field METHODS_NOTALLOWED_OPT
protected static final int
CLASSPATH_OPT
protected static final int
STYLE_OPT
Field STYLE_OPT
protected static final int
DEPLOY_OPT
Field DEPLOY_OPT
protected org.apache.axis.utils.CLOptionDescriptor[]
options
Define the understood options. Each CLOptionDescriptor contains: - The "long" version of the option. Eg, "help" means that "--help" will be recognised. - The option flags, governing the option's argument(s). - The "short" version of the option. Eg, 'h' means that "-h" will be recognised. - A description of the option for the usage message
protected org.apache.axis.wsdl.fromJava.Emitter
emitter
Field emitter
protected String
className
Field className
protected String
wsdlFilename
Field wsdlFilename
protected String
wsdlImplFilename
Field wsdlImplFilename
protected HashMap
namespaceMap
Field namespaceMap
protected int
mode
Field mode
boolean
locationSet
Field locationSet
protected String
typeMappingVersion
Field typeMappingVersion
protected boolean
isDeploy
Field isDeplpy
Constructors Summary
protected Java2WSDL()
Instantiate a Java2WSDL emitter.

    
             
      
        emitter = createEmitter();
    
Methods Summary
protected voidaddOptions(org.apache.axis.utils.CLOptionDescriptor[] newOptions)
addOptions Add option descriptions to the tool. Allows extended classes to add additional options.

param
newOptions CLOptionDescriptor[] the options


        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;
        }
    
protected org.apache.axis.wsdl.fromJava.EmittercreateEmitter()
Instantiate an Emitter

return

        return new Emitter();
    
protected voidgenerateServerSide(org.apache.axis.wsdl.fromJava.Emitter j2w, java.lang.String wsdlFileName)
Generate the server side artifacts from the generated WSDL

param
j2w the Java2WSDL emitter
param
wsdlFileName the generated WSDL file
throws
Exception

        org.apache.axis.wsdl.toJava.Emitter w2j = new org.apache.axis.wsdl.toJava.Emitter();
        File wsdlFile = new File(wsdlFileName);
        w2j.setServiceDesc(j2w.getServiceDesc());
        w2j.setQName2ClassMap(j2w.getQName2ClassMap());
        w2j.setOutputDir(wsdlFile.getParent());
        w2j.setServerSide(true);	
        w2j.setHelperWanted(true);
        
        // setup namespace-to-package mapping
        String ns = j2w.getIntfNamespace();
        String pkg = j2w.getCls().getPackage().getName();
        w2j.getNamespaceMap().put(ns, pkg);
        
        Map nsmap = j2w.getNamespaceMap();
        if (nsmap != null) {
            for (Iterator i = nsmap.keySet().iterator(); i.hasNext(); ) {
                pkg = (String) i.next();
                ns = (String) nsmap.get(pkg);
                w2j.getNamespaceMap().put(ns, pkg);
            }
        }
        
        // set 'deploy' mode
        w2j.setDeploy(true);
        
        if (j2w.getImplCls() != null) {
            w2j.setImplementationClassName(j2w.getImplCls().getName());
        } else {
            if (!j2w.getCls().isInterface()) {
                w2j.setImplementationClassName(j2w.getCls().getName());
            } else {
                throw new Exception("implementation class is not specified.");
            }
        }
        
        w2j.run(wsdlFileName);
    
public static voidmain(java.lang.String[] args)
Main Run the Java2WSDL emitter with the specified command-line arguments

param
args String[] command-line arguments


        Java2WSDL java2wsdl = new Java2WSDL();

        System.exit(java2wsdl.run(args));
    
protected booleanparseOption(org.apache.axis.utils.CLOption option)
Parse an option

param
option CLOption is the option
return


        String value;
        boolean status = true;

        switch (option.getId()) {

            case CLOption.TEXT_ARGUMENT:
                if (className != null) {
                    System.out.println(
                            Messages.getMessage(
                                    "j2wDuplicateClass00", className,
                                    option.getArgument()));
                    printUsage();

                    status = false;    // error
                }

                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();

                status = false;
                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(Messages.getMessage("j2wmodeerror",
                            modeArg));
                }
                break;

            case OUTPUT_OPT:
                wsdlFilename = option.getArgument();
                break;

            case INPUT_OPT:
                emitter.setInputWSDL(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 BINDING_NAME_OPT:
                emitter.setBindingName(option.getArgument());
                break;

            case STOP_CLASSES_OPT:
                emitter.setStopClasses(option.getArgument());
                break;

            case TYPEMAPPING_OPT:
                value = option.getArgument();
                typeMappingVersion = value;
                break;

            case SOAPACTION_OPT:
                value = option.getArgument();

                if (value.equalsIgnoreCase("DEFAULT")) {
                    emitter.setSoapAction("DEFAULT");
                } else if (value.equalsIgnoreCase("OPERATION")) {
                    emitter.setSoapAction("OPERATION");
                } else if (value.equalsIgnoreCase("NONE")) {
                    emitter.setSoapAction("NONE");
                } else {
                    System.out.println(
                            Messages.getMessage("j2wBadSoapAction00"));

                    status = false;
                }
                break;

            case STYLE_OPT:
                value = option.getArgument();

                if (value.equalsIgnoreCase("DOCUMENT")
                        || value.equalsIgnoreCase("RPC")
                        || value.equalsIgnoreCase("WRAPPED")) {
                    emitter.setStyle(value);
                } else {
                    System.out.println(Messages.getMessage("j2woptBadStyle00"));

                    status = false;
                }
                break;

            case USE_OPT:
                value = option.getArgument();

                if (value.equalsIgnoreCase("LITERAL")
                        || value.equalsIgnoreCase("ENCODED")) {
                    emitter.setUse(value);
                } else {
                    System.out.println(Messages.getMessage("j2woptBadUse00"));

                    status = false;
                }
                break;

            case EXTRA_CLASSES_OPT:
                try {
                    emitter.setExtraClasses(option.getArgument());
                } catch (ClassNotFoundException e) {
                    System.out.println(Messages.getMessage("j2woptBadClass00",
                            e.toString()));

                    status = false;
                }
                break;

            case IMPORT_SCHEMA_OPT:
                emitter.setInputSchema(option.getArgument());
                break;

            case CLASSPATH_OPT:
                ClassUtils.setDefaultClassLoader(ClassUtils.createClassLoader(
                        option.getArgument(),
                        this.getClass().getClassLoader()));
                break;
                
            case DEPLOY_OPT:
                isDeploy = true;
                break;
                
            default :
                break;
        }

        return status;
    
protected voidprintUsage()
printUsage print usage information and quit.


        String lSep = System.getProperty("line.separator");
        StringBuffer msg = new StringBuffer();

        msg.append("Java2WSDL "
                + Messages.getMessage("j2wemitter00")).append(lSep);
        msg.append(
                Messages.getMessage(
                        "j2wusage00",
                        "java " + getClass().getName()
                + " [options] class-of-portType")).append(lSep);
        msg.append(Messages.getMessage("j2woptions00")).append(lSep);
        msg.append(CLUtil.describeOptions(options).toString());
        msg.append(Messages.getMessage("j2wdetails00")).append(lSep);
        System.out.println(msg.toString());
    
protected intrun(java.lang.String[] args)
run checks the command-line arguments and runs the tool.

param
args String[] command-line arguments.
return


        // Parse the arguments
        CLArgsParser argsParser = new CLArgsParser(args, options);

        // Print parser errors, if any
        if (null != argsParser.getErrorString()) {
            System.err.println(
                    Messages.getMessage("j2werror00", argsParser.getErrorString()));
            printUsage();

            return (1);
        }

        // Get a list of parsed options
        List clOptions = argsParser.getArguments();
        int size = clOptions.size();

        try {

            // Parse the options and configure the emitter as appropriate.
            for (int i = 0; i < size; i++) {
                if (parseOption((CLOption) clOptions.get(i)) == false) {
                    return (1);
                }
            }

            // validate argument combinations
            if (validateOptions() == false) {
                return (1);
            }

            // Set the namespace map
            if (!namespaceMap.isEmpty()) {
                emitter.setNamespaceMap(namespaceMap);
            }

            TypeMappingRegistryImpl tmr = new TypeMappingRegistryImpl();
            tmr.doRegisterFromVersion(typeMappingVersion);
            emitter.setTypeMappingRegistry(tmr);

            // Find the class using the name
            emitter.setCls(className);

            // Generate a full wsdl, or interface & implementation wsdls
            if (wsdlImplFilename == null) {
                emitter.emit(wsdlFilename, mode);
            } else {
                emitter.emit(wsdlFilename, wsdlImplFilename);
            }
						            		
            if (isDeploy) {
                generateServerSide(emitter, (wsdlImplFilename != null) ? wsdlImplFilename : wsdlFilename);             
            }
            // everything is good
            return (0);
        } catch (Throwable t) {
            t.printStackTrace();

            return (1);
        }
    
protected booleanvalidateOptions()
validateOptions This method is invoked after the options are set to validate the option settings.

return


        // Can't proceed without a class name
        if ((className == null)) {
            System.out.println(Messages.getMessage("j2wMissingClass00"));
            printUsage();

            return false;
        }

        if (!locationSet
                && ((mode == Emitter.MODE_ALL)
                || (mode == Emitter.MODE_IMPLEMENTATION))) {
            System.out.println(Messages.getMessage("j2wMissingLocation00"));
            printUsage();

            return false;
        }
        return true;    // a-OK