xjc binding customization does not work in jaxb 2.1.3. It works in jaxb 2.0

女生的网名这么多〃 提交于 2019-12-24 01:37:58

问题


I developed a binding customization file in jaxb 2.0 in JDK 1.6.0 and it worked fine.

Now I'm using jaxb 2.1.3 in JDK 1.6.0_13 and it gives me errors:

Error xxx shows up in more than one properties

which is what the binding file is suppose to be handling by renaming them.

What happened between 2.0 and 2.1.3 that I need be aware of and what do I need to change. I've searched near and far and can't figure it out. Thanks so much for your help.

I'm using the binding customization file because the schema has a couple property names that would get a "catch-all" property because the field name is used by two different parts of a schema. The 2 fields are called expression and assertion

I get the following errors parsing a schema:

[ERROR] Element "assertion" shows up in more than one properties.
line 649 of file:/D:/jaxb/extract-xjbfix/090403-0_901-Packet-Schema.xsd

[ERROR] The following location is relevant to the above error
line 647 of file:/D:/jaxb/extract-xjbfix/090403-0_901-Packet-Schema.xsd

[ERROR] Element "expression" shows up in more than one properties.
line 518 of file:/D:/jaxb/extract-xjbfix/090403-0_901-Packet-Schema.xsd

[ERROR] The following location is relevant to the above error
line 516 of file:/D:/jaxb/extract-xjbfix/090403-0_901-Packet-Schema.xsd

[ERROR] Element "expression" shows up in more than one properties.
line 522 of file:/D:/jaxb/extract-xjbfix/090403-0_901-Packet-Schema.xsd

[ERROR] The following location is relevant to the above error
line 516 of file:/D:/jaxb/extract-xjbfix/090403-0_901-Packet-Schema.xsd

Failed to parse a schema.

my xjc command is :

xjc -extension 090403-0_901-Packet-Schema.xsd -b binding.xjb

my xjb file is:

<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings version="2.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="090403-0_901-Packet-Schema.xsd" node="/xs:schema">

<jxb:globalBindings>
    <xjc:superClass name="com.pw.ietm.XMLExtract.IetmElement"/>
</jxb:globalBindings>

<jxb:schemaBindings>
     <jxb:package name="com.pw.ietm.XMLExtract"/>
</jxb:schemaBindings>

<!-- Modify Expression because expression is used in two different parts of a schema -->

<jxb:bindings node="//xs:complexType[@name='expression_comtype']/xs:choice/xs:sequence[position()=1]/xs:element[@name='expression'][position()=1]">
    <jxb:property name="expressionFirst"/>
</jxb:bindings>

<jxb:bindings node="//xs:complexType[@name='expression_comtype']/xs:choice/xs:sequence[position()=1]/xs:element[@name='expression'][position()=2]">
    <jxb:property name="expressionSecond"/>
</jxb:bindings>

<jxb:bindings node="//xs:complexType[@name='expression_comtype']/xs:choice/xs:sequence[position()=2]/xs:element[@name='expression']">
    <jxb:property name="expressionAlone"/>
</jxb:bindings>

<!-- Modify Loop-step because assertion is used in two different parts of a schema -->

<jxb:bindings node="//xs:complexType[@name='loop-step_comtype']/xs:sequence/xs:element[@name='assertion'][position()=1]">
    <jxb:property name="assertionInitial"/>
</jxb:bindings>

<jxb:bindings node="//xs:complexType[@name='loop-step_comtype']/xs:sequence/xs:element[@name='assertion'][position()=2]">
    <jxb:property name="assertionChanging"/>
</jxb:bindings>

</jxb:bindings> <!-- schemaLocation="090403-0_901-Packet-Schema.xsd" node="/xs:schema" -->

The schema is very large but here are the 2 assertion and expression comtype (which is where the errors point to):

<xs:complexType name="loop-step_comtype">
<xs:sequence>
<xs:element name="assignment" type="assignment_comtype" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="assertion" type="**assertion_comtype**" minOccurs="0"/>
<xs:element name="expression" type="expression_comtype"/>
<xs:element name="assertion" type="**assertion_comtype**" minOccurs="0"/>
<xs:element name="step-seq" type="step-seq_comtype"/>
</xs:sequence>
<xs:attributeGroup ref="common_attrgroup"/>
</xs:complexType>


<xs:complexType name="expression_comtype">
<xs:choice>
<xs:sequence>
<xs:element name="expression" type="**expression_comtype**"/>
<xs:group ref="binop_elemgroup"/>
<xs:element name="expression" type="**expression_comtype**"/>
</xs:sequence>
<xs:sequence>
<xs:group ref="unop_elemgroup"/>
<xs:element name="expression" type="**expression_comtype**"/>
</xs:sequence>
<xs:element name="property-libref" type="property-libref_comtype"/>
<xs:group ref="value_elemgroup"/>
</xs:choice>
<xs:attributeGroup ref="common_attrgroup"/>
</xs:complexType> 

回答1:


Problem is actually a bug in java versions after 1.6.0 Please see Issue 642 at https://jaxb.dev.java.net/issues/show_bug.cgi?id=642 Problem has been resolved but as of 8/31/09 no target date for which release the fix will be incorporated. I will continue to use 1.6.0



来源:https://stackoverflow.com/questions/868658/xjc-binding-customization-does-not-work-in-jaxb-2-1-3-it-works-in-jaxb-2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!