自定义绑定以强制创建内部类或 xs:element 的 getters/setters
我有一个来自第三方提供商的架构声明,如下所示。
<xs:complexType name="GroupParameterType">
<xs:sequence minOccurs="0" maxOccurs="4">
<xs:element name="name" type="xs:string">
<xs:annotation>
<xs:documentation>The name of the parameter.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="value" type="xs:string">
<xs:annotation>
<xs:documentation>The value of the parameter.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
上面是我无法更改的架构。我正在尝试为 jaxb 2.0 编写自定义绑定,以便我可以在 java 代码中将名称引用为 GroupParameterType.Name 或 GroupParameterType.Value。
当前的默认绑定为我生成列表,即 getNameandValueList,但我想要分别为名称和值提供单独的 getter 和 setter。
我尝试放入如下所示的自定义绑定:
<jxb:bindings schemaLocation="GroupParameter.xsd" node="xs:element[@name='name']">
<jxb:globalBindings localScoping="toplevel" generateIsSetMethod="true"/>
</jxb:bindings>
<jxb:bindings schemaLocation="GroupParameter.xsd" node="xs:element[@name='value']">
<jxb:globalBindings localScoping="toplevel" generateIsSetMethod="true"/>
</jxb:bindings>
它没有任何改变默认类生成的功能。谁能给我一些指示,接下来我还能尝试什么?我希望有默认的列表生成以及名称和值的 getter/setter 或将名称和值作为内部类。如果我删除 maxOccurs=4 选项,我可以生成 getter/setter,但由于我无法修改架构,所以我尝试使用外部绑定文件来获取该行为。
谢谢 舜
I have a schema declaration as follow from a third-party provider.
<xs:complexType name="GroupParameterType">
<xs:sequence minOccurs="0" maxOccurs="4">
<xs:element name="name" type="xs:string">
<xs:annotation>
<xs:documentation>The name of the parameter.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="value" type="xs:string">
<xs:annotation>
<xs:documentation>The value of the parameter.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
Above is the schema that i CANNOT change. I am trying to write a custom binding for jaxb 2.0 such that I can refer to name as GroupParameterType.Name or GroupParameterType.Value in java code.
Current default binding generates List for me i.e. getNameandValueList, but I want separate getters and setters for name and value respectively.
I tried putting in a custom binding like the following :
<jxb:bindings schemaLocation="GroupParameter.xsd" node="xs:element[@name='name']">
<jxb:globalBindings localScoping="toplevel" generateIsSetMethod="true"/>
</jxb:bindings>
<jxb:bindings schemaLocation="GroupParameter.xsd" node="xs:element[@name='value']">
<jxb:globalBindings localScoping="toplevel" generateIsSetMethod="true"/>
</jxb:bindings>
and it did nothing to change the default class generation. Can anyone give me some pointers as so what else can I try next ? I am looking to have the default List generation ALONG WITH the getters/setters for name and value OR have name and value as Inner Classes. If i remove the maxOccurs=4 option, I can generate getters/setters but since I can't modify the schema, I am trying to get that behavior using external binding file.
Thanks
Shon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非修改架构,否则无法获得此行为。您确实有一个映射到异构元素属性的架构模型,并且您无法通过自定义来更改它。
您可以尝试使用代码注入插件作为最后的撤退。
You can't get this behaviour unless you modify your schema. You do have a schema model which maps to a heterogeneous element property, and you can't change it with a customization.
You can try the code injection plugin as the last retreat.