FileDocCategorySizeDatePackage
Emitter.javaAPI DocApache Axis 1.430676Sat Apr 22 18:57:26 BST 2006org.apache.axis.wsdl.toJava

Emitter

public class Emitter extends org.apache.axis.wsdl.gen.Parser
This class produces java files for stubs, skeletons, and types from a WSDL document.
author
Russell Butek (butek@us.ibm.com)
author
Tom Jordahl (tjordahl@macromedia.com)
author
Rich Scheuerle (scheu@us.ibm.com)
author
Steve Graham (sggraham@us.ibm.com)

Fields Summary
public static final String
DEFAULT_NSTOPKG_FILE
Field DEFAULT_NSTOPKG_FILE
protected HashMap
namespaceMap
Field namespaceMap
protected String
typeMappingVersion
Field typeMappingVersion
protected org.apache.axis.wsdl.symbolTable.BaseTypeMapping
baseTypeMapping
Field baseTypeMapping
protected Namespaces
namespaces
Field namespaces
protected String
NStoPkgFilename
Field NStoPkgFilename
private boolean
bEmitServer
Field bEmitServer
private boolean
bDeploySkeleton
Field bDeploySkeleton
private boolean
bEmitTestCase
Field bEmitTestCase
private boolean
bGenerateAll
Field bGenerateAll
private boolean
bHelperGeneration
Field bHelperGeneration
private boolean
bBuildFileGeneration
private boolean
typeCollisionProtection
private boolean
allowInvalidURL
Check if URL endpoints are valid or not
private String
packageName
Field packageName
private org.apache.axis.constants.Scope
scope
Field scope
private GeneratedFileInfo
fileInfo
Field fileInfo
private HashMap
delayedNamespacesMap
Field delayedNamespacesMap
private String
outputDir
Field outputDir
protected List
nsIncludes
Field nsIncludes - defines a list of namespaces to specifically include in the generated source code. If non-empty, anything not in this list should be excluded. If empty, everything in this and not specifically excluded should be generated.
protected List
nsExcludes
Field nsIncludes - defines a list of namespaces to specifically exclude from generated source code. Any entry in this list that is in conflict with the includes list should be ignored and generated.
protected List
properties
Field properties - defines a set of general purpose properties that can be used by custom JavaGeneratorFactories.
private String
implementationClassName
Field implementationClassName - defines a non default classname for the actual implementation class. Particularly useful when exporting a webservice directly from the java implementation.
private org.apache.axis.encoding.TypeMapping
defaultTM
Field defaultTM
private org.apache.axis.encoding.TypeMappingRegistryImpl
tmr
private HashMap
qName2ClassMap
The mapping of qname to its corresponding java type generated by Java2Wsdl emitter. For deploy mode roundtripping use.
private org.apache.axis.description.ServiceDesc
serviceDesc
The ServiceDesc. For deploy mode roundtripping use.
private boolean
isDeploy
The deploy mode flag
Constructors Summary
public Emitter()
Default constructor.


           
      
        setFactory(new JavaGeneratorFactory(this));
    
Methods Summary
public voiddebug(boolean value)
Turn on/off debug messages.

param
value
deprecated
Use setDebug(value)

        setDebug(value);
    
public voiddeploySkeleton(boolean value)
Turn on/off server skeleton deploy

param
value
deprecated
Use setSkeletonWanted(value)

        setSkeletonWanted(value);
    
protected booleandoesExist(java.lang.String className)
Check if the className exists.

param
className className to check
return
true if exists, false if not

        
        try {
            ClassUtils.forName(className);
        } catch (ClassNotFoundException e) {
            return false;
        }		
        
        return true;
    
public voidemit(java.lang.String uri)
Call this method if you have a uri for the WSDL document

param
uri wsdlURI the location of the WSDL file.
throws
Exception
deprecated
Call run(uri) instead.

        run(uri);
    
public voidemit(java.lang.String context, org.w3c.dom.Document doc)
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.
throws
IOException
throws
SAXException
throws
WSDLException
throws
ParserConfigurationException
deprecated
Call run(context, doc) instead.

        run(context, doc);
    
public voidgenerateAll(boolean all)

param
all
deprecated
Use setAllWanted(all)

        setAllWanted(all);
    
public voidgenerateImports(boolean generateImports)
Turn on/off generation of elements from imported files.

param
generateImports
deprecated
Use setImports(generateImports)

        setImports(generateImports);
    
public voidgenerateServerSide(boolean value)
Turn on/off server-side binding generation

param
value
deprecated
Use setServerSide(value)

        setServerSide(value);
    
public voidgenerateTestCase(boolean value)
Turn on/off test case creation

param
value
deprecated
Use setTestCaseWanted()

        setTestCaseWanted(value);
    
public booleangetDebug()
Return the status of the debug switch.

return
deprecated
Use isDebug()

        return isDebug();
    
public org.apache.axis.encoding.TypeMappinggetDefaultTypeMapping()
Returns the default TypeMapping used by the service

return
the default TypeMapping used by the service

        if (defaultTM == null) {
            defaultTM =
                    (TypeMapping)tmr.getTypeMapping(Constants.URI_SOAP11_ENC);
        }
        return defaultTM;
    
public booleangetDeploySkeleton()
Indicate if we should be deploying skeleton or implementation

return
deprecated
Use isSkeletonWanted()

        return isSkeletonWanted();
    
public booleangetGenerateServerSide()
Indicate if we should be emitting server side code and deploy/undeploy

return
deprecated
Use isServerSide()

        return isServerSide();
    
public java.util.ListgetGeneratedClassNames()
This method returns a list of all generated class names.

return

        return fileInfo.getClassNames();
    
public GeneratedFileInfogetGeneratedFileInfo()
Returns an object which contains of information on all generated files including the class name, filename and a type string.

return
An org.apache.axis.wsdl.toJava.GeneratedFileInfo object
see
org.apache.axis.wsdl.toJava.GeneratedFileInfo

        return fileInfo;
    
public java.util.ListgetGeneratedFileNames()
This method returns a list of all generated file names.

return

        return fileInfo.getFileNames();
    
public booleangetHelperGeneration()
Indicate if we should be generating Helper classes

return
deprecated
Use isHelperWanted()

        return isHelperWanted();
    
public java.lang.StringgetImplementationClassName()
Get an implementation classname to use instead of the default.

return

		return implementationClassName;
	
public java.lang.StringgetJavaName(javax.xml.namespace.QName qName)
Convert the specified QName into a full Java Name.

param
qName
return


        // If this is one of our special 'collection' qnames.
        // get the element type and append []
        if (qName.getLocalPart().indexOf("[") > 0) {
            String localPart = qName.getLocalPart().substring(0,
                    qName.getLocalPart().indexOf("["));
            QName eQName = new QName(qName.getNamespaceURI(), localPart);

            return getJavaName(eQName) + "[]";
        }

        // Handle the special "java" namespace for types
        if (qName.getNamespaceURI().equalsIgnoreCase("java")) {
            return qName.getLocalPart();
        }

        // The QName may represent a base java name, so check this first
        String fullJavaName =
                getFactory().getBaseTypeMapping().getBaseName(qName);

        if (fullJavaName != null) {
            return fullJavaName;
        }

        fullJavaName = getJavaNameHook(qName);
        if (fullJavaName != null) {
            return fullJavaName;
        }
        // Use the namespace uri to get the appropriate package
        String pkg = getPackage(qName.getNamespaceURI());

        if (pkg != null && pkg.length() > 0) {
            fullJavaName = pkg + "."
                    + Utils.xmlNameToJavaClass(qName.getLocalPart());
        } else {
            fullJavaName = Utils.xmlNameToJavaClass(qName.getLocalPart());
        }

        return fullJavaName;
    
protected java.lang.StringgetJavaNameHook(javax.xml.namespace.QName qname)

 return null; 
public java.lang.StringgetJavaVariableName(javax.xml.namespace.QName typeQName, javax.xml.namespace.QName xmlName, boolean isElement)

param
typeQName QName for containing xml type
param
xmlName QName for element
return

        String javaName = getJavaVariableNameHook(typeQName, xmlName, isElement);
        if (javaName == null) {
            String elemName = Utils.getLastLocalPart(xmlName.getLocalPart());            
            javaName = Utils.xmlNameToJava(elemName);
        }
        return javaName;
    
protected java.lang.StringgetJavaVariableNameHook(javax.xml.namespace.QName typeQName, javax.xml.namespace.QName xmlName, boolean isElement)

        return null;
    
private voidgetNStoPkgFromPropsFile(java.util.HashMap namespaces)
Tries to load the namespace-to-package mapping file.
  1. if a file name is explicitly set using setNStoPkg(), tries to load the mapping from this file. If this fails, the built-in default mapping is used.

  2. if no file name is set, tries to load the file DEFAULT_NSTOPKG_FILE as a java resource. If this fails, the built-in dfault mapping is used.

param
namespaces a hashmap which is filled with the namespace-to-package mapping in this method
throws
IOException
see
#setNStoPkg(String)
see
#DEFAULT_NSTOPKG_FILE
see
org.apache.axis.utils.ClassUtils#getResourceAsStream(java.lang.Class,String)


        Properties mappings = new Properties();

        if (NStoPkgFilename != null) {
            try {
                mappings.load(new FileInputStream(NStoPkgFilename));

                if (verbose) {
                    System.out.println(
                            Messages.getMessage(
                                    "nsToPkgFileLoaded00", NStoPkgFilename));
                }
            } catch (Throwable t) {

                // loading the custom mapping file failed. We do not try
                // to load the mapping from a default mapping file.
                throw new IOException(
                        Messages.getMessage(
                                "nsToPkgFileNotFound00", NStoPkgFilename));
            }
        } else {
            try {
                mappings.load(new FileInputStream(DEFAULT_NSTOPKG_FILE));

                if (verbose) {
                    System.out.println(
                            Messages.getMessage(
                                    "nsToPkgFileLoaded00", DEFAULT_NSTOPKG_FILE));
                }
            } catch (Throwable t) {
                try {
                    mappings.load(ClassUtils.getResourceAsStream(Emitter.class,
                            DEFAULT_NSTOPKG_FILE));

                    if (verbose) {
                        System.out.println(
                                Messages.getMessage(
                                        "nsToPkgDefaultFileLoaded00",
                                        DEFAULT_NSTOPKG_FILE));
                    }
                } catch (Throwable t1) {

                    // loading the default mapping file failed.
                    // The built-in default mapping is used
                    // No message is given, since this is generally what happens
                }
            }
        }

        Enumeration keys = mappings.propertyNames();

        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();

            namespaces.put(key, mappings.getProperty(key));
        }
    
public java.util.ListgetNamespaceExcludes()
Returns the list of excludes to specifically exclude from the generated source.

        return this.nsExcludes;
    
public java.util.ListgetNamespaceIncludes()
Returns the list of namespaces specifically excluded from the generated code.

        return this.nsIncludes;
    
public java.util.HashMapgetNamespaceMap()
Get the map of namespace -> Java package names

return

        return delayedNamespacesMap;
    
public NamespacesgetNamespaces()
Method getNamespaces

return

        return namespaces;
    
public java.lang.StringgetOutputDir()
Get the output directory to use for emitted source files

return

        return outputDir;
    
public java.lang.StringgetPackage(java.lang.String namespace)
Get the Package name for the specified namespace

param
namespace
return

        return namespaces.getCreate(namespace);
    
public java.lang.StringgetPackage(javax.xml.namespace.QName qName)
Get the Package name for the specified QName

param
qName
return

        return getPackage(qName.getNamespaceURI());
    
public java.lang.StringgetPackageName()
Get global package name to use instead of mapping namespaces

return

        return packageName;
    
public java.util.ListgetProperties()
Gets the list of extension properties for custom JavaGeneratorFactories.

        return this.properties;
    
public java.util.HashMapgetQName2ClassMap()
Get the type qname to java class map

return
the type qname to java class map

        return qName2ClassMap;
    
public org.apache.axis.constants.ScopegetScope()
Get the scope for the deploy.xml file.

return

        return scope;
    
public org.apache.axis.description.ServiceDescgetServiceDesc()
Retruns the SericeDesc object

return

        return serviceDesc;
    
public java.lang.StringgetTypeMappingVersion()
Get the typemapping version

        return typeMappingVersion;    
    
public booleangetVerbose()
Return the status of the verbose switch

return
deprecated
Use isVerbose()

        return isVerbose();
    
public org.apache.axis.wsdl.gen.GeneratorFactorygetWriterFactory()
Get the GeneratorFactory.

return
deprecated
Call getFactory instead. This doesn't return a WriterFactory, it returns a GeneratorFactory.

        return getFactory();
    
public booleanisAllWanted()
Method isAllWanted

return

        return bGenerateAll;
    
public booleanisAllowInvalidURL()

return
Returns the allowInvalidURL.

        return allowInvalidURL;
    
public booleanisBuildFileWanted()
get the build file genaeration state

return

        return bBuildFileGeneration;
    
public booleanisDeploy()
Returns the deploy mode flag

return

        return isDeploy;
    
public booleanisHelperWanted()
Indicate if we should be generating Helper classes

return

        return bHelperGeneration;
    
public booleanisServerSide()
Indicate if we should be emitting server side code and deploy/undeploy

return

        return bEmitServer;
    
public booleanisSkeletonWanted()
Indicate if we should be deploying skeleton or implementation

return

        return bDeploySkeleton;
    
public booleanisTestCaseWanted()
Method isTestCaseWanted

return

        return bEmitTestCase;
    
public booleanisTypeCollisionProtection()
Get the type collision protection setting

return

        return this.typeCollisionProtection;
    
public voidrun(java.lang.String wsdlURL)
Emit appropriate Java files for a WSDL at a given URL.

This method will time out after the number of milliseconds specified by our timeoutms member.

param
wsdlURL
throws
Exception

        setup();
        super.run(wsdlURL);
    
public voidrun(java.lang.String context, org.w3c.dom.Document doc)
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.
throws
IOException
throws
SAXException
throws
WSDLException
throws
ParserConfigurationException

        setup();
        super.run(context, doc);
    
protected voidsanityCheck(org.apache.axis.wsdl.symbolTable.SymbolTable symbolTable)
Method sanityCheck

param
symbolTable


        Iterator it = symbolTable.getHashMap().values().iterator();

        while (it.hasNext()) {
            Vector v = (Vector) it.next();

            for (int i = 0; i < v.size(); ++i) {
                SymTabEntry entry = (SymTabEntry) v.elementAt(i);
                String namespace = entry.getQName().getNamespaceURI();
                String packageName =
                        org.apache.axis.wsdl.toJava.Utils.makePackageName(
                                namespace);
                String localName = entry.getQName().getLocalPart();

                if (localName.equals(packageName)
                        && packageName.equals(
                                namespaces.getCreate(namespace))) {
                    packageName += "_pkg";

                    namespaces.put(namespace, packageName);
                }
            }
        }
    
public voidsetAllWanted(boolean all)
By default, code is generated only for referenced elements. Call bGenerateAll(true) and WSDL2Java will generate code for all elements in the scope regardless of whether they are referenced. Scope means: by default, all WSDL files; if generateImports(false), then only the immediate WSDL file.

param
all

        bGenerateAll = all;
    
public voidsetAllowInvalidURL(boolean allowInvalidURL)

param
allowInvalidURL The allowInvalidURL to set.

        this.allowInvalidURL = allowInvalidURL;
    
public voidsetBuildFileWanted(boolean value)
turn the build file genaration ON

param
value

        bBuildFileGeneration = value;
    
public voidsetDefaultTypeMapping(org.apache.axis.encoding.TypeMapping defaultTM)
Sets the default TypeMapping used by the service

param
defaultTM the default TypeMapping used by the service

        this.defaultTM = defaultTM;
    
public voidsetDeploy(boolean isDeploy)
Sets the deploy mode flag

param
isDeploy deploy mode flag

        this.isDeploy = isDeploy;
    
public voidsetFactory(java.lang.String factory)
Sets the WriterFactory Class to use

param
factory the name of the factory Class


        try {
            Class clazz = ClassUtils.forName(factory);
            GeneratorFactory genFac;
            try {
                Constructor ctor = clazz.getConstructor(new Class[]{
                    getClass()});

                genFac = (GeneratorFactory) ctor.newInstance(new Object[]{
                    this});
            } catch (NoSuchMethodException ex) {
                genFac = (GeneratorFactory) clazz.newInstance();
            }

            setFactory(genFac);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    
public voidsetHelperGeneration(boolean value)
Turn on/off Helper class generation

param
value
deprecated
Use setHelperWanted(value)

        setHelperWanted(value);
    
public voidsetHelperWanted(boolean value)
Turn on/off Helper class generation

param
value

        bHelperGeneration = value;
    
public voidsetImplementationClassName(java.lang.String implementationClassName)
Set an implementation classname to use instead of the default.

param
implementationClassName

		this.implementationClassName = implementationClassName;
	
public voidsetNStoPkg(java.lang.String NStoPkgFilename)
Set the NStoPkg mappings filename.

param
NStoPkgFilename


        if (NStoPkgFilename != null) {
            this.NStoPkgFilename = NStoPkgFilename;
        }
    
public voidsetNamespaceExcludes(java.util.List nsExcludes)
Sets the list of namespaces to specifically exclude from the generated source.

        this.nsExcludes = nsExcludes;
    
public voidsetNamespaceIncludes(java.util.List nsIncludes)
Sets the list of namespaces to specifically include in the generated code.

        this.nsIncludes = nsIncludes;
    
public voidsetNamespaceMap(java.util.HashMap map)
Set a map of namespace -> Java package names

param
map

        delayedNamespacesMap = map;
    
public voidsetOutputDir(java.lang.String outputDir)
Set the output directory to use in emitted source files

param
outputDir

        this.outputDir = outputDir;
    
public voidsetPackageName(java.lang.String packageName)
Set a global package name to use instead of mapping namespaces

param
packageName

        this.packageName = packageName;
    
public voidsetProperties(java.util.List properties)
Sets the list of extension properties for custom JavaGeneratorFactories.

        this.properties = properties;
    
public voidsetQName2ClassMap(java.util.HashMap map)
Set the type qname to java class map

param
map a type qname to javaclass map (from Java2Wsdl emitter)

        qName2ClassMap = map;
    
public voidsetScope(org.apache.axis.constants.Scope scope)
Set the scope for the deploy.xml file.

param
scope One of 'null', Scope.APPLICATION, Scope.REQUEST, Scope.SESSION. Anything else is equivalent to 'null' null and no explicit scope tag will appear in deploy.xml.

        this.scope = scope;
    
public voidsetServerSide(boolean value)
Turn on/off server skeleton creation

param
value

        this.bEmitServer = value;
    
public voidsetServiceDesc(org.apache.axis.description.ServiceDesc serviceDesc)
Sets the ServicdDesc object

param
serviceDesc ServiceDesc to set

        this.serviceDesc = serviceDesc;
    
public voidsetSkeletonWanted(boolean value)
Turn on/off server skeleton deploy

param
value

        bDeploySkeleton = value;
    
public voidsetTestCaseWanted(boolean value)
Turn on/off test case creation

param
value

        this.bEmitTestCase = value;
    
public voidsetTypeCollisionProtection(boolean value)
Enable/disable type collision protection

param
value

        this.typeCollisionProtection = value;
    
public voidsetTypeMappingVersion(java.lang.String typeMappingVersion)
Method setTypeMappingVersion

param
typeMappingVersion

        this.typeMappingVersion = typeMappingVersion;
        tmr.doRegisterFromVersion(typeMappingVersion);
        baseTypeMapping = new BaseTypeMapping() {

            final TypeMapping defaultTM = getDefaultTypeMapping();

            public String getBaseName(QName qNameIn) {

                javax.xml.namespace.QName qName =
                        new javax.xml.namespace.QName(qNameIn.getNamespaceURI(),
                                qNameIn.getLocalPart());
                Class cls =
                        defaultTM.getClassForQName(qName);

                if (cls == null) {
                    return null;
                } else {
                    return JavaUtils.getTextClassName(cls.getName());
                }
            }
        };
    
public voidsetWrapArrays(boolean wrapArrays)

        this.wrapArrays = wrapArrays;
    
private voidsetup()
Method setup

throws
IOException


        if (baseTypeMapping == null) {
            setTypeMappingVersion(typeMappingVersion);
        }

        getFactory().setBaseTypeMapping(baseTypeMapping);

        namespaces = new Namespaces(outputDir);

        if (packageName != null) {
            namespaces.setDefaultPackage(packageName);
        } else {

            // First, read the namespace mapping file - configurable, by default
            // NStoPkg.properties - if it exists, and load the namespaceMap HashMap
            // with its data.
            getNStoPkgFromPropsFile(namespaces);

            if (delayedNamespacesMap != null) {
                namespaces.putAll(delayedNamespacesMap);
            }
        }
    
public voidverbose(boolean value)
Turn on/off verbose messages

param
value
deprecated
Use setVerbose(value)

        setVerbose(value);