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 st...@apache.org on 2002/10/25 08:24:37 UTC
cvs commit: xml-axis/java/tools/org/apache/axis/tools/ant/wsdl Mapper.java MappingSet.java NamespaceMapping.java TypeMappingVersionEnum.java Java2WsdlAntTask.java Wsdl2javaAntTask.java
stevel 2002/10/24 23:24:37
Modified: java/tools build.xml
java/tools/org/apache/axis/tools/ant/axis
RunAxisFunctionalTestsTask.java
java/tools/org/apache/axis/tools/ant/foreach
ForeachTask.java
java/tools/org/apache/axis/tools/ant/wsdl
Java2WsdlAntTask.java Wsdl2javaAntTask.java
Added: java/tools/org/apache/axis/tools/ant/wsdl Mapper.java
MappingSet.java NamespaceMapping.java
TypeMappingVersionEnum.java
Log:
big cleanup and javadoc of the ant tasks. Nothing valid *should* break, though we are now a lot stricter than before, so things that break were probably invalid.
Still need docs to describe what is going on with nested elements. quick summary, you can go <mapping file="somefile/>, the final intent is to have a mappingset datatype that you can use across tasks, then add multiple wsdl file support to wsdl2java
Revision Changes Path
1.12 +11 -5 xml-axis/java/tools/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/xml-axis/java/tools/build.xml,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- build.xml 19 Sep 2002 15:58:02 -0000 1.11
+++ build.xml 25 Oct 2002 06:24:36 -0000 1.12
@@ -64,6 +64,7 @@
<!-- build my ForEach task -->
<echo message="Building ForEach" />
<javac srcdir="${tools.dir}/${componentName}/foreach"
+ debug="${debug}"
destdir="${tools.build.dir}">
<classpath refid="classpath"/>
<include name="*.java" />
@@ -72,6 +73,7 @@
<!-- build the RunAxisFunctionalTest task -->
<echo message="Building RunAxisFunctionalTest" />
<javac srcdir="${tools.dir}/${componentName}/axis"
+ debug="${debug}"
destdir="${tools.build.dir}">
<classpath refid="classpath"/>
<include name="*.java" />
@@ -79,7 +81,8 @@
<!-- build the wsdl2java and java2wsdl tasks -->
<echo message="Building WSDL tasks" />
- <javac srcdir="${tools.dir}/${componentName}/wsdl"
+ <javac srcdir="${tools.dir}/${componentName}/wsdl"
+ debug="${debug}"
destdir="${tools.build.dir}">
<classpath>
<pathelement location="${build.lib}/${name}.jar"/>
@@ -108,8 +111,11 @@
<property name="xdocs.dir" location="${env.ANT_HOME}/proposal/xdocs" />
<path id="xdoclet.extra.classpath">
- <pathelement location="${build.lib}/axis.jar"/>
+ <fileset dir="${build.lib}">
+ <include name="**/*.jar"/>
+ </fileset>
</path>
+
<property name="xdoclet.extra.classpath.asprop"
refid="xdoclet.extra.classpath"/>
@@ -120,19 +126,19 @@
-<target name="xdocs" depends="probe-xdocs"
+<target name="xdocs" depends="probe-xdocs,compile"
description="Run xdoclet over the ant tasks to create doc pages"
if="xdocs.found">
<echo>
running xdocs with classpath=${xdoclet.extra.classpath.asprop}
</echo>
<ant inheritAll="${ant.inheritAll}" inheritRefs="${ant.inheritRefs}" dir="${xdocs.dir}">
- <property name="src.dir" location="org/apache/axis/tools/ant"/>
+ <property name="src.dir" location="org/apache/axis/tools/ant/"/>
<property name="src.root" location="."/>
<property name="xdoclet.extra.classpath"
value="${xdoclet.extra.classpath.asprop}"/>
</ant>
</target>
-
+
</project>
1.4 +4 -1 xml-axis/java/tools/org/apache/axis/tools/ant/axis/RunAxisFunctionalTestsTask.java
Index: RunAxisFunctionalTestsTask.java
===================================================================
RCS file: /home/cvs/xml-axis/java/tools/org/apache/axis/tools/ant/axis/RunAxisFunctionalTestsTask.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RunAxisFunctionalTestsTask.java 17 Oct 2002 20:41:08 -0000 1.3
+++ RunAxisFunctionalTestsTask.java 25 Oct 2002 06:24:36 -0000 1.4
@@ -68,7 +68,10 @@
* Ant task for starting / stopping servers and running junit in the middle.
* Based on the Cactus org.apache.commons.cactus.ant package, heavily munged
* and cruftily dumped into one file.
- *
+ * <p>
+ * <i>For Axis development; there is no support or stability associated
+ * with this task</i>
+ * @ant.task category="axis"
* @author Rob Jellinghaus (robj@unrealities.com)
*/
public class RunAxisFunctionalTestsTask extends Task
1.9 +18 -15 xml-axis/java/tools/org/apache/axis/tools/ant/foreach/ForeachTask.java
Index: ForeachTask.java
===================================================================
RCS file: /home/cvs/xml-axis/java/tools/org/apache/axis/tools/ant/foreach/ForeachTask.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ForeachTask.java 19 Sep 2002 15:58:02 -0000 1.8
+++ ForeachTask.java 25 Oct 2002 06:24:36 -0000 1.9
@@ -68,22 +68,25 @@
/**
* Call a target foreach entry in a set of parameters based on a fileset.
+ * <p>
+ * <i>For Axis development; there is no support or stability associated
+ * with this task</i>
* <pre>
- * <target name="target1">
- * <foreach target="target2">
- * <param name="param1">
- * <fileset refid="fset1"/>
- * </param>
- * <param name="param2">
- * <item value="jar" />
- * <item value="zip" />
- * </param>
- * </foreach>
- * </target>
+ * <target name="target1">
+ * <foreach target="target2">
+ * <param name="param1">
+ * <fileset refid="fset1"/>
+ * </param>
+ * <param name="param2">
+ * <item value="jar" />
+ * <item value="zip" />
+ * </param>
+ * </foreach>
+ * </target>
*
- * <target name="target2">
- * <echo message="prop is ${param1}.${param2}" />
- * </target>
+ * <target name="target2">
+ * <echo message="prop is ${param1}.${param2}" />
+ * </target>
* </pre>
* <br>
* Really this just a wrapper around "AntCall"
@@ -92,7 +95,7 @@
* in <code>ExecuteOn</code>. It allows the user
* to specify whether directories, files, or both directories and files
* from the filesets are included as entries in the parameter set.
- *
+ * @ant.task category="axis"
* @author <a href="mailto:tpv@spamcop.net">Tim Vernum</a>
* @author Davanum Srinivas
*/
1.9 +226 -87 xml-axis/java/tools/org/apache/axis/tools/ant/wsdl/Java2WsdlAntTask.java
Index: Java2WsdlAntTask.java
===================================================================
RCS file: /home/cvs/xml-axis/java/tools/org/apache/axis/tools/ant/wsdl/Java2WsdlAntTask.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Java2WsdlAntTask.java 18 Oct 2002 20:54:28 -0000 1.8
+++ Java2WsdlAntTask.java 25 Oct 2002 06:24:36 -0000 1.9
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -64,13 +64,27 @@
import java.util.HashMap;
import java.io.StringWriter;
import java.io.PrintWriter;
+import java.io.File;
+/*
+ * Important. we autogenerate the ant task docs from this.
+ * after adding a new attribute
+ * 1. add the javadoc for the end users. Make it meaningful
+ * 2. get jakarta_ant/proposals/xdocs from ant CVS
+ * 3. run the xdocs target in tools/build.xml
+ * this creates xml files in xdocs/build
+ * 4. run proposals/xdocs/dvsl build.xml to create the html files
+ * these are also created under xdocs/build
+ * 5. copy the the html files to docs/ant
+ * 4. check in the changes in docs/ant
+ */
/**
- * Generates a WSDL description from a Java class.
- *
+ * Generates a WSDL description from a Java class.
* @author Rich Scheuerle (scheu@us.ibm.com)
- * @ant.task category="axis"
+ * @author Steve Loughran
+ * @ant.task category="axis" name="axis-java2wsdl"
*/
+
public class Java2WsdlAntTask extends Task
{
private String namespace = "";
@@ -89,39 +103,71 @@
private boolean useInheritedMethods = false;
private String exclude = null;
private String stopClasses = null;
- private String tm = "1.1";
+ private String typeMappingVersion = TypeMappingVersionEnum.DEFAULT_VERSION;
private String style = null;
+ private String serviceElementName=null;
+ private String methods=null;
private String use = null;
+ private MappingSet mappings=new MappingSet();
private String extraClasses = null;
- // The method executing the task
+ /**
+ * trace out parameters
+ * @param logLevel to log at
+ * @see org.apache.tools.ant.Project#log
+ */
+ public void traceParams(int logLevel) {
+ log("Running Java2WsdlAntTask with parameters:", logLevel);
+ log("\tnamespace:" + namespace, logLevel);
+ log("\tPkgtoNS:" + namespaceMap, logLevel);
+ log("\tlocation:" + location, logLevel);
+ log("\toutput:" + output, logLevel);
+ log("\tinput:" + input, logLevel);
+ log("\tclassName:" + className, logLevel);
+ log("\tservicePortName:" + servicePortName, logLevel);
+ log("\tportTypeName:" + portTypeName, logLevel);
+ log("\tbindingName:" + bindingName, logLevel);
+ log("\timplClass:" + implClass, logLevel);
+ log("\tinheritance:" + useInheritedMethods, logLevel);
+ log("\texcluded:" + exclude, logLevel);
+ log("\tstopClasses:" + stopClasses, logLevel);
+ log("\ttypeMappingVersion:" + typeMappingVersion, logLevel);
+ log("\tstyle:" + style, logLevel);
+ log("\toutputImpl:" + outputImpl, logLevel);
+ log("\tuse:" + use, logLevel);
+ log("\tnamespaceImpl:" + namespaceImpl, logLevel);
+ log("\tlocationImport:" + locationImport, logLevel);
+ log("\tserviceElementName:" + serviceElementName, logLevel);
+ log("\tmethods:" + methods, logLevel);
+ log("\textraClasses:" + extraClasses, logLevel);
+}
+
+ /**
+ * validation code
+ * @throws BuildException if validation failed
+ */
+ protected void validate()
+ throws BuildException {
+ if(className==null || className.length() ==0) {
+ throw new BuildException("No classname was specified");
+ }
+ if(location==null || location.length() == 0) {
+ throw new BuildException("No location was specified");
+ }
+ }
+
+ /**
+ * execute the task
+ * @throws BuildException
+ */
public void execute() throws BuildException {
try {
- log("Running Java2WsdlAntTask with parameters:", Project.MSG_VERBOSE);
- log("\tnamespace:" + namespace, Project.MSG_VERBOSE);
- log("\tPkgtoNS:" + namespaceMap, Project.MSG_VERBOSE);
- log("\tlocation:" + location, Project.MSG_VERBOSE);
- log("\toutput:" + output, Project.MSG_VERBOSE);
- log("\tinput:" + input, Project.MSG_VERBOSE);
- log("\tclassName:" + className, Project.MSG_VERBOSE);
- log("\tservicePortName:" + servicePortName, Project.MSG_VERBOSE);
- log("\tportTypeName:" + portTypeName, Project.MSG_VERBOSE);
- log("\tbindingName:" + bindingName, Project.MSG_VERBOSE);
- log("\timplClass:" + implClass, Project.MSG_VERBOSE);
- log("\tinheritance:" + useInheritedMethods, Project.MSG_VERBOSE);
- log("\texcluded:" + exclude, Project.MSG_VERBOSE);
- log("\tstopClasses:" + stopClasses, Project.MSG_VERBOSE);
- log("\ttypeMappingVersion:" + tm, Project.MSG_VERBOSE);
- log("\tstyle:" + style, Project.MSG_VERBOSE);
- log("\tuse:" + use, Project.MSG_VERBOSE);
- log("\toutputImpl:" + outputImpl, Project.MSG_VERBOSE);
- log("\tnamespaceImpl:" + namespaceImpl, Project.MSG_VERBOSE);
- log("\tlocationImport:" + locationImport, Project.MSG_VERBOSE);
- log("\textraClasses:" + extraClasses, Project.MSG_VERBOSE);
-
+ traceParams(Project.MSG_VERBOSE);
+ validate();
// Instantiate the emitter
Emitter emitter = new Emitter();
-
+ //do the mappings
+ mappings.execute(this,namespaceMap);
if (!namespaceMap.isEmpty()) {
emitter.setNamespaceMap(namespaceMap);
}
@@ -149,7 +195,7 @@
emitter.setExtraClasses(extraClasses);
}
- if (tm.equals("1.1")) {
+ if (typeMappingVersion.equals("1.1")) {
emitter.setDefaultTypeMapping(DefaultTypeMappingImpl.getSingleton());
} else {
emitter.setDefaultTypeMapping(DefaultSOAPEncodingTypeMappingImpl.create());
@@ -170,6 +216,12 @@
emitter.setLocationUrl(location);
emitter.setImportUrl(locationImport);
emitter.setUseInheritedMethods(useInheritedMethods);
+ if(serviceElementName!=null) {
+ emitter.setServiceElementName( serviceElementName);
+ }
+ if(methods!=null) {
+ emitter.setAllowedMethods(methods);
+ }
if (outputImpl == null) {
// Normal case
emitter.emit(output, Emitter.MODE_ALL);
@@ -177,7 +229,13 @@
// Emit interface and implementation wsdls
emitter.emit(output, outputImpl);
}
+
+
+ } catch(BuildException b) {
+ //pass build exceptions up the wire
+ throw b;
} catch (Throwable t) {
+ //other trouble: stack trace the trouble and throw an exception
StringWriter writer = new StringWriter();
t.printStackTrace(new PrintWriter(writer));
log(writer.getBuffer().toString(), Project.MSG_ERR);
@@ -185,132 +243,213 @@
}
}
- // The setter for the "output" attribute
- public void setOutput(String parameter) {
- this.output = parameter;
+ /**
+ * The name of the output WSDL file.
+ * If not specified, a suitable default WSDL file is written into
+ * the current directory.
+ * @param parameter
+ */
+ public void setOutput(File parameter) {
+ this.output = parameter.getPath();
}
- // The setter for the "input" attribute
- public void setInput(String parameter) {
- this.input = parameter;
+ /**
+ * Optional attribute that indicates the name of the input wsdl file.
+ * The output wsdl file will contain everything from the input wsdl
+ * file plus the new constructs. If a new construct is already present
+ * in the input wsdl file, it is not added. This option is useful for
+ * constructing a wsdl file with multiple ports, bindings, or portTypes.
+ * @param parameter filename
+ */
+ public void setInput(File parameter) {
+ this.input = parameter.getPath();
}
- // The setter for the "outputImpl" attribute
- public void setOutputImpl(String parameter) {
- this.outputImpl = parameter;
+ /**
+ * Use this option to indicate the name of the output implementation WSDL
+ * file. If specified, Java2WSDL will produce separate interface and implementation
+ * WSDL files. If not, a single WSDL file is generated
+ * @param parameter
+ */
+ public void setOutputImpl(File parameter) {
+ this.outputImpl = parameter.getPath();
}
- // The setter for the "location" attribute
+ /**
+ * The url of the location of the service. The name after the last slash or
+ * backslash is the name of the service port (unless overridden by the -s
+ * option). The service port address location attribute is assigned the
+ * specified value.
+ * @param parameter a URL
+ */
public void setLocation(String parameter) {
this.location = parameter;
}
- // The setter for the "locationImport" attribute
+ /**
+ * the location of the interface WSDL when generating an implementation WSDL
+ * Required when <tt>outputImpl</tt> is set
+ * @param parameter URL?
+ */
public void setLocationImport(String parameter) {
this.locationImport = parameter;
}
- // The setter for the "className" attribute
+ /**
+ * the class name to import, eg. org.example.Foo. Required.
+ * The class must be on the classpath.
+ * @param parameter fully qualified class name
+ */
public void setClassName(String parameter) {
this.className = parameter;
}
- // The setter for the "implClass" attribute
+ /**
+ * Sometimes extra information is available in the implementation class
+ * file. Use this option to specify the implementation class.
+ * @param parameter
+ */
public void setImplClass(String parameter) {
this.implClass = parameter;
}
- // The setter for the "servicePortName" attribute
+ /**
+ * service port name (obtained from location if not specified)
+ * @param parameter portname
+ */
public void setServicePortName(String parameter) {
this.servicePortName = parameter;
}
- // The setter for the "portTypeName" attribute
+ /**
+ * Indicates the name to use use for the portType element.
+ * If not specified, the class-of-portType name is used.
+ * @param parameter
+ */
public void setPortTypeName(String parameter) {
this.portTypeName = parameter;
}
- // The setter for the "bindingName" attribute
+ /**
+ * The name to use use for the binding element.
+ * If not specified, the value of the
+ * <tt>servicePortName</tt> + "SoapBinding" is used.
+ * @param parameter
+ */
public void setBindingName(String parameter) {
this.bindingName = parameter;
}
- // The setter for the "namespace" attribute
+ /**
+ * the target namespace. Required.
+ * @param parameter
+ */
public void setNamespace(String parameter) {
this.namespace = parameter;
}
- // The setter for the "namespaceImpl" attribute
+ /**
+ * Namespace of the implementation WSDL.
+ * @param parameter
+ */
public void setNamespaceImpl(String parameter) {
this.namespaceImpl = parameter;
}
- // The setter for the "useInheritedMethods" attribute
+ /**
+ * should inherited methods be exported too? Default=false
+ * @param parameter
+ */
public void setUseInheritedMethods(boolean parameter) {
this.useInheritedMethods = parameter;
}
- // The setter for the "exclude" attribute
+ /**
+ * Comma separated list of methods to exclude from the wsdl file.
+ * @param exclude
+ */
public void setExclude(String exclude) {
this.exclude = exclude;
}
- // The setter for the "stopClasses" attribute
+ /**
+ * Comma separated list of classes which stop the Java2WSDL
+ * inheritance search.
+ * @param stopClasses
+ */
public void setStopClasses(String stopClasses) {
this.stopClasses = stopClasses;
}
- // The setter for the "style" attribute
+ /**
+ * The style of the WSDL document: RPC, DOCUMENT or WRAPPED.
+ * If RPC, a rpc/encoded wsdl is generated. If DOCUMENT, a
+ * document/literal wsdl is generated. If WRAPPED, a
+ * document/literal wsdl is generated using the wrapped approach.
+ * @param style
+ */
public void setStyle(String style) {
this.style = style;
}
- // The setter for the "use" attribute
- public void setUse(String use) {
- this.use = use;
+ /**
+ * add a mapping of namespaces to packages
+ */
+ public void addMapping(NamespaceMapping mapping) {
+ mappings.addMapping(mapping);
}
- /** the command arguments */
- public Mapping createMapping() {
- Mapping pkg = new Mapping();
- return pkg;
+ /**
+ * add a mapping of namespaces to packages
+ */
+ public void addMappingSet(MappingSet mappingset) {
+ mappings.addMappingSet(mappingset);
}
- // The setter for the "typeMappingVersion" attribute
- public void setTypeMappingVersion(String parameter) {
- this.tm = parameter;
- }
- // The setter for the "extraClasses" attribute
- public void setExtraClasses(String extraClasses) {
- this.extraClasses = extraClasses;
+ /**
+ * the default type mapping registry to use. Either 1.1 or 1.2.
+ * Default is 1.1
+ * @param parameter new version
+ */
+ public void setTypeMappingVersion(TypeMappingVersionEnum parameter) {
+ this.typeMappingVersion = parameter.getValue();
}
/**
- * Used for nested package definitions.
+ * If this option is specified, only the indicated methods in your
+ * interface class will be exported into the WSDL file. The methods list
+ * must be comma separated. If not specified, all methods declared in
+ * the interface class will be exported into the WSDL file
+ * @param methods list of methods
*/
- public class Mapping {
- private String namespace = null;
- private String packageName = null;
-
- public void setNamespace(String value) {
- namespace = value;
- if(namespace != null && packageName != null) {
- namespaceMap.put(packageName,namespace);
- namespace = null;
- packageName = null;
- }
- }
+ public void setMethods(String methods) {
+ this.methods = methods;
+ }
+
+ /**
+ * Set the use option
+ */
+ public void setUse(String use) {
+ this.use = use;
+ }
+
+ /**
+ * the name of the service element.
+ * If not specified, the service element is the <tt>portTypeName</tt>Service.
+ * @param serviceElementName
+ */
+ public void setServiceElementName(String serviceElementName) {
+ this.serviceElementName = serviceElementName;
+ }
- public void setPackage(String value) {
- packageName = value;
- if(namespace != null && packageName != null) {
- namespaceMap.put(packageName,namespace);
- namespace = null;
- packageName = null;
- }
- }
+ /**
+ * The setter for the "extraClasses" attribute
+ */
+ public void setExtraClasses(String extraClasses) {
+ this.extraClasses = extraClasses;
}
+
}
1.5 +108 -61 xml-axis/java/tools/org/apache/axis/tools/ant/wsdl/Wsdl2javaAntTask.java
Index: Wsdl2javaAntTask.java
===================================================================
RCS file: /home/cvs/xml-axis/java/tools/org/apache/axis/tools/ant/wsdl/Wsdl2javaAntTask.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Wsdl2javaAntTask.java 11 Oct 2002 17:23:59 -0000 1.4
+++ Wsdl2javaAntTask.java 25 Oct 2002 06:24:37 -0000 1.5
@@ -60,23 +60,52 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.EnumeratedAttribute;
import java.io.File;
import java.io.IOException;
import java.net.Authenticator;
import java.util.HashMap;
+/*
+ * IMPORTANT: see Java2WsdlAntTask on how to javadoc this task and rebuild
+ * the task documentation afterwards
+ *
+ */
+
/**
- * Ant task for running Wsdl2java utility. It is still not ready for
- * end users, though that is the final intent.
- * This task does no dependency checking; files are generated whether they
- * need to be or not.
- * As well as the nested parameters, this task uses the file
+ * Create Java classes from local or remote WSDL.
+ * Mappings from namespaces to packages can be provided as nested <mapping>
+ * elements.
+ * <p>
+ * Proxy settings are taken from the java runtime settings of http.ProxyHost,
+ * http.ProxyPort, etc. The Ant task <setProxy> can set these.
+ * As well as the nested mapping elements, this task uses the file
* <tt>NStoPkg.properties</tt> in the project base directory
* for namespace mapping
- * @ant.task category="axis"
- * @author steve loughran
+ * <p>
+ * This task does no dependency checking; files are generated whether they
+ * need to be or not. The exception to this is the Impl class, which is
+ * not overwritten if it exists. This is a safety measure. However, all other
+ * classes are generated overwriting anything that exists.
+ * <p>
+ * The safe way to use this task is to have it generate the java source in
+ * a build directory, then have a <copy> task selectively copy the
+ * files you need into a safe location. Again, copying into the source tree
+ * is dangerous, but a separate build/src tree is safe. Then include this
+ * separate tree in the <javac> task's src attribute to include it in the
+ * build. Implement your own implementation classes of the server stub and the
+ * test cases using the generated templates.
+ * If you want to add methods to autogenerated data types, consider subclassing
+ * them, or write helper classes.
+ * <p>
+ * Tip: if you <get> the wsdl, and use the <filesmatch> condition
+ * to compare the fetched wsdl with a catched copy, you can make the target that
+ * calls the axis-wsd2ljava task conditional on the WSDL having changed. This stops
+ * spurious code regeneration and follow-on rebuilds across the java source tree.
+ * @ant.task category="axis" name="axis-wsdl2java"
* @author Davanum Srinivas (dims@yahoo.com)
+ * @author steve loughran
*/
public class Wsdl2javaAntTask extends Task
{
@@ -93,9 +122,11 @@
private String output = "." ;
private String deployScope = "";
private String url = "";
- private String tm = "1.1";
+ private String typeMappingVersion = TypeMappingVersionEnum.DEFAULT_VERSION;
private long timeout = 45000;
-
+ private File namespaceMappingFile=null;
+ private MappingSet mappings = new MappingSet();
+
/**
* do we print a stack trace when something goes wrong?
*/
@@ -104,7 +135,10 @@
* what action to take when there was a failure and the source was some
* URL
*/
- private boolean failOnNetworkErrors=false;
+ private boolean failOnNetworkErrors=false;
+
+ public Wsdl2javaAntTask() {
+ }
/**
* validation code
@@ -127,7 +161,7 @@
/**
* trace out parameters
- * @param level to log at
+ * @param logLevel to log at
* @see org.apache.tools.ant.Project#log
*/
public void traceParams(int logLevel) {
@@ -145,32 +179,42 @@
log("\tdeployScope:" + deployScope, logLevel);
log("\tURL:" + url, logLevel);
log("\tall:" + all, logLevel);
- log("\ttypeMappingVersion:" + tm, logLevel);
+ log("\ttypeMappingVersion:" + typeMappingVersion, logLevel);
log("\ttimeout:" + timeout, logLevel);
log("\tfailOnNetworkErrors:" + failOnNetworkErrors, logLevel);
log("\tprintStackTraceOnFailure:" + printStackTraceOnFailure, logLevel);
- }
+ log("\tnamespaceMappingFile"+namespaceMappingFile, logLevel);
+ }
/**
* The method executing the task
* @throws BuildException if validation or execution failed
*/
public void execute() throws BuildException {
+ //before we get any further, if the user didnt spec a namespace mapping
+ //file, we load in the default
+ if(namespaceMappingFile==null) {
+ namespaceMappingFile = getProject().resolveFile("NStoPkg.properties");
+ }
traceParams(Project.MSG_VERBOSE);
validate();
try {
// Instantiate the emitter
Emitter emitter = new Emitter();
+ //extract the scope
Scope scope = Scope.getScope(deployScope, null);
if (scope != null) {
emitter.setScope(scope);
- } else if ("none".equalsIgnoreCase(deployScope)) {
+ } else if (deployScope.length()==0
+ || "none".equalsIgnoreCase(deployScope)) {
/* leave default (null, or not-explicit) */;
} else {
log("Unrecognized scope: " + deployScope + ". Ignoring it.", Project.MSG_VERBOSE);
}
+ //do the mappings
+ mappings.execute(this, namespaceMap);
if (!namespaceMap.isEmpty()) {
emitter.setNamespaceMap(namespaceMap);
}
@@ -186,9 +230,8 @@
emitter.setSkeletonWanted(skeletonDeploy);
emitter.setVerbose(verbose);
emitter.setDebug(debug);
- emitter.setTypeMappingVersion(tm);
- //TODO: extract this and make it an attribute
- emitter.setNStoPkg(project.resolveFile("NStoPkg.properties"));
+ emitter.setTypeMappingVersion(typeMappingVersion);
+ emitter.setNStoPkg(namespaceMappingFile);
emitter.setTimeout(timeout);
Authenticator.setDefault(new DefaultAuthenticator(null,null));
@@ -215,6 +258,8 @@
}
}
} catch (BuildException b) {
+ //we rethrow this immediately; but need to catch it to stop it being
+ //mistaken for a throwable.
throw b;
} catch (Throwable t) {
if(printStackTraceOnFailure) {
@@ -306,10 +351,15 @@
* add scope to deploy.xml: "Application", "Request", "Session"
* optional;
*/
- public void setDeployScope(String parameter) {
- this.deployScope = parameter;
+ public void setDeployScope(String scope) {
+ this.deployScope = scope;
}
-
+/*
+ //unused till we can somehow get ant to be case insensitive when handling enums
+ public void setDeployScope(DeployScopeEnum scope) {
+ this.deployScope = scope.getValue();
+ }
+*/
/**
* URL to fetch and generate WSDL for.
* Can be remote or a local file.
@@ -327,61 +377,58 @@
}
/**
- * Set the type mapping version; default is "1.2"
+ * the default type mapping registry to use. Either 1.1 or 1.2.
+ * Default is 1.1
+ * @param parameter new version
*/
- public void setTypeMappingVersion(String parameter) {
- this.tm = parameter;
+ public void setTypeMappingVersion(TypeMappingVersionEnum parameter) {
+ this.typeMappingVersion = parameter.getValue();
}
/**
- * timeout in seconds for URL retrieval; default is 45 seconds.
+ * timeout in milliseconds for URL retrieval; default is 45 seconds.
* Set this to -1 to disable timeouts altogether: other negative values
* are not allowed)
- * TODO: normally format conversions are failures, but because this method
- * ignored such errors, we have to keep going. Maybe it could be escalated to
- * a failure in end-user versions.
*/
- public void setTimeout(String parameter) {
- try {
- this.timeout = new Long(parameter).longValue();
- } catch (NumberFormatException e) {
- // Sorry, stick with default.
- log("Could not convert "+parameter+" to a number", Project.MSG_WARN);
- }
+ public void setTimeout(long parameter) {
+ this.timeout = parameter;
}
- /** the command arguments */
- public Mapping createMapping() {
- Mapping pkg = new Mapping();
- return pkg;
+ /**
+ * add a mapping of namespaces to packages
+ */
+ public void addMapping(NamespaceMapping mapping) {
+ mappings.addMapping(mapping);
}
/**
- * Used for nested package definitions.
- */
- public class Mapping {
- private String namespace;
- private String packageName;
-
- /**
- * namespace to map to a package
- */
- public void setNamespace(String value) {
- namespace = value;
- if(namespace != null && packageName != null)
- namespaceMap.put(namespace, packageName);
- }
-
- /**
- * java package to generate for the namespace's classes
- */
- public void setPackage(String value) {
- packageName = value;
- if(namespace != null && packageName != null)
- namespaceMap.put(namespace, packageName);
- }
+ * add a mapping of namespaces to packages
+ */
+ public void addMappingSet(MappingSet mappingset) {
+ mappings.addMappingSet(mappingset);
}
+ /**
+ * set the mapping file. This is a properties file of
+ * package=namespace order. Optional, default is to look for
+ * a file called NStoPkg.properties in the project directory.
+ * @param namespaceMappingFile
+ */
+ public void setNamespaceMappingFile(File namespaceMappingFile) {
+ this.namespaceMappingFile = namespaceMappingFile;
+ }
+
+ /**
+ * valid deploy scopes for the task
+ */
+ /*
+ public static class DeployScopeEnum extends EnumeratedAttribute {
+ public String[] getValues() {
+ return new String[]{"Application", "Request", "Session","none"};
+ }
+
+ }
+ */
}
1.1 xml-axis/java/tools/org/apache/axis/tools/ant/wsdl/Mapper.java
Index: Mapper.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 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 acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", 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 apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 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 org.apache.axis.tools.ant.wsdl;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectComponent;
import java.util.HashMap;
/**
* interface that namespace mappers are expected to implement
*/
public interface Mapper {
/**
* execute the mapping
* @param owner owner object
* @param map map to map to
* @throws BuildException in case of emergency
*/
void execute(ProjectComponent owner, HashMap map) throws BuildException;
}
1.1 xml-axis/java/tools/org/apache/axis/tools/ant/wsdl/MappingSet.java
Index: MappingSet.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 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 acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", 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 apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 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 org.apache.axis.tools.ant.wsdl;
import org.apache.tools.ant.ProjectComponent;
import java.util.List;
import java.util.LinkedList;
import java.util.HashMap;
import java.util.Iterator;
/**
*a mappingset is a set of mappings
*/
public class MappingSet implements Mapper {
List mappings=new LinkedList();
/**
* add a new mapping
* @param mapping
*/
public void addMapping(NamespaceMapping mapping) {
mappings.add(mapping);
}
/**
* add a mappingset inside this one
* @param mappingset
*/
public void addMappingSet(MappingSet mappingset) {
mappings.add(mappingset);
}
/**
* execute by mapping everything iteratively and recursively
* @param owner
* @param map
*/
public void execute(ProjectComponent owner, HashMap map) {
Iterator it=mappings.iterator();
while (it.hasNext()) {
Mapper mapper = (Mapper) it.next();
mapper.execute(owner,map);
}
}
}
1.1 xml-axis/java/tools/org/apache/axis/tools/ant/wsdl/NamespaceMapping.java
Index: NamespaceMapping.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 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 acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", 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 apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 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 org.apache.axis.tools.ant.wsdl;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.Project;
import java.util.HashMap;
import java.util.Properties;
import java.util.Enumeration;
import java.io.File;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
/**
* Used for nested package definitions.
*/
public class NamespaceMapping implements Mapper {
private String namespace = null;
private String packageName = null;
private File mappingFile;
/**
* pass in the namespace to map to
*/
public NamespaceMapping() {
}
/**
* the namespace in the WSDL. Required.
* @param value new uri of the mapping
*/
public void setNamespace(String value) {
namespace = value;
}
/**
* the Java package to bind to. Required.
* @param value java package name
*/
public void setPackage(String value) {
packageName = value;
}
/**
* name of a property file that contains mappings in
* package=namespace format
* @param file
*/
public void setFile(File file) {
mappingFile = file;
}
/**
* map a namespace to a package
* @param owner owning project component (For logging)
* @param map map to assign to
* @param packName package name
* @param nspace namespace
*/
protected void map(ProjectComponent owner,
HashMap map,
String packName,
String nspace) {
owner.log("mapping "+nspace+" to "+packName, Project.MSG_VERBOSE);
map.put(packName, nspace);
}
/**
* validate the option set
*/
private void validate() {
if (mappingFile != null) {
if (namespace != null || packageName != null) {
throw new BuildException(
"Namespace or Package cannot be used with a File attribute");
}
} else {
if (namespace == null) {
throw new BuildException("namespace must be defined");
}
if (packageName == null) {
throw new BuildException("package must be defined");
}
}
}
/**
* Load a mapping file and save it to the map
* @param owner owner component
* @param map target map file
* @throws BuildException if an IOException needed swallowing
*/
protected void mapFile(ProjectComponent owner, HashMap map) throws BuildException {
Properties props = loadMappingPropertiesFile();
Enumeration keys = props.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
String uri = props.getProperty(key);
map(owner, map, key, uri);
}
}
/**
* load a file containing properties
* @return a properties file with zero or more mappings
* @throws BuildException if the load failed
*/
private Properties loadMappingPropertiesFile() throws BuildException {
Properties props = new Properties();
FileInputStream instr = null;
try {
instr = new FileInputStream(mappingFile);
props.load(new BufferedInputStream(instr));
} catch (IOException e) {
throw new BuildException("Failed to load " + mappingFile, e);
} finally {
if (instr != null) {
try {
instr.close();
} catch (IOException e) {
}
}
}
return props;
}
/**
* execute the mapping
* @param owner owner object
* @param map map to map to
* @throws BuildException in case of emergency
*/
public void execute(ProjectComponent owner, HashMap map) throws BuildException {
validate();
if (mappingFile != null) {
mapFile(owner, map);
} else {
map(owner, map, packageName, namespace);
}
}
}
1.1 xml-axis/java/tools/org/apache/axis/tools/ant/wsdl/TypeMappingVersionEnum.java
Index: TypeMappingVersionEnum.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 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 acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", 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 apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 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 org.apache.axis.tools.ant.wsdl;
import org.apache.tools.ant.types.EnumeratedAttribute;
/**
* valid typemappings for the Ant tasks
*/
public class TypeMappingVersionEnum extends EnumeratedAttribute {
public String[] getValues() {
return new String[]{"1.1", "1.2"};
}
/**
* default mapping version is 1.1
*/
public static final String DEFAULT_VERSION="1.1";
}