Package org.apache.ws.resource.tool

Source Code of org.apache.ws.resource.tool.Wsdl2JavaTask

/*=============================================================================*
*  Copyright 2004 The Apache Software Foundation
*
*  Licensed 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.ws.resource.tool;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.FileScanner;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Environment;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
* Ant task that wraps {@link Wsdl2Java}.
*
* @author Ian Springer (ian DOT springer AT hp DOT com)
*/
public class Wsdl2JavaTask extends MatchingTask
{

    static
    {
        if ( System.getProperty( "log4j.configuration" ) == null )
        {
            System.setProperty( "log4j.configuration", "log4j.properties" );
        }
    }

    private List m_wsdls = new ArrayList();
    private File m_outputDir;
    private Path m_classpath;
    private Boolean m_verbose;

    public void setOutputDir( File outputDir )
    {
        m_outputDir = outputDir;
    }

    /**
     * Set the classpath to be passed to the XMLBeans schema compiler.
     *
     * @param classpath the classpath to be passed to the XMLBeans schema compiler
     */
    public void setClasspath( Path classpath )
    {
        if ( m_classpath == null )
        {
            m_classpath = classpath;
        }
        else
        {
            m_classpath.append( classpath );
        }
    }

    /**
     * Gets the classpath to be used for this compilation.
     *
     * @return the classpath
     */
    public Path getClasspath()
    {
        return m_classpath;
    }

    /**
     * Adds a reference to a classpath defined elsewhere.
     *
     * @param ref the reference to add
     */
    public void setClasspathRef( Reference ref )
    {
        createClasspath().setRefid( ref );
    }

    /**
     * DOCUMENT_ME
     *
     * @param verbose DOCUMENT_ME
     */
    public void setVerbose( boolean verbose )
    {
        m_verbose = Boolean.valueOf( verbose );
    }

    /**
     * DOCUMENT_ME
     *
     * @param debug DOCUMENT_ME
     *
     * @deprecated
     */
    public void setDebug( boolean debug )
    {
        // this attribute is no longer used
    }

    /**
     * DOCUMENT_ME
     *
     * @param nonProxyHosts DOCUMENT_ME
     */
    public void setNonProxyHosts( String nonProxyHosts )
    {
        nonProxyHosts = nonProxyHosts.trim();
        if ( !nonProxyHosts.startsWith( "${" ) )
        {
            System.setProperty( "http.nonProxyHosts", nonProxyHosts );
        }
    }

    /**
     * DOCUMENT_ME
     *
     * @param proxyHost DOCUMENT_ME
     */
    public void setProxyHost( String proxyHost )
    {
        proxyHost = proxyHost.trim();
        if ( !proxyHost.startsWith( "${" ) )
        {
            System.setProperty( "http.proxyHost", proxyHost );
        }
    }

    /**
     * DOCUMENT_ME
     *
     * @param proxyPort DOCUMENT_ME
     */
    public void setProxyPort( String proxyPort )
    {
        proxyPort = proxyPort.trim();
        if ( !proxyPort.startsWith( "${" ) )
        {
            System.setProperty( "http.proxyPort", proxyPort );
        }
    }

    /**
     * DOCUMENT_ME
     *
     * @param wsdl a WSDM WSDL file
     */
    public void setWsdl( File wsdl )
    {
        m_wsdls.add( wsdl );
    }

    /**
     * Sets a system property.
     *
     * @param var the system property to be set
     */
    public void addConfiguredSysproperty( Environment.Variable var )
    {
        getProject().log( "Setting system property: " + var.getKey() + " = " + var.getValue() );
        System.setProperty( var.getKey(),
                var.getValue() );
    }

    /**
     * DOCUMENT_ME
     *
     * @param wsdls DOCUMENT_ME
     */
    public void addConfiguredWsdls( FileSet wsdls )
    {
        processWsdlFileset( wsdls );
    }

    /**
     * Creates the classpath.
     *
     * @return the classpath
     */
    public Path createClasspath()
    {
        if ( m_classpath == null )
        {
            m_classpath = new Path( getProject() );
        }
        return m_classpath.createPath();
    }

    /**
     * DOCUMENT_ME
     *
     * @throws org.apache.tools.ant.BuildException
     *          DOCUMENT_ME
     */
    public void execute()
            throws BuildException
    {
        Wsdl2Java.Wsdl2JavaOptions options = new Wsdl2Java.Wsdl2JavaOptions();
        if ( m_verbose != null )
        {
            options.setVerbose( m_verbose.booleanValue() );
        }
        File[] classpathFiles = Wsdl2Java.toFileArray( m_classpath.toString() );
        File[] wsdlFiles = (File[]) m_wsdls.toArray( new File[0] );
        try
        {
            Wsdl2Java wsdl2Java = createWsdl2Java( wsdlFiles, m_outputDir, classpathFiles, options );
            wsdl2Java.generate();
        }
        catch ( Exception e )
        {
            throw new BuildException( e );
        }
    }

    protected Wsdl2Java createWsdl2Java( File[] wsdlFiles, File outputDir, File[] classpathFiles, Wsdl2Java.Wsdl2JavaOptions options )
            throws Exception
    {
        return new Wsdl2Java( wsdlFiles, outputDir, classpathFiles, options );
    }

    /**
     * DOCUMENT_ME
     *
     * @return DOCUMENT_ME
     */
    public String toString()
    {
        return "Wsdl2Java Ant task";
    }

    private void processWsdlFileset( FileSet fileSet )
    {
        if ( fileSet.getDir( getProject() ) != null )
        {
            FileScanner scanner = fileSet.getDirectoryScanner( getProject() );
            File basedir = scanner.getBasedir();
            String[] files = scanner.getIncludedFiles();

            for ( int i = 0; i < files.length; i++ )
            {
                m_wsdls.add( new File( basedir, files[i] ) );
            }
        }
    }

}
TOP

Related Classes of org.apache.ws.resource.tool.Wsdl2JavaTask

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.