butek 02/05/16 07:48:21 Modified: java/docs integration-guide.html Added: java/samples/integrationGuide/example1 MyListPortsWriter.java MyWSDL2Java.java java/samples/integrationGuide/example2 MyDeployWriter.java MyEmitter.java MyGeneratorFactory.java WSDL2Useless.java Log: First cut at documenting the extensibility of WSDL2Java. This documentation seems most appropriate in the integration guide so that's where I've put it. I've also written a couple examples. This work is a LONG way from being done, but I've gotta do some non-AXIS work for a while, so I thought I should commit what I've done so far. Revision Changes Path 1.6 +542 -0 xml-axis/java/docs/integration-guide.html Index: integration-guide.html =================================================================== RCS file: /home/cvs/xml-axis/java/docs/integration-guide.html,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- integration-guide.html 15 Mar 2002 10:19:35 -0000 1.5 +++ integration-guide.html 16 May 2002 14:48:20 -0000 1.6 @@ -36,6 +36,7 @@ <br> <a href="#Internationalization Plug">Internationalization</a> <br> <a href="#Performance Monitoring Plug">Performance Monitoring</a> <br> <a href="#Encoding Plug">Encoding</a> +<br> <a href="#WSDL plug">WSDL Parser and Code Generator Framework</a> <h2> <a NAME="Introduction"></a>Introduction</h2> The primary purpose of this guide is @@ -483,5 +484,546 @@ Example</li> </ul> +<h3> +<a NAME="WSDL plug"></a>WSDL Parser and Code Generator Framework</h3> +WSDL2Java is AXIS's tool to generate Java artifacts from WSDL. This +tool is extensible. If users of AXIS wish to extend AXIS, then they +may also need to extend or change the generated artifacts. For example, +if AXIS is inserted into some product which has an existing deployment +model that's different than AXIS's deployment model, then that product's +version of WSDL2Java will be required to generate deployment descriptors +other than AXIS's deploy.wsdd. +<p>What follows immediately is a description of the framework. If +you would rather dive down into the dirt of <a href="#WSDL Examples">examples</a>, +you could learn a good deal just from them. Then you could come back +up here and learn the gory details. +<p>There are three parts to WSDL2Java: +<ol> +<li> +The symbol table</li> + +<li> +The parser front end with a generator framework</li> + +<li> +The code generator back end (WSDL2Java itself)</li> +</ol> + +<h4> +Symbol Table</h4> +The symbol table, found in org.apache.axis.wsdl.symbolTable, will contain +all the symbols from a WSDL document, both the symbols from the WSDL constructs +themselves (portType, binding, etc), and also the XML schema types that +the WSDL refers to. +<p><font color="#FF0000">NOTE: Needs lots of description here.</font> +<p>The symbol table is not extensible, but you <b>can</b> add fields to +it by using the Dynamic Variables construct: +<ul> +<li> +You must have some constant object for a dynamic variable key. For +example: public static final String MY_KEY = "my key";</li> + +<li> +You set the value of the variable in your GeneratorFactory.generatorPass: +entry.setDynamicVar(MY_KEY, myValue);</li> + +<li> +You get the value of the variable in your generators: Object myValue += entry.getDynamicVar(MY_KEY);</li> +</ul> + +<h4> +Parser Front End and Generator Framework</h4> +The parser front end and generator framework is located in org.apache.axis.wsdl.gen. +The parser front end consists of two files: +<ul> +<li> +Parser</li> + +<br><tt>public class Parser {</tt> +<br><tt> public Parser();</tt> +<br><tt> public boolean isDebug();</tt> +<br><tt> public void setDebug(boolean);</tt> +<br><tt> public boolean isImports();</tt> +<br><tt> public void setImports(boolean);</tt> +<br><tt> public boolean isVerbose();</tt> +<br><tt> public void setVerbose(boolean);</tt> +<br><tt> public long getTimeout();</tt> +<br><tt> public void setTimeout(long);</tt> +<br><tt> public java.lang.String getUsername();</tt> +<br><tt> public void setUsername(java.lang.String);</tt> +<br><tt> public java.lang.String getPassword();</tt> +<br><tt> public void setPassword(java.lang.String);</tt> +<br><tt> public GeneratorFactory getFactory();</tt> +<br><tt> public void setFactory(GeneratorFactory);</tt> +<br><tt> public org.apache.axis.wsdl.symbolTable.SymbolTable +getSymbolTable();</tt> +<br><tt> public javax.wsdl.Definition getCurrentDefinition();</tt> +<br><tt> public java.lang.String getWSDLURI();</tt> +<br><tt> public void run(String wsdl) throws java.lang.Exception;</tt> +<br><tt> public void run(String context, org.w3c.dom.Document +wsdlDoc) throws java.io.IOException, javax.wsdl.WSDLException;</tt> +<br><tt>}</tt> +<p>The basic behavior of this class is simple: you instantiate a +Parser, then you run it. +<ul><tt>Parser parser = new Parser();</tt> +<br><tt>parser.run("myfile.wsdl");</tt></ul> + +<p><br>There are various options on the parser that have accessor methods: +<ul> +<li> +debug - default is false - dump the symbol table after the WSDL file has +been parsed</li> + +<li> +imports - default is true - should imported files be visited?</li> + +<li> +verbose - default is false - list each file as it is being parsed</li> + +<li> +timeout - default is 45 - the number of seconds to wait before halting +the parse</li> + +<li> +username - no default - needed for protected URI's</li> + +<li> +password - no default - needed for protected URI's</li> +</ul> + +<p><br>Other miscellaneous methods on the parser: +<ul> +<li> +get/setFactory - get or set the GeneratorFactory on this parser - see below +for details. The default generator factory is NoopFactory, which +generates nothing.</li> + +<li> +getSymbolTable - once a run method is called, the symbol table will be +populated and can get queried.</li> + +<li> +getCurrentDefinition - once a run method is called, the parser will contain +a Definition object which represents the given wsdl file. Definition +is a WSDL4J object.</li> + +<li> +getWSDLURI - once the run method which takes a string is called, the parser +will contain the string representing the location of the WSDL file. +Note that the other run method - run(String context, Document wsdlDoc) +- does not provide a location for the wsdl file. If this run method +is used, getWSDLURI will be null.</li> + +<li> +There are two run methods. The first, as shown above, takes a URI +string which represents the location of the WSDL file. If you've +already parsed the WSDL file into an XML Document, then you can use the +second run method, which takes a context and the WSDL Document.</li> +</ul> + +<p><br>An extension of this class would ... +<br><br> +<font color="#FF0000">NOTE: continue this sentiment...</font> +<br> +<li> +WSDL2</li> + +<br>Parser is the programmatic interface into the WSDL parser. WSDL2 +is the command line tool for the parser. It provides an extensible +framework for calling the Parser from the command line. It is named +WSDL2 because extensions of it will likely begin with WSDL2: <b>WSDL2</b>Java, +<b>WSDL2</b>Lisp, <b>WSDL2</b>XXX. +<p><tt>public class WSDL2 {</tt> +<br><tt> protected WSDL2();</tt> +<br><tt> protected Parser createParser();</tt> +<br><tt> protected Parser getParser();</tt> +<br><tt> protected void addOptions(org.apache.axis.utils.CLOptionDescriptor[]);</tt> +<br><tt> protected void parseOption(org.apache.axis.utils.CLOption);</tt> +<br><tt> protected void validateOptions();</tt> +<br><tt> protected void printUsage();</tt> +<br><tt> protected void run(String[]);</tt> +<br><tt> public static void main(String[]);</tt> +<br><tt>}</tt> +<p>Like all good command line tools, it has a main method. Unlike +some command line tools, however, its methods are not static. Static +methods are not extensible. WSDL2's main method constructs an instance +of itself and calls methods on that instance rather than calling static +methods. These methods follow a behavior pattern. The main +method is very simple: +<br> +<ul><tt> public static void main(String[] args) {</tt> +<br><tt> WSDL2 wsdl2 = new WSDL2();</tt> +<br><tt> wsdl2.run(args);</tt> +<br><tt> }</tt></ul> + +<p><br>The constructor calls createParser to construct a Parser or an extension +of Parser. +<p>run calls: +<ul> +<li> +parseOption to parse each command line option and call the appropriate +Parser accessor. For example, when this method parses --verbose, +it calls parser.setVerbose(true)</li> + +<li> +validateOptions to make sure all the option values are consistent</li> + +<li> +printUsage if the usage of the tool is in error</li> + +<li> +parser.run(args);</li> +</ul> + +<p><br>If an extension has additional options, then it is expected to call +addOptions before calling run. So extensions will call, as necessary, +getParser, addOptions, run. Extensions will override, as necessary, +createParser, parseOption, validateOptions, printUsage. +<br> +<p>The generator framework consists of 2 files: +<ul> +<li> +Generator</li> + +<br>The Generator interface is very simple. It just defines a generate +method. +<p><tt>public interface Generator</tt> +<br><tt>{</tt> +<br><tt> public void generate() throws java.io.IOException;</tt> +<br><tt>}</tt> +<br> +<li> +GeneratorFactory</li> + +<p><br><tt>public interface GeneratorFactory</tt> +<br><tt>{</tt> +<br><tt> public void generatorPass(javax.wsdl.Definition, +SymbolTable);</tt> +<br><tt> public Generator getGenerator(javax.wsdl.Message, +SymbolTable);</tt> +<br><tt> public Generator getGenerator(javax.wsdl.PortType, +SymbolTable);</tt> +<br><tt> public Generator getGenerator(javax.wsdl.Binding, +SymbolTable);</tt> +<br><tt> public Generator getGenerator(javax.wsdl.Service, +SymbolTable);</tt> +<br><tt> public Generator getGenerator(TypeEntry, SymbolTable);</tt> +<br><tt> public Generator getGenerator(javax.wsdl.Definition, +SymbolTable);</tt> +<br><tt> public void setBaseTypeMapping(BaseTypeMapping);</tt> +<br><tt> public BaseTypeMapping getBaseTypeMapping();</tt> +<br><tt>}</tt> +<p>The GeneratorFactory interface defines a set of methods that the parser +uses to get generators. There should be a generator for each of the +WSDL constructs (message, portType, etc - note that these depend on the +WSDL4J classes: javax.xml.Message, javax.xml.PortType, etc); a generator +for schema types; and a generator for the WSDL Definition itself. +This last generator is used to generate anything that doesn't fit into +the previous categories +<p>In addition to the getGeneratorMethods, the GeneratorFactory defines +a generatorPass method which provides the factory implementation a chance +to walk through the symbol table to do any preprocessing before the actual +generation begins. +<p>Accessors for the base type mapping are also defined. These are +used to translate QNames to base types in the given target mapping. +<br> </ul> +In addition to Parser, WSDL2, Generator, and GeneratorFactory, the org.apache.axis.wsdl.gen +package also contains a couple of no-op classes: NoopGenerator and +NoopFactory. NoopGenerator is a convenience class for extensions +that do not need to generate artifacts for every WSDL construct. +For example, WSDL2Java does not generate anything for messages, therefore +its factory's getGenerator(Message, SymbolTable) method returns an instance +of NoopGenerator. NoopFactory returns a NoopGenerator for all getGenerator +methods. The default factory for Parser is the NoopFactory.</ul> + +<h4> +Code Generator Back End</h4> +The meat of the WSDL2Java back end generators is in org.apache.axis.wsdl.toJava. +Emitter extends Parser. org.apache.axis.wsdl.WSDL2Java extends WSDL2. +JavaGeneratorFactory implements GeneratorFactory. And the various +JavaXXXWriter classes implement the Generator interface. +<p><font color="#FF0000">NOTE: Need lots more description here...</font> +<h4> +<a NAME="WSDL Examples"></a>WSDL Framework Extension Examples</h4> +Everything above sounds rather complex. It is, but that doesn't mean +your extension has to be. +<h5> +Example 1 - Simple extension of WSDL2Java - additional artifact</h5> +The simplest extension of the framework is one which generates everything +that WSDL2Java already generates, plus something new. Example 1 is +such an extension. It's extra artifact is a file for each service +that lists that service's ports. I don't know why you'd want to do +this, but it makes for a good, simple example. See samples/integrationGuide/example1 +for the complete implementation of this example. +<br> +<ul> +<li> +First you must create your writer that writes the new artifact. This +new class extends org.apache.axis.wsdl.toJava.JavaWriter. JavaWriter +dictates behavior to its extensions; it calls writeFileHeader and writeFileBody. +Since we don't care about a file header for this example, writeFileHeader +is a no-op method. writeFileBody does the real work of this writer.</li> + +<p><br><tt>public class MyListPortsWriter extends JavaWriter {</tt> +<br><tt> private Service service;</tt> +<br><tt> public MyListPortsWriter(</tt> +<br><tt> +Emitter emitter,</tt> +<br><tt> +ServiceEntry sEntry,</tt> +<br><tt> +SymbolTable symbolTable) {</tt> +<br><tt> super(emitter,</tt> +<br><tt> +new QName(</tt> +<br><tt> +sEntry.getQName().getNamespaceURI(),</tt> +<br><tt> +sEntry.getQName().getLocalPart() + "Lst"),</tt> +<br><tt> +"", "lst", "Generating service port list file", "service list");</tt> +<br><tt> this.service = sEntry.getService();</tt> +<br><tt> }</tt> +<br><tt> protected void writeFileHeader() throws IOException +{</tt> +<br><tt> }</tt> +<br><tt> protected void writeFileBody() throws IOException +{</tt> +<br><tt> Map portMap = service.getPorts();</tt> +<br><tt> Iterator portIterator += portMap.values().iterator();</tt><tt></tt> +<p><tt> while (portIterator.hasNext()) +{</tt> +<br><tt> +Port p = (Port) portIterator.next();</tt> +<br><tt> +pw.println(p.getName());</tt> +<br><tt> }</tt> +<br><tt> pw.close();</tt> +<br><tt> }</tt> +<br><tt>}</tt> +<br> +<li> +Then you need a main program. This main program extends WSDL2Java +so that it gets all the functionality of that tool. The main of this +tool does 3 things:</li> + +<ul> +<li> +instantiates itself</li> + +<li> +adds MyListPortsWriter to the list of generators for a WSDL service</li> + +<li> +calls the run method.</li> +</ul> +That's it! The base tool does all the rest of the work. +<p><tt>public class MyWSDL2Java extends WSDL2Java {</tt><tt></tt> +<p><tt> public static void main(String args[]) {</tt> +<br><tt> MyWSDL2Java myWSDL2Java += new MyWSDL2Java();</tt><tt></tt> +<p><tt> JavaGeneratorFactory +factory =</tt> +<br><tt> +(JavaGeneratorFactory) myWSDL2Java.getParser().getFactory();</tt> +<br><tt> factory.addGenerator(Service.class, +MyListPortsWriter.class);</tt><tt></tt> +<p><tt> myWSDL2Java.run(args);</tt> +<br><tt> }</tt> +<br><tt>}</tt></ul> + +<h5> +Example 2 - Not quite as simple an extension of WSDL2Java - change an artifact</h5> +In this example, we'll replace deploy.wsdd with mydeploy.useless. +For brevity, mydeploy.useless is rather useless. Making it useful +is an exercise left to the reader. See samples/integrationGuide/example2 +for the complete implementation of this example. +<ul> +<li> +First, here is the writer for the mydeploy.useless. This new class +extends org.apache.axis.wsdl.toJava.JavaWriter. JavaWriter dictates +behavior to its extensions; it calls writeFileHeader and writeFileBody. +Since we don't care about a file header for this example, writeFileHeader +is a no-op method. writeFileBody does the real work of this writer. +It simply writes a bit of a song, depending on user input.</li> + +<p><br>Note that we've also overridden the generate method. The parser +always calls generate, but since this is a server-side artifact, we don't +want to generate it unless we are generating server-side artifacts (in +other words, in terms of the command line options, we've specified the +--serverSide option). +<p><tt>public class MyDeployWriter extends JavaWriter {</tt> +<br><tt> public MyDeployWriter(Emitter emitter, Definition +definition,</tt> +<br><tt> +SymbolTable symbolTable) {</tt> +<br><tt> super(emitter,</tt> +<br><tt> +new QName(definition.getTargetNamespace(), "deploy"),</tt> +<br><tt> +"", "useless", "Generating deploy.useless", "deploy");</tt> +<br><tt> }</tt> +<br><tt> public void generate() throws IOException {</tt> +<br><tt> if (emitter.isServerSide()) +{</tt> +<br><tt> +super.generate();</tt> +<br><tt> }</tt> +<br><tt> }</tt> +<br><tt> protected void writeFileHeader() throws IOException +{</tt> +<br><tt> }</tt> +<br><tt> protected void writeFileBody() throws IOException +{</tt> +<br><tt> MyEmitter myEmitter += (MyEmitter) emitter;</tt> +<br><tt> if (myEmitter.getSong() +== MyEmitter.RUM) {</tt> +<br><tt> +pw.println("Yo! Ho! Ho! And a bottle of rum.");</tt> +<br><tt> }</tt> +<br><tt> else if (myEmitter.getSong() +== MyEmitter.WORK) {</tt> +<br><tt> +pw.println("Hi ho! Hi ho! It's off to work we go.");</tt> +<br><tt> }</tt> +<br><tt> else {</tt> +<br><tt> +pw.println("Feelings... Nothing more than feelings...");</tt> +<br><tt> }</tt> +<br><tt> pw.close();</tt> +<br><tt> }</tt> +<br><tt>}</tt> +<br><tt></tt> +<li> +Since we're changing what WSDL2Java generates, rather than simply adding +to it like the previous example did, calling addGenerator isn't good enough. +In order to change what WSDL2Java generates, you have to create a generator +factory and provide your own generators. Since we want to keep most +of WSDL2Java's artifacts, we can simply extend WSDL2Java's factory - JavaGeneratorFactory +- and override the addDefinitionGenerators method.</li> + +<p><br><tt>public class MyGeneratorFactory extends JavaGeneratorFactory +{</tt> +<br><tt> protected void addDefinitionGenerators() {</tt> +<br><tt> addGenerator(Definition.class, +JavaDefinitionWriter.class); // WSDL2Java's JavaDefinitionWriter</tt> +<br><tt> addGenerator(Definition.class, +MyDeployWriter.class); // our DeployWriter</tt> +<br><tt> addGenerator(Definition.class, +JavaUndeployWriter.class); // WSDL2Java's JavaUndeployWriter</tt> +<br><tt> }</tt> +<br><tt>}</tt> +<br> +<li> +Now we must write the API's to our tool. Since we've added an option +- song - we need both the programmatic API - an extension of Parser (actually +Emitter in this case since we're extending WSDL2Java and Emitter is WSDL2Java's +parser extension) - and the command line API.</li> + +<p><br>Here is our programmatic API. It adds song accessors to Emitter. +It also, in the constructor, lets the factory know about the emitter and +the emitter know about the factory. +<p><tt>public class MyEmitter extends Emitter {</tt> +<br><tt> public static final int RUM = 0;</tt> +<br><tt> public static final int WORK = 1;</tt> +<br><tt> private int song = -1;</tt><tt></tt> +<p><tt> public MyEmitter() {</tt> +<br><tt> MyGeneratorFactory factory += new MyGeneratorFactory();</tt> +<br><tt> setFactory(factory);</tt> +<br><tt> factory.setEmitter(this);</tt> +<br><tt> }</tt> +<br><tt> public int getSong() {</tt> +<br><tt> return song;</tt> +<br><tt> }</tt> +<br><tt> public void setSong(int song) {</tt> +<br><tt> this.song = song;</tt> +<br><tt> }</tt> +<br><tt>}</tt> +<p>And here is our command line API. It's a bit more complex that +our previous example's main program, but it does 2 extra things: +<ol> +<li> +accept a new command line option: --song rum|work (this is the biggest +chunk of the new work).</li> + +<li> +create a new subclass of Parser</li> +</ol> + +<p><br><tt>public class WSDL2Useless extends WSDL2Java {</tt> +<br><tt> protected static final int SONG_OPT = 'g';</tt> +<br><tt> protected static final CLOptionDescriptor[] +options = new CLOptionDescriptor[]{</tt> +<br><tt> new CLOptionDescriptor("song",</tt> +<br><tt> +CLOptionDescriptor.ARGUMENT_REQUIRED,</tt> +<br><tt> +SONG_OPT,</tt> +<br><tt> +"Choose a song for deploy.useless: work or rum")</tt> +<br><tt> };</tt><tt></tt> +<p><tt> public WSDL2Useless() {</tt> +<br><tt> addOptions(options);</tt> +<br><tt> }</tt> +<br><tt> protected Parser createParser() {</tt> +<br><tt> return new MyEmitter();</tt> +<br><tt> }</tt> +<br><tt> protected void parseOption(CLOption option) +{</tt> +<br><tt> if (option.getId() == +SONG_OPT) {</tt> +<br><tt> +String arg = option.getArgument();</tt> +<br><tt> +if (arg.equals("rum")) {</tt> +<br><tt> +((MyEmitter) parser).setSong(MyEmitter.RUM);</tt> +<br><tt> +}</tt> +<br><tt> +else if (arg.equals("work")) {</tt> +<br><tt> +((MyEmitter) parser).setSong(MyEmitter.WORK);</tt> +<br><tt> +}</tt> +<br><tt> }</tt> +<br><tt> else {</tt> +<br><tt> +super.parseOption(option);</tt> +<br><tt> }</tt> +<br><tt> }</tt> +<br><tt> public static void main(String args[]) {</tt> +<br><tt> WSDL2Useless useless += new WSDL2Useless();</tt><tt></tt> +<p><tt> useless.run(args);</tt> +<br><tt> }</tt> +<br><tt>}</tt> +<p>Let's go through this one method at a time. +<ul> +<li> +constructor - this constructor adds the new option --song rum|work. +(the abbreviated version of this option is "-g", rather an odd abbreviation, +but "-s" is the abbreviation for --serverSide and "-S" is the abbreviation +for --skeletonDeploy. Bummer. I just picked some other letter.</li> + +<li> +createParser - we've got to provide a means by which the parent class can +get our Parser extension.</li> + +<li> +parseOption - this method processes our new option. If the given +option isn't ours, just let super.parseOption do its work.</li> + +<li> +main - this main is actually simpler than the first example's main. +The first main had to add our generator to the list of generators. +In this example, the factory already did that, so all that this main must +do is instantiate itself and run itself.</li> +</ul> +</ul> </body> </html> 1.1 xml-axis/java/samples/integrationGuide/example1/MyListPortsWriter.java Index: MyListPortsWriter.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package samples.integrationGuide.example1; import java.io.IOException; import java.util.Iterator; import java.util.Map; import javax.wsdl.Port; import javax.wsdl.QName; import javax.wsdl.Service; import org.apache.axis.wsdl.symbolTable.ServiceEntry; import org.apache.axis.wsdl.symbolTable.SymbolTable; import org.apache.axis.wsdl.toJava.Emitter; import org.apache.axis.wsdl.toJava.JavaWriter; /** * This is my example of a class that writes a list of a service's * ports to a file named <serviceName>Lst.lst. * * Note: because of a name clash problem, I add the suffix "Lst". * I hope to remove this in a future version of this example. * * Details of the JavaWriter bug: JavaWriter looks to make sure a * class doesn't already exist before creating a file, but not all * files that we generate are .class files! This works with * deploy.wsdd and undeploy.wsdd because these files just happen * to begin with lowercase letters, where Java classes begin with * uppercase letters. But this example shows the problem quite * well. I would LIKE to call the file <serviceName>.lst, but * JavaWriter sees that we already have a class called * <serviceName> and won't let me proceed. */ public class MyListPortsWriter extends JavaWriter { private Service service; /** * Constructor. */ public MyListPortsWriter( Emitter emitter, ServiceEntry sEntry, SymbolTable symbolTable) { super(emitter, new QName( sEntry.getQName().getNamespaceURI(), sEntry.getQName().getLocalPart() + "Lst"), "", "lst", "Generating service port list file", "service list"); this.service = sEntry.getService(); } // ctor /** * Override the common JavaWriter header to a no-op. */ protected void writeFileHeader() throws IOException { } // writeFileHeader /** * Write the service list file. */ protected void writeFileBody() throws IOException { Map portMap = service.getPorts(); Iterator portIterator = portMap.values().iterator(); while (portIterator.hasNext()) { Port p = (Port) portIterator.next(); pw.println(p.getName()); } pw.close(); // Note: this really should be done in JavaWriter. } // writeFileBody } // class MyListPortsWriter 1.1 xml-axis/java/samples/integrationGuide/example1/MyWSDL2Java.java Index: MyWSDL2Java.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package samples.integrationGuide.example1; import javax.wsdl.Service; import org.apache.axis.wsdl.WSDL2Java; import org.apache.axis.wsdl.toJava.JavaGeneratorFactory; public class MyWSDL2Java extends WSDL2Java { /** * Main */ public static void main(String args[]) { MyWSDL2Java myWSDL2Java = new MyWSDL2Java(); JavaGeneratorFactory factory = (JavaGeneratorFactory) myWSDL2Java.getParser().getFactory(); factory.addGenerator(Service.class, MyListPortsWriter.class); myWSDL2Java.run(args); } // main } // MyWSDL2Java 1.1 xml-axis/java/samples/integrationGuide/example2/MyDeployWriter.java Index: MyDeployWriter.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package samples.integrationGuide.example2; import java.io.IOException; import javax.wsdl.Definition; import javax.wsdl.QName; import org.apache.axis.wsdl.symbolTable.SymbolTable; import org.apache.axis.wsdl.toJava.Emitter; import org.apache.axis.wsdl.toJava.JavaWriter; public class MyDeployWriter extends JavaWriter { public MyDeployWriter(Emitter emitter, Definition definition, SymbolTable symbolTable) { super(emitter, new QName(definition.getTargetNamespace(), "deploy"), "", "useless", "Generating deploy.useless", "deploy"); } // ctor public void generate() throws IOException { if (emitter.isServerSide()) { super.generate(); } } // generate /** * Override the common JavaWriter header to a no-op. */ protected void writeFileHeader() throws IOException { } // writeFileHeader /** * Write the service list file. */ protected void writeFileBody() throws IOException { MyEmitter myEmitter = (MyEmitter) emitter; if (myEmitter.getSong() == MyEmitter.RUM) { pw.println("Yo! Ho! Ho! And a bottle of rum."); } else if (myEmitter.getSong() == MyEmitter.WORK) { pw.println("Hi ho! Hi ho! It's off to work we go."); } else { pw.println("Feelings... Nothing more than feelings..."); } pw.close(); // Note: this really should be done in JavaWriter. } // writeFileBody } // class MyDeployWriter 1.1 xml-axis/java/samples/integrationGuide/example2/MyEmitter.java Index: MyEmitter.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package samples.integrationGuide.example2; import org.apache.axis.wsdl.toJava.Emitter; public class MyEmitter extends Emitter { public static final int RUM = 0; public static final int WORK = 1; private int song = -1; public MyEmitter() { MyGeneratorFactory factory = new MyGeneratorFactory(); setFactory(factory); factory.setEmitter(this); } // ctor public int getSong() { return song; } // getSong public void setSong(int song) { this.song = song; } // setSong } // class MyEmitter 1.1 xml-axis/java/samples/integrationGuide/example2/MyGeneratorFactory.java Index: MyGeneratorFactory.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package samples.integrationGuide.example2; import javax.wsdl.Definition; import org.apache.axis.wsdl.gen.Generator; import org.apache.axis.wsdl.symbolTable.SymbolTable; import org.apache.axis.wsdl.symbolTable.TypeEntry; import org.apache.axis.wsdl.toJava.Emitter; import org.apache.axis.wsdl.toJava.JavaDefinitionWriter; import org.apache.axis.wsdl.toJava.JavaGeneratorFactory; import org.apache.axis.wsdl.toJava.JavaUndeployWriter; /** * IBM Extension to WSDL2Java Emitter * This class is used to locate the IBM extension writers. * (For example the IBM JavaType Writer) * * @author Rich Scheuerle ([EMAIL PROTECTED]) * @author Russell Butek ([EMAIL PROTECTED]) */ public class MyGeneratorFactory extends JavaGeneratorFactory { /* * NOTE! addDefinitionGenerators is the ONLY addXXXGenerators method * that works at this point in time (2002-17-May). This rest of them * are soon to be implemented. */ protected void addDefinitionGenerators() { addGenerator(Definition.class, JavaDefinitionWriter.class); // WSDL2Java's JavaDefinitionWriter addGenerator(Definition.class, MyDeployWriter.class); // our DeployWriter addGenerator(Definition.class, JavaUndeployWriter.class); // WSDL2Java's JavaUndeployWriter } // addDefinitionGenerators } // class MyGeneratorFactory 1.1 xml-axis/java/samples/integrationGuide/example2/WSDL2Useless.java Index: WSDL2Useless.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package samples.integrationGuide.example2; import org.apache.axis.utils.CLOption; import org.apache.axis.utils.CLOptionDescriptor; import org.apache.axis.wsdl.WSDL2Java; import org.apache.axis.wsdl.gen.Parser; import org.apache.axis.wsdl.toJava.Emitter; public class WSDL2Useless extends WSDL2Java { protected static final int SONG_OPT = 'g'; protected static final CLOptionDescriptor[] options = new CLOptionDescriptor[]{ new CLOptionDescriptor("song", CLOptionDescriptor.ARGUMENT_REQUIRED, SONG_OPT, "Choose a song for deploy.useless: work or rum") }; public WSDL2Useless() { addOptions(options); } // ctor protected Parser createParser() { return new MyEmitter(); } // createParser protected void parseOption(CLOption option) { if (option.getId() == SONG_OPT) { String arg = option.getArgument(); if (arg.equals("rum")) { ((MyEmitter) parser).setSong(MyEmitter.RUM); } else if (arg.equals("work")) { ((MyEmitter) parser).setSong(MyEmitter.WORK); } } else { super.parseOption(option); } } // parseOption /** * Main */ public static void main(String args[]) { WSDL2Useless useless = new WSDL2Useless(); useless.run(args); } // main } // class WSDL2Useless