Hi,

     I've started using Castor and while the docs are pretty good,
they're a bit short on complex mapping examples.  I can't seem to find
anywhere elsewhere, though I'm still digging through the list archive
for castor-users (sadly, searching the list archive for "complex
mapping" didn't turn up much).

     I'm using Castor for java-to-XML mapping where I have an
existing, mostly-defined XML and Java classes to deal with.  Here's an
example of the sort of mapping I'm having problems with right now:

-----Order Example with <Items></Items> tags
<Order>
    <CustomerWrapper>
        <WrapperDetail>uselessValue</WrapperDetail>
        <Customer>
            <Recipient>Bob</Recipient>
            <Address>123 Public Street</Address>
            <ZipCode>11111111</ZipCode>
        </Customer>
    </CustomerWrapper>
    <Items>
        <Item>
            <Sku>value</Sku>
            <Description>value</Description>
            <Manufacturer>value</Manufacturer>
        </Item>
        <Item>
            <Sku>value</Sku>
            <Description>value</Description>
            <Manufacturer>value</Manufacturer>
        </Item>
        <Item>
            <Sku>value</Sku>
            <Description>value</Description>
            <Manufacturer>value</Manufacturer>
        </Item>
        <!-- ...repeat Item tags ad nauseam... -->
    </Items>
</Order>
-----

The problems I'm having are with the
<CustomerWrapper></CustomerWrapper> surrounding the <Customer>, the
<WrapperDetail>, neither of which map to a java class (I'd like to
just ignore them) and the <Items></Items> surrounding the multiple
<Item> elements.  When I drop those out of the data, everything works
fine with the following mapping files.

According to the docs, I should be able ignore <CustomerWrapper> by
specifying the fields like:

        <field name="recipient" type="String" location="CustomerWrapper"
node="text">
            <bind-xml name="Recipient"/>
        </field>

But when I do so and add the <CustomerWrapper> back in, I get:

Unable to find FieldDescriptor for 'CustomerWrapper' in ClassDescriptor of
sol-and-offers{file: [not available]; line: 2; column: 29}

Similarly, when I add the <Items></Items> back in (without the other
changes, I get:

"unable to find FieldDescriptor for 'Items' in ClassDescriptor of
Order{file: [not available]; line: 51; column: 10}"


-----Customer Mapping
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
    "http://castor.org/mapping.dtd";>
<mapping>
    <class name="com.foo.Customer">
        <map-to xml="Customer"/>
        <field name="recipient" type="String" node="text">
            <bind-xml name="Recipient"/>
        </field>
        <field name="address" type="String" node="text">
            <bind-xml name="Address"/>
        </field>
        <field name="zipCode" type="String" node="text">
            <bind-xml name="ZipCode"/>
        </field>
    </class>
</mapping>
-----

-----Item Mapping
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
    "http://castor.org/mapping.dtd";>
<mapping>
    <class name="com.foo.Item">
        <field name="sku" type="String" node="text">
            <bind-xml name="Sku"/>
        </field>
        <field name="description" type="String" node="text">
            <bind-xml name="Description"/>
        </field>
        <field name="manufacturer" type="String" node="text">
            <bind-xml name="Manufacturer"/>
        </field>
    </class>
</mapping>
-----

-----Order Mapping
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
    "http://castor.org/mapping.dtd";>
<mapping>
    <include href="CustomerMapping.xml"/>
    <include href="ItemMapping.xml"/>
    <class name="com.foo.Order">
        <field name="customer" type="com.foo.Customer">
            <xml bind-to="Customer"/>
        </field>
        <field name="Items" type="com.foo.Item" collection="arraylist"/>
    </class>
</mapping>
-----

Steven J. Owens
[EMAIL PROTECTED]



-------------------------------------------------
If you wish to unsubscribe from this list, please 
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to