从模式添加注释JAXB绑定类 [英] adding an annotation to a JAXB binding class from a schema
问题描述
喜计算器世界,
我想在一个特定的元件可以用作通过JAXB一个XmlRootElement将一个XSD来指定
I want to specify in a XSD that a specific element can be used as a XmlRootElement by JAXB.
我知道如何注释添加到生成的类:我想要做的就是指定一个元素可以为code前代根元素产生。
I know how to add the annotation to the generated class: what I want to do is to specify that a element can be generated as a root element before the code generation.
我使用外部JAXB自定义(.xjb文件)。
其目的是在这里不修改模式(因为他们定义的标准)。
I use external JAXB customizations (.xjb files). The purpose is here to not modifying the schemas (as they are defining standards).
任何人都知道该怎么办?
谢谢!
Anybody knows how do that? Thanks!
NJ
推荐答案
问题解决了。
在JAXB插件注释<一个href=\"http://confluence.highsource.org/display/J2B/Annotate+Plugin\">http://confluence.highsource.org/display/J2B/Annotate+Plugin做这项工作。
The JAXB plugin Annotate http://confluence.highsource.org/display/J2B/Annotate+Plugin do the job.
添加下面的代码片段在JAXB绑定文件(外部绑定,即一个.xjb文件):
Add the following fragment in your jaxb binding file (external binding, i.e. a .xjb file):
<jaxb:bindings schemaLocation="csw/2.0.2/CSW-discovery.xsd" node="/xs:schema">
<jaxb:bindings node="xs:complexType[@name='GetRecordsType']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
name="GetRecordsType" />
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
不要忘了申报命名空间:
Do not forget to declare the namespaces:
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="http://annox.dev.java.net"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
jaxb:extensionBindingPrefixes="xjc annox" version="2.1">
...
</jaxb:bindings>
和使用ANT或MAVEN任务<一href=\"http://confluence.highsource.org/display/J2B/User+Guide\">http://confluence.highsource.org/display/J2B/User+Guide继续进行的资源的产生
And use a ANT or MAVEN task http://confluence.highsource.org/display/J2B/User+Guide to proceed the generation of the sources.
我还是搜索如何手动指定(没有用Ant或Maven的XJC任务)的JAXB扩展,但它现在的作品。 (我有我自己的Ant脚本什么的,为什么我搜索手动调用XJC)。
I still search how to specify manually (without an xjc task with ant or maven) the JAXB extensions but it works now. (I have my own ANT script what's why I search to manually call XJC).
在JAXB扩展机制是非常方便的,看看到JAXB2基础:
<一href=\"http://confluence.highsource.org/display/J2B/Home\">http://confluence.highsource.org/display/J2B/Home
The JAXB extension mechanism is very convenient, have a look to JAXB2 Basics: http://confluence.highsource.org/display/J2B/Home
这篇关于从模式添加注释JAXB绑定类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!