蓖麻可以从多个XSD文件从基本XSD导入处理类生成? [英] Can Castor handle class generation from multiple XSDs importing from a base XSD?

查看:329
本文介绍了蓖麻可以从多个XSD文件从基本XSD导入处理类生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个XSD的是重复使用相同的实体。例如,双方的XSD的 ProductPurchaseRequest.xsd ProductQuoteRequest.xsd 都有一个 <产品>在他们标签来描述有问题的产品。出于这个原因,我创建了一个 Product.xsd 文件来定义<产品> 标签和两个 ProductPurchaseRequest.xsd ProductQuoteRequest.xsd 导入 Product.xsd 用`

I have several XSDs that reuse the same entities. For example, both the XSDs for the ProductPurchaseRequest.xsd and ProductQuoteRequest.xsd both have a <product> tag in them to describe the product in question. For this reason I created a Product.xsd file to define the <product> tag and both ProductPurchaseRequest.xsd and ProductQuoteRequest.xsd import the Product.xsd with a `.

我想用蓖麻来从论文的XSD的Java类,并为他们两个用于再presenting的产品,使同一类我可以重复使用相同的逻辑,它们映射到我们的模型中的产品型号类。

I would like to use Castor to generate Java classes from theses XSDs, and for both of them to use the same class for representing the Product so that I could reuse the same logic for mapping them to our model's ProductModel class.

蓖麻能这样做吗?如果是这样,这将是它的Ant任务语法。如果不是这样,也许会是JAXB一个更好的选择?

Can Castor do this? If so, what would be the Ant task syntax for it. If not, would perhaps JAXB be a better alternative?

推荐答案

所以,我能得到整个事情使用JAXB参考实现的工作。诀窍是要认识到从 JAXB网站下载的是一个的下载不可以实际库!双击接受许可证和库将本地下载。创建一个测试文件夹( JAXB_TEST ),并复制所有的下载的.jar s到一个 LIB 子文件夹。我把我所有的XSD在 XSD 子文件夹。从那以后,我跑到下面的蚂蚁的build.xml 文件。

So I was able to get the whole thing working using the JAXB reference implementation. The trick was to realise that the download from JAXB site is a downloader and not the actual libraries! Double-click to accept the licence and the libraries will download locally. Created a test folder (JAXB_TEST) and copied all the downloaded .jars to a lib subfolder. I put all my XSDs in XSD subfolder. After that I ran the following Ant build.xml file.

<?xml version="1.0"?>
<project name="jaxb_test" basedir="." default="package" >

    <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
        <classpath>
            <fileset dir="./lib" includes="*.jar" />
        </classpath>
    </taskdef>

    <target name="generate">
        <delete dir="./gen-src" />
        <mkdir dir="./gen-src" />

        <xjc destdir="./gen-src" language="XMLSCHEMA" package="com.mmm" >
            <schema dir="./xsd" includes="EPC*.xsd" />
        </xjc>      
    </target>

    <target name="compile" depends="generate" >
        <delete dir="./bin" />
        <mkdir dir="./bin" />

        <javac srcdir="./gen-src" destdir="./bin" includeantruntime="false" />
    </target>

    <target name="package" depends="compile" >
        <delete dir="./dist" />
        <mkdir dir="./dist" />
        <jar destfile="./dist/jaxb-gen.jar" basedir="./bin" />
    </target>   


</project>

我是,我曾与被称为根标签的XSD唯一的问题&LT;产品&GT; 匿名延长产品键入添加版本属性(我总是喜欢在我的根标签的),这是造成名称冲突的JAXB。所以不是,我把匿名类型到一个名为类型(即 TopLevelProduct ),并设置根到该类型和JAXB很高兴。

The only problem I had was that I had an xsd with a root tag called <product> that anonymous extended the Product type to add a version attribute (which I always like to have on my root tag's) which was causing a name conflict for JAXB. So instead, I turned the anonymous type into a named type (i.e. TopLevelProduct) and set the root to that type and JAXB was happy with that.

这篇关于蓖麻可以从多个XSD文件从基本XSD导入处理类生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆