Hi,
 
I'm using castor-0.9.4 to translate XML schema files to Castor Java
classes. Since the schemas I'm using are somewhat complex, I sought a
way to integrate translation and real code generation with my usual ANT
tool. Therefore, I developed an ANT build.xml file that does just that.
I'll append it to this mail.
 
Furthermore, I have seen some problems with the SourceGenerator ( e.g.
problems with different elements having the same name; missing package
indications when using non-trivial element content [ see previous mail ]
), that must be patched in the source files before compiling with javac.
Therefore, I have included a patch mechanism in the build.xml that will
allow for such changes. To use that mechanism, I translate the XML
schema with the SourceGenerator, transfer all relevant generated source
files into directory patch, do whatever changes are needed, and
translate/compile the whole stuff again. As soon as there are some files
in directory patch, they will be copied onto the generated source files,
before javac will compile the complete stuff.
 
The directory structure needed for the build.xml is as follows
 
  classes                       ==>  base dir for generated .class files
  my                            ==>
    package                     ==>  dir structure according to the
                                       package struct
      xml                       ==>
        patch                   ==>  directory patch with putative patch
                                       files
        MySchema.xsd            ==>  the schema
        build.xml               ==>  the ANT build.xml file
        MyTest.java             ==>  any number of own classes
 
I hope, this will be of some use. Maybe, there are extensions possible
to it. Please feel free to introduce them. Just drop me a mail, so that
I can update myself :-)
 
 
Best regards,
Kurt Spanier



<?xml version="1.0"?>
 
<!--  BUILD.XML USED BY ANT v1.4 !!!  -->
 
 
<project name="my.project" default="all-gen" basedir="../../..">
 
  <!-- ==================================================== -->
  <!--              Demo build file                         -->
  <!-- ==================================================== -->
 
  <!--  some properties for defining directory structure and stuff  -->
  <property name="myxml.dir"      value="my/package/xml"/>
  <property name="myxml.pck"      value="my.package.xml"/>
  <property name="gen.dir"        value="${myxml.dir}/generated"/>
  <property name="genbase.dir"    value="${gen.dir}/${myxml.dir}"/>
  <property name="types.dir"      value="${genbase.dir}/types"/>
  <property name="dirs.base"      value="${basedir}"/>
  <property name="classdir"       value="${dirs.base}/classes"/>
 
  <!--  the XML schema file  -->
  <property name="my.include"
              value="-i ${dirs.base}/${myxml.dir}/MySchema.xsd"/>

  <!--  controlling the source code generator  -->
  <property name="package.arg"    value="-package ${myxml.pck}"/>
  <property name="types.arg"      value="-types j2"/>
  <property name="dest.arg"       value="-dest ${dirs.base}/${gen.dir}"/>
  <property name="fixed.args"
              value="-f ${package.arg} ${types.arg} ${dest.arg}"/>
  <property name="patch.dir"      value="${myxml.dir}/patch"/>
 
 
  <!--  target all, just for compiling classes in the base directory  -->
  <target name="all">
    <javac srcdir="${dirs.base}"
           destdir="${classdir}"
           includes="${myxml.dir}/**.java"
    />
  </target>
 
 
  <!--  target all-gen, for creating the whole pack  -->
  <target name="all-gen" depends="translate-copy">
    <javac srcdir="${dirs.base}"
           destdir="${classdir}"
 includes="${types.dir}/**.java,${genbase.dir}/**.java,${myxml.dir}/**.java"
    />
  </target>
 
 
  <!--  target translate-copy, for generating classes via the
        source code generator, and subsequent patching of generated classes
        ( if there are patch files )
  -->
  <target name="translate-copy" depends="translate">
    <copy todir="${dirs.base}/${genbase.dir}" overwrite="yes">
      <fileset dir="${dirs.base}/${patch.dir}" includes="**.java"/>
    </copy>
  </target>


  <!--  target translate, just to run the source code generator  -->
  <target name="translate">
    <java classname="org.exolab.castor.builder.SourceGenerator">
      <arg line="${my.include} ${fixed.args}"/>
    </java>
  </target>
 
 
  <!--  target clean, to get rid of all .class files  -->
  <target name="clean">
    <delete dir="${classdir}/${myxml.dir}"/>
  </target>
 
 
  <!--  target clean_all, to clean classes, and the generated source files -->
  <target name="clean_all" depends="clean">
    <delete dir="${dirs.base}/${gen.dir}"/>
  </target>
 
</project>


----------==========#########>>>>>ZDV<<<<<#########==========----------

X.500:                                              Tel.:
   Kurt Spanier, Zentrum fuer Datenverarbeitung,      +49 7071 29-70334
   Universitaet Tuebingen, DE
SMTP-Mail:                                          FAX.:
   [EMAIL PROTECTED]                   +49 7071 29-5912
Snail-Mail:
   Dr. Kurt Spanier, Zentrum fuer Datenverarbeitung,
   Universitaet Tuebingen, Waechterstrasse 76, D-72074 Tuebingen
PGP-Public-Key:
   finger "Kurt Spanier"@x500.uni-tuebingen.de

----------==========##########>>>>>@<<<<<##########==========----------

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to