Castor生成复杂类型无法工作的类

时间:2011-01-07 11:19:46

标签: java castor

您好我有以下内容,它不使用bindigs.xml文件为complextypes生成类文件。

Sample.xsd文件

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="Data">
        <xs:annotation>
            <xs:documentation>This section contains the supply chain message 
          data</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:choice>
                <xs:element name="PurchaseOrder">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="LineItem" type="LineItemType" maxOccurs="unbounded"/>
                        </xs:sequence>
                        <xs:attribute name="OrderNumber" type="xs:string" use="required"/>
                    </xs:complexType>
                </xs:element>
                <xs:element name="OrderReceipt">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="LineItem" type="ReceiptLineItemType" maxOccurs="unbounded"/>
                        </xs:sequence>
                        <xs:attribute name="OrderNumber" type="xs:string" use="required"/>
                    </xs:complexType>
                </xs:element>
            </xs:choice>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="SkuType">
        <xs:annotation>
            <xs:documentation>Contains Product Identifier</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="Number" type="xs:integer"/>
            <xs:element name="ID" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="ReceiptSkuType">
        <xs:annotation>
            <xs:documentation>Contains Product Identifier</xs:documentation>
        </xs:annotation>
        <xs:complexContent>
            <xs:extension base="SkuType">
                <xs:sequence>
                    <xs:element name="InternalID" type="xs:string"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="LineItemType">
        <xs:sequence>
            <xs:element name="Sku" type="SkuType"/>
            <xs:element name="Value" type="xs:double"/>
            <xs:element name="BillingInstructions" type="xs:string"/>
            <xs:element name="DeliveryDate" type="xs:date"/>
            <xs:element name="Number" type="xs:integer"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="ReceiptLineItemType">
        <xs:sequence>
            <xs:element name="Sku" type="ReceiptSkuType"/>
            <xs:element name="Value" type="xs:double"/>
            <xs:element name="PackingDescription" type="xs:string"/>
            <xs:element name="ShipDate" type="xs:dateTime"/>
            <xs:element name="Number" type="xs:integer"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

bindings.xml

&LT;

binding xmlns="http://www.castor.org/SourceGenerator/Binding" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xsi:schemaLocation="http://www.castor.org/SourceGenerator/Binding
                C:\\Castor\\xsd\\binding.xsd" 
            defaultBinding="element">

   <elementBinding name="/Data/PurchaseOrder/LineItem">
      <java-class name="PurchaseOrderLineItem"/>
   </elementBinding>

   <elementBinding name="/Data/OrderReceipt/LineItem">
      <java-class name="OrderReceiptLineItem1"/>
   </elementBinding>

   <elementBinding name="/complexType:ReceiptLineItemType/Sku">
      <java-class name="Xxxxxx"/>
   </elementBinding>




   <elementBinding name="/complexType:LineItemType/Sku">
      <java-class name="Yyyyyy"/>
   </elementBinding>    

</binding>

pom.xml插件配置:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>castor-maven-plugin</artifactId>
                <version>1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <bindingfile>src/main/castor/binding.xml</bindingfile>
                    <schema>src/main/castor/sample.xsd</schema>
                    <packaging>com.sg.defi.castor.correspondence</packaging>
                    <properties>src/main/castor/castorbuilder.properties</properties>
                </configuration> 

            </plugin>

在任何.properties文件中是否有任何要更改的内容,以便获取使用给定bindingies的webs.xml文件名称生成的类文件。

1 个答案:

答案 0 :(得分:0)

想出来! ,

将complextypes的binding.xml修改为

<elementBinding name="/complexType:ReceiptLineItemType/Sku">    
   <java-class name="Xxxxxx"/>  
  </elementBinding> 

Change the above code to 

<complexTypeBinding name="complexType:ReceiptLineItemType/Sku">    
   <java-class name="Xxxxxx"/>  
</complexTypeBinding> 

非常遗憾的是,蓖麻网站本身以错误的方式发布了这个例子

http://www.castor.org/how-to-use-a-binding-file-with-source-generation.html