Return-Path: Delivered-To: apmail-xml-axis-dev-archive@xml.apache.org Received: (qmail 95165 invoked by uid 500); 10 Oct 2001 14:54:20 -0000 Mailing-List: contact axis-dev-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-dev@xml.apache.org Received: (qmail 95156 invoked from network); 10 Oct 2001 14:54:20 -0000 Message-ID: <47FD4196C273D411950300508BCF1978013B1BC5@S0001EXC0006> From: Tom Jordahl To: "'axis-dev@xml.apache.org'" Subject: RE: I've added XML import support to Wsdl2java Date: Wed, 10 Oct 2001 10:53:44 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N This looks fine, although the literal "void" makes me nervous. Is there a QName defined in ServiceDescription for the void type? Maybe not.... I would apply the description "rough" to the ServiceDescription code I added. :-) -- Tom Jordahl -----Original Message----- From: Russell Butek [mailto:butek@us.ibm.com] Sent: Friday, October 05, 2001 6:10 PM To: axis-dev@xml.apache.org Subject: I've added XML import support to Wsdl2java All, I've added import support. If you're curious, here are the wsdl documents I used to test it: (See attached file: import.zip). These will eventually get into a formal test. Tom, one note, my test initially failed. I think I fixed a bug in the new ServiceDescription code where it would fail if the returnType was "void". I'm not sure I did the right thing, so could you check it for me? Here's the detail: @@ -1126,12 +1189,14 @@ } } // set output type - QName qn = emitFactory.getType(parms.returnType).getQName(); - String outputType = "new org.apache.axis.utils.QName(\"" + qn.getNamespaceURI() + "\", \"" + - qn.getLocalPart() + "\")"; - pw.println(" sd.setOutputType(" + outputType + ");"); + if (!"void".equals(parms.returnType)) { + QName qn = emitFactory.getType(parms.returnType).getQName(); + String outputType = "new org.apache.axis.utils.QName(\"" + qn.getNamespaceURI() + "\", \"" + + qn.getLocalPart() + "\")"; + pw.println(" sd.setOutputType(" + outputType + ");"); - pw.println(" "); + pw.println(); + } // Set this service description for the call pw.println(" call.setServiceDescription(sd);"); Russell Butek butek@us.ibm.com ---------------------- Forwarded by Russell Butek/Austin/IBM on 10/05/2001 05:01 PM --------------------------- butek@apache.org on 10/05/2001 04:57:35 PM Please respond to axis-dev@xml.apache.org To: xml-axis-cvs@apache.org cc: Subject: cvs commit: xml-axis/java/src/org/apache/axis/wsdl Wsdl2java.java Utils.java Emitter.java butek 01/10/05 14:57:35 Modified: java/src/org/apache/axis/wsdl Wsdl2java.java Utils.java Emitter.java Log: Support XML imports. Added -n, --noImports only generate code for the immediate WSDL document Fixed (hopefully) a bug in the ServiceDescription code when the return is a void. Revision Changes Path 1.15 +11 -1 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.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- Wsdl2java.java 2001/10/05 20:28:18 1.14 +++ Wsdl2java.java 2001/10/05 21:57:34 1.15 @@ -76,6 +76,7 @@ protected static final int OUTPUT_OPT = 'o'; protected static final int SCOPE_OPT = 'd'; protected static final int TEST_OPT = 't'; + protected static final int NOIMPORTS_OPT = 'n'; /** * Define the understood options. Each CLOptionDescriptor contains: @@ -118,7 +119,11 @@ new CLOptionDescriptor("testCase", CLOptionDescriptor.ARGUMENT_DISALLOWED, TEST_OPT, - "emit junit testcase class for web service") + "emit junit testcase class for web service"), + new CLOptionDescriptor("noImports", + CLOptionDescriptor.ARGUMENT_DISALLOWED, + NOIMPORTS_OPT, + "only generate code for the immediate WSDL document") }; /** @@ -205,9 +210,14 @@ System.err.println("Unrecognized scope: " + scope + ". Ignoring it."); } break; + case TEST_OPT: bTestClass = true; emitter.generateTestCase(true); + break; + + case NOIMPORTS_OPT: + emitter.generateImports(false); break; } } 1.3 +3 -1 xml-axis/java/src/org/apache/axis/wsdl/Utils.java Index: Utils.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Utils.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Utils.java 2001/10/04 15:42:43 1.2 +++ Utils.java 2001/10/05 21:57:34 1.3 @@ -200,7 +200,9 @@ */ public static boolean isSchemaNS(String s) { return (s.equals("http://www.w3.org/2001/XMLSchema") - || s.equals("http://www.w3.org/1999/XMLSchema")); + || s.equals("http://www.w3.org/1999/XMLSchema") + || s.equals("http://www.w3.org/2001/XMLSchema/") + || s.equals("http://www.w3.org/1999/XMLSchema/")); } /** 1.38 +104 -39 xml-axis/java/src/org/apache/axis/wsdl/Emitter.java Index: Emitter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Emitter.java,v retrieving revision 1.37 retrieving revision 1.38 diff -u -r1.37 -r1.38 --- Emitter.java 2001/10/05 20:28:18 1.37 +++ Emitter.java 2001/10/05 21:57:34 1.38 @@ -69,6 +69,7 @@ import javax.wsdl.BindingOperation; import javax.wsdl.Definition; import javax.wsdl.Fault; +import javax.wsdl.Import; import javax.wsdl.Input; import javax.wsdl.Operation; import javax.wsdl.Output; @@ -118,13 +119,39 @@ private boolean bEmitTestCase = false; private boolean bVerbose = false; private boolean bGeneratePackageName = false; + private boolean bGenerateImports = true; String packageName = null; String packageDirName = ""; String outputDir = null; byte scope = NO_EXPLICIT_SCOPE; private TypeFactory emitFactory = null; + private HashMap portTypesInfo = null; + /** + * Default constructor. + */ + public Emitter() { + portTypesInfo = new HashMap(); + } // ctor + + /** + * Construct an Emitter that initially looks like the given Emitter. + */ + public Emitter(Emitter that) { + this.bEmitSkeleton = that.bEmitSkeleton; + this.bMessageContext = that.bMessageContext; + this.bEmitTestCase = that.bEmitTestCase; + this.bVerbose = that.bVerbose; + this.bGeneratePackageName = that.bGeneratePackageName; + this.bGenerateImports = that.bGenerateImports; + this.packageName = that.packageName; + this.packageDirName = that.packageDirName; + this.outputDir = that.outputDir; + this.scope = that.scope; + this.emitFactory = that.emitFactory; + this.portTypesInfo = that.portTypesInfo; + } // ctor /** * Call this method if you have a uri for the WSDL document @@ -135,8 +162,7 @@ System.out.println("Parsing XML File: " + uri); try { - doc = XMLUtils.newDocument(uri); - emit(doc); + emit(XMLUtils.newDocument(uri)); } catch (Throwable t) { t.printStackTrace(); @@ -148,53 +174,61 @@ * Call this method if your WSDL document has already been parsed as an XML DOM document. */ public void emit(Document doc) throws IOException { - this.doc = doc; - try { + setup(); WSDLReader reader = new WSDLReader(); - File outputFile = null; - def = reader.readWSDL(null, doc); - - // Generate package name if desired - if (packageName == null && bGeneratePackageName) { - makePackageName(); - } - - // Make sure the directory that the files will go into exists - if (outputDir == null) { - outputFile = new File(packageDirName); - } else { - outputFile = new File(outputDir, packageDirName); - } - - outputFile.mkdirs(); - - if (bVerbose && packageName != null) { - System.out.println("Using package name: " + packageName); - } + emit(def, doc); + } + catch (Throwable t) { + t.printStackTrace(); + System.out.println("Error in parsing: " + t.getMessage()); + } + } // emit - emitFactory = new TypeFactory(); + private void emit(Definition def, Document doc) throws IOException { + this.def = def; + this.doc = doc; + // Generate types from doc + if (doc != null) { emitFactory.buildTypes(doc); - if (bVerbose) { System.out.println("Types:"); emitFactory.dump(); } + // Output Java classes for types + writeTypes(); + } + + if (def != null) { + // Generated all the imported XML + if (bGenerateImports) { + + // Generate the imported WSDL documents + Map imports = def.getImports(); + Object[] importKeys = imports.keySet().toArray(); + for (int i = 0; i < importKeys.length; ++i) { + Vector v = (Vector) imports.get(importKeys[i]); + for (int j = 0; j < v.size(); ++j) { + Import imp = (Import) v.get(j); + Emitter emitter = new Emitter(this); + emitter.emit(imp.getDefinition(), + XMLUtils.newDocument(imp.getLocationURI())); + } + } + } + // Collect information about ports and operations wsdlAttr = new WsdlAttributes(def, new HashMap()); // output interfaces for portTypes - HashMap portTypesInfo = writePortTypes(); + portTypesInfo = writePortTypes(); // Output Stub classes for bindings writeBindings(portTypesInfo); - // Output Java classes for types - writeTypes(); - // Output factory classes for services writeServices(); @@ -202,12 +236,33 @@ if (bEmitSkeleton) { writeDeploymentXML(); } + } + } // emit + /** + * Set up the emitter variables: packageName, wsdlAttr, output directory, etc. + */ + private void setup() { + // Generate package name if desired + if (packageName == null && bGeneratePackageName) { + makePackageName(); } - catch (WSDLException e) { - e.printStackTrace(); + + // Make sure the directory that the files will go into exists + File outputFile = null; + if (outputDir == null) { + outputFile = new File(packageDirName); + } else { + outputFile = new File(outputDir, packageDirName); } - } // emit + outputFile.mkdirs(); + + if (bVerbose && packageName != null) { + System.out.println("Using package name: " + packageName); + } + + emitFactory = new TypeFactory(); + } // setup /////////////////////////////////////////////////// // @@ -223,7 +278,7 @@ } /** - * Turn on/off server skeleton creation + * Turn on/off test case creation * @param boolean value */ public void generateTestCase(boolean value) { @@ -239,6 +294,14 @@ } /** + * Turn on/off generation of elements from imported files. + * @param boolean generateImports + */ + public void generateImports(boolean generateImports) { + this.bGenerateImports = generateImports; + } // generateImports + + /** * Turn on/off verbose messages * @param boolean value */ @@ -1126,12 +1189,14 @@ } } // set output type - QName qn = emitFactory.getType(parms.returnType).getQName(); - String outputType = "new org.apache.axis.utils.QName(\"" + qn.getNamespaceURI() + "\", \"" + - qn.getLocalPart() + "\")"; - pw.println(" sd.setOutputType(" + outputType + ");"); + if (!"void".equals(parms.returnType)) { + QName qn = emitFactory.getType(parms.returnType).getQName(); + String outputType = "new org.apache.axis.utils.QName(\"" + qn.getNamespaceURI() + "\", \"" + + qn.getLocalPart() + "\")"; + pw.println(" sd.setOutputType(" + outputType + ");"); - pw.println(" "); + pw.println(); + } // Set this service description for the call pw.println(" call.setServiceDescription(sd);");