<!--
  ~ 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.
  -->

<project name="quickstartjibx" basedir="." default="generate.all">

    <property environment="env"/>
    <property name="AXIS2_HOME" value="../.."/>
	<property name="wsdl.uri" value="./resources/META-INF/StockQuoteService.wsdl"/>
	<property name="service.target" value="build/service"/>
    <property name="client.target" value="build/client"/>

    <property name="build.dir" value="build"/>

    <path id="axis2.classpath">
        <fileset dir="${AXIS2_HOME}/lib">
            <include name="*.jar"/>
        </fileset>
    </path>
    <path id="client.class.path">
        <fileset dir="${AXIS2_HOME}/lib">
            <include name="*.jar" />
        </fileset>
        <fileset dir="${build.dir}/client/build/lib" >
            <include name="*.jar" />
        </fileset>
    </path>

    <target name="init">
        <delete dir="${build.dir}"/>
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.dir}/service"/>
        <mkdir dir="${build.dir}/client"/>
    </target>
	
    <target name="generate.service" depends="init">
        <java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true" classpathref="axis2.classpath">
            <arg line="-uri ${wsdl.uri}"/>
			<arg line="-s"/>
            <arg line="-ss"/>
			<arg line="-uw"/>
            <arg line="-sd"/>
			<arg line="-ssi"/>
            <arg line="-ap"/>
			<arg line="-ns2p http://quickstart.samples/xsd=samples.quickstart.service.jibx.xsd"/>
			<arg line="-l java"/>
            <arg line="-p samples.quickstart.service.jibx"/>
            <arg line="-d jibx"/>
            <arg line="-o ${build.dir}/service"/>
        </java>
        <copy file="${basedir}/src/samples/quickstart/service/jibx/StockQuoteServiceSkeleton.java"
              toDir="${build.dir}/service/src/samples/quickstart/service/jibx/"
              overwrite="yes">    
        </copy>
        <copy file="${basedir}/resources/META-INF/services.xml"
              toDir="${build.dir}/service/resources/"
              overwrite="yes">
        </copy>
        <ant dir="${build.dir}/service">
            <property name="axis2.home" value="../../${AXIS2_HOME}"/>
        </ant>
		<copy file="${basedir}/build/service/build/lib/StockQuoteService.aar"
              toDir="${basedir}/../../repository/services"
              overwrite="yes">
        </copy>
    </target>

    <target name="generate.client" depends="init">
        <java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true" classpathref="axis2.classpath">
            <arg line="-uri ${wsdl.uri}"/>
			<arg line="-s"/>
			<arg line="-uw"/>
            <arg line="-ns2p http://quickstart.samples/xsd=samples.quickstart.service.jibx.xsd"/>
			<arg line="-l java"/>
            <arg line="-p samples.quickstart.service.jibx"/>
            <arg line="-d jibx"/>
            <arg line="-o ${build.dir}/client"/>
        </java>
        <copy file="${basedir}/src/samples/quickstart/clients/JiBXClient.java"
              toDir="${build.dir}/client/src/samples/quickstart/clients/"
              overwrite="yes">
        </copy>
        <ant dir="${build.dir}/client">
            <property name="axis2.home" value="../../${AXIS2_HOME}"/>
        </ant>
    </target>

    <target name="generate.all" depends="generate.service, generate.client"/>

    <target name="run.client" depends="generate.client">
        <java classname="samples.quickstart.clients.JiBXClient" fork="true">
            <classpath refid="client.class.path" />
        </java>
    </target>

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>
</project>
