001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.util.ant;
016    
017    import java.io.File;
018    
019    import org.apache.axis.tools.ant.wsdl.NamespaceMapping;
020    import org.apache.axis.tools.ant.wsdl.Wsdl2javaAntTask;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class Wsdl2JavaTask {
026    
027            public static void generateJava(String url, String output) {
028                    generateJava(url, output, null);
029            }
030    
031            public static void generateJava(String url, String output, String mapping) {
032                    Wsdl2javaAntTask wsdl2Java = new Wsdl2javaAntTask();
033    
034                    if (mapping != null) {
035                            NamespaceMapping namespaceMapping = new NamespaceMapping();
036    
037                            namespaceMapping.setFile(new File(mapping));
038    
039                            wsdl2Java.addMapping(namespaceMapping);
040                    }
041    
042                    wsdl2Java.setFailOnNetworkErrors(true);
043                    wsdl2Java.setOutput(new File(output));
044                    wsdl2Java.setPrintStackTraceOnFailure(true);
045                    wsdl2Java.setProject(AntUtil.getProject());
046                    wsdl2Java.setServerSide(true);
047                    wsdl2Java.setTestCase(false);
048                    wsdl2Java.setURL(url);
049    
050                    try {
051                            wsdl2Java.execute();
052                    }
053                    catch (Exception e) {
054                            e.printStackTrace();
055                    }
056            }
057    
058    }