You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by bu...@apache.org on 2001/10/05 23:57:35 UTC
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);");