hi james
sounds like exactly the right approach to me :)
(i created a point wise reply but i decided to delete it since i couldn't
add anything of substance.)
- robert
On Sunday, March 3, 2002, at 09:29 PM, James Strachan wrote:
> I've done some more work on betwixt to autoconfigure digester rules.
> Basically the default XMLBeanInfo introspector will now look for methods
> of
> the format
>
> addFoo(Bar bar);
>
> On a bean where Foo is the singular property name "foo" and "Bar" is the
> type of the property. This is enough to handle many common bean graphs.
> For
> example now Betwixt can auto default the digester rules to parse & output
> RSS. So betwixt can go in both directions XML -> bean -> XML for the RSS
> demo in Digester!
>
> If more complex digester rules are required, the BeanReader in betwixt
> is-a
> Digester so all the features available in Digester are available to you.
>
> e.g. in the RSS example there's a bean of the following format...
>
> public class Channel
>
> public Item[] getItems();
>
> public void addItem(Item item);
> }
>
> The type returned by the getItems() method could be an array, Iterator,
> Collection or Map - they are all treated as a 1-N relation or a
> 'collection'.
>
> Betwixt will associate these two methods together (the get*() and add*())
> as
> being a collection property called "items" . So these will both refer to
> the
> <item> element in the XMLBeanInfo. This pattern is useful as both the
> getter
> and setter (or 'adder') get associated with the same XML element in both
> directions. (c.f the <elenent> tag in the betwixt XML documents).
>
> Also this means that the type of each item in the 'collection' can be
> deduced. Currently the default introspector uses a starts-with algorithm
> to
> match the 2 together. So right now the default introspector would not be
> able to match the addPerson() method in the following bean..
>
> public class Foo {
> public Collection getPeople();
> public void addPerson(Person person);
> }
>
> So the default digester rules wouldn't work properly and would need a
> manual
> override. So betwixt would generate XML fine but wouldn't be able to add
> new
> people when parsing XML.
>
> Though if a slightly different naming convention were chosen it would work
> fine...
>
>
> public class Foo {
> public Iterator getPersonIterator();
> public void addPerson(Person person);
> }
>
> i.e. from a 'collection' property (of a type Map, Iterator, array or
> Collection), we often don't know what the type is for one item in the
> collection using regular introspection. But finding the add*(Type) method,
> we can deduce the type - though this algorithm depends on the matching up
> of
> the add*() method to the get*() method names. So long as the getter
> property
> starts with the 'property name' of the add method, this works fine.
>
> So these are all fine
>
> getChildren(); & addChild();
> getPersonList() & addPerson();
> getItems() & addItem();
> getChannels() & addChannel();
> getSheep() & addSheep();
>
>
> I've added a unit test case that round trips an RSS document using the
> RSSDigester example from Digester together with the BeanReader &
> BeanWriter
> from Betwixt to ensure that the XML is parsed & output correctly. Also I'
> ve
> updated the OVERVIEW.html document considerably to try explain better what
> Betwixt is and how to use it.
>
> I'm writing this mail offline but hopefully by the time you get it all
> these
> changes will have been committed to CVS.
>
> James
>
>
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED].;
> org>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED].;
> org>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>