<?xml version="1.0" encoding="UTF-8"?>
<project name="dbwg-build-deploy-test-for_example" default="init">

    <description>
        Tomcat Implementation.
        
        Run wsdl2java to generate code implementing web service based on examples.wsdl, 
        Modify code to implement an echo service, 
        compile the code, 
        Build the war, 
        Deploy the war
        
    </description>

    <target name="init" depends="delete,mkdir,copy,wsdl2java,wsdd,insertecho,compile,war,tomcat-stop,deploy,tomcat-start"/>

    <property name="examplesDir" location="../../../examples/6/09"/>
    <property name="app" value="databinding_axis13"/>
    <property name="wait" value="10"/>
    <property environment="env"/>
    <property name="axis_home" value="${env.AXIS_HOME}"/>
    <property name="java_home" value="${env.JAVA_HOME}"/>
    <property name="tomcat_home" value="${env.CATALINA_HOME}"/>
    <property name="util_jar" location="lib/dbwg-util.jar" />
    <property name="webapps" value="C:/jakarta-tomcat-5.0.28/webapps" />
    <path id="class.path">
        <fileset dir="${axis_home}/lib">
            <include name="**/*.jar"/>
        </fileset>
        <fileset dir="${java_home}/lib">
            <include name="**/*.jar"/>
        </fileset>
    </path>    
    
    <target name="delete">
        <echo>****Start Processing example ${example} (${exampleNo} of ${exampleMax}) *****</echo>
        <echo>delete old files/directories</echo>
        <delete file="example-results-invalid.txt" quiet="true" failonerror="false"/>
        <delete file="example-results-ok.txt" quiet="true" failonerror="false"/>
        <delete file="${app}.war" quiet="true"/>
        <delete file="${webapps}/${app}.war" quiet="true"/>
        <delete dir="${app}" quiet="true"/>
    </target>

    <target name="mkdir">
        <echo>make new directories</echo>
        <mkdir dir="${app}/WEB-INF/lib"/>
        <mkdir dir="${app}/WEB-INF/classes"/>
    </target>

    <target name="copy">
        <echo>copy jars to WEB-INF/lib</echo>
        <copy todir="${app}/WEB-INF/lib">
            <fileset dir="${axis_home}/lib" excludes="**/*log*.jar,**/*saml*.jar,**/*wss*.jar,**/*xml*.jar,**/*xalan*.jar,**/*xerces*.jar"/>
        </copy>   
        <echo>copy web.xml to WEB-INF</echo>
        <copy todir="${app}/WEB-INF" file="web.xml"/>     
    </target>
    
    <target name="wsdl2java">
        <echo>create java code from wsdl</echo>
        <java fork="true" classname="org.apache.axis.wsdl.WSDL2Java" classpathref="class.path">
            <arg line="-o ${app}/WEB-INF/classes -p databinding --server-side ${examplesDir}/${example}/echo${example}.wsdl"/>
        </java> 
    </target>
    
    <target name="wsdd">
        <echo>Create server-config.wsdd</echo>
        <xslt
            style="makewsdd.xsl"
            in="${app}/WEB-INF/classes/databinding/deploy.wsdd"
            out="${app}/WEB-INF/server-config.wsdd">
        </xslt>
    </target>
    
    <target name="insertecho">
        <echo>insert echo in generated impl java code</echo>
        <java fork="true" classname="org.w3c.dbwg.wsdl.util.ModSOAPImpl" classpath="${util_jar}">
            <arg line="${app}/WEB-INF/classes/databinding/SoapBindingImpl.java"/>
        </java> 
    </target>
    
    <target name="compile">
        <echo>compile java code</echo>
        <javac srcdir="${app}/WEB-INF/classes/databinding" 
                destdir="${app}/WEB-INF/classes"
                fork="yes"
                executable="${java_home}/bin/javac">
             <classpath refid="class.path"/>
        </javac>    
    </target>
    
    <target name="war">
        <echo>build war file</echo>
        <jar destfile="${app}.war" basedir="${app}"/>
    </target>
             
    <target name="tomcat-stop">
        <echo>stop tomcat (${tomcat_home}) for example ${example} (${exampleNo} of ${exampleMax}</echo>
        <exec executable="${tomcat_home}/bin/shutdown.bat" os="${os}" spawn="true" />
        <sleep seconds="6"/>
    </target>             
    
    <target name="deploy">
        <echo>delete old war file (${example})</echo>
        <delete dir="${webapps}/${app}" quiet="true"/>
        <echo>copy new war file to app server (${example})</echo>
        <copy todir="${webapps}" file="${app}.war"/>
    </target>    
    
    <target name="tomcat-start">
        <echo>start tomcat (${tomcat_home}) example ${example} for (${exampleNo} of ${exampleMax}</echo>
        <exec executable="${tomcat_home}/bin/startup.bat" os="${os}" spawn="true" />
        <sleep seconds="12"/>
    </target>
</project>    
