commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Erdely" <mjerd...@gmail.com>
Subject Re: [betwixt] How do I control the mapping of a member class, Jav a --> XML?
Date Tue, 22 Aug 2006 15:45:22 GMT
Jesse,

You were completely correct for your solution. My XML was invalid in
the Address.betwixt file.

Thanks for your help!

-Michael


On 8/22/06, Sweetland, Jesse <JSweetland@talk.com> wrote:
> The way I interpret the bean info files (and the way it has worked for me)
> is that:
>
> (Address.betwixt)
> <info>
>         <element name="Address">
>                 ...
>         </element>
> </info>
>
> Specifies a default element name for objects of that type.  So if you had:
>
> (Customer.betwixt)
> <info>
>         <element name="Customer">
>                 <element property="shippingAddress"/>
>         </element>
> </info>
>
> Then Betwixt would look at the shippingAddress property, determine that it
> is an Address object, and then select the default element name of "Address"
> given in Address.betwixt.  Note that if you had subclasses of Address with
> their own Betwixt mappings then the subclass element name would be chosen.
> (I'm not sure that the Betwixt introspector gracefully degrades to the
> superclass or superinterfaces of a class if a Betwixt mapping is not found
> for the exact class.  If you are using a subclass of Address, then you may
> want to try specifying a Betwixt mapping for each subclass.)  Betwixt calls
> this polymorphic binding; in schema it's called substitution groups.
>
> This form:
>
> (Customer.betwixt)
> <info>
>         <element name="Customer">
>                 <element name="shippingAddress" property="shippingAddress"/>
>         </element>
> </info>
>
> Means that the default element name for the Address class should be
> overridden with "shippingAddress" in the context of a customer.  This has
> worked fairly reliably for me.
>
>
>
> -----Original Message-----
> From: Michael Erdely [mailto:mjerdely@gmail.com]
> Sent: Monday, August 21, 2006 5:30 PM
> To: Jakarta Commons Users List
> Subject: Re: [betwixt] How do I control the mapping of a member class, Jav a
> --> XML?
>
> Thank you but I am still getting the same behavior.
>
> Doesn't having the outer element name of "Address" in Address.bewtixt
> imply that all child elements are contained within the "Address"
> element parent?
>
> I have tried other Address.betwixt outer element name combinations
> with no luck as well.
>
>
> On 8/21/06, Sweetland, Jesse <JSweetland@talk.com> wrote:
> > I've had a great deal of luck by providing separate bean info documents
> for
> > each class.  Something like this might work better for you:
> >
> > Customer.betwixt:
> >
> > <?xml version="1.0"?>
> > <info>
> >         <element name="Customer"
> > uri="'http://www.example.com/customer/2006-06-01/">
> >                 <attribute name="name" property="name"/>
> >                 <element name="ShippingAddress" property="shippingAddress"
> > uri="'http://www.example.com/customer/2006-06-01/"/>
> >                 <!-- ... -->
> >         </element>
> > </info>
> >
> >
> >
> > Address.betwixt:
> >
> > <?xml version="1.0"?>
> > <info>
> >         <element name="Address"
> > uri="'http://www.example.com/customer/2006-06-01/">
> >                 <element name="addressLine1" property="addressLine1"
> > uri="'http://www.example.com/customer/2006-06-01/"/>
> >                 <element name="addressLine2" property="addressLine1"
> > uri="'http://www.example.com/customer/2006-06-01/"/>
> >                 <!-- ... -->
> >         </element>
> > </info>
> >
> >
> >
> > -----Original Message-----
> > From: Michael Erdely [mailto:mjerdely@gmail.com]
> > Sent: Monday, August 21, 2006 5:04 PM
> > To: commons-user@jakarta.apache.org
> > Subject: [betwixt] How do I control the mapping of a member class, Java
> -->
> > XML?
> >
> > My JavaBean has shippingAddress (of type Address) as a member of
> > Customer along with a few primitives.
> >
> > My configuration file properly renames the shippingAddress element
> > with the proper namespace. However, for the Address object primitives,
> > my the configuration file gets ignored so the elements have the wrong
> > names and no namespace.
> >
> > Any ideas? I am hoping I am just missing something simple.
> >
> > I am using Betwixt 0.7.
> >
> > -Michael
> >
> >
> > Snippet of XML
> > ________________________________________________________________________
> > <bt1:Customer name="Mr Smith"
> > xmlns:bt1="http://www.example.com/customer/2006-06-01/">
> >     <bt1:ShippingAddress>
> >       <addressLine1>123 Main St</addressLine1>
> >       <city>Anytown</city>
> >
> >
> > Customer.betwixt snippet
> > ________________________________________________________________________
> > <?xml version='1.0' encoding='UTF-8' ?>
> > <info>
> >         <element name='Customer'
> > uri='http://www.example.com/customer/2006-06-01/'>
> >                 <attribute name='name' property='name'/>
> >                 <element name='ShippingAddress' property='shippingAddress'
> > uri='http://www.example.com/customer/2006-06-01/'>
> >                         <element name='AddressLine1'
> property='addressLine1'
> > uri='http://www.example.com/customer/2006-06-01/'/>
> >                         <element name='City' property='city'
> > uri='http://www.example.com/customer/2006-06-01/'/>
> >
> >
> > Java Code
> > ________________________________________________________________________
> > Customer customer = new Customer ();
> > customer.setName("Mr Smith");
> >
> > Address address = new Address ();
> > address.setAddressLine1("123 Main St");
> > address.setCity("Anytown");
> >
> > customer.setShippingAddress(address);
> >
> > StringWriter outputWriter = new StringWriter();
> > BeanWriter beanWriter = new BeanWriter(outputWriter);
> >
> >
> beanWriter.getXMLIntrospector().getConfiguration().setAttributesForPrimitive
> > s(false);
> > beanWriter.getBindingConfiguration().setMapIDs(false);
> > beanWriter.setWriteEmptyElements(false);
> > beanWriter.enablePrettyPrint();
> >
> > beanWriter.write(customer);
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message