2013-08-27 30 views
2

我的問題是這樣的: 我必須從頭開始實現web要素服務的服務器,我想從XSD精確得到:與JAXB(XJC)在Java bean類轉換

^h ** P:/ /schemas.opengis.net/wfs/1.1.0/wfs.xsd

我運行命令:

xjc h**p://schemas.opengis.net/wfs/1.1.0/wfs.xsd 

[ERROR] Property "Title" is already defined. Use <jaxb:property> to resolve this conflict. 
    line 232 of h**p://www.w3.org/1999/xlink.xsd 

[ERROR] The following location is relevant to the above error 
    line 219 of h**p://www.w3.org/1999/xlink.xsd 

[ERROR] Property "Title" is already defined. Use <jaxb:property> to resolve this conflict. 
    line 261 of h**p://www.w3.org/1999/xlink.xsd 

[ERROR] The following location is relevant to the above error 
    line 246 of h**p://www.w3.org/1999/xlink.xsd 

Failed to parse a schema. 

然而,當我運行:

xjc h**p://schemas.opengis.net/ows/1.1.0/owsGetCapabilities.xsd 

該過程100%成功。

h的片段部分** P://www.w3.org/1999/xlink.xsd是:

<xs:attributeGroup name="locatorAttrs"> 
    <xs:attribute ref="xlink:type" fixed="locator" use="required"/> 
    <xs:attribute ref="xlink:href" use="required"/> 
    <xs:attribute ref="xlink:role"/> 
    <xs:attribute ref="xlink:title"/> 
    <xs:attribute ref="xlink:label"> 
    <xs:annotation> 
    <xs:documentation> 
    label is not required, but locators have no particular 
    XLink function if they are not labeled. 
    </xs:documentation> 
    </xs:annotation> 
    </xs:attribute> 
</xs:attributeGroup> 

<xs:group name="locatorModel"> 
    <xs:sequence> 
    <xs:element ref="xlink:title" minOccurs="0" maxOccurs="unbounded"/> 
    </xs:sequence> 
</xs:group> 

<xs:complexType name="locatorType"> 
    <xs:group ref="xlink:locatorModel"/> 
    <xs:attributeGroup ref="xlink:locatorAttrs"/> 
</xs:complexType> 

<xs:element name="arc" type="xlink:arcType" abstract="true"/> 

<xs:attributeGroup name="arcAttrs"> 
    <xs:attribute ref="xlink:type" fixed="arc" use="required"/> 
    <xs:attribute ref="xlink:arcrole"/> 
    <xs:attribute ref="xlink:title"/> 
    <xs:attribute ref="xlink:show"/> 
    <xs:attribute ref="xlink:actuate"/> 
    <xs:attribute ref="xlink:from"/> 
    <xs:attribute ref="xlink:to"> 
    <xs:annotation> 
    <xs:documentation> 
    from and to have default behavior when values are missing 
    </xs:documentation> 
    </xs:annotation> 
    </xs:attribute> 
</xs:attributeGroup> 

<xs:group name="arcModel"> 
    <xs:sequence> 
    <xs:element ref="xlink:title" minOccurs="0" maxOccurs="unbounded"/> 
    </xs:sequence> 
</xs:group> 

有什麼不對?

回答

4

問題是與的xmlns:的xlink = 「http://www.w3.org/1999/xlink」

解決方案: 創建和使用binding.xjb:

<jxb:bindings version="2.0" 
     xmlns:jxb="http://java.sun.com/xml/ns/jaxb" 
     xmlns:xs="http://www.w3.org/2001/XMLSchema" > 

    <jxb:bindings schemaLocation="http://www.w3.org/1999/xlink.xsd" node="/xs:schema"> 

     <jxb:bindings node="//xs:attributeGroup[@name='locatorAttrs']"> 
      <jxb:bindings node=".//xs:attribute[@ref='xlink:title']"> 
       <jxb:property name="title1"/> 
      </jxb:bindings> 
     </jxb:bindings> 

     <jxb:bindings node="//xs:attributeGroup[@name='arcAttrs']">   
      <jxb:bindings node=".//xs:attribute[@ref='xlink:title']"> 
       <jxb:property name="title2"/> 
      </jxb:bindings>    
     </jxb:bindings>    
    </jxb:bindings>   

</jxb:bindings> 

工作ant任務(build.xml和binding.xjb在同一個文件夾中):

<xjc schema="${src.folder.xsd}\${src.file.xsd}" package="${src.package}" destdir="${src.folder}" binding="binding.xjb"> 
     <produces dir="${src.folder}\${src.package}" includes="**/*.java" /> 
</xjc> 
+0

它的工作原理。謝謝RafałOleksiak – jlucasps

+0

只是一個小小的評論:不是使用「title1」和「title2」作爲名字,也可以在兩種情況下使用「titleAttr」,例如,在我看來這更具表現力。 – Simikolon