Methods Summary |
---|
public void | addMapping(NamespaceMapping mapping)add a mapping of namespaces to packages
mappings.addMapping(mapping);
|
public void | addMappingSet(MappingSet mappingset)add a mapping of namespaces to packages
mappings.addMappingSet(mappingset);
|
public void | addSysproperty(Environment.Variable sysp)Adds a system property that tests can access.
commandline.addSysproperty(sysp);
|
public org.apache.tools.ant.types.Path | createClasspath()set the classpath
if (classpath == null) {
classpath = new Path(getProject());
}
return classpath.createPath();
|
protected org.apache.axis.wsdl.toJava.Emitter | createEmitter()This factory method makes it easier to extend this Ant task
with a custom Emitter, if necessary.
return new Emitter();
|
public org.apache.axis.wsdl.toJava.NamespaceSelector | createNsExclude()Adds an additional namespace to the list to be excluded
from source code generation.
NamespaceSelector selector = new NamespaceSelector();
nsExcludes.add(selector);
return selector;
|
public org.apache.axis.wsdl.toJava.NamespaceSelector | createNsInclude()Adds an additional namespace to the list to be included
in source code generation.
NamespaceSelector selector = new NamespaceSelector();
nsIncludes.add(selector);
return selector;
|
public org.apache.axis.wsdl.toJava.FactoryProperty | createProperty()Adds a property name/value pair for specialized
JavaGeneratorFactories.
FactoryProperty property = new FactoryProperty();
properties.add(property);
return property;
|
protected org.apache.axis.wsdl.toJava.NamespaceSelector | createSelector()
return new NamespaceSelector();
|
public void | execute()The method executing the task
//before we get any further, if the user didnt spec a namespace mapping
//file, we load in the default
traceParams(Project.MSG_VERBOSE);
validate();
CommandlineJava.SysProperties sysProperties =
commandline.getSystemProperties();
if (sysProperties != null) {
sysProperties.setSystem();
}
try {
// Instantiate the emitter
Emitter emitter = createEmitter();
//extract the scope
Scope scope = Scope.getScope(deployScope, null);
if (scope != null) {
emitter.setScope(scope);
} 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, with namespaces mapped as the key
mappings.execute(this, namespaceMap, false);
if (!namespaceMap.isEmpty()) {
emitter.setNamespaceMap(namespaceMap);
}
emitter.setTestCaseWanted(testCase);
emitter.setHelperWanted(helperGen);
if (factory != null) {
emitter.setFactory(factory);
}
emitter.setNamespaceIncludes(nsIncludes);
emitter.setNamespaceExcludes(nsExcludes);
emitter.setProperties(properties);
emitter.setImports(!noImports);
emitter.setAllWanted(all);
emitter.setOutputDir(output);
emitter.setServerSide(server);
emitter.setSkeletonWanted(skeletonDeploy);
emitter.setVerbose(verbose);
emitter.setDebug(debug);
emitter.setQuiet(quiet);
emitter.setTypeMappingVersion(typeMappingVersion);
emitter.setNowrap(noWrapped);
emitter.setAllowInvalidURL(allowInvalidURL);
emitter.setWrapArrays(wrapArrays);
if (namespaceMappingFile != null) {
emitter.setNStoPkg(namespaceMappingFile.toString());
}
emitter.setTimeout(timeout);
emitter.setImplementationClassName(implementationClassName);
Authenticator.setDefault(new DefaultAuthenticator(username, password));
if (classpath != null) {
AntClassLoader cl = new AntClassLoader(
getClass().getClassLoader(),
getProject(),
classpath,
false);
log("Using CLASSPATH " + cl.getClasspath(),
Project.MSG_VERBOSE);
ClassUtils.setDefaultClassLoader(cl);
}
try {
if(url.indexOf(':") == -1)
url = getProject().resolveFile(url).getAbsolutePath();
} catch (Throwable t){
}
log("WSDL2Java " + url, Project.MSG_INFO);
try {
emitter.run(url);
} catch (Throwable e) {
if (url.startsWith("http://")) {
// What we have is either a network error or invalid XML -
// the latter most likely an HTML error page. This makes
// it impossible to continue with the test, so we stop here
if (!failOnNetworkErrors) {
// test mode, issue a warning, and return without
//reporting a fatal error.
log(e.toString(), Project.MSG_WARN);
return;
} else {
//in 'consumer' mode, bail out with the URL
throw new BuildException("Could not build " + url, e);
}
} else {
throw e;
}
}
} 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) {
traceParams(Project.MSG_INFO);
t.printStackTrace();
}
//now throw an exception that includes the error text of the caught exception.
throw new BuildException("WSDL processing error for "
+ url +" :\n "+t.getMessage() , t);
} finally {
if (sysProperties != null) {
sysProperties.restoreSystem();
}
}
|
public void | setAll(boolean parameter)flag to generate code for all elements, even unreferenced ones
default=false;
this.all = parameter;
|
public void | setAllowInvalidUrl(boolean b)Set the allowInvalidURL flag.
this.allowInvalidURL = b;
|
public void | setDebug(boolean debug)flag for debug output; default=false
this.debug = debug;
|
public void | setDeployScope(java.lang.String scope)add scope to deploy.xml: "Application", "Request", "Session"
optional;
this.deployScope = scope;
|
public void | setFactory(java.lang.String parameter)name of the Java2WSDLFactory class for
extending WSDL generation functions
this.factory = parameter;
|
public void | setFailOnNetworkErrors(boolean failOnNetworkErrors)should the task fail the build if there is a network error?
optional: defaults to false
this.failOnNetworkErrors = failOnNetworkErrors;
|
public void | setHelperGen(boolean parameter)Turn on/off Helper class generation;
default is false
this.helperGen = parameter;
|
public void | setImplementationClassName(java.lang.String implementationClassName)Set the name of the class implementing the web service.
This is especially useful when exporting a java class
as a web service using Java2WSDL followed by WSDL2Java.
this.implementationClassName = implementationClassName;
|
public void | setNamespaceMappingFile(java.io.File namespaceMappingFile)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.
this.namespaceMappingFile = namespaceMappingFile;
|
public void | setNoImports(boolean parameter)only generate code for the immediate WSDL document,
and not imports; default=false;
this.noImports = parameter;
|
public void | setNoWrapped(boolean noWrapped)Set the noWrapped flag.
this.noWrapped = noWrapped;
|
public void | setOutput(java.io.File parameter)output directory for emitted files
try {
this.output = parameter.getCanonicalPath();
} catch (IOException ioe) {
throw new BuildException(ioe);
}
|
public void | setPassword(java.lang.String password)set any password required for BASIC authenticated access to the WSDL;
optional; only used if username is set
this.password = password;
|
public void | setPrintStackTraceOnFailure(boolean printStackTraceOnFailure)should we print a stack trace on failure?
Optional, default=true.
this.printStackTraceOnFailure = printStackTraceOnFailure;
|
public void | setProtocolHandlerPkgs(java.lang.String handlerPkgs)append any protocol handler pkgs specified with the task
String currentPkgs = System.getProperty("java.protocol.handler.pkgs");
String newPkgs = null;
if (currentPkgs == null)
newPkgs = handlerPkgs;
else
// append to the existing list
newPkgs = currentPkgs + "|" + handlerPkgs;
System.setProperty("java.protocol.handler.pkgs", newPkgs);
|
public void | setQuiet(boolean quiet)flag for quiet output; default=false
this.quiet = quiet;
|
public void | setServerSide(boolean parameter)emit server-side bindings for web service; default=false
this.server = parameter;
|
public void | setSkeletonDeploy(boolean parameter)deploy skeleton (true) or implementation (false) in deploy.wsdd.
Default is false. Assumes server-side="true".
this.skeletonDeploy = parameter;
|
public void | setTestCase(boolean parameter)flag for automatic Junit testcase generation
default is false
this.testCase = parameter;
|
public void | setTimeout(long parameter)timeout in milliseconds for URL retrieval; default is 45 seconds.
Set this to -1 to disable timeouts altogether: other negative values
are not allowed)
this.timeout = parameter;
|
public void | setTypeMappingVersion(TypeMappingVersionEnum parameter)the default type mapping registry to use. Either 1.1 or 1.2.
Default is 1.1
this.typeMappingVersion = parameter.getValue();
|
public void | setURL(java.lang.String parameter)URL to fetch and generate WSDL for.
Can be remote or a local file.
this.url = parameter;
|
public void | setUsername(java.lang.String username)set any username required for BASIC authenticated access to the WSDL;
optional.
this.username = username;
|
public void | setVerbose(boolean verbose)flag for verbose output; default=false
this.verbose = verbose;
|
public void | setWrapArrays(boolean wrapArrays)Set the wrap arrays flag - if true this will make new classes
like "ArrayOfString" for literal "wrapped" arrays. Otherwise it
will use "String []" and generate appropriate metadata.
this.wrapArrays = wrapArrays;
|
private void | traceNetworkSettings(int logLevel)
traceSystemSetting("http.proxyHost", logLevel);
traceSystemSetting("http.proxyPort", logLevel);
traceSystemSetting("http.proxyUser", logLevel);
traceSystemSetting("http.proxyPassword", logLevel);
traceSystemSetting("socks.proxyHost", logLevel);
traceSystemSetting("socks.proxyPort", logLevel);
|
public void | traceParams(int logLevel)trace out parameters
log("Running Wsdl2javaAntTask with parameters:", logLevel);
log("\tverbose:" + verbose, logLevel);
log("\tdebug:" + debug, logLevel);
log("\tquiet:" + quiet, logLevel);
log("\tserver-side:" + server, logLevel);
log("\tskeletonDeploy:" + skeletonDeploy, logLevel);
log("\thelperGen:" + helperGen, logLevel);
log("\tfactory:" + factory, logLevel);
log("\tnsIncludes:" + nsIncludes, logLevel);
log("\tnsExcludes:" + nsExcludes, logLevel);
log("\tfactoryProps:" + properties, logLevel);
log("\ttestCase:" + testCase, logLevel);
log("\tnoImports:" + noImports, logLevel);
log("\tNStoPkg:" + namespaceMap, logLevel);
log("\toutput:" + output, logLevel);
log("\tprotocolHandlerPkgs:" + protocolHandlerPkgs, logLevel);
log("\tdeployScope:" + deployScope, logLevel);
log("\tURL:" + url, logLevel);
log("\tall:" + all, logLevel);
log("\ttypeMappingVersion:" + typeMappingVersion, logLevel);
log("\ttimeout:" + timeout, logLevel);
log("\tfailOnNetworkErrors:" + failOnNetworkErrors, logLevel);
log("\tprintStackTraceOnFailure:" + printStackTraceOnFailure, logLevel);
log("\tnamespaceMappingFile:" + namespaceMappingFile, logLevel);
log("\tusername:" + username, logLevel);
log("\t:password" + password, logLevel);
log("\t:noWrapped" + noWrapped, logLevel);
log("\t:allowInvalidURL" + allowInvalidURL, logLevel);
log("\t:implementationClassName" + implementationClassName, logLevel);
log("\t:classpath" + classpath, logLevel);
traceNetworkSettings(logLevel);
|
private void | traceSystemSetting(java.lang.String setting, int logLevel)
String value = System.getProperty(setting);
log("\t" + setting + "=" + value, logLevel);
|
protected void | validate()validation code
if (url == null || url.length() == 0) {
throw new BuildException("No url specified");
}
if (timeout < -1) {
throw new BuildException("negative timeout supplied");
}
File outdir = new File(output);
if (!outdir.isDirectory() || !outdir.exists()) {
throw new BuildException("output directory is not valid");
}
if (quiet) {
if (verbose) {
throw new BuildException("quiet and verbose options are " +
"exclusive");
}
if (debug) {
throw new BuildException("quiet and debug options are " +
"exclusive");
}
}
|