You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by "Monks, Peter" <pe...@vignette.com> on 2005/04/13 18:33:46 UTC

Building with xsdconfig extensions from Ant

G'day everyone,

I've been using XMLBeans for a while now and have been very impressed with it - kudos to the development team and also BEA for releasing it as open source!

Recently we tried to introduce some extensions to our generated classes, using an xsdconfig such as:

  <xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config <http://xml.apache.org/xmlbeans/2004/02/xbean/config> ">
    <xb:extension for="com.acme.xml.content.ContentObjectCluster">
      <xb:interface name="com.acme.xml.extensions.ContentObjectClusterExtension">
        <xb:staticHandler>com.acme.xml.extensions.ContentObjectClusterExtensionHandler</xb:staticHandler>
      </xb:interface>
    </xb:extension>
  </xb:config>

However I'm having a helluva time trying to build it.  We're using the Ant xmlbean task, and after reading the note about circular dependencies in the "Building" directions on the "ExtensionInterfacesFeature" page in the Wiki, I tried something like:

  <target name="-generate-xmlbeans" unless="schema.generated.classes.uptodate" depends="-init">
    <taskdef name="xmlbean" classname="org.apache.xmlbeans.impl.tool.XMLBean" />

    <!-- First up, generate without the config file -->
    <xmlbean srconly="true"
             srcgendir="${path.source.java}"
             verbose="${compile.verbose}"
             classgendir="${path.output.compile}">
      <fileset dir="${path.source.schemas}" includes="${schema.source.file.name.1}" />
      <fileset dir="${path.source.schemas}" includes="${schema.source.file.name.2}" />
      <fileset dir="${path.source.schemas}" includes="${schema.source.file.name.3}" />
      <fileset dir="${path.source.schemas}" includes="${schema.source.file.name.4}" />
      <fileset dir="${path.source.schemas}" includes="${schema.source.file.name.5}" />
      <fileset dir="${path.source.schemas}" includes="${schema.source.file.name.6}" />
    </xmlbean>

    <!-- Then compile the code, including the hand-written extension classes -->
    <antcall target="CommonTargetsJavaLibrary.compile" inheritAll="true" inheritRefs="true" />
    <antcall target="CommonTargetsJavaLibrary.package" inheritAll="true" inheritRefs="true" />

    <!-- Now regenerate again, this time with the config file, and with the JAR containing
         the compiled extension classes in the classpath -->
    <xmlbean srconly="true"
             srcgendir="${path.source.java}"
             verbose="${compile.verbose}"
             classgendir="${path.output.compile}"
             classpath="${path.output.artifacts}/${name.package}.jar">
      <fileset dir="${path.source.schemas}" includes="${schema.config.file.name}" />
      <fileset dir="${path.source.schemas}" includes="${schema.source.file.name.1}" />
      <fileset dir="${path.source.schemas}" includes="${schema.source.file.name.2}" />
      <fileset dir="${path.source.schemas}" includes="${schema.source.file.name.3}" />
      <fileset dir="${path.source.schemas}" includes="${schema.source.file.name.4}" />
      <fileset dir="${path.source.schemas}" includes="${schema.source.file.name.5}" />
      <fileset dir="${path.source.schemas}" includes="${schema.source.file.name.6}" />
    </xmlbean>

    <!-- Housekeeping -->
    ...
  </target>

This didn't work - XMLBeans reports that it's unable to find my compiled extension interface and handler class, even though I've passed the JAR file containing those classes to the xmlbean task (via the "classpath" attribute).

I also journeyed down the path of using the <java> task to invoke the schema generator directly in the second generation step, but I quickly become lost in a maze of twisty little passages, all alike.

Anyway, does anyone have a functioning ant script that they'd be able to share, that demonstrates how to correctly generate code that includes extension classes?  It would be ideal if it did NOT use the schema generator to compile the generated code, since we compile the generated code in a separate step in our ant script.

Thanks in advance!
Peter

PS. Please cc me on any replies, since I'm not subscribed to this list.
 
----------------------------------------------------------------------
Peter Monks                             http://www.sydneyclimbing.com/ <http://www.sydneyclimbing.com/> 
pmonks@sydneyclimbing.com <ma...@sydneyclimbing.com>       http://www.geocities.com/yosemite/4455/ <http://www.geocities.com/yosemite/4455/> 
---------------------------------------------------------------------- 



Re: Building with xsdconfig extensions from Ant (a solution ?)

Posted by Jean-Christophe Pazzaglia <Je...@eurecom.fr>.
Hi,

I did have the same problem some times ago,
and as I told Peter, I managed to get around by
*not* using the xmlbean task but a java task
calling the SchemaCompiler and requesting a
*fork* something like:

<java fork="*true*" 
classname="*org.apache.xmlbeans.impl.tool.SchemaCompiler*" args="*-src . 
-scronly ${packagedir}/${myschema}.xsd 
${packagedir}/${extensionconfig}.xsdconfig*">
<classpath>
 <pathelement location="*${xmlbeanlib}/xbean.jar*" />
 <pathelement path="*noext.jar*" />  <!-- jar without extension -->
 <!-- add your path here -->
 </classpath>
 </java>

It seems that it solved the Peter's problem too,
it is probably related to a classpath/classloader  issue (*)
(and I suspect the task to not fork)



Hope this will help other persons too,

Best Regards,

jc


(*) it maybe that the loader use the 'non extended' version
already in memory from a previous step ???

-- 
Jean-Christophe Pazzaglia, PhD <Je...@eurecom.fr>
Corporate communications
Tel: (+33) 4-93-00-26-78 
PGP Key available : http://www.eurecom.fr/~pazzagli/publickey.pgp
--
Institut Eurécom - Office 029
http://www.eurecom.fr/
2229 Route des CrĂȘtes 
BP 193 
06904 Sophia Antipolis, France
Fax: (+33) 4-93-00-26-27
















---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org