001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }