From commons-dev-return-4975-qmlist-jakarta-archive-commons-dev=jakarta.apache.org@jakarta.apache.org Mon Mar 04 03:17:34 2002
Return-Path:
Delivered-To: apmail-jakarta-commons-dev-archive@apache.org
Received: (qmail 47339 invoked from network); 4 Mar 2002 03:17:34 -0000
Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131)
by daedalus.apache.org with SMTP; 4 Mar 2002 03:17:34 -0000
Received: (qmail 11919 invoked by uid 97); 4 Mar 2002 03:17:40 -0000
Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org
Received: (qmail 11903 invoked by uid 97); 4 Mar 2002 03:17:40 -0000
Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm
Precedence: bulk
List-Unsubscribe:
List-Subscribe:
List-Help:
List-Post:
List-Id: "Jakarta Commons Developers List"
Reply-To: "Jakarta Commons Developers List"
Delivered-To: mailing list commons-dev@jakarta.apache.org
Received: (qmail 11892 invoked from network); 4 Mar 2002 03:17:39 -0000
Message-ID: <001001c1c32a$831838d0$9865fea9@spiritsoft.com>
From: "James Strachan"
To: "Jakarta Commons Developers"
Subject: [betwixt] can now auto-default Digester rules!
Date: Sun, 3 Mar 2002 21:29:16 -0000
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
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
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 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:
For additional commands, e-mail: