📄 wsdltodotnet.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */package org.apache.tools.ant.taskdefs.optional.dotnet;import java.io.File;import java.util.Vector;import java.util.Iterator;import java.net.MalformedURLException;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 org.apache.tools.ant.taskdefs.condition.Os;import org.apache.tools.ant.util.FileUtils;/** * Converts a WSDL file or URL resource into a .NET language. * * Why add a wrapper to the MS WSDL tool? * So that you can verify that your web services, be they written with Axis or *anyone else's SOAP toolkit, work with .NET clients. * *This task is dependency aware when using a file as a source and destination; *so if you <get> the file (with <code>usetimestamp="true"</code>) then *you only rebuild stuff when the WSDL file is changed. Of course, *if the server generates a new timestamp every time you ask for the WSDL, *this is not enough...use the <filesmatch> <condition> to *to byte for byte comparison against a cached WSDL file then make *the target conditional on that test failing. * See "Creating an XML Web Service Proxy", "wsdl.exe" docs in * the framework SDK documentation * @version 0.5 * @ant.task category="dotnet" * @since Ant 1.5 */public class WsdlToDotnet extends Task { /** * used for timestamp checking */ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); /** * name of output file (required) */ private File destFile = null; /** * language; defaults to C# */ private String language = "CS"; /** * flag set to true to generate server side skeleton */ private boolean server = false; /** * namespace */ private String namespace = null; /** * flag to control action on execution trouble */ private boolean failOnError = true; // CheckStyle:VisibilityModifier OFF - bc /** * any extra command options? */ protected String extraOptions = null; // CheckStyle:VisibilityModifier ON /** * protocol string. Exact value set depends on SOAP stack version. * @since Ant 1.7 */ private String protocol = null; /** * should errors come in an IDE format. This * is WSE only. * @since Ant 1.7 */ private boolean ideErrors = false; /** * filesets of file to compile * @since Ant 1.7 */ private Vector schemas = new Vector(); /** * our WSDL file. * @since ant1.7 */ private Schema wsdl = new Schema(); /** * compiler * @since ant1.7 */ private Compiler compiler = null; /** * error message: dest file is a directory */ public static final String ERROR_DEST_FILE_IS_DIR = "destination file is a directory"; /** * error message: no dest file */ public static final String ERROR_NO_DEST_FILE = "destination file must be specified"; /** * Name of the file to generate. Required * @param destFile filename */ public void setDestFile(File destFile) { this.destFile = destFile; } /** * Sets the URL to fetch. Fetching is by wsdl.exe; Ant proxy settings * are ignored; either url or srcFile is required. * @param url url to save */ public void setUrl(String url) { wsdl.setUrl(url); } /** * The local WSDL file to parse; either url or srcFile is required. * @param srcFile WSDL file */ public void setSrcFile(File srcFile) { wsdl.setFile(srcFile); } /** * set the language; one of "CS", "JS", or "VB" * optional, default is CS for C# source * @param language language to generate */ public void setLanguage(String language) { this.language = language; } /** * flag to enable server side code generation; * optional, default=false * @param server server-side flag */ public void setServer(boolean server) { this.server = server; } /** * namespace to place the source in. * optional; default "" * @param namespace new namespace */ public void setNamespace(String namespace) { this.namespace = namespace; } /** * Whether or not a failure should halt the build. * Optional - default is <code>true</code>. * @param failOnError new failure option */ public void setFailOnError(boolean failOnError) { this.failOnError = failOnError; } /** * Any extra WSDL.EXE options which aren't explicitly * supported by the ant wrapper task; optional * *@param extraOptions The new ExtraOptions value */ public void setExtraOptions(String extraOptions) { this.extraOptions = extraOptions; } /** * Defines wether errors are machine parseable. * Optional, default=true * * @since Ant 1.7 * @param ideErrors a <code>boolean</code> value. */ public void setIdeErrors(boolean ideErrors) { this.ideErrors = ideErrors; } /** * what protocol to use. SOAP, SOAP1.2, HttpPost and HttpGet * are the base options. Different version and implementations may. * offer different options. * @since Ant 1.7 * * @param protocol the protocol to use. */ public void setProtocol(String protocol) { this.protocol = protocol; } /** * add a new source schema to the compilation * @since Ant 1.7 * * @param source a nested schema element. */ public void addSchema(Schema source) { schemas.add(source); } /** * flag to trigger turning a filename into a file:url * ignored for the mono compiler. * @param b a <code>boolean</code> value. */ public void setMakeURL(boolean b) { wsdl.setMakeURL(b); } /** * identify the compiler * @since Ant 1.7 * @param compiler the enumerated value. */ public void setCompiler(Compiler compiler) { this.compiler = compiler; } /** * validation code * @throws BuildException if validation failed */ protected void validate() throws BuildException { if (destFile == null) { throw new BuildException(ERROR_NO_DEST_FILE); } if (destFile.isDirectory()) { throw new BuildException( ERROR_DEST_FILE_IS_DIR); } wsdl.validate(); } /** * do the work by building the command line and then calling it * *@throws BuildException if validation or execution failed */ public void execute() throws BuildException { log("This task is deprecated and will be removed in a future version\n" + "of Ant. It is now part of the .NET Antlib:\n" + "http://ant.apache.org/antlibs/dotnet/index.html", Project.MSG_WARN); if (compiler == null) { compiler = Compiler.createDefaultCompiler(); } validate(); NetCommand command = new NetCommand(this, "WSDL", compiler.getCommand()); command.setFailOnError(failOnError); //fill in args compiler.applyExtraArgs(command); command.addArgument("/nologo");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -