如何使用外部绑定文件覆盖 JAXB 中的默认名称?

2024-01-29

我有一个看起来像这样的元素。

 <xsd:element name="container">
    <xsd:complexType>
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
        <xsd:element ref="navmap"/>
        <xsd:element ref="keymap" />
        <xsd:element ref="container" />
        <xsd:element ref="ad" />
        <xsd:element ref="button" />
        <xsd:element ref="checkbox" />        
      </xsd:choice>
    </xsd:complexType>
  </xsd:element>

以下是为此元素创建的默认代码。

@XmlElements({
    @XmlElement(name = "navmap", type = Navmap.class),
    @XmlElement(name = "keymap", type = Keymap.class),
    @XmlElement(name = "container", type = Container.class),
    @XmlElement(name = "ad", type = Ad.class),
    @XmlElement(name = "button", type = Button.class),
    @XmlElement(name = "checkbox", type = Checkbox.class),
})
protected List<Object> navmapOrKeymapOrContainer;

我的问题是我需要在我的 .xjb 绑定文件以更改默认生成的名称 navmapOrKeymapOrContainer 到其他类似的东西 children?


Example:

<xs:complexType>
  <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:annotation>
      <xs:appinfo>
        <jaxb:property name="Shapes"/>
      </xs:appinfo>
    </xs:annotation>
    <xs:element name="Rectangle" type="Rectangle"/>
    <xs:element name="Square" type="Square"/>
    <xs:element name="Circle" type="Circle"/>
  </xs:choice>
</xs:complexType>

在您的绑定文件中调整它就可以了。看here http://archive.oreilly.com/pub/a/onjava/2003/12/10/jaxb.html?page=2以供参考。

清单 11 揭示了这个秘密:

<jxb:bindings version="1.0" 
  xmlns:jxb="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" 
  jxb:extensionBindingPrefixes="xjc">
<jxb:bindings schemaLocation="po4.xsd" node="/xs:schema">
  <jxb:globalBindings>
    <xjc:superClass name="com.syh.
    <xjc:serializable uid="12343"/>
  </jxb:globalBindings>
  <jxb:bindings node="//xs:element[@name='Widgets']//xs:complexType//xs:choice">
      <jxb:property name="Shapes"/>
  </jxb:bindings>
</jxb:bindings>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用外部绑定文件覆盖 JAXB 中的默认名称? 的相关文章

随机推荐